1.优化启动速度

This commit is contained in:
payton 2023-07-28 17:50:13 +08:00
parent 4614891001
commit 2cf462da0c
5 changed files with 145 additions and 97 deletions

View File

@ -96,44 +96,7 @@ int test_sd_free(void)
return 0; return 0;
} }
UINT8 sf_check_power_on_mode(void)
{
FILE *fp = NULL;
UINT32 u32ize = 0;
char *pStrSrc = NULL;
char *pStrOtsOk = "Mode=";
char *temp = NULL;
UINT8 startup = 0;
system("cat /proc/cmdline > /tmp/Mode.txt");
fp = fopen("/tmp/Mode.txt","r");
if(fp == NULL){
return FALSE;
}
fseek(fp, 0, SEEK_END);
u32ize = ftell(fp); // take file size
fseek(fp, 0, SEEK_SET); // move to position zero
pStrSrc = (char *)malloc(u32ize*sizeof(char));
if (pStrSrc) {
fread(pStrSrc, 1, u32ize, fp);
temp = strstr(pStrSrc, pStrOtsOk);
if ( temp != NULL) {
temp += strlen("Mode=");
sscanf(temp, "%hhd", &startup);
printf("%s: PowerOnModeStr=%d\r\n", __func__,startup);
//printf("%s: temp=%s\r\n", __func__,temp);
}
free(pStrSrc);
}
fclose(fp);
fp = NULL;
pStrSrc = NULL;
u32ize = 0;
return startup;
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
printf("*********************************************\n"); printf("*********************************************\n");
@ -143,17 +106,25 @@ int main(int argc, char *argv[])
printf("*********************************************\n"); printf("*********************************************\n");
//gpio_direction_input(C_GPIO(10)); //gpio_direction_input(C_GPIO(10));
SINT16 startup = 0; SINT16 startup = 0;
SINT32 UpdateTime = 0; //SINT32 UpdateTime = 0;
SINT32 isUsb = 0;
SINT32 isCard = 0;
SINT32 isUpdate = 0;
//SF_MESSAGE_BUF_S stMessageBuf = {0}; //SF_MESSAGE_BUF_S stMessageBuf = {0};
//BOOL autosend = FALSE; //BOOL autosend = FALSE;
SF_MUTEX_INIT_LOCK(Param_mutexLock); SF_MUTEX_INIT_LOCK(Param_mutexLock);
SF_MUTEX_INIT_LOCK(GPIO_mutexLock); SF_MUTEX_INIT_LOCK(GPIO_mutexLock);
//test_sd_free(); //test_sd_free();
//return 0; //return 0;
SINT32 isUsb = sf_usb_IsInsert();
SINT32 isCard = sf_in_card_exist(); sf_app_mcu_para_start();
SINT32 isUpdate = sf_in_update();
printf("[%s:%d] isUsb = %d isCard = %d isUpdate:%d\n", __FUNCTION__, __LINE__, isUsb,isCard,isUpdate); isUsb = sf_usb_IsInsert();
isCard = sf_in_card_exist();
isUpdate = sf_in_update();
sf_set_fw_update(isUpdate);
if(!isUsb) if(!isUsb)
{ {
sf_app_load_ko_start(); sf_app_load_ko_start();
@ -166,29 +137,21 @@ int main(int argc, char *argv[])
//app_led_group_register(); //app_led_group_register();
app_message_recv_start(); app_message_recv_start();
sf_poweron_type_set(sf_check_power_on_mode());
sf_mcu_flag_init();
sf_mcu_init();
startup = sf_poweron_type_get();
if((SF_MCU_STARTUP_NORMAL != startup) && (!isUsb)){
sf_get_power_on_mode();
sf_mcu_wdg_set(30);
}
sf_led_init(); sf_led_init();
sf_customer_param_load(); sf_customer_param_load();
sf_app_para_check_start(); sf_app_para_check_start();
UIMenuStoreInfo *puiPara = sf_app_ui_para_get(); UIMenuStoreInfo *puiPara = sf_app_ui_para_get();
startup = sf_poweron_type_get();
printf("[%s:%d] isUsb = %d isCard = %d isUpdate:%d CamMode:%d startup:%d %s\n", __FUNCTION__, __LINE__, isUsb,isCard,isUpdate,puiPara->CamMode, startup, sf_poweron_type_string(startup));
printf("[%s:%d] CamMode:%d\n", __FUNCTION__, __LINE__,puiPara->CamMode); if((!isUsb) && (SF_MCU_STARTUP_NORMAL != startup) /*&& (0 == isUpdate)*/)
if((!isUsb) && (SF_MCU_STARTUP_NORMAL != startup))
{ {
//sf_usb_mux_s(1); #if SF_IQ_TEST != ENABLE
//sf_load_ko(); sf_4G_usb_init();
sf_mcu_reg_set(SF_MCU_CTRL_MODULE_PIR, 1); app_RegisterNet_start();
#endif
sf_app_battery_start(); sf_app_battery_start();
} }
@ -196,13 +159,20 @@ int main(int argc, char *argv[])
//sf_app_data_ready_start(); //sf_app_data_ready_start();
//sf_set_fw_update(isUpdate);
sf_sys_status_led_set(SF_LED_SYS_STATE_PIR_NOT_DETECT); if(isUsb){
sf_sys_status_led_set(SF_LED_SYS_STATE_NORMAL); sf_sys_status_led_set(SF_LED_SYS_STATE_USB_IN);
}
else{
sf_sys_status_led_set(SF_LED_SYS_STATE_PIR_NOT_DETECT);
sf_sys_status_led_set(SF_LED_SYS_STATE_NORMAL);
}
if((startup == SF_MCU_STARTUP_NORMAL) && (!isUsb))
{
app_auto_poweroff_start();
}
struct sigaction sigAction; struct sigaction sigAction;
sigAction.sa_handler = sf_signalStop; sigAction.sa_handler = sf_signalStop;
sigemptyset(&sigAction.sa_mask); sigemptyset(&sigAction.sa_mask);
@ -214,34 +184,9 @@ int main(int argc, char *argv[])
sigaction(SIGTERM, &sigAction, NULL); //-15 sigaction(SIGTERM, &sigAction, NULL); //-15
//app_led_pin_init(); //app_led_pin_init();
//app_upgrade_sd_execute(); //app_upgrade_sd_execute();
app_preinit(); //app_preinit();
startup = sf_poweron_type_get();
if(SF_MCU_STARTUP_ONKEY == startup)
{
//sf_wifi_app_start();
}
#if SF_IQ_TEST != ENABLE
if(1 == isUpdate) //SLOGD("poweron type beginning :[%d,%s]\n", startup, sf_poweron_type_string(startup));
{
while (20 > UpdateTime)
{
if(1 == sf_get_fw_update())//check if update
{
printf("[%s:%d] FwUpdate:%d\n", __FUNCTION__, __LINE__,sf_get_fw_update());
break;
}
UpdateTime++;
sf_sleep_ms(500);
}
}
if((!isUsb) && (0 == sf_get_fw_update()) && (SF_MCU_STARTUP_NORMAL != startup) && (SF_ON == puiPara->GprsSwitch))
{
app_RegisterNet_start();
}
#endif
SLOGD("poweron type beginning :[%d,%s]\n", startup, sf_poweron_type_string(startup));
/*if(SF_MCU_STARTUP_ONKEY != startup) /*if(SF_MCU_STARTUP_ONKEY != startup)
{ {
sf_share_mem_file_init(); sf_share_mem_file_init();

View File

@ -727,7 +727,7 @@ static SINT32 sf_app_proccess_cmd_mcu(SF_MESSAGE_BUF_S *pMessageBuf)
startup = sf_poweron_type_get(); startup = sf_poweron_type_get();
if(SF_MCU_STARTUP_NORMAL != startup){ if(SF_MCU_STARTUP_NORMAL != startup){
sf_get_power_on_mode(); sf_get_power_on_mode();
stMessageBuf.arg3 = (SINT32)sf_mcu_get_irshtter(); stMessageBuf.arg3 = (SINT32)sf_get_light_value();
} }
stMessageBuf.arg1 = SF_MCU_CMD_POWERON; stMessageBuf.arg1 = SF_MCU_CMD_POWERON;

View File

@ -42,6 +42,7 @@
#include <dirent.h> #include <dirent.h>
#include "sf_file.h" #include "sf_file.h"
#include "sf_hal_ttyusb.h" #include "sf_hal_ttyusb.h"
#include "sf_commu_mcu.h"
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
extern "C" { extern "C" {
@ -117,6 +118,11 @@ SF_THREAD_S UsbKoTskCfg =
.IsRun = 0, .IsRun = 0,
.TskId = -1, .TskId = -1,
}; };
SF_THREAD_S McuParaTskCfg =
{
.IsRun = 0,
.TskId = -1,
};
SINT8 debugFlag = 0; SINT8 debugFlag = 0;
@ -1220,11 +1226,14 @@ void* sf_sys_do_4g_upgrade(void *arg)
sf_set_module_update(0); sf_set_module_update(0);
sf_sleep_ms(1000); sf_sleep_ms(1000);
//Ux_PostEvent(NVTEVT_SYSTEM_SHUTDOWN, 1, 0); //Ux_PostEvent(NVTEVT_SYSTEM_SHUTDOWN, 1, 0);
sf_set_power_off_flag(1); if(PWR_ON_SETUP == sf_poweron_type_get()){
SF_MESSAGE_BUF_S stMessageBuf = {0}; sf_set_power_off_flag(1);
stMessageBuf.cmdId = CMD_POWEROFF; SF_MESSAGE_BUF_S stMessageBuf = {0};
stMessageBuf.arg1 = APP_POWER_OFF_NORMAL; stMessageBuf.cmdId = CMD_POWEROFF;
sf_com_message_send_to_cardv(&stMessageBuf); stMessageBuf.arg1 = APP_POWER_OFF_NORMAL;
sf_com_message_send_to_cardv(&stMessageBuf);
}
} }
@ -1259,7 +1268,6 @@ void* sf_app_load_ko_thread(void *arg)
UsbKoTskCfg.IsRun = 1; UsbKoTskCfg.IsRun = 1;
sf_load_ko(); sf_load_ko();
UsbKoTskCfg.IsRun = 0; UsbKoTskCfg.IsRun = 0;
SLOGI("thread end\n"); SLOGI("thread end\n");
@ -1300,3 +1308,96 @@ SINT32 sf_app_load_ko_stop(void)
} }
return SF_SUCCESS; return SF_SUCCESS;
} }
UINT8 sf_check_power_on_mode(void)
{
FILE *fp = NULL;
UINT32 u32ize = 0;
char *pStrSrc = NULL;
char *pStrOtsOk = "Mode=";
char *temp = NULL;
UINT8 startup = 0;
system("cat /proc/cmdline > /tmp/Mode.txt");
fp = fopen("/tmp/Mode.txt","r");
if(fp == NULL){
return FALSE;
}
fseek(fp, 0, SEEK_END);
u32ize = ftell(fp); // take file size
fseek(fp, 0, SEEK_SET); // move to position zero
pStrSrc = (char *)malloc(u32ize*sizeof(char));
if (pStrSrc) {
fread(pStrSrc, 1, u32ize, fp);
temp = strstr(pStrSrc, pStrOtsOk);
if ( temp != NULL) {
temp += strlen("Mode=");
sscanf(temp, "%hhd", &startup);
printf("%s: PowerOnModeStr=%d\r\n", __func__,startup);
//printf("%s: temp=%s\r\n", __func__,temp);
}
free(pStrSrc);
}
fclose(fp);
fp = NULL;
pStrSrc = NULL;
u32ize = 0;
return startup;
}
void* sf_app_mcu_para_thread(void *arg)
{
SLOGI("thread run\n");
McuParaTskCfg.IsRun = 1;
SINT32 isUsb = sf_usb_IsInsert();
sf_poweron_type_set(sf_check_power_on_mode());
sf_mcu_flag_init();
sf_mcu_init();
if((SF_MCU_STARTUP_NORMAL != sf_poweron_type_get()) && (!isUsb)){
sf_get_power_on_mode();
sf_mcu_wdg_set(5);
}
McuParaTskCfg.IsRun = 0;
SLOGI("thread end\n");
return NULL;
}
SINT32 sf_app_mcu_para_start(void)
{
SINT32 ret = SF_FAILURE;
if(McuParaTskCfg.IsRun)
{
SLOGE("thread has already run !!!\n");
return SF_FAILURE;
}
ret = pthread_create(&McuParaTskCfg.TskId, NULL, sf_app_mcu_para_thread, NULL);
if(ret != SF_SUCCESS)
{
MLOGD("thread creat fail!\n");
return ret;
}
return SF_SUCCESS;
}
SINT32 sf_app_mcu_para_stop(void)
{
UINT16 ret = 0;
MLOGD("s\n");
if(0 == McuParaTskCfg.IsRun){
return SF_SUCCESS;
}
McuParaTskCfg.IsRun = 0;
ret = pthread_join(McuParaTskCfg.TskId, NULL);
if(ret != SF_SUCCESS)
{
MLOGD("thread stop fail!\n");
return ret;
}
return SF_SUCCESS;
}

View File

@ -1062,8 +1062,8 @@ void sf_mcu_version_get(UINT8 *mcuVer)
*************************************************/ *************************************************/
UINT8 sf_get_power_on_mode(void) UINT8 sf_get_power_on_mode(void)
{ {
static UINT8 ModeFlag = 1; static UINT8 ModeFlag = 0;
if(ModeFlag) if(!ModeFlag)
{ {
ModeFlag = sf_mcu_power_on_para_get(SF_MCU_POWERON); ModeFlag = sf_mcu_power_on_para_get(SF_MCU_POWERON);
} }

View File

@ -687,6 +687,7 @@ void sf_set_power_off_flag(UINT8 flag)
*************************************************/ *************************************************/
UINT8 sf_get_power_on_mode(void) UINT8 sf_get_power_on_mode(void)
{ {
#if HUNTING_CAMERA_4G != ENABLE
static int ModeFlag = 1; static int ModeFlag = 1;
if(ModeFlag) if(ModeFlag)
{ {
@ -698,6 +699,7 @@ UINT8 sf_get_power_on_mode(void)
ConfigureModeFlag = 1; ConfigureModeFlag = 1;
} }
} }
#endif
return PowerOnMode; return PowerOnMode;
} }