b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame^] | 1 | /** |
| 2 | * \file gpio-test.c |
| 3 | * \brief A Documented file. |
| 4 | * |
| 5 | * Detailed description |
| 6 | * \Author: Sniper <js.wang@mobiletek.cn> |
| 7 | * \Version: 1.0.0 |
| 8 | * \Date: 2022-04-26 |
| 9 | */ |
| 10 | #include <stdio.h> |
| 11 | #include <string.h> |
| 12 | #include <sys/types.h> |
| 13 | #include <sys/stat.h> |
| 14 | #include <fcntl.h> |
| 15 | #include <errno.h> |
| 16 | #include <limits.h> |
| 17 | #include <sys/wait.h> |
| 18 | #include <unistd.h> |
| 19 | #include <sys/mount.h> |
| 20 | #include <sys/mman.h> |
| 21 | #include <ctype.h> |
| 22 | #include <stdbool.h> |
| 23 | #include <cutils/properties.h> |
| 24 | #include "mbtk_gpio_def.h" |
| 25 | #include "gpio-define.h" |
| 26 | |
| 27 | #ifndef TRUE |
| 28 | #define TRUE 1 /* Boolean true value. */ |
| 29 | #endif |
| 30 | |
| 31 | #ifndef FALSE |
| 32 | #define FALSE 0 /* Boolean false value. */ |
| 33 | #endif |
| 34 | |
| 35 | #define gpio_log(...) if(gpio_debug)printf(__VA_ARGS__) |
| 36 | #define HWMAP_DEVICE "/dev/hwmap" |
| 37 | #define PAGE_OFFS_BITS(pgsz) ((unsigned int)(pgsz)-1) |
| 38 | #define PAGE_MASK_BITS(pgsz) (~PAGE_OFFS_BITS(pgsz)) |
| 39 | #define STR_MAX_LEN 220 |
| 40 | typedef enum { |
| 41 | MBTK_ADC0 = 0, /* ADC 0 */ |
| 42 | MBTK_ADC1 /* ADC 1 */ |
| 43 | } mbtk_adc_enum; |
| 44 | |
| 45 | static int gpio_debug = 0; |
| 46 | #define DEBUG_GPIO_TEST 1 |
| 47 | |
| 48 | /**/ |
| 49 | #define GPIO_MAX_CURRENT (7<<10) //设置GPIO最大输出电流 |
| 50 | #define GPIO_STRONG_PULLUP (1<<3) //设置GPIO强上拉 |
| 51 | #define GPIO_PULLUP_ENABLE ((1<<15)|(1<<14)) //GPIO上拉 |
| 52 | #define GPIO_PULLDOWN_ENABLE ((1<<15)|1<<13) //GPIO下拉 |
| 53 | |
| 54 | #define MBTK_GPIO_OUTPUT 1 |
| 55 | #define MBTK_GPIO_INPUT 0 |
| 56 | |
| 57 | #if (defined(MBTK_PROJECT_L508_X6) || defined(MBTK_PROJECT_T108)) |
| 58 | struct gpio_register_function gpio_func_register[128] = { |
| 59 | {GPIO_FUNC_GPIO_00, 0}, |
| 60 | {GPIO_FUNC_GPIO_01, 0}, |
| 61 | {GPIO_FUNC_GPIO_02, 0}, |
| 62 | {GPIO_FUNC_GPIO_03, 0}, |
| 63 | {GPIO_FUNC_GPIO_04, 0}, |
| 64 | {GPIO_FUNC_GPIO_05, 0}, |
| 65 | {GPIO_FUNC_GPIO_06, 0}, |
| 66 | {GPIO_FUNC_GPIO_07, 0}, |
| 67 | {GPIO_FUNC_GPIO_08, 0}, |
| 68 | {GPIO_FUNC_GPIO_09, 0}, |
| 69 | {GPIO_FUNC_GPIO_10, 0}, |
| 70 | {GPIO_FUNC_GPIO_11, 0}, |
| 71 | {GPIO_FUNC_GPIO_12, 0}, |
| 72 | {GPIO_FUNC_GPIO_13, 0}, |
| 73 | {GPIO_FUNC_GPIO_14, 0}, |
| 74 | {GPIO_FUNC_GPIO_15, 0}, |
| 75 | {GPIO_FUNC_GPIO_16, 0}, |
| 76 | {GPIO_FUNC_GPIO_17, 0}, |
| 77 | {GPIO_FUNC_GPIO_18, 0}, |
| 78 | {GPIO_FUNC_GPIO_19, 0}, |
| 79 | {GPIO_FUNC_GPIO_20, 0}, |
| 80 | {GPIO_FUNC_GPIO_21, 0}, |
| 81 | {GPIO_FUNC_GPIO_22, 0}, |
| 82 | {GPIO_FUNC_GPIO_23, 0}, |
| 83 | {GPIO_FUNC_GPIO_24, 0}, |
| 84 | {GPIO_FUNC_GPIO_25, 0}, |
| 85 | {GPIO_FUNC_GPIO_26, 0}, |
| 86 | {GPIO_FUNC_GPIO_27, 0}, |
| 87 | {GPIO_FUNC_GPIO_28, 0}, |
| 88 | {GPIO_FUNC_GPIO_29, 0}, |
| 89 | {GPIO_FUNC_GPIO_30, 0}, |
| 90 | {GPIO_FUNC_GPIO_31, 0}, |
| 91 | {GPIO_FUNC_GPIO_32, 0}, |
| 92 | {GPIO_FUNC_GPIO_33, 0}, |
| 93 | {GPIO_FUNC_GPIO_34, 0}, |
| 94 | {GPIO_FUNC_GPIO_35, 0}, |
| 95 | {GPIO_FUNC_GPIO_36, 0}, |
| 96 | {GPIO_FUNC_GPIO_37, 0}, // GPIO_37 |
| 97 | {GPIO_FUNC_GPIO_38, 0}, // GPIO_38 |
| 98 | {GPIO_FUNC_GPIO_39, 0}, // GPIO_39 |
| 99 | {GPIO_FUNC_GPIO_40, 0}, // GPIO_40 |
| 100 | {GPIO_FUNC_GPIO_41, 0}, //GPIO_41 |
| 101 | {GPIO_FUNC_GPIO_42, 0}, //GPIO_42 |
| 102 | {GPIO_FUNC_GPIO_43, 0}, //GPIO_43 |
| 103 | {GPIO_FUNC_GPIO_44,0}, //GPIO_44 |
| 104 | {GPIO_FUNC_GPIO_45,0}, //GPIO_45 |
| 105 | {GPIO_FUNC_GPIO_46,0}, //GPIO_46 |
| 106 | {GPIO_FUNC_GPIO_47,0}, //GPIO_47 |
| 107 | {GPIO_FUNC_SDIO_DAT3, 1}, //GPIO_48 |
| 108 | {GPIO_FUNC_GPIO_49, 0}, |
| 109 | {GPIO_FUNC_GPIO_50, 0}, |
| 110 | {GPIO_FUNC_GPIO_51, 0}, |
| 111 | {GPIO_FUNC_GPIO_52, 0}, |
| 112 | {GPIO_FUNC_GPIO_53, 0}, |
| 113 | {GPIO_FUNC_GPIO_54, 0}, |
| 114 | {GPIO_FUNC_SDIO_DAT2, 1}, //GPIO_55 |
| 115 | {GPIO_FUNC_SDIO_DAT1, 1}, //GPIO_56 |
| 116 | {GPIO_FUNC_SDIO_DAT0, 1}, //GPIO_57 |
| 117 | {GPIO_FUNC_SDIO_CMD, 1}, //GPIO_58 |
| 118 | {GPIO_FUNC_SDIO_CLK, 1}, //GPIO_59 |
| 119 | {GPIO_FUNC_GPIO_60, 0}, |
| 120 | {0,0},{0,0},{0,0},{0,0}, |
| 121 | {0,0},{0,0}, |
| 122 | {GPIO_FUNC_DVL_0, 1},//GPIO_67 |
| 123 | {GPIO_FUNC_DVL_1, 1},//GPIO_68 |
| 124 | {GPIO_FUNC_GPIO_69, 0}, |
| 125 | {GPIO_FUNC_GPIO_70, 0}, |
| 126 | {GPIO_FUNC_QSPI_DAT3, 1}, //GPIO_71 |
| 127 | {GPIO_FUNC_QSPI_DAT2, 1}, //GPIO_72 |
| 128 | {GPIO_FUNC_QSPI_DAT1, 1}, //GPIO_73 |
| 129 | {GPIO_FUNC_QSPI_DAT0, 1}, //GPIO_74 |
| 130 | {GPIO_FUNC_QSPI_CLK, 1}, //GPIO_75 |
| 131 | {GPIO_FUNC_QSPI_CS1, 1}, //GPIO_76 |
| 132 | {GPIO_FUNC_GPIO_77, 0}, |
| 133 | {GPIO_FUNC_GPIO_78, 0}, |
| 134 | {GPIO_FUNC_GPIO_79, 0}, |
| 135 | {GPIO_FUNC_GPIO_80, 0}, |
| 136 | {GPIO_FUNC_USIM_UCLK, 1},//GPIO_81 |
| 137 | {GPIO_FUNC_USIM_UIO, 1},//GPIO_82 |
| 138 | {GPIO_FUNC_USIM_URSTn, 1},//GPIO_83 |
| 139 | |
| 140 | {GPIO_FUNC_MMC1_DAT3,5}, //GPIO_84 |
| 141 | {GPIO_FUNC_MMC1_DAT2,5}, //GPIO_85 |
| 142 | {GPIO_FUNC_MMC1_DAT1,5}, //GPIO_86 |
| 143 | {GPIO_FUNC_MMC1_DAT0,5}, //GPIO_87 |
| 144 | {GPIO_FUNC_MMC1_CMD,5}, //GPIO_88 |
| 145 | {GPIO_FUNC_MMC1_CLK,5}, //GPIO_89 |
| 146 | {GPIO_FUNC_MMC1_CD,1}, //GPIO_90 |
| 147 | {0,0}, |
| 148 | {0,0},{0,0},{0,0},{0,0}, |
| 149 | {0,0},{0,0},{0,0}, |
| 150 | {GPIO_FUNC_USB_ID, 1},//GPIO_99 |
| 151 | {0,0},{0,0},{0,0},{0,0}, |
| 152 | {0,0},{0,0},{0,0},{0,0}, |
| 153 | {0,0},{0,0},{0,0},{0,0}, |
| 154 | {0,0},{0,0},{0,0},{0,0}, |
| 155 | {0,0}, |
| 156 | {GPIO_FUNC_PRI_TDI, 1}, //GPIO_117 |
| 157 | {GPIO_FUNC_PRI_TMS, 1}, //GPIO_118 |
| 158 | {GPIO_FUNC_PRI_TCK, 1}, //GPIO_119 |
| 159 | {GPIO_FUNC_PRI_TDO, 1}, //GPIO_120 |
| 160 | {GPIO_FUNC_QSPI_VMODE_GPIO, 1}, //GPIO_121 |
| 161 | {GPIO_FUNC_VBUS_DRV, 1}, //GPIO_122 |
| 162 | {GPIO_FUNC_CLK_REQ, 1}, //GPIO_123 |
| 163 | {0,0}, |
| 164 | {GPIO_FUNC_VCXO_REQ, 1}, //GPIO_125 |
| 165 | {0,0}, //GPIO_126 |
| 166 | {GPIO_FUNC_VCXO_OUT, 1}, //GPIO_127 |
| 167 | {0,0}, |
| 168 | }; |
| 169 | |
| 170 | #else |
| 171 | struct gpio_register_function gpio_func_register[128] = { |
| 172 | {GPIO_FUNC_GPIO_00, 0}, |
| 173 | {GPIO_FUNC_GPIO_01, 0}, |
| 174 | {GPIO_FUNC_GPIO_02, 0}, |
| 175 | {GPIO_FUNC_GPIO_03, 0}, |
| 176 | {GPIO_FUNC_GPIO_04, 0}, |
| 177 | {GPIO_FUNC_GPIO_05, 0}, |
| 178 | {GPIO_FUNC_GPIO_06, 0}, |
| 179 | {GPIO_FUNC_GPIO_07, 0}, |
| 180 | {GPIO_FUNC_GPIO_08, 0}, |
| 181 | {GPIO_FUNC_GPIO_09, 0}, |
| 182 | {GPIO_FUNC_GPIO_10, 0}, |
| 183 | {GPIO_FUNC_GPIO_11, 0}, |
| 184 | {GPIO_FUNC_GPIO_12, 0}, |
| 185 | {GPIO_FUNC_GPIO_13, 0}, |
| 186 | {GPIO_FUNC_GPIO_14, 0}, |
| 187 | {GPIO_FUNC_GPIO_15, 0}, |
| 188 | {GPIO_FUNC_GPIO_16, 0}, |
| 189 | {GPIO_FUNC_GPIO_17, 0}, |
| 190 | {GPIO_FUNC_GPIO_18, 0}, |
| 191 | {GPIO_FUNC_GPIO_19, 0}, |
| 192 | {GPIO_FUNC_GPIO_20, 0}, |
| 193 | {GPIO_FUNC_GPIO_21, 0}, |
| 194 | {GPIO_FUNC_GPIO_22, 0}, |
| 195 | {GPIO_FUNC_GPIO_23, 0}, |
| 196 | {GPIO_FUNC_GPIO_24, 0}, |
| 197 | {GPIO_FUNC_GPIO_25, 0}, |
| 198 | {GPIO_FUNC_GPIO_26, 0}, |
| 199 | {GPIO_FUNC_GPIO_27, 0}, |
| 200 | {GPIO_FUNC_GPIO_28, 0}, |
| 201 | {GPIO_FUNC_GPIO_29, 0}, |
| 202 | {GPIO_FUNC_GPIO_30, 0}, |
| 203 | {GPIO_FUNC_GPIO_31, 0}, |
| 204 | {GPIO_FUNC_GPIO_32, 0}, |
| 205 | {GPIO_FUNC_GPIO_33, 0}, |
| 206 | {GPIO_FUNC_GPIO_34, 0}, |
| 207 | {GPIO_FUNC_GPIO_35, 0}, |
| 208 | {GPIO_FUNC_GPIO_36, 0}, |
| 209 | {GPIO_FUNC_MMC1_DAT3, 5}, // GPIO_37 |
| 210 | {GPIO_FUNC_MMC1_DAT2, 5}, // GPIO_38 |
| 211 | {GPIO_FUNC_MMC1_DAT1, 5}, // GPIO_39 |
| 212 | {GPIO_FUNC_MMC1_DAT0, 5}, // GPIO_40 |
| 213 | {GPIO_FUNC_MMC1_CMD, 5}, //GPIO_41 |
| 214 | {GPIO_FUNC_MMC1_CLK, 5}, //GPIO_42 |
| 215 | {GPIO_FUNC_MMC1_CD , 1}, //GPIO_43 |
| 216 | {0,0},{0,0},{0,0},{0,0}, |
| 217 | {GPIO_FUNC_SDIO_DAT3, 1}, //GPIO_48 |
| 218 | {GPIO_FUNC_GPIO_49, 0}, |
| 219 | {GPIO_FUNC_GPIO_50, 0}, |
| 220 | {GPIO_FUNC_GPIO_51, 0}, |
| 221 | {GPIO_FUNC_GPIO_52, 0}, |
| 222 | {GPIO_FUNC_GPIO_53, 0}, |
| 223 | {GPIO_FUNC_GPIO_54, 0}, |
| 224 | {GPIO_FUNC_SDIO_DAT2, 1}, //GPIO_55 |
| 225 | {GPIO_FUNC_SDIO_DAT1, 1}, //GPIO_56 |
| 226 | {GPIO_FUNC_SDIO_DAT0, 1}, //GPIO_57 |
| 227 | {GPIO_FUNC_SDIO_CMD, 1}, //GPIO_58 |
| 228 | {GPIO_FUNC_SDIO_CLK, 1}, //GPIO_59 |
| 229 | {GPIO_FUNC_GPIO_60, 0}, |
| 230 | {0,0},{0,0},{0,0},{0,0}, |
| 231 | {0,0},{0,0}, |
| 232 | {GPIO_FUNC_DVL_0, 1},//GPIO_67 |
| 233 | {GPIO_FUNC_DVL_1, 1},//GPIO_68 |
| 234 | {GPIO_FUNC_GPIO_69, 0}, |
| 235 | {GPIO_FUNC_GPIO_70, 0}, |
| 236 | {GPIO_FUNC_QSPI_DAT3, 1}, //GPIO_71 |
| 237 | {GPIO_FUNC_QSPI_DAT2, 1}, //GPIO_72 |
| 238 | {GPIO_FUNC_QSPI_DAT1, 1}, //GPIO_73 |
| 239 | {GPIO_FUNC_QSPI_DAT0, 1}, //GPIO_74 |
| 240 | {GPIO_FUNC_QSPI_CLK, 1}, //GPIO_75 |
| 241 | {GPIO_FUNC_QSPI_CS1, 1}, //GPIO_76 |
| 242 | {GPIO_FUNC_GPIO_77, 0}, |
| 243 | {GPIO_FUNC_GPIO_78, 0}, |
| 244 | {GPIO_FUNC_GPIO_79, 0}, |
| 245 | {GPIO_FUNC_GPIO_80, 0}, |
| 246 | {GPIO_FUNC_USIM_UCLK, 1},//GPIO_81 |
| 247 | {GPIO_FUNC_USIM_UIO, 1},//GPIO_82 |
| 248 | {GPIO_FUNC_USIM_URSTn, 1},//GPIO_83 |
| 249 | {0,0},{0,0},{0,0},{0,0}, |
| 250 | {0,0},{0,0},{0,0},{0,0}, |
| 251 | {0,0},{0,0},{0,0},{0,0}, |
| 252 | {0,0},{0,0},{0,0}, |
| 253 | {GPIO_FUNC_USB_ID, 1},//GPIO_99 |
| 254 | {0,0},{0,0},{0,0},{0,0}, |
| 255 | {0,0},{0,0},{0,0},{0,0}, |
| 256 | {0,0},{0,0},{0,0},{0,0}, |
| 257 | {0,0},{0,0},{0,0},{0,0}, |
| 258 | {0,0}, |
| 259 | {GPIO_FUNC_PRI_TDI, 1}, //GPIO_117 |
| 260 | {GPIO_FUNC_PRI_TMS, 1}, //GPIO_118 |
| 261 | {GPIO_FUNC_PRI_TCK, 1}, //GPIO_119 |
| 262 | {GPIO_FUNC_PRI_TDO, 1}, //GPIO_120 |
| 263 | {GPIO_FUNC_QSPI_VMODE_GPIO, 1}, //GPIO_121 |
| 264 | {GPIO_FUNC_VBUS_DRV, 1}, //GPIO_122 |
| 265 | {GPIO_FUNC_CLK_REQ, 1}, //GPIO_123 |
| 266 | {0,0}, |
| 267 | {GPIO_FUNC_VCXO_REQ, 1}, //GPIO_125 |
| 268 | {GPIO_FUNC_VCXO_OUT, 1}, //GPIO_126 |
| 269 | {0,0}, |
| 270 | }; |
| 271 | |
| 272 | #endif |
| 273 | |
| 274 | static int mbtk_gpio_adc(channel) |
| 275 | { |
| 276 | int ret = 0; |
| 277 | |
| 278 | ret = mbtk_adc_get(channel); |
| 279 | #if DEBUG_GPIO_TEST |
| 280 | printf("ADC_%d_value =%d\n", channel, ret); |
| 281 | #endif |
| 282 | if(ret >= 500 ){ //TODO: 各项目高电平标准? |
| 283 | ret = 1; |
| 284 | } |
| 285 | else if (ret>=0 && ret<=480){ |
| 286 | ret = 0; |
| 287 | } |
| 288 | else{ |
| 289 | ret = -1; |
| 290 | } |
| 291 | return ret; |
| 292 | } |
| 293 | |
| 294 | |
| 295 | static int hwacc_register(int rw, unsigned int addr, unsigned int *data) |
| 296 | { |
| 297 | int fid; |
| 298 | unsigned int pagesize, len, len_aligned; |
| 299 | unsigned int addr_aligned; |
| 300 | volatile unsigned int *pa; |
| 301 | void *vpa; |
| 302 | |
| 303 | len = pagesize = sysconf(_SC_PAGESIZE); |
| 304 | if((fid = open(HWMAP_DEVICE, O_RDWR)) < 0) |
| 305 | { |
| 306 | printf("Failed to open %s\n", HWMAP_DEVICE); |
| 307 | exit(-1); |
| 308 | } |
| 309 | |
| 310 | // Align the length so the mapped area is page-aligned and contains the requested area |
| 311 | addr_aligned = addr & PAGE_MASK_BITS(pagesize); |
| 312 | len_aligned =((addr + len - addr_aligned) + pagesize - 1) & PAGE_MASK_BITS(pagesize); |
| 313 | |
| 314 | /* Notes on flags: MAP_PRIVATE results in copy on write; MAP_SHARED allows normal write */ |
| 315 | /* MAP_SHARED required O_RDWR in open above, otherwise mmap fails with errno=EACCES */ |
| 316 | /* Notes on prot: PROT_WRITE allows read and write; PROT_READ allows read only */ |
| 317 | /* Notes on off: an unsigned 32-bit value, should be aligned to page size according to mmap manpage */ |
| 318 | if((vpa = mmap(0, len_aligned, PROT_READ|PROT_WRITE, MAP_SHARED, fid, addr_aligned)) == MAP_FAILED) |
| 319 | { |
| 320 | printf("mmap failed (%d)\n", errno); |
| 321 | } |
| 322 | else |
| 323 | { |
| 324 | pa = (volatile unsigned int *)((unsigned char *)vpa + (addr & PAGE_OFFS_BITS(pagesize))); |
| 325 | if(rw == 0) |
| 326 | { |
| 327 | *data = *pa; |
| 328 | gpio_log("Value read from 0x%.8x via MVA=0x%p is 0x%.8x\n", addr, pa, *data); |
| 329 | } |
| 330 | else if(rw == 1) |
| 331 | { |
| 332 | *pa = *data; |
| 333 | gpio_log("Value %.8x written to 0x%.8x via MVA=0x%p\n", *data, addr, pa); |
| 334 | #if defined(HWACC_DEBUG) |
| 335 | { |
| 336 | unsigned int val; |
| 337 | val = *pa; |
| 338 | printf("Value read from 0x%.8x via MVA=0x%p is 0x%.8x\n", addr, pa, val); |
| 339 | } |
| 340 | #endif |
| 341 | } |
| 342 | munmap(vpa, len); |
| 343 | } |
| 344 | |
| 345 | close(fid); |
| 346 | return 0; |
| 347 | } |
| 348 | /* |
| 349 | 设置GPIO 模式:第一步读GPIO22默认function |
| 350 | root@OpenWrt:/# hwacc r 0xd401e134 |
| 351 | Option = r Addr = d401e134 |
| 352 | Value read from 0xd401e134 via MVA=0x0xb6fc3134 is 0x0000d040 //默认GPIO功能 |
| 353 | Bit0~bit2值对应上面表格各function,0代表GPIO功能 |
| 354 | */ |
| 355 | static int gpio_register_read(int reg) |
| 356 | { |
| 357 | int ret = -1; |
| 358 | #if 0 |
| 359 | FILE * fp; |
| 360 | // "/bin/hwacc r 0xd401e134"; |
| 361 | char command[36] = {0}; |
| 362 | char buffer[1024]; |
| 363 | int i = 0; |
| 364 | |
| 365 | sprintf(command, "/bin/hwacc r 0x%x", reg); |
| 366 | fp = popen(command, "r"); |
| 367 | while(1) |
| 368 | { |
| 369 | if( fgets (buffer, sizeof(buffer), fp)!=NULL ) { |
| 370 | buffer[strlen(buffer) - 1] = 0; |
| 371 | // gpio_log("out [%d]: %s\n", strlen(buffer), buffer); |
| 372 | }else{ |
| 373 | break; |
| 374 | } |
| 375 | i = strstr_n(buffer, "is"); |
| 376 | if(i) |
| 377 | { |
| 378 | ret = str_to_hex(&buffer[i + 2]); |
| 379 | gpio_log("read 0x%x value:%s, %x\n", reg, &buffer[i + 2], ret); |
| 380 | } |
| 381 | } |
| 382 | pclose(fp); |
| 383 | #else |
| 384 | #ifndef MBTK_PROJECT_PN1803 |
| 385 | usleep(50); |
| 386 | #endif |
| 387 | hwacc_register(0, reg, &ret); |
| 388 | #ifndef MBTK_PROJECT_PN1803 |
| 389 | usleep(50); |
| 390 | #endif |
| 391 | #endif |
| 392 | return ret; |
| 393 | } |
| 394 | /* |
| 395 | 设置输入输出状态,设置PDR寄存器GPIO22为output |
| 396 | root@OpenWrt:/# hwacc w 0xD401900c 0x00c03800 |
| 397 | Option = w Addr = d401900c Data=00c03800 |
| 398 | Value 00c03800 written to 0xd401900c via MVA=0x0xb6f9f00c |
| 399 | */ |
| 400 | static void gpio_register_write(int reg, int value) |
| 401 | { |
| 402 | #if 0 |
| 403 | FILE * fp; |
| 404 | // "/bin/hwacc w 0xD401900c 0x00c03800" |
| 405 | char command[36] = {0}; |
| 406 | char buffer[1024]; |
| 407 | |
| 408 | sprintf(command, "/bin/hwacc w 0x%x 0x%x", reg, value); |
| 409 | gpio_log("command: %s\n", command); |
| 410 | fp = popen(command, "r"); |
| 411 | while(1) |
| 412 | { |
| 413 | if( fgets (buffer, sizeof(buffer), fp)!=NULL ) { |
| 414 | gpio_log("%s\n", buffer); |
| 415 | }else{ |
| 416 | break; |
| 417 | } |
| 418 | } |
| 419 | pclose(fp); |
| 420 | |
| 421 | #else |
| 422 | #ifndef MBTK_PROJECT_PN1803 |
| 423 | usleep(50); |
| 424 | #endif |
| 425 | hwacc_register(1, reg, &value); |
| 426 | #ifndef MBTK_PROJECT_PN1803 |
| 427 | usleep(50); |
| 428 | #endif |
| 429 | #endif |
| 430 | } |
| 431 | /* |
| 432 | AF SEL<p>This field is used for alternate function selection for a pin. |
| 433 | It selects between the eight possible alternate functions for the pin. |
| 434 | Alternate function 0 is always the reset case. |
| 435 | |
| 436 | <p>0x0 = Alternate function 0 (primary function at reset) |
| 437 | <p>0x1 = Alternate function 1 |
| 438 | <p>0x2 = Alternate function 2 |
| 439 | <p>0x3 = Alternate function 3 |
| 440 | <p>0x4 = Alternate function 4 |
| 441 | <p>0x5 = Alternate function 5 |
| 442 | <p>0x6 = Alternate function 6 |
| 443 | <p>0x7 = Alternate function 7 |
| 444 | */ |
| 445 | static int gpio_register_set_func_0(int port) |
| 446 | { |
| 447 | int ret; |
| 448 | struct gpio_register_function *reg = NULL; |
| 449 | if(port > 128) |
| 450 | return -1; |
| 451 | reg = &gpio_func_register[port]; |
| 452 | if(0 == reg->reg) |
| 453 | return -1; |
| 454 | ret = gpio_register_read(reg->reg); |
| 455 | if((ret & 0x7) != reg->func_gpio) |
| 456 | { |
| 457 | //printf("Gpio set func [%d] [0x%x]!\n", reg->func_gpio, (ret & 0xfffffff8) | reg->func_gpio); |
| 458 | gpio_register_write(reg->reg, (ret & 0xfffffff8) | reg->func_gpio); |
| 459 | } |
| 460 | return 0; |
| 461 | } |
| 462 | /* |
| 463 | 设置GPIO 方向 |
| 464 | 读取输入输出状态,读PDR寄存器:0x0c |
| 465 | root@OpenWrt:/# hwacc r 0xD401900c |
| 466 | Option = r Addr = d401900c |
| 467 | Value read from 0xd401900c via MVA=0x0xb6f3900c is 0x00803800 //bit22为0,代表Input |
| 468 | */ |
| 469 | static void gpio_register_set_direction(int port, int dir) |
| 470 | { |
| 471 | int ret; |
| 472 | int reg = 0xD4019000; |
| 473 | |
| 474 | if(port > (32 - 1)) |
| 475 | reg = 0xD4019004; |
| 476 | if(port > (32 * 2 - 1)) |
| 477 | reg = 0xD4019008; |
| 478 | if(port > (32 * 3 - 1)) |
| 479 | reg = 0xD4019100; |
| 480 | |
| 481 | reg += 0x0c; |
| 482 | port = port % 0x20; |
| 483 | ret = gpio_register_read(reg); |
| 484 | //printf("[Direction] reg_value=%x\n", ret); |
| 485 | // 设置 输出 0 && 1 |
| 486 | if(!(ret & (0x1 << port)) && dir) |
| 487 | { |
| 488 | gpio_register_write(reg, ret | (0x1 << port)); //set the gpio bit |
| 489 | //printf("[Direction out] reg_value=%x\n", gpio_register_read(reg)); |
| 490 | } |
| 491 | // 设置 输入 1 && 0 |
| 492 | if((ret & (0x1 << port)) && !dir) |
| 493 | { |
| 494 | #if 1 |
| 495 | gpio_register_write(reg, ret & (~(0x1 << port))); //clear the gpio bit,mbtk_tanggaoyou |
| 496 | #else |
| 497 | gpio_register_write(reg, ret | !(0x1 << port)); //这是错误配置,实际没有任何作用,还是原来的值 |
| 498 | #endif |
| 499 | //printf("[Direction in] reg_value=%x\n", gpio_register_read(reg)); |
| 500 | } |
| 501 | } |
| 502 | /* |
| 503 | 设置GPIO 输出电平 |
| 504 | |
| 505 | 读取电平状态,先读PLR寄存器:0x00 |
| 506 | root@OpenWrt:/# hwacc r 0xD4019000 |
| 507 | Option = r Addr = d4019000 |
| 508 | Value read from 0xd4019000 via MVA=0x0xb6f1c000 is 0x81e82a30 |
| 509 | 对应下面具体BIT |
| 510 | 1000 0001 1110 1000 0010 1010 0011 0000 BIT22默认电平高 |
| 511 | |
| 512 | 设置输出高:设置PSR寄存器:0x18(只写寄存器) |
| 513 | root@OpenWrt:/# hwacc w 0xD4019018 0x400000 |
| 514 | Option = w Addr = d4019018 Data=00400000 |
| 515 | Value 00400000 written to 0xd4019018 via MVA=0x0xb6f56018 //bit22写1,输出高 |
| 516 | |
| 517 | 设置输出低:设置PCR寄存器:0x24 |
| 518 | root@OpenWrt:/# hwacc w 0xD4019024 0x400000 |
| 519 | Option = w Addr = d4019024 Data=00400000 |
| 520 | Value 00400000 written to 0xd4019024 via MVA=0x0xb6faa024 //Bit22写1,GPIO22输出低 |
| 521 | |
| 522 | */ |
| 523 | static void gpio_register_set_value(int port, int value) |
| 524 | { |
| 525 | int ret; |
| 526 | int reg = 0xD4019000; |
| 527 | |
| 528 | if(port > (32 - 1)) |
| 529 | reg = 0xD4019004; |
| 530 | if(port > (32 * 2 - 1)) |
| 531 | reg = 0xD4019008; |
| 532 | if(port > (32 * 3 - 1)) |
| 533 | reg = 0xD4019100; |
| 534 | |
| 535 | if(value) |
| 536 | { |
| 537 | reg += 0x18; |
| 538 | } |
| 539 | else |
| 540 | reg += 0x24; |
| 541 | |
| 542 | port = port % 0x20; |
| 543 | ret = gpio_register_read(reg); |
| 544 | //printf("[Value] reg_value=%x\n", gpio_register_read(0xD4019004)); |
| 545 | // 设置 高电平 0 && 1 |
| 546 | if(value) |
| 547 | { |
| 548 | gpio_register_write(reg, ret | (0x1 << port)); |
| 549 | //printf("[Value high] reg_value=%x\n", gpio_register_read(0xD4019004)); |
| 550 | return; |
| 551 | } |
| 552 | // 设置 低电平 1 && 0 |
| 553 | if(!(ret & (0x1 << port)) && !value) |
| 554 | { |
| 555 | gpio_register_write(reg, ret | (0x1 << port)); |
| 556 | //printf("[Value low] reg_value=%x\n", gpio_register_read(0xD4019004)); |
| 557 | } |
| 558 | } |
| 559 | /* |
| 560 | 读取电平状态,先读PLR寄存器:0x00 |
| 561 | root@OpenWrt:/# hwacc r 0xD4019000 |
| 562 | Option = r Addr = d4019000 |
| 563 | Value read from 0xd4019000 via MVA=0x0xb6f1c000 is 0x81e82a30 |
| 564 | 对应下面具体BIT |
| 565 | 1000 0001 1110 1000 0010 1010 0011 0000 BIT22默认电平高 |
| 566 | */ |
| 567 | static int gpio_register_get_value(int port) |
| 568 | { |
| 569 | int ret = -1; |
| 570 | int reg = 0xD4019000; |
| 571 | |
| 572 | if(port > (32 - 1)) |
| 573 | reg = 0xD4019004; |
| 574 | if(port > (32 * 2 - 1)) |
| 575 | reg = 0xD4019008; |
| 576 | if(port > (32 * 3 - 1)) |
| 577 | reg = 0xD4019100; |
| 578 | port = port % 0x20; |
| 579 | ret = gpio_register_read(reg); |
| 580 | if(ret & (0x1 << port)) |
| 581 | { |
| 582 | return 1; |
| 583 | } |
| 584 | return 0; |
| 585 | } |
| 586 | |
| 587 | void gpio_debug_set(int enable) |
| 588 | { |
| 589 | gpio_debug = enable; |
| 590 | } |
| 591 | |
| 592 | |
| 593 | |
| 594 | #if defined(MBTK_PROJECT_PN1803) |
| 595 | int gpio_register_test_out(int port, int value) |
| 596 | { |
| 597 | int ret; |
| 598 | int i; |
| 599 | int valueh = 0; |
| 600 | int valuel = 1; |
| 601 | |
| 602 | //printf("Gpio port [%d] test start!\n", port); |
| 603 | ret = gpio_register_set_func_0(port); //设功能为GPIO |
| 604 | if(ret){ |
| 605 | printf("gpio_port can't support!\n"); |
| 606 | return -1; |
| 607 | } |
| 608 | gpio_register_set_direction(port, 1); //设方向为输出 |
| 609 | ret = gpio_register_get_value(port); |
| 610 | //printf("gpio default value is : %d.\n", ret); |
| 611 | |
| 612 | |
| 613 | //[High] |
| 614 | for(i = 0; i <= 10; i++){ |
| 615 | gpio_register_set_value(port, 1); |
| 616 | usleep(50); |
| 617 | valueh = gpio_register_get_value(port); |
| 618 | //printf("set high? %d\n",valueh); |
| 619 | if(1 == valueh){ |
| 620 | break; |
| 621 | } |
| 622 | } |
| 623 | //usleep(10000); |
| 624 | for(i = 0; i <= 35; i++){ |
| 625 | ret = mbtk_gpio_adc(0); |
| 626 | usleep(3000); |
| 627 | if(1 == ret){ |
| 628 | break; |
| 629 | } |
| 630 | } |
| 631 | if(1 != ret){ |
| 632 | ret=-1; |
| 633 | goto exit; |
| 634 | } |
| 635 | printf("******gpio should is high: %d.******\n", ret); |
| 636 | |
| 637 | |
| 638 | //[Low] |
| 639 | usleep(200); |
| 640 | for(i = 0; i <= 10; i++){ |
| 641 | gpio_register_set_value(port, 0); //输出低 |
| 642 | usleep(50); |
| 643 | valuel = gpio_register_get_value(port); |
| 644 | //printf("set low? %d\n",valuel); |
| 645 | if(0 == valuel){ |
| 646 | break; |
| 647 | } |
| 648 | } |
| 649 | //usleep(10000); |
| 650 | for(i = 0; i <= 35; i++){ |
| 651 | ret = mbtk_gpio_adc(0); |
| 652 | usleep(3000); |
| 653 | if(0 == ret){ |
| 654 | break; |
| 655 | } |
| 656 | } |
| 657 | printf("******gpio should is low: %d.******\n", ret); |
| 658 | if(0 != ret){ |
| 659 | ret=-1; |
| 660 | goto exit; |
| 661 | } |
| 662 | |
| 663 | exit: |
| 664 | //gpio_register_set_direction(port, 0); //设方向为输入 |
| 665 | return ret; |
| 666 | } |
| 667 | |
| 668 | int mbtk_at_gpio(bool gnss_support, void* arg) |
| 669 | { |
| 670 | int test_gpio[] = { |
| 671 | 56, 55, 58, 57, 48, 59, 12, 20, 5, 43, 21, |
| 672 | 49, 50, 27, 28, 26, 25, 16, 17, 15, 126, 125, |
| 673 | 4, 0, 3, 18, 7, 6, 1, 2, /*54,*/ 19, 13, |
| 674 | 32, 31, 23, 24, 22, /*122,*/ 33, 35, 36, 34, 14, |
| 675 | 99,/* 53,*/ 37, 38, 39, 40, 41, 42}; |
| 676 | |
| 677 | int i, j, ret, total, n = 0; |
| 678 | int *fail_io = (int *)arg; |
| 679 | total = (sizeof(test_gpio)/sizeof(int)); |
| 680 | //printf("Start test gpio total: %d\n", total); |
| 681 | |
| 682 | /* [1 all gpio set to low] */ |
| 683 | for(j = 0; j < 6 ; j++){ |
| 684 | for(i = 0; i < total; i++){ |
| 685 | gpio_register_set_func_0(test_gpio[i]); |
| 686 | gpio_register_set_direction(test_gpio[i], 1); |
| 687 | gpio_register_set_value(test_gpio[i], 0); |
| 688 | } |
| 689 | //usleep(10000); |
| 690 | for(i = 0; i <= 35; i++){ |
| 691 | ret = mbtk_gpio_adc(0); |
| 692 | usleep(3000); |
| 693 | if(0 == ret){ |
| 694 | break; |
| 695 | } |
| 696 | } |
| 697 | printf("pre set ADC: %d, times: %d\n",ret, j); |
| 698 | if(0 == ret){ |
| 699 | break; |
| 700 | } |
| 701 | } |
| 702 | if(0 != ret){ |
| 703 | printf("Fail, please retest"); |
| 704 | return -1; |
| 705 | } |
| 706 | |
| 707 | |
| 708 | /* [2 GPIOTEST] */ |
| 709 | for(i = 0; i < total; i++){ |
| 710 | ret = gpio_register_test_out(test_gpio[i], 0); |
| 711 | if(-1 == ret){ |
| 712 | printf("!!!!!!!!!!!!gpio [%d] test failed!!!!!!!!!!!!\n", test_gpio[i]); |
| 713 | fail_io[n] = test_gpio[i]; |
| 714 | n++; |
| 715 | }else{ |
| 716 | //printf("############gpio [%d] test success############\n", test_gpio[i]); |
| 717 | } |
| 718 | } |
| 719 | mbtk_adc_close(); |
| 720 | return n; |
| 721 | } |
| 722 | |
| 723 | #elif defined(MBTK_PROJECT_L508) |
| 724 | |
| 725 | |
| 726 | #define READ_GPIO_NUM 22 |
| 727 | |
| 728 | #define DEBUG_GPIO_TEST 1 |
| 729 | |
| 730 | mbtk_gpio_test_pin_and_gpio *p_test_gpio =NULL; |
| 731 | mbtk_gpio_test_pin_and_gpio *p_gnss_gpio = NULL; |
| 732 | int test_gpio_group_total_pin = 0; |
| 733 | int gnss_gpio_group_total_pin = 0; |
| 734 | |
| 735 | int gpio_test_set_group_pin_to_low(mbtk_gpio_test_pin_and_gpio *p_pin_group_array, int total_num) |
| 736 | { |
| 737 | int i; |
| 738 | int gpio_num = 0; |
| 739 | int ret = 0; |
| 740 | |
| 741 | if(p_pin_group_array == NULL) |
| 742 | return -1; |
| 743 | |
| 744 | for(i=0; i < total_num; i++) |
| 745 | { |
| 746 | gpio_num = p_pin_group_array[i].gpio_num; |
| 747 | ret += gpio_register_set_func_0(gpio_num); |
| 748 | gpio_register_set_direction(gpio_num, MBTK_GPIO_OUTPUT); |
| 749 | gpio_register_set_value(gpio_num, 0); |
| 750 | } |
| 751 | return ret; |
| 752 | } |
| 753 | |
| 754 | |
| 755 | int gpio_test_init(void) |
| 756 | { |
| 757 | int i,j,ret; |
| 758 | int gpio_num = 0; |
| 759 | |
| 760 | |
| 761 | |
| 762 | |
| 763 | system("i2cset -y -f 2 0x31 0x12 0x46"); |
| 764 | system("echo 53 > /sys/class/gpio/export"); //gnss uart rx |
| 765 | system("echo out > /sys/class/gpio/gpio53/direction"); |
| 766 | system("echo 54 > /sys/class/gpio/export");//gnss uart tx |
| 767 | system("echo out > /sys/class/gpio/gpio54/direction"); |
| 768 | system("echo 22 > /sys/class/gpio/export");//check pin |
| 769 | |
| 770 | gpio_register_set_func_0(READ_GPIO_NUM); |
| 771 | gpio_register_set_direction(READ_GPIO_NUM, 1); //输出 |
| 772 | |
| 773 | usleep(500); |
| 774 | /* |
| 775 | GPIO22默认是上拉,如果改成GPIO输入模式,其PIN脚电压是高电平,必须改成下拉后GPIO22才处于低电平状态,否则测试PIN拉低失败 |
| 776 | */ |
| 777 | gpio_register_set_direction(READ_GPIO_NUM, MBTK_GPIO_INPUT); //设置输入模式 |
| 778 | gpio_register_write(GPIO_FUNC_GPIO_22,0xb040); //PULL DOWN |
| 779 | |
| 780 | |
| 781 | gpio_test_set_group_pin_to_low(p_gnss_gpio,gnss_gpio_group_total_pin); //set all gnss reserver pin to low |
| 782 | |
| 783 | |
| 784 | /* [1 all gpio set to low] */ |
| 785 | for(j = 0; j < 6 ; j++){ |
| 786 | gpio_test_set_group_pin_to_low(p_test_gpio,test_gpio_group_total_pin); |
| 787 | |
| 788 | for(i = 0; i <= 5; i++){ |
| 789 | ret = gpio_register_get_value(READ_GPIO_NUM); |
| 790 | if(0 == ret){ |
| 791 | break; |
| 792 | } |
| 793 | usleep(3000); |
| 794 | } |
| 795 | |
| 796 | if(0 == ret){ |
| 797 | break; |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | if(0 != ret){ |
| 802 | printf("[GPIOTEST]set all low Fail, please retest\n"); |
| 803 | return -1; |
| 804 | } |
| 805 | printf("[GPIOTEST]pre set SUCCESS\n"); |
| 806 | return 0; |
| 807 | } |
| 808 | |
| 809 | int gpio_test(void* arg,int index,mbtk_gpio_test_pin_and_gpio *p_pin_group_array,int total) |
| 810 | { |
| 811 | int ret,i; |
| 812 | int *fail_io = (int *)arg; |
| 813 | int failed_num = index; |
| 814 | int gpio_num = 0; |
| 815 | int pin_num = 0; |
| 816 | bool falied_flag = FALSE; |
| 817 | |
| 818 | for(i = 0; i < total; i++){ |
| 819 | gpio_num = p_pin_group_array[i].gpio_num; |
| 820 | pin_num = p_pin_group_array[i].pin_num; |
| 821 | falied_flag = FALSE; |
| 822 | |
| 823 | #if DEBUG_GPIO_TEST |
| 824 | ret = gpio_register_get_value(gpio_num); |
| 825 | printf("[GPIOTEST]pin_num%d default value= %d\n", pin_num, ret); |
| 826 | #endif |
| 827 | |
| 828 | //set high |
| 829 | gpio_register_set_value(gpio_num, 1); |
| 830 | |
| 831 | #if DEBUG_GPIO_TEST |
| 832 | ret = gpio_register_get_value(gpio_num); |
| 833 | printf("[GPIOTEST]pin_num%d set high= %d\n", pin_num, ret); |
| 834 | #endif |
| 835 | //get |
| 836 | ret = gpio_register_get_value(READ_GPIO_NUM); |
| 837 | if(1 != ret){ |
| 838 | printf("[GPIOTEST]pin%d test high failed\n", pin_num); |
| 839 | falied_flag = TRUE; |
| 840 | }else{ |
| 841 | printf("[GPIOTEST]pin[%d] test high success\n", pin_num); |
| 842 | } |
| 843 | |
| 844 | //set low |
| 845 | gpio_register_set_value(gpio_num, 0); |
| 846 | #if DEBUG_GPIO_TEST |
| 847 | ret = gpio_register_get_value(gpio_num); |
| 848 | printf("[GPIOTEST]pin_num%d set low= %d\n", pin_num, ret); |
| 849 | #endif |
| 850 | //get |
| 851 | ret = gpio_register_get_value(READ_GPIO_NUM); |
| 852 | if(0 != ret){ |
| 853 | printf("[GPIOTEST]pin_num%d test low failed\n", pin_num); |
| 854 | falied_flag = TRUE; |
| 855 | |
| 856 | }else{ |
| 857 | printf("[GPIOTEST]pin_num%d test low success\n", pin_num); |
| 858 | } |
| 859 | |
| 860 | if(falied_flag) |
| 861 | { |
| 862 | fail_io[failed_num] = p_pin_group_array[i].pin_num; |
| 863 | #if DEBUG_GPIO_TEST |
| 864 | printf("[GPIOTEST]NO.%d pin_num%d failed %d\n",i,pin_num, failed_num); |
| 865 | #endif |
| 866 | failed_num++; |
| 867 | } |
| 868 | } |
| 869 | return failed_num; |
| 870 | } |
| 871 | |
| 872 | |
| 873 | int mbtk_at_gpio(bool gnss_support,void* arg) |
| 874 | { |
| 875 | int n = 0; |
| 876 | mbtk_gpio_test_pin_and_gpio test_gpio[] = |
| 877 | { |
| 878 | //{GPIO , PIN} |
| 879 | {0,100}, //RMII_RX-DV |
| 880 | {1,101}, //RMII_RXD0 |
| 881 | {2,102},//RMII_RXD1 |
| 882 | {3,103},//RMII_CLK |
| 883 | {6,104},//RMII_TXD0 |
| 884 | {7,105},//RMII_TXD1 |
| 885 | {15,106},//RMII_TX_EN |
| 886 | {16,109},//RMII_MDC |
| 887 | {17,110},//RMII_MDIO |
| 888 | {18,107},//RMII_INT |
| 889 | {99,16},//USB_ID |
| 890 | {34,9}, //SPI0_CS |
| 891 | {36,8},//SPI0_TXD |
| 892 | {35,7},//SPI0_RXD |
| 893 | {33,6},//SPI0_CLK |
| 894 | {14,51}, //NET_LIGHT |
| 895 | {13,49}, //STATUS LED |
| 896 | {12,50},//WAKE_IN |
| 897 | {49,55}, //I2C SCL |
| 898 | {50,56}, //I2C SDA |
| 899 | {19,53}, //USIM_DET |
| 900 | {43,48}, //SD_DET |
| 901 | {118,52}, //WAKE OUT |
| 902 | {120,54}, //FLIGHT MODE |
| 903 | |
| 904 | |
| 905 | {20,45}, //NORMAL GPIO |
| 906 | {59,122}, //SDIO_CLK |
| 907 | {56,117}, //SDIO_DATA1 |
| 908 | {55,118},//SDIO_DATA2 |
| 909 | {58,119},//SDIO_CMD |
| 910 | {48,120},//SDIO_DATA3 |
| 911 | {57,121},//SDIO_DATA0 |
| 912 | {5,84}, //NORMAL GPIO |
| 913 | {4,30},//NORMAL GPIO |
| 914 | {21,28}, //NORMAL GPIO |
| 915 | {23,69}, //UART_RING |
| 916 | {24,70}, //UART_DCD |
| 917 | {27,73}, //PCM_OUT |
| 918 | {28,74}, //PCM_IN |
| 919 | {26,75}, //PCM_SYNC |
| 920 | {25,76}, //PCM_CLK |
| 921 | |
| 922 | {126,112},//NORMAL GPIO or pwm3 |
| 923 | {117,123}, //PWM |
| 924 | {125,116}, //CLK_REQ |
| 925 | |
| 926 | //{54,114}, //debug uart2, no need be tested |
| 927 | //{53,115}, //debug uart2, no need be tested |
| 928 | |
| 929 | }; |
| 930 | |
| 931 | mbtk_gpio_test_pin_and_gpio GNSS_test_gpio[] = { |
| 932 | {54,114}, //GPS UTXD, UART1_TXD,L508LAN+L508CN(D)+L508EN+L508LEN+L508TLCN NOT CONNECTED |
| 933 | {53,115}, //GPS URXD,UART1-RXD,L508LAN+L508CN(D)+L508EN+L508LEN+L508TLCN NOT CONNECTED |
| 934 | {32,66}, //PIN66,host wake GPS, RTS, L508TLCN_V2+L508LEN_V2+L508EN_V2 NOT CONNECTED |
| 935 | {31,67}, //PIN67,GPS wake Host,CTS, L508TLCN_V2+L508LEN_V2+L508EN_V2 NOT CONNECTED |
| 936 | {123,42},//GPS_EN, L508TLCN_V2+L508LEN_V2+L508EN_V2 NOT CONNECTED |
| 937 | {122,35}, //32K OUT, L508TLCN_V2+L508LEN_V2+L508EN_V2 not connected |
| 938 | }; |
| 939 | p_gnss_gpio = GNSS_test_gpio; |
| 940 | gnss_gpio_group_total_pin = (sizeof(GNSS_test_gpio)/sizeof(GNSS_test_gpio[0])); |
| 941 | |
| 942 | p_test_gpio = test_gpio; |
| 943 | test_gpio_group_total_pin = (sizeof(test_gpio)/sizeof(test_gpio[0])); |
| 944 | |
| 945 | if(!gnss_support) |
| 946 | n = test_gpio_group_total_pin+gnss_gpio_group_total_pin; |
| 947 | else |
| 948 | n = test_gpio_group_total_pin; |
| 949 | |
| 950 | printf("[init] L508 XX GPIOTEST v1.3 total pin=%d\n",n); |
| 951 | |
| 952 | n = gpio_test_init(); |
| 953 | if(-1 == n) |
| 954 | { |
| 955 | goto gpiotest_finished; |
| 956 | } |
| 957 | n = 0; |
| 958 | |
| 959 | n = gpio_test(arg,0,p_test_gpio,test_gpio_group_total_pin); |
| 960 | |
| 961 | //if the module has gnss chip, don't test the gnss's pins |
| 962 | if(!gnss_support) |
| 963 | { |
| 964 | n = gpio_test(arg,n,p_gnss_gpio,gnss_gpio_group_total_pin); |
| 965 | } |
| 966 | |
| 967 | gpiotest_finished: |
| 968 | system("echo 53 > /sys/class/gpio/unexport"); //unexport gnss uart rx |
| 969 | system("echo 54 > /sys/class/gpio/unexport");//unexportgnss uart tx |
| 970 | system("echo 22 > /sys/class/gpio/unexport");//unexportcheck pin |
| 971 | |
| 972 | printf("\n[GPIOTEST] Finished %d!!\n\n",n); |
| 973 | return n; |
| 974 | } |
| 975 | |
| 976 | |
| 977 | |
| 978 | #elif defined(MBTK_PROJECT_L509) |
| 979 | //测低 |
| 980 | static uint16 mbtk_gpio_test_all_low(mbtk_gpio_paired_info_struct *pin_array, uint16 MAX_pin_num) |
| 981 | { |
| 982 | uint16 index = 0; |
| 983 | uint16 OUT_pin, Read_pin; |
| 984 | uint32 read_high_value; |
| 985 | uint32 read_low_value; |
| 986 | uint16 fail_num = 0; |
| 987 | //int res; |
| 988 | |
| 989 | printf("[GPIOTEST][run test all pin low]\n"); |
| 990 | |
| 991 | for(index = 0; index < MAX_pin_num; index++){ |
| 992 | OUT_pin = pin_array[index].output_gpio; |
| 993 | Read_pin = pin_array[index].input_gpio; |
| 994 | |
| 995 | //输出低 |
| 996 | gpio_register_set_direction(OUT_pin, 1); |
| 997 | gpio_register_set_value(OUT_pin, 0); |
| 998 | |
| 999 | //输入脚设为输入 |
| 1000 | gpio_register_set_direction(Read_pin,0); |
| 1001 | } |
| 1002 | |
| 1003 | for(index = 0; index < MAX_pin_num; index++){ |
| 1004 | OUT_pin = pin_array[index].output_gpio; |
| 1005 | Read_pin = pin_array[index].input_gpio; |
| 1006 | read_low_value = gpio_register_get_value(Read_pin); |
| 1007 | |
| 1008 | //结果检测 |
| 1009 | if(read_low_value != 0){ |
| 1010 | printf("[GPIOTEST][!Low Failed!]: GPIO%d PIN%d\n", Read_pin, pin_array[index].input_pin); |
| 1011 | pin_array[index].mbtk_gpio_test_result = 1; |
| 1012 | fail_num ++; |
| 1013 | } |
| 1014 | #if DEBUG_GPIO_TEST |
| 1015 | else{ |
| 1016 | printf("[GPIOTEST][-Low Success-]: GPIO%d \n", Read_pin); |
| 1017 | } |
| 1018 | #endif |
| 1019 | } |
| 1020 | return fail_num; |
| 1021 | } |
| 1022 | |
| 1023 | |
| 1024 | //测高 |
| 1025 | static uint16 mbtk_gpio_test_pin_high(mbtk_gpio_paired_info_struct *pin_array, uint16 MAX_pin_num) |
| 1026 | { |
| 1027 | uint16 index = 0; |
| 1028 | uint16 OUT_pin, Read_pin; |
| 1029 | uint32 read_high_value; |
| 1030 | uint32 read_low_value; |
| 1031 | uint16 fail_num = 0; |
| 1032 | int i = 0; |
| 1033 | |
| 1034 | printf("[GPIOTEST][run test pin high]\n"); |
| 1035 | |
| 1036 | for(index = 0; index < MAX_pin_num; index++){ |
| 1037 | OUT_pin = pin_array[index].output_gpio; |
| 1038 | Read_pin = pin_array[index].input_gpio; |
| 1039 | |
| 1040 | //设高 |
| 1041 | gpio_register_set_direction(OUT_pin,1); |
| 1042 | gpio_register_set_direction(Read_pin,0); |
| 1043 | gpio_register_set_value(OUT_pin, 1); |
| 1044 | usleep(10000); |
| 1045 | read_high_value = gpio_register_get_value(Read_pin); |
| 1046 | #if DEBUG_GPIO_TEST |
| 1047 | printf("[GPIOTEST][test_high]: PIN%d: get value =%d \n", pin_array[index].input_pin, read_high_value); |
| 1048 | #endif |
| 1049 | |
| 1050 | //设高后重新设低 |
| 1051 | usleep(10000); |
| 1052 | gpio_register_set_value(OUT_pin, 0); |
| 1053 | usleep(10000); |
| 1054 | for(i = 0; i < 10; i++){ |
| 1055 | read_low_value = gpio_register_get_value(Read_pin); |
| 1056 | if(0 == read_low_value){ |
| 1057 | break; |
| 1058 | } |
| 1059 | usleep(20000); |
| 1060 | } |
| 1061 | #if DEBUG_GPIO_TEST |
| 1062 | printf("[GPIOTEST][test_low]: PIN%d: get value =%d \n", pin_array[index].input_pin, read_low_value); |
| 1063 | #endif |
| 1064 | if(read_high_value != 1 || read_low_value != 0){ |
| 1065 | printf("[GPIOTEST][!High Failed!]: Gpio%d PIN%d\n", Read_pin,pin_array[index].input_pin); |
| 1066 | pin_array[index].mbtk_gpio_test_result = 2; |
| 1067 | fail_num ++; |
| 1068 | } |
| 1069 | #if DEBUG_GPIO_TEST |
| 1070 | else{ |
| 1071 | printf("[GPIOTEST][-High Success-]: Gpio%d \n", Read_pin); |
| 1072 | } |
| 1073 | #endif |
| 1074 | } |
| 1075 | return fail_num; |
| 1076 | } |
| 1077 | |
| 1078 | |
| 1079 | static void gpio_test_init_test_gpio_mode(mbtk_gpio_paired_info_struct pin_array[], int MAX_pin_num) |
| 1080 | { |
| 1081 | int index = 0; |
| 1082 | int OUT_pin, Read_pin; |
| 1083 | |
| 1084 | printf("[GPIOTEST] L509 GPIOTEST v2.2 --init\n"); |
| 1085 | |
| 1086 | gpio_register_set_func_0(125); |
| 1087 | gpio_register_set_direction(125, 1); |
| 1088 | gpio_register_set_value(125, 1); //RS2299开关的使能脚 |
| 1089 | |
| 1090 | system("i2cset -y -f 2 0x31 0x12 0x46"); //使能0x12地址的VLDO, 某组GPIO的供电 |
| 1091 | |
| 1092 | gpio_register_write(GPIO_FUNC_GPIO_53, 0xb040); //GPIO53 DTR set PULL DOWN |
| 1093 | |
| 1094 | for(index = 0; index < MAX_pin_num; index++){ |
| 1095 | OUT_pin = pin_array[index].output_gpio; |
| 1096 | Read_pin = pin_array[index].input_gpio; |
| 1097 | pin_array[index].mbtk_gpio_test_result = 0; //init as passed |
| 1098 | gpio_register_set_func_0(OUT_pin); |
| 1099 | gpio_register_set_func_0(Read_pin); |
| 1100 | gpio_register_set_value(OUT_pin, 0); |
| 1101 | } |
| 1102 | |
| 1103 | #if DEBUG_GPIO_TEST |
| 1104 | printf("[GPIOTEST]gpio_test_init_test_gpio_mode FINISH\n"); |
| 1105 | #endif |
| 1106 | |
| 1107 | } |
| 1108 | |
| 1109 | |
| 1110 | int mbtk_at_gpio(bool gnss_support, void* arg) |
| 1111 | { |
| 1112 | int i, num; |
| 1113 | int *fail_io = (int *)arg; |
| 1114 | /*OPEN SWITCH */ |
| 1115 | uint16 test_fail_count = 0; |
| 1116 | uint16 test_MAX_pin_num = 0; |
| 1117 | char buf[STR_MAX_LEN]; |
| 1118 | //uint16 str_len = 0; |
| 1119 | uint16 temp_len =0; |
| 1120 | uint16 Out_pin; |
| 1121 | uint16 in_pin; |
| 1122 | //uint16 fail_print_num = 0; |
| 1123 | |
| 1124 | mbtk_gpio_paired_info_struct test_pin_array[] ={ |
| 1125 | //output_pin, output_gpio, input_gpio, input_pin, test_result |
| 1126 | {122, 16, 17, 121, 0}, /* RGMII/RMII_MD_CLK <---SW RS2299---> RGMII/RMII_MD_IO */ |
| 1127 | |
| 1128 | {78, 7, 2, 73, 0}, /* RGMII/RMII_TX_1 <---SW RS2299---> RGMII/RMII_RXD1 */ |
| 1129 | {77, 6, 1, 76, 0}, /* RGMII/RMII_TXD0 <---SW RS2299---> RGMII/RMII_RXD0 */ |
| 1130 | {81, 15, 3, 75, 0}, /* RGMII/RMII_TX_EN <---SW RS2299---> RGMII/RMII_CLK */ |
| 1131 | {74, 0, 18, 120, 0}, /* RGMII/RMII_RX_DV <---SW RS2299---> RGMII/RMII_INT */ |
| 1132 | |
| 1133 | {1, 117, 120, 2, 0}, /* WAKEUP_IN <---SW RS2299---> AP_READY */ |
| 1134 | {4, 118, 19, 13, 0}, /* FLIGHTMODE <---SW RS2299---> USIM_CD */ |
| 1135 | {5, 123, 126, 6, 0}, /* NET_MODE <---SW RS2299---> NET_STATUS */ |
| 1136 | {23, 43, 23, 62, 0}, /* MMC1_CD <---SW RS2299---> UART_RI */ |
| 1137 | |
| 1138 | {79, 4, 5, 82, 0}, /* RGMII_RX_2 <---SW RS2299---> RGMII_RX_3 */ |
| 1139 | {80, 13, 14, 84, 0}, /* RGMII_TX_2 <---SW RS2299---> RGMII_TX_3 */ |
| 1140 | {129, 48, 55, 130, 0}, /* WLAN_DAT3 <---SW RS2299---> WLAN_DAT2 */ |
| 1141 | {131, 56, 57, 132, 0}, /* WLAN_DAT1 <---SW RS2299---> WLAN_DAT0 */ |
| 1142 | |
| 1143 | {24, 28, 27, 25, 0}, /* PCM_IN <---SW RS2299---> PCM_OUT */ |
| 1144 | {26, 26, 25, 27, 0}, /* PCM_SYNC <---SW RS2299---> PCM_CLK */ |
| 1145 | {37, 34, 33, 40, 0}, /* SPI_CS <---SW RS2299---> SPI_CLK */ |
| 1146 | {38, 36, 35, 39, 0}, /* SPI_DOUT <---SW RS2299---> SPI_DIN */ |
| 1147 | |
| 1148 | {133, 59, 58, 134, 0}, /* WLAN_CLK/PCIE_RSTN <---SW RS2299---> WLAN_CMD/PCIE_WK */ |
| 1149 | {135, 21, 99, 139, 0}, /* WLAN_WAKE_HOST <---SW RS2299---> USB_ID */ |
| 1150 | {119, 20, 22, 136, 0}, /* RGMII/RMII_RST_N <---SW RS2299---> WLAN_EN */ |
| 1151 | {83, 12, 122, 118, 0}, /* RGMII_CLK_TX <---SW RS2299---> WLAN_SLP_CLK */ |
| 1152 | |
| 1153 | {41, 49, 50, 42, 0}, /* I2C_SCL <---SW RS2299---> I2C_SDA */ |
| 1154 | {143, 10, 11, 144, 0}, /* GRFC1 <---SW RS2299---> GRFC2 */ |
| 1155 | {64, 32, 31, 65, 0}, /* UART_CTS <---SW RS2299---> UART_RTS */ |
| 1156 | {63, 54, 53, 66, 0}, /* UART_DCD <---SW RS2299---> UART_DTR */ |
| 1157 | }; |
| 1158 | |
| 1159 | |
| 1160 | /* [1]初始化待测GPIO */ |
| 1161 | test_MAX_pin_num = sizeof(test_pin_array) / sizeof(test_pin_array[0]); |
| 1162 | if(gnss_support){ //TODO: When the hardware does not have GNSS, do not test GPIO53, 54 |
| 1163 | //bad implement, need modify |
| 1164 | test_MAX_pin_num = test_MAX_pin_num - 1; |
| 1165 | } |
| 1166 | gpio_test_init_test_gpio_mode(test_pin_array, test_MAX_pin_num); |
| 1167 | |
| 1168 | |
| 1169 | /* [2]测试过程 */ |
| 1170 | test_fail_count = mbtk_gpio_test_all_low(test_pin_array, test_MAX_pin_num); |
| 1171 | |
| 1172 | if(!test_fail_count){ //set all pin to low success |
| 1173 | printf("[GPIOTEST]set all pin to low: success\n"); |
| 1174 | test_fail_count = mbtk_gpio_test_pin_high(&test_pin_array, test_MAX_pin_num); |
| 1175 | } |
| 1176 | else{ |
| 1177 | printf("[GPIOTEST]set all pin low: failed num=%d!!!\n", test_fail_count); |
| 1178 | } |
| 1179 | |
| 1180 | |
| 1181 | //memset(buf,0,STR_MAX_LEN); |
| 1182 | /* [3]测试结果检测与上报 */ |
| 1183 | if(test_fail_count ){ |
| 1184 | //printf( "GPIOTEST Fail %02d PINs:\n", test_fail_count*2); |
| 1185 | sprintf(buf, "GPIOTEST Fail %02d PINs:", test_fail_count * 2); |
| 1186 | temp_len = strlen(buf); |
| 1187 | |
| 1188 | num = 0; |
| 1189 | for(i = 0; i < test_MAX_pin_num; i++){ |
| 1190 | if(test_pin_array[i].mbtk_gpio_test_result){ |
| 1191 | Out_pin = test_pin_array[i].output_pin; |
| 1192 | in_pin = test_pin_array[i].input_pin; |
| 1193 | fail_io[num++] = Out_pin; |
| 1194 | fail_io[num++] = in_pin; |
| 1195 | } |
| 1196 | } |
| 1197 | } |
| 1198 | |
| 1199 | else{ |
| 1200 | printf(buf, "ALL GPIO TEST PASS\r\n"); |
| 1201 | } |
| 1202 | |
| 1203 | printf("\n[GPIOTEST] Finished !!\n\n"); |
| 1204 | return test_fail_count * 2; |
| 1205 | } |
| 1206 | |
| 1207 | |
| 1208 | #elif defined(MBTK_PROJECT_L508_X6) |
| 1209 | int gpio_register_test_out_0(int port) |
| 1210 | { |
| 1211 | int ret; |
| 1212 | int i; |
| 1213 | int valueh = 0; |
| 1214 | int valuel = 1; |
| 1215 | |
| 1216 | //printf("Gpio port [%d] test start!\n", port); |
| 1217 | ret = gpio_register_set_func_0(port); //设功能为GPIO |
| 1218 | if(ret){ |
| 1219 | printf("gpio_port can't support!\n"); |
| 1220 | return -1; |
| 1221 | } |
| 1222 | gpio_register_set_direction(port, 1); //设方向为输出 |
| 1223 | //ret = gpio_register_get_value(port); |
| 1224 | //printf("gpio default value is : %d.\n", ret); |
| 1225 | |
| 1226 | |
| 1227 | //[High] |
| 1228 | for(i = 0; i <= 10; i++){ |
| 1229 | gpio_register_set_value(port, 1); |
| 1230 | usleep(50); |
| 1231 | valueh = gpio_register_get_value(port); |
| 1232 | //printf("set high? %d\n",valueh); |
| 1233 | if(1 == valueh){ |
| 1234 | break; |
| 1235 | } |
| 1236 | } |
| 1237 | usleep(5000); |
| 1238 | for(i = 0; i <= 10; i++){ |
| 1239 | ret = mbtk_gpio_adc(0); |
| 1240 | usleep(3000); |
| 1241 | if(1 == ret){ |
| 1242 | break; |
| 1243 | } |
| 1244 | } |
| 1245 | //printf("******gpio should is high: %d.******\n", ret); |
| 1246 | if(1 != ret){ |
| 1247 | ret=-1; |
| 1248 | goto exit; |
| 1249 | } |
| 1250 | |
| 1251 | |
| 1252 | |
| 1253 | //[Low] |
| 1254 | usleep(200); |
| 1255 | for(i = 0; i <= 10; i++){ |
| 1256 | gpio_register_set_value(port, 0); //输出低 |
| 1257 | usleep(50); |
| 1258 | valuel = gpio_register_get_value(port); |
| 1259 | //printf("set low? %d\n",valuel); |
| 1260 | if(0 == valuel){ |
| 1261 | break; |
| 1262 | } |
| 1263 | } |
| 1264 | usleep(5000); |
| 1265 | for(i = 0; i <= 10; i++){ |
| 1266 | ret = mbtk_gpio_adc(0); |
| 1267 | usleep(3000); |
| 1268 | if(0 == ret){ |
| 1269 | break; |
| 1270 | } |
| 1271 | } |
| 1272 | printf("******gpio should is low: %d.******\n", ret); |
| 1273 | if(0 != ret){ |
| 1274 | ret=-1; |
| 1275 | goto exit; |
| 1276 | } |
| 1277 | |
| 1278 | exit: |
| 1279 | gpio_register_set_value(port, 0); |
| 1280 | //gpio_register_set_direction(port, 0); //设方向为输入 |
| 1281 | return ret; |
| 1282 | } |
| 1283 | |
| 1284 | int gpio_register_test_out_1(int port) |
| 1285 | { |
| 1286 | int ret; |
| 1287 | int i; |
| 1288 | int valueh = 0; |
| 1289 | int valuel = 1; |
| 1290 | |
| 1291 | //printf("Gpio port [%d] test start!\n", port); |
| 1292 | ret = gpio_register_set_func_0(port); //设功能为GPIO |
| 1293 | if(ret){ |
| 1294 | printf("gpio_port can't support!\n"); |
| 1295 | return -1; |
| 1296 | } |
| 1297 | gpio_register_set_direction(port, 1); //设方向为输出 |
| 1298 | //ret = gpio_register_get_value(port); |
| 1299 | //printf("gpio default value is : %d.\n", ret); |
| 1300 | |
| 1301 | |
| 1302 | //[High] |
| 1303 | for(i = 0; i <= 10; i++){ |
| 1304 | gpio_register_set_value(port, 1); |
| 1305 | usleep(50); |
| 1306 | valueh = gpio_register_get_value(port); |
| 1307 | //printf("set high? %d\n",valueh); |
| 1308 | if(1 == valueh){ |
| 1309 | break; |
| 1310 | } |
| 1311 | } |
| 1312 | usleep(5000); |
| 1313 | for(i = 0; i <= 10; i++){ |
| 1314 | ret = mbtk_gpio_adc(1); |
| 1315 | usleep(3000); |
| 1316 | if(1 == ret){ |
| 1317 | break; |
| 1318 | } |
| 1319 | } |
| 1320 | if(1 != ret){ |
| 1321 | ret=-1; |
| 1322 | goto exit; |
| 1323 | } |
| 1324 | //printf("******gpio should is high: %d.******\n", ret); |
| 1325 | |
| 1326 | |
| 1327 | //[Low] |
| 1328 | usleep(200); |
| 1329 | for(i = 0; i <= 10; i++){ |
| 1330 | gpio_register_set_value(port, 0); //输出低 |
| 1331 | usleep(50); |
| 1332 | valuel = gpio_register_get_value(port); |
| 1333 | //printf("set low? %d\n",valuel); |
| 1334 | if(0 == valuel){ |
| 1335 | break; |
| 1336 | } |
| 1337 | } |
| 1338 | usleep(10000); |
| 1339 | for(i = 0; i <= 10; i++){ |
| 1340 | ret = mbtk_gpio_adc(1); |
| 1341 | usleep(3000); |
| 1342 | if(0 == ret){ |
| 1343 | break; |
| 1344 | } |
| 1345 | } |
| 1346 | //printf("******gpio should is low: %d.******\n", ret); |
| 1347 | if(0 != ret){ |
| 1348 | ret=-1; |
| 1349 | goto exit; |
| 1350 | } |
| 1351 | |
| 1352 | exit: |
| 1353 | gpio_register_set_value(port, 0); |
| 1354 | //error: no need set direction in gpio_register_set_direction(port, 0); |
| 1355 | return ret; |
| 1356 | } |
| 1357 | |
| 1358 | |
| 1359 | int gpio_register_test_out_2(int port_in, int port_out) |
| 1360 | { |
| 1361 | int ret_in; |
| 1362 | int ret_out; |
| 1363 | int i; |
| 1364 | int valueh = 0; |
| 1365 | int valuel = 1; |
| 1366 | |
| 1367 | //printf("Gpio port [%d] test start!\n", port_out); |
| 1368 | ret_in = gpio_register_set_func_0(port_in); //设功能为GPIO |
| 1369 | ret_out = gpio_register_set_func_0(port_out); |
| 1370 | if((ret_in+ret_out)){ |
| 1371 | printf("gpio_port can't support!\n"); |
| 1372 | return -1; |
| 1373 | } |
| 1374 | gpio_register_set_direction(port_out, 1); //设方向为输出 |
| 1375 | gpio_register_set_direction(port_in, 0); //设方向为输入 |
| 1376 | //ret_in = gpio_register_get_value(port_in); |
| 1377 | //printf("gpio default value is : %d.\n", ret_in); |
| 1378 | |
| 1379 | |
| 1380 | //[High] |
| 1381 | for(i = 0; i <= 10; i++){ |
| 1382 | gpio_register_set_value(port_out, 1); |
| 1383 | usleep(50); |
| 1384 | valueh = gpio_register_get_value(port_out); |
| 1385 | //printf("set high? %d\n",valueh); |
| 1386 | if(1 == valueh){ |
| 1387 | break; |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | usleep(5000); |
| 1392 | for(i = 0; i <= 10; i++){ |
| 1393 | ret_in = gpio_register_get_value(port_in); |
| 1394 | usleep(3000); |
| 1395 | if(1 == ret_in){ |
| 1396 | break; |
| 1397 | } |
| 1398 | } |
| 1399 | if(1 != ret_in){ |
| 1400 | ret_in=-1; |
| 1401 | printf("get high failed! \n"); |
| 1402 | goto exit; |
| 1403 | } |
| 1404 | //printf("******gpio should is high: %d.******\n", ret_in); |
| 1405 | |
| 1406 | |
| 1407 | //[Low] |
| 1408 | usleep(200); |
| 1409 | for(i = 0; i <= 10; i++){ |
| 1410 | gpio_register_set_value(port_out, 0); //输出低 |
| 1411 | usleep(50); |
| 1412 | valuel = gpio_register_get_value(port_out); |
| 1413 | //printf("set low? %d\n",valuel); |
| 1414 | if(0 == valuel){ |
| 1415 | break; |
| 1416 | } |
| 1417 | } |
| 1418 | |
| 1419 | usleep(5000); |
| 1420 | for(i = 0; i <= 10; i++){ |
| 1421 | ret_in = gpio_register_get_value(port_in); |
| 1422 | usleep(3000); |
| 1423 | if(0 == ret_in){ |
| 1424 | break; |
| 1425 | } |
| 1426 | } |
| 1427 | //printf("******gpio should is low: %d.******\n", ret_in); |
| 1428 | if(0 != ret_in){ |
| 1429 | ret_in=-1; |
| 1430 | printf("get low failed! \n"); |
| 1431 | goto exit; |
| 1432 | } |
| 1433 | |
| 1434 | exit: |
| 1435 | gpio_register_set_value(port_out, 0); |
| 1436 | //gpio_register_set_direction(port_out, 0); |
| 1437 | return ret_in; |
| 1438 | } |
| 1439 | |
| 1440 | |
| 1441 | static int gpio_test_init_test_gpio_mode(void ) |
| 1442 | { |
| 1443 | const int test_gpio_1[] = { |
| 1444 | 40, 33, 34, 39, 99, 10, 11, 88, 87, 86, 85, 84, 89, |
| 1445 | 56, 55, 58, 57, 48, 59, 10, 90, 20, 53, 19, 46, 127, |
| 1446 | 49, 50, 32, 31, 6, 7 |
| 1447 | }; |
| 1448 | |
| 1449 | const int test_gpio_0[] = { |
| 1450 | 8, 27, 28, 26, 25, 15, 1, 3, 0, |
| 1451 | 37, 38,35, 36, 42, 41, 21, 22, 24, 23, |
| 1452 | 54, 125, 18, 13, 14, 17, 16, 5, 4, 2, 12, |
| 1453 | 43, 44, 45, 47, 117, 119 |
| 1454 | }; |
| 1455 | int i, j, ret_0, ret_1, total_1, total_0, n = 0; |
| 1456 | total_0 = (sizeof(test_gpio_0)/sizeof(int)); |
| 1457 | total_1 = (sizeof(test_gpio_1)/sizeof(int)); |
| 1458 | |
| 1459 | //system("at at+gpsinit=0"); |
| 1460 | system("i2cset -y -f 2 0x32 0x0d 0x00"); |
| 1461 | system("i2cset -y -f 2 0x31 0x18 0x8f"); |
| 1462 | usleep(10000); |
| 1463 | |
| 1464 | //printf("[init]gpio_test_init_test_gpio_mode FINISH\n"); |
| 1465 | /* [1 all gpio set to low] */ |
| 1466 | for(j = 0; j < 6 ; j++){ |
| 1467 | for(i = 0; i < total_0; i++){ |
| 1468 | gpio_register_set_func_0(test_gpio_0[i]); |
| 1469 | gpio_register_set_direction(test_gpio_0[i], 1); |
| 1470 | gpio_register_set_value(test_gpio_0[i], 0); |
| 1471 | } |
| 1472 | for(i = 0; i < total_1; i++){ |
| 1473 | gpio_register_set_func_0(test_gpio_1[i]); |
| 1474 | gpio_register_set_direction(test_gpio_1[i], 1); |
| 1475 | gpio_register_set_value(test_gpio_1[i], 0); |
| 1476 | } |
| 1477 | |
| 1478 | usleep(50000); |
| 1479 | for(i = 0; i <= 10; i++){ |
| 1480 | ret_0 = mbtk_gpio_adc(0); |
| 1481 | usleep(3000); |
| 1482 | ret_1 = mbtk_gpio_adc(1); |
| 1483 | |
| 1484 | if(ret_0 ==0 && ret_1 == 0){ |
| 1485 | break; |
| 1486 | } |
| 1487 | } |
| 1488 | printf("pre set ADC0: %d, ADC1: %d, times: %d\n", ret_0, ret_1, j); |
| 1489 | if(ret_0 ==0 && ret_1 == 0){ |
| 1490 | break; |
| 1491 | } |
| 1492 | } |
| 1493 | if(!(ret_0 ==0 && ret_1 == 0)){ |
| 1494 | |
| 1495 | printf("Fail, please retest"); |
| 1496 | return -1; |
| 1497 | } |
| 1498 | gpio_register_set_value(119, 1); |
| 1499 | gpio_register_set_value(117, 1); |
| 1500 | return 0; |
| 1501 | } |
| 1502 | |
| 1503 | int mbtk_at_gpio(bool gnss_support, void* arg) |
| 1504 | { |
| 1505 | const int test_gpio_0[] = { |
| 1506 | 35, 93, |
| 1507 | 36, 94, |
| 1508 | 42, 97, |
| 1509 | 41, 98, |
| 1510 | 21, 100, |
| 1511 | 22, 101, |
| 1512 | 24, 102, |
| 1513 | 23, 103, |
| 1514 | 54, 107, |
| 1515 | 125, 108, |
| 1516 | 18, 109, |
| 1517 | 13, 114, |
| 1518 | 14, 115, |
| 1519 | 17, 116, |
| 1520 | 16, 117, |
| 1521 | 5, 119, |
| 1522 | 4, 127, |
| 1523 | 2, 120, |
| 1524 | 12, 126, |
| 1525 | 0, 90, |
| 1526 | 27, 73, |
| 1527 | 28, 74, |
| 1528 | 26, 75, |
| 1529 | 25, 76, |
| 1530 | 15, 86, |
| 1531 | 1, 88, |
| 1532 | 3, 89, |
| 1533 | 37, 91, |
| 1534 | 38, 92, |
| 1535 | 8, 72 |
| 1536 | }; |
| 1537 | |
| 1538 | const int test_gpio_1[] = { |
| 1539 | 40, 6, |
| 1540 | 33, 7, |
| 1541 | 34, 8, |
| 1542 | 39, 9, |
| 1543 | 99, 16, |
| 1544 | 56, 27, |
| 1545 | 58, 29, |
| 1546 | 55, 28, |
| 1547 | 57, 30, |
| 1548 | 48, 31, |
| 1549 | 59, 32, |
| 1550 | 20, 49, |
| 1551 | 53, 50, |
| 1552 | 19, 51, |
| 1553 | 49, 55, |
| 1554 | 50, 56, |
| 1555 | 32, 66, |
| 1556 | 31, 67, |
| 1557 | 6, 68, |
| 1558 | 11, 83, |
| 1559 | 10, 84, |
| 1560 | 7, 69, |
| 1561 | 90, 48, |
| 1562 | 46, 52, |
| 1563 | 127, 54, |
| 1564 | 88, 21, |
| 1565 | 87, 22, |
| 1566 | 86, 23, |
| 1567 | 85, 24, |
| 1568 | 84, 25, |
| 1569 | 89, 26, |
| 1570 | }; |
| 1571 | |
| 1572 | const int test_gpio_2[] = { //GPS组 |
| 1573 | 43, 53, |
| 1574 | 47, 95, |
| 1575 | 45, 71, |
| 1576 | 44, 70, |
| 1577 | }; |
| 1578 | |
| 1579 | int i, j, ret_0, ret_1, ret_2, total_1, total_0, total_2, n = 0; |
| 1580 | int *fail_io = (int *)arg; |
| 1581 | total_0 = (sizeof(test_gpio_0)/sizeof(int)); //GPIO+PIN |
| 1582 | total_1 = (sizeof(test_gpio_1)/sizeof(int)); |
| 1583 | total_2 = (sizeof(test_gpio_2)/sizeof(int)); |
| 1584 | if(gnss_support == 1){ |
| 1585 | total_2 = total_2 - 4; |
| 1586 | } |
| 1587 | printf("L508-X6 Start test gpio V1.1\n"); |
| 1588 | /* [1 all gpio Init] */ |
| 1589 | gpio_test_init_test_gpio_mode(); |
| 1590 | |
| 1591 | |
| 1592 | /* [2 GPIOTEST] */ |
| 1593 | //Test 0 |
| 1594 | for(i = 0; i < total_0; i=i+2){ |
| 1595 | ret_0 = gpio_register_test_out_0(test_gpio_0[i]); |
| 1596 | if(-1 == ret_0){ |
| 1597 | printf("!!!!!!!!!!!!gpio [%d] test failed!!!!!!!!!!!!\n", test_gpio_0[i]); |
| 1598 | fail_io[n] = test_gpio_0[i+1]; |
| 1599 | n++; |
| 1600 | }else{ |
| 1601 | //printf("############gpio [%d] test success############\n", test_gpio_0[i]); |
| 1602 | } |
| 1603 | } |
| 1604 | |
| 1605 | //Test 1 |
| 1606 | for(i = 0; i < total_1; i=i+2){ |
| 1607 | ret_1 = gpio_register_test_out_1(test_gpio_1[i]); |
| 1608 | if(-1 == ret_1){ |
| 1609 | printf("!!!!!!!!!!!!gpio [%d] test failed!!!!!!!!!!!!\n", test_gpio_1[i]); |
| 1610 | fail_io[n] = test_gpio_1[i+1]; |
| 1611 | n++; |
| 1612 | }else{ |
| 1613 | //printf("############gpio [%d] test success############\n", test_gpio_1[i]); |
| 1614 | } |
| 1615 | } |
| 1616 | |
| 1617 | //Test 2 |
| 1618 | for(i = 0; i < total_2; i=i+4){ |
| 1619 | ret_2 = gpio_register_test_out_2(test_gpio_2[i], test_gpio_2[i+2]); |
| 1620 | if(-1 == ret_2){ |
| 1621 | printf("!!!!!!!!!!!!gpio [%d] test failed!!!!!!!!!!!!\n", test_gpio_2[i+2]); |
| 1622 | fail_io[n] = test_gpio_2[i+3]; |
| 1623 | n++; |
| 1624 | }else{ |
| 1625 | //printf("############gpio [%d] test success############\n", test_gpio_2[i+2]); |
| 1626 | } |
| 1627 | } |
| 1628 | |
| 1629 | mbtk_adc_close(); |
| 1630 | return n; |
| 1631 | } |
| 1632 | |
| 1633 | #elif 0//(MBTK_PROJECT_T108) |
| 1634 | int gpio_register_test_out(int port, int value) |
| 1635 | { |
| 1636 | int ret; |
| 1637 | int i; |
| 1638 | int valueh = 0; |
| 1639 | int valuel = 1; |
| 1640 | |
| 1641 | //printf("Gpio port [%d] test start!\n", port); |
| 1642 | ret = gpio_register_set_func_0(port); //设功能为GPIO |
| 1643 | if(ret){ |
| 1644 | printf("gpio_port can't support!\n"); |
| 1645 | return -1; |
| 1646 | } |
| 1647 | gpio_register_set_direction(port, 1); //设方向为输出 |
| 1648 | //ret = gpio_register_get_value(port); |
| 1649 | //printf("gpio default value is: %d\n", ret); |
| 1650 | |
| 1651 | |
| 1652 | //[High] |
| 1653 | for(i = 0; i <= 9; i++){ |
| 1654 | gpio_register_set_value(port, 1); |
| 1655 | usleep(50); |
| 1656 | //valueh = gpio_register_get_value(port); |
| 1657 | //printf("set high? %d\n", valueh); |
| 1658 | if(1 == valueh){ |
| 1659 | break; |
| 1660 | } |
| 1661 | } |
| 1662 | |
| 1663 | for(i = 0; i <= 35; i++){ |
| 1664 | ret = gpio_register_get_value(118); |
| 1665 | if(1 == ret){ |
| 1666 | break; |
| 1667 | } |
| 1668 | usleep(3000); |
| 1669 | } |
| 1670 | printf("******gpio should is high: %d.******\n", ret); |
| 1671 | if(1 != ret){ |
| 1672 | ret=-1; |
| 1673 | goto exit; |
| 1674 | } |
| 1675 | |
| 1676 | //[Low] |
| 1677 | usleep(200); |
| 1678 | for(i = 0; i <= 9; i++){ |
| 1679 | gpio_register_set_value(port, 0); //输出低 |
| 1680 | usleep(50); |
| 1681 | //valuel = gpio_register_get_value(port); |
| 1682 | //printf("set low? %d\n", valuel); |
| 1683 | if(0 == valuel){ |
| 1684 | break; |
| 1685 | } |
| 1686 | } |
| 1687 | |
| 1688 | for(i = 0; i <= 35; i++){ |
| 1689 | ret = gpio_register_get_value(118); |
| 1690 | if(0 == ret){ |
| 1691 | break; |
| 1692 | } |
| 1693 | usleep(3000); |
| 1694 | } |
| 1695 | //printf("******gpio should is low: %d.******\n", ret); |
| 1696 | if(0 != ret){ |
| 1697 | ret=-1; |
| 1698 | goto exit; |
| 1699 | } |
| 1700 | |
| 1701 | exit: |
| 1702 | gpio_register_set_value(port, 0); |
| 1703 | gpio_register_set_direction(port, 0); //设方向为输入 |
| 1704 | return ret; |
| 1705 | } |
| 1706 | |
| 1707 | int gpio_test_init_test_gpio_mode(void) |
| 1708 | { |
| 1709 | const int test_gpio[] = { |
| 1710 | 99, |
| 1711 | 117, |
| 1712 | 21,22,23,24,44,41,120, |
| 1713 | 8,127,46,59,58,57,56,55,48,19,34,33,35,36,49, |
| 1714 | 50,25,28,26,122,20,10,11, |
| 1715 | 39,40,37,38, |
| 1716 | 51,52,31,32, |
| 1717 | }; |
| 1718 | |
| 1719 | int i, j, ret, total, n = 0; |
| 1720 | total = (sizeof(test_gpio)/sizeof(int)); |
| 1721 | printf("[init]gpio_test_init_test_gpio_mode BEGIN\n"); |
| 1722 | |
| 1723 | /* [1 all gpio set to low] */ |
| 1724 | gpio_register_set_func_0(118); |
| 1725 | gpio_register_set_direction(118, 0); |
| 1726 | system("echo in > /sys/class/gpio/gpio118/direction"); |
| 1727 | |
| 1728 | for(j = 0; j < 6 ; j++){ |
| 1729 | for(i = 0; i < total; i++){ |
| 1730 | gpio_register_set_func_0(test_gpio[i]); |
| 1731 | gpio_register_set_direction(test_gpio[i], 1); |
| 1732 | gpio_register_set_value(test_gpio[i], 0); |
| 1733 | //ret = gpio_register_get_value(test_gpio[i]); |
| 1734 | //printf("[init]get gpio%d=%d\n", test_gpio[i], ret); |
| 1735 | } |
| 1736 | |
| 1737 | for(i = 0; i <= 35; i++){ |
| 1738 | ret = gpio_register_get_value(118); |
| 1739 | printf("[init]get gpi118=%d\n", ret); |
| 1740 | usleep(3000); |
| 1741 | if(0 == (ret)){ |
| 1742 | break; |
| 1743 | } |
| 1744 | } |
| 1745 | |
| 1746 | printf("pre set ADC: %d, times: %d\n",(ret), j); |
| 1747 | if(0 == (ret)){ |
| 1748 | break; |
| 1749 | } |
| 1750 | } |
| 1751 | if(0 != (ret)){ |
| 1752 | printf("!!!Set all low FAIL, please retest\n"); |
| 1753 | return -1; |
| 1754 | } |
| 1755 | return 0; |
| 1756 | } |
| 1757 | |
| 1758 | int mbtk_at_gpio(bool gnss_support, void* arg) |
| 1759 | { |
| 1760 | |
| 1761 | const int test_gpio[] = { |
| 1762 | //GPIO PIN GPIO PIN GPIO PIN GPIO PIN |
| 1763 | 99, 170, 117, 59, 21, 61, 22, 62, |
| 1764 | 23, 144, 24, 147, 44, 5, 41, 159, |
| 1765 | 120, 143, 8, 171, 127, 160, 46, 149, |
| 1766 | 59, 19, 58, 18, 57, 20, 56, 21, |
| 1767 | 55, 22, 48, 23, 19, 3, 34, 79, |
| 1768 | 33, 80, 35, 78, 36, 77, 49, 43, |
| 1769 | 50, 42, 25, 67, 28, 66, 26, 65, |
| 1770 | 122, 169, 20, 152, 10, 74, 11, 73, |
| 1771 | 39, 166, 40, 164, 37, 165, 38, 163, |
| 1772 | 51, 58, 52, 60, 31, 57, 32, 56, |
| 1773 | }; |
| 1774 | |
| 1775 | int i, n = 0, ret, total; |
| 1776 | int *fail_io = (int *)arg; |
| 1777 | int try_count = 0; |
| 1778 | total = (sizeof(test_gpio)/sizeof(int)); |
| 1779 | printf("T108 Start test gpio V1.0, total gpio=%d\n", (total/2)); |
| 1780 | |
| 1781 | for(try_count; try_count < 4; try_count++){ |
| 1782 | n = 0; |
| 1783 | /* [1 all gpio Init] */ |
| 1784 | gpio_test_init_test_gpio_mode(); |
| 1785 | |
| 1786 | /* [2 GPIOTEST] */ |
| 1787 | for(i = 0; i < total; i = i + 2){ |
| 1788 | ret = gpio_register_test_out(test_gpio[i], 0); |
| 1789 | if(-1 == ret){ |
| 1790 | n++; |
| 1791 | printf("!!!!!!!!!!!!gpio [%d] test failed!!!!!!!!!!!!\n", test_gpio[i]); |
| 1792 | if(try_count != 3){ |
| 1793 | printf(" ---TEST FAILED! RETRY!--- \n"); |
| 1794 | usleep(5000); |
| 1795 | break; |
| 1796 | } |
| 1797 | fail_io[n - 1] = test_gpio[i+1]; |
| 1798 | }else{ |
| 1799 | //printf("############gpio [%d] test success############\n", test_gpio[i]); |
| 1800 | } |
| 1801 | } |
| 1802 | if(0 == n){ |
| 1803 | break; |
| 1804 | } |
| 1805 | } |
| 1806 | return n; |
| 1807 | } |
| 1808 | |
| 1809 | |
| 1810 | #elif (MBTK_PROJECT_T108) |
| 1811 | static int gpio_test(int port) |
| 1812 | { |
| 1813 | int ret; |
| 1814 | int i; |
| 1815 | int valueh = 0; |
| 1816 | int valuel = 1; |
| 1817 | |
| 1818 | //printf("Gpio port [%d] test start!\n", port); |
| 1819 | ret = gpio_register_set_func_0(port); |
| 1820 | if(ret){ |
| 1821 | printf("gpio_port can't support!\n"); |
| 1822 | return -1; |
| 1823 | } |
| 1824 | gpio_register_set_direction(port, 1); |
| 1825 | //ret = gpio_register_get_value(port); |
| 1826 | //printf("gpio default value is: %d\n", ret); |
| 1827 | |
| 1828 | |
| 1829 | //[High] |
| 1830 | for(i = 0; i <= 5; i++){ |
| 1831 | gpio_register_set_value(port, 1); |
| 1832 | usleep(50); |
| 1833 | //valueh = gpio_register_get_value(port); |
| 1834 | //printf("set high? %d\n", valueh); |
| 1835 | if(1 == valueh){ |
| 1836 | break; |
| 1837 | } |
| 1838 | } |
| 1839 | |
| 1840 | for(i = 0; i <= 5; i++){ |
| 1841 | ret = gpio_register_get_value(118); |
| 1842 | if(1 == ret){ |
| 1843 | |
| 1844 | break; |
| 1845 | } |
| 1846 | usleep(3000); |
| 1847 | } |
| 1848 | //printf("count=%d \n", i); |
| 1849 | //printf("******gpio should is high: %d.******\n", ret); |
| 1850 | if(1 != ret){ |
| 1851 | ret=-1; |
| 1852 | goto exit; |
| 1853 | } |
| 1854 | |
| 1855 | //[Low] |
| 1856 | usleep(200); |
| 1857 | for(i = 0; i <= 9; i++){ |
| 1858 | gpio_register_set_value(port, 0); |
| 1859 | usleep(50); |
| 1860 | //valuel = gpio_register_get_value(port); |
| 1861 | //printf("set low? %d\n", valuel); |
| 1862 | if(0 == valuel){ |
| 1863 | break; |
| 1864 | } |
| 1865 | } |
| 1866 | |
| 1867 | for(i = 0; i <= 5; i++){ |
| 1868 | ret = gpio_register_get_value(118); |
| 1869 | if(0 == ret){ |
| 1870 | |
| 1871 | break; |
| 1872 | } |
| 1873 | usleep(3000); |
| 1874 | } |
| 1875 | //printf("count=%d \n", i); |
| 1876 | //printf("******gpio should is low: %d.******\n", ret); |
| 1877 | if(0 != ret){ |
| 1878 | ret=-1; |
| 1879 | goto exit; |
| 1880 | } |
| 1881 | |
| 1882 | exit: |
| 1883 | gpio_register_set_value(port, 0); |
| 1884 | gpio_register_set_direction(port, 0); |
| 1885 | return ret; |
| 1886 | |
| 1887 | } |
| 1888 | |
| 1889 | static int gpio_test_init_test_gpio_mode(void) |
| 1890 | { |
| 1891 | const int test_gpio[] = { |
| 1892 | 99,8,117,21,22,23,24,41,120,19,123, |
| 1893 | 58,59,57,56,55,48,125,127,36,35,34, |
| 1894 | 33,54,47,53,46,50,49,11,10,26,28,25, |
| 1895 | 27,32,31,51,52,39,40,37,38, |
| 1896 | 44,45 |
| 1897 | }; |
| 1898 | |
| 1899 | int i, j, ret, total, n = 0; |
| 1900 | total = (sizeof(test_gpio)/sizeof(int)); |
| 1901 | //printf("[init]gpio_test_init_test_gpio_mode BEGIN\n"); |
| 1902 | |
| 1903 | /* [1 all gpio set to low] */ |
| 1904 | gpio_register_set_func_0(118); |
| 1905 | gpio_register_set_direction(118, 0); |
| 1906 | |
| 1907 | for(j = 0; j < 5 ; j++){ |
| 1908 | for(i = 0; i < total; i++){ |
| 1909 | gpio_register_set_func_0(test_gpio[i]); |
| 1910 | gpio_register_set_direction(test_gpio[i], 1); |
| 1911 | gpio_register_set_value(test_gpio[i], 0); |
| 1912 | //ret = gpio_register_get_value(test_gpio[i]); |
| 1913 | //printf("[init]get gpio%d=%d\n", test_gpio[i], ret); |
| 1914 | } |
| 1915 | |
| 1916 | |
| 1917 | for(i = 0; i <= 10; i++){ |
| 1918 | ret = gpio_register_get_value(118); |
| 1919 | //printf("[init]get gpi118=%d\n", ret); |
| 1920 | usleep(3000); |
| 1921 | if(0 == (ret)){ |
| 1922 | break; |
| 1923 | } |
| 1924 | } |
| 1925 | |
| 1926 | //printf("pre set 118: %d, times: %d\n",(ret), j); |
| 1927 | if(0 == (ret)){ |
| 1928 | break; |
| 1929 | } |
| 1930 | } |
| 1931 | if(0 != (ret)){ |
| 1932 | printf("!!!Set all low FAIL, please retest\n"); |
| 1933 | return -1; |
| 1934 | } |
| 1935 | return 0; |
| 1936 | } |
| 1937 | |
| 1938 | int mbtk_at_gpio(bool gnss_support, void* arg) |
| 1939 | { |
| 1940 | const int test_gpio[] = { |
| 1941 | //GPIO PIN GPIO PIN GPIO PIN GPIO PIN |
| 1942 | 99, 170, 8, 171, 117, 59, 21, 61, |
| 1943 | 22, 62, 23, 144, 24, 147, 41, 159, |
| 1944 | 120, 143, 19, 3, 123, 5, 58, 18, |
| 1945 | 59, 19, 57, 20, 56, 21, 55, 22, |
| 1946 | 48, 23, 125, 149, 127, 160, 36, 77, |
| 1947 | 35, 78, 34, 79, 33, 80, 54, 163, |
| 1948 | #if 0 //Hard Ware ERROR! |
| 1949 | 47, 164, |
| 1950 | 46, 166, |
| 1951 | #endif |
| 1952 | 53, 165, 50, 42, 49, 43, 11, 73, |
| 1953 | 10, 74, 26, 65, 28, 66, 25, 67, |
| 1954 | 27, 68, 32, 56, 31, 57, 51, 58, |
| 1955 | 52, 60, 39, 192, 40, 193, 37, 194, |
| 1956 | 38, 195, |
| 1957 | #if 0 //undefine GNSS |
| 1958 | 44, 161, |
| 1959 | 45, 151, |
| 1960 | #endif |
| 1961 | }; |
| 1962 | |
| 1963 | int i, n = 0, ret, total; |
| 1964 | int *fail_io = (int *)arg; |
| 1965 | int try_count; |
| 1966 | total = (sizeof(test_gpio)/sizeof(int)); |
| 1967 | printf("T108 V2 Start test gpio V0.8, total gpio=%d\n", (total/2)); |
| 1968 | |
| 1969 | for(try_count = 0; try_count < 4; try_count++){ |
| 1970 | n = 0; |
| 1971 | /* [1 all gpio Init] */ |
| 1972 | gpio_test_init_test_gpio_mode(); |
| 1973 | |
| 1974 | /* [2 GPIOTEST] */ |
| 1975 | for(i = 0; i < total; i = i + 2){ |
| 1976 | ret = gpio_test(test_gpio[i]); |
| 1977 | if(-1 == ret){ |
| 1978 | n++; |
| 1979 | printf("!!!!!!!!!!!!gpio [%d] test failed!!!!!!!!!!!!\n", test_gpio[i]); |
| 1980 | if(try_count != 3){ |
| 1981 | printf(" ---TEST FAILED! RETRY!--- \n"); |
| 1982 | usleep(5000); |
| 1983 | break; |
| 1984 | } |
| 1985 | fail_io[n - 1] = test_gpio[i + 1]; |
| 1986 | }else{ |
| 1987 | //printf("############gpio [%d] test success############\n", test_gpio[i]); |
| 1988 | } |
| 1989 | } |
| 1990 | if(0 == n){ |
| 1991 | printf(" ---ALL PASS---\n"); |
| 1992 | break; |
| 1993 | } |
| 1994 | } |
| 1995 | return n; |
| 1996 | } |
| 1997 | |
| 1998 | |
| 1999 | #else |
| 2000 | int mbtk_at_gpio(bool gnss_support, void* arg) |
| 2001 | { |
| 2002 | return -1; |
| 2003 | } |
| 2004 | |
| 2005 | #endif |
| 2006 | |