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

220 lines
4.8 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
\******************************************************************************/
/******************************************************************************\
Functions definitions
\******************************************************************************/
/*
*******************************************************************************
* void System_Drivers_Machine(void)
*
* Description : 系统驱动相关程序处理。 (最小5ms调用周期)
*
* Arguments : NONE
* Returns : NONE
* Notes : NONE
*
*******************************************************************************
*/
#if 0
void System_Drivers_Machine(void)
{
#if KEY_HALL_ENABLE
Key_Handler(); //按键检测
Hall_Handler(); //开关盖检测
#endif
#if DISCHARGE_ENABLE
DisCharge_Handler(); //放电boost功能
#endif
#if CHARGER_ENABLE
Charger_Handler(); //充电功能
#endif
}
#endif
/*****************************************************************************
* 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
}
}
if(F_sys_tim_10ms)
{
F_sys_tim_10ms = 0;
#ifdef LED_DISPLAY
LED_Drv();
#endif
}
if(F_sys_tim_100ms)
{
F_sys_tim_100ms = 0;
#if VOX_ENABLE
Vol_Det_Machine();
Vor_Det_Machine();
#endif
}
if( F_sys_tim_1s )
{
F_sys_tim_1s = 0;
/*1、唤醒后工作N s后进入Sleep Mode,N需要大于100ms。
2、有VIN存在的情况下系不会进入sleep mode。
*/
if( Check_Require_Sleep() )
{
if( Decnt_SleepDelay > 0 ) /*能否在数字中实现此功能?*/
{
#ifdef _DEBUG_MAIN
printf("sleep decounter:%d,CHIP_STA1:0x%x\r\n", (uint16_t)Decnt_SleepDelay,(uint16_t)CHIP_STA1);
#endif
Decnt_SleepDelay--;
/*倒数进Sleep Mode过程中出现了中断则重新计时。*/
if( Enter_Sleep_Cnt_Restart_Flag )
{
Enter_Sleep_Cnt_Restart_Flag = 0;
Decnt_SleepDelay = ENTER_STANDBYMODE_CNT;
}
if( Decnt_SleepDelay == 0 )
{
#ifdef _DEBUG_MAIN
printf("Enter Standby Mode!\r\n");
#endif
/*清标志位*/
Protect_Type_Flg = 0;
gIrq_Event_Type = 0;
}
return;
}
//WakeUp_Init_Set(); //唤醒中断使能设置
SFRADDR = WKUP_EN0;
SFRDATA = 0xE4; //wake0 up enable.
SFRADDR = WKUP_EN1;
SFRDATA = 0xFF; //wake1 up enable.
SFRADDR = WKUP_EN3;
SFRDATA = 0xFF; //wake3 up enable.bat low,Timer,VOX loadin\loadon wake up.
//Enter_Sleep();
//InSleep_Handler(); //Disable All IRQ
{
ES0 = 0; //UART0 IRQ Disable
EX4 = 0;
EX3 = 0;
EX2 = 0;
EX7 = 0;
ET0 = 0; //timer0 IRQ Disable
ET1 = 0; //timer1 IRQ Disable
SFRADDR = ADC_CTL0;
SFRDATA &= ~0x80; //ADC Disable.
}
PCON |= 0x02; //Enter StandbyMode, Only int0 or int1 can wake up system
/// OutSleep_Handler(); //Enable IRQ
{
ES0 = 1; //UART0 IRQ
EX4 = 1;
EX3 = 1;
EX2 = 1;
EX7 = 1;
ET0 = 1; //timer0 IRQ
ET1 = 1; //timer1 IRQ
SFRADDR = ADC_CTL0;
SFRDATA |= 0x80; //ADC enable.
}
Decnt_SleepDelay = ENTER_STANDBYMODE_CNT;
}
else
{
Decnt_SleepDelay = ENTER_STANDBYMODE_CNT;
}
#if 0
Vbat_Value(); //获取Bat电压,用于ADC测试
#endif
}
}