SY8837_Demo_For_OurSelf/UsrSrc/system/system.c

237 lines
5.3 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 system.c
* @brief system module
* @ic sy8837
*
* @version 1.0
* @date 2024/12/02 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 2024/12/02 Alex build this file
* Attention:1、由于同一个Byte的中断标志位会分配在不同的中断中对于清中断标志位写1清不能用 |= ,需要用 =
例如IRQ_FLAG10 = 0x02; //Clear bit0,bit1 interrupt flag
2、外部中断0主要是用于系统唤醒功能中断处理函数中无需作逻辑功能处理必需预留接口
******************************************************************************/
/*_____ I N C L U D E S ____________________________________________________*/
#include "system.h"
#include "adc.h"
#include "hall.h"
#include "key.h"
#include "sleep.h"
#include "uart.h"
#include "bat.h"
#include "sys_tim.h"
#include "charger_module.h"
#include "discharge_module.h"
#include "led.h"
#include "vox_module.h"
#include "watchdog.h"
#include "userapp.h"
#include "pwm.h"
/******************************************************************************\
Macro definitions
\******************************************************************************/
/******************************************************************************\
Variables definitions
\******************************************************************************/
/******************************************************************************\
Functions definitions
\******************************************************************************/
/*
*******************************************************************************
* void System_Init(void)
*
* Description : System Initialization
*
* Arguments : NONE
* Returns : NONE
* Notes : NONE
*
*******************************************************************************
*/
void System_Init(void)
{
SFRADDR = P0_PD; //Disable P00\P01 Pull Down.
SFRDATA = 0x00;
#if UART0_ENABLE
UART0_Init();
#endif
#if UART1_ENABLE
UART1_Init();
#endif
Sys_Tim0_Init();
#if TIMER1_ENABLE
Sys_Tim1_Init();
#endif
#if WTG_ENABLE
/* 65ms */
WDTREL = 0x00; //WDTPS = 0,wdt_f = wdt_f1/2;WDTPS = 1,wdt_f = wdt_f1/32;
/* 1s */
// WDTREL = 0x80; //WDTPS = 0,wdt_f = wdt_f1/2;WDTPS = 1,wdt_f = wdt_f1/32;
#endif
#if VOX_ENABLE
VOX_CTL0 = EN_VOR_VDS | EN_VOL_VDS | EN_VOR_ADTR | EN_VOL_ADTL ; //vox vds 钳压环使能vox Adt Enbale;
SFRADDR = VOX_CON0; //设置VOX负载识别电流4.5uA。见Config.h文件。
SFRDATA = VOX_ADT_CUR_SET;
SFRADDR = VOX_CON2; //设置VOX轻重载转换滤波时间。bit3:2 VOX轻载转重载滤波时间bit1:0 VOX重载转轻载滤波时间
SFRDATA |= (VOX_LIGHT_TO_HAVEY_DEB << 2) | VOX_HAVEY_TO_LIGHT_DEB | VOX_IOFF_CUR_SET ;
#endif
#if ADC_ENABLE
Adc_Init();
#endif
#if KEY_ENABLE
SFRADDR = PMU_CTL0; //Enable Key Det Function
SFRDATA |= 0x02;
#endif
SFRADDR = MFP_CTL0; //Set P00 As Key.
SFRDATA &=~ 0x03;
SFRDATA |= 0x01;
/*
SFRADDR = MFP_CTL1; //Set P06 As Hall.
SFRDATA &=~ 0x30;
SFRDATA |= 0x10;
*/
/* Interrupt Enable 根据应用选择必要的中断 */
SFRADDR = IRQ_EN3; //INT2 --- VOX EDGE LOADON
SFRDATA = 0x3C;
/* 开外部中断使能 */
EX0 = 1;
EAL = 1; //开总中断。
#if CHARGER_ENABLE
Charger_Init();
#endif
#ifdef PWM_ENABLE
PWM_Init_Set(3,PWM_REL_VALUE);
#endif
#ifdef LED_DISPLAY
LED_Init();
LED_Clr();
#endif
#if GAUGE_ENABLE
// Bat_Cal_Init(); //电池电量初始化
#endif
#ifdef SLEEP_ENABLE
WakeUp_Init_Set();
#endif
Systerm_State.Next_State = POWER_ON_STATE;
}
/*
*******************************************************************************
* void EX0_isr(void ) interrupt Interrupt_Vector_IE0
*
* Description : System External Intterupt 0
*
* Arguments : NONE
* Returns : NONE
* Notes : NONE
*
*******************************************************************************
*/
void EX0_isr(void) interrupt Interrupt_Vector_IE0
{
#if SLEEP_ENABLE
Enter_Sleep_Cnt_Restart_Flag = 1;
#endif
}
/*
*******************************************************************************
* void EX2_isr(void) interrupt Interrupt_Vector_IE2
*
* Description : System External Intterupt 2
*
* Arguments : NONE
* Returns : NONE
* Notes : NONE
*
*******************************************************************************
*/
void EX2_isr(void) interrupt Interrupt_Vector_IE2
{
IRQ_FLAG3 = 0x3C;
#if SLEEP_ENABLE
Enter_Sleep_Cnt_Restart_Flag = 1;
#endif
}
/*
*******************************************************************************
* void EX3_isr(void) interrupt Interrupt_Vector_IE2
*
* Description : System External Intterupt 2
*
* Arguments : NONE
* Returns : NONE
* Notes : NONE
*
*******************************************************************************
*/
#ifdef TIM_WKUP
void EX3_isr(void) interrupt Interrupt_Vector_IE3
{
IRQ_FLAG10 = Standby_Tmr_WkUp;
#if SLEEP_ENABLE
Enter_Sleep_Cnt_Restart_Flag = 1;
#endif
}
#endif