SY883x_For_Client_JLAB_JS07/UsrSrc/system/system.c

241 lines
5.6 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
*
*
* @version 1.0
* @date 2022/08/04 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 2022/08/15 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 "gpio_comm.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 = PMU_CTL0; //硬件trim需求。Disable Hall,Enable Key,
SFRDATA |= 0x30;
/*test*/
SFRADDR = P0_PD;
SFRDATA &= ~0x03;
#if UART0_ENABLE
SFRADDR = P0_PU;
SFRDATA = 0x03;
SFRADDR = MFP_CTL0;
SFRDATA = 0x05; //P01 as UART's TX,P00 as UART's RX
BD = 1; //Select additional Baudrate generator
PCON |= 0x80; //Baudrate double enable
//baudrate set
S0RELH = HIBYTE(S0REL_VALUE);
S0RELL = LOBYTE(S0REL_VALUE);//s0rel=1023, baudrate = fclk/32 = 187.5k
S0CON = 0x40; //SCON: MODE 1, 8-bit UART, REN disable
TI0 = 1;
RI0 = 1;
ES0 = 1; //Enable UART0 IRQ
#endif
#if LED_DISPLAY
P01 = 1;
SFRADDR = P0_OE; //Set P03、P04 LED1-LED2,P01 As TX
SFRDATA |= 0x1A;
LED_On_Flag = 1;
#endif
#if VOX_ENABLE
VOX_CTL0 = 0xC3; //VOX 负载接入、存在识别功能使能负载自动识别。打开Vox vds钳压环使能主要用于VOX 5V输出
SFRADDR = VOX_CON0; //设置VOX输出200mA负载识别电流4.5uA。
SFRDATA = (VOX_IOUT_200MA << 3) | VOX_ADT_Cur_4_5UA;
SFRADDR = VOX_CON2; //设置VOX轻重载转换滤波时间。bit3:2 VOX轻载转重载滤波时间bit1:0 VOX重载转轻载滤波时间
SFRDATA |= (VOX_LIGHT_TO_HAVEY_128 << 2) | VOX_HAVEY_TO_LIGHT_8;
#endif
TMOD = 0x01; //mode 1, 16bit timer
TH0 = C_TIM0_Reload >> 8;
TL0 = C_TIM0_Reload & 0xFF;
ET0 = 1; //enable time0 interrupt
TR0 = 1; //time0 run
#ifdef TIMER1_ENABLE
TMOD |= 0x10; //mode 1, 16bit timer
TH1 = C_TIM1_Reload >> 8;
TL1 = C_TIM1_Reload & 0xFF;
ET1 = 1; //enable time1 interrupt
TR1 = 1; //time1 run
#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
#ifdef HALL_ENABLE
#endif
#ifdef NTC_ENABLE
SFRADDR = MFP_CTL1; //Set P07 Pinmux As AD4 Function
SFRDATA |= 0x80;
SFRADDR = ADCCS_CTL0; //AD0~AD4 GPIO constant 20uA current source enable.
SFRDATA = 0x10;
#endif
/* Interrupt Enable 根据应用选择必要的中断 */
SFRADDR = IRQ_EN3; //INT2 --- VOX EDGE LOADON
SFRDATA = 0x3C;
/* 开外部中断使能 */
EX0 = 1;
EX2 = 1;
EAL = 1; //开总中断。
#if CHARGER_ENABLE
#ifdef SY8836 //合封OVP芯片SY8836
SFRADDR = PMU_CTL7; //合封芯片关闭VBUS OV检测使能
SFRDATA &= ~0x20;
SFRADDR = REG_CHG0;
SFRDATA |= 0x04; //合封关VDPM环
#endif
/*如下参数按需更改。*/
REG_CHG1 = CHG_CURRENT_250MA; //设置充电电流 250mA
#endif
}
/*
*******************************************************************************
* 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
{
}
/*
*******************************************************************************
* 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
}