Browse Source

V2版本 MainTask测试通过,新增uart线程文件

CHENJIE-PC\QiXiang_CHENJIE 4 years ago
parent
commit
22503d7eb8
5 changed files with 108 additions and 32 deletions
  1. 15 9
      inc/app.h
  2. 13 7
      src/MainTask.c
  3. 32 0
      src/UartTask.c
  4. 47 3
      src/UartTask.h
  5. 1 13
      src/app.c

+ 15 - 9
inc/app.h

@@ -12,6 +12,20 @@
 extern "C" {
 #endif
 
+#define BAT4830
+#ifdef  BAT4830
+    #define Batt_Cell_Num  (14)
+    #define Batt_Temp_Num  (5)
+#else
+    #define Batt_Cell_Num  (17)
+    #define Batt_Temp_Num  (7)
+#endif
+#define Batt_Cell_Num_2 (Batt_Cell_Num*2)
+
+#define	SwVersion		0xA21
+#define HwVersion		0xB22
+
+
 #define QMSG_ID_BASE               (0x160) 
 #define QMSG_ID_NW_IP_READY        (QMSG_ID_BASE)
 #define QMSG_ID_NW_IP_SUSPEND      (QMSG_ID_BASE + 1)
@@ -70,14 +84,6 @@ extern UINT8 BattSN[BATT_SN_LEN];
 extern CHAR  TcpServerIpV4Address[16];
 extern CHAR  TcpServerPort[5];
 
-typedef enum
-{
-    PROCESS_UART_STATE_IDLE = 0,
-    PROCESS_UART_STATE_CHECK,
-    PROCESS_UART_STATE_WORK,
-    PROCESS_UART_STATE_SLEEP
-}process_Uart;
-
 typedef enum
 {
     PROCESS_CAN_STATE_IDLE = 0,
@@ -210,7 +216,7 @@ typedef struct  _GPS_INFO
 	uint32_t latitude;
 	uint32_t longitude;
 }GPS_INFO;
-uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg,uint8_t* Uart_Rece_buffer,uint8_t Data_Len);
+//uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg,uint8_t* Uart_Rece_buffer,uint8_t Data_Len);
 
 #ifdef __cplusplus
 }

+ 13 - 7
src/MainTask.c

@@ -26,8 +26,14 @@
 #include "ec_tcpip_api.h"
 #include "hal_module_adapter.h"
 #include "timers.h"
-//#include "app.h"
+#include "app.h"
 #include "MainTask.h"
+
+//全局变量
+static uint32_t Timer_count = 0;//每100ms加1
+volatile bool Sleep_flag = false;//睡眠标志位
+
+//主线程堆栈声明区
 static StaticTask_t           gProcess_Main_Task_t;
 static UINT8                  gProcess_Main_TaskStack[PROC_MAIN_TASK_STACK_SIZE];
 static osThreadId_t           MainTaskId = NULL;
@@ -36,9 +42,6 @@ uint8_t deepslpTimerID          = DEEPSLP_TIMER_ID7;//睡眠定时器ID
 volatile bool Work_timer_end = false;
 static process_Main 		    gProcess_Main_Task;
 #define PROC_MAIN_STATE_SWITCH(a)  (gProcess_Main_Task = a)
-//全局变量
-static uint32_t Timer_count = 0;//每100ms加1
-volatile bool Sleep_flag = false;//睡眠标志位
 
 //函数声明区
 static void appBeforeHib(void *pdata, slpManLpState state);
