[L508][优化GPIO测试][根据参数(=1)区分是否测试gnss pin脚,上报失败pin脚号]

Change-Id: I20a5a47c92a01a58047b951f041f5b567b83962a
diff --git a/mbtk/libmbtk_factory/mbtk_gpio.c b/mbtk/libmbtk_factory/mbtk_gpio.c
index 45f2d9d..eeeaeb5 100755
--- a/mbtk/libmbtk_factory/mbtk_gpio.c
+++ b/mbtk/libmbtk_factory/mbtk_gpio.c
@@ -23,6 +23,7 @@
 #include <cutils/properties.h>
 #include "mbtk_gpio_def.h"
 #include "gpio-define.h"
+#include "mbtk_type.h"
 
 #define gpio_log(...)     if(gpio_debug)printf(__VA_ARGS__)
 #define HWMAP_DEVICE "/dev/hwmap"
@@ -711,158 +712,254 @@
 
 #elif defined(MBTK_PROJECT_L508)
 
-int test_gpio[] = 
-{ 
-	0,2,1,6,16,15,17,99,
-	34,36,35,33,14,49,50,12,118,120,
-	43,19,7,3,
-	20,59,126,117,125,18,56,55,58,48,57,5,4,21,
-	23,24,13,27,28,26,25,
-	32,31,
-	54,
-	53,123,122
-};
-int total;
-total = (sizeof(test_gpio)/sizeof(int));
+
+#define READ_GPIO_NUM 22
+
+#define DEBUG_GPIO_TEST 1
+
+mbtk_gpio_test_pin_and_gpio *p_test_gpio =NULL;
+mbtk_gpio_test_pin_and_gpio *p_gnss_gpio = NULL;
+int test_gpio_group_total_pin = 0;
+int gnss_gpio_group_total_pin = 0;
+
+int gpio_test_set_group_pin_to_low(mbtk_gpio_test_pin_and_gpio *p_pin_group_array, int total_num)
+{
+    int i;
+    int gpio_num = 0;
+    int ret = 0;
+
+    if(p_pin_group_array == NULL)
+       return -1;
+
+	for(i=0; i < total_num; i++)
+	{
+       gpio_num = p_pin_group_array[i].gpio_num;
+	   ret += gpio_register_set_func_0(gpio_num);
+	   gpio_register_set_direction(gpio_num, MBTK_GPIO_OUTPUT);
+	   gpio_register_set_value(gpio_num, 0);
+	}
+	return ret;
+}
 	
 
 int gpio_test_init(void)
 {
 	int i,j,ret;
-	//int *fail_io = (int *)arg;
-	printf("[init] L508 XX GPIOTEST v1.2 \n");
+    int gpio_num = 0;
+
+	
+
+
 	system("i2cset -y -f 2 0x31 0x12 0x46");
 	system("echo 53 > /sys/class/gpio/export");  //gnss uart rx
 	system("echo out > /sys/class/gpio/gpio53/direction");
 	system("echo 54 > /sys/class/gpio/export");//gnss uart tx
 	system("echo out > /sys/class/gpio/gpio54/direction");
 	system("echo 22 > /sys/class/gpio/export");//check pin
-
-	gpio_register_set_func_0(22);
-	gpio_register_set_direction(22, 1);	//输出
+	
+	gpio_register_set_func_0(READ_GPIO_NUM);
+	gpio_register_set_direction(READ_GPIO_NUM, 1);	//输出
 
 	usleep(500);		 
-	/*
-	GPIO22默认是上拉,如果改成GPIO输入模式,其PIN脚电压是高电平,必须改成下拉后GPIO22才处于低电平状态,否则测试PIN拉低失败
-	*/	
-	gpio_register_set_direction(22, MBTK_GPIO_INPUT);	//设置输入模式
+/*
+     GPIO22默认是上拉,如果改成GPIO输入模式,其PIN脚电压是高电平,必须改成下拉后GPIO22才处于低电平状态,否则测试PIN拉低失败
+*/	
+	gpio_register_set_direction(READ_GPIO_NUM, MBTK_GPIO_INPUT);	//设置输入模式
 	gpio_register_write(GPIO_FUNC_GPIO_22,0xb040);  //PULL DOWN
 
 
+    gpio_test_set_group_pin_to_low(p_gnss_gpio,gnss_gpio_group_total_pin); //set all gnss reserver pin to low
+
+	
 	/* [1 all gpio set to low] */
-	for(j = 0; j < 6 ; j++){
-		for(i = 0; i < total; i++){
-			gpio_register_set_func_0(test_gpio[i]);
-			gpio_register_set_direction(test_gpio[i], 1);
-			gpio_register_set_value(test_gpio[i], 0);
-		}
+    for(j = 0; j < 6 ; j++){
+         gpio_test_set_group_pin_to_low(p_test_gpio,test_gpio_group_total_pin);
 
 		for(i = 0; i <= 5; i++){
-			ret = gpio_register_get_value(22);
-			
+			ret = gpio_register_get_value(READ_GPIO_NUM);
 			if(0 == ret){
 				break;
 			}
-		
 			usleep(3000);
-		
 		}
-		
-		printf("pre set ADC: %d, times: %d\n",ret, j);
-		
+	
 		if(0 == ret){
 			break;
 		}
 	}
 
 	if(0 != ret){
-		printf("set all low Fail, please retest\n");
+		printf("[GPIOTEST]set all low Fail, please retest\n");
 		return -1;
 	}
-	
-	printf("pre set SUCCESS\n");
-	
+	printf("[GPIOTEST]pre set SUCCESS\n");
 	return 0;
 }
 
-int gpio_test(void* arg)
+int gpio_test(void* arg,int index,mbtk_gpio_test_pin_and_gpio *p_pin_group_array,int total)
 {
-	int ret,i,j;
+	int ret,i;
 	int *fail_io = (int *)arg;
-	int n = 0;
+	int failed_num = index;
 	int gpio_num = 0;
+	int pin_num = 0;
+    bool falied_flag = FALSE;
+
 	for(i = 0; i < total; i++){	
-	
-		gpio_num = test_gpio[i];
-		
-		//ret = gpio_register_get_value(test_gpio[i]);
-		//printf("GPIO%d default value? %d\n", test_gpio[i], ret);
-		
+        gpio_num = p_pin_group_array[i].gpio_num;
+		pin_num = p_pin_group_array[i].pin_num;
+		falied_flag = FALSE;
+
+#if DEBUG_GPIO_TEST
+		ret = gpio_register_get_value(gpio_num);
+		printf("[GPIOTEST]pin_num%d default value= %d\n", pin_num, ret);
+#endif
+
 		//set high
 		gpio_register_set_value(gpio_num, 1);
-		
+
+#if DEBUG_GPIO_TEST
 		ret = gpio_register_get_value(gpio_num);
-		
-		printf("GPIO%d set high= %d\n", gpio_num, ret);
-		
+		printf("[GPIOTEST]pin_num%d set high= %d\n", pin_num, ret);
+#endif
 		//get 
-		ret = gpio_register_get_value(22);
-		
+		ret = gpio_register_get_value(READ_GPIO_NUM);
 		if(1 != ret){
-			printf("gpio [%d] test high failed\n", gpio_num);
-			
-			fail_io[n] = gpio_num;
-			
-			n++;
-		}else{
-			printf("gpio[%d] test high success\n", gpio_num);
-		}
+            printf("[GPIOTEST]pin%d test high failed\n", pin_num);
+            falied_flag = TRUE;
+        }else{
+            printf("[GPIOTEST]pin[%d] test high success\n", pin_num);
+        }
 
 		//set low
-		gpio_register_set_value(gpio_num, 0);
-		
-		//ret = gpio_register_get_value(test_gpio[i]);
-		//printf("GPIO%d set low? %d\n", test_gpio[i], ret);
-		
+	    gpio_register_set_value(gpio_num, 0);
+#if DEBUG_GPIO_TEST
+		ret = gpio_register_get_value(gpio_num);
+		printf("[GPIOTEST]pin_num%d set low= %d\n", pin_num, ret);
+#endif
 		//get 
-		ret = gpio_register_get_value(22);
-	
+		ret = gpio_register_get_value(READ_GPIO_NUM);
 		if(0 != ret){
-			printf("gpio [%d] test low failed\n", gpio_num);
-			
-			fail_io[n] = test_gpio[i];
-			
-			n++;
-		}else{
-			printf("gpio [%d] test low success\n", gpio_num);
+            printf("[GPIOTEST]pin_num%d test low failed\n", pin_num);
+			falied_flag = TRUE;
+
+        }else{
+            printf("[GPIOTEST]pin_num%d test low success\n", pin_num);
+        }
+
+		if(falied_flag)
+		{
+            fail_io[failed_num] = p_pin_group_array[i].pin_num;
+#if DEBUG_GPIO_TEST
+		 printf("[GPIOTEST]NO.%d pin_num%d failed %d\n",i,pin_num, failed_num);
+#endif
+			failed_num++;
 		}
 	}
-	return n;
+	return failed_num;
 }
