- 论坛徽章:
- 0
|
/*==================================================================================================
FUNCTION: getGpio()
DESCRIPTION: This function is responsible for handling get GPIO status.
ARGUMENTS PASSED:
TC_GPIO_DATA *gpio_data- Pointer to TC_GPIO_DATA data structure
RETURN VALUE:
void
IMPORTANT NOTES:
None
==================================================================================================*/
int getGpio(TC_GPIO_DATA *gpio_data)
{
char *pos=NULL;
char gpio_str[8], buf[1024];
int ret=-1;
int i;
memset(buf, 0, 1024);
memset(gpio_str, 0, 8);
if( gpio_fp != NULL )
fclose(gpio_fp);
gpio_fp = fopen("/sys/kernel/debug/gp
io","r");
if( !gpio_fp )
{
TCMD_TRACE("Error: can not open debugfs gpio control file\n");
return ret;
}
TCMD_TRACE("Open the file success \n");
TCMD_TRACE("the gpio number is %d :\n",gpio_data->gpio_number);
sprintf(gpio_str,"gpio-%d",gpio_data->gpio_number);
for(i=0;i8;i++)
TCMD_TRACE("%c",gpio_str);
while( fgets(buf, 1024, gpio_fp) )
{
TCMD_TRACE("Begin to parse data information \n");
if( (pos=strstr(buf,gpio_str)) != NULL )
{/* Found */
TCMD_TRACE("Found the current gpio address \n");
pos += strlen(gpio_str);
while( *pos && *pos!=')' )
pos++;
TCMD_TRACE("Begin to parse the detaillll info \n");
if(*pos == ')' )
{
pos+=2; /* bypass ") " */
if( strncmp(pos,"in ",4)==0 )
{
gpio_data->in_out=0;
pos +=4;
}else if(strncmp(pos,"out ",4)==0)
{
gpio_data->in_out=1;
pos +=4;
}else
{
ret = -2;
TCMD_TRACE("can't find the inout flag \n ");
break;
}
if( strncmp(pos, "lo",2)==0 )
{
gpio_data->level=0;
}else if( strncmp(pos,"hi",2)==0 )
{
gpio_data->level=1;
}else
{
ret = -3;
TCMD_TRACE("can't find the hilow flag \n");
break;
}
/* Successful parsed */
ret=0;
TCMD_TRACE("parse success \n");
}
else
{
ret=-4;
TCMD_TRACE("some unexpected error \n");
break;
}
}else
{/* Not found in this line */
TCMD_TRACE("can't find the address in this line \n");
continue;
}
}
fclose(gpio_fp);
gpio_fp = NULL;
TCMD_TRACE("get gpio over \n");
return ret;
}
座在我旁的同事找到了毛病:
1:在寻找文件中时,可能分析找到了对应的gpio,但是不会break退出,而是接着向下寻找:如下中绿线下的部分:
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] Found the current gpio address [14:41:36] Begin to parse the detaillll info [14:41:36] parse success
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:36] Begin to parse data information
[14:41:36] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] Begin to parse data information
[14:41:37] can't find the address in this line
[14:41:37] get gpio over
2另外,在sprintf(gpio_str,"gpio-%d",gpio_data->gpio_number);
如找gpio-2 因为用 if( (pos=strstr(buf,gpio_str)) != NULL )
会找gpio-20中一样,从而可能产生错误,如果第一个问题解决就不会有这个问题。
下面带色就是这个问题:这是因为gpio-20 gpio-21 gpio-22 gpio-23gpio-24 ...29
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] Found the current gpio address [14:47:25] Begin to parse the detaillll info [14:47:25] parse success
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
14:47:25] Found the current gpio address [14:47:25] Begin to parse the detaillll info [[14:47:25] parse success
[14:47:25] Begin to parse data information
[14:47:25] Found the current gpio address [14:47:25] Begin to parse the detaillll info [14:47:25] parse success
[14:47:25] Begin to parse data information
[14:47:25] Found the current gpio address [14:47:25] Begin to parse the detaillll info [14:47:25] parse success
[14:47:25] Begin to parse data information
[14:47:25] Found the current gpio address [14:47:25] Begin to parse the detaillll info [14:47:25] parse success
[14:47:25] Begin to parse data information
[14:47:25] Found the current gpio address [14:47:25] Begin to parse the detaillll info [14:47:25] parse success
[14:47:25] Begin to parse data information
[14:47:25] Found the current gpio address [14:47:25] Begin to parse the detaillll info [14:47:25] parse success
[14:47:25] Begin to parse data information
[14:47:25] Found the current gpio address [14:47:25] Begin to parse the detaillll info [14:47:25] parse success
[14:47:25] Begin to parse data information
[14:47:25] Found the current gpio address [14:47:25] Begin to parse the detaillll info [14:47:25] parse success
[14:47:25] Begin to parse data information
[14:47:25] Found the current gpio address [14:47:25] Begin to parse the detaillll info [14:47:25] parse success
[14:47:25] Begin to parse data information
[14:47:25] Found the current gpio address [14:47:25] Begin to parse the detaillll info [14:47:25] parse success
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:25] can't find the address in this line
[14:47:25] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] can't find the address in this line
[14:47:26] Begin to parse data information
[14:47:26] Found the current gpio address
[14:47:26] Begin to parse the detaillll info
[14:47:26] some unexpected error
[14:47:26] get gpio over
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/63775/showart_1677737.html |
|