|
@@ -0,0 +1,579 @@
|
|
|
+/*******************************
|
|
|
+ *
|
|
|
+ * 骑享程序V2版本
|
|
|
+ *
|
|
|
+ * ****************************/
|
|
|
+#include "bsp.h"
|
|
|
+#include "bsp_custom.h"
|
|
|
+#include "osasys.h"
|
|
|
+#include "ostask.h"
|
|
|
+#include "queue.h"
|
|
|
+#include "ps_event_callback.h"
|
|
|
+#include "app.h"
|
|
|
+#include "cmisim.h"
|
|
|
+#include "cmimm.h"
|
|
|
+#include "cmips.h"
|
|
|
+#include "sockets.h"
|
|
|
+#include "psifevent.h"
|
|
|
+#include "ps_lib_api.h"
|
|
|
+#include "lwip/netdb.h"
|
|
|
+#include <cis_def.h>
|
|
|
+#include "debug_log.h"
|
|
|
+#include "slpman_ec616.h"
|
|
|
+#include "plat_config.h"
|
|
|
+
|
|
|
+//基础定义
|
|
|
+#define Batt_Cell_Num (17)//默认数值14、17
|
|
|
+#define Batt_Temp_Num (7)//默认数值5、7
|
|
|
+#define Batt_Cell_Num_2 (Batt_Cell_Num*2)
|
|
|
+//主任务调度定义
|
|
|
+#define PROC_MAIN_TASK_STACK_SIZE (1024)
|
|
|
+static StaticTask_t gProcess_Main_Task_t;
|
|
|
+static UINT8 gProcess_Main_TaskStack[PROC_MAIN_TASK_STACK_SIZE];
|
|
|
+uint8_t deepslpTimerID = DEEPSLP_TIMER_ID7;
|
|
|
+uint8_t MainSlpHandler = 0xff;
|
|
|
+typedef enum
|
|
|
+{
|
|
|
+ PROCESS_STATE_IDLE = 0,
|
|
|
+ PROCESS_STATE_WORK,
|
|
|
+ PROCESS_STATE_SLEEP
|
|
|
+}process_Main;
|
|
|
+static process_Main gProcess_Main_Task = PROCESS_STATE_IDLE;
|
|
|
+#define PROC_MAIN_STATE_SWITCH(a) (gProcess_Main_Task = a)
|
|
|
+//Uart线程定义
|
|
|
+#define PROC_UART_TASK_STACK_SIZE (1024)
|
|
|
+static StaticTask_t gProcess_Uart_Task_t;
|
|
|
+static UINT8 gProcess_Uart_TaskStack[PROC_UART_TASK_STACK_SIZE];
|
|
|
+
|
|
|
+#define Uart_Send_LEN (8)
|
|
|
+#define Uart_Rece_LEN (50)
|
|
|
+#define battbuffer_len (110)
|
|
|
+#define RTE_UART_RX_IO_MODE RTE_UART1_RX_IO_MODE
|
|
|
+extern ARM_DRIVER_USART Driver_USART1;
|
|
|
+static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
|
|
|
+volatile bool isRecvTimeout = false;
|
|
|
+volatile bool isRecvComplete = false;
|
|
|
+typedef enum
|
|
|
+{
|
|
|
+ PROCESS_UART_STATE_IDLE = 0,
|
|
|
+ PROCESS_UART_STATE_CHECK,
|
|
|
+ PROCESS_UART_STATE_WORK,
|
|
|
+ PROCESS_UART_STATE_SLEEP
|
|
|
+}process_Uart;
|
|
|
+static process_Uart gProcess_Uart_Task = PROCESS_UART_STATE_IDLE;
|
|
|
+#define PROC_UART_STATE_SWITCH(a) (gProcess_Uart_Task = a)
|
|
|
+volatile bool Uart_Sleep_State = false;
|
|
|
+uint8_t UartSlpHandler = 0xfe;
|
|
|
+//Fota线程定义
|
|
|
+#define PROC_FOTA_TASK_STACK_SIZE (1024)
|
|
|
+static StaticTask_t gProcess_Fota_Task_t;
|
|
|
+static UINT8 gProcess_Fota_TaskStack[PROC_FOTA_TASK_STACK_SIZE];
|
|
|
+Fota_Type Fota_Stuct;
|
|
|
+//CAN线程定义
|
|
|
+
|
|
|
+//Tcp线程定义
|
|
|
+
|
|
|
+//GPS线程定义
|
|
|
+
|
|
|
+//函数声明区
|
|
|
+void Uart_func(void);
|
|
|
+void USART_callback(uint32_t event);
|
|
|
+//睡眠进出函数
|
|
|
+static void appBeforeHib(void *pdata, slpManLpState state)
|
|
|
+{
|
|
|
+ uint32_t *p_param = (uint32_t *)pdata;
|
|
|
+
|
|
|
+ #ifdef USING_PRINTF
|
|
|
+ printf("Before Hibernate:%d \n",state);
|
|
|
+ #endif
|
|
|
+ slpManAONIOLatchEn(AonIOLatch_Enable);
|
|
|
+
|
|
|
+}
|
|
|
+static void appAfterHib(void *pdata, slpManLpState state)
|
|
|
+{
|
|
|
+ #ifdef USING_PRINTF
|
|
|
+ printf("Try Hibernate Failed:%d \n",state);
|
|
|
+ #endif
|
|
|
+}
|
|
|
+static void appBeforeSlp1(void *pdata, slpManLpState state)
|
|
|
+{
|
|
|
+ #ifdef USING_PRINTF
|
|
|
+ printf("Before Sleep1:%d \n",state);
|
|
|
+ #endif
|
|
|
+ slpManAONIOLatchEn(AonIOLatch_Enable);
|
|
|
+}
|
|
|
+static void appAfterSlp1(void *pdata, slpManLpState state)
|
|
|
+{
|
|
|
+ #ifdef USING_PRINTF
|
|
|
+ printf("After Sleep1:%d \n",state);
|
|
|
+ #endif
|
|
|
+}
|
|
|
+static void appBeforeSlp2(void *pdata, slpManLpState state)
|
|
|
+{
|
|
|
+ #ifdef USING_PRINTF
|
|
|
+ printf("before sleep2:%d \n",state);
|
|
|
+ #endif
|
|
|
+ slpManAONIOLatchEn(AonIOLatch_Enable);
|
|
|
+}
|
|
|
+static void appAfterSlp2(void *pdata, slpManLpState state)
|
|
|
+{
|
|
|
+ #ifdef USING_PRINTF
|
|
|
+ printf("sleep2 failed:%d \n",state);
|
|
|
+ #endif
|
|
|
+}
|
|
|
+// 主任务线程
|
|
|
+static void Main_Task(void* arg)
|
|
|
+{
|
|
|
+ uint32_t sleep_count = 0;
|
|
|
+ uint32_t Uart_time = 0;
|
|
|
+ uint32_t sleep_time_value;
|
|
|
+ int32_t inParam = 0xAABBCCDD;
|
|
|
+ uint32_t Chrgend_Work_time = 180000;
|
|
|
+ uint32_t Wakeup_Work_time = 1000;
|
|
|
+ uint32_t Sleep_Time = 20000;
|
|
|
+ //上述参数应写入文件里
|
|
|
+ slpManSlpState_t State;
|
|
|
+ uint8_t cnt;
|
|
|
+ slpManWakeSrc_e Wakeup_source;
|
|
|
+
|
|
|
+ NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
|
|
|
+ NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
|
|
|
+ NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
|
|
|
+ NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
|
|
|
+ FaultDisplay(LED_TURN_OFF);
|
|
|
+ NVIC_EnableIRQ(PadWakeup1_IRQn);
|
|
|
+ slpManSetPmuSleepMode(true,SLP_HIB_STATE,false);
|
|
|
+ slpManApplyPlatVoteHandle("MainSlp",&MainSlpHandler);
|
|
|
+ slpManRegisterUsrdefinedBackupCb(appBeforeHib,&inParam,SLPMAN_HIBERNATE_STATE);
|
|
|
+ slpManRegisterUsrdefinedRestoreCb(appAfterHib,NULL,SLPMAN_HIBERNATE_STATE);
|
|
|
+ slpManRegisterUsrdefinedBackupCb(appBeforeSlp1,NULL,SLPMAN_SLEEP1_STATE);
|
|
|
+ slpManRegisterUsrdefinedRestoreCb(appAfterSlp1,NULL,SLPMAN_SLEEP1_STATE);
|
|
|
+ slpManRegisterUsrdefinedBackupCb(appBeforeSlp2,NULL,SLPMAN_SLEEP2_STATE);
|
|
|
+ slpManRegisterUsrdefinedRestoreCb(appAfterSlp2,NULL,SLPMAN_SLEEP2_STATE);
|
|
|
+
|
|
|
+ slpManPlatVoteDisableSleep(MainSlpHandler, SLP_SLP1_STATE);
|
|
|
+ slpManSlpState_t slpstate = slpManGetLastSlpState();
|
|
|
+ #ifdef USING_PRINTF
|
|
|
+ printf("slpstate:%d \n",slpstate);
|
|
|
+ #endif
|
|
|
+ Wakeup_source = slpManGetWakeupSrc();//获取唤醒源
|
|
|
+ #ifdef USING_PRINTF
|
|
|
+ printf("Wakeup_source:%d \n",Wakeup_source);
|
|
|
+ #endif
|
|
|
+ PROC_MAIN_STATE_SWITCH(PROCESS_STATE_IDLE);
|
|
|
+ if (Wakeup_source==0)
|
|
|
+ {
|
|
|
+ sleep_time_value = Wakeup_Work_time;
|
|
|
+ }
|
|
|
+ else if (Wakeup_source==1)
|
|
|
+ {
|
|
|
+ sleep_time_value = Wakeup_Work_time;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sleep_time_value = Chrgend_Work_time;
|
|
|
+ }
|
|
|
+ if((slpstate == SLP_SLP2_STATE) || (slpstate == SLP_HIB_STATE))
|
|
|
+ {
|
|
|
+ PROC_MAIN_STATE_SWITCH(PROCESS_STATE_WORK);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ PROC_MAIN_STATE_SWITCH(PROCESS_STATE_WORK);
|
|
|
+ }
|
|
|
+ //线程初始化完成
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ switch(gProcess_Main_Task)
|
|
|
+ {
|
|
|
+ case PROCESS_STATE_IDLE:
|
|
|
+ {
|
|
|
+ PROC_MAIN_STATE_SWITCH(PROCESS_STATE_WORK);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case PROCESS_STATE_WORK:
|
|
|
+ {
|
|
|
+ osDelay(10/portTICK_PERIOD_MS);
|
|
|
+ sleep_count++;
|
|
|
+ Uart_time++;
|
|
|
+ if (Uart_time >100)
|
|
|
+ {
|
|
|
+ Uart_time = 0;
|
|
|
+ PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_WORK);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (sleep_count >=sleep_time_value)
|
|
|
+ {
|
|
|
+ PROC_MAIN_STATE_SWITCH(PROCESS_STATE_SLEEP);
|
|
|
+ sleep_count = 0;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case PROCESS_STATE_SLEEP:
|
|
|
+ {
|
|
|
+ #ifdef USING_PRINTF
|
|
|
+ printf("[%d]Main_sleep\r\n",__LINE__);
|
|
|
+ #endif
|
|
|
+ while(true)
|
|
|
+ {
|
|
|
+ PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_SLEEP);
|
|
|
+ if(Uart_Sleep_State)
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
+ osDelay(1000/portTICK_PERIOD_MS);
|
|
|
+ if(slpManCheckVoteState(MainSlpHandler, &State, &cnt)==RET_TRUE)
|
|
|
+ {
|
|
|
+ #ifdef USING_PRINTF
|
|
|
+ printf("[%d]We Can Check Vote Main State, state=%d, cnt=%d\r\n",__LINE__,State,cnt);
|
|
|
+ #endif
|
|
|
+ }
|
|
|
+ slpManPlatVoteForceEnableSleep(MainSlpHandler, SLP_SLP1_STATE); //增加强制投票
|
|
|
+ if(slpManCheckVoteState(MainSlpHandler, &State, &cnt)==RET_TRUE)
|
|
|
+ {
|
|
|
+ #ifdef USING_PRINTF
|
|
|
+ printf("[%d]We Can Check Vote Main State Again, state=%d, cnt=%d\r\n",__LINE__,State,cnt);
|
|
|
+ #endif
|
|
|
+ }
|
|
|
+ #ifdef USING_PRINTF
|
|
|
+ printf("[%d]Waiting sleep\r\n",__LINE__);
|
|
|
+ #endif
|
|
|
+ slpManSlpState_t slpstate = slpManPlatGetSlpState();
|
|
|
+ #ifdef USING_PRINTF
|
|
|
+ printf("which slpstate can go now :%d \n",slpstate);
|
|
|
+ #endif
|
|
|
+ slpManDeepSlpTimerStart(deepslpTimerID, Sleep_Time);
|
|
|
+ while(1)
|
|
|
+ {
|
|
|
+ if(!slpManDeepSlpTimerIsRunning(deepslpTimerID))
|
|
|
+ {
|
|
|
+ slpManDeepSlpTimerDel(deepslpTimerID);
|
|
|
+ }
|
|
|
+ slpManDeepSlpTimerStart(deepslpTimerID, Sleep_Time);
|
|
|
+ osDelay(60000/portTICK_PERIOD_MS);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+//Uart校验程序
|
|
|
+unsigned int crc_chk(uint8_t* data, uint8_t length)
|
|
|
+{
|
|
|
+ int j;
|
|
|
+ uint16_t reg_crc=0xFFFF;
|
|
|
+ while(length--)
|
|
|
+ {
|
|
|
+ reg_crc ^= *data++;
|
|
|
+ for(j=0;j<8;j++)
|
|
|
+ {
|
|
|
+ if(reg_crc & 0x01)
|
|
|
+ {
|
|
|
+ reg_crc=(reg_crc>>1) ^ 0xA001;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ reg_crc=reg_crc >>1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return reg_crc;
|
|
|
+}
|
|
|
+//Uart发送接收函数
|
|
|
+uint8_t* Uart_Receive_send_func(Uart_Receive_Type Uart_Receive_Msg,uint8_t* Uart_Rece_buffer,uint8_t Data_Len)
|
|
|
+{
|
|
|
+ uint16_t CRC_Rece_buffer;
|
|
|
+ uint16_t CRC_chk_buffer;
|
|
|
+ uint8_t Uart_Send_buffer[8];
|
|
|
+ Uart_Send_buffer[0] = Uart_Receive_Msg.Bms_Address;
|
|
|
+ Uart_Send_buffer[1] = Uart_Receive_Msg.Bms_Read_Funcode;
|
|
|
+ Uart_Send_buffer[2] = Uart_Receive_Msg.Reg_Begin_H;
|
|
|
+ Uart_Send_buffer[3] = Uart_Receive_Msg.Reg_Begin_L;
|
|
|
+ Uart_Send_buffer[4] = Uart_Receive_Msg.Reg_Num_H;
|
|
|
+ Uart_Send_buffer[5] = Uart_Receive_Msg.Reg_Num_L;
|
|
|
+ CRC_chk_buffer = crc_chk(Uart_Send_buffer,6);
|
|
|
+ Uart_Send_buffer[6] = CRC_chk_buffer;
|
|
|
+ Uart_Send_buffer[7] = CRC_chk_buffer>>8;
|
|
|
+ uint32_t timeout = 0x00000000;
|
|
|
+ USARTdrv->Send(Uart_Send_buffer,8);
|
|
|
+ USARTdrv->Receive(Uart_Rece_buffer,Data_Len);
|
|
|
+ while((isRecvTimeout == false) && (isRecvComplete == false))
|
|
|
+ {
|
|
|
+ timeout++;
|
|
|
+ osDelay(100);
|
|
|
+ if (timeout>=10)
|
|
|
+ {
|
|
|
+ timeout =0;
|
|
|
+ isRecvTimeout = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (isRecvComplete == true)
|
|
|
+ {
|
|
|
+ isRecvComplete = false;
|
|
|
+ CRC_Rece_buffer =*(Uart_Rece_buffer+Data_Len-1)<<8|*(Uart_Rece_buffer+Data_Len-2);
|
|
|
+ CRC_chk_buffer = crc_chk(Uart_Rece_buffer,Data_Len-2);
|
|
|
+ if (CRC_Rece_buffer == CRC_chk_buffer)//满足校验
|
|
|
+ {
|
|
|
+ return Uart_Rece_buffer;//此处指针移位出现重启问题
|
|
|
+ }
|
|
|
+ else //接收数据的校验不过
|
|
|
+ {
|
|
|
+ USARTdrv->Uninitialize();
|
|
|
+ USARTdrv->Initialize(USART_callback);
|
|
|
+ USARTdrv->PowerControl(ARM_POWER_FULL);
|
|
|
+ USARTdrv->Control(ARM_USART_MODE_ASYNCHRONOUS |
|
|
|
+ ARM_USART_DATA_BITS_8 |
|
|
|
+ ARM_USART_PARITY_NONE |
|
|
|
+ ARM_USART_STOP_BITS_1 |
|
|
|
+ ARM_USART_FLOW_CONTROL_NONE, 9600);
|
|
|
+ memset(Uart_Rece_buffer,0xff,Data_Len);
|
|
|
+ return Uart_Rece_buffer;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ memset(Uart_Rece_buffer,0x00,Data_Len);
|
|
|
+ isRecvTimeout = false;
|
|
|
+ return Uart_Rece_buffer;
|
|
|
+ }
|
|
|
+}
|
|
|
+//Uart回调程序
|
|
|
+void USART_callback(uint32_t event)
|
|
|
+{
|
|
|
+ if(event & ARM_USART_EVENT_RX_TIMEOUT)
|
|
|
+ {
|
|
|
+ isRecvTimeout = true;
|
|
|
+ }
|
|
|
+ if(event & ARM_USART_EVENT_RECEIVE_COMPLETE)
|
|
|
+ {
|
|
|
+ isRecvComplete = true;
|
|
|
+ }
|
|
|
+}
|
|
|
+//Uart读取函数
|
|
|
+void Uart_func(void)
|
|
|
+{
|
|
|
+ Uart_Receive_Type Uart_Receive_Msg;
|
|
|
+ Uart_Receive_Msg.Bms_Address = 0x01;
|
|
|
+ Uart_Receive_Msg.Bms_Read_Funcode = 0x03;
|
|
|
+ int Rece_index = 0;
|
|
|
+ uint8_t *Uart_Rece_buffer = NULL;
|
|
|
+ volatile bool Uart_task = false;
|
|
|
+ volatile uint8_t Data_Len;
|
|
|
+ Uart_Rece_buffer = (uint8_t *)malloc(Uart_Rece_LEN);
|
|
|
+ while(!Uart_task)
|
|
|
+ {
|
|
|
+ switch (Rece_index)
|
|
|
+ {
|
|
|
+ case 0://current
|
|
|
+ {
|
|
|
+ Uart_Receive_Msg.Reg_Begin_H = 0x00;
|
|
|
+ Uart_Receive_Msg.Reg_Begin_L= 0x02+Batt_Cell_Num;
|
|
|
+ Uart_Receive_Msg.Reg_Num_H = 0x00;
|
|
|
+ Uart_Receive_Msg.Reg_Num_L = 0x01;
|
|
|
+ Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
|
|
|
+ memset(Uart_Rece_buffer,0x00,Data_Len);
|
|
|
+ Uart_Rece_buffer = Uart_Receive_send_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 1://cell votage
|
|
|
+ {
|
|
|
+ Uart_Receive_Msg.Reg_Begin_H = 0x00;
|
|
|
+ Uart_Receive_Msg.Reg_Begin_L = 0x02;
|
|
|
+ Uart_Receive_Msg.Reg_Num_H = Batt_Cell_Num>>8;
|
|
|
+ Uart_Receive_Msg.Reg_Num_L = Batt_Cell_Num;
|
|
|
+ Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
|
|
|
+ memset(Uart_Rece_buffer,0x00,Data_Len);
|
|
|
+ Uart_Rece_buffer = Uart_Receive_send_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 2://temprature
|
|
|
+ {
|
|
|
+ Uart_Receive_Msg.Reg_Begin_H = 0x00;
|
|
|
+ Uart_Receive_Msg.Reg_Begin_L = 0x06+Batt_Cell_Num;
|
|
|
+ Uart_Receive_Msg.Reg_Num_H = Batt_Temp_Num>>8;
|
|
|
+ Uart_Receive_Msg.Reg_Num_L = Batt_Temp_Num;
|
|
|
+ Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
|
|
|
+ memset(Uart_Rece_buffer,0x00,Data_Len);
|
|
|
+ Uart_Rece_buffer = Uart_Receive_send_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 3://batt votage
|
|
|
+ {
|
|
|
+ Uart_Receive_Msg.Reg_Begin_H = 0x00;
|
|
|
+ Uart_Receive_Msg.Reg_Begin_L = 0x18+Batt_Cell_Num+Batt_Temp_Num;
|
|
|
+ Uart_Receive_Msg.Reg_Num_H = 0x00;
|
|
|
+ Uart_Receive_Msg.Reg_Num_L = 0x01;
|
|
|
+ Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
|
|
|
+ memset(Uart_Rece_buffer,0x00,Data_Len);
|
|
|
+ Uart_Rece_buffer = Uart_Receive_send_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 4://soc,soh
|
|
|
+ {
|
|
|
+ Uart_Receive_Msg.Reg_Begin_H = 0x00;
|
|
|
+ Uart_Receive_Msg.Reg_Begin_L = 0x09+Batt_Cell_Num+Batt_Temp_Num;
|
|
|
+ Uart_Receive_Msg.Reg_Num_H = 0x00;
|
|
|
+ Uart_Receive_Msg.Reg_Num_L = 0x04;
|
|
|
+ Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
|
|
|
+ memset(Uart_Rece_buffer,0x00,Data_Len);
|
|
|
+ Uart_Rece_buffer = Uart_Receive_send_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 5://均衡
|
|
|
+ {
|
|
|
+ Uart_Receive_Msg.Reg_Begin_H = 0x00;
|
|
|
+ Uart_Receive_Msg.Reg_Begin_L = 0x06+Batt_Cell_Num+Batt_Temp_Num;
|
|
|
+ Uart_Receive_Msg.Reg_Num_H = 0x00;
|
|
|
+ Uart_Receive_Msg.Reg_Num_L = 0x02;
|
|
|
+ Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
|
|
|
+ memset(Uart_Rece_buffer,0x00,Data_Len);
|
|
|
+ Uart_Rece_buffer = Uart_Receive_send_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 6://最高最低温度和加热和充放电MOS控制
|
|
|
+ {
|
|
|
+ Uart_Receive_Msg.Reg_Begin_H = 0x00;
|
|
|
+ Uart_Receive_Msg.Reg_Begin_L = 0x19+Batt_Cell_Num+Batt_Temp_Num;
|
|
|
+ Uart_Receive_Msg.Reg_Num_H = 0x00;
|
|
|
+ Uart_Receive_Msg.Reg_Num_L = 0x04;
|
|
|
+ Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
|
|
|
+ memset(Uart_Rece_buffer,0x00,Data_Len);
|
|
|
+ Uart_Rece_buffer = Uart_Receive_send_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ {
|
|
|
+ PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
|
|
|
+ Uart_task = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Rece_index++;
|
|
|
+ }
|
|
|
+ free(Uart_Rece_buffer);
|
|
|
+}
|
|
|
+//Uart线程
|
|
|
+static void Uart_Task(void* arg)
|
|
|
+{
|
|
|
+ USARTdrv->Initialize(USART_callback);
|
|
|
+ USARTdrv->PowerControl(ARM_POWER_FULL);
|
|
|
+ USARTdrv->Control(ARM_USART_MODE_ASYNCHRONOUS |
|
|
|
+ ARM_USART_DATA_BITS_8 |
|
|
|
+ ARM_USART_PARITY_NONE |
|
|
|
+ ARM_USART_STOP_BITS_1 |
|
|
|
+ ARM_USART_FLOW_CONTROL_NONE, 9600);
|
|
|
+ slpManApplyPlatVoteHandle("UARTSLP",&UartSlpHandler);
|
|
|
+ slpManPlatVoteDisableSleep(UartSlpHandler, SLP_SLP2_STATE);
|
|
|
+ PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
|
|
|
+
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ switch (gProcess_Uart_Task)
|
|
|
+ {
|
|
|
+ case PROCESS_UART_STATE_IDLE:
|
|
|
+ {
|
|
|
+ NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case PROCESS_UART_STATE_WORK:
|
|
|
+ {
|
|
|
+ #ifdef USING_PRINTF
|
|
|
+ printf("UART_STATE_WORK!\n");
|
|
|
+ #endif
|
|
|
+ Uart_func();//读取函数运行
|
|
|
+ PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case PROCESS_UART_STATE_SLEEP:
|
|
|
+ {
|
|
|
+ slpManPlatVoteEnableSleep(UartSlpHandler, SLP_SLP2_STATE);
|
|
|
+ Uart_Sleep_State = true;
|
|
|
+ USARTdrv->PowerControl(ARM_POWER_LOW);
|
|
|
+ #ifdef USING_PRINTF
|
|
|
+ printf("UART_STATE_SLEEP\n");
|
|
|
+ #endif
|
|
|
+ while(1)
|
|
|
+ {
|
|
|
+ osDelay(3000/portTICK_PERIOD_MS);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+//Fota线程
|
|
|
+static void Fota_Task(void* arg)
|
|
|
+{
|
|
|
+ Fota_Stuct.Fota_Data_Len=100;
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ osDelay(1000);
|
|
|
+ }
|
|
|
+}
|
|
|
+//Uart线程初始化
|
|
|
+void Uart_Task_Init()
|
|
|
+{
|
|
|
+ osThreadAttr_t task_attr;
|
|
|
+ memset(&task_attr,0,sizeof(task_attr));
|
|
|
+ memset(gProcess_Uart_TaskStack, 0xA5, PROC_UART_TASK_STACK_SIZE);
|
|
|
+ task_attr.name = "Uart_Task";
|
|
|
+ task_attr.stack_mem = gProcess_Uart_TaskStack;
|
|
|
+ task_attr.stack_size = PROC_UART_TASK_STACK_SIZE;
|
|
|
+ task_attr.priority = osPriorityNormal;
|
|
|
+ task_attr.cb_mem = &gProcess_Uart_Task_t;
|
|
|
+ task_attr.cb_size = sizeof(StaticTask_t);
|
|
|
+ osThreadNew(Uart_Task, NULL, &task_attr);
|
|
|
+}
|
|
|
+void Fota_Task_Init()
|
|
|
+{
|
|
|
+ osThreadAttr_t task_attr;
|
|
|
+ memset(&task_attr,0,sizeof(task_attr));
|
|
|
+ memset(gProcess_Fota_TaskStack, 0xA5, PROC_FOTA_TASK_STACK_SIZE);
|
|
|
+ task_attr.name = "Fota_Task";
|
|
|
+ task_attr.stack_mem = gProcess_Fota_TaskStack;
|
|
|
+ task_attr.stack_size = PROC_FOTA_TASK_STACK_SIZE;
|
|
|
+ task_attr.priority = osPriorityNormal;
|
|
|
+ task_attr.cb_mem = &gProcess_Fota_Task_t;
|
|
|
+ task_attr.cb_size = sizeof(StaticTask_t);
|
|
|
+ osThreadNew(Fota_Task, NULL, &task_attr);
|
|
|
+}
|
|
|
+//主任务线程初始化
|
|
|
+void Main_Task_Init()
|
|
|
+{
|
|
|
+ #ifndef USING_PRINTF
|
|
|
+ if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
|
|
|
+ {
|
|
|
+ HAL_UART_RecvFlowControl(false);
|
|
|
+ }
|
|
|
+ #endif
|
|
|
+ osThreadAttr_t task_attr;
|
|
|
+ memset(&task_attr,0,sizeof(task_attr));
|
|
|
+ memset(gProcess_Main_TaskStack, 0xA5, PROC_MAIN_TASK_STACK_SIZE);
|
|
|
+ task_attr.name = "Main_Task";
|
|
|
+ task_attr.stack_mem = gProcess_Main_TaskStack;
|
|
|
+ task_attr.stack_size = PROC_MAIN_TASK_STACK_SIZE;
|
|
|
+ task_attr.priority = osPriorityNormal;
|
|
|
+ task_attr.cb_mem = &gProcess_Main_Task_t;
|
|
|
+ task_attr.cb_size = sizeof(StaticTask_t);
|
|
|
+ osThreadNew(Main_Task, NULL, &task_attr);
|
|
|
+}
|
|
|
+void appInit(void *arg)
|
|
|
+{
|
|
|
+ Main_Task_Init();
|
|
|
+ Uart_Task_Init();
|
|
|
+ Fota_Task_Init();
|
|
|
+}
|
|
|
+//主函数入口
|
|
|
+void main_entry(void)
|
|
|
+{
|
|
|
+ BSP_CommonInit();
|
|
|
+ osKernelInitialize();
|
|
|
+ registerAppEntry(appInit, NULL);
|
|
|
+ if (osKernelGetState() == osKernelReady)
|
|
|
+ {
|
|
|
+ osKernelStart();
|
|
|
+ }
|
|
|
+ while(1);
|
|
|
+}
|