@@ -181,9 +184,12 @@ void MainTaskDeInit(void *arg)
 //定时器回调函数区
 void montior_timer_callback(TimerHandle_t xTimer)
 {
-    // #ifdef USING_PRINTF
-    //     printf("Hello montior Timer!\n");
-    // #endif
+    #ifdef USING_PRINTF
+        if (Timer_count%50==0)
+        {
+            printf("Hello 5s montior Timer,SwVersion:%x!\n",SwVersion);
+        }
+    #endif
     Timer_count++;
     if(Timer_count>100000*100)
     {

+ 32 - 0
src/UartTask.c

@@ -25,4 +25,36 @@
 #include "plat_config.h"
 #include "ec_tcpip_api.h"
 #include "hal_module_adapter.h"
+#include "UartTask.h"
 
+static StaticTask_t             gProcess_Uart_Task_t;
+static UINT8                  gProcess_Uart_TaskStack[PROC_UART_TASK_STACK_SIZE];
+static osThreadId_t           UartTaskId = NULL;
+static process_Uart             gProcess_Uart_Task = PROCESS_UART_STATE_IDLE;
+#define PROC_UART_STATE_SWITCH(a)  (gProcess_Uart_Task = a)
+
+
+//Uart线程任务区
+static void UartTask(void* arg)
+{
+
+}
+//Uart线程初始化
+void UartTaskInit(void *arg)
+{
+    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 = osPriorityBelowNormal7;
+    task_attr.cb_mem = &gProcess_Uart_Task_t;
+    task_attr.cb_size = sizeof(StaticTask_t);
+    UartTaskId = osThreadNew(UartTask, NULL, &task_attr);
+}
+void UartTaskDeInit(void *arg)
+{
+    osThreadTerminate(UartTaskId);
+    UartTaskId = NULL;
+}

+ 47 - 3
src/UartTask.h

@@ -7,12 +7,56 @@
  *
  ****************************************************************************/
 
-typedef struct Uart_Receive_Type
+//全局变量声明区
+extern bool Sleep_flag;
+extern uint32_t Timer_count;
+
+//底层变量声明区
+extern ARM_DRIVER_USART Driver_USART1;
+static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
+volatile bool isRecvTimeout = false;
+volatile bool isRecvComplete = false;
+//
+#define PROC_UART_TASK_STACK_SIZE           (1024)
+#define UART_READ_CODE 0x03
+#define UART_WRITE_CODE 0x10
+#define BMS_ADDRESS_CODE 0x01
+typedef struct Uart_Read_Msg_Type
 {
     uint8_t Bms_Address; 
-    uint8_t Bms_Read_Funcode; 
+    uint8_t Bms_Funcode; 
     uint8_t Reg_Begin_H; 
     uint8_t Reg_Begin_L; 
     uint8_t Reg_Num_H; 
     uint8_t Reg_Num_L; 
-}Uart_Receive_Type;
+    uint8_t CRC_H;
+    uint8_t CRC_L;
+}Uart_Read_Msg_Type;
+typedef struct Uart_Write_Msg_Type
+{
+    uint8_t Bms_Address; 
+    uint8_t Bms_Funcode; 
+    uint8_t Reg_Begin_H; 
+    uint8_t Reg_Begin_L; 
+    uint8_t Reg_Num_H; 
+    uint8_t Reg_Num_L; 
+    uint8_t Data_Count;
+    uint8_t Data[2];
+    uint8_t CRC_H;
+    uint8_t CRC_L;
+}Uart_Write_Msg_Type;
+
+typedef struct Uart_Write_Answer_Msg_Type
+{
+    uint8_t Bms_Address; 
+    uint8_t Bms_Funcode; 
+}Uart_Write_Answer_Msg_Type;
+typedef enum
+{
+    PROCESS_UART_STATE_IDLE = 0,
+    PROCESS_UART_STATE_CHECK,
+    PROCESS_UART_STATE_WORK,
+    PROCESS_UART_STATE_SLEEP
+}process_Uart;
+void UartTaskInit(void* arg);
+void UartTaskDeInit(void* arg);

+ 1 - 13
src/app.c

@@ -27,19 +27,7 @@
 #include "app.h"
 
 #include "MainTask.h"
-
-#define BAT4830
-#ifdef  BAT4830
-    #define Batt_Cell_Num  (14)
-    #define Batt_Temp_Num  (5)
-#else
-    #define Batt_Cell_Num  (17)
-    #define Batt_Temp_Num  (7)
-#endif
-#define Batt_Cell_Num_2 (Batt_Cell_Num*2)
-
-#define	SwVersion		0xA21
-#define HwVersion		0xB22
+#include "UartTask.h"
 
 void appInit(void *arg)
 {