Both_Way_Comm_SY8833/TP3310_Demo.si4project/Backup/userapp(1901).c

223 lines
5.0 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
******************************************************************************
*
* @file UserApp.c
* @brief UserApp module
*
*
* @version 1.0
* @date 2023/03/27 15:00:40
* @author Alex Xu
*
* Copyright (c) 2013-2099,Tkplusemi Technology Co.,Ltd.
* All Rights Reserved
*
* History:
* Revision Date Author Desc
* 1.0.0 2023/03/27 Alex build this file
******************************************************************************/
/*_____ I N C L U D E S ____________________________________________________*/
#include "userapp.h"
#include "gpio.h"
#include "adc.h"
#include "hall.h"
#include "key.h"
#include "sleep.h"
#include "system.h"
#include "bat.h"
#include "sys_tim.h"
#include "charger_module.h"
#include "discharge_module.h"
#include "led.h"
#include "vox_module.h"
/******************************************************************************\
Macro definitions
\******************************************************************************/
/******************************************************************************\
Variables definitions
\******************************************************************************/
idata uint8_t bat_level_update = 0;
/******************************************************************************\
Functions definitions
\******************************************************************************/
/*****************************************************************************
* Function : UserAPP
* Description : 5ms调用周期
* Input : None
* Output : None
* Return : None
* Note : None
*****************************************************************************/
void UserAPP(void)
{
if(F_sys_tim_5ms)
{
F_sys_tim_5ms = 0;
#if KEY_HALL_ENABLE
Key_Handler(); //按键检测
Hall_Handler(); //开关盖检测
#endif
#if DISCHARGE_ENABLE
DisCharge_Handler(); //放电boost功能
#endif
#if CHARGER_ENABLE
Charger_Handler(); //充电功能
#endif
}
#ifdef LED_DISPLAY
if(F_sys_tim_10ms)
{
F_sys_tim_10ms = 0;
LED_Drv();
}
#endif
if(F_sys_tim_100ms)
{
F_sys_tim_100ms = 0;
#if ADC_ENABLE
Vbat_Adc = Vbat_Value(); //获取Bat电压
#endif
#if BAT_VALUE
check_bat_level();
#endif
#if VOX_ENABLE
Vol_Det_Machine();
Vor_Det_Machine();
#ifndef BOOST_AOUT
if(( OFF == Vol_Vout_Enable ) && ( OFF == Vor_Vout_Enable ))
{
DisCharge_Boost_Close();
}
#endif
#endif
}
if( F_sys_tim_1s )
{
F_sys_tim_1s = 0;
if (bat_level_update != bat_level)
{
g_188_Num = bat_level * 10;
bat_level_update = bat_level;
}
printf("1s Timer Count.\r\n");
//#ifdef _DEBUG_BAT
printf("bat_level:%d,disnum:%d.\r\n",(uint16_t)bat_level,(uint16_t)g_188_Num);
//#endif
#ifdef DISPLAY_LED_188
#if 0
g_188_Num++;
if(g_188_Num >= 188)
{
g_188_Num = 0;
}
#endif
#endif
#if SLEEP_ENABLE
/*1、唤醒后工作Ns后进入Sleep Mode,N需要大于100ms。
2、有VIN存在的情况下系不会进入sleep mode。
*/
if( Decnt_SleepDelay > 0 ) /*能否在数字中实现此功能?*/
{
Decnt_SleepDelay--;
/*倒数进Sleep Mode过程中出现了KEY\HALL\Loadon\IOFF中断则重新计时。*/
if( Enter_Sleep_Cnt_Restart_Flag )
{
Enter_Sleep_Cnt_Restart_Flag = 0;
Decnt_SleepDelay = ENTER_STANDBYMODE_CNT;
}
#if KEY_HALL_ENABLE
/*todo*/
if( (Event_key == KEY_EVENT_LL_8S) && Decnt_SleepDelay == 0 ) //8s按键后重新倒数计时计时到0系统Software Reset。在倒数过程中出现中断则重新计时。
{
RSTCON = 0xAC;
SRST = 0x01;
}
#endif
#ifdef _DEBUG_MAIN
// printf("sleep decnt:%d,STA0:0x%x,STA1:0x%x,STA2:0x%x,STA3:0x%x,STA4:0x%x\r\n", (uint16_t)Decnt_SleepDelay,(uint16_t)CHIP_STA0,(uint16_t)CHIP_STA1,(uint16_t)CHIP_STA2,(uint16_t)CHIP_STA3,(uint16_t)CHIP_STA4);
printf("sleep decnt:%d,STA0:0x%x,STA1:0x%x,STA2:0x%x,STA4:0x%x\r\n", (uint16_t)Decnt_SleepDelay,(uint16_t)CHIP_STA0,(uint16_t)CHIP_STA1,(uint16_t)CHIP_STA2,(uint16_t)CHIP_STA4);
#endif
return;
}
if( Check_Require_Sleep() )
{
/* 唤醒中断使能设置 */
SFRADDR = WKUP_EN0;
SFRDATA = 0xE6; //wake0 up enable.
SFRADDR = WKUP_EN3;
SFRDATA = 0xFF; //wake3 up enable.bat low,Timer,VOX loadin\loadon wake up.
/* Enter Sleep */
#ifdef DISPLAY_LED_188
Set_AllLed_Down();
#endif
/* InSleep Handler */ //Disable All IRQ
#if UART0_ENABLE
ES0 = 0; //UART0 IRQ Disable
#endif
EX4 = 0;
EX2 = 0;
ET0 = 0; //timer0 IRQ Disable
#if TIMER1_ENABLE
ET1 = 0; //timer1 IRQ Disable
#endif
PCON |= 0x02; //Enter StandbyMode, Only int0 or int1 can wake up system
/* OutSleep Handler */ //Enable IRQ
#if UART0_ENABLE
ES0 = 1; //UART0 IRQ
#endif
EX4 = 1;
EX2 = 1;
ET0 = 1; //timer0 IRQ
#if TIMER1_ENABLE
ET1 = 1; //timer1 IRQ
#endif
Decnt_SleepDelay = ENTER_STANDBYMODE_CNT;
}
else
{
Decnt_SleepDelay = ENTER_STANDBYMODE_CNT;
}
#endif
}
}