一、u-Boot升级灯
运行u-Boot程序时LED灯闪烁,找到运行过程中一直在运行的函数在里面进行LED引脚电平的翻转
宏定义
Z:\SunFan\AHD580\pip\na51055_PIP\BSP\u-boot\include\configs\nvt-na51055-evb.h
Z:\SunFan\AHD580\pip\na51055_PIP\BSP\u-boot\drivers\mtd\nvt_flash_spi\nvt_flash_spi_cmd.c
自带led引脚电平设置函数
/* LED function for FW update*/
static void led_set_gpio_high(int operation)
{
u32 gpio_reg;
int ofs = NVT_LED_RED_PIN/32;
int shift = NVT_LED_RED_PIN & 0x1F;
ofs = ofs*0x4;
/*Set gpio as high*/
gpio_reg = INW(IOADDR_GPIO_REG_BASE + 0x20 + ofs);
#if 0
if (gpio_reg & (1 << shift))
RESTORE_GPIO_DIR = 1;
else {
gpio_reg |= (1 << shift);
OUTW(IOADDR_GPIO_REG_BASE + 0x20 + ofs, gpio_reg);
}
#else
gpio_reg |= (1 << shift);
OUTW(IOADDR_GPIO_REG_BASE + 0x20 + ofs, gpio_reg);
#endif
OUTW(IOADDR_GPIO_REG_BASE + 0x40 + ofs, (1 << shift));
//LED BLUE
ofs = NVT_LED_BLUE_PIN/32;
shift = NVT_LED_BLUE_PIN & 0x1F;
ofs = ofs*0x4;
gpio_reg = INW(IOADDR_GPIO_REG_BASE + 0x20 + ofs);
gpio_reg |= (1 << shift);
OUTW(IOADDR_GPIO_REG_BASE + 0x20 + ofs, gpio_reg);
OUTW(IOADDR_GPIO_REG_BASE + 0x40 + ofs, (1 << shift));
#if 0 // do not use delay!!! it will slow down flash erase/program!!!
/*Config duration*/
if (operation)
mdelay(NVT_LED_PROGRAM_DURATION);
else
mdelay(NVT_LED_ERASE_DURATION);
#endif
}
static void led_set_gpio_low(void)
{
//u32 gpio_reg;
int ofs = NVT_LED_RED_PIN/32;
int shift = NVT_LED_RED_PIN & 0x1F;
ofs = ofs*0x4;
/*Set gpio as low*/
OUTW(IOADDR_GPIO_REG_BASE + 0x60 + ofs, (1 << shift));
//LED BLUE
ofs = NVT_LED_BLUE_PIN/32;
shift = NVT_LED_BLUE_PIN & 0x1F;
ofs = ofs*0x4;
OUTW(IOADDR_GPIO_REG_BASE + 0x60 + ofs, (1 << shift));
#if 0
/*Force gpio direction as original config*/
if (!(RESTORE_GPIO_DIR)) {
gpio_reg = INW(IOADDR_GPIO_REG_BASE + 0x20 + ofs);
gpio_reg &= ~(1 << shift);
OUTW(IOADDR_GPIO_REG_BASE + 0x20 + ofs, gpio_reg);
RESTORE_GPIO_DIR = 0;
}
#endif
}
在spiNand_programPage和nand_cmd_erase_block里面进行计数电平翻转
二、将内容保存在Flash里面
在UIInfo.h(na51055_PIP\code\application\source\cardv\SrcCode\UIWnd\SPORTCAM\UIInfo\UIInfo.h)里面名为UI_IndexInfo的枚举类型定义一个成员用来计数(枚举类型里面的美格成员都是一个唯一的整数值),然后通过SysSetFlag()和SysGetFlag()函数来设置和获取枚举类型成员的值
1、应用场景:ACC断开后震动开机次数计数
(1)在UIInfo.h定义一个名为SF_SHOCKPOWERON_CNT的成员来记录震动开机次数
(2)然后在震动开关机文件里面的函数应用
UIWnd\SPORTCAM\UIFlow\UIFlowMovie\UIFlowWndMovie.c:
每次开机都会跑这个函数,acc接入震动开机计数清零、acc断开开机一次计数值甲乙
System\SysMain_Exe.c:在System_OnShutdown关机函数里面判断计数值是否超过预设值,调用Gsensor_SetSensitivityParking(GSENSOR_OFF);并传入参数GSENSOR_OFF使得下次震动无法开机
// Gsensor_SetSensitivityParking(DrvPower_GetBatteryValue()<210?GSENSOR_OFF:SysGetFlag(FL_GSENSOR));
/*sf begin*/
if((SysGetFlag(SF_SHOCKPOWERON_CNT)>10)||(DrvPower_GetBatteryValue()<210)){
Gsensor_SetSensitivityParking(GSENSOR_OFF);
}else{
Gsensor_SetSensitivityParking(SysGetFlag(FL_GSENSOR));
}
/*sf end*/
三、低电检测
System\SysMain_Exe.c:在System_OnShutdown关机函数里面调用DrvPower_GetBatteryValue通过ADC读取当前电压