blob: e4baaef94cf521dec9daa551d1b25bdbfc9c3f86 [file] [log] [blame]
/**
* \file gpio-test.c
* \brief A Documented file.
*
* Detailed description
* \Author: Sniper <js.wang@mobiletek.cn>
* \Version: 1.0.0
* \Date: 2022-04-26
*/
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <limits.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/mount.h>
#include "mbtk_log.h"
#include <sys/mman.h>
#include <ctype.h>
#include <cutils/properties.h>
#include "mbtk_gpio_def.h"
#include "gpio-define.h"
#define gpio_log(...) if(gpio_debug)printf(__VA_ARGS__)
#define HWMAP_DEVICE "/dev/hwmap"
#define PAGE_OFFS_BITS(pgsz) ((unsigned int)(pgsz)-1)
#define PAGE_MASK_BITS(pgsz) (~PAGE_OFFS_BITS(pgsz))
#define STR_MAX_LEN 220
typedef enum {
MBTK_ADC0 = 0, /* ADC 0 */
MBTK_ADC1 /* ADC 1 */
} mbtk_adc_enum;
static int gpio_debug = 0;
#if (defined(MBTK_PROJECT_L508_X6) || defined(MBTK_PROJECT_T108))
struct gpio_register_function gpio_func_register[128] = {
{GPIO_FUNC_GPIO_00, 0},
{GPIO_FUNC_GPIO_01, 0},
{GPIO_FUNC_GPIO_02, 0},
{GPIO_FUNC_GPIO_03, 0},
{GPIO_FUNC_GPIO_04, 0},
{GPIO_FUNC_GPIO_05, 0},
{GPIO_FUNC_GPIO_06, 0},
{GPIO_FUNC_GPIO_07, 0},
{GPIO_FUNC_GPIO_08, 0},
{GPIO_FUNC_GPIO_09, 0},
{GPIO_FUNC_GPIO_10, 0},
{GPIO_FUNC_GPIO_11, 0},
{GPIO_FUNC_GPIO_12, 0},
{GPIO_FUNC_GPIO_13, 0},
{GPIO_FUNC_GPIO_14, 0},
{GPIO_FUNC_GPIO_15, 0},
{GPIO_FUNC_GPIO_16, 0},
{GPIO_FUNC_GPIO_17, 0},
{GPIO_FUNC_GPIO_18, 0},
{GPIO_FUNC_GPIO_19, 0},
{GPIO_FUNC_GPIO_20, 0},
{GPIO_FUNC_GPIO_21, 0},
{GPIO_FUNC_GPIO_22, 0},
{GPIO_FUNC_GPIO_23, 0},
{GPIO_FUNC_GPIO_24, 0},
{GPIO_FUNC_GPIO_25, 0},
{GPIO_FUNC_GPIO_26, 0},
{GPIO_FUNC_GPIO_27, 0},
{GPIO_FUNC_GPIO_28, 0},
{GPIO_FUNC_GPIO_29, 0},
{GPIO_FUNC_GPIO_30, 0},
{GPIO_FUNC_GPIO_31, 0},
{GPIO_FUNC_GPIO_32, 0},
{GPIO_FUNC_GPIO_33, 0},
{GPIO_FUNC_GPIO_34, 0},
{GPIO_FUNC_GPIO_35, 0},
{GPIO_FUNC_GPIO_36, 0},
{GPIO_FUNC_GPIO_37, 0}, // GPIO_37
{GPIO_FUNC_GPIO_38, 0}, // GPIO_38
{GPIO_FUNC_GPIO_39, 0}, // GPIO_39
{GPIO_FUNC_GPIO_40, 0}, // GPIO_40
{GPIO_FUNC_GPIO_41, 0}, //GPIO_41
{GPIO_FUNC_GPIO_42, 0}, //GPIO_42
{GPIO_FUNC_GPIO_43, 0}, //GPIO_43
{GPIO_FUNC_GPIO_44,0}, //GPIO_44
{GPIO_FUNC_GPIO_45,0}, //GPIO_45
{GPIO_FUNC_GPIO_46,0}, //GPIO_46
{GPIO_FUNC_GPIO_47,0}, //GPIO_47
{GPIO_FUNC_SDIO_DAT3, 1}, //GPIO_48
{GPIO_FUNC_GPIO_49, 0},
{GPIO_FUNC_GPIO_50, 0},
{GPIO_FUNC_GPIO_51, 0},
{GPIO_FUNC_GPIO_52, 0},
{GPIO_FUNC_GPIO_53, 0},
{GPIO_FUNC_GPIO_54, 0},
{GPIO_FUNC_SDIO_DAT2, 1}, //GPIO_55
{GPIO_FUNC_SDIO_DAT1, 1}, //GPIO_56
{GPIO_FUNC_SDIO_DAT0, 1}, //GPIO_57
{GPIO_FUNC_SDIO_CMD, 1}, //GPIO_58
{GPIO_FUNC_SDIO_CLK, 1}, //GPIO_59
{GPIO_FUNC_GPIO_60, 0},
{0,0},{0,0},{0,0},{0,0},
{0,0},{0,0},
{GPIO_FUNC_DVL_0, 1},//GPIO_67
{GPIO_FUNC_DVL_1, 1},//GPIO_68
{GPIO_FUNC_GPIO_69, 0},
{GPIO_FUNC_GPIO_70, 0},
{GPIO_FUNC_QSPI_DAT3, 1}, //GPIO_71
{GPIO_FUNC_QSPI_DAT2, 1}, //GPIO_72
{GPIO_FUNC_QSPI_DAT1, 1}, //GPIO_73
{GPIO_FUNC_QSPI_DAT0, 1}, //GPIO_74
{GPIO_FUNC_QSPI_CLK, 1}, //GPIO_75
{GPIO_FUNC_QSPI_CS1, 1}, //GPIO_76
{GPIO_FUNC_GPIO_77, 0},
{GPIO_FUNC_GPIO_78, 0},
{GPIO_FUNC_GPIO_79, 0},
{GPIO_FUNC_GPIO_80, 0},
{GPIO_FUNC_USIM_UCLK, 1},//GPIO_81
{GPIO_FUNC_USIM_UIO, 1},//GPIO_82
{GPIO_FUNC_USIM_URSTn, 1},//GPIO_83
{GPIO_FUNC_MMC1_DAT3,5}, //GPIO_84
{GPIO_FUNC_MMC1_DAT2,5}, //GPIO_85
{GPIO_FUNC_MMC1_DAT1,5}, //GPIO_86
{GPIO_FUNC_MMC1_DAT0,5}, //GPIO_87
{GPIO_FUNC_MMC1_CMD,5}, //GPIO_88
{GPIO_FUNC_MMC1_CLK,5}, //GPIO_89
{GPIO_FUNC_MMC1_CD,1}, //GPIO_90
{0,0},
{0,0},{0,0},{0,0},{0,0},
{0,0},{0,0},{0,0},
{GPIO_FUNC_USB_ID, 1},//GPIO_99
{0,0},{0,0},{0,0},{0,0},
{0,0},{0,0},{0,0},{0,0},
{0,0},{0,0},{0,0},{0,0},
{0,0},{0,0},{0,0},{0,0},
{0,0},
{GPIO_FUNC_PRI_TDI, 1}, //GPIO_117
{GPIO_FUNC_PRI_TMS, 1}, //GPIO_118
{GPIO_FUNC_PRI_TCK, 1}, //GPIO_119
{GPIO_FUNC_PRI_TDO, 1}, //GPIO_120
{GPIO_FUNC_QSPI_VMODE_GPIO, 1}, //GPIO_121
{GPIO_FUNC_VBUS_DRV, 1}, //GPIO_122
{GPIO_FUNC_CLK_REQ, 1}, //GPIO_123
{0,0},
{GPIO_FUNC_VCXO_REQ, 1}, //GPIO_125
{0,0}, //GPIO_126
{GPIO_FUNC_VCXO_OUT, 1}, //GPIO_127
{0,0},
};
#else
struct gpio_register_function gpio_func_register[128] = {
{GPIO_FUNC_GPIO_00, 0},
{GPIO_FUNC_GPIO_01, 0},
{GPIO_FUNC_GPIO_02, 0},
{GPIO_FUNC_GPIO_03, 0},
{GPIO_FUNC_GPIO_04, 0},
{GPIO_FUNC_GPIO_05, 0},
{GPIO_FUNC_GPIO_06, 0},
{GPIO_FUNC_GPIO_07, 0},
{GPIO_FUNC_GPIO_08, 0},
{GPIO_FUNC_GPIO_09, 0},
{GPIO_FUNC_GPIO_10, 0},
{GPIO_FUNC_GPIO_11, 0},
{GPIO_FUNC_GPIO_12, 0},
{GPIO_FUNC_GPIO_13, 0},
{GPIO_FUNC_GPIO_14, 0},
{GPIO_FUNC_GPIO_15, 0},
{GPIO_FUNC_GPIO_16, 0},
{GPIO_FUNC_GPIO_17, 0},
{GPIO_FUNC_GPIO_18, 0},
{GPIO_FUNC_GPIO_19, 0},
{GPIO_FUNC_GPIO_20, 0},
{GPIO_FUNC_GPIO_21, 0},
{GPIO_FUNC_GPIO_22, 0},
{GPIO_FUNC_GPIO_23, 0},
{GPIO_FUNC_GPIO_24, 0},
{GPIO_FUNC_GPIO_25, 0},
{GPIO_FUNC_GPIO_26, 0},
{GPIO_FUNC_GPIO_27, 0},
{GPIO_FUNC_GPIO_28, 0},
{GPIO_FUNC_GPIO_29, 0},
{GPIO_FUNC_GPIO_30, 0},
{GPIO_FUNC_GPIO_31, 0},
{GPIO_FUNC_GPIO_32, 0},
{GPIO_FUNC_GPIO_33, 0},
{GPIO_FUNC_GPIO_34, 0},
{GPIO_FUNC_GPIO_35, 0},
{GPIO_FUNC_GPIO_36, 0},
{GPIO_FUNC_MMC1_DAT3, 5}, // GPIO_37
{GPIO_FUNC_MMC1_DAT2, 5}, // GPIO_38
{GPIO_FUNC_MMC1_DAT1, 5}, // GPIO_39
{GPIO_FUNC_MMC1_DAT0, 5}, // GPIO_40
{GPIO_FUNC_MMC1_CMD, 5}, //GPIO_41
{GPIO_FUNC_MMC1_CLK, 5}, //GPIO_42
{GPIO_FUNC_MMC1_CD , 1}, //GPIO_43
{0,0},{0,0},{0,0},{0,0},
{GPIO_FUNC_SDIO_DAT3, 1}, //GPIO_48
{GPIO_FUNC_GPIO_49, 0},
{GPIO_FUNC_GPIO_50, 0},
{GPIO_FUNC_GPIO_51, 0},
{GPIO_FUNC_GPIO_52, 0},
{GPIO_FUNC_GPIO_53, 0},
{GPIO_FUNC_GPIO_54, 0},
{GPIO_FUNC_SDIO_DAT2, 1}, //GPIO_55
{GPIO_FUNC_SDIO_DAT1, 1}, //GPIO_56
{GPIO_FUNC_SDIO_DAT0, 1}, //GPIO_57
{GPIO_FUNC_SDIO_CMD, 1}, //GPIO_58
{GPIO_FUNC_SDIO_CLK, 1}, //GPIO_59
{GPIO_FUNC_GPIO_60, 0},
{0,0},{0,0},{0,0},{0,0},
{0,0},{0,0},
{GPIO_FUNC_DVL_0, 1},//GPIO_67
{GPIO_FUNC_DVL_1, 1},//GPIO_68
{GPIO_FUNC_GPIO_69, 0},
{GPIO_FUNC_GPIO_70, 0},
{GPIO_FUNC_QSPI_DAT3, 1}, //GPIO_71
{GPIO_FUNC_QSPI_DAT2, 1}, //GPIO_72
{GPIO_FUNC_QSPI_DAT1, 1}, //GPIO_73
{GPIO_FUNC_QSPI_DAT0, 1}, //GPIO_74
{GPIO_FUNC_QSPI_CLK, 1}, //GPIO_75
{GPIO_FUNC_QSPI_CS1, 1}, //GPIO_76
{GPIO_FUNC_GPIO_77, 0},
{GPIO_FUNC_GPIO_78, 0},
{GPIO_FUNC_GPIO_79, 0},
{GPIO_FUNC_GPIO_80, 0},
{GPIO_FUNC_USIM_UCLK, 1},//GPIO_81
{GPIO_FUNC_USIM_UIO, 1},//GPIO_82
{GPIO_FUNC_USIM_URSTn, 1},//GPIO_83
{0,0},{0,0},{0,0},{0,0},
{0,0},{0,0},{0,0},{0,0},
{0,0},{0,0},{0,0},{0,0},
{0,0},{0,0},{0,0},
{GPIO_FUNC_USB_ID, 1},//GPIO_99
{0,0},{0,0},{0,0},{0,0},
{0,0},{0,0},{0,0},{0,0},
{0,0},{0,0},{0,0},{0,0},
{0,0},{0,0},{0,0},{0,0},
{0,0},
{GPIO_FUNC_PRI_TDI, 1}, //GPIO_117
{GPIO_FUNC_PRI_TMS, 1}, //GPIO_118
{GPIO_FUNC_PRI_TCK, 1}, //GPIO_119
{GPIO_FUNC_PRI_TDO, 1}, //GPIO_120
{GPIO_FUNC_QSPI_VMODE_GPIO, 1}, //GPIO_121
{GPIO_FUNC_VBUS_DRV, 1}, //GPIO_122
{GPIO_FUNC_CLK_REQ, 1}, //GPIO_123
{0,0},
{GPIO_FUNC_VCXO_REQ, 1}, //GPIO_125
{GPIO_FUNC_VCXO_OUT, 1}, //GPIO_126
{0,0},
};
#endif
static int mbtk_gpio_adc(channel)
{
int ret = 0;
ret = mbtk_adc_get(channel);
//printf("ADC_%d_value =%d\n", channel, ret);
if(ret >= 500 ){
ret = 1;
}
else if (ret>=0 && ret<=480){
ret = 0;
}
else{
ret = -1;
}
return ret;
}
static int hwacc_register(int rw, unsigned int addr, unsigned int *data)
{
int fid;
unsigned int pagesize, len, len_aligned;
unsigned int addr_aligned;
volatile unsigned int *pa;
void *vpa;
len = pagesize = sysconf(_SC_PAGESIZE);
if((fid = open(HWMAP_DEVICE, O_RDWR)) < 0)
{
printf("Failed to open %s\n", HWMAP_DEVICE);
exit(-1);
}
// Align the length so the mapped area is page-aligned and contains the requested area
addr_aligned = addr & PAGE_MASK_BITS(pagesize);
len_aligned =((addr + len - addr_aligned) + pagesize - 1) & PAGE_MASK_BITS(pagesize);
/* Notes on flags: MAP_PRIVATE results in copy on write; MAP_SHARED allows normal write */
/* MAP_SHARED required O_RDWR in open above, otherwise mmap fails with errno=EACCES */
/* Notes on prot: PROT_WRITE allows read and write; PROT_READ allows read only */
/* Notes on off: an unsigned 32-bit value, should be aligned to page size according to mmap manpage */
if((vpa = mmap(0, len_aligned, PROT_READ|PROT_WRITE, MAP_SHARED, fid, addr_aligned)) == MAP_FAILED)
{
printf("mmap failed (%d)\n", errno);
}
else
{
pa = (volatile unsigned int *)((unsigned char *)vpa + (addr & PAGE_OFFS_BITS(pagesize)));
if(rw == 0)
{
*data = *pa;
gpio_log("Value read from 0x%.8x via MVA=0x%p is 0x%.8x\n", addr, pa, *data);
}
else if(rw == 1)
{
*pa = *data;
gpio_log("Value %.8x written to 0x%.8x via MVA=0x%p\n", *data, addr, pa);
#if defined(HWACC_DEBUG)
{
unsigned int val;
val = *pa;
printf("Value read from 0x%.8x via MVA=0x%p is 0x%.8x\n", addr, pa, val);
}
#endif
}
munmap(vpa, len);
}
close(fid);
return 0;
}
/*
设置GPIO 模式:第一步读GPIO22默认function
root@OpenWrt:/# hwacc r 0xd401e134
Option = r Addr = d401e134
Value read from 0xd401e134 via MVA=0x0xb6fc3134 is 0x0000d040 //默认GPIO功能
Bit0~bit2值对应上面表格各function,0代表GPIO功能
*/
static int gpio_register_read(int reg)
{
int ret = -1;
#if 0
FILE * fp;
// "/bin/hwacc r 0xd401e134";
char command[36] = {0};
char buffer[1024];
int i = 0;
sprintf(command, "/bin/hwacc r 0x%x", reg);
fp = popen(command, "r");
while(1)
{
if( fgets (buffer, sizeof(buffer), fp)!=NULL ) {
buffer[strlen(buffer) - 1] = 0;
// gpio_log("out [%d]: %s\n", strlen(buffer), buffer);
}else{
break;
}
i = strstr_n(buffer, "is");
if(i)
{
ret = str_to_hex(&buffer[i + 2]);
gpio_log("read 0x%x value:%s, %x\n", reg, &buffer[i + 2], ret);
}
}
pclose(fp);
#else
#ifndef MBTK_PROJECT_PN1803
usleep(50);
#endif
hwacc_register(0, reg, &ret);
#ifndef MBTK_PROJECT_PN1803
usleep(50);
#endif
#endif
return ret;
}
/*
设置输入输出状态,设置PDR寄存器GPIO22为output
root@OpenWrt:/# hwacc w 0xD401900c 0x00c03800
Option = w Addr = d401900c Data=00c03800
Value 00c03800 written to 0xd401900c via MVA=0x0xb6f9f00c
*/
static void gpio_register_write(int reg, int value)
{
#if 0
FILE * fp;
// "/bin/hwacc w 0xD401900c 0x00c03800"
char command[36] = {0};
char buffer[1024];
sprintf(command, "/bin/hwacc w 0x%x 0x%x", reg, value);
gpio_log("command: %s\n", command);
fp = popen(command, "r");
while(1)
{
if( fgets (buffer, sizeof(buffer), fp)!=NULL ) {
gpio_log("%s\n", buffer);
}else{
break;
}
}
pclose(fp);
#else
#ifndef MBTK_PROJECT_PN1803
usleep(50);
#endif
hwacc_register(1, reg, &value);
#ifndef MBTK_PROJECT_PN1803
usleep(50);
#endif
#endif
}
/*
AF SEL<p>This field is used for alternate function selection for a pin.
It selects between the eight possible alternate functions for the pin.
Alternate function 0 is always the reset case.
<p>0x0 = Alternate function 0 (primary function at reset)
<p>0x1 = Alternate function 1
<p>0x2 = Alternate function 2
<p>0x3 = Alternate function 3
<p>0x4 = Alternate function 4
<p>0x5 = Alternate function 5
<p>0x6 = Alternate function 6
<p>0x7 = Alternate function 7
*/
static int gpio_register_set_func_0(int port)
{
int ret;
struct gpio_register_function *reg = NULL;
if(port > 128)
return -1;
reg = &gpio_func_register[port];
if(0 == reg->reg)
return -1;
ret = gpio_register_read(reg->reg);
if((ret & 0x7) != reg->func_gpio)
{
//printf("Gpio set func [%d] [0x%x]!\n", reg->func_gpio, (ret & 0xfffffff8) | reg->func_gpio);
gpio_register_write(reg->reg, (ret & 0xfffffff8) | reg->func_gpio);
}
return 0;
}
/*
设置GPIO 方向
读取输入输出状态,读PDR寄存器:0x0c
root@OpenWrt:/# hwacc r 0xD401900c
Option = r Addr = d401900c
Value read from 0xd401900c via MVA=0x0xb6f3900c is 0x00803800 //bit22为0,代表Input
*/
static void gpio_register_set_direction(int port, int dir)
{
int ret;
int reg = 0xD4019000;
if(port > (32 - 1))
reg = 0xD4019004;
if(port > (32 * 2 - 1))
reg = 0xD4019008;
if(port > (32 * 3 - 1))
reg = 0xD4019100;
reg += 0x0c;
port = port % 0x20;
ret = gpio_register_read(reg);
//printf("[Direction] reg_value=%x\n", ret);
// 设置 输出 0 && 1
if(!(ret & (0x1 << port)) && dir)
{
gpio_register_write(reg, ret | (0x1 << port));
//printf("[Direction out] reg_value=%x\n", gpio_register_read(reg));
}
// 设置 输入 1 && 0
if((ret & (0x1 << port)) && !dir)
{
gpio_register_write(reg, ret | !(0x1 << port));
//printf("[Direction in] reg_value=%x\n", gpio_register_read(reg));
}
}
/*
设置GPIO 输出电平
读取电平状态,先读PLR寄存器:0x00
root@OpenWrt:/# hwacc r 0xD4019000
Option = r Addr = d4019000
Value read from 0xd4019000 via MVA=0x0xb6f1c000 is 0x81e82a30
对应下面具体BIT
1000 0001 1110 1000 0010 1010 0011 0000 BIT22默认电平高
设置输出高:设置PSR寄存器:0x18(只写寄存器)
root@OpenWrt:/# hwacc w 0xD4019018 0x400000
Option = w Addr = d4019018 Data=00400000
Value 00400000 written to 0xd4019018 via MVA=0x0xb6f56018 //bit22写1,输出高
设置输出低:设置PCR寄存器:0x24
root@OpenWrt:/# hwacc w 0xD4019024 0x400000
Option = w Addr = d4019024 Data=00400000
Value 00400000 written to 0xd4019024 via MVA=0x0xb6faa024 //Bit22写1,GPIO22输出低
*/
static void gpio_register_set_value(int port, int value)
{
int ret;
int reg = 0xD4019000;
if(port > (32 - 1))
reg = 0xD4019004;
if(port > (32 * 2 - 1))
reg = 0xD4019008;
if(port > (32 * 3 - 1))
reg = 0xD4019100;
if(value)
{
reg += 0x18;
}
else
reg += 0x24;
port = port % 0x20;
ret = gpio_register_read(reg);
//printf("[Value] reg_value=%x\n", gpio_register_read(0xD4019004));
// 设置 高电平 0 && 1
if(value)
{
gpio_register_write(reg, ret | (0x1 << port));
//printf("[Value high] reg_value=%x\n", gpio_register_read(0xD4019004));
return;
}
// 设置 低电平 1 && 0
if(!(ret & (0x1 << port)) && !value)
{
gpio_register_write(reg, ret | (0x1 << port));
//printf("[Value low] reg_value=%x\n", gpio_register_read(0xD4019004));
}
}
/*
读取电平状态,先读PLR寄存器:0x00
root@OpenWrt:/# hwacc r 0xD4019000
Option = r Addr = d4019000
Value read from 0xd4019000 via MVA=0x0xb6f1c000 is 0x81e82a30
对应下面具体BIT
1000 0001 1110 1000 0010 1010 0011 0000 BIT22默认电平高
*/
static int gpio_register_get_value(int port)
{
int ret = -1;
int reg = 0xD4019000;
if(port > (32 - 1))
reg = 0xD4019004;
if(port > (32 * 2 - 1))
reg = 0xD4019008;
if(port > (32 * 3 - 1))
reg = 0xD4019100;
port = port % 0x20;
ret = gpio_register_read(reg);
if(ret & (0x1 << port))
{
return 1;
}
return 0;
}
void gpio_debug_set(int enable)
{
gpio_debug = enable;
}
#if defined(MBTK_PROJECT_PN1803)
int gpio_register_test_out(int port, int value)
{
int ret;
int i;
int valueh = 0;
int valuel = 1;
//printf("Gpio port [%d] test start!\n", port);
ret = gpio_register_set_func_0(port); //设功能为GPIO
if(ret){
printf("gpio_port can't support!\n");
return -1;
}
gpio_register_set_direction(port, 1); //设方向为输出
ret = gpio_register_get_value(port);
//printf("gpio default value is : %d.\n", ret);
//[High]
for(i = 0; i <= 10; i++){
gpio_register_set_value(port, 1);
usleep(50);
valueh = gpio_register_get_value(port);
//printf("set high? %d\n",valueh);
if(1 == valueh){
break;
}
}
//usleep(10000);
for(i = 0; i <= 35; i++){
ret = mbtk_gpio_adc(0);
usleep(3000);
if(1 == ret){
break;
}
}
if(1 != ret){
ret=-1;
goto exit;
}
printf("******gpio should is high: %d.******\n", ret);
//[Low]
usleep(200);
for(i = 0; i <= 10; i++){
gpio_register_set_value(port, 0); //输出低
usleep(50);
valuel = gpio_register_get_value(port);
//printf("set low? %d\n",valuel);
if(0 == valuel){
break;
}
}
//usleep(10000);
for(i = 0; i <= 35; i++){
ret = mbtk_gpio_adc(0);
usleep(3000);
if(0 == ret){
break;
}
}
printf("******gpio should is low: %d.******\n", ret);
if(0 != ret){
ret=-1;
goto exit;
}
exit:
//gpio_register_set_direction(port, 0); //设方向为输入
return ret;
}
int mbtk_at_gpio(void* arg)
{
int test_gpio[] = {
56, 55, 58, 57, 48, 59, 12, 20, 5, 43, 21,
49, 50, 27, 28, 26, 25, 16, 17, 15, 126, 125,
4, 0, 3, 18, 7, 6, 1, 2, /*54,*/ 19, 13,
32, 31, 23, 24, 22, /*122,*/ 33, 35, 36, 34, 14,
99,/* 53,*/ 37, 38, 39, 40, 41, 42};
int i, j, ret, total, n = 0;
int *fail_io = (int *)arg;
total = (sizeof(test_gpio)/sizeof(int));
//printf("Start test gpio total: %d\n", total);
/* [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);
}
//usleep(10000);
for(i = 0; i <= 35; i++){
ret = mbtk_gpio_adc(0);
usleep(3000);
if(0 == ret){
break;
}
}
printf("pre set ADC: %d, times: %d\n",ret, j);
if(0 == ret){
break;
}
}
if(0 != ret){
printf("Fail, please retest");
return -1;
}
/* [2 GPIOTEST] */
for(i = 0; i < total; i++){
ret = gpio_register_test_out(test_gpio[i], 0);
if(-1 == ret){
printf("!!!!!!!!!!!!gpio [%d] test failed!!!!!!!!!!!!\n", test_gpio[i]);
fail_io[n] = test_gpio[i];
n++;
}else{
//printf("############gpio [%d] test success############\n", test_gpio[i]);
}
}
mbtk_adc_close();
return n;
}
#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));
int gpio_test_init(void)
{
int i,j,ret;
//int *fail_io = (int *)arg;
printf("[init] L508 XX GPIOTEST v1.2 \n");
system("i2cset -y -f 2 0x31 0x12 0x46");
gpio_register_set_func_0(22);
gpio_register_set_direction(22, 1); //输出
usleep(500); //这里要先设置输出再设置为输入,怀疑L508TLC软件使用了GPIO22
gpio_register_set_direction(22, 0); //GPIO22 DTR做输入,检测电压
#if 0
/* 错误点预先关闭 */
gpio_register_set_func_0(123);
gpio_register_set_func_0(32);
gpio_register_set_func_0(53);
gpio_register_set_direction(123, 1);
gpio_register_set_direction(32, 1);
gpio_register_set_direction(53, 1);
#endif
/* [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(i = 0; i <= 5; i++){
ret = gpio_register_get_value(22);
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");
return -1;
}
printf("pre set SUCCESS\n");
return 0;
}
int gpio_test(void* arg)
{
int ret,i,j;
int *fail_io = (int *)arg;
int n = 0;
for(i = 0; i < total; i++){
ret = gpio_register_get_value(test_gpio[i]);
printf("GPIO%d default value? %d\n", test_gpio[i], ret);
//set high
gpio_register_set_value(test_gpio[i], 1);
ret = gpio_register_get_value(test_gpio[i]);
printf("GPIO%d set high? %d\n", test_gpio[i], ret);
//get
ret = gpio_register_get_value(22);
if(1 != ret){
printf("gpio [%d] test high failed\n", test_gpio[i]);
fail_io[n] = test_gpio[i];
n++;
}else{
printf("gpio[%d] test high success\n", test_gpio[i]);
}
//set low
gpio_register_set_value(test_gpio[i], 0);
ret = gpio_register_get_value(test_gpio[i]);
printf("GPIO%d set low? %d\n", test_gpio[i], ret);
//get
ret = gpio_register_get_value(22);
if(0 != ret){
printf("gpio [%d] test low failed\n", test_gpio[i]);
fail_io[n] = test_gpio[i];
n++;
}else{
printf("gpio [%d] test low success\n", test_gpio[i]);
}
}
return n;
}
int mbtk_at_gpio(void* arg)
{
int i, j, ret, total, n = 0;
//int *fail_io = (int *)arg;
n = gpio_test_init();
if(-1 == n)
{
//return -1;
}
n = gpio_test(arg);
return n;
}
#elif defined(MBTK_PROJECT_L509)
mbtk_gpio_test_pin_paired test_pin_array[] ={ //是GPIO_array
//120 5 33 这几个输入脚没法正常设置为输入
//{52,51,0}, //拉不低 没有这一组
//{54,53,0},
{16,17,0},
{117,120,0},
//{118,19,0}, //usim
{123,126,0},
{43,23,0},
{28,27,0},
{26,25,0},
{34,33,0},
{36,35,0},
{49,50,0},
{32,31,0},
{7,2,0},
{6,1,0},
{15,3,0},
{0,18,0},
{4,5,0},
{13,14,0},
{48,55,0},
{56,57,0},
{59,58,0},
{21,99,0},
//{20,22,0}, //拉不低
//{12,122,0}, //拉不低 122好像不该用
};
//测低
uint16 mbtk_gpio_test_all_low(mbtk_gpio_test_pin_paired *pin_array, uint16 MAX_pin_num)
{
uint16 index =0;
uint16 OUT_pin, Read_pin;
uint32 read_high_value;
uint32 read_low_value;
uint16 fail_num=0;
int res;
printf("[test_low_begin]\n");
for(index = 0; index < MAX_pin_num; index++){
OUT_pin = pin_array[index].output_pin;
Read_pin = pin_array[index].input_pin;
//输出低
gpio_register_set_direction(OUT_pin,1);
gpio_register_set_value(OUT_pin, 0);
//输入脚设为输入
gpio_register_set_direction(Read_pin,0);
}
for(index = 0; index < MAX_pin_num; index++){
OUT_pin = pin_array[index].output_pin;
Read_pin = pin_array[index].input_pin;
read_low_value = gpio_register_get_value(Read_pin);
//结果检测
if(read_low_value != 0){
printf("[!Low Failed!]: GPIO%d \n", Read_pin);
pin_array[index].mbtk_gpio_test_result = 1;
fail_num ++;
}
else{
printf("[-Low Success-]: GPIO%d \n", Read_pin);
}
}
return fail_num;
}
//测高
uint16 mbtk_gpio_test_pin_high(mbtk_gpio_test_pin_paired *pin_array,uint16 MAX_pin_num)
{
uint16 index =0;
uint16 OUT_pin, Read_pin;
uint32 read_high_value;
uint32 read_low_value;
uint16 fail_num=0;
int i = 0;
printf("[test_high_begin]\n");
for(index = 0;index<MAX_pin_num;index++)
{
OUT_pin = pin_array[index].output_pin;
Read_pin = pin_array[index].input_pin;
//设高
gpio_register_set_direction(OUT_pin,1);
gpio_register_set_direction(Read_pin,0);
gpio_register_set_value(OUT_pin, 1);
usleep(20000);
read_high_value = gpio_register_get_value(Read_pin);
printf("[test_high]: Gpio%d: get value =%d \n", Read_pin, read_high_value);
//设高后重新设低
usleep(20000);
gpio_register_set_value(OUT_pin, 0);
usleep(80000);
//read_low_value = gpio_register_get_value(Read_pin);
//read_low_value = gpio_register_get_value(Read_pin);
for(i = 0;i < 10; i++){
read_low_value = gpio_register_get_value(Read_pin);
if(0 == read_low_value){
break;
}
usleep(20000);
}
printf("[test_low]: Gpio%d: get value =%d \n", Read_pin, read_low_value);
if(read_high_value != 1||read_low_value !=0)
{
printf("[!High Failed!]: Gpio%d\n",Read_pin);
pin_array[index].mbtk_gpio_test_result = 2;
fail_num ++;
}
else{
printf("[-High Success-]: Gpio%d \n", Read_pin);
}
}
return fail_num;
}
void gpio_test_init_test_gpio_mode(mbtk_gpio_test_pin_paired pin_array[],int MAX_pin_num)
{
int index =0;
int OUT_pin, Read_pin;
printf("[init] L509 GPIOTEST v1 \n");
for(index = 0;index<MAX_pin_num;index++)
{
OUT_pin = pin_array[index].output_pin;
Read_pin = pin_array[index].input_pin;
pin_array[index].mbtk_gpio_test_result = 0; //init as passed
gpio_register_set_func_0(OUT_pin);
gpio_register_set_func_0(Read_pin);
}
//gpio_register_set_func_0();
system("i2cset -y -f 2 0x31 0x12 0x46");
system("echo 33 > /sys/class/gpio/export");
system("echo 120 > /sys/class/gpio/export");
system("echo 126 > /sys/class/gpio/export");
system("echo in > /sys/class/gpio/gpio126/direction");
system("echo in > /sys/class/gpio/gpio120/direction");
system("echo in > /sys/class/gpio/gpio5/direction");
system("echo in > /sys/class/gpio/gpio33/direction");
printf("[3init]gpio_test_init_test_gpio_mode FINISH\n");
}
int mbtk_at_gpio(void* arg)
{
int i, num;
int *fail_io = (int *)arg;
/*OPEN SWITCH */
uint16 test_fail_count = 0;
uint16 test_MAX_pin_num = 0;
char buf[STR_MAX_LEN];
uint16 str_len=0;
uint16 temp_len =0;
uint16 Out_pin;
uint16 in_pin;
uint16 fail_print_num = 0;
gpio_register_set_func_0(125);
gpio_register_set_direction(125, 1);
gpio_register_set_value(125, 1); //开关使能脚
#if 0
/* [2]设置高低电压范围 */
if(th->threshold_high == 0 && th->threshold_low == 0 &&th->threshold_high_low_diff== 0)
{ //use default threshold
th->threshold_high = MBTK_GPIOTEST_THRESHOLD_DEFAULT_HIGH;
th->threshold_low = MBTK_GPIOTEST_THRESHOLD_DEFAULT_LOW;
th->threshold_high_low_diff = MBTK_GPIOTEST_THRESHOLD_DEFAULT_DIFF;
}
RTI_LOG("GPIOTEST: threshold -- %d -- %d -- %d",th->threshold_low,th->threshold_high_low_diff,th->threshold_high);
#endif
/* [3]初始化待测GPIO */
test_MAX_pin_num = sizeof(test_pin_array)/sizeof(test_pin_array[0]);
gpio_test_init_test_gpio_mode(test_pin_array,test_MAX_pin_num);
/* [4]测试过程 */
test_fail_count = mbtk_gpio_test_all_low(test_pin_array,test_MAX_pin_num);
printf("[set_low]set ALL GPIO low, fail_num=%d\n",test_fail_count);
if(!test_fail_count) //set all pin low passed
{
printf("[set all pin low passed]\n");
test_fail_count = mbtk_gpio_test_pin_high(&test_pin_array,test_MAX_pin_num);
}
//memset(buf,0,STR_MAX_LEN);
/* [5]测试结果检测 */
if(test_fail_count )
{
//printf( "GPIOTEST Fail %02d PINs:\n", test_fail_count*2);
sprintf(buf, "GPIOTEST Fail %02d PINs:", test_fail_count*2);
temp_len = strlen(buf);
num = 0;
for(i = 0; i< test_MAX_pin_num; i++)
{
if(test_pin_array[i].mbtk_gpio_test_result)
{
Out_pin = test_pin_array[i].output_pin;
in_pin = test_pin_array[i].input_pin;
fail_io[num++] = Out_pin;
fail_io[num++] = in_pin;
}
}
}
else
{
printf(buf,"ALL GPIO TEST PASS\r\n");
}
//temp_len = strlen(buf);
return test_fail_count * 2;
}
#elif defined(MBTK_PROJECT_L508_X6)
int gpio_register_test_out_0(int port, int value)
{
int ret;
int i;
int valueh = 0;
int valuel = 1;
printf("Gpio port [%d] test start!\n", port);
ret = gpio_register_set_func_0(port); //设功能为GPIO
if(ret){
printf("gpio_port can't support!\n");
return -1;
}
gpio_register_set_direction(port, 1); //设方向为输出
ret = gpio_register_get_value(port);
//printf("gpio default value is : %d.\n", ret);
//[High]
for(i = 0; i <= 10; i++){
gpio_register_set_value(port, 1);
usleep(50);
valueh = gpio_register_get_value(port);
//printf("set high? %d\n",valueh);
if(1 == valueh){
break;
}
}
//usleep(10000);
for(i = 0; i <= 35; i++){
ret = mbtk_gpio_adc(0);
usleep(3000);
if(1 == ret){
break;
}
}
//printf("******gpio should is high: %d.******\n", ret);
if(1 != ret){
ret=-1;
goto exit;
}
//[Low]
usleep(200);
for(i = 0; i <= 10; i++){
gpio_register_set_value(port, 0); //输出低
usleep(50);
valuel = gpio_register_get_value(port);
//printf("set low? %d\n",valuel);
if(0 == valuel){
break;
}
}
//usleep(10000);
for(i = 0; i <= 35; i++){
ret = mbtk_gpio_adc(0);
usleep(3000);
if(0 == ret){
break;
}
}
//printf("******gpio should is low: %d.******\n", ret);
if(0 != ret){
ret=-1;
goto exit;
}
exit:
gpio_register_set_value(port, 0);
gpio_register_set_direction(port, 0); //设方向为输入
return ret;
}
int gpio_register_test_out_1(int port, int value)
{
int ret;
int i;
int valueh = 0;
int valuel = 1;
printf("Gpio port [%d] test start!\n", port);
ret = gpio_register_set_func_0(port); //设功能为GPIO
if(ret){
printf("gpio_port can't support!\n");
return -1;
}
gpio_register_set_direction(port, 1); //设方向为输出
ret = gpio_register_get_value(port);
printf("gpio default value is : %d.\n", ret);
//[High]
for(i = 0; i <= 10; i++){
gpio_register_set_value(port, 1);
usleep(50);
valueh = gpio_register_get_value(port);
//printf("set high? %d\n",valueh);
if(1 == valueh){
break;
}
}
//usleep(10000);
for(i = 0; i <= 35; i++){
ret = mbtk_gpio_adc(1);
usleep(3000);
if(1 == ret){
break;
}
}
if(1 != ret){
ret=-1;
goto exit;
}
//printf("******gpio should is high: %d.******\n", ret);
//[Low]
usleep(200);
for(i = 0; i <= 10; i++){
gpio_register_set_value(port, 0); //输出低
usleep(50);
valuel = gpio_register_get_value(port);
//printf("set low? %d\n",valuel);
if(0 == valuel){
break;
}
}
//usleep(10000);
for(i = 0; i <= 35; i++){
ret = mbtk_gpio_adc(1);
usleep(3000);
if(0 == ret){
break;
}
}
//printf("******gpio should is low: %d.******\n", ret);
if(0 != ret){
ret=-1;
goto exit;
}
exit:
gpio_register_set_value(port, 0);
gpio_register_set_direction(port, 0); //设方向为输入
return ret;
}
int gpio_register_test_out_2(int port_in, int port_out, int value)
{
int ret_in;
int ret_out;
int i;
int valueh = 0;
int valuel = 1;
printf("Gpio port [%d] test start!\n", port_out);
ret_in = gpio_register_set_func_0(port_in); //设功能为GPIO
ret_out = gpio_register_set_func_0(port_out);
if((ret_in+ret_out)){
printf("gpio_port can't support!\n");
return -1;
}
gpio_register_set_direction(port_out, 1); //设方向为输出
gpio_register_set_direction(port_in, 0); //设方向为输入
ret_in = gpio_register_get_value(port_in);
printf("gpio default value is : %d.\n", ret_in);
//[High]
for(i = 0; i <= 10; i++){
gpio_register_set_value(port_out, 1);
usleep(50);
valueh = gpio_register_get_value(port_out);
printf("set high? %d\n",valueh);
if(1 == valueh){
break;
}
}
for(i = 0; i <= 35; i++){
ret_in = gpio_register_get_value(port_in);
usleep(3000);
if(1 == ret_in){
break;
}
}
if(1 != ret_in){
ret_in=-1;
printf("get high failed! \n");
goto exit;
}
printf("******gpio should is high: %d.******\n", ret_in);
//[Low]
usleep(200);
for(i = 0; i <= 10; i++){
gpio_register_set_value(port_out, 0); //输出低
usleep(50);
valuel = gpio_register_get_value(port_out);
printf("set low? %d\n",valuel);
if(0 == valuel){
break;
}
}
for(i = 0; i <= 35; i++){
ret_in = gpio_register_get_value(port_in);
usleep(3000);
if(0 == ret_in){
break;
}
}
printf("******gpio should is low: %d.******\n", ret_in);
if(0 != ret_in){
ret_in=-1;
printf("get low failed! \n");
goto exit;
}
exit:
gpio_register_set_value(port_out, 0);
gpio_register_set_direction(port_out, 0); //设方向为输入
return ret_in;
}
void gpio_test_init_test_gpio_mode(void )
{
int test_gpio_1[] = {
40, 33, 34, 39, 99,
56, 58, 55, 57, 48, 59, 123, 122, 20, 53,
19, 49, 50, 32 ,31, 6, 11, 10,
88, 87, 86, 85, 84, 89,
90, 46, 127, 117, 119,
};
int test_gpio_0[] = {
7, 8, 27, 28, 26, 25, 15, 1, 3, 0,
37, 38,35, 36, 42, 41, 21, 22, 24, 23,
54, 125, 18, 13, 14, 17, 16, 5, 4, 2, 12,
44, 45, 47
};
int i, j, ret_0, ret_1, total_1, total_0, n = 0;
total_0 = (sizeof(test_gpio_0)/sizeof(int));
total_1 = (sizeof(test_gpio_1)/sizeof(int));
//system("at at+gpsinit=0");
system("i2cset -y -f 2 0x32 0x0d 0x00");
system("i2cset -y -f 2 0x31 0x18 0x8f");
usleep(10000);
//printf("[init]gpio_test_init_test_gpio_mode FINISH\n");
/* [1 all gpio set to low] */
for(j = 0; j < 6 ; j++){
for(i = 0; i < total_1; i++){
gpio_register_set_func_0(test_gpio_1[i]);
gpio_register_set_direction(test_gpio_1[i], 1);
gpio_register_set_value(test_gpio_1[i], 0);
}
for(i = 0; i < total_0; i++){
gpio_register_set_func_0(test_gpio_0[i]);
gpio_register_set_direction(test_gpio_0[i], 1);
gpio_register_set_value(test_gpio_0[i], 0);
}
//usleep(10000);
for(i = 0; i <= 35; i++){
ret_0 = mbtk_gpio_adc(0);
usleep(3000);
ret_1 = mbtk_gpio_adc(1);
if(0 == (ret_0 + ret_1)){
break;
}
}
printf("pre set ADC: %d, times: %d\n",(ret_0 + ret_1), j);
if(0 == (ret_0 + ret_1)){
break;
}
}
if(0 != (ret_0 + ret_1)){
printf("Fail, please retest");
return -1;
}
gpio_register_set_value(119, 1);
gpio_register_set_value(117, 1);
}
int mbtk_at_gpio(void* arg)
{
printf("Start test gpio V1.0\n");
int test_gpio_1[] = {
40, 33, 34, 39, 99,
56, 58, 55, 57, 48, 59, 20, 53,
19, 49, 50, 32 ,31, 6, 11, 10,7,
90, 46, 127,
88, 87, 86, 85, 84, 89,
};
int test_gpio_0[] = {
35, 36, 42, 41, 21, 22, 24, 23,
54, 125, 18, 13, 14, 17, 16, 5, 4, 2, 12,0,
27, 28, 26, 25, 15, 1, 3,
37, 38,8
};
int test_gpio_2[] = { //GPS组
43,47,
//45,44
};
int i, j, ret_0, ret_1, ret_2, total_1, total_0, total_2, n = 0;
int *fail_io = (int *)arg;
total_0 = (sizeof(test_gpio_0)/sizeof(int));
total_1 = (sizeof(test_gpio_1)/sizeof(int));
total_2 = (sizeof(test_gpio_2)/sizeof(int));
/* [1 all gpio Init] */
gpio_test_init_test_gpio_mode();
/* [2 GPIOTEST] */
//Test 0
for(i = 0; i < total_0; i++){
ret_0 = gpio_register_test_out_0(test_gpio_0[i], 0);
if(-1 == ret_0){
printf("!!!!!!!!!!!!gpio [%d] test failed!!!!!!!!!!!!\n", test_gpio_0[i]);
fail_io[n] = test_gpio_0[i];
n++;
}else{
//printf("############gpio [%d] test success############\n", test_gpio_0[i]);
}
}
//Test 1
for(i = 0; i < total_1; i++){
ret_1 = gpio_register_test_out_1(test_gpio_1[i], 0);
if(-1 == ret_1){
printf("!!!!!!!!!!!!gpio [%d] test failed!!!!!!!!!!!!\n", test_gpio_1[i]);
fail_io[n] = test_gpio_1[i];
n++;
}else{
//printf("############gpio [%d] test success############\n", test_gpio_1[i]);
}
}
//Test 2
for(i = 0; i < total_2; i=i+2){
ret_2 = gpio_register_test_out_2(test_gpio_2[i], test_gpio_2[i+1], 0);
if(-1 == ret_2){
//printf("!!!!!!!!!!!!gpio [%d] test failed!!!!!!!!!!!!\n", test_gpio_2[i+1]);
fail_io[n] = test_gpio_2[i];
n++;
}else{
printf("############gpio [%d] test success############\n", test_gpio_2[i+1]);
}
}
mbtk_adc_close();
return n;
}
#elif defined(MBTK_PROJECT_T108)
int gpio_register_test_out(int port, int value)
{
int ret;
int i;
int valueh = 0;
int valuel = 1;
//printf("Gpio port [%d] test start!\n", port);
ret = gpio_register_set_func_0(port); //设功能为GPIO
if(ret){
printf("gpio_port can't support!\n");
return -1;
}
gpio_register_set_direction(port, 1); //设方向为输出
//ret = gpio_register_get_value(port);
//printf("gpio default value is: %d\n", ret);
//[High]
for(i = 0; i <= 9; i++){
gpio_register_set_value(port, 1);
usleep(50);
//valueh = gpio_register_get_value(port);
//printf("set high? %d\n", valueh);
if(1 == valueh){
break;
}
}
for(i = 0; i <= 35; i++){
ret = gpio_register_get_value(118);
if(1 == ret){
break;
}
usleep(3000);
}
printf("******gpio should is high: %d.******\n", ret);
if(1 != ret){
ret=-1;
goto exit;
}
//[Low]
usleep(200);
for(i = 0; i <= 9; i++){
gpio_register_set_value(port, 0); //输出低
usleep(50);
//valuel = gpio_register_get_value(port);
//printf("set low? %d\n", valuel);
if(0 == valuel){
break;
}
}
for(i = 0; i <= 35; i++){
ret = gpio_register_get_value(118);
if(0 == ret){
break;
}
usleep(3000);
}
//printf("******gpio should is low: %d.******\n", ret);
if(0 != ret){
ret=-1;
goto exit;
}
exit:
gpio_register_set_value(port, 0);
gpio_register_set_direction(port, 0); //设方向为输入
return ret;
}
int gpio_test_init_test_gpio_mode(void)
{
int test_gpio[] = {
99,
117,
21,22,23,24,44,41,120,
8,127,46,59,58,57,56,55,48,19,34,33,35,36,49,
50,25,28,26,122,20,10,11,
39,40,37,38,
51,52,31,32,
};
int i, j, ret, total, n = 0;
total = (sizeof(test_gpio)/sizeof(int));
printf("[init]gpio_test_init_test_gpio_mode BEGIN\n");
/* [1 all gpio set to low] */
//system("echo 118 > /sys/class/gpio/unexport");
//system("echo 118 > /sys/class/gpio/export");
gpio_register_set_func_0(118);
gpio_register_set_direction(118, 0);
system("echo in > /sys/class/gpio/gpio118/direction");
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);
//ret = gpio_register_get_value(test_gpio[i]);
//printf("[init]get gpio%d=%d\n", test_gpio[i], ret);
}
//system("hwacc w 0xd401e1ac 0x1040"); //52
for(i = 0; i <= 35; i++){
ret = gpio_register_get_value(118);
printf("[init]get gpi118=%d\n", ret);
usleep(3000);
if(0 == (ret)){
break;
}
}
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");
return -1;
}
return 0;
}
int mbtk_at_gpio(void* arg)
{
int test_gpio[] = {
99,
117,
21,22,23,24,44,41,120,
8,127,46,59,58,57,56,55,48,19,34,33,35,36,49,
50,25,28,26,122,20,10,11,
39,40,37,38,
51,52,31,32,
};
int i, n = 0, ret, total;
int *fail_io = (int *)arg;
total = (sizeof(test_gpio)/sizeof(int));
printf("T108 Start test gpio V1.0, total gpio=%d\n", total);
/* [1 all gpio Init] */
gpio_test_init_test_gpio_mode();
/* [2 GPIOTEST] */
for(i = 0; i < total; i++){
ret = gpio_register_test_out(test_gpio[i], 0);
if(-1 == ret){
printf("!!!!!!!!!!!!gpio [%d] test failed!!!!!!!!!!!!\n", test_gpio[i]);
fail_io[n] = test_gpio[i];
n++;
}else{
//printf("############gpio [%d] test success############\n", test_gpio[i]);
}
}
return n;
}
#else
int mbtk_at_gpio(void* arg)
{
return -1;
}
#endif