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

216 lines
5.2 KiB
C
Raw Permalink 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 : void LED_Display_App(void)
* Description : 5ms调用周期
* Input : None
* Output : None
* Return : None
* Note : None
*****************************************************************************/
/*
充电:
1、充电中无其它行为打断时开关盒状态下都显示充电常亮灯效1Hz闪烁
2、充满常亮可被其它灯效打断
非充电:
1、首次使用开盖灯效①高电亮4s后灭②低电1Hz闪4s后灭
2、非首次使用开盖灯效①耳机在盒亮4s后灭②耳机不在盒
③充电中,开盖闪一下,如何闪?亮多久后灭?
3、关盖灯效高电亮4s后灭低电1Hz闪4s后灭
4、关盒状态下无灯效显示
*/
void LED_Display_App(void)
{
}
/*****************************************************************************
* 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
Vox_Det_Machine();
#endif
}
if( F_sys_tim_1s )
{
F_sys_tim_1s = 0;
#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 0
/*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 */
/* 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
SFRADDR = ADC_CTL0;
SFRDATA &= ~0x80; //ADC Disable.
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
}
}