错误信息查看GPIO

wylqx 2014-01-13 10:48:34
GPIO测试程序(device/hisilicon/godbox/driver/sdk/sample/ecs/sample_gpio.c)

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#include <errno.h>

#include <string.h>

#include <sys/types.h>

#include <sys/socket.h>

#include <netinet/in.h>

#include <arpa/inet.h>

#include <string.h>

#include <pthread.h>



#include <assert.h>

#include <linux/fb.h>

#include <sys/mman.h>

#include <sys/ioctl.h>

#include <fcntl.h>

#include <unistd.h>



#include "hi_unf_ecs.h"



#define MULIT_CONFIG_BASE 0x10203000





#define SIM0_GPIO (MULIT_CONFIG_BASE + 0x09C)

#define TEST_GPIO_NUM (11*8+6) //(10*8+1) // run this by John

// à 控制GPIO Pin 1-2, 1-3

#define TEST_GPIO_NUM_OUT1 (1*8+2) // test by John

#define TEST_GPIO_NUM_OUT2 (1*8+3) // test by John



static HI_U32 g_u32GpioConfigValue[3] = {0};





/* you need make sure the multi-purpose pin config gpio mode before using gpio function.configing register please reference hardware user manual*/

static HI_VOID ConfigGpioPinMux(void)

{

HI_SYS_ReadRegister(SIM0_GPIO, &g_u32GpioConfigValue[0]); /*store old pin function define */

HI_SYS_WriteRegister(SIM0_GPIO, 0x0); /*config 0x1020309c is 0x0 ,gpio10_1 */

}



/* you don't resume the pin function if the pin all use to gpio,otherwise you deed resume the pin functin with old function*/

static HI_VOID RestoreGpioPinMux(void)

{

HI_SYS_WriteRegister(SIM0_GPIO, g_u32GpioConfigValue[0]); /* resume the pin functin with old function */

}



HI_S32 main(int argc, char *argv[])

{

HI_S32 Ret;

HI_CHAR u8IntTestFlag;

HI_BOOL read_level;

int pp;

HI_BOOL state;



ConfigGpioPinMux();



Ret = HI_UNF_GPIO_Open();

if (HI_SUCCESS != Ret)

{

printf("%s: %d ErrorCode=0x%x\n", __FILE__, __LINE__, Ret);

goto ERR0;

}



Ret = HI_UNF_GPIO_SetDirBit(TEST_GPIO_NUM, HI_TRUE); //set gpio direction is input

if (HI_SUCCESS != Ret)

{

printf("%s: %d ErrorCode=0x%x\n", __FILE__, __LINE__, Ret);

goto ERR1;

}



// à set GPIO output mode

Ret = HI_UNF_GPIO_SetDirBit(TEST_GPIO_NUM_OUT1, HI_FALSE); //set gpio direction is output

if (HI_SUCCESS != Ret)

{

printf("%s: %d ErrorCode=0x%x\n", __FILE__, __LINE__, Ret);

goto ERR1;

}



Ret = HI_UNF_GPIO_SetDirBit(TEST_GPIO_NUM_OUT2, HI_FALSE); //set gpio direction is output

if (HI_SUCCESS != Ret)

{

printf("%s: %d ErrorCode=0x%x\n", __FILE__, __LINE__, Ret);

goto ERR1;

}

// à Test 10 次

for(pp=0;pp<10;pp++){

// read GPIO 11-6

Ret = HI_UNF_GPIO_ReadBit(TEST_GPIO_NUM, &read_level);

if (HI_SUCCESS != Ret) {

printf("%s: %d ErrorCode=0x%x\n", __FILE__, __LINE__, Ret);

goto ERR1;

}



if( read_level == HI_TRUE )

printf("%s: %d -> TEST_GPIO_NUM is high \n", __FILE__, __LINE__);

else if( read_level == HI_FALSE )

printf("%s: %d -> TEST_GPIO_NUM is low \n", __FILE__, __LINE__);

else

printf("%s: %d -> TEST_GPIO_NUM is other \n", __FILE__, __LINE__);



// control high/low state

if( pp%2 == 0 )

state = HI_TRUE; // LED 灭

else

state = HI_FALSE; // LED 亮

// set GPIO 1-2

Ret = HI_UNF_GPIO_WriteBit(TEST_GPIO_NUM_OUT1, state);

if (HI_SUCCESS != Ret) {

printf("%s: %d ErrorCode=0x%x\n", __FILE__, __LINE__, Ret);

}



// set GPIO 1-3

Ret = HI_UNF_GPIO_WriteBit(TEST_GPIO_NUM_OUT2, state);

if (HI_SUCCESS != Ret) {

printf("%s: %d ErrorCode=0x%x\n", __FILE__, __LINE__, Ret);

}



sleep(1);

}



printf("input any other key to exit sample_gpio.\n");

u8IntTestFlag = getchar();



ERR1:

Ret = HI_UNF_GPIO_Close();

if (HI_SUCCESS != Ret)

{

printf("%s: %d ErrorCode=0x%x\n", __FILE__, __LINE__, Ret);

return Ret;

}



ERR0:

RestoreGpioPinMux();



return Ret;

}




以上测试程序会控制主板两颗LED闪灭显示,实测在SPC053的版本可正常运作,但改为SDK060的版本后无法控制。


...全文
219 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wylqx 2014-01-14
  • 打赏
  • 举报
回复
由于使用的是 gpio1_2 ,gpio1_3 ,根据代码发现,没有对 gpio1_2,gpio1_3 进行复用寄存器设置。 gpio1 管脚默认为0 ,复用到gpio 功能。 估计在 spc050 版本上 ,没有任何操作此管脚,所以gpio能用,在 spc060上被其他功能占用,所以才导致这类问题。 gpio 管脚使用前,必须先设置复用。请跟硬件确认怎样将 gpio1_2, gpio1_3 复用到 gpio 功能。

23,407

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