-		
-	
 
 
-int mbtk_at_gpio(bool gnss_support, void* arg)
+int mbtk_at_gpio(bool gnss_support,void* arg)
 {
-	int i, j, ret, total, n = 0;
-	//int *fail_io = (int *)arg;
+	int n = 0;
+	mbtk_gpio_test_pin_and_gpio test_gpio[] = 
+	{
+		//{GPIO , PIN}
+		{0,100}, //RMII_RX-DV
+		{1,101}, //RMII_RXD0
+		{2,102},//RMII_RXD1
+		{3,103},//RMII_CLK
+		{6,104},//RMII_TXD0
+		{7,105},//RMII_TXD1
+		{15,106},//RMII_TX_EN
+		{16,109},//RMII_MDC
+		{17,110},//RMII_MDIO
+		{18,107},//RMII_INT
+		{99,16},//USB_ID
+		{34,9}, //SPI0_CS
+		{36,8},//SPI0_TXD
+		{35,7},//SPI0_RXD
+		{33,6},//SPI0_CLK
+		{14,51}, //NET_LIGHT
+		{13,49}, //STATUS LED
+		{12,50},//WAKE_IN
+		{49,55}, //I2C SCL
+		{50,56}, //I2C SDA
+		{19,53}, //USIM_DET
+		{43,48}, //SD_DET
+		{118,52}, //WAKE OUT
+		{120,54}, //FLIGHT MODE
+		
+		
+		{20,45}, //NORMAL GPIO
+		{59,122},  //SDIO_CLK
+		{56,117}, //SDIO_DATA1
+		{55,118},//SDIO_DATA2
+		{58,119},//SDIO_CMD
+		{48,120},//SDIO_DATA3
+		{57,121},//SDIO_DATA0
+		{5,84}, //NORMAL GPIO
+		{4,30},//NORMAL GPIO
+		{21,28}, //NORMAL GPIO
+		{23,69}, //UART_RING
+		{24,70}, //UART_DCD
+		{27,73}, //PCM_OUT
+		{28,74}, //PCM_IN
+		{26,75}, //PCM_SYNC
+		{25,76}, //PCM_CLK
+		
+		{126,112},//NORMAL GPIO or pwm3
+		{117,123},	//PWM
+		{125,116}, //CLK_REQ 
+
+		//{54,114}, //debug uart2, no need be tested
+		//{53,115}, //debug uart2, no need be tested
+
+	};
+   
+	mbtk_gpio_test_pin_and_gpio GNSS_test_gpio[] = {
+		{54,114}, //GPS UTXD, UART1_TXD,L508LAN+L508CN(D)+L508EN+L508LEN+L508TLCN NOT CONNECTED
+		{53,115}, //GPS URXD,UART1-RXD,L508LAN+L508CN(D)+L508EN+L508LEN+L508TLCN NOT CONNECTED
+		{32,66}, //PIN66,host wake GPS, RTS, L508TLCN_V2+L508LEN_V2+L508EN_V2 NOT CONNECTED
+		{31,67}, //PIN67,GPS wake Host,CTS, L508TLCN_V2+L508LEN_V2+L508EN_V2 NOT CONNECTED
+		{123,42},//GPS_EN, L508TLCN_V2+L508LEN_V2+L508EN_V2 NOT CONNECTED
+		{122,35},  //32K OUT, L508TLCN_V2+L508LEN_V2+L508EN_V2 not connected   
+	};
+	p_gnss_gpio = GNSS_test_gpio;
+	gnss_gpio_group_total_pin = (sizeof(GNSS_test_gpio)/sizeof(GNSS_test_gpio[0]));
+
+    p_test_gpio = test_gpio;
+	test_gpio_group_total_pin = (sizeof(test_gpio)/sizeof(test_gpio[0]));
+
+   if(!gnss_support) 
+       n = test_gpio_group_total_pin+gnss_gpio_group_total_pin;
+    else
+       n = test_gpio_group_total_pin;
+
+	printf("[init] L508 XX GPIOTEST v1.3 total pin=%d\n",n);	
 
 	n = gpio_test_init();
-	
 	if(-1 == n)
 	{
-	//return -1;
+		goto gpiotest_finished;
 	}
-	
-	n = gpio_test(arg);
+    n = 0;
 
+	n = gpio_test(arg,0,p_test_gpio,test_gpio_group_total_pin);
+
+   //if the module has gnss chip, don't test the gnss's pins
+    if(!gnss_support) 
+	{
+    	n = gpio_test(arg,n,p_gnss_gpio,gnss_gpio_group_total_pin);
+	}
+
+gpiotest_finished:
 	system("echo 53 > /sys/class/gpio/unexport"); //unexport gnss uart rx
 	system("echo 54 > /sys/class/gpio/unexport");//unexportgnss uart tx
 	system("echo 22 > /sys/class/gpio/unexport");//unexportcheck pin
 
-	printf("\n[GPIOTEST] Finished !!\n\n");
-	
+	printf("\n[GPIOTEST] Finished %d!!\n\n",n);
 	return n;
 }
 
diff --git a/mbtk/libmbtk_factory/mbtk_gpio_def.h b/mbtk/libmbtk_factory/mbtk_gpio_def.h
index e9ba6a5..4234f86 100755
--- a/mbtk/libmbtk_factory/mbtk_gpio_def.h
+++ b/mbtk/libmbtk_factory/mbtk_gpio_def.h
@@ -163,5 +163,11 @@
 	uint8 mbtk_gpio_test_result; // 0 is pass, 1 is low failed, 2 is high failed
 }mbtk_gpio_paired_info_struct;
 
+typedef struct
+{
+  uint16 gpio_num;
+  uint16 pin_num;   //moudle pin num
+}mbtk_gpio_test_pin_and_gpio;
+
 #endif /*__GPIO_DEFINE_H__*/