SY8835_For_Demo_Ourself/UsrSrc/system/system.c

171 lines
3.7 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 sy8835
*
* @version 1.0
* @date 2024/11/01 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/11/01 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 "gpio.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"
#include "pmu.h"
#include "user.h"
/******************************************************************************\
Macro definitions
\******************************************************************************/
/******************************************************************************\
Variables definitions
\******************************************************************************/
/******************************************************************************\
Functions definitions
\******************************************************************************/
/*
*******************************************************************************
* void System_Init(void)
*
* Description : System Initialization
*
* Arguments : NONE
* Returns : NONE
* Notes : NONE
*
*******************************************************************************
*/
void System_Init(void)
{
#if UART0_ENABLE
UART0_Init();
#endif
#if UART1_ENABLE
UART1_Init();
#endif
#if UART2_ENABLE
UART2_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 ADC_ENABLE
Adc_Init();
#endif
/* Interrupt Enable 根据应用选择必要的中断 */
ExtSfr_Write(IRQ_PIN_CFG,0x08); //pmu 下降沿中断使能;双沿唤醒。
/* 开外部中断使能 */
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
pmu_Init();
I2C_GPIOInit();
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 0
if( IRQ_FLAG&0x01 ) //pmu irq negtive interrupt.
{
IRQ_FLAG = 0x01;
// Get_PMU_Info(&pmu_Info); //获取pmu状态
}
#endif
#if SLEEP_ENABLE
Enter_Sleep_Cnt_Restart_Flag = 1;
#endif
IRQ_FLAG = 0x0F;
}