142 lines
4.1 KiB
C
142 lines
4.1 KiB
C
/********************************************************************************
|
||
Copyright (C), Sinowealth Electronic. Ltd.
|
||
Author: Sino
|
||
Version: V0.0
|
||
Date: 2020/04/26
|
||
History:
|
||
V2.0 2020/04/26 Preliminary
|
||
********************************************************************************/
|
||
#include "Main.h"
|
||
#include "stdio.h"
|
||
|
||
// 发送字符串
|
||
char putchar(char c)
|
||
{
|
||
REN = 0; // 开启发送
|
||
IO_485_DE = 1; // 开启485发送
|
||
SBUF = c; // 发
|
||
while(!TI);
|
||
IO_485_DE = 0; // 关闭485发送
|
||
TI = 0;
|
||
return c;
|
||
}
|
||
|
||
/*************************************************************************************************
|
||
* 函数名: main
|
||
* 参 数: 无
|
||
* 返回值: 无
|
||
* 描 述: 主函数,当初始化结束后,程序会在While(1)中死循环
|
||
1.可通过定时器来触发各个功能模块的执行
|
||
2.可通过其他中断源来触发对应模块的执行
|
||
*************************************************************************************************/
|
||
void main(void)
|
||
{
|
||
Initial(); //初始化系统
|
||
|
||
// printf("SystemClock: 8MHz");
|
||
|
||
while(1)
|
||
{
|
||
//KeyProcess(); //按键处理
|
||
|
||
if(bTimer50msFlg) //50mS处理和AFE相关的数据采集、计算、保护等
|
||
{
|
||
McuWDTClear(); //定时清狗
|
||
|
||
bTimer50msFlg = 0;
|
||
AFEInfoProcess(); //获取AFE信息,计算电压、温度、电流
|
||
|
||
BalanceProcess(); //平衡及断线处理
|
||
|
||
ProtectProcess(); //电压、电流、温度保护
|
||
|
||
PorSelfTest(); //第一次上电保护检测(延时较短,暂定50mS一次检测)
|
||
|
||
LoadCheck(); //检测负载是否释放
|
||
|
||
ChgerCheck(); //检测充电器是否释放
|
||
|
||
MosCtrl(); //MOS状态检测及控制
|
||
|
||
ProtectOCRecover(); //过流保护自恢复
|
||
|
||
//LedDisplay(); //LED显示
|
||
|
||
#if (UART0_DEFINE != 0)
|
||
Uart0Check(); //检查UART0是否正常,如果不正常,则复位指针向量
|
||
#endif
|
||
|
||
#if (UART1_DEFINE != 0)
|
||
Uart1Check(); //检查UART1是否正常,如果不正常,则复位指针向量
|
||
#endif
|
||
|
||
#if (UART2_DEFINE != 0)
|
||
Uart2Check(); //检查UART2是否正常,如果不正常,则复位指针向量
|
||
#endif
|
||
}
|
||
|
||
if(bTimer1sFlg) //1s定时周期
|
||
{
|
||
IO_LED = ~IO_LED; //LED
|
||
|
||
// printf("\r\n");
|
||
// printf("BAT0:%.2f mV\r\n", AFE.uiCell[0]*1.0*CALIVOL/E2uiVPackGain);
|
||
// printf("BAT1:%.2f mV\r\n", AFE.uiCell[1]*1.0*CALIVOL/E2uiVPackGain);
|
||
// printf("BAT2:%.2f mV\r\n", AFE.uiCell[2]*1.0*CALIVOL/E2uiVPackGain);
|
||
// printf("BAT3:%.2f mV\r\n", AFE.uiCell[3]*1.0*CALIVOL/E2uiVPackGain);
|
||
// printf("BAT4:%.2f mV\r\n", AFE.uiCell[4]*1.0*CALIVOL/E2uiVPackGain);
|
||
// printf("TOTAL:%.2f mV\r\n",(AFE.uiCell[1]+AFE.uiCell[2]+AFE.uiCell[3]+AFE.uiCell[4])*1.0*CALIVOL/E2uiVPackGain);
|
||
//
|
||
// printf("\r\n");
|
||
// printf("TEMP I0:%.2f C\r\n", AFE.uiICTempe[0]*17.0/100.0-270);
|
||
// printf("TEMP I1:%.2f C\r\n", AFE.uiICTempe[1]*17.0/100.0-270);
|
||
// printf("TEMP E0:%.2f C\r\n", AFE.uiTS[0]*1.0);
|
||
// printf("TEMP E1:%.2f C\r\n", AFE.uiTS[1]*1.0);
|
||
//
|
||
// printf("\r\n");
|
||
// printf("CURR I1:%.2f mA\r\n", AFE.siCurr*1000.0*1000.0/16384/5);
|
||
// printf("\r\nBSTATUS:%x\r\n", REG.AFEBSTATUS);
|
||
|
||
bTimer1sFlg = 0;
|
||
GasGaugeManage(); //Calculate the battery charge and discharge capacity
|
||
|
||
AFERamCheck(); //检测AFE寄存器是否误写
|
||
|
||
AFETwiCheck(); //检测AFE有无连续5S通讯错误
|
||
E2PRomTwiCheck(); //检测EEPROM有无连续5S通讯错误
|
||
RTCTwiCheck(); //检测RTC有无连续5S通讯错误
|
||
|
||
if(!RamCheckProcess()) //检测参数变量区是否误写
|
||
{
|
||
SysParaInit();
|
||
}
|
||
|
||
McuFlashWrWaitCheck(); //检测是否需要更新参数到MCU Flash
|
||
|
||
E2PRomBKCheck(); //备份EEPROM
|
||
|
||
//LowPowerCheck(); //低功耗检测
|
||
|
||
|
||
}
|
||
|
||
SystemResetProcess(); //系统复位
|
||
|
||
ISPProcess(); //在线升级代码
|
||
|
||
CaliProcess(); //校准
|
||
|
||
McuFlashProcess(); //备份参数到MCU Flash区
|
||
|
||
E2PRomBKProcess(); //外挂EEPROM备份
|
||
|
||
//LowPowerProcess(); //低功耗处理
|
||
|
||
Info.uiPackStatus = uiPackStatus; //更新PACK和Battery的信息,可通过UART反馈给主机
|
||
Info.uiBatStatus = uiBatStatus;
|
||
|
||
}
|
||
}
|
||
|
||
|
||
|