Commit fa5f01c5 authored by hu's avatar hu

调整电源管理

parent b69dc729
......@@ -67,6 +67,8 @@
static uint8_t PowerGetNMStatus(void);
extern void SEG_LCD_Window_Switch(uint8_t Sw);
extern void DelayUs(uint32_t time);
extern void Sys_KL30_Init(void);
extern void Sys_Wakeup_Init(void);
Power_Status_t Power_KL30_Init ( void )
{
......@@ -311,7 +313,8 @@ Power_Status_t Power_Stay_ON(void)
u8PowerSts = m_IGN_ON;
}
}
if (((u8Condition3 == 1u) || (u8Condition3 >= 7u)))
//if (((u8Condition3 == 1u) || (u8Condition3 >= 7u)))
if (SYS_OPR_STAT_HALT)
{
u8PowerSts = m_IGN_LIMIT;
}
......
#ifndef SYSTEM_MONITOR_H
#define SYSTEM_MONITOR_H
#include "System_Monitor.h"
#include "TYW_stdint.h"
typedef struct
{
uint8_t SumCnt;
uint16_t DebounceTimer;
uint32_t ActVoltage;
uint8_t FinalSts;
uint8_t ActSts;
} MonitorStruct;
/*
0 ----1st-------6500 不可运行 1
6500 ----2st-------7000 回差段 2
7000 ----3st-------9000 低压段 3
9000 ----4st-------9500 回差段 4
9500-----5st------16000 正常段 5
16000----6st------16500 回差段 6
16500----7st------18000 高压段 7
18000----8st------18500 回差段 8
18500----9st------65535 高压段 9
0-----6.5 不可运行--ALL----------限制
6.5-----9 除电机外均可运行--------正常
9-----16.5 均可运行---------------正常
16.5-----18.5 只有CAN可运行----------限制
18.8-----65535 不可运行--ALL----------限制
6.5-18.5 CAN 可运行区间
*/
/*电源运行状态*/
#define SYS_OPR_STAT_RUN ((System_FUN_KL30_Status_Get() > 1u)&&(System_FUN_KL30_Status_Get() < 7u ))
#define SYS_OPR_STAT_HALT ((System_FUN_KL30_Status_Get() == 1u) || (System_FUN_KL30_Status_Get() >= 7u))
#define SYS_OPR_STAT_LIM_LVP (System_FUN_KL30_Status_Get() == 1U)
#define SYS_OPR_STAT_LIM_OVP (System_FUN_KL30_Status_Get() >= 7u)
/*仪表工作状态*/
#define SYS_OPR_STAT_IGN_ON (System_FUN_KL15_Status_Get() == 1U)
#define SYS_OPR_STAT_IGN_OFF (System_FUN_KL15_Status_Get() == 0U)
/*网络管理电源工作状态*/
#define SYS_OPR_STAT_IGN_ON_NM (System_NM_KL15_Status_Get() == 1U)
#define SYS_OPR_STAT_IGN_OFF_NM (System_NM_KL15_Status_Get() == 0U)
/*网络管理电源运行状态*/
#define SYS_OPR_STAT_RUN_NM ((System_NM_KL30_Status_Get() > 1u) && (System_NM_KL30_Status_Get() < 9u ))
#define SYS_OPR_STAT_HALT_NM ((System_NM_KL30_Status_Get() == 9u) || (System_NM_KL30_Status_Get() == 1u))
static uint8_t System_Calc_FunRange(uint16_t u16Vol);
static uint8_t System_Calc_NMRange(uint16_t u16Vol);
uint8_t Read_KL30_ConvertFinish(void);
static void System_Fun_Process(void);
static void System_NM_Process(void);
void Sys_LogicProcess(void);
void Sys_Status_Update_Service ( void );
uint16_t Sys_Read_KL30_Voltage(void);
uint16_t Sys_Read_KL15_Voltage(void);
uint8_t Sys_Read_KL30_Valid(void);
uint8_t Sys_Read_KL15_Valid(void);
uint16_t Sys_Force_Read_KL30_Voltage(void);
uint16_t Sys_Force_Read_KL15_Voltage(void);
uint8_t System_FUN_KL30_Status_Get(void);
uint8_t System_FUN_KL15_Status_Get(void);
uint8_t System_NM_KL15_Status_Get(void);
uint8_t System_NM_KL30_Status_Get(void);
uint8_t System_LINE_KL15(void);
void Sys_Set_DebounceTimer(uint16_t u16NMKL30, uint16_t u16NMKL15, uint16_t u16FUNKL30, uint16_t u16FUNKL15);
/*void Sys_Set_VolRange(uint16_t FUN_Vol[], uint16_t NM_Vol[]);*/
void Sys_Set_VolRange(const uint16_t FUN_Vol[], const uint16_t NM_Vol[]);
void System_Monitor_KL30Init(void);
void System_Monitor_WakeupInit(void);
void System_Fast_WakeUp(void);
void Sys_KL30_Init (void);
void Sys_WakeUp_Init (void);
void Sys_BlockDelay(uint32_t u32Ms);
void Sys_Rolling(void);
void Sys_RollingClear(void);
uint32_t Sys_Get_ms_Rolling_Counter(void);
#endif
#ifndef SYSTEM__MONITOR__H
#define SYSTEM__MONITOR__H
/* #define Platform_16Bit
#define Platform_32Bit*/
#ifdef Platform_16Bit
#define monitorlib_uint8_t unsigned char
#define monitorlib_uint16_t unsigned int
#define monitorlib_uint32_t unsigned long
#else
#define monitorlib_uint8_t unsigned char
#define monitorlib_uint16_t unsigned short
#define monitorlib_uint32_t unsigned int
#define monitorlib_uint64_t unsigned long long
#endif
/*
0 ----1st-------6500 不可运行 1
6500 ----2st-------7000 回差段 2
7000 ----3st-------9000 低压段 3
9000 ----4st-------9500 回差段 4
9500-----5st------16000 正常段 5
16000----6st------16500 回差段 6
16500----7st------18000 高压段 7
18000----8st------18500 回差段 8
18500----9st------65535 高压段 9
0-----6.5 不可运行--ALL----------限制
6.5-----9 除电机外均可运行--------正常
9-----16.5 均可运行---------------正常
16.5-----18.5 只有CAN可运行----------限制
18.8-----65535 不可运行--ALL----------限制
6.5-18.5 CAN 可运行区间
*/
typedef monitorlib_uint8_t (*Get_Voltage_Vaild)(void);
typedef monitorlib_uint16_t (*Get_Voltage_Value)(void);
typedef monitorlib_uint8_t (*Get_LineInStatus)(void);
typedef void (*COMMON_Delay)(monitorlib_uint32_t mMs);
typedef void (*pfunLogic)(void);
typedef struct
{
Get_Voltage_Vaild SysGet_KL30_Valid;
Get_Voltage_Vaild SysGet_KL15_Valid;
Get_Voltage_Value SysGet_KL30_value_Force;
Get_Voltage_Value SysGet_KL15_value_Force;
Get_Voltage_Value SysGet_KL30_value;
Get_Voltage_Value SysGet_KL15_value;
Get_LineInStatus SysGet_KL15Line;
COMMON_Delay COM_Delay;
pfunLogic SysMonitorLogic;
} MonitorExt_st;
/* SYS RUN Status */
#define SYS_OPR_STAT_RUN ((System_FUN_KL30_Status_Get( ) > 1u) && (System_FUN_KL30_Status_Get( ) < 7u))
#define SYS_OPR_STAT_HALT ((System_FUN_KL30_Status_Get( ) == 3u) || (System_FUN_KL30_Status_Get( ) > 7u))
#define SYS_OPR_STAT_LIM_LVP (System_FUN_KL30_Status_Get( ) == 1U)
#define SYS_OPR_STAT_LIM_OVP (System_FUN_KL30_Status_Get( ) > 7u)
/*fun status*/
#define SYS_OPR_STAT_IGN_ON (System_FUN_KL15_Status_Get( ) == 1U)
#define SYS_OPR_STAT_IGN_OFF (System_FUN_KL15_Status_Get( ) == 0U)
/*nm run status*/
#define SYS_OPR_STAT_IGN_ON_NM (System_NM_KL15_Status_Get( ) == 1U)
#define SYS_OPR_STAT_IGN_OFF_NM (System_NM_KL15_Status_Get( ) == 0U)
/*nm status*/
#define SYS_OPR_STAT_RUN_NM ((System_NM_KL30_Status_Get( ) > 1u) && (System_NM_KL30_Status_Get( ) < 9u))
#define SYS_OPR_STAT_HALT_NM ((System_NM_KL30_Status_Get( ) == 9u) || (System_NM_KL30_Status_Get( ) == 1u))
monitorlib_uint8_t Read_KL30_ConvertFinish(void);
monitorlib_uint16_t Get_Sysmonitor_Version(void);
void Sys_Status_Update_Service(void);
void Sys_Set_Pata(const monitorlib_uint16_t FUN_Vol [], MonitorExt_st *pfunc);
void System_Monitor_KL30Init(void);
void System_Monitor_WakeupInit(void);
void System_XHY_CheckWakeup(void);
monitorlib_uint8_t System_FUN_KL30_Status_Get(void);
monitorlib_uint8_t System_FUN_KL15_Status_Get(void);
monitorlib_uint8_t System_NM_KL15_Status_Get(void);
monitorlib_uint8_t System_NM_KL30_Status_Get(void);
monitorlib_uint8_t System_LINE_KL15(void);
void Sys_WakeUp_Init(void);
#endif
#include "System_Monitor.h"
#include "RTE_ADC.h"
#include "GPIO.h"
#include "dr7f701441.dvf.h"
#include "Watchdog.h"
#include "COM_CAN.h"
#define u16Base_Vol 0u
#define u16ENTER_LOW_N_RANGE 6500U
#define u16EXIT_LOW_N_RANGE 7000U
#define u16ENTER_LOW_Y_RANGE 9000U
#define u16EXIT_LOW_Y_RANGE 9500U
#define u16EXIT_HIGH_Y_RANGE 30000U
#define u16ENTER_HIGH_Y_RANGE 32000U
#define u16EXIT_HIGH_N_RANGE 31000U
#define u16ENTER_HIGH_N_RANGE 33000U
#define u16Top_Vol 0xffffu
uint32_t u32SysRollingCounter;
static const uint16_t SysFun_Range[10u] =
{
u16Base_Vol,
u16ENTER_LOW_N_RANGE,
u16EXIT_LOW_N_RANGE,
u16ENTER_LOW_Y_RANGE,
u16EXIT_LOW_Y_RANGE,
u16EXIT_HIGH_Y_RANGE,
u16ENTER_HIGH_Y_RANGE,
u16EXIT_HIGH_N_RANGE,
u16ENTER_HIGH_N_RANGE,
u16Top_Vol,
};
static const uint16_t SysNM_Range[10u] =
{
u16Base_Vol,
u16ENTER_LOW_N_RANGE,
u16EXIT_LOW_N_RANGE,
u16ENTER_LOW_Y_RANGE,
u16EXIT_LOW_Y_RANGE,
u16EXIT_HIGH_Y_RANGE,
u16ENTER_HIGH_Y_RANGE,
u16EXIT_HIGH_N_RANGE,
u16ENTER_HIGH_N_RANGE,
u16Top_Vol,
};
uint16_t Sys_Force_Read_KL30_Voltage(void)
{
uint16_t u16Voltage;
u16Voltage = (uint16_t)RTE_ForceRead_KL30_Voltage();
return u16Voltage;
}
uint16_t Sys_Force_Read_KL15_Voltage(void)
{
uint16_t u16Voltage;
u16Voltage = (uint16_t)RTE_ForceRead_KL15_Voltage();
return u16Voltage;
}
uint16_t Sys_Read_KL30_Voltage(void)
{
uint16_t u16Voltage;
u16Voltage = (uint16_t)RTE_Read_KL30_Voltage();
return u16Voltage;
}
uint16_t Sys_Read_KL15_Voltage(void)
{
uint16_t u16Voltage;
u16Voltage = (uint16_t)RTE_Read_KL15_Voltage();
return u16Voltage;
}
uint8_t Sys_Read_KL30_Valid(void)
{
uint8_t u8Valid;
u8Valid = RTE_Read_KL30_Valid();
return u8Valid;
}
uint8_t Sys_Read_KL15_Valid(void)
{
uint8_t u8Valid;
u8Valid = RTE_Read_KL15_Valid();
return u8Valid;
}
uint8_t System_LINE_KL15(void)
{
uint8_t u8KL15;
u8KL15 = ADC_KL15_IN; //15��Ӳ��
return u8KL15;
}
void Sys_KL30_Init ( void)
{
Sys_Set_DebounceTimer(1000u, 2u, 1000u, 80u);
Sys_Set_VolRange(SysFun_Range, SysNM_Range);
System_Monitor_KL30Init();
System_Fast_WakeUp();
}
void Sys_WakeUp_Init ( void)
{
Sys_Set_DebounceTimer(1000u, 2u, 1000u, 80u);
Sys_Set_VolRange(SysFun_Range, SysNM_Range);
System_Monitor_WakeupInit();
System_Fast_WakeUp();
}
/*����������ִ�������*/
void Sys_LogicProcess(void)
{
COM_NM_ACT();
}
void Sys_Rolling(void)
{
if (u32SysRollingCounter != 65535ul)
{
u32SysRollingCounter++;
}
else
{
u32SysRollingCounter = 0;
}
}
void Sys_RollingClear(void)
{
u32SysRollingCounter = 0;
}
uint32_t Sys_Get_ms_Rolling_Counter(void)
{
return u32SysRollingCounter;
}
void Sys_BlockDelay(uint32_t u32Ms)
{
uint32_t RocBackup, Counter;
Sys_RollingClear();
RocBackup = Sys_Get_ms_Rolling_Counter();
do
{
WDT_Clear();
Counter = Sys_Get_ms_Rolling_Counter();
if ( Counter >= RocBackup )
{
Counter -= RocBackup;
}
else
{
Counter = 65535U - RocBackup + Counter + 1U;
}
}
while ( Counter < u32Ms );
}
\ No newline at end of file
#include "GenDelay.h"
#include "GPIO.h"
#include "ADC.h"
#include "System_Monitor.h"
#include "Analog_Signals.h"
#define u16Base_Vol 0u // 0
#define u16ENTER_LOW_N_RANGE 6500U // 1
#define u16EXIT_LOW_N_RANGE 7000U // 2
#define u16ENTER_LOW_Y_RANGE 19500U // 3
#define u16EXIT_LOW_Y_RANGE 20000U // 4
#define u16EXIT_HIGH_Y_RANGE 32000U // 5
#define u16ENTER_HIGH_Y_RANGE 32500U // 6
#define u16EXIT_HIGH_N_RANGE 33000U // 7
#define u16ENTER_HIGH_N_RANGE 33500U // 8
#define u16Top_Vol 0xffffu
#pragma alignvar(8)
static const monitorlib_uint16_t SysFun_Range [ 26u ] = {
u16Base_Vol,
u16ENTER_LOW_N_RANGE,
u16EXIT_LOW_N_RANGE,
u16ENTER_LOW_Y_RANGE,
u16EXIT_LOW_Y_RANGE,
u16EXIT_HIGH_Y_RANGE,
u16ENTER_HIGH_Y_RANGE,
u16EXIT_HIGH_N_RANGE,
u16ENTER_HIGH_N_RANGE,
u16Top_Vol,
30000u, /**进入保护的时间*/
10u,
u16Base_Vol,
u16ENTER_LOW_N_RANGE,
u16EXIT_LOW_N_RANGE,
u16ENTER_LOW_Y_RANGE,
u16EXIT_LOW_Y_RANGE,
u16EXIT_HIGH_Y_RANGE,
u16ENTER_HIGH_Y_RANGE,
u16EXIT_HIGH_N_RANGE,
u16ENTER_HIGH_N_RANGE,
u16Top_Vol,
10000u,
10u,
10u, /**退出保护的时间*/
10u, /**退出保护的时间*/
};
monitorlib_uint16_t Sys_Read_KL30_Voltage_F(void)
{
monitorlib_uint16_t u16Voltage;
u16Voltage = ADC_Conv_Single_Channel(ADC_CH_KL30_VOLTAGE);
return u16Voltage;
}
monitorlib_uint16_t Sys_Read_KL15_Voltage_F(void)
{
monitorlib_uint16_t u16Voltage;
u16Voltage = ADC_Conv_Single_Channel(ADC_CH_KL30_VOLTAGE);
return u16Voltage;
}
monitorlib_uint16_t Sys_Read_KL30_Voltage(void)
{
monitorlib_uint16_t u16Voltage;
u16Voltage = ADC_Read_Signal(ADC_CH_KL30_VOLTAGE);
return u16Voltage;
}
monitorlib_uint16_t Sys_Read_KL15_Voltage(void)
{
monitorlib_uint16_t u16Voltage;
u16Voltage = ADC_Read_Signal(ADC_CH_KL30_VOLTAGE);
return u16Voltage;
}
monitorlib_uint8_t Sys_Read_KL30_Valid(void)
{
monitorlib_uint8_t u8Valid;
u8Valid = ADC_Read_Signal_Valid(ADC_CH_KL30_VOLTAGE);
return u8Valid;
}
monitorlib_uint8_t Sys_Read_KL15_Valid(void)
{
monitorlib_uint8_t u8Valid;
u8Valid = ADC_Read_Signal_Valid(ADC_CH_KL30_VOLTAGE);
return u8Valid;
}
monitorlib_uint8_t System_LINE_KL15(void)
{
monitorlib_uint8_t u8KL15;
if ( ADC_KL15_IN == 1u )
{
u8KL15 = 1u;
}
else
{
u8KL15 = 0u;
}
return u8KL15;
}
void Common_BlockDelay(monitorlib_uint32_t u32Ms)
{
Gen_TimeDelay(u32Ms * 1000u, 50u);
}
void Sys_LogicProcess(void)
{
}
void Sys_KL30_Init(void)
{
MonitorExt_st m_st;
m_st.COM_Delay = Common_BlockDelay;
m_st.SysGet_KL15Line = System_LINE_KL15;
m_st.SysGet_KL15_Valid = Sys_Read_KL15_Valid;
m_st.SysGet_KL30_Valid = Sys_Read_KL30_Valid;
m_st.SysGet_KL15_value = Sys_Read_KL15_Voltage;
m_st.SysGet_KL30_value = Sys_Read_KL30_Voltage;
m_st.SysGet_KL15_value_Force = Sys_Read_KL15_Voltage_F;
m_st.SysGet_KL30_value_Force = Sys_Read_KL30_Voltage_F;
m_st.SysMonitorLogic = Sys_LogicProcess;
Sys_Set_Pata(SysFun_Range, &m_st);
System_Monitor_KL30Init( );
}
void Sys_WakeUp_Init(void)
{
MonitorExt_st m_st;
m_st.COM_Delay = Common_BlockDelay;
m_st.SysGet_KL15Line = System_LINE_KL15;
m_st.SysGet_KL15_Valid = Sys_Read_KL15_Valid;
m_st.SysGet_KL30_Valid = Sys_Read_KL30_Valid;
m_st.SysGet_KL15_value = Sys_Read_KL15_Voltage;
m_st.SysGet_KL30_value = Sys_Read_KL30_Voltage;
m_st.SysGet_KL15_value_Force = Sys_Read_KL15_Voltage_F;
m_st.SysGet_KL30_value_Force = Sys_Read_KL30_Voltage_F;
m_st.SysMonitorLogic = Sys_LogicProcess;
Sys_Set_Pata(SysFun_Range, &m_st);
System_Monitor_WakeupInit( );
}
......@@ -673,31 +673,31 @@ uint16_t Common_ReadRollingCounter(void)
return SysRollingCounter;
}
void Common_BlockDelay(uint16_t m_MS)
{
uint16_t RocBackup;
uint16_t Counter;
uint16_t DIMCounter;
DIMCounter = m_MS * 20u;
Common_RollingCounterClear();
RocBackup = Common_ReadRollingCounter();
do
{
Counter = Common_ReadRollingCounter();
if (Counter >= RocBackup)
{
Counter -= RocBackup;
}
else
{
Counter = 65535u - RocBackup + Counter + 1u;
}
}
while (Counter < DIMCounter);
}
//void Common_BlockDelay(uint16_t m_MS)
//{
// uint16_t RocBackup;
// uint16_t Counter;
// uint16_t DIMCounter;
//
// DIMCounter = m_MS * 20u;
// Common_RollingCounterClear();
// RocBackup = Common_ReadRollingCounter();
// do
// {
// Counter = Common_ReadRollingCounter();
//
// if (Counter >= RocBackup)
// {
// Counter -= RocBackup;
// }
// else
// {
// Counter = 65535u - RocBackup + Counter + 1u;
// }
//
// }
// while (Counter < DIMCounter);
//}
uint32_t Common_GetIgnOnTime(void)
{
......
......@@ -30,7 +30,7 @@ uint32_t Common_GetIgnOffTime(void); /*ms*/
void Common_RollingCounterAdd(void);
void Common_RollingCounterClear(void);
void Common_BlockDelay(uint16_t m_MS);
//void Common_BlockDelay(uint16_t m_MS);
uint16_t Common_ReadRollingCounter(void);
void Set_Can18FF5510_FirstRecv_Event(void);
......
......@@ -116,7 +116,7 @@ SECTIONS
.tdata align(4) MAX_SIZE(0x0400) :>. /* initialized and zero-initialized data in TDA area */
.ramfunc align(4) :>. /* program code in RAM area */
.stack align(4) pad(0xC000) :>. /* definition of stack size */
.stack align(4) pad(0x4000) :>. /* definition of stack size */
/* Renesas FDL data sections */
......
......@@ -226,8 +226,8 @@ void Sys_Sleep_Init(void)
* \attention
* \retval None
******************************************************************************/
void Sys_Wakeup_Init(void)
{
}
//void Sys_Wakeup_Init(void)
//{
//
//}
......@@ -28,7 +28,7 @@ extern {
extern void Sys_Startup_Pre_Init(void);
extern void Sys_Startup_Init(void);
extern void Sys_Sleep_Init(void);
extern void Sys_Wakeup_Init(void);
//extern void Sys_Wakeup_Init(void);
#ifdef __cplusplus
}
......
......@@ -323,7 +323,7 @@ void Sys_Exact_50us_Tasks(void)
{
static uint32_t PerCounter = 0u;
GenDelay_Tick();
Sys_Rolling();
//Sys_Rolling();
COM_NM_Process();
COM_TX_Process();
DoCAN_Timer_Update(50);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment