错误信息查看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的版本后无法控制。