Browse Source

【新建】新建qx_app,旧版本在电脑上进行备份,先采用一个文件

CHENJIE-PC\QiXiang_CHENJIE 4 years ago
parent
commit
993385eaae
33 changed files with 1236 additions and 14055 deletions
  1. 22 0
      ARMCC/Makefile
  2. 12 0
      GCC/Makefile
  3. 0 549
      app _0_4.c
  4. 0 736
      app _1_7_1.c
  5. 0 915
      app.c
  6. 0 577
      app_0_1.c
  7. 0 460
      app_0_2.c
  8. 0 522
      app_0_3.c
  9. 0 526
      app_0_5.c
  10. 0 612
      app_1_0.c
  11. 0 619
      app_1_0_1.c
  12. 0 337
      app_1_1.c
  13. 0 353
      app_1_2.c
  14. 0 671
      app_1_3.c
  15. 0 703
      app_1_4.c
  16. 0 714
      app_1_5.c
  17. 0 717
      app_1_6.c
  18. 0 735
      app_1_7.c
  19. 0 421
      app_1_8.c
  20. 0 280
      app_1_8_1.c
  21. 0 390
      app_1_8_2.c
  22. 0 263
      app_socket.c
  23. 0 216
      bsp_custom.c
  24. 0 1227
      cisAsynEntry.c
  25. 0 1512
      hal_module_adapter.c
  26. 241 0
      inc/RTE_Device.h
  27. 58 0
      inc/app.h
  28. 16 0
      inc/bsp_custom.h
  29. 428 0
      inc/can.h
  30. 143 0
      inc/cisAsynEntry.h
  31. 143 0
      inc/hal_module_adapter.h
  32. 173 0
      inc/sensor.h
  33. BIN
      软件版本修改记录及备份.xlsx

+ 22 - 0
ARMCC/Makefile

@@ -0,0 +1,22 @@
+AVAILABLE_TARGETS = ec616_0h00
+TOOLCHAIN         = ARMCC
+BINNAME           = qx-app-flash
+TOP               := ../../../../../..
+
+BUILD_AT                    = n
+BUILD_AT_DEBUG              = n
+THIRDPARTY_CISONENET_ENABLE = y
+THIRDPARTY_WAKAAMA_ENABLE   = n
+THIRDPARTY_ERCOAP_ENABLE    = y
+THIRDPARTY_TINYDTLS_ENABLE  = y
+THIRDPARTY_MBEDTLS_ENABLE   = y
+
+CFLAGS_INC        +=  -I ../inc
+
+
+obj-y             += PLAT/project/$(TARGET)/apps/qx_app/src/app.o \
+                     PLAT/project/$(TARGET)/apps/qx_app/src/cisAsynEntry.o \
+		     						PLAT/project/$(TARGET)/apps/qx_app/src/bsp_custom.o \
+									PLAT/project/$(TARGET)/apps/qx_app/src/hal_module_adapter.o
+
+include $(TOP)/PLAT/tools/scripts/Makefile.rules

+ 12 - 0
GCC/Makefile

@@ -0,0 +1,12 @@
+
+AVAILABLE_TARGETS = ec616_0h00
+TOOLCHAIN         = GCC
+BINNAME           = bluejoy-x1-flash
+TOP               := ../../../../../..
+
+CFLAGS_INC        +=  -I ../inc
+obj-y             += PLAT/project/$(TARGET)/apps/bluejoy_x1/src/app.o \
+                     PLAT/project/$(TARGET)/apps/bluejoy_x1/src/bsp_custom.o
+                                        
+
+include $(TOP)/PLAT/tools/scripts/Makefile.rules

+ 0 - 549
app _0_4.c

@@ -1,549 +0,0 @@
-/****************************************************************************
- *
- * Copy right:   2020-, Copyrigths of QIXIANG TECH Ltd.
- * File name:    app.c
- * Description:  QX app source file 
- * History:      Rev1.0   2020-10-16
- * Athuor:       chenjie 
- *
- ****************************************************************************/
-//include 
-#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
-// app task static stack and control block
-#define PROC_TASK_STACK_SIZE    (1024)
-
-
-//uart def
-#define RECV_BUFFER_LEN         (16)
-#define SEND_BUFFER_LEN         (16)
-#define Uart_Send_LEN         (8)
-#define Uart_Rece_LEN         (16)
-#define RTE_UART_RX_IO_MODE      RTE_UART1_RX_IO_MODE
-
-
-//statement variable
-extern ARM_DRIVER_USART Driver_USART1;
-static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
-
-/** \brief usart receive buffer */
-uint8_t recBuffer[RECV_BUFFER_LEN];
-
-/** \brief usart send buffer */
-uint8_t sendBuffer[RECV_BUFFER_LEN];
-
-/** \brief receive timeout flag */
-volatile bool isRecvTimeout = false;
-
-/** \brief receive complete flag */
-volatile bool isRecvComplete = false;
-
-uint8_t Uart_Rece_buffer[Uart_Rece_LEN];
-uint8_t Uart_Data_buffer[8];
-
-/** \brief 电压传输 */
-
-UINT8 *Uart_Rece_BattCellU1_U4;
-UINT8 *Uart_Rece_BattCellU5_U8;
-UINT8 *Uart_Rece_BattCellU9_U12;
-UINT8 *Uart_Rece_BattCellU13_U14;
-UINT8 *Uart_Rece_BattT;
-
-volatile bool Can_Task_Flag = false;
-volatile bool Uart_Task_Flag = false;
-
-
-typedef enum
-{
-    PROCESS1_STATE_IDLE = 0,
-    PROCESS1_STATE_WORK,
-    PROCESS1_STATE_SLEEP
-}process1SM;
-typedef enum
-{
-    PROCESS2_STATE_IDLE = 0,
-    PROCESS2_STATE_WORK,
-    PROCESS2_STATE_SLEEP
-}process2SM;
-
-static StaticTask_t           gProcessTask0;
-static UINT8                    gProcessTaskStack0[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask1;
-static UINT8                    gProcessTaskStack1[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask2;
-static UINT8                    gProcessTaskStack2[PROC_TASK_STACK_SIZE];
-
-static process1SM 		    gProc1State = PROCESS1_STATE_IDLE;
-static process2SM 		    gProc2State = PROCESS2_STATE_IDLE;
-#define PROC1_STATE_SWITCH(a)  (gProc1State = a)
-#define PROC2_STATE_SWITCH(a)  (gProc2State = a)
-
-
-
-
-unsigned int crc_chk(unsigned char* data, unsigned char length)
-{  
-    int j;
-    unsigned int 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;
-}
-
-uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg)
-{
-    uint16_t CRC_chk_buffer;
-    uint8_t Uart_Send_buffer[Uart_Send_LEN];
-    uint8_t Rece_Data_Len;
-    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;
-    USARTdrv->Send(Uart_Send_buffer,8);
-    Uart_Rece_buffer[0]=0xfe;
-    uint8_t timeout=0;
-    while((timeout<10)&&(Uart_Rece_buffer[0]!=0x01))
-    {
-        USARTdrv->Receive(Uart_Rece_buffer,13);
-        timeout++;
-        osDelay(10);
-    }
-    Rece_Data_Len = 11;
-
-    if (Uart_Rece_buffer[0]==0xfe)//没收到数据,全部为空值
-    {
-        Uart_Data_buffer[0] = 0x00;
-        Uart_Data_buffer[1] = 0x00;
-        Uart_Data_buffer[2] = 0x00;
-        Uart_Data_buffer[3] = 0x00;
-        Uart_Data_buffer[4] = 0x00;
-        Uart_Data_buffer[5] = 0x00;
-        Uart_Data_buffer[6] = 0x00;
-        Uart_Data_buffer[7] = 0x00;
-        return Uart_Data_buffer;
-    }
-    else
-    {
-        CRC_chk_buffer =Uart_Rece_buffer[12]<<8|Uart_Rece_buffer[11];
-        if (CRC_chk_buffer == crc_chk(Uart_Rece_buffer,11))//满足校验
-        {
-            for (uint8_t i = 0; i < 8; i++)
-            {
-                Uart_Data_buffer[i]=Uart_Rece_buffer[i+3];
-            }
-            return Uart_Data_buffer;
-        }
-        else //接收数据的校验不过
-        {
-            Uart_Data_buffer[0] = 0xff;
-            Uart_Data_buffer[1] = 0xff;
-            Uart_Data_buffer[2] = 0xff;
-            Uart_Data_buffer[3] = 0xff;
-            Uart_Data_buffer[4] = 0xff;
-            Uart_Data_buffer[5] = 0xff;
-            Uart_Data_buffer[6] = 0xff;
-            Uart_Data_buffer[7] = 0xff;
-            return Uart_Data_buffer;
-        }
-        
-
-    }
-}
-void USART_callback(uint32_t event)
-{
-    if(event & ARM_USART_EVENT_RX_TIMEOUT)
-    {
-        isRecvTimeout = true;
-    }
-    if(event & ARM_USART_EVENT_RECEIVE_COMPLETE)
-    {
-        isRecvComplete = true;
-    }
-}
-static void process0AppTask(void* arg)
-{
-    UINT8 Can_index = 0;
-    UINT8 Uart_index = 0;
-    Can_Task_Flag = false;
-    Uart_Task_Flag = false;
-    while(1)
-    {
-        osDelay(10);//10ms
-        Can_index++;
-        Uart_index++;
-        if (Uart_index >=10)//Uart 100ms 调用一次
-        {
-            Uart_Task_Flag = true;
-            Uart_index = 0;
-        }
-        if (Can_index >=10)//Can 100ms 调用一次
-        {
-            Can_Task_Flag = true;
-            Can_index = 0;
-        } 
-    }
-}
-static void process1AppTask(void* arg)
-{
-	PROC1_STATE_SWITCH(PROCESS1_STATE_IDLE);
-    uint32_t Can_ID;
-    UINT8 value;
-    NVIC_EnableIRQ(PadWakeup0_IRQn);
-    Can_InitType param;
-    Can_TxMsgType Can_TxMsg;
-    param.baudrate = CAN_500Kbps;
-    param.mode = REQOP_NORMAL;
-    param.TxStdIDH = 0x00;
-    param.TxStdIDL = 0x00;
-    param.RxStdIDH[0] = 0x00;
-    param.RxStdIDL[0] = 0x00;
-    /*stdid 0000 0000 001x*/
-    param.RxStdIDH[1] = 0x00;
-    param.RxStdIDL[1] = 0x20;
-    /*stdid 0000 0000 010x */
-    param.RxStdIDH[2] = 0x00;
-    param.RxStdIDL[2] = 0x40;
-    /*stdid 0000 0000 011x*/
-    param.RxStdIDH[3] = 0x00;
-    param.RxStdIDL[3] =0x60;
-    /*stdid 0000 0000 100x */
-    param.RxStdIDH[4] = 0x00;
-    param.RxStdIDL[4] = 0x80;
-    /*stdid 0000 0000 101x*/
-    param.RxStdIDH[5] = 0x00;
-    param.RxStdIDL[5] =0xa0;
-    param.packType = STD_PACK;
-    HAL_Can_Init(param);
-    int send_index = 0;
-
-    while(1)
-    {
-        switch(gProc1State)
-        {
-            case PROCESS1_STATE_IDLE:
-            {
-                if(Can_Task_Flag)
-                {
-                    PROC1_STATE_SWITCH(PROCESS1_STATE_WORK);
-                    FaultDisplay(LED_TURN_ON);
-                }
-                break;
-            }
-            case PROCESS1_STATE_WORK:
-            {
-                switch(send_index)
-                {
-                case 0:
-                {
-                    Can_ID = 0x001;
-                    Can_TxMsg.Data[0] = *(Uart_Rece_BattCellU1_U4+0);
-                    Can_TxMsg.Data[1] = *(Uart_Rece_BattCellU1_U4+1);
-                    Can_TxMsg.Data[2] = *(Uart_Rece_BattCellU1_U4+2);
-                    Can_TxMsg.Data[3] = *(Uart_Rece_BattCellU1_U4+3);
-                    Can_TxMsg.Data[4] = *(Uart_Rece_BattCellU1_U4+4);
-                    Can_TxMsg.Data[5] = *(Uart_Rece_BattCellU1_U4+5);
-                    Can_TxMsg.Data[6] = *(Uart_Rece_BattCellU1_U4+6);
-                    Can_TxMsg.Data[7] = *(Uart_Rece_BattCellU1_U4+7);
-                    break;
-                }
-                case 1:
-                {
-                    Can_ID = 0x011;
-                    Can_TxMsg.Data[0] = *(Uart_Rece_BattCellU5_U8+0);
-                    Can_TxMsg.Data[1] = *(Uart_Rece_BattCellU5_U8+1);
-                    Can_TxMsg.Data[2] = *(Uart_Rece_BattCellU5_U8+2);
-                    Can_TxMsg.Data[3] = *(Uart_Rece_BattCellU5_U8+3);
-                    Can_TxMsg.Data[4] = *(Uart_Rece_BattCellU5_U8+4);
-                    Can_TxMsg.Data[5] = *(Uart_Rece_BattCellU5_U8+5);
-                    Can_TxMsg.Data[6] = *(Uart_Rece_BattCellU5_U8+6);
-                    Can_TxMsg.Data[7] = *(Uart_Rece_BattCellU5_U8+7);
-                    break;
-                }
-                case 2:
-                {
-                    Can_ID = 0x021;
-                    Can_TxMsg.Data[0] = *(Uart_Rece_BattCellU9_U12+0);
-                    Can_TxMsg.Data[1] = *(Uart_Rece_BattCellU9_U12+1);
-                    Can_TxMsg.Data[2] = *(Uart_Rece_BattCellU9_U12+2);
-                    Can_TxMsg.Data[3] = *(Uart_Rece_BattCellU9_U12+3);
-                    Can_TxMsg.Data[4] = *(Uart_Rece_BattCellU9_U12+4);
-                    Can_TxMsg.Data[5] = *(Uart_Rece_BattCellU9_U12+5);
-                    Can_TxMsg.Data[6] = *(Uart_Rece_BattCellU9_U12+6);
-                    Can_TxMsg.Data[7] = *(Uart_Rece_BattCellU9_U12+7);
-                    break;
-                }
-                case 3:
-                {
-                    Can_ID = 0x031;
-                    Can_TxMsg.Data[0] = *(Uart_Rece_BattCellU13_U14+0);
-                    Can_TxMsg.Data[1] = *(Uart_Rece_BattCellU13_U14+1);
-                    Can_TxMsg.Data[2] = *(Uart_Rece_BattCellU13_U14+2);
-                    Can_TxMsg.Data[3] = *(Uart_Rece_BattCellU13_U14+3);
-                    Can_TxMsg.Data[4] = 0x00;
-                    Can_TxMsg.Data[5] = 0x00;
-                    Can_TxMsg.Data[6] = 0x00;
-                    Can_TxMsg.Data[7] = 0x00;
-                    break;
-                }
-                // case 4:
-                // {
-                //     Can_ID = 0x041;
-                //     Can_TxMsg.Data[0] = send_index;
-                //     Can_TxMsg.Data[1] = 0x00;
-                //     Can_TxMsg.Data[2] = 0x00;
-                //     Can_TxMsg.Data[3] = 0x00;
-                //     Can_TxMsg.Data[4] = 0x00;
-                //     Can_TxMsg.Data[5] = 0x00;
-                //     Can_TxMsg.Data[6] = 0x00;
-                //     Can_TxMsg.Data[7] = 0x00;
-                //     break;
-                // }
-                }
-
-                Can_TxMsg.stdIDH = Can_ID>>3;
-                Can_TxMsg.stdIDL = Can_ID<<5;
-                Can_TxMsg.DLC  = 8;
-                HAL_Can_Transmit(Can_TxMsg);
-                send_index++; 
-                if (send_index >3)
-                {
-                    send_index = 0;
-                    FaultDisplay(LED_TURN_OFF);	
-                    Can_Task_Flag  = false;
-                    PROC1_STATE_SWITCH(PROCESS1_STATE_IDLE);
-                }
-                break;
-            }
-            case PROCESS1_STATE_SLEEP:
-            {                                     
-                break;
-            }
-        }
-    }
-}
-static void process2AppTask(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);
-    uint8_t *chk_point;
-    int Rece_index = 0;
-    Uart_Receive_Type Uart_Receive_Msg;
-	PROC2_STATE_SWITCH(PROCESS2_STATE_IDLE);
-    while(1)
-    {
-        switch(gProc2State)
-        {
-            case PROCESS2_STATE_IDLE:
-            {   
-                if(Uart_Task_Flag)
-                {
-                    NetSocDisplay(3,LED_TURN_ON);
-                    Rece_index = 0;
-                    PROC2_STATE_SWITCH(PROCESS2_STATE_WORK);
-                }
-                break;
-            }
-            case PROCESS2_STATE_WORK:
-            {
-                Uart_Receive_Msg.Bms_Address = 0x01;
-                Uart_Receive_Msg.Bms_Read_Funcode = 0x03;
-
-                switch(Rece_index)
-                {
-                    case 0://读取电压1-4
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L = 0x02;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Rece_BattCellU1_U4 = Uart_Receive_func(Uart_Receive_Msg);
-                        break;
-                    }
-                    case 1://读取电压5-8
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x06;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Rece_BattCellU5_U8 = Uart_Receive_func(Uart_Receive_Msg);
-                        break;
-                    }
-                    case 2:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x0A;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Rece_BattCellU9_U12 = Uart_Receive_func(Uart_Receive_Msg);
-                        break;
-                    }
-                    case 3:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x0E;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Rece_BattCellU13_U14 = Uart_Receive_func(Uart_Receive_Msg);
-                        break;
-                    }
-                }
-                Rece_index++;
-                if (Rece_index>3)
-                {
-                    Rece_index=0;
-                    Uart_Task_Flag = false;
-                    NetSocDisplay(3,LED_TURN_OFF);
-                    PROC2_STATE_SWITCH(PROCESS2_STATE_IDLE);
-                 }
-                break;
-            }
-            case PROCESS2_STATE_SLEEP:
-            {	        
-                //此处写休眠程序
-                break;
-            }
-        }
-    }
-}
-/**
-  \fn          process0Init(void)
-  \brief       process0Init function.
-  \return
-*/
-void process0Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack0, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process0AppTask";
-    task_attr.stack_mem = gProcessTaskStack0;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask0;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process0AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process1Init(void)
-  \brief       process1Init function.
-  \return
-*/
-void process1Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack1, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process1AppTask";
-    task_attr.stack_mem = gProcessTaskStack1;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask1;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process1AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process2Init(void)
-  \brief       process2Init function.
-  \return
-*/
-void process2Init(void)
-{
-    osThreadAttr_t task_attr;
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack2, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process2AppTask";
-    task_attr.stack_mem = gProcessTaskStack2;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask2;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process2AppTask, NULL, &task_attr);
-}
-/**
-  \fn          appInit(void)
-  \brief       appInit function.
-  \return
-*/
-void appInit(void *arg)
-{   
-    process0Init();
-	process1Init();
-    process2Init();
-}
-
-/**
-  \fn          int main_entry(void)
-  \brief       main entry function.
-  \return
-*/
-void main_entry(void) {
-
-    BSP_CommonInit();
-    osKernelInitialize();
-
-    registerAppEntry(appInit, NULL);
-    if (osKernelGetState() == osKernelReady)
-    {
-        osKernelStart();
-    }
-    while(1);
-}

+ 0 - 736
app _1_7_1.c

@@ -1,736 +0,0 @@
-/****************************************************************************
- *
- * Copy right:   2020-, Copyrigths of QIXIANG TECH Ltd.
- * File name:    app.c
- * Description:  QX app source file 
- * History:      Rev1.0   2020-10-16
- * Athuor:       chenjie 
- *
- ****************************************************************************/
-//include 
-#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
-// app task static stack and control block
-#define PROC_TASK_STACK_SIZE    (1024)
-
-
-//uart def
-#define Uart_Send_LEN         (8)
-#define Uart_Rece_LEN         (16)
-#define RTE_UART_RX_IO_MODE      RTE_UART1_RX_IO_MODE
-
-//statement variable
-extern ARM_DRIVER_USART Driver_USART1;
-static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
-
-/** \brief usart receive buffer */
-uint8_t Uart_Data_buffer[8];
-
-/** \brief usart send buffer */
-
-/** \brief receive timeout flag */
-volatile bool isRecvTimeout = false;
-
-/** \brief receive complete flag */
-volatile bool isRecvComplete = false;
-
-uint8_t process0SlpHandler     = 0xff;
-uint8_t process1SlpHandler     = 0xff;
-uint8_t process2SlpHandler     = 0xff;
-uint8_t deepslpTimerID         = 7;
-
-/** \brief 电压传输 */
-
-uint8_t Uart_Rece_BattCellU1_U4[8];
-uint8_t Uart_Rece_BattCellU5_U8[8];
-uint8_t Uart_Rece_BattCellU9_U12[8];
-uint8_t Uart_Rece_BattCellU13_U14[8];
-uint8_t Uart_Rece_BattT[8];
-int16_t Uart_Rece_BattI=0x0000;
-uint8_t Uart_Rece_Batt_states[6];
-uint16_t Uart_Rece_BattU;
-uint16_t Uart_Rece_Batt_MaxcellU;
-uint16_t Uart_Rece_Batt_MincellU;
-
-uint8_t Can_Rece_buffer[8];
-typedef enum
-{
-    PROCESS_STATE_IDLE = 0,
-    PROCESS_STATE_WORK,
-    PROCESS_STATE_SLEEP
-}processSM;
-typedef enum
-{
-    PROCESS_Uart_STATE_IDLE = 0,
-    PROCESS_Uart_STATE_WORK,
-    PROCESS_Uart_STATE_CHECK,
-    PROCESS_Uart_STATE_SLEEP
-}process_Uart;
-
-static StaticTask_t           gProcessTask0;
-static UINT8                    gProcessTaskStack0[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask1;
-static UINT8                    gProcessTaskStack1[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask2;
-static UINT8                    gProcessTaskStack2[PROC_TASK_STACK_SIZE];
-
-processSM 	    gProc0State = PROCESS_STATE_IDLE;
-process_Uart 	gProc1State = PROCESS_Uart_STATE_IDLE;
-processSM 	    gProc2State = PROCESS_STATE_IDLE;
-#define PROC_Task_STATE_SWITCH(a)  (gProc0State = a) //任务调度切换
-#define PROC_Uart_STATE_SWITCH(a)  (gProc1State = a) //uart 状态切换
-#define PROC_Can_STATE_SWITCH(a)  (gProc2State = a) //can 状态切换
-
-
-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;
-}
-
-uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg)
-{
-    uint8_t Uart_Rece_buffer[Uart_Rece_LEN];
-    uint16_t CRC_Reve_buffer;
-    uint16_t CRC_chk_buffer;
-    uint8_t Uart_Send_buffer[8];
-    uint8_t Rece_Data_Len;
-    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;
-    Uart_Rece_buffer[0]=0xfe;
-    uint32_t timeout=0;
-    USARTdrv->Send(Uart_Send_buffer,8);
-    USARTdrv->Receive(Uart_Rece_buffer,13);
-    Rece_Data_Len = 11;
-    while((isRecvTimeout == false) && (isRecvComplete == false))// 未收到数据不叫时间超时,收到数据但是不全叫时间超时
-    {
-        timeout++;
-        if (timeout>7000000)
-        {
-            timeout =0;
-            isRecvTimeout = true;
-            break;
-        }
-    }
-    if (isRecvComplete == true)
-    {
-        isRecvComplete = false;
-        CRC_chk_buffer =Uart_Rece_buffer[12]<<8|Uart_Rece_buffer[11];
-        CRC_Reve_buffer = crc_chk(Uart_Rece_buffer,11);
-        if (CRC_Reve_buffer == CRC_chk_buffer)//满足校验
-        {
-            for (uint8_t i = 0; i < 8; i++)
-            {
-                Uart_Data_buffer[i]=Uart_Rece_buffer[i+3];
-            }
-            return Uart_Data_buffer;
-        }
-        else //接收数据的校验不过暂时屏蔽
-        {
-            for (uint8_t i = 0; i < 8; i++)
-            {
-                Uart_Data_buffer[i]=0xff;
-            }
-            return Uart_Data_buffer;
-        }
-    }
-    if (isRecvTimeout == true)//没收到数据,全部为空值
-    {
-        Uart_Data_buffer[0] = 0x00;
-        Uart_Data_buffer[1] = 0x00;
-        Uart_Data_buffer[2] = 0x00;
-        Uart_Data_buffer[3] = 0x00;
-        Uart_Data_buffer[4] = 0x00;
-        Uart_Data_buffer[5] = 0x00;
-        Uart_Data_buffer[6] = 0x00;
-        Uart_Data_buffer[7] = 0xff;
-        isRecvTimeout = false;
-        osDelay(1000);
-        return Uart_Data_buffer;
-    }
-}
-void USART_callback(uint32_t event)
-{
-    if(event & ARM_USART_EVENT_RX_TIMEOUT)
-    {
-        isRecvTimeout = true;
-    }
-    if(event & ARM_USART_EVENT_RECEIVE_COMPLETE)
-    {
-        isRecvComplete = true;
-    }
-}
-
-static void process0AppTask(void* arg)
-{
-    uint32_t inParam = 0xAABBCCDD;
-    uint32_t cnt;
-    UINT8 Can_index = 0;
-    UINT8 Uart_index = 0;
-    uint32_t sleep_index = 0;
-    PROC_Task_STATE_SWITCH(PROCESS_STATE_IDLE);
-    NetSocDisplay(0,LED_TURN_OFF);
-    NetSocDisplay(1,LED_TURN_OFF);
-    NetSocDisplay(2,LED_TURN_OFF);
-    NetSocDisplay(3,LED_TURN_OFF);
-    NetSocDisplay(4,LED_TURN_OFF);
-
-
-    slpManSetPmuSleepMode(true,SLP_HIB_STATE,false);
-    slpManApplyPlatVoteHandle("process0slp",&process0SlpHandler);
-    slpManPlatVoteDisableSleep(process0SlpHandler, SLP_SLP2_STATE); 
-    slpManSlpState_t slpstate = slpManGetLastSlpState();
-    if((slpstate == SLP_SLP2_STATE) || (slpstate == SLP_HIB_STATE))
-    {
-        PROC_Task_STATE_SWITCH(PROCESS_STATE_IDLE);
-    }
-    else
-    {
-        PROC_Task_STATE_SWITCH(PROCESS_STATE_WORK);
-    }
-    
-    while(1)
-    {
-        switch(gProc0State)
-        {
-            case PROCESS_STATE_IDLE:
-            {   
-                PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_CHECK);
-                NetSocDisplay(0,LED_TURN_ON);
-                osDelay(100);//delay 100ms
-                if(Uart_Rece_BattI!=0x0000)
-                {
-                    PROC_Task_STATE_SWITCH(PROCESS_STATE_WORK);
-                }
-                sleep_index++;
-                if(sleep_index>=100)
-                {
-                    NetSocDisplay(0,LED_TURN_OFF);
-                    sleep_index=0;
-                    PROC_Task_STATE_SWITCH(PROCESS_STATE_SLEEP);
-                }
-                break;
-            }
-            case PROCESS_STATE_WORK:
-            {
-                osDelay(10);//10ms
-                Can_index++;
-                Uart_index++;
-                if (Uart_index >10)//Uart 100ms 调用一次
-                {
-                    PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_WORK);
-                    Uart_index = 0;
-                }
-                if (Can_index >=100)//Can 1000ms 调用一次
-                {
-                    PROC_Can_STATE_SWITCH(PROCESS_STATE_WORK);
-                    Can_index = 0;
-                }
-                if((Uart_Rece_BattI==0x0000)&&(Can_Rece_buffer[0]==0xff))
-                {
-                    sleep_index++;
-                }
-                else
-                {
-                    sleep_index = 0;
-                }
-
-                if (sleep_index >=6000)
-                {
-                    PROC_Task_STATE_SWITCH(PROCESS_STATE_SLEEP);
-                    sleep_index = 0;
-                }
-                break;
-                
-            }
-            case PROCESS_STATE_SLEEP:
-            {
-
-                slpManSlpState_t State;
-                uint8_t cnt;
-                PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_SLEEP);
-                PROC_Can_STATE_SWITCH(PROCESS_STATE_SLEEP);
-                slpManPlatVoteEnableSleep(process0SlpHandler,SLP_SLP2_STATE);
-                slpManPlatVoteDisableSleep(process0SlpHandler, SLP_HIB_STATE); 
-                slpManDeepSlpTimerStart(deepslpTimerID, 300000); // create a 10s timer, DeepSleep Timer is always oneshoot
-                while(1)                // now app can enter hib, but ps and phy maybe not, so wait here
-                {
-                    osDelay(3000);
-                }
-            }
-        }
-    }
-}
-
-static void process1AppTask(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);
-    int Rece_index = 0;
-    uint8_t *Uart_Reve_Point = NULL;
-    Uart_Receive_Type Uart_Receive_Msg;
-	PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE);
-    slpManPlatVoteDisableSleep(process2SlpHandler, SLP_SLP2_STATE);
-    Uart_Receive_Msg.Bms_Address = 0x01;
-    Uart_Receive_Msg.Bms_Read_Funcode = 0x03;
-    while(1)
-    {
-        switch(gProc1State)
-        {
-            case PROCESS_Uart_STATE_IDLE:
-            {   
-                NetSocDisplay(1,LED_TURN_OFF);     
-                Rece_index = 0;
-                
-                break;
-            }
-            case PROCESS_Uart_STATE_CHECK:
-            {
-                Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                Uart_Receive_Msg.Reg_Begin_L= 0x10;
-                Uart_Receive_Msg.Reg_Num_H = 0x00;
-                Uart_Receive_Msg.Reg_Num_L = 0x04;
-                Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                Uart_Rece_BattI = *(Uart_Reve_Point+0)<<8 | *(Uart_Reve_Point+1);
-                PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE);
-                break;
-            }
-            case PROCESS_Uart_STATE_WORK:
-            {
-                NetSocDisplay(1,LED_TURN_ON);
-                switch(Rece_index)
-                {
-                    case 0://读取电压1-4
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L = 0x02;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU1_U4[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 1://读取电压5-8
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x06;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU5_U8[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 2:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x0A;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU9_U12[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 3:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x0E;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU13_U14[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 4:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x14;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattT[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 5:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x10;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        Uart_Rece_BattI = *(Uart_Reve_Point+0)<<8 | *(Uart_Reve_Point+1);
-                        for (int i = 0; i < 6; i++)
-                        {
-                            Uart_Rece_Batt_states[i] = *(Uart_Reve_Point+2+i);
-                        }
-                        break;
-                    }
-                    case 6:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x2B;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        Uart_Rece_BattU = *(Uart_Reve_Point+0)<<8 | *(Uart_Reve_Point+1);
-                        Uart_Rece_Batt_MaxcellU = *(Uart_Reve_Point+2)<<8 | *(Uart_Reve_Point+3);
-                        Uart_Rece_Batt_MincellU = *(Uart_Reve_Point+4)<<8 | *(Uart_Reve_Point+5);
-                        break;
-                    }
-                    default:
-                    {
-                       PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE);
-                        break;
-                    }
-                }
-                Rece_index++;
-                break;
-            }
-            case PROCESS_Uart_STATE_SLEEP:
-            {	
-                slpManPlatVoteEnableSleep(process2SlpHandler, SLP_SLP2_STATE);  
-                slpManPlatVoteDisableSleep(process2SlpHandler, SLP_HIB_STATE);  
-                while(1)
-                {
-                    osDelay(3000);
-                }           
-                //此处休眠
-                break;
-            }
-        }
-    }
-}
-static void process2AppTask(void* arg)
-{
-	PROC_Can_STATE_SWITCH(PROCESS_STATE_IDLE);
-    uint32_t Can_ID;
-    NVIC_EnableIRQ(PadWakeup1_IRQn);
-    Can_InitType param;
-    Can_TxMsgType Can_TxMsg;
-    param.baudrate = CAN_500Kbps;
-    param.mode = REQOP_NORMAL;
-    param.TxStdIDH = 0x00;
-    param.TxStdIDL = 0x00;
-    param.RxStdIDH[0] = 0x00;
-    param.RxStdIDL[0] = 0x00;
-    /*stdid 0000 0000 001x*/
-    param.RxStdIDH[1] = 0x00;
-    param.RxStdIDL[1] = 0x20;
-    /*stdid 0000 0000 010x */
-    param.RxStdIDH[2] = 0x00;
-    param.RxStdIDL[2] = 0x40;
-    /*stdid 0000 0000 011x*/
-    param.RxStdIDH[3] = 0x00;
-    param.RxStdIDL[3] =0x60;
-    /*stdid 0000 0000 100x */
-    param.RxStdIDH[4] = 0x00;
-    param.RxStdIDL[4] = 0x80;
-    /*stdid 0000 0000 101x*/
-    param.RxStdIDH[5] = 0x00;
-    param.RxStdIDL[5] =0xa0;
-    param.packType = STD_PACK;
-    HAL_Can_Init(param);
-    int send_index = 0;
-    slpManPlatVoteDisableSleep(process1SlpHandler, SLP_SLP2_STATE);
-    while(1)
-    {
-        switch(gProc2State)
-        {
-            case PROCESS_STATE_IDLE:
-            {
-                HAL_Can_Receive(Can_Rece_buffer);
-                send_index = 0;
-                break;
-            }
-            case PROCESS_STATE_WORK:
-            {
-                switch(send_index)
-                {
-                    case 0:
-                    {
-                        Can_ID = 0x001;
-                        for (int i = 0; i < 8; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU1_U4[i];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 1:
-                    {
-                        Can_ID = 0x013;
-                        for (int i = 0; i < 8; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU5_U8[i];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 2:
-                    {
-                        Can_ID = 0x021;
-                        for (int i = 0; i < 8; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU9_U12[i];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 3:
-                    {
-                        Can_ID = 0x031;
-                        for (int i = 0; i < 4; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU13_U14[i];
-                        }
-                        Can_TxMsg.Data[4] = 0x00;
-                        Can_TxMsg.Data[5] = 0x00;
-                        Can_TxMsg.Data[6] = 0x00;
-                        Can_TxMsg.Data[7] = 0x00;
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 4:
-                    {
-                        Can_ID  = 0x101;
-                        for (int i = 0; i < 4; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattT[i*2+1];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 5:
-                    {
-                        Can_ID = 0x201;
-                        Can_TxMsg.Data[0] = Uart_Rece_BattU>>8;
-                        Can_TxMsg.Data[1] = Uart_Rece_BattU;
-                        Can_TxMsg.Data[2] = 0x00;
-                        Can_TxMsg.Data[3] = 0x00;//外电压
-                        Can_TxMsg.Data[4] = 0x00;
-                        Can_TxMsg.Data[5] = 0x00;//累加电压
-                        Can_TxMsg.Data[6] = Uart_Rece_BattI>>8;
-                        Can_TxMsg.Data[7] = Uart_Rece_BattI;
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-
-                    }
-                    case 6:
-                    {
-                        Can_ID = 0x211;
-                        Can_TxMsg.Data[0] = Uart_Rece_Batt_MaxcellU>>8;
-                        Can_TxMsg.Data[1] = Uart_Rece_Batt_MaxcellU;
-                        Can_TxMsg.Data[2] = Uart_Rece_Batt_MincellU>>8;
-                        Can_TxMsg.Data[3] = Uart_Rece_Batt_MincellU;
-                        Can_TxMsg.Data[4] = 0x00;
-                        Can_TxMsg.Data[5] = 0x00;
-                        Can_TxMsg.Data[6] = 0x00;
-                        Can_TxMsg.Data[7] = 0x00;
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-
-                    }
-                    default:
-                    {
-                       PROC_Can_STATE_SWITCH(PROCESS_STATE_IDLE);
-                       Can_Rece_buffer[0]=0xff;
-                    }
-                }
-                send_index ++;	
-                break;
-            }
-            case PROCESS_STATE_SLEEP:
-            {   
-                slpManPlatVoteEnableSleep(process1SlpHandler, SLP_SLP2_STATE); 
-                slpManPlatVoteDisableSleep(process1SlpHandler, SLP_HIB_STATE);   
-                while(1)
-                {
-                    osDelay(3000);
-                }                                     
-                break;
-            }
-        }
-    }
-}
-/**
-  \fn          process0Init(void)
-  \brief       process0Init function.
-  \return
-*/
-void process0Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack0, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process0AppTask";
-    task_attr.stack_mem = gProcessTaskStack0;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask0;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process0AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process1Init(void)
-  \brief       process1Init function.
-  \return
-*/
-void process1Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack1, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process1AppTask";
-    task_attr.stack_mem = gProcessTaskStack1;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask1;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process1AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process2Init(void)
-  \brief       process2Init function.
-  \return
-*/
-void process2Init(void)
-{
-    osThreadAttr_t task_attr;
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack2, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process2AppTask";
-    task_attr.stack_mem = gProcessTaskStack2;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask2;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process2AppTask, NULL, &task_attr);
-}
-/**
-  \fn          appInit(void)
-  \brief       appInit function.
-  \return
-*/
-void appInit(void *arg)
-{   
-    process0Init();//任务调度和检测程序
-	process1Init();//Uart程序
-    process2Init();//Can程序
-}
-
-/**
-  \fn          int main_entry(void)
-  \brief       main entry function.
-  \return
-*/
-void main_entry(void) {
-
-    BSP_CommonInit();
-    osKernelInitialize();
-
-    registerAppEntry(appInit, NULL);
-    if (osKernelGetState() == osKernelReady)
-    {
-        osKernelStart();
-    }
-    while(1);
-}

+ 0 - 915
app.c

@@ -1,915 +0,0 @@
-/****************************************************************************
- *
- * Copy right:   2020-, Copyrigths of QIXIANG TECH Ltd.
- * File name:    app.c
- * Description:  QX app source file 
- * History:      Rev1.0   2020-10-16
- * Athuor:       chenjie 
- *
- ****************************************************************************/
-//include 
-#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
-// app task static stack and control block
-#define PROC_TASK_STACK_SIZE    (1024)
-
-
-//uart def
-#define Uart_Send_LEN         (8)
-#define Uart_Rece_LEN         (40)//串口读取的最大数量,40个字节,能满足一次性读取17个单体
-#define RTE_UART_RX_IO_MODE      RTE_UART1_RX_IO_MODE
-
-//statement variable
-extern ARM_DRIVER_USART Driver_USART1;
-static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
-
-/** \brief receive timeout flag */
-volatile bool isRecvTimeout = false;
-
-/** \brief receive complete flag */
-volatile bool isRecvComplete = false;
-
-uint8_t process0SlpHandler     = 0xff;
-uint8_t process1SlpHandler     = 0xff;
-uint8_t process2SlpHandler     = 0xff;
-uint8_t process3SlpHandler     = 0xff;
-uint8_t Can_Rece_buffer[8];
-uint8_t Batt_Cell_Num = 14;//默认数值14、17
-uint8_t Batt_Cell_Num_2 ;//默认数值
-uint8_t Batt_Temp_Num = 5;//默认数值5、7
-int16_t Uart_Rece_BattI=0x0000;
-uint8_t battbuffer[73];//电池数据都存在此数组中————电压14,温度5
-/**
- *  存放规则如下:
- * 位置:   0       1       2       3       4       5       6       7       8       9       10      11      12      13      14      15              16             
- * 数据:   年      月      日      时      分      秒    信息体标志  年      月      日      时      分       秒    网络信号  故障等级  故障代码高     故障代码低
- * 
- *         17      18       19          20          21          22         23       24      25      26 27 28 29   30       30+1 .... 30+X*2      31+X*2       31+1...31+X*2+N
- *         电流H    电流L  Link电压H    Link电压L   Pack电压H   Pack电压L   开关状态   SOC     SOH    均衡状态      单体个数X    单体v1...单体vX   温度个数N     温度1..温度N    
- *          32+X*2+N     33+X*2+N 
- *          电池状态    是否加热
- * */
-uint16_t data_index = 0x0000;
-
-typedef enum
-{
-    PROCESS_STATE_IDLE = 0,
-    PROCESS_STATE_WORK,
-    PROCESS_STATE_SLEEP
-}processSM;
-typedef enum
-{
-    PROCESS_Uart_STATE_IDLE = 0,
-    PROCESS_Uart_STATE_WORK,
-    PROCESS_Uart_STATE_CHECK,
-    PROCESS_Uart_STATE_SLEEP
-}process_Uart;
-typedef enum
-{
-    PROCESS_NB_STATE_IDLE = 0,
-    PROCESS_NB_STATE_WORK,
-    PROCESS_NB_STATE_CONNECT,
-    PROCESS_NB_STATE_SLEEP
-}process_NB;
-static StaticTask_t           gProcessTask0;
-static UINT8                    gProcessTaskStack0[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask1;
-static UINT8                    gProcessTaskStack1[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask2;
-static UINT8                    gProcessTaskStack2[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask3;
-static UINT8                    gProcessTaskStack3[PROC_TASK_STACK_SIZE];
-
-processSM 	    gProc0State = PROCESS_STATE_IDLE;
-process_Uart 	gProc1State = PROCESS_Uart_STATE_IDLE;
-processSM 	    gProc2State = PROCESS_STATE_IDLE;
-process_NB	    gProc3State = PROCESS_NB_STATE_IDLE;
-#define PROC_Task_STATE_SWITCH(a)  (gProc0State = a) //任务调度切换
-#define PROC_Uart_STATE_SWITCH(a)  (gProc1State = a) //uart 状态切换
-#define PROC_Can_STATE_SWITCH(a)  (gProc2State = a) //can 状态切换
-#define PROC_NB_STATE_SWITCH(a)  (gProc3State = a) //NB状态切换
-uint8_t deepslpTimerID          = 7;
-//-------------------------------------------------------------------------------------------------------------------------------------------------------
-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;
-}
-uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg,uint8_t *Uart_Rece_buffer)
-{
-    uint16_t CRC_Rece_buffer;
-    uint16_t CRC_chk_buffer;
-    uint8_t Uart_Send_buffer[8];
-    uint8_t Rece_Data_Len;
-    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=0;
-    USARTdrv->Send(Uart_Send_buffer,8);
-    Rece_Data_Len = Uart_Receive_Msg.Reg_Num_L<<1;//读取几个寄存器的值,数据长度乘以二
-    USARTdrv->Receive(Uart_Rece_buffer,Rece_Data_Len+5);
-    while((isRecvTimeout == false) && (isRecvComplete == false))// 未收到数据不叫时间超时,收到数据但是不全叫时间超时
-    {
-        timeout++;
-        if (timeout>7000000)
-        {
-            timeout =0;
-            isRecvTimeout = true;
-            break;
-        }
-    }
-    if (isRecvComplete == true)
-    {
-        Rece_Data_Len = *(Uart_Rece_buffer+2);
-        isRecvComplete = false;
-        CRC_Rece_buffer =*(Uart_Rece_buffer+Rece_Data_Len+4)<<8|*(Uart_Rece_buffer+Rece_Data_Len+3);
-        CRC_chk_buffer = crc_chk(Uart_Rece_buffer,Rece_Data_Len+3);  
-        // #ifdef USING_PRINTF
-        //     // printf("Uart_Send_buffer:  ");
-        //     // for(int i=0;i<8;i++)
-        //     // {
-        //     // printf("%x ",Uart_Send_buffer[i]);
-        //     // }
-        //     // printf("\n");
-        //     printf("Uart_Rece_buffer: ");
-        //     for(int i=0;i<Rece_Data_Len+5;i++)
-        //     {
-        //     printf("%x ",*(Uart_Rece_buffer+i));
-        //     }
-        //     printf("crcchk:%x,%x  ",CRC_chk_buffer,CRC_Rece_buffer);
-        // #endif
-        if (CRC_Rece_buffer == CRC_chk_buffer)//满足校验
-        {
-            return Uart_Rece_buffer+3;
-        }
-        else //接收数据的校验不过暂时屏蔽
-        {
-            memset(Uart_Rece_buffer,0xff,Uart_Rece_LEN);
-            return Uart_Rece_buffer;
-        }
-    }
-    if (isRecvTimeout == true)//没收到数据,全部为空值
-    {
-        memset(Uart_Rece_buffer,0x00,Uart_Rece_LEN);
-        isRecvTimeout = false;
-        osDelay(1000);
-        return Uart_Rece_buffer;
-    }
-    return Uart_Rece_buffer;
-}
-void USART_callback(uint32_t event)
-{
-    if(event & ARM_USART_EVENT_RX_TIMEOUT)
-    {
-        isRecvTimeout = true;
-    }
-    if(event & ARM_USART_EVENT_RECEIVE_COMPLETE)
-    {
-        isRecvComplete = true;
-    }
-}
-
-static void process0AppTask(void* arg)//任务调度程序
-{
-    UINT16 Can_index = 0;
-    UINT16 Uart_index = 0;
-    UINT16 NB_index  = 0;
-    uint32_t sleep_index = 0;
-    PROC_Task_STATE_SWITCH(PROCESS_STATE_IDLE);
-    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("process0slp",&process0SlpHandler);
-    slpManPlatVoteDisableSleep(process0SlpHandler, SLP_SLP2_STATE); 
-    slpManSlpState_t slpstate = slpManGetLastSlpState();
-    #ifdef USING_PRINTF
-            printf("slpstate:%d \n",slpstate);
-    #endif
-    if((slpstate == SLP_SLP2_STATE) || (slpstate == SLP_HIB_STATE))
-    {
-        PROC_Task_STATE_SWITCH(PROCESS_STATE_IDLE);
-    }
-    else
-    {
-        PROC_Task_STATE_SWITCH(PROCESS_STATE_WORK);
-    }
-    
-    while(1)
-    {
-        switch(gProc0State)
-        {
-            case PROCESS_STATE_IDLE:
-            {   
-                #ifdef USING_PRINTF
-                        printf("wake up 2s \n");
-                #endif
-                PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_CHECK);
-                NetSocDisplay(LED_SOC_0,LED_TURN_ON);
-                osDelay(100);//delay 100ms
-                if(Uart_Rece_BattI!=0x0000)
-                {
-                    PROC_Task_STATE_SWITCH(PROCESS_STATE_WORK);
-                }
-                sleep_index++;
-                if(sleep_index>=50)
-                {
-                    NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
-                    sleep_index=0;
-                    PROC_Task_STATE_SWITCH(PROCESS_STATE_SLEEP);
-                }
-                break;
-            }
-            case PROCESS_STATE_WORK:
-            {
-                osDelay(10);//10ms
-                Can_index++;
-                Uart_index++;
-                NB_index++;
-                if (Uart_index >10)//Uart 100ms 调用一次
-                {
-                    PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_WORK);
-                    Uart_index = 0;
-                }
-                if (Can_index >=100)//Can 1000ms 调用一次
-                {
-                    PROC_Can_STATE_SWITCH(PROCESS_STATE_WORK);
-                    Can_index = 0;
-                }
-                if (NB_index >=1000)//NB 10s 调用一次
-                {
-                    PROC_NB_STATE_SWITCH(PROCESS_NB_STATE_CONNECT);
-                    NB_index = 0;
-                }
-                if((Uart_Rece_BattI==0x0000)&&(Can_Rece_buffer[0]==0xff))
-                {
-                    sleep_index++;
-                }
-                else
-                {
-                    sleep_index = 0;
-                }
-
-                if (sleep_index >=6000)
-                {
-                    PROC_Task_STATE_SWITCH(PROCESS_STATE_SLEEP);
-                    sleep_index = 0;
-                }
-                break;
-                
-            }
-            case PROCESS_STATE_SLEEP:
-            {
-                PROC_NB_STATE_SWITCH(PROCESS_NB_STATE_SLEEP);
-                PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_SLEEP);
-                PROC_Can_STATE_SWITCH(PROCESS_STATE_SLEEP);
-                slpManPlatVoteEnableSleep(process0SlpHandler,SLP_SLP2_STATE);
-                slpManPlatVoteDisableSleep(process0SlpHandler, SLP_HIB_STATE); 
-                #ifdef USING_PRINTF
-                        printf("ready to sleep \n");
-                #endif
-                slpManDeepSlpTimerStart(deepslpTimerID,60000); // create a 60s timer, DeepSleep Timer is always oneshoot
-                while(1)                // now app can enter hib, but ps and phy maybe not, so wait here
-                {
-                    osDelay(3000);
-                }
-            }
-        }
-    }
-}
-
-static void process1AppTask(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);
-    int Rece_index = 0;
-    uint8_t *Uart_Reve_Point = NULL;
-    Uart_Receive_Type Uart_Receive_Msg;
-	PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE);
-    slpManApplyPlatVoteHandle("process1slp",&process1SlpHandler);
-    Uart_Receive_Msg.Bms_Address = 0x01;
-    Uart_Receive_Msg.Bms_Read_Funcode = 0x03;
-    uint8_t *Uart_Rece_buffer;
-    Batt_Cell_Num_2 = Batt_Cell_Num<<1;
-    while(1)
-    {
-        switch(gProc1State)
-        {
-            case PROCESS_Uart_STATE_IDLE:
-            {   
-                NetSocDisplay(LED_SOC_1,LED_TURN_OFF);     
-                Rece_index = 0;
-                break;
-            }
-            case PROCESS_Uart_STATE_CHECK://检查电流数值
-            {
-                Uart_Rece_buffer = (uint8_t *)malloc(16);
-                memset(Uart_Rece_buffer,0xff,8);
-                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;
-                Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer);
-                Uart_Rece_BattI = *(Uart_Reve_Point+0)<<8 |*(Uart_Reve_Point+1);
-                #ifdef USING_PRINTF
-                        printf("Check_Current!");
-                #endif
-                free(Uart_Rece_buffer);
-                PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE);
-                break;
-            }
-            case PROCESS_Uart_STATE_WORK:
-            {
-                NetSocDisplay(LED_SOC_1,LED_TURN_ON);
-                Uart_Rece_buffer = (uint8_t *)malloc(Uart_Rece_LEN);
-                memset(Uart_Rece_buffer,0xff,Uart_Rece_LEN);
-                switch(Rece_index)
-                {
-                    case 0://读取电流
-                    {
-                        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;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer);
-                        Uart_Rece_BattI = *(Uart_Reve_Point+0)<<8 |*(Uart_Reve_Point+1);
-                        break;
-                    }
-                    case 1://读取单体电压
-                    {
-                        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;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer);
-                        // #ifdef USING_PRINTF
-                        //     printf("BattCellV: ");
-                        //     for (size_t i = 0; i < Batt_Cell_Num_2; i++)
-                        //     {
-                        //         printf("%x ",*(Uart_Reve_Point+i));
-                        //     }
-                        //     printf("\n");
-                        // #endif
-                        battbuffer[30] = Batt_Cell_Num;
-                        memcpy(&battbuffer[31],Uart_Reve_Point,Batt_Cell_Num_2);
-                        break;
-                    }
-                    case 2://读取温度
-                    {
-                        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;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer);
-                        battbuffer[31+Batt_Cell_Num_2] = Batt_Temp_Num;
-                        for (int i = 0; i < Batt_Temp_Num; i++)
-                        {
-                            battbuffer[32+Batt_Cell_Num_2+i] = *(Uart_Reve_Point+2*i+1);
-                        }
-                        // #ifdef USING_PRINTF
-                        //     printf("BattCellT: ");
-                        //     for (size_t i = 0; i < Batt_Temp_Num; i++)
-                        //     {
-                        //         printf("%x ",*(Uart_Reve_Point+2*i+1));
-                        //     }
-                        //     printf("\n");
-                        // #endif
-                        break;
-                    }
-                    case 3://读取总电压,目前保护板只有一个电压
-                    {
-                        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;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer);
-                        battbuffer[19] = *(Uart_Reve_Point+0);//Link U
-                        battbuffer[20] = *(Uart_Reve_Point+1);
-                        battbuffer[21] = *(Uart_Reve_Point+0);//Pack U
-                        battbuffer[22] = *(Uart_Reve_Point+1);
-                        break;
-                    }
-                    case 4://读取状态及SOC
-                    {
-                        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;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer);
-                        battbuffer[23] = *(Uart_Reve_Point+0)>>1;//mos状态
-                        battbuffer[24] = *(Uart_Reve_Point+5);//SOC
-                        battbuffer[25] = *(Uart_Reve_Point+7);//SOH
-                        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;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer);
-                        memcpy(&battbuffer[26],Uart_Reve_Point,4);
-                        break;
-                    }
-                    default:
-                    {
-                        PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE);
-                        break;
-                    }
-                }
-                Rece_index++;
-                free(Uart_Rece_buffer);
-                break;
-            }
-            case PROCESS_Uart_STATE_SLEEP:
-            {	 
-                while(1)
-                {
-                    osDelay(3000);
-                }           
-                //此处休眠
-            }
-        }
-    }
-}
-static void process2AppTask(void* arg)
-{
-	PROC_Can_STATE_SWITCH(PROCESS_STATE_IDLE);
-    slpManApplyPlatVoteHandle("process2slp",&process2SlpHandler);
-    uint32_t Can_ID;
-    Can_InitType param;
-    Can_TxMsgType Can_TxMsg;
-    param.baudrate = CAN_500Kbps;
-    param.mode = REQOP_NORMAL;
-    param.TxStdIDH = 0x00;
-    param.TxStdIDL = 0x00;
-    param.RxStdIDH[0] = 0x00;
-    param.RxStdIDL[0] = 0x00;
-    /*stdid 0000 0000 001x*/
-    param.RxStdIDH[1] = 0x00;
-    param.RxStdIDL[1] = 0x20;
-    /*stdid 0000 0000 010x */
-    param.RxStdIDH[2] = 0x00;
-    param.RxStdIDL[2] = 0x40;
-    /*stdid 0000 0000 011x*/
-    param.RxStdIDH[3] = 0x00;
-    param.RxStdIDL[3] =0x60;
-    /*stdid 0000 0000 100x */
-    param.RxStdIDH[4] = 0x00;
-    param.RxStdIDL[4] = 0x80;
-    /*stdid 0000 0000 101x*/
-    param.RxStdIDH[5] = 0x00;
-    param.RxStdIDL[5] =0xa0;
-    param.packType = STD_PACK;
-    HAL_Can_Init(param);
-    int send_index = 0;
-    while(1)
-    {
-        switch(gProc2State)
-        {
-            case PROCESS_STATE_IDLE:
-            {
-                HAL_Can_Receive(Can_Rece_buffer);
-                send_index = 0;
-                break;
-            }
-            case PROCESS_STATE_WORK:
-            {
-                switch(send_index)
-                {
-                    case 0:
-                    {
-                        Can_ID = 0x001;
-                        for (int i = 0; i < 8; i++)
-                        {
-                            Can_TxMsg.Data[i] = battbuffer[i+31+send_index*8];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 1:
-                    {
-                        Can_ID = 0x013;
-                        for (int i = 0; i < 8; i++)
-                        {
-                            Can_TxMsg.Data[i] = battbuffer[i+31+send_index*8];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 2:
-                    {
-                        Can_ID = 0x021;
-                        for (int i = 0; i < 8; i++)
-                        {
-                            Can_TxMsg.Data[i] = battbuffer[i+31+send_index*8];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 3:
-                    {
-                        Can_ID = 0x031;
-                        for (int i = 0; i < 4; i++)
-                        {
-                            Can_TxMsg.Data[i] = battbuffer[i+31+send_index*8];
-                        }
-                        Can_TxMsg.Data[4] = 0x00;
-                        Can_TxMsg.Data[5] = 0x00;
-                        Can_TxMsg.Data[6] = 0x00;
-                        Can_TxMsg.Data[7] = 0x00;
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 4:
-                    {
-                        Can_ID  = 0x101;
-                        for (int i = 0; i < 4; i++)
-                        { 
-                            Can_TxMsg.Data[2*i] = 0x00;
-                            Can_TxMsg.Data[2*i+1] = battbuffer[i+32+Batt_Cell_Num_2];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    default:
-                    {
-                       PROC_Can_STATE_SWITCH(PROCESS_STATE_IDLE);
-                       Can_Rece_buffer[0]=0xff;
-                       break;
-                    }
-                }
-                // #ifdef USING_PRINTF
-                //     printf("CANID:%#x  Msg:  ",Can_ID);
-                //     for (size_t i = 0; i < 8; i++)
-                //     {
-                //         printf("%x ",Can_TxMsg.Data[i]);
-                //     }
-                //     printf("\n");
-                // #endif
-                // #ifdef USING_PRINTF
-                //         printf("CANsend :%x\n ",Can_ID);
-                // #endif
-                send_index ++;	
-                break;
-            }
-            case PROCESS_STATE_SLEEP:
-            {    
-                while(1)
-                {
-                    osDelay(3000);
-                }                                     
-            }
-        }
-    }
-}
-uint8_t bcc_chk(uint8_t* data, uint8_t length)
-{
-    uint8_t bcc_chk_return = 0x00;
-    uint8_t count = 0;
-    while (count<length)
-    {
-        bcc_chk_return^=data[count];
-        count++;
-    }
-    return  bcc_chk_return;
-}
-void TcpCallBack(void)
-{
-    #ifdef USING_PRINTF
-        printf("[%d]TcpCallBacl\n",__LINE__);
-    #endif
-}
-void Tcp_Data_Assemble(uint8_t datatype)
-{
-    int16_t Batt_current;
-    Batt_current = Uart_Rece_BattI;
-    OsaUtcTimeTValue timestracture;
-    appGetSystemTimeUtcSync(&timestracture);
-    battbuffer[0] = timestracture.UTCtimer1>>16;
-    battbuffer[0] = battbuffer[0] - 0x07D0;
-    battbuffer[1] = timestracture.UTCtimer1>>8;
-    battbuffer[2] = timestracture.UTCtimer1;
-    battbuffer[3] = timestracture.UTCtimer2>>24;
-    battbuffer[4] = timestracture.UTCtimer2>>16;
-    battbuffer[5] = timestracture.UTCtimer2>>8;
-    switch (datatype)
-    {
-    case 0x80:
-    {
-        battbuffer[6] = 0x80;//信息体标志,此处为电池信息
-        battbuffer[7] = battbuffer[0];//年 
-        battbuffer[8] = battbuffer[1];//月
-        battbuffer[9] = battbuffer[2];//日
-        battbuffer[10] = battbuffer[3];//时 0时区时间
-        battbuffer[11] = battbuffer[4];//分
-        battbuffer[12] = battbuffer[5];//秒
-
-        battbuffer[13] = 0x1A;// 网络信号
-        battbuffer[14] = 0x00;//故障等级
-        battbuffer[15] = 0x00;//故障代码高
-        battbuffer[16] = 0x00;//故障代码低
-        //电流适应性更改,从int转换到uint,加1000的偏移量,100mA的单位
-        if (Batt_current>0x8000)
-        {
-            Batt_current = Batt_current|0x7fff;
-            Batt_current = 0x2710 - Batt_current;
-            Batt_current = Batt_current;
-        }
-        else
-        {
-            Batt_current = Batt_current+0x2710;
-            Batt_current = Batt_current;
-        }
-        
-        battbuffer[17] = Batt_current>>8;
-        battbuffer[18] = Batt_current;
-
-        data_index = 32+Batt_Cell_Num_2+Batt_Temp_Num;
-        battbuffer[data_index] = 0x00;//电池状态
-        data_index++;
-        battbuffer[data_index] = 0x00;//是否加热
-        data_index++;
-
-        break;
-    }
-    default:
-        break;
-    }
-    return;
-}
-static void process3AppTask(void* arg)
-{
-    CHAR SN[] = "GYTEST00000000003";
-    CHAR   serverip[] = "47.97.127.222";
-    UINT16 serverport = 8712;
-    int TcpConnectID = -1;
-    int TcpSendID = -1;
-    int NB_send_len=59+Batt_Cell_Num_2+Batt_Temp_Num;//设定网络发送最大数值
-    slpManApplyPlatVoteHandle("process3slp",&process3SlpHandler);
-	PROC_NB_STATE_SWITCH(PROCESS_NB_STATE_IDLE);
-
-    while(1)
-    {
-        switch(gProc3State)
-        {
-            case PROCESS_NB_STATE_IDLE:
-            {
-                osDelay(100);
-                break;
-            }
-            case PROCESS_NB_STATE_CONNECT:
-            {
-                while(TcpConnectID<0)
-                {
-                    TcpConnectID = tcpipConnectionCreate(1,PNULL,PNULL,serverip,serverport,TcpCallBack);
-                    osDelay(100);
-                    #ifdef USING_PRINTF
-                        printf("ConnectID:%d\n ",TcpConnectID);
-                    #endif
-                }
-                PROC_NB_STATE_SWITCH(PROCESS_NB_STATE_WORK);
-                break;
-            }
-            case PROCESS_NB_STATE_WORK:
-            {
-                uint8_t* TcpSendBuffer;
-                TcpSendBuffer = (uint8_t *)malloc(NB_send_len);//申请发送的数据内存
-                if (!TcpSendBuffer)
-                {
-                    #ifdef USING_PRINTF
-                        printf("[%d]malloc error! \r\n",__LINE__);
-                    #endif
-                }
-                memset(TcpSendBuffer,0x00,92);
-                *(TcpSendBuffer+0) = 0x23;
-                *(TcpSendBuffer+1) = 0x23;
-                *(TcpSendBuffer+2) = 0x02;
-                *(TcpSendBuffer+3) = 0xfe;
-                memcpy(TcpSendBuffer+4,SN,17);
-                *(TcpSendBuffer+21) = 0x01;//不加密
-                Tcp_Data_Assemble(0x80);
-                
-                *(TcpSendBuffer+22) = data_index>>8;//数据长度
-                *(TcpSendBuffer+23) = data_index;//数据长度
-
-                memcpy(TcpSendBuffer+24,battbuffer,data_index);
-                #ifdef USING_PRINTF
-                    printf("battbuffer:");
-                    for (int i = 0; i < data_index; i++)
-                    {
-                        printf("%x ",battbuffer[i]);
-                    }
-                    printf("\n ");
-                #endif
-                *(TcpSendBuffer+NB_send_len-1) = bcc_chk(TcpSendBuffer,NB_send_len-1);
-                // #ifdef USING_PRINTF
-                //     printf("[%d]sizeof:%d \r\n",__LINE__,sizeof(TcpSendBuffer)-1);
-                // #endif
-                // #ifdef USING_PRINTF
-                //     printf("[%d]Tcpchk:%#X \r\n",__LINE__,*(TcpSendBuffer+91));
-                // #endif
-                TcpSendID  = tcpipConnectionSend(TcpConnectID,TcpSendBuffer,NB_send_len,PNULL,PNULL,PNULL);
-                #ifdef USING_PRINTF
-                    printf("ConnectID:%d,TcpSend:%d,data length:%d,Data:  ",TcpConnectID,TcpSendID,NB_send_len);
-                    for (int i = 0; i < NB_send_len; i++)
-                    {
-                        printf("%x ",*(TcpSendBuffer+i));
-                    }
-                    printf("\n ");
-                #endif
-
-                free(TcpSendBuffer);
-                PROC_NB_STATE_SWITCH(PROCESS_NB_STATE_IDLE);
-                break;
-            }
-            case PROCESS_NB_STATE_SLEEP:
-            {     
-                while(1)
-                {
-                    osDelay(3000);
-                }                                     
-            }
-        }
-    }
-}
-/**
-  \fn          process0Init(void)
-  \brief       process0Init function.
-  \return
-*/
-void process0Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack0, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process0AppTask";
-    task_attr.stack_mem = gProcessTaskStack0;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask0;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process0AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process1Init(void)
-  \brief       process1Init function.
-  \return
-*/
-void process1Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack1, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process1AppTask";
-    task_attr.stack_mem = gProcessTaskStack1;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask1;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process1AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process2Init(void)
-  \brief       process2Init function.
-  \return
-*/
-void process2Init(void)
-{
-    osThreadAttr_t task_attr;
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack2, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process2AppTask";
-    task_attr.stack_mem = gProcessTaskStack2;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask2;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process2AppTask, NULL, &task_attr);
-}
-void process3Init(void)
-{
-    osThreadAttr_t task_attr;
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack3, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process3AppTask";
-    task_attr.stack_mem = gProcessTaskStack3;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask3;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process3AppTask, NULL, &task_attr);
-}
-/**
-  \fn          appInit(void)
-  \brief       appInit function.
-  \return
-*/
-void appInit(void *arg)
-{   
-    process0Init();//任务调度和检测程序
-	process1Init();//Uart程序
-    process2Init();//Can程序
-    process3Init();//NB程序
-}
-
-/**
-  \fn          int main_entry(void)
-  \brief       main entry function.
-  \return
-*/
-void main_entry(void) {
-
-    BSP_CommonInit();
-    osKernelInitialize();
-
-    registerAppEntry(appInit, NULL);
-    if (osKernelGetState() == osKernelReady)
-    {
-        osKernelStart();
-    }
-    while(1);
-}

+ 0 - 577
app_0_1.c

@@ -1,577 +0,0 @@
-/****************************************************************************
- *
- * Copy right:   2017-, Copyrigths of EigenComm Ltd.
- * File name:    app.c
- * Description:  EC616 onenet demo app source file
- * History:      Rev1.0   2018-10-12
- *
- ****************************************************************************/
-#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"
-
-
-// app task static stack and control block
-#define PROC_TASK_STACK_SIZE           (1024)
-#define ONENET_TASK_STACK_SIZE        (1024)
-#define RECV_BUFFER_LEN     (16)
-#define RTE_UART_RX_IO_MODE     RTE_UART1_RX_IO_MODE
-extern ARM_DRIVER_USART Driver_USART1;
-static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
-
-/** \brief usart receive buffer */
-uint8_t recBuffer[RECV_BUFFER_LEN];
-
-/** \brief usart send buffer */
-uint8_t sendBuffer[RECV_BUFFER_LEN];
-
-/** \brief receive timeout flag */
-volatile bool isRecvTimeout = false;
-
-/** \brief receive complete flag */
-volatile bool isRecvComplete = false;
-
-typedef enum
-{
-    PROCESS_STATE_IDLE = 0,
-    PROCESS_STATE_WORK,
-    PROCESS_STATE_SLEEP
-}processSM;
-
-
-static StaticTask_t           gOnenetTask;
-static uint8_t                  gOnenetTaskStack[ONENET_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask;
-static UINT8                    gProcessTaskStack[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask2;
-static UINT8                    gProcessTaskStack2[PROC_TASK_STACK_SIZE];
-
-static processSM 		    gProcState = PROCESS_STATE_IDLE;
-
-#define PROC_STATE_SWITCH(a)  (gProcState = a)
-
-
-
-static UINT8                    gImsi[16] = {0};
-static UINT32                   gCellID = 0;
-static NmAtiSyncRet           gNetworkInfo;
-static appRunningState_t        stateMachine = APP_INIT_STATE;
-uint8_t onenetASlpHandler    = 0xff;
-uint8_t processSlpHandler     = 0xff;
-
-
-static INT32 onenetPSUrcCallback(urcID_t eventID, void *param, UINT32 paramLen)
-{
-    UINT8 rssi = 0;
-    CmiSimImsiStr *imsi = NULL;
-    CmiPsCeregInd *cereg = NULL;
-    NmAtiNetifInfo *netif = NULL;
-
-    switch(eventID)
-    {
-        case NB_URC_ID_SIM_READY:
-        {
-            imsi = (CmiSimImsiStr *)param;
-            //memcpy(gImsi, imsi->contents, imsi->length);
-            //DEBUG_TRACE(APP, TRACE_LEVEL_INFO,"SIM ready(imsi=%s len=%d)", imsi->contents, imsi->length);
-            break;
-        }
-        case NB_URC_ID_MM_SIGQ:
-        {
-            rssi = *(UINT8 *)param;
-            ECOMM_TRACE(UNILOG_PLA_APP, onenetPSUrcCallback_1, P_INFO, 1, "URCCallBack:RSSI signal=%d", rssi);
-            break;
-        }
-        case NB_URC_ID_PS_BEARER_ACTED:
-        {
-            ECOMM_TRACE(UNILOG_PLA_APP, onenetPSUrcCallback_2, P_INFO, 0, "URCCallBack:Default bearer activated");
-            break;
-        }
-        case NB_URC_ID_PS_BEARER_DEACTED:
-        {
-            ECOMM_TRACE(UNILOG_PLA_APP, onenetPSUrcCallback_3, P_INFO, 0, "URCCallBack:Default bearer Deactivated");
-            break;
-        }
-        case NB_URC_ID_PS_CEREG_CHANGED:
-        {
-            cereg = (CmiPsCeregInd *)param;
-            gCellID = cereg->celId;
-            ECOMM_TRACE(UNILOG_PLA_APP, onenetPSUrcCallback_4, P_INFO, 4, "URCCallBack:CEREG changed act:%d celId:%d locPresent:%d tac:%d", cereg->act, cereg->celId, cereg->locPresent, cereg->tac);
-            break;
-        }
-        case NB_URC_ID_PS_NETINFO:
-        {
-            netif = (NmAtiNetifInfo *)param;
-            if (netif->netStatus == NM_NETIF_ACTIVATED)
-            {
-                stateMachine = APP_IPREADY_STATE;
-                ECOMM_TRACE(UNILOG_PLA_APP, onenetPSUrcCallback_5, P_INFO, 0, "URCCallBack:PSIF network active");
-            }
-            else if (netif->netStatus == NM_NETIF_OOS)
-            {
-                ECOMM_TRACE(UNILOG_PLA_APP, onenetPSUrcCallback_6, P_INFO, 0, "URCCallBack:PSIF network OOS");
-            }
-            else if (netif->netStatus == NM_NO_NETIF_OR_DEACTIVATED ||
-                     netif->netStatus == NM_NO_NETIF_NOT_DIAL)
-            {
-                stateMachine = APP_DEACTIVE_STATE;
-                ECOMM_TRACE(UNILOG_PLA_APP, onenetPSUrcCallback_7, P_INFO, 0, "URCCallBack:PSIF network deactive");
-            }
-            break;
-
-        }
-    }
-    return 0;
-}
-
-
-
-static void onenetAppTask(void *arg)
-{
-    cis_version_t ver;
-    UINT8 cid[CMI_PS_CID_NUM] = {0};
-    UINT8 cidlen = 0;
-    INT8 ret;
-    UINT8 psmMode = 0, actType = 0, edrxModeValue = 0;
-    UINT16 tac = 0;
-    UINT32 tauTime = 0, activeTime = 0, cellID = 0, nwEdrxValueMs = 0, nwPtwMs = 0, reqEdrxValueMs = 0;
-    UINT8 csq = 0, regstate = 0;
-    INT8  snr = 0;
-    INT8  rsrp = 0;
-	
-    cis_version(&ver);
-#ifdef USING_PRINTF
-	printf("[%d]CIS SDK Version:%d.%d.%d",__LINE__,ver.major,ver.minor,ver.micro);
-#else	
-    ECOMM_TRACE(UNILOG_PLA_APP, onenetAppTask_0, P_INFO, 3, "CIS SDK Version:%u.%u.%u",ver.major,ver.minor,ver.micro);
-#endif
-  //  slpManSetPmuSleepMode(true, SLP_SLP2_STATE, false);	
-  //  slpManApplyPlatVoteHandle("onenetAppTask",&onenetASlpHandler); 
-   // slpManPlatVoteDisableSleep(onenetASlpHandler, SLP_SLP2_STATE); 
-    while (1)
-    {       
-#ifdef USING_PRINTF
-	printf("[%d]stateMachine:%d \r\n",__LINE__ ,stateMachine);
-#else	
-    ECOMM_TRACE(UNILOG_PLA_APP, onenetAppTask_sm, P_INFO, 1, "stateMachine:%u",stateMachine);
-#endif	   
-        switch(stateMachine)
-        {
-            case APP_INIT_STATE:
-                osDelay(2000/portTICK_PERIOD_MS);
-                break;
-            case APP_DEACTIVE_STATE:
-                cisOnenetDeinit();
-               
-#ifdef USING_PRINTF
-	printf("[%d] deinit onenet \r\n",__LINE__);
-#else	
-    ECOMM_TRACE(UNILOG_PLA_APP, onenetAppTask_1, P_INFO, 0, "deinit onenet");
-#endif				
-                break;
-            case APP_IPREADY_STATE:
-               {
-                    appGetImsiNumSync(gImsi);
-                    
-#ifdef USING_PRINTF
-	 printf("[%d]IMSI = %s \r\n", __LINE__,gImsi);
-#else	
-    ECOMM_STRING(UNILOG_PLA_STRING, onenetAppTask_2, P_INFO, "IMSI = %s", gImsi);
-#endif
-
-                    ret = appGetSignalInfoSync(&csq, &snr, &rsrp);
-
-#ifdef USING_PRINTF
-	 printf("[%d] SNR=%d csq=%d, rsrp=%d\r\n",__LINE__, snr, csq, rsrp);
-#else	
-        ECOMM_TRACE(UNILOG_PLA_APP, onenetAppTask_SIG, P_INFO, 3, "SNR=%d csq=%d, rsrp=%d", snr, csq, rsrp);
-#endif					
-
-                    ret = appGetLocationInfoSync(&tac, &cellID);
-#ifdef USING_PRINTF
-	  printf("[%d]tac=%d, cellID=%d ret=%d",__LINE__, tac, cellID, ret);
-#else	
-     ECOMM_TRACE(UNILOG_PLA_APP, onenetAppTask_3, P_INFO, 3, "tac=%d, cellID=%d ret=%d", tac, cellID, ret);
-#endif					
-                   
-
-	                    ret = appGetEDRXSettingSync(&actType, &nwEdrxValueMs, &nwPtwMs);
-	                   
-#ifdef USING_PRINTF
-	  printf("[%d]actType=%d, nwEdrxValueMs=%d nwPtwMs=%d ret=%d",__LINE__, actType, nwEdrxValueMs, nwPtwMs, ret);
-#else	
-      ECOMM_TRACE(UNILOG_PLA_APP, onenetAppTask_4, P_INFO, 4, "actType=%d, nwEdrxValueMs=%d nwPtwMs=%d ret=%d", actType, nwEdrxValueMs, nwPtwMs, ret);
-#endif
-	                    appGetPSMSettingSync(&psmMode, &tauTime, &activeTime);
-#ifdef USING_PRINTF						
-						printf("[%d]Get PSM info mode=%d, TAU=%d, ActiveTime=%d", __LINE__, psmMode, tauTime, activeTime);
-#else						
-	                    ECOMM_TRACE(UNILOG_PLA_APP, onenetAppTask_5, P_INFO, 3, "Get PSM info mode=%d, TAU=%d, ActiveTime=%d", psmMode, tauTime, activeTime);
-#endif						
-	                    if (psmMode == 0)
-	                         appSetPSMSettingSync(1, 12*60*60, 100);
-	                    // Make user obj/instance/resource
-	                    prvMakeUserdata();
-	                    cisOnenetInit();
-	                    stateMachine = APP_REPORT_STATE;
-	                    break;
-	                }
-	            case APP_REPORT_STATE:
-	                {
-#ifdef USING_PRINTF						
-					printf("[%d]check cis if ready\r\n",__LINE__);
-#else
-					ECOMM_TRACE(UNILOG_PLA_APP, onenetAppTask_6, P_INFO, 0, "check cis if ready");
-#endif					
-	                    if (cisAsyncCheckNotificationReady())
-	                    {
-	                        if (cisAsynGetNotifyOnceStatus())
-	                        {
-	                            stateMachine = APP_IDLE_STATE;
-	                            break;
-	                        }
-	                        else
-	                        {
-	                            prvMakeUserdata();
-	                            cisDataObserveReport();
-	                        }
-	                    }
-	                    osDelay(10000/portTICK_PERIOD_MS);
-	                    break;
-	                }
-	             case  APP_IDLE_STATE:
-	                {
-				//slpManPlatVoteEnableSleep(onenetASlpHandler, SLP_SLP2_STATE);  // cancel the prohibition of sleep2
-				while(1)
-				{
-#ifdef USING_PRINTF				
-				printf("[%d]Waiting sleep\r\n",__LINE__);
-#else
-					ECOMM_TRACE(UNILOG_PLA_APP, onenetAppTask_sl0, P_INFO, 0, "Waiting sleep");
-#endif
-					osDelay(1000/portTICK_PERIOD_MS);
-				}
-				break;
-			   
-	                 }
-
-   	 }
-    }
-
-}
-static void ProcBeforeSlp1(void *pdata, slpManLpState state)
-{
-	slpManSlpState_t State = slpManPlatGetSlpState();
-#ifdef USING_PRINTF				
-	printf("[%d]slp state=%d",__LINE__,State);
-#else
-	ECOMM_TRACE(UNILOG_PLA_APP, ProcBeforeSlp1_0, P_SIG, 1, "slp state=%u",State);
-#endif	
-	
-	/*Latch AONIO*/
-	slpManAONIOLatchEn(AonIOLatch_Enable);
-	IOLatchEn res = slpManAONIOGetLatchCfg();
-	
-#ifdef USING_PRINTF				
-	printf("[%d]Get AONIO latch = %d\r\n",__LINE__,res);
-#else
-	ECOMM_TRACE(UNILOG_PLA_APP, ProcBeforeSlp1_1, P_SIG, 1, "Get AONIO latch = %u",res);
-#endif
-
-}
-
-static void ProcAfterSlp1(void *pdata, slpManLpState state)
-{
-    /*restore AONIO status*/
-	PowerPinConfig(AON_IO);	
-#ifdef USING_PRINTF
-	printf("[%d]After Sleep1, no matter sleep success or not this function will excute\r\n",__LINE__);
-#else		
-	ECOMM_TRACE(UNILOG_PLA_APP, ProcAfterSlp1_1, P_SIG, 0, "After Sleep1, no matter sleep success or not this function will excute");
-#endif	
-}
-
-static void ProcBeforeSlp2(void *pdata, slpManLpState state)
-{
-#ifdef USING_PRINTF
-	printf("[%d]Before Sleep2\r\n",__LINE__);
-#else		
-	 ECOMM_TRACE(UNILOG_PLA_APP, ProcBeforeSlp2_1, P_SIG, 0, "Before Sleep2");
-#endif
-   
-}
-
-static void ProcAfterSlp2(void *pdata, slpManLpState state)
-{
-#ifdef USING_PRINTF
-	printf("[%d]Sleep2 Failed, Interrupt Pending. Only sleep failed this function will excute\r\n",__LINE__);
-#else
-    ECOMM_TRACE(UNILOG_PLA_APP, ProcAfterSlp2_1, P_SIG, 0, "Sleep2 Failed, Interrupt Pending. Only sleep failed this function will excute");
-#endif
-}
-
-static void ProcBeforeHib(void *pdata, slpManLpState state)
-{
-    uint32_t *p_param = (uint32_t *)pdata;
-#ifdef USING_PRINTF
-	printf("[%d]Before Hibernate = %x",__LINE__,*p_param);
-#else
-    ECOMM_TRACE(UNILOG_PLA_APP, ProcBeforeHib_1, P_SIG, 1, "Before Hibernate = %x",*p_param);
-#endif
-}
-
-static void ProcAfterHib(void *pdata, slpManLpState state)
-{
-#ifdef USING_PRINTF
-	printf("[%d]Try Hibernate Failed, Interrupt Pending. Only sleep failed this function will excute\r\n",__LINE__);
-#else
-    ECOMM_TRACE(UNILOG_PLA_APP, ProcAfterHib_1, P_SIG, 0, "Try Hibernate Failed, Interrupt Pending. Only sleep failed this function will excute");
-#endif	
-}
-
-void GGACallBack(UINT8 res, UINT8 * params)
-{
-#ifdef USING_PRINTF	
-	printf("GPS:len=%d,data=%s\r\n",res,params);
-#else
-       ECOMM_STRING(UNILOG_PLA_STRING, GPS_DATA, P_INFO, "gps:%s", params);
-#endif
-}
-void USART_callback(uint32_t event)
-{
-    if(event & ARM_USART_EVENT_RX_TIMEOUT)
-    {
-        isRecvTimeout = true;
-    }
-    if(event & ARM_USART_EVENT_RECEIVE_COMPLETE)
-    {
-        isRecvComplete = true;
-    }
-}
-static void processAppTask(void* arg)
-{
-	uint32_t cnt;
-	uint8_t buffer1[RECV_BUFFER_LEN];
-    buffer1[0]=0xff;
-    buffer1[1]=0xfe;
-
-	PROC_STATE_SWITCH(PROCESS_STATE_IDLE);
-    while(1)
-    {
-
-            switch(gProcState)
-            {
-                case PROCESS_STATE_IDLE:
-                {
-
-					//slpManPlatVoteDisableSleep(processSlpHandler, SLP_SLP2_STATE); 
-					PROC_STATE_SWITCH(PROCESS_STATE_WORK);
-					/*
-						trigger irq config
-					*/  
-					NVIC_EnableIRQ(PadWakeup0_IRQn);
-                    break;
-                }
-				case PROCESS_STATE_WORK:
-				{
-					/*just for debug ,PROCESS_STATE_WORK ,This state is used to handle normal business logic */
-					cnt = 2;
-					UINT8 BUF[16]={0};
-					int i=1;
-					while(1)
-					{
-                        i++;
-						NetSocDisplay(0,LED_TURN_OFF);
-						osDelay(100);
-						NetSocDisplay(0,LED_TURN_ON);
-						osDelay(100);
-                        #ifdef USING_PRINTF
-                            printf("[%d]printf_test, i=%d, cnt=%d",__LINE__,i,cnt);
-                        #endif
-                        USARTdrv->Send(buffer1, 2);
-                        ECOMM_TRACE(UNILOG_PLA_APP, APPTask1, P_VALUE, 2, "printf_test, i=%u, cnt=%u",i,cnt);
-                       if (i>1000)
-                       {
-                           break;
-                       }
-                       
-					}
-							
-					/*
-						ready to sleep
-					*/
-                    #ifdef USING_PRINTF
-                        printf("[%d]sleep switch, i=%d, cnt=%d",__LINE__,i,cnt);
-                    #endif
-					PROC_STATE_SWITCH(PROCESS_STATE_SLEEP);
-					break;
-				}
-                case PROCESS_STATE_SLEEP:
-                {	                        
-                    #ifdef USING_PRINTF
-                        printf("[%d]sleep entry");
-                    #endif	                
-					slpManSlpState_t State;
-					uint8_t cnt;
-					osDelay(3000/portTICK_PERIOD_MS);	 
-					break;
-                }
-            }
-    }
-}
-static void process2AppTask(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, 115200);
-
-    uint8_t* greetStr = "UART Echo Demo\n";
-
-    USARTdrv->Send(greetStr, strlen((const char*)greetStr));
-	PROC_STATE_SWITCH(PROCESS_STATE_IDLE);
-
-    while(1)
-    {
-
-            switch(gProcState)
-            {
-                case PROCESS_STATE_IDLE:
-                {
-
-					//slpManPlatVoteDisableSleep(processSlpHandler, SLP_SLP2_STATE); 
-					PROC_STATE_SWITCH(PROCESS_STATE_WORK);
-					/*
-						trigger irq config
-					*/  
-					NVIC_EnableIRQ(PadWakeup0_IRQn);
-                    break;
-                }
-				case PROCESS_STATE_WORK:
-				{
-					/*just for debug ,PROCESS_STATE_WORK ,This state is used to handle normal business logic */
-					UINT8 BUF[16]={0};
-					int i=0;
-                    int cnt=0;
-					while(1)
-					{
-						NetSocDisplay(1,LED_TURN_OFF);
-						osDelay(400);
-						NetSocDisplay(1,LED_TURN_ON);
-						osDelay(600);
-                        USARTdrv->Receive(recBuffer, 16);
-                        USARTdrv->Send(recBuffer, 16);
-					}
-					PROC_STATE_SWITCH(PROCESS_STATE_SLEEP);
-					break;
-				}
-                case PROCESS_STATE_SLEEP:
-                {		                
-					slpManSlpState_t State;
-					uint8_t cnt;
-					osDelay(3000/portTICK_PERIOD_MS);	 
-					break;
-                }
-            }
-    }
-}
-void processInit(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "ProcessAppTask";
-    task_attr.stack_mem = gProcessTaskStack;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(processAppTask, NULL, &task_attr);
-}
-void process2Init(void)
-{
-    osThreadAttr_t task_attr;
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack2, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process2AppTask";
-    task_attr.stack_mem = gProcessTaskStack2;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask2;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process2AppTask, NULL, &task_attr);
-}
-void onenetInit()
-{
-    osThreadAttr_t task_attr;
- 
-
-    registerPSEventCallback(NB_GROUP_ALL_MASK, onenetPSUrcCallback);
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gOnenetTaskStack, 0xA5, ONENET_TASK_STACK_SIZE);
-    task_attr.name = "OnenetAppTask";
-    task_attr.stack_mem = gOnenetTaskStack;
-    task_attr.stack_size = ONENET_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;
-    task_attr.cb_mem = &gOnenetTask;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(onenetAppTask, NULL, &task_attr);
-
-}
-
-void appInit(void *arg)
-{
-	AdcTaskInit();
- //	onenetInit();
-	processInit();
-    process2Init();
-}
-
-/**
-  \fn          int main_entry(void)
-  \brief       main entry function.
-  \return
-*/
-void main_entry(void) {
-
-    BSP_CommonInit();
-    osKernelInitialize();
-
-    registerAppEntry(appInit, NULL);
-    if (osKernelGetState() == osKernelReady)
-    {
-        osKernelStart();
-    }
-    while(1);
-}
-

+ 0 - 460
app_0_2.c

@@ -1,460 +0,0 @@
-/****************************************************************************
- *
- * Copy right:   2020-, Copyrigths of QIXIANG TECH Ltd.
- * File name:    app.c
- * Description:  QX app source file 
- * History:      Rev1.0   2020-10-16
- * Athuor:       chenjie 
- *
- ****************************************************************************/
-//include 
-#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
-// app task static stack and control block
-#define PROC_TASK_STACK_SIZE    (1024)
-
-
-//uart def
-#define RECV_BUFFER_LEN         (16)
-#define SEND_BUFFER_LEN         (16)
-#define Uart_Send_LEN         (8)
-#define Uart_Rece_LEN         (32)
-#define RTE_UART_RX_IO_MODE      RTE_UART1_RX_IO_MODE
-
-
-//statement variable
-extern ARM_DRIVER_USART Driver_USART1;
-static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
-
-/** \brief usart receive buffer */
-uint8_t recBuffer[RECV_BUFFER_LEN];
-
-/** \brief usart send buffer */
-uint8_t sendBuffer[RECV_BUFFER_LEN];
-
-/** \brief receive timeout flag */
-volatile bool isRecvTimeout = false;
-
-/** \brief receive complete flag */
-volatile bool isRecvComplete = false;
-
-volatile bool Rece_complete_flag = false;
-
-uint8_t Uart_Send_buffer[Uart_Send_LEN];
-uint8_t Uart_Send_reg[Uart_Send_LEN];
-
-uint8_t Uart_Rece_CRCbuffer[Uart_Rece_LEN];
-
-static UINT8  Uart_BMS_Address  = 0x01;
-static UINT8  Uart_BMS_read_func = 0x03;
-volatile uint8_t Uart_Send_reg_beginH;
-volatile uint8_t Uart_Send_reg_beginL;
-volatile uint8_t Uart_Send_reg_numH;
-volatile uint8_t Uart_Send_reg_numL;
-volatile uint16_t CRC_chk_Sebuffer;
-volatile uint16_t CRC_chk_Rebuffer;
-volatile uint8_t CAN_stdID;
-/** \brief 电压传输 */
-
-UINT8 *Uart_Rece_battv1_v4;
-UINT8 *Uart_Rece_battv5_v8;
-UINT8 *Uart_Rece_battv8_v12;
-UINT8 *Uart_Rece_battv12_v16;
-
-volatile uint8_t CAN_ID_0[8];
-volatile uint8_t CAN_ID_1[8];
-volatile uint8_t CAN_ID_2[8];
-volatile uint8_t CAN_ID_3[8];
-int send_index = 0;
-
-
-typedef enum
-{
-    PROCESS_STATE_IDLE = 0,
-    PROCESS_STATE_WORK1,
-    PROCESS_STATE_WORK2,
-    PROCESS_STATE_WORK3,
-    PROCESS_STATE_SLEEP
-}processSM;
-
-static StaticTask_t           gProcessTask0;
-static UINT8                    gProcessTaskStack0[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask1;
-static UINT8                    gProcessTaskStack1[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask2;
-static UINT8                    gProcessTaskStack2[PROC_TASK_STACK_SIZE];
-
-static processSM 		    gProcState = PROCESS_STATE_IDLE;
-
-#define PROC_STATE_SWITCH(a)  (gProcState = a)
-
-
-
-
-
-unsigned int crc_chk(unsigned char* data, unsigned char length)
-{  
-    int j;
-    unsigned int 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;
-}
-
-void LED_Control_func(Void)
-{   
-    for (int i = 0; i <=3; i++)
-    {
-        NetSocDisplay(i,LED_TURN_ON);
-        osDelay(100/portTICK_PERIOD_MS);
-    }
-    for (int i = 3; i >= 0; i--)
-    {
-        NetSocDisplay(i,LED_TURN_OFF);
-        osDelay(100/portTICK_PERIOD_MS);
-    }
-}
-uint8_t* Uart_Receive_func(Void)
-{
-    static uint8_t Uart_Rece_buffer[Uart_Rece_LEN];
-    Uart_Send_buffer[0] = Uart_BMS_Address;
-    Uart_Send_buffer[1] = Uart_BMS_read_func;
-    Uart_Send_buffer[2] = Uart_Send_reg_beginH;
-    Uart_Send_buffer[3] = Uart_Send_reg_beginL;
-    Uart_Send_buffer[4] = Uart_Send_reg_numH;
-    Uart_Send_buffer[5] = Uart_Send_reg_numL;
-    CRC_chk_Sebuffer = crc_chk(Uart_Send_buffer,6);
-    Uart_Send_buffer[6] = CRC_chk_Sebuffer;
-    Uart_Send_buffer[7] = CRC_chk_Sebuffer>>8;
-    Uart_Rece_buffer[0]= 0x00;
-    USARTdrv->Send(Uart_Send_buffer,Uart_Send_LEN );
-    USARTdrv->Receive(Uart_Rece_buffer,Uart_Rece_LEN);	
-    for(int i =0;i<11;i++)
-    {
-        Uart_Rece_CRCbuffer[i] = Uart_Rece_buffer[i];
-    }
-
-    CRC_chk_Rebuffer = crc_chk(Uart_Rece_CRCbuffer,11);
-    if (Uart_Rece_buffer[11]==CRC_chk_Rebuffer && Uart_Rece_buffer[12]==CRC_chk_Rebuffer>>8)
-    {
-        return Uart_Rece_buffer;
-    }
-    else
-    {
-        NetSocDisplay(3,LED_TURN_OFF);
-        for (int i = 0; i < 16; i++)
-        {
-            Uart_Rece_buffer[i]=0xff;
-        } 
-        return Uart_Rece_buffer;
-    }
-    
-    //接收数据的校验
-}
-void USART_callback(uint32_t event)
-{
-    if(event & ARM_USART_EVENT_RX_TIMEOUT)
-    {
-        isRecvTimeout = true;
-    }
-    if(event & ARM_USART_EVENT_RECEIVE_COMPLETE)
-    {
-        isRecvComplete = true;
-    }
-}
-static void process0AppTask(void* arg)
-{
-    while(1)
-    {
-        uint32_t msDelay = 0;
-        while (1)
-        {
-            for (uint32_t i = 0; i < 70000; i++)
-            {;}
-            msDelay++;
-        }
-    }
-}
-static void process1AppTask(void* arg)
-{
-	PROC_STATE_SWITCH(PROCESS_STATE_IDLE);
-    uint32_t Can_ID;
-    NVIC_EnableIRQ(PadWakeup0_IRQn);
-    Can_InitType param;
-    Can_TxMsgType Can_TxMsg;
-    param.baudrate = CAN_500Kbps;
-    param.mode = REQOP_NORMAL;
-    param.TxStdIDH = 0x00;
-    param.TxStdIDL = 0x00;
-    param.RxStdIDH[0] = 0x00;
-    param.RxStdIDL[0] = 0x00;
-    /*stdid 0000 0000 001x*/
-    param.RxStdIDH[1] = 0x00;
-    param.RxStdIDL[1] = 0x20;
-    /*stdid 0000 0000 010x */
-    param.RxStdIDH[2] = 0x00;
-    param.RxStdIDL[2] = 0x40;
-    /*stdid 0000 0000 011x*/
-    param.RxStdIDH[3] = 0x00;
-    param.RxStdIDL[3] =0x60;
-    /*stdid 0000 0000 100x */
-    param.RxStdIDH[4] = 0x00;
-    param.RxStdIDL[4] = 0x80;
-    /*stdid 0000 0000 101x*/
-    param.RxStdIDH[5] = 0x00;
-    param.RxStdIDL[5] =0xa0;
-    param.packType = STD_PACK;
-    HAL_Can_Init(param);
-    while(1)
-    {
-        switch(gProcState)
-        {
-            case PROCESS_STATE_IDLE:
-            {
-                PROC_STATE_SWITCH(PROCESS_STATE_WORK1);
-                break;
-            }
-            case PROCESS_STATE_WORK1:
-            {
-                FaultDisplay(LED_TURN_ON);
-                switch(send_index)
-                {
-                case 0:
-                case 1:
-                case 2:
-                case 3:
-                case 4:
-                case 5:
-                {
-                    Can_ID = 0x0009;
-                    Can_TxMsg.stdIDH = Can_ID>>3;
-                    Can_TxMsg.stdIDL = Can_ID<<5;
-                    Can_TxMsg.DLC  = 8;
-                    Can_TxMsg.Data[0] = *(Uart_Rece_battv1_v4+3);
-                    Can_TxMsg.Data[1] = *(Uart_Rece_battv1_v4+4);
-                    Can_TxMsg.Data[2] = *(Uart_Rece_battv1_v4+5);
-                    Can_TxMsg.Data[3] = *(Uart_Rece_battv1_v4+6);
-                    Can_TxMsg.Data[4] = *(Uart_Rece_battv1_v4+7);
-                    Can_TxMsg.Data[5] = *(Uart_Rece_battv1_v4+8);
-                    Can_TxMsg.Data[6] = *(Uart_Rece_battv1_v4+9);
-                    Can_TxMsg.Data[7] = *(Uart_Rece_battv1_v4+10);
-                    HAL_Can_Transmit(Can_TxMsg);
-                    break;
-                }
-                }
-
-                send_index++; 
-                if (send_index >10)
-                {
-                    send_index=0;
-                    PROC_STATE_SWITCH(PROCESS_STATE_SLEEP);
-                }
-                break;
-            }
-            case PROCESS_STATE_SLEEP:
-            {
-                FaultDisplay(LED_TURN_OFF);	                                     
-                osDelay(100/portTICK_PERIOD_MS);
-                PROC_STATE_SWITCH(PROCESS_STATE_WORK1);
-                break;
-            }
-        }
-    }
-}
-static void process2AppTask(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);
-    uint8_t *chk_point;
-    int Rece_index = 0;
-	PROC_STATE_SWITCH(PROCESS_STATE_IDLE);
-    while(1)
-    {
-        switch(gProcState)
-        {
-            case PROCESS_STATE_IDLE:
-            {
-                PROC_STATE_SWITCH(PROCESS_STATE_WORK1);
-                break;
-            }
-            case PROCESS_STATE_WORK1:
-            {
-                NetSocDisplay(3,LED_TURN_ON);
-                Uart_Send_reg_beginH = 0x00;
-                Uart_Send_reg_numH = 0x00;
-                switch(Rece_index)
-                {
-                    case 0:
-                    {
-                        Uart_Send_reg_beginL = 0x02;
-                        Uart_Send_reg_numL = 0x04;	
-                        chk_point = Uart_Receive_func();
-                        Uart_Rece_battv1_v4 = chk_point;
-                        break;
-                    }
-                    default:
-                    {
-                        break;
-                    }
-                        
-                }
-                Rece_index++;
-                if (Rece_index!=0)
-                {
-                    Rece_index=0;
-                }
-                
-                PROC_STATE_SWITCH(PROCESS_STATE_WORK2);
-                break;
-            }
-            case PROCESS_STATE_WORK2:
-            {
-                osDelay(100/portTICK_PERIOD_MS); 
-                PROC_STATE_SWITCH(PROCESS_STATE_WORK1);
-                break;
-            }
-            case PROCESS_STATE_SLEEP:
-            {	        
-                //此处写休眠程序
-                break;
-            }
-        }
-    }
-}
-/**
-  \fn          process0Init(void)
-  \brief       process0Init function.
-  \return
-*/
-void process0Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack0, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process0AppTask";
-    task_attr.stack_mem = gProcessTaskStack0;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask0;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process0AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process1Init(void)
-  \brief       process1Init function.
-  \return
-*/
-void process1Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack1, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process1AppTask";
-    task_attr.stack_mem = gProcessTaskStack1;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask1;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process1AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process2Init(void)
-  \brief       process2Init function.
-  \return
-*/
-void process2Init(void)
-{
-    osThreadAttr_t task_attr;
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack2, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process2AppTask";
-    task_attr.stack_mem = gProcessTaskStack2;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask2;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process2AppTask, NULL, &task_attr);
-}
-/**
-  \fn          appInit(void)
-  \brief       appInit function.
-  \return
-*/
-void appInit(void *arg)
-{   
-    process0Init();
-	process1Init();
-    process2Init();
-}
-
-/**
-  \fn          int main_entry(void)
-  \brief       main entry function.
-  \return
-*/
-void main_entry(void) {
-
-    BSP_CommonInit();
-    osKernelInitialize();
-
-    registerAppEntry(appInit, NULL);
-    if (osKernelGetState() == osKernelReady)
-    {
-        osKernelStart();
-    }
-    while(1);
-}

+ 0 - 522
app_0_3.c

@@ -1,522 +0,0 @@
-/****************************************************************************
- *
- * Copy right:   2020-, Copyrigths of QIXIANG TECH Ltd.
- * File name:    app.c
- * Description:  QX app source file 
- * History:      Rev1.0   2020-10-16
- * Athuor:       chenjie 
- *
- ****************************************************************************/
-//include 
-#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
-// app task static stack and control block
-#define PROC_TASK_STACK_SIZE    (1024)
-
-
-//uart def
-#define RECV_BUFFER_LEN         (16)
-#define SEND_BUFFER_LEN         (16)
-#define Uart_Send_LEN         (8)
-#define Uart_Rece_LEN         (32)
-#define RTE_UART_RX_IO_MODE      RTE_UART1_RX_IO_MODE
-
-
-//statement variable
-extern ARM_DRIVER_USART Driver_USART1;
-static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
-
-/** \brief usart receive buffer */
-uint8_t recBuffer[RECV_BUFFER_LEN];
-
-/** \brief usart send buffer */
-uint8_t sendBuffer[RECV_BUFFER_LEN];
-
-/** \brief receive timeout flag */
-volatile bool isRecvTimeout = false;
-
-/** \brief receive complete flag */
-volatile bool isRecvComplete = false;
-
-uint8_t Uart_Send_reg[Uart_Send_LEN];
-
-uint8_t Uart_Rece_CRCbuffer[Uart_Rece_LEN];
-
-/** \brief 电压传输 */
-
-UINT8 *Uart_Rece_BattCellU1_U4;
-UINT8 *Uart_Rece_BattCellU5_U8;
-UINT8 *Uart_Rece_BattCellU9_U12;
-UINT8 *Uart_Rece_BattCellU13_U16;
-UINT8 *Uart_Rece_BattT;
-
-volatile bool Can_Task_Flag = false;
-volatile bool Uart_Task_Flag = false;
-
-
-typedef enum
-{
-    PROCESS_STATE_IDLE = 0,
-    PROCESS_STATE_WORK,
-    PROCESS_STATE_SLEEP
-}processSM;
-
-static StaticTask_t           gProcessTask0;
-static UINT8                    gProcessTaskStack0[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask1;
-static UINT8                    gProcessTaskStack1[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask2;
-static UINT8                    gProcessTaskStack2[PROC_TASK_STACK_SIZE];
-
-static processSM 		    gProcState = PROCESS_STATE_IDLE;
-
-#define PROC_STATE_SWITCH(a)  (gProcState = a)
-
-
-
-
-
-unsigned int crc_chk(unsigned char* data, unsigned char length)
-{  
-    int j;
-    unsigned int 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;
-}
-
-uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg)
-{
-    volatile uint16_t CRC_chk_Sebuffer;
-    volatile uint16_t CRC_chk_Rebuffer;
-    uint8_t Uart_Send_buffer[Uart_Send_LEN];
-    uint8_t Rece_Data_Len;
-    static uint8_t Uart_Rece_buffer[Uart_Rece_LEN];
-    uint8_t Uart_Rece_Out[Uart_Rece_LEN];
-    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_Sebuffer = crc_chk(Uart_Send_buffer,6);
-    Uart_Send_buffer[6] = CRC_chk_Sebuffer;
-    Uart_Send_buffer[7] = CRC_chk_Sebuffer>>8;
-    USARTdrv->Send(Uart_Send_buffer,Uart_Send_LEN);
-    USARTdrv->Receive(Uart_Rece_buffer,Uart_Rece_LEN);
-    Rece_Data_Len = Uart_Rece_buffer[2]+3;
-    for(uint8_t i =0;i<Rece_Data_Len;i++)
-    {
-        Uart_Rece_CRCbuffer[i] = Uart_Rece_buffer[i];
-    }
-
-    CRC_chk_Rebuffer = crc_chk(Uart_Rece_CRCbuffer,Rece_Data_Len);
-    if (Uart_Rece_buffer[Rece_Data_Len+1]==CRC_chk_Rebuffer && Uart_Rece_buffer[Rece_Data_Len+2]==CRC_chk_Rebuffer>>8)
-    {
-        for (uint8_t i = 0; i <Uart_Rece_buffer[2]; i++)
-        {
-            Uart_Rece_Out[i]=Uart_Rece_buffer[i+3];
-        } 
-        return Uart_Rece_Out;
-    }
-    else
-    {	
-        for (uint8_t i = 0; i <Uart_Rece_buffer[2]; i++)
-        {
-            Uart_Rece_Out[i]=0x00;
-        } 
-        return Uart_Rece_Out;
-    }
-    
-    //接收数据的校验
-}
-void USART_callback(uint32_t event)
-{
-    if(event & ARM_USART_EVENT_RX_TIMEOUT)
-    {
-        isRecvTimeout = true;
-    }
-    if(event & ARM_USART_EVENT_RECEIVE_COMPLETE)
-    {
-        isRecvComplete = true;
-    }
-}
-static void process0AppTask(void* arg)
-{
-    while(1)
-    {
-        UINT8 Can_index = 0;
-        UINT8 Uart_index = 0;
-        Can_Task_Flag = false;
-        Uart_Task_Flag = false;
-
-        for (uint8_t i = 0; i <=10000; i++)//100s
-        {
-            osDelay(10/portTICK_PERIOD_MS);//10ms
-            Can_index++;
-            Uart_index++;
-            if (Uart_index >=50)//Uart 50ms 调用一次
-            {
-                Uart_Task_Flag = true;
-                Uart_index = 0;
-            }
-            if (Can_index >=100)//Can 100ms 调用一次
-            {
-                Can_Task_Flag = true;
-                Can_index = 0;
-            }
-            
-        }
-        
-    }
-}
-static void process1AppTask(void* arg)
-{
-	PROC_STATE_SWITCH(PROCESS_STATE_IDLE);
-    uint32_t Can_ID;
-    NVIC_EnableIRQ(PadWakeup0_IRQn);
-    Can_InitType param;
-    Can_TxMsgType Can_TxMsg;
-    param.baudrate = CAN_500Kbps;
-    param.mode = REQOP_NORMAL;
-    param.TxStdIDH = 0x00;
-    param.TxStdIDL = 0x00;
-    param.RxStdIDH[0] = 0x00;
-    param.RxStdIDL[0] = 0x00;
-    /*stdid 0000 0000 001x*/
-    param.RxStdIDH[1] = 0x00;
-    param.RxStdIDL[1] = 0x20;
-    /*stdid 0000 0000 010x */
-    param.RxStdIDH[2] = 0x00;
-    param.RxStdIDL[2] = 0x40;
-    /*stdid 0000 0000 011x*/
-    param.RxStdIDH[3] = 0x00;
-    param.RxStdIDL[3] =0x60;
-    /*stdid 0000 0000 100x */
-    param.RxStdIDH[4] = 0x00;
-    param.RxStdIDL[4] = 0x80;
-    /*stdid 0000 0000 101x*/
-    param.RxStdIDH[5] = 0x00;
-    param.RxStdIDL[5] =0xa0;
-    param.packType = STD_PACK;
-    HAL_Can_Init(param);
-    int send_index = 0;
-
-    while(1)
-    {
-        switch(gProcState)
-        {
-            case PROCESS_STATE_IDLE:
-            {
-                if(Can_Task_Flag)
-                {
-                    PROC_STATE_SWITCH(PROCESS_STATE_WORK);
-                    FaultDisplay(LED_TURN_ON);
-                }
-                break;
-            }
-            case PROCESS_STATE_WORK:
-            {
-                switch(send_index)
-                {
-                case 0:
-                {
-                    Can_ID = 0x000;
-                    Can_TxMsg.Data[0] = send_index;
-                    Can_TxMsg.Data[1] = 0x00;
-                    Can_TxMsg.Data[2] = 0x00;
-                    Can_TxMsg.Data[3] = 0x00;
-                    Can_TxMsg.Data[4] = 0x00;
-                    Can_TxMsg.Data[5] = 0x00;
-                    Can_TxMsg.Data[6] = 0x00;
-                    Can_TxMsg.Data[7] = 0x00;
-                    break;
-                }
-                case 1:
-                {
-                    Can_ID = 0x001;
-                    Can_TxMsg.Data[0] = send_index;
-                    Can_TxMsg.Data[1] = 0x00;
-                    Can_TxMsg.Data[2] = 0x00;
-                    Can_TxMsg.Data[3] = 0x00;
-                    Can_TxMsg.Data[4] = 0x00;
-                    Can_TxMsg.Data[5] = 0x00;
-                    Can_TxMsg.Data[6] = 0x00;
-                    Can_TxMsg.Data[7] = 0x00;
-                    break;
-                }
-                case 2:
-                {
-                    Can_ID = 0x002;
-                    Can_TxMsg.Data[0] = send_index;
-                    Can_TxMsg.Data[1] = 0x00;
-                    Can_TxMsg.Data[2] = 0x00;
-                    Can_TxMsg.Data[3] = 0x00;
-                    Can_TxMsg.Data[4] = 0x00;
-                    Can_TxMsg.Data[5] = 0x00;
-                    Can_TxMsg.Data[6] = 0x00;
-                    Can_TxMsg.Data[7] = 0x00;
-                    break;
-                }
-                case 3:
-                {
-                    Can_ID = 0x003;
-                    Can_TxMsg.Data[0] = send_index;
-                    Can_TxMsg.Data[1] = 0x00;
-                    Can_TxMsg.Data[2] = 0x00;
-                    Can_TxMsg.Data[3] = 0x00;
-                    Can_TxMsg.Data[4] = 0x00;
-                    Can_TxMsg.Data[5] = 0x00;
-                    Can_TxMsg.Data[6] = 0x00;
-                    Can_TxMsg.Data[7] = 0x00;
-                    break;
-                }
-                case 4:
-                {
-                    Can_ID = 0x004;
-                    Can_TxMsg.Data[0] = send_index;
-                    Can_TxMsg.Data[1] = 0x00;
-                    Can_TxMsg.Data[2] = 0x00;
-                    Can_TxMsg.Data[3] = 0x00;
-                    Can_TxMsg.Data[4] = 0x00;
-                    Can_TxMsg.Data[5] = 0x00;
-                    Can_TxMsg.Data[6] = 0x00;
-                    Can_TxMsg.Data[7] = 0x00;
-                    break;
-                }
-                }
-
-                Can_TxMsg.stdIDH = Can_ID>>3;
-                Can_TxMsg.stdIDL = Can_ID<<5;
-                Can_TxMsg.DLC  = 8;
-                HAL_Can_Transmit(Can_TxMsg);
-                send_index++; 
-                if (send_index >4)
-                {
-                    send_index = 0;
-                    FaultDisplay(LED_TURN_OFF);	
-                    Can_Task_Flag  = false;
-                    PROC_STATE_SWITCH(PROCESS_STATE_IDLE);
-                }
-                break;
-            }
-            case PROCESS_STATE_SLEEP:
-            {                                     
-                break;
-            }
-        }
-    }
-}
-static void process2AppTask(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);
-    uint8_t *chk_point;
-    int Rece_index = 0;
-    Uart_Receive_Type Uart_Receive_Msg;
-	PROC_STATE_SWITCH(PROCESS_STATE_IDLE);
-    while(1)
-    {
-        switch(gProcState)
-        {
-            case PROCESS_STATE_IDLE:
-            {   
-                if(Uart_Task_Flag)
-                {
-                    NetSocDisplay(3,LED_TURN_ON);
-                    Rece_index = 0;
-                    PROC_STATE_SWITCH(PROCESS_STATE_WORK);
-                }
-                break;
-            }
-            case PROCESS_STATE_WORK:
-            {
-                Uart_Receive_Msg.Bms_Address = 0x01;
-                Uart_Receive_Msg.Bms_Read_Funcode = 0x03;
-
-                switch(Rece_index)
-                {
-                    case 0://读取电压1-4
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x02;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Rece_BattCellU1_U4 = Uart_Receive_func(Uart_Receive_Msg);
-                        break;
-                    }
-                    case 1://读取电压5-8
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x06;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Rece_BattCellU5_U8 = Uart_Receive_func(Uart_Receive_Msg);
-                        break;
-                    }
-                    case 2://读取温度
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x14;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x05;
-                        Uart_Rece_BattT = Uart_Receive_func(Uart_Receive_Msg);
-                        break;
-                    }
-                        
-                }
-                Rece_index++;
-                if (Rece_index>3)
-                {
-                    Rece_index=0;
-                    Uart_Task_Flag = false;
-                    NetSocDisplay(3,LED_TURN_OFF);
-                    PROC_STATE_SWITCH(PROCESS_STATE_IDLE);
-                }
-                break;
-            }
-            case PROCESS_STATE_SLEEP:
-            {	        
-                //此处写休眠程序
-                break;
-            }
-        }
-    }
-}
-/**
-  \fn          process0Init(void)
-  \brief       process0Init function.
-  \return
-*/
-void process0Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack0, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process0AppTask";
-    task_attr.stack_mem = gProcessTaskStack0;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask0;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process0AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process1Init(void)
-  \brief       process1Init function.
-  \return
-*/
-void process1Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack1, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process1AppTask";
-    task_attr.stack_mem = gProcessTaskStack1;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask1;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process1AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process2Init(void)
-  \brief       process2Init function.
-  \return
-*/
-void process2Init(void)
-{
-    osThreadAttr_t task_attr;
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack2, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process2AppTask";
-    task_attr.stack_mem = gProcessTaskStack2;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask2;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process2AppTask, NULL, &task_attr);
-}
-/**
-  \fn          appInit(void)
-  \brief       appInit function.
-  \return
-*/
-void appInit(void *arg)
-{   
-    process0Init();
-	process1Init();
-    process2Init();
-}
-
-/**
-  \fn          int main_entry(void)
-  \brief       main entry function.
-  \return
-*/
-void main_entry(void) {
-
-    BSP_CommonInit();
-    osKernelInitialize();
-
-    registerAppEntry(appInit, NULL);
-    if (osKernelGetState() == osKernelReady)
-    {
-        osKernelStart();
-    }
-    while(1);
-}

+ 0 - 526
app_0_5.c

@@ -1,526 +0,0 @@
-/****************************************************************************
- *
- * Copy right:   2020-, Copyrigths of QIXIANG TECH Ltd.
- * File name:    app.c
- * Description:  QX app source file 
- * History:      Rev1.0   2020-10-16
- * Athuor:       chenjie 
- *
- ****************************************************************************/
-//include 
-#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
-// app task static stack and control block
-#define PROC_TASK_STACK_SIZE    (1024)
-
-
-//uart def
-#define Uart_Send_LEN         (8)
-#define Uart_Rece_LEN         (16)
-#define RTE_UART_RX_IO_MODE      RTE_UART1_RX_IO_MODE
-
-//statement variable
-extern ARM_DRIVER_USART Driver_USART1;
-static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
-
-/** \brief usart receive buffer */
-uint8_t Uart_Data_buffer[8];
-
-/** \brief usart send buffer */
-
-/** \brief receive timeout flag */
-volatile bool isRecvTimeout = false;
-
-/** \brief receive complete flag */
-volatile bool isRecvComplete = false;
-
-
-/** \brief 电压传输 */
-
-UINT8 *Uart_Rece_BattCellU1_U4;
-UINT8 *Uart_Rece_BattCellU5_U8;
-UINT8 *Uart_Rece_BattCellU9_U12;
-UINT8 *Uart_Rece_BattCellU13_U14;
-UINT8 *Uart_Rece_BattT;
-
-typedef enum
-{
-    PROCESS1_STATE_IDLE = 0,
-    PROCESS1_STATE_WORK,
-    PROCESS1_STATE_SLEEP
-}process1SM;
-typedef enum
-{
-    PROCESS2_STATE_IDLE = 0,
-    PROCESS2_STATE_WORK,
-    PROCESS2_STATE_SLEEP
-}process2SM;
-
-static StaticTask_t           gProcessTask0;
-static UINT8                    gProcessTaskStack0[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask1;
-static UINT8                    gProcessTaskStack1[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask2;
-static UINT8                    gProcessTaskStack2[PROC_TASK_STACK_SIZE];
-
-process1SM 	gProc1State = PROCESS1_STATE_IDLE;
-process2SM 	gProc2State = PROCESS2_STATE_IDLE;
-#define PROC1_STATE_SWITCH(a)  (gProc1State = a)
-#define PROC2_STATE_SWITCH(a)  (gProc2State = a)
-
-
-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;
-}
-
-uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg)
-{
-    uint8_t Uart_Rece_buffer[Uart_Rece_LEN];
-    uint16_t CRC_Reve_buffer;
-    uint16_t CRC_chk_buffer;
-    uint8_t Uart_Send_buffer[8];
-    uint8_t Rece_Data_Len;
-    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;
-    Uart_Rece_buffer[0]=0xfe;
-    uint32_t timeout=0;
-    USARTdrv->Send(Uart_Send_buffer,8);
-    USARTdrv->Receive(Uart_Rece_buffer,13);
-    Rece_Data_Len = 11;
-    while((isRecvTimeout == false) && (isRecvComplete == false))
-    {
-        timeout++;
-        if (timeout>7000000)
-        {
-            timeout =0;
-            isRecvTimeout = true;
-            break;
-        }
-    }
-    if (isRecvComplete == true)
-    {
-        isRecvComplete = false;
-        //CRC_chk_buffer =Uart_Rece_buffer[12]<<8|Uart_Rece_buffer[11];
-        //CRC_Reve_buffer = crc_chk(Uart_Rece_buffer,11);
-        if (1)//满足校验
-        {
-            for (uint8_t i = 0; i < 8; i++)
-            {
-                Uart_Data_buffer[i]=Uart_Rece_buffer[i+3];
-            }
-            return Uart_Data_buffer;
-        }
-        else //接收数据的校验不过暂时屏蔽
-        {
-            for (uint8_t i = 0; i < 8; i++)
-            {
-                Uart_Data_buffer[i]=Uart_Rece_buffer[i+3];
-            }
-            return Uart_Data_buffer;
-        }
-    }
-    if (isRecvTimeout == true)//没收到数据,全部为空值
-    {
-        Uart_Data_buffer[0] = 0x00;
-        Uart_Data_buffer[1] = 0x00;
-        Uart_Data_buffer[2] = 0x00;
-        Uart_Data_buffer[3] = 0x00;
-        Uart_Data_buffer[4] = 0x00;
-        Uart_Data_buffer[5] = 0x00;
-        Uart_Data_buffer[6] = 0x00;
-        Uart_Data_buffer[7] = 0x00;
-        isRecvTimeout = false;
-        osDelay(1000);
-        return Uart_Data_buffer;
-    }
-}
-void USART_callback(uint32_t event)
-{
-    if(event & ARM_USART_EVENT_RX_TIMEOUT)
-    {
-        isRecvTimeout = true;
-    }
-    if(event & ARM_USART_EVENT_RECEIVE_COMPLETE)
-    {
-        isRecvComplete = true;
-    }
-}
-
-static void process0AppTask(void* arg)
-{
-    UINT8 Can_index = 0;
-    UINT8 Uart_index = 0;
-    while(1)
-    {
-        osDelay(10);//10ms
-        Can_index++;
-        Uart_index++;
-        if (Uart_index >5)//Uart 100ms 调用一次
-        {
-            PROC2_STATE_SWITCH(PROCESS2_STATE_WORK);
-            Uart_index = 0;
-        }
-        if (Can_index >10)//Can 100ms 调用一次
-        {
-            PROC1_STATE_SWITCH(PROCESS1_STATE_WORK);
-            Can_index = 0;
-        } 
-    }
-}
-static void process1AppTask(void* arg)
-{
-	PROC1_STATE_SWITCH(PROCESS1_STATE_IDLE);
-    uint32_t Can_ID;
-    NVIC_EnableIRQ(PadWakeup0_IRQn);
-    Can_InitType param;
-    Can_TxMsgType Can_TxMsg;
-    param.baudrate = CAN_500Kbps;
-    param.mode = REQOP_NORMAL;
-    param.TxStdIDH = 0x00;
-    param.TxStdIDL = 0x00;
-    param.RxStdIDH[0] = 0x00;
-    param.RxStdIDL[0] = 0x00;
-    /*stdid 0000 0000 001x*/
-    param.RxStdIDH[1] = 0x00;
-    param.RxStdIDL[1] = 0x20;
-    /*stdid 0000 0000 010x */
-    param.RxStdIDH[2] = 0x00;
-    param.RxStdIDL[2] = 0x40;
-    /*stdid 0000 0000 011x*/
-    param.RxStdIDH[3] = 0x00;
-    param.RxStdIDL[3] =0x60;
-    /*stdid 0000 0000 100x */
-    param.RxStdIDH[4] = 0x00;
-    param.RxStdIDL[4] = 0x80;
-    /*stdid 0000 0000 101x*/
-    param.RxStdIDH[5] = 0x00;
-    param.RxStdIDL[5] =0xa0;
-    param.packType = STD_PACK;
-    HAL_Can_Init(param);
-    int send_index = 0;
-
-    while(1)
-    {
-        switch(gProc1State)
-        {
-            case PROCESS1_STATE_IDLE:
-            {
-                send_index = 0;
-                FaultDisplay(LED_TURN_OFF);
-                break;
-            }
-            case PROCESS1_STATE_WORK:
-            {
-                switch(send_index)
-                {
-                    case 0:
-                    {
-                        Can_ID = 0x001;
-                        Can_TxMsg.Data[0] = *(Uart_Rece_BattCellU1_U4+0);
-                        Can_TxMsg.Data[1] = *(Uart_Rece_BattCellU1_U4+1);
-                        Can_TxMsg.Data[2] = *(Uart_Rece_BattCellU1_U4+2);
-                        Can_TxMsg.Data[3] = *(Uart_Rece_BattCellU1_U4+3);
-                        Can_TxMsg.Data[4] = *(Uart_Rece_BattCellU1_U4+4);
-                        Can_TxMsg.Data[5] = *(Uart_Rece_BattCellU1_U4+5);
-                        Can_TxMsg.Data[6] = *(Uart_Rece_BattCellU1_U4+6);
-                        Can_TxMsg.Data[7] = *(Uart_Rece_BattCellU1_U4+7);
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 1:
-                    {
-                        Can_ID = 0x011;
-                        Can_TxMsg.Data[0] = *(Uart_Rece_BattCellU5_U8+0);
-                        Can_TxMsg.Data[1] = *(Uart_Rece_BattCellU5_U8+1);
-                        Can_TxMsg.Data[2] = *(Uart_Rece_BattCellU5_U8+2);
-                        Can_TxMsg.Data[3] = *(Uart_Rece_BattCellU5_U8+3);
-                        Can_TxMsg.Data[4] = *(Uart_Rece_BattCellU5_U8+4);
-                        Can_TxMsg.Data[5] = *(Uart_Rece_BattCellU5_U8+5);
-                        Can_TxMsg.Data[6] = *(Uart_Rece_BattCellU5_U8+6);
-                        Can_TxMsg.Data[7] = *(Uart_Rece_BattCellU5_U8+7);
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 2:
-                    {
-                        Can_ID = 0x021;
-                        Can_TxMsg.Data[0] = *(Uart_Rece_BattCellU9_U12+0);
-                        Can_TxMsg.Data[1] = *(Uart_Rece_BattCellU9_U12+1);
-                        Can_TxMsg.Data[2] = *(Uart_Rece_BattCellU9_U12+2);
-                        Can_TxMsg.Data[3] = *(Uart_Rece_BattCellU9_U12+3);
-                        Can_TxMsg.Data[4] = *(Uart_Rece_BattCellU9_U12+4);
-                        Can_TxMsg.Data[5] = *(Uart_Rece_BattCellU9_U12+5);
-                        Can_TxMsg.Data[6] = *(Uart_Rece_BattCellU9_U12+6);
-                        Can_TxMsg.Data[7] = *(Uart_Rece_BattCellU9_U12+7);
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 3:
-                    {
-                        Can_ID = 0x031;
-                        Can_TxMsg.Data[0] = *(Uart_Rece_BattCellU13_U14+0);
-                        Can_TxMsg.Data[1] = *(Uart_Rece_BattCellU13_U14+1);
-                        Can_TxMsg.Data[2] = *(Uart_Rece_BattCellU13_U14+2);
-                        Can_TxMsg.Data[3] = *(Uart_Rece_BattCellU13_U14+3);
-                        Can_TxMsg.Data[4] = 0x00;
-                        Can_TxMsg.Data[5] = 0x00;
-                        Can_TxMsg.Data[6] = 0x00;
-                        Can_TxMsg.Data[7] = 0x00;
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    default:
-                    {
-                        PROC1_STATE_SWITCH(PROCESS1_STATE_IDLE);
-                        break;
-                    }
-                }
-                send_index++;
-                FaultDisplay(LED_TURN_ON);	
-                break;
-            }
-            case PROCESS1_STATE_SLEEP:
-            {                                     
-                break;
-            }
-        }
-    }
-}
-static void process2AppTask(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);
-    int Rece_index = 0;
-    Uart_Receive_Type Uart_Receive_Msg;
-	PROC2_STATE_SWITCH(PROCESS2_STATE_IDLE);
-    while(1)
-    {
-        switch(gProc2State)
-        {
-            case PROCESS2_STATE_IDLE:
-            {   
-                Rece_index = 0;
-                NetSocDisplay(3,LED_TURN_OFF);
-                break;
-            }
-            case PROCESS2_STATE_WORK:
-            {
-                Uart_Receive_Msg.Bms_Address = 0x01;
-                Uart_Receive_Msg.Bms_Read_Funcode = 0x03;
-                switch(Rece_index)
-                {
-                    case 0://读取电压1-4
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L = 0x02;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Rece_BattCellU1_U4 = Uart_Receive_func(Uart_Receive_Msg);
-                        break;
-                    }
-                    case 1://读取电压5-8
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x06;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Rece_BattCellU5_U8 = Uart_Receive_func(Uart_Receive_Msg);
-                        break;
-                    }
-                    case 2:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x0A;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Rece_BattCellU9_U12 = Uart_Receive_func(Uart_Receive_Msg);
-                        break;
-                    }
-                    case 3:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x0E;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Rece_BattCellU13_U14 = Uart_Receive_func(Uart_Receive_Msg);
-                        break;
-                    }
-                    default:
-                    {
-                        PROC2_STATE_SWITCH(PROCESS2_STATE_IDLE);
-                        break;
-                    }
-                }
-                Rece_index++;
-                NetSocDisplay(3,LED_TURN_ON);
-                break;
-            }
-            case PROCESS2_STATE_SLEEP:
-            {	        
-                //此处写休眠程序
-                break;
-            }
-        }
-    }
-}
-/**
-  \fn          process0Init(void)
-  \brief       process0Init function.
-  \return
-*/
-void process0Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack0, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process0AppTask";
-    task_attr.stack_mem = gProcessTaskStack0;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask0;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process0AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process1Init(void)
-  \brief       process1Init function.
-  \return
-*/
-void process1Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack1, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process1AppTask";
-    task_attr.stack_mem = gProcessTaskStack1;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask1;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process1AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process2Init(void)
-  \brief       process2Init function.
-  \return
-*/
-void process2Init(void)
-{
-    osThreadAttr_t task_attr;
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack2, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process2AppTask";
-    task_attr.stack_mem = gProcessTaskStack2;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask2;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process2AppTask, NULL, &task_attr);
-}
-/**
-  \fn          appInit(void)
-  \brief       appInit function.
-  \return
-*/
-void appInit(void *arg)
-{   
-    process0Init();
-	process1Init();
-    process2Init();
-}
-
-/**
-  \fn          int main_entry(void)
-  \brief       main entry function.
-  \return
-*/
-void main_entry(void) {
-
-    BSP_CommonInit();
-    osKernelInitialize();
-
-    registerAppEntry(appInit, NULL);
-    if (osKernelGetState() == osKernelReady)
-    {
-        osKernelStart();
-    }
-    while(1);
-}

+ 0 - 612
app_1_0.c

@@ -1,612 +0,0 @@
-/****************************************************************************
- *
- * Copy right:   2020-, Copyrigths of QIXIANG TECH Ltd.
- * File name:    app.c
- * Description:  QX app source file 
- * History:      Rev1.0   2020-10-16
- * Athuor:       chenjie 
- *
- ****************************************************************************/
-//include 
-#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
-// app task static stack and control block
-#define PROC_TASK_STACK_SIZE    (1024)
-
-
-//uart def
-#define Uart_Send_LEN         (8)
-#define Uart_Rece_LEN         (16)
-#define RTE_UART_RX_IO_MODE      RTE_UART1_RX_IO_MODE
-
-//statement variable
-extern ARM_DRIVER_USART Driver_USART1;
-static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
-
-/** \brief usart receive buffer */
-uint8_t Uart_Data_buffer[8];
-
-/** \brief usart send buffer */
-
-/** \brief receive timeout flag */
-volatile bool isRecvTimeout = false;
-
-/** \brief receive complete flag */
-volatile bool isRecvComplete = false;
-
-uint8_t process0SlpHandler     = 0xff;
-uint8_t process1SlpHandler     = 0xff;
-uint8_t process2SlpHandler     = 0xff;
-
-/** \brief 电压传输 */
-
-uint8_t Uart_Rece_BattCellU1_U4[8];
-uint8_t Uart_Rece_BattCellU5_U8[8];
-uint8_t Uart_Rece_BattCellU9_U12[8];
-uint8_t Uart_Rece_BattCellU13_U14[8];
-uint8_t Uart_Rece_BattT[8];
-int16_t Uart_Rece_BattI;
-uint8_t Uart_Rece_Batt_states[6];
-uint16_t Uart_Rece_BattU;
-uint16_t Uart_Rece_Batt_MaxcellU;
-uint16_t Uart_Rece_Batt_MincellU;
-typedef enum
-{
-    PROCESS1_STATE_IDLE = 0,
-    PROCESS1_STATE_WORK,
-    PROCESS1_STATE_SLEEP
-}process1SM;
-typedef enum
-{
-    PROCESS2_STATE_IDLE = 0,
-    PROCESS2_STATE_WORK,
-    PROCESS2_STATE_SLEEP
-}process2SM;
-
-static StaticTask_t           gProcessTask0;
-static UINT8                    gProcessTaskStack0[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask1;
-static UINT8                    gProcessTaskStack1[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask2;
-static UINT8                    gProcessTaskStack2[PROC_TASK_STACK_SIZE];
-
-process1SM 	gProc1State = PROCESS1_STATE_IDLE;
-process2SM 	gProc2State = PROCESS2_STATE_IDLE;
-#define PROC1_STATE_SWITCH(a)  (gProc1State = a)
-#define PROC2_STATE_SWITCH(a)  (gProc2State = a)
-
-
-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;
-}
-
-uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg)
-{
-    uint8_t Uart_Rece_buffer[Uart_Rece_LEN];
-    uint16_t CRC_Reve_buffer;
-    uint16_t CRC_chk_buffer;
-    uint8_t Uart_Send_buffer[8];
-    uint8_t Rece_Data_Len;
-    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;
-    Uart_Rece_buffer[0]=0xfe;
-    uint32_t timeout=0;
-    USARTdrv->Send(Uart_Send_buffer,8);
-    USARTdrv->Receive(Uart_Rece_buffer,13);
-    Rece_Data_Len = 11;
-    while((isRecvTimeout == false) && (isRecvComplete == false))// 未收到数据不叫时间超时,收到数据但是不全叫时间超时
-    {
-        timeout++;
-        if (timeout>7000000)
-        {
-            timeout =0;
-            isRecvTimeout = true;
-            break;
-        }
-    }
-    if (isRecvComplete == true)
-    {
-        isRecvComplete = false;
-        CRC_chk_buffer =Uart_Rece_buffer[12]<<8|Uart_Rece_buffer[11];
-        CRC_Reve_buffer = crc_chk(Uart_Rece_buffer,11);
-        if (CRC_Reve_buffer == CRC_chk_buffer)//满足校验
-        {
-            for (uint8_t i = 0; i < 8; i++)
-            {
-                Uart_Data_buffer[i]=Uart_Rece_buffer[i+3];
-            }
-            return Uart_Data_buffer;
-        }
-        else //接收数据的校验不过暂时屏蔽
-        {
-            for (uint8_t i = 0; i < 8; i++)
-            {
-                Uart_Data_buffer[i]=0xff;
-            }
-            return Uart_Data_buffer;
-        }
-    }
-    if (isRecvTimeout == true)//没收到数据,全部为空值
-    {
-        Uart_Data_buffer[0] = 0x00;
-        Uart_Data_buffer[1] = 0x00;
-        Uart_Data_buffer[2] = 0x00;
-        Uart_Data_buffer[3] = 0x00;
-        Uart_Data_buffer[4] = 0x00;
-        Uart_Data_buffer[5] = 0x00;
-        Uart_Data_buffer[6] = 0x00;
-        Uart_Data_buffer[7] = 0xff;
-        isRecvTimeout = false;
-        osDelay(1000);
-        return Uart_Data_buffer;
-    }
-}
-void USART_callback(uint32_t event)
-{
-    if(event & ARM_USART_EVENT_RX_TIMEOUT)
-    {
-        isRecvTimeout = true;
-    }
-    if(event & ARM_USART_EVENT_RECEIVE_COMPLETE)
-    {
-        isRecvComplete = true;
-    }
-}
-
-static void process0AppTask(void* arg)
-{
-    uint32_t inParam = 0xAABBCCDD;
-    uint32_t cnt;
-    slpManSetPmuSleepMode(true,SLP_HIB_STATE,false);
-    slpManApplyPlatVoteHandle("process0slp",&process0SlpHandler);
-    slpManSlpState_t slpstate = slpManGetLastSlpState();
-    UINT8 Can_index = 0;
-    UINT8 Uart_index = 0;
-    while(1)
-    {
-        osDelay(10);//10ms
-        Can_index++;
-        Uart_index++;
-        if (Uart_index >10)//Uart 100ms 调用一次
-        {
-            PROC2_STATE_SWITCH(PROCESS2_STATE_WORK);
-            Uart_index = 0;
-        }
-        if (Can_index >=100)//Can 100ms 调用一次
-        {
-            PROC1_STATE_SWITCH(PROCESS1_STATE_WORK);
-            Can_index = 0;
-        } 
-    }
-}
-static void process1AppTask(void* arg)
-{
-	PROC1_STATE_SWITCH(PROCESS1_STATE_IDLE);
-    uint32_t Can_ID;
-    NVIC_EnableIRQ(PadWakeup1_IRQn);
-    Can_InitType param;
-    Can_TxMsgType Can_TxMsg;
-    param.baudrate = CAN_500Kbps;
-    param.mode = REQOP_NORMAL;
-    param.TxStdIDH = 0x00;
-    param.TxStdIDL = 0x00;
-    param.RxStdIDH[0] = 0x00;
-    param.RxStdIDL[0] = 0x00;
-    /*stdid 0000 0000 001x*/
-    param.RxStdIDH[1] = 0x00;
-    param.RxStdIDL[1] = 0x20;
-    /*stdid 0000 0000 010x */
-    param.RxStdIDH[2] = 0x00;
-    param.RxStdIDL[2] = 0x40;
-    /*stdid 0000 0000 011x*/
-    param.RxStdIDH[3] = 0x00;
-    param.RxStdIDL[3] =0x60;
-    /*stdid 0000 0000 100x */
-    param.RxStdIDH[4] = 0x00;
-    param.RxStdIDL[4] = 0x80;
-    /*stdid 0000 0000 101x*/
-    param.RxStdIDH[5] = 0x00;
-    param.RxStdIDL[5] =0xa0;
-    param.packType = STD_PACK;
-    HAL_Can_Init(param);
-    int send_index = 0;
-
-    while(1)
-    {
-        switch(gProc1State)
-        {
-            case PROCESS1_STATE_IDLE:
-            {
-                send_index = 0;
-                FaultDisplay(LED_TURN_OFF);
-                break;
-            }
-            case PROCESS1_STATE_WORK:
-            {
-                switch(send_index)
-                {
-                    case 0:
-                    {
-                        Can_ID = 0x001;
-                        for (int i = 0; i < 8; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU1_U4[i];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 1:
-                    {
-                        Can_ID = 0x012;
-                        for (int i = 0; i < 8; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU5_U8[i];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 2:
-                    {
-                        Can_ID = 0x021;
-                        for (int i = 0; i < 8; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU9_U12[i];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 3:
-                    {
-                        Can_ID = 0x031;
-                        for (int i = 0; i < 4; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU13_U14[i];
-                        }
-                        Can_TxMsg.Data[4] = 0x00;
-                        Can_TxMsg.Data[5] = 0x00;
-                        Can_TxMsg.Data[6] = 0x00;
-                        Can_TxMsg.Data[7] = 0x00;
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 4:
-                    {
-                        Can_ID  = 0x101;
-                        for (int i = 0; i < 4; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattT[i*2+1];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 5:
-                    {
-                        Can_ID = 0x201;
-                        Can_TxMsg.Data[0] = Uart_Rece_BattU>>8;
-                        Can_TxMsg.Data[1] = Uart_Rece_BattU;
-                        Can_TxMsg.Data[2] = 0x00;
-                        Can_TxMsg.Data[3] = 0x00;//外电压
-                        Can_TxMsg.Data[4] = 0x00;
-                        Can_TxMsg.Data[5] = 0x00;//累加电压
-                        Can_TxMsg.Data[6] = Uart_Rece_BattI>>8;
-                        Can_TxMsg.Data[7] = Uart_Rece_BattI;
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-
-                    }
-                    default:
-                    {
-                        PROC1_STATE_SWITCH(PROCESS1_STATE_IDLE);
-                    }
-                }
-                send_index ++;
-                FaultDisplay(LED_TURN_ON);	
-                break;
-            }
-            case PROCESS1_STATE_SLEEP:
-            {                                     
-                break;
-            }
-        }
-    }
-}
-static void process2AppTask(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);
-    int Rece_index = 0;
-    uint8_t *Uart_Reve_Point = NULL;
-    Uart_Receive_Type Uart_Receive_Msg;
-	PROC2_STATE_SWITCH(PROCESS2_STATE_IDLE);
-    while(1)
-    {
-        switch(gProc2State)
-        {
-            case PROCESS2_STATE_IDLE:
-            {   
-                Rece_index = 0;
-                NetSocDisplay(3,LED_TURN_OFF);
-                break;
-            }
-            case PROCESS2_STATE_WORK:
-            {
-                Uart_Receive_Msg.Bms_Address = 0x01;
-                Uart_Receive_Msg.Bms_Read_Funcode = 0x03;
-                switch(Rece_index)
-                {
-                    case 0://读取电压1-4
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L = 0x02;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU1_U4[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 1://读取电压5-8
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x06;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU5_U8[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 2:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x0A;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU9_U12[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 3:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x0E;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU13_U14[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 4:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x14;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattT[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 5:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x10;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        Uart_Rece_BattI = *(Uart_Reve_Point+0)<<8 | *(Uart_Reve_Point+1);
-                        for (int i = 0; i < 6; i++)
-                        {
-                            Uart_Rece_Batt_states[i] = *(Uart_Reve_Point+2+i);
-                        }
-                        break;
-                    }
-                    case 6:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x2B;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        Uart_Rece_BattU = *(Uart_Reve_Point+0)<<8 | *(Uart_Reve_Point+1);
-                        Uart_Rece_Batt_MaxcellU = *(Uart_Reve_Point+2)<<8 | *(Uart_Reve_Point+3);
-                        Uart_Rece_Batt_MincellU = *(Uart_Reve_Point+4)<<8 | *(Uart_Reve_Point+5);
-                        break;
-                    }
-                    default:
-                    {
-                        PROC2_STATE_SWITCH(PROCESS2_STATE_IDLE);
-                        break;
-                    }
-                }
-                Rece_index++;
-                NetSocDisplay(3,LED_TURN_ON);
-                break;
-            }
-            case PROCESS2_STATE_SLEEP:
-            {	        
-                //此处写休眠程序
-                break;
-            }
-        }
-    }
-}
-/**
-  \fn          process0Init(void)
-  \brief       process0Init function.
-  \return
-*/
-void process0Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack0, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process0AppTask";
-    task_attr.stack_mem = gProcessTaskStack0;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask0;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process0AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process1Init(void)
-  \brief       process1Init function.
-  \return
-*/
-void process1Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack1, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process1AppTask";
-    task_attr.stack_mem = gProcessTaskStack1;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask1;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process1AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process2Init(void)
-  \brief       process2Init function.
-  \return
-*/
-void process2Init(void)
-{
-    osThreadAttr_t task_attr;
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack2, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process2AppTask";
-    task_attr.stack_mem = gProcessTaskStack2;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask2;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process2AppTask, NULL, &task_attr);
-}
-/**
-  \fn          appInit(void)
-  \brief       appInit function.
-  \return
-*/
-void appInit(void *arg)
-{   
-    process0Init();
-	process1Init();
-    process2Init();
-}
-
-/**
-  \fn          int main_entry(void)
-  \brief       main entry function.
-  \return
-*/
-void main_entry(void) {
-
-    BSP_CommonInit();
-    osKernelInitialize();
-
-    registerAppEntry(appInit, NULL);
-    if (osKernelGetState() == osKernelReady)
-    {
-        osKernelStart();
-    }
-    while(1);
-}

+ 0 - 619
app_1_0_1.c

@@ -1,619 +0,0 @@
-/****************************************************************************
- *
- * Copy right:   2020-, Copyrigths of QIXIANG TECH Ltd.
- * File name:    app.c
- * Description:  QX app source file 
- * History:      Rev1.0   2020-10-16
- * Athuor:       chenjie 
- *
- ****************************************************************************/
-//include 
-#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
-// app task static stack and control block
-#define PROC_TASK_STACK_SIZE    (1024)
-
-
-//uart def
-#define Uart_Send_LEN         (8)
-#define Uart_Rece_LEN         (16)
-#define RTE_UART_RX_IO_MODE      RTE_UART1_RX_IO_MODE
-
-//statement variable
-extern ARM_DRIVER_USART Driver_USART1;
-static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
-
-/** \brief usart receive buffer */
-uint8_t Uart_Data_buffer[8];
-
-/** \brief usart send buffer */
-
-/** \brief receive timeout flag */
-volatile bool isRecvTimeout = false;
-
-/** \brief receive complete flag */
-volatile bool isRecvComplete = false;
-
-uint8_t process0SlpHandler     = 0xff;
-uint8_t process1SlpHandler     = 0xff;
-uint8_t process2SlpHandler     = 0xff;
-
-/** \brief 电压传输 */
-
-uint8_t Uart_Rece_BattCellU1_U4[8];
-uint8_t Uart_Rece_BattCellU5_U8[8];
-uint8_t Uart_Rece_BattCellU9_U12[8];
-uint8_t Uart_Rece_BattCellU13_U14[8];
-uint8_t Uart_Rece_BattT[8];
-int16_t Uart_Rece_BattI;
-uint8_t Uart_Rece_Batt_states[6];
-uint16_t Uart_Rece_BattU;
-uint16_t Uart_Rece_Batt_MaxcellU;
-uint16_t Uart_Rece_Batt_MincellU;
-uint8_t Can_Rece_buffer[16];
-typedef enum
-{
-    PROCESS1_STATE_IDLE = 0,
-    PROCESS1_STATE_WORK,
-    PROCESS1_STATE_SLEEP
-}process1SM;
-typedef enum
-{
-    PROCESS2_STATE_IDLE = 0,
-    PROCESS2_STATE_WORK,
-    PROCESS2_STATE_SLEEP
-}process2SM;
-
-static StaticTask_t           gProcessTask0;
-static UINT8                    gProcessTaskStack0[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask1;
-static UINT8                    gProcessTaskStack1[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask2;
-static UINT8                    gProcessTaskStack2[PROC_TASK_STACK_SIZE];
-
-process1SM 	gProc1State = PROCESS1_STATE_IDLE;
-process2SM 	gProc2State = PROCESS2_STATE_IDLE;
-#define PROC1_STATE_SWITCH(a)  (gProc1State = a)
-#define PROC2_STATE_SWITCH(a)  (gProc2State = a)
-
-
-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;
-}
-
-uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg)
-{
-    uint8_t Uart_Rece_buffer[Uart_Rece_LEN];
-    uint16_t CRC_Reve_buffer;
-    uint16_t CRC_chk_buffer;
-    uint8_t Uart_Send_buffer[8];
-    uint8_t Rece_Data_Len;
-    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;
-    Uart_Rece_buffer[0]=0xfe;
-    uint32_t timeout=0;
-    USARTdrv->Send(Uart_Send_buffer,8);
-    USARTdrv->Receive(Uart_Rece_buffer,13);
-    Rece_Data_Len = 11;
-    while((isRecvTimeout == false) && (isRecvComplete == false))// 未收到数据不叫时间超时,收到数据但是不全叫时间超时
-    {
-        timeout++;
-        if (timeout>7000000)
-        {
-            timeout =0;
-            isRecvTimeout = true;
-            break;
-        }
-    }
-    if (isRecvComplete == true)
-    {
-        isRecvComplete = false;
-        CRC_chk_buffer =Uart_Rece_buffer[12]<<8|Uart_Rece_buffer[11];
-        CRC_Reve_buffer = crc_chk(Uart_Rece_buffer,11);
-        if (CRC_Reve_buffer == CRC_chk_buffer)//满足校验
-        {
-            for (uint8_t i = 0; i < 8; i++)
-            {
-                Uart_Data_buffer[i]=Uart_Rece_buffer[i+3];
-            }
-            return Uart_Data_buffer;
-        }
-        else //接收数据的校验不过暂时屏蔽
-        {
-            for (uint8_t i = 0; i < 8; i++)
-            {
-                Uart_Data_buffer[i]=0xff;
-            }
-            return Uart_Data_buffer;
-        }
-    }
-    if (isRecvTimeout == true)//没收到数据,全部为空值
-    {
-        Uart_Data_buffer[0] = 0x00;
-        Uart_Data_buffer[1] = 0x00;
-        Uart_Data_buffer[2] = 0x00;
-        Uart_Data_buffer[3] = 0x00;
-        Uart_Data_buffer[4] = 0x00;
-        Uart_Data_buffer[5] = 0x00;
-        Uart_Data_buffer[6] = 0x00;
-        Uart_Data_buffer[7] = 0xff;
-        isRecvTimeout = false;
-        osDelay(1000);
-        return Uart_Data_buffer;
-    }
-}
-void USART_callback(uint32_t event)
-{
-    if(event & ARM_USART_EVENT_RX_TIMEOUT)
-    {
-        isRecvTimeout = true;
-    }
-    if(event & ARM_USART_EVENT_RECEIVE_COMPLETE)
-    {
-        isRecvComplete = true;
-    }
-}
-
-static void process0AppTask(void* arg)
-{
-    uint32_t inParam = 0xAABBCCDD;
-    uint32_t cnt;
-    slpManSetPmuSleepMode(true,SLP_HIB_STATE,false);
-    slpManApplyPlatVoteHandle("process0slp",&process0SlpHandler);
-    slpManSlpState_t slpstate = slpManGetLastSlpState();
-    UINT8 Can_index = 0;
-    UINT8 Uart_index = 0;
-    while(1)
-    {
-        osDelay(10);//10ms
-        Can_index++;
-        Uart_index++;
-        if (Uart_index >10)//Uart 100ms 调用一次
-        {
-            PROC2_STATE_SWITCH(PROCESS2_STATE_WORK);
-            Uart_index = 0;
-        }
-        if (Can_index >=100)//Can 100ms 调用一次
-        {
-            PROC1_STATE_SWITCH(PROCESS1_STATE_WORK);
-            Can_index = 0;
-        } 
-    }
-}
-static void process1AppTask(void* arg)
-{
-	PROC1_STATE_SWITCH(PROCESS1_STATE_IDLE);
-    uint32_t Can_ID;
-    NVIC_EnableIRQ(PadWakeup1_IRQn);
-    Can_InitType param;
-    Can_TxMsgType Can_TxMsg;
-    param.baudrate = CAN_500Kbps;
-    param.mode = REQOP_NORMAL;
-    param.TxStdIDH = 0x00;
-    param.TxStdIDL = 0x00;
-    param.RxStdIDH[0] = 0x00;
-    param.RxStdIDL[0] = 0x00;
-    /*stdid 0000 0000 001x*/
-    param.RxStdIDH[1] = 0x00;
-    param.RxStdIDL[1] = 0x20;
-    /*stdid 0000 0000 010x */
-    param.RxStdIDH[2] = 0x00;
-    param.RxStdIDL[2] = 0x40;
-    /*stdid 0000 0000 011x*/
-    param.RxStdIDH[3] = 0x00;
-    param.RxStdIDL[3] =0x60;
-    /*stdid 0000 0000 100x */
-    param.RxStdIDH[4] = 0x00;
-    param.RxStdIDL[4] = 0x80;
-    /*stdid 0000 0000 101x*/
-    param.RxStdIDH[5] = 0x00;
-    param.RxStdIDL[5] =0xa0;
-    param.packType = STD_PACK;
-    HAL_Can_Init(param);
-    int send_index = 0;
-
-    while(1)
-    {
-        switch(gProc1State)
-        {
-            case PROCESS1_STATE_IDLE:
-            {
-                HAL_Can_Receive(Can_Rece_buffer);
-                send_index = 0;
-                FaultDisplay(LED_TURN_OFF);
-                break;
-            }
-            case PROCESS1_STATE_WORK:
-            {
-                switch(send_index)
-                {
-                    case 0:
-                    {
-                        Can_ID = 0x001;
-                        for (int i = 0; i < 8; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU1_U4[i];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 1:
-                    {
-                        Can_ID = 0x012;
-                        for (int i = 0; i < 8; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU5_U8[i];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 2:
-                    {
-                        Can_ID = 0x021;
-                        for (int i = 0; i < 8; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU9_U12[i];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 3:
-                    {
-                        Can_ID = 0x031;
-                        for (int i = 0; i < 4; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU13_U14[i];
-                        }
-                        Can_TxMsg.Data[4] = 0x00;
-                        Can_TxMsg.Data[5] = 0x00;
-                        Can_TxMsg.Data[6] = 0x00;
-                        Can_TxMsg.Data[7] = 0x00;
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 4:
-                    {
-                        Can_ID  = 0x101;
-                        for (int i = 0; i < 4; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattT[i*2+1];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 5:
-                    {
-                        Can_ID = 0x201;
-                        Can_TxMsg.Data[0] = Uart_Rece_BattU>>8;
-                        Can_TxMsg.Data[1] = Uart_Rece_BattU;
-                        Can_TxMsg.Data[2] = 0x00;
-                        Can_TxMsg.Data[3] = 0x00;//外电压
-                        Can_TxMsg.Data[4] = 0x00;
-                        Can_TxMsg.Data[5] = 0x00;//累加电压
-                        Can_TxMsg.Data[6] = Uart_Rece_BattI>>8;
-                        Can_TxMsg.Data[7] = Uart_Rece_BattI;
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-
-                    }
-                    default:
-                    {
-                        PROC1_STATE_SWITCH(PROCESS1_STATE_IDLE);
-                    }
-                }
-                send_index ++;
-                FaultDisplay(LED_TURN_ON);	
-                break;
-            }
-            case PROCESS1_STATE_SLEEP:
-            {                                     
-                break;
-            }
-        }
-    }
-}
-static void process2AppTask(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);
-    int Rece_index = 0;
-    uint8_t *Uart_Reve_Point = NULL;
-    Uart_Receive_Type Uart_Receive_Msg;
-	PROC2_STATE_SWITCH(PROCESS2_STATE_IDLE);
-    while(1)
-    {
-        switch(gProc2State)
-        {
-            case PROCESS2_STATE_IDLE:
-            {   
-                Rece_index = 0;
-                NetSocDisplay(3,LED_TURN_OFF);
-                break;
-            }
-            case PROCESS2_STATE_WORK:
-            {
-                Uart_Receive_Msg.Bms_Address = 0x01;
-                Uart_Receive_Msg.Bms_Read_Funcode = 0x03;
-                switch(Rece_index)
-                {
-                    case 0://读取电压1-4
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L = 0x02;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU1_U4[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 1://读取电压5-8
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x06;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU5_U8[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 2:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x0A;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU9_U12[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 3:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x0E;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU13_U14[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 4:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x14;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattT[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 5:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x10;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        Uart_Rece_BattI = *(Uart_Reve_Point+0)<<8 | *(Uart_Reve_Point+1);
-                        for (int i = 0; i < 6; i++)
-                        {
-                            Uart_Rece_Batt_states[i] = *(Uart_Reve_Point+2+i);
-                        }
-                        break;
-                    }
-                    case 6:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x2B;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        Uart_Rece_BattU = *(Uart_Reve_Point+0)<<8 | *(Uart_Reve_Point+1);
-                        Uart_Rece_Batt_MaxcellU = *(Uart_Reve_Point+2)<<8 | *(Uart_Reve_Point+3);
-                        Uart_Rece_Batt_MincellU = *(Uart_Reve_Point+4)<<8 | *(Uart_Reve_Point+5);
-                        break;
-                    }
-                    case 7:
-                    {
-                        USARTdrv->Send(Can_Rece_buffer,16);
-                    }
-                    default:
-                    {
-                        PROC2_STATE_SWITCH(PROCESS2_STATE_IDLE);
-                        break;
-                    }
-                }
-                Rece_index++;
-                NetSocDisplay(3,LED_TURN_ON);
-                break;
-            }
-            case PROCESS2_STATE_SLEEP:
-            {	        
-                //此处写休眠程序
-                break;
-            }
-        }
-    }
-}
-
-/**
-  \fn          process0Init(void)
-  \brief       process0Init function.
-  \return
-*/
-void process0Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack0, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process0AppTask";
-    task_attr.stack_mem = gProcessTaskStack0;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask0;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process0AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process1Init(void)
-  \brief       process1Init function.
-  \return
-*/
-void process1Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack1, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process1AppTask";
-    task_attr.stack_mem = gProcessTaskStack1;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask1;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process1AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process2Init(void)
-  \brief       process2Init function.
-  \return
-*/
-void process2Init(void)
-{
-    osThreadAttr_t task_attr;
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack2, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process2AppTask";
-    task_attr.stack_mem = gProcessTaskStack2;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask2;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process2AppTask, NULL, &task_attr);
-}
-/**
-  \fn          appInit(void)
-  \brief       appInit function.
-  \return
-*/
-void appInit(void *arg)
-{   
-    process0Init();
-	process1Init();
-    process2Init();
-}
-
-/**
-  \fn          int main_entry(void)
-  \brief       main entry function.
-  \return
-*/
-void main_entry(void) {
-
-    BSP_CommonInit();
-    osKernelInitialize();
-
-    registerAppEntry(appInit, NULL);
-    if (osKernelGetState() == osKernelReady)
-    {
-        osKernelStart();
-    }
-    while(1);
-}

+ 0 - 337
app_1_1.c

@@ -1,337 +0,0 @@
-/****************************************************************************
- *
- * Copy right:   2020-, Copyrigths of QIXIANG TECH Ltd.
- * File name:    app.c  睡眠测试
- * Description:  QX app source file 
- * History:      Rev1.0   2020-10-16
- * Athuor:       chenjie 
- *
- ****************************************************************************/
-//include 
-#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
-// app task static stack and control block
-#define PROC_TASK_STACK_SIZE    (1024)
-
-
-uint8_t process0SlpHandler     = 0xff;
-uint8_t process1SlpHandler     = 0xfe;
-uint8_t process2SlpHandler     = 0xfd;
-uint8_t deepslpTimerID          = 0;
-typedef enum
-{
-    PROCESS0_STATE_IDLE = 0,
-    PROCESS0_STATE_WORK,
-    PROCESS0_STATE_SLEEP
-}process0SM;
-typedef enum
-{
-    PROCESS1_STATE_IDLE = 0,
-    PROCESS1_STATE_WORK,
-    PROCESS1_STATE_SLEEP
-}process1SM;
-typedef enum
-{
-    PROCESS2_STATE_IDLE = 0,
-    PROCESS2_STATE_WORK,
-    PROCESS2_STATE_SLEEP
-}process2SM;
-
-
-static StaticTask_t           gProcessTask0;
-static UINT8                    gProcessTaskStack0[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask1;
-static UINT8                    gProcessTaskStack1[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask2;
-static UINT8                    gProcessTaskStack2[PROC_TASK_STACK_SIZE];
-
-process0SM 	gProc0State = PROCESS0_STATE_IDLE;
-process1SM 	gProc1State = PROCESS1_STATE_IDLE;
-process2SM 	gProc2State = PROCESS2_STATE_IDLE;
-
-#define PROC0_STATE_SWITCH(a)  (gProc0State = a)
-#define PROC1_STATE_SWITCH(a)  (gProc1State = a)
-#define PROC2_STATE_SWITCH(a)  (gProc2State = a)
-
-static void appBeforeHib(void *pdata, slpManLpState state)
-{
-    uint32_t *p_param = (uint32_t *)pdata;
-
-    ECOMM_TRACE(UNILOG_PLA_APP, appBeforeHib_1, P_SIG, 1, "Before Hibernate = %x",*p_param);
-
-}
-
-static void appAfterHib(void *pdata, slpManLpState state)
-{
-    ECOMM_TRACE(UNILOG_PLA_APP, appAfterHib_1, P_SIG, 0, "Try Hibernate Failed, Interrupt Pending. Only sleep failed this function will excute");
-}
-
-
-static void appBeforeSlp1(void *pdata, slpManLpState state)
-{
-    ECOMM_TRACE(UNILOG_PLA_APP, appBeforeSlp1_1, P_SIG, 0, "Before Sleep1");
-}
-
-static void appAfterSlp1(void *pdata, slpManLpState state)
-{
-    ECOMM_TRACE(UNILOG_PLA_APP, appAfterSlp1_1, P_SIG, 0, "After Sleep1, no matter sleep success or not this function will excute");
-}
-
-
-static void appBeforeSlp2(void *pdata, slpManLpState state)
-{
-    ECOMM_TRACE(UNILOG_PLA_APP, appBeforeSlp2_1, P_SIG, 0, "Before Sleep2");
-}
-
-static void appAfterSlp2(void *pdata, slpManLpState state)
-{
-    ECOMM_TRACE(UNILOG_PLA_APP, appAfterSlp2_1, P_SIG, 0, "Sleep2 Failed, Interrupt Pending. Only sleep failed this function will excute");
-}
-
-static void process0AppTask(void* arg)
-{
-    NetSocDisplay(0,LED_TURN_OFF);
-    NetSocDisplay(1,LED_TURN_OFF);
-    NetSocDisplay(2,LED_TURN_OFF);
-    NetSocDisplay(3,LED_TURN_OFF);
-    NetSocDisplay(4,LED_TURN_OFF);
-    uint32_t inParam = 0xAABBCCDD;
-    uint32_t cnt;
-    slpManSetPmuSleepMode(true,SLP_HIB_STATE,false);
-    //slpManApplyPlatVoteHandle("process0slp",&process0SlpHandler);
-    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);
-
-    slpManSlpState_t slpstate = slpManGetLastSlpState();
-    UINT8 Can_index = 0;
-    UINT8 Uart_index = 0;
-    uint8_t sleep_index = 0;
-    PROC0_STATE_SWITCH(PROCESS0_STATE_IDLE);
-    while(1)
-    {
-        switch(gProc0State)
-        {
-            case PROCESS0_STATE_IDLE:
-            {   
-                PROC0_STATE_SWITCH(PROCESS0_STATE_WORK);
-                break;
-            }
-            case PROCESS0_STATE_WORK:
-            {
-                NetSocDisplay(0,LED_TURN_ON);
-                osDelay(10);//10ms
-                Can_index++;
-                Uart_index++;
-                if (Uart_index >10)//Uart 100ms 调用一次
-                {
-                    PROC2_STATE_SWITCH(PROCESS2_STATE_WORK);
-                    Uart_index = 0;
-                }
-                if (Can_index >=100)//Can 1000ms 调用一次
-                {
-                    PROC1_STATE_SWITCH(PROCESS1_STATE_WORK);
-                    Can_index = 0;
-                }
-                if (sleep_index>5000)
-                {
-                    sleep_index =0;
-                    PROC0_STATE_SWITCH(PROCESS0_STATE_SLEEP);
-                }
-                break;
-            }
-            case PROCESS0_STATE_SLEEP:
-            {
-
-                slpManSlpState_t State;
-                uint8_t cnt;
-                //slpManPlatVoteEnableSleep(process0SlpHandler, SLP_HIB_STATE);  // cancel the prohibition of sleep2
-                //slpManDeepSlpTimerStart(deepslpTimerID, 60000);     // create a 30s timer, DeepSleep Timer is always oneshoot
-                while(1)                // now app can enter hib, but ps and phy maybe not, so wait here
-                {
-                    osDelay(3000);
-                }
-            }
-        }
-    }
-}
-static void process1AppTask(void* arg)
-{
-	PROC1_STATE_SWITCH(PROCESS1_STATE_IDLE);
-    //slpManApplyPlatVoteHandle("process1slp",&process1SlpHandler);
-    NVIC_EnableIRQ(PadWakeup0_IRQn);
-    while(1)
-    {
-        switch(gProc1State)
-        {
-            case PROCESS1_STATE_IDLE:
-            {
-                break;
-            }
-            case PROCESS1_STATE_WORK:
-            {
-                NetSocDisplay(1,LED_TURN_ON);
-                osDelay(10000);
-                PROC1_STATE_SWITCH(PROCESS1_STATE_SLEEP);
-                break;
-            }
-            case PROCESS1_STATE_SLEEP:
-            {   
-                //slpManPlatVoteDisableSleep(process1SlpHandler, SLP_SLP2_STATE);                                  
-                break;
-            }
-        }
-    }
-}
-static void process2AppTask(void* arg)
-{
-	PROC2_STATE_SWITCH(PROCESS2_STATE_IDLE);
-    //slpManApplyPlatVoteHandle("process2slp",&process2SlpHandler);
-    NVIC_EnableIRQ(PadWakeup0_IRQn);
-    while(1)
-    {
-        switch(gProc2State)
-        {
-            case PROCESS2_STATE_IDLE:
-            {   
-                break;
-            }
-            case PROCESS2_STATE_WORK:
-            {
-                NetSocDisplay(2,LED_TURN_ON);
-                osDelay(20000);
-                PROC2_STATE_SWITCH(PROCESS2_STATE_SLEEP);
-                break;
-            }
-            case PROCESS2_STATE_SLEEP:
-            {	        
-                //slpManPlatVoteDisableSleep(process2SlpHandler, SLP_SLP2_STATE);                                  
-                break;
-            }
-        }
-    }
-}
-/**
-  \fn          process0Init(void)
-  \brief       process0Init function.
-  \return
-*/
-void process0Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack0, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process0AppTask";
-    task_attr.stack_mem = gProcessTaskStack0;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask0;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process0AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process1Init(void)
-  \brief       process1Init function.
-  \return
-*/
-void process1Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack1, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process1AppTask";
-    task_attr.stack_mem = gProcessTaskStack1;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask1;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process1AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process2Init(void)
-  \brief       process2Init function.
-  \return
-*/
-void process2Init(void)
-{
-    osThreadAttr_t task_attr;
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack2, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process2AppTask";
-    task_attr.stack_mem = gProcessTaskStack2;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask2;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process2AppTask, NULL, &task_attr);
-}
-/**
-  \fn          appInit(void)
-  \brief       appInit function.
-  \return
-*/
-void appInit(void *arg)
-{   
-    process0Init();
-	process1Init();
-    process2Init();
-}
-
-/**
-  \fn          int main_entry(void)
-  \brief       main entry function.
-  \return
-*/
-void main_entry(void) {
-
-    BSP_CommonInit();
-    osKernelInitialize();
-
-    registerAppEntry(appInit, NULL);
-    if (osKernelGetState() == osKernelReady)
-    {
-        osKernelStart();
-    }
-    while(1);
-}

+ 0 - 353
app_1_2.c

@@ -1,353 +0,0 @@
-/****************************************************************************
- *
- * Copy right:   2020-, Copyrigths of QIXIANG TECH Ltd.
- * File name:    app.c  睡眠测试
- * Description:  QX app source file 
- * History:      Rev1.0   2020-10-16
- * Athuor:       chenjie 
- *
- ****************************************************************************/
-//include 
-#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
-// app task static stack and control block
-#define PROC_TASK_STACK_SIZE    (1024)
-
-
-uint8_t process0SlpHandler     = 0xff;
-uint8_t process1SlpHandler     = 0xff;
-uint8_t process2SlpHandler     = 0xff;
-uint8_t deepslpTimerID         = 0;
-typedef enum
-{
-    PROCESS0_STATE_IDLE = 0,
-    PROCESS0_STATE_WORK,
-    PROCESS0_STATE_SLEEP
-}process0SM;
-typedef enum
-{
-    PROCESS1_STATE_IDLE = 0,
-    PROCESS1_STATE_WORK,
-    PROCESS1_STATE_SLEEP
-}process1SM;
-typedef enum
-{
-    PROCESS2_STATE_IDLE = 0,
-    PROCESS2_STATE_WORK,
-    PROCESS2_STATE_SLEEP
-}process2SM;
-
-
-static StaticTask_t           gProcessTask0;
-static UINT8                    gProcessTaskStack0[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask1;
-static UINT8                    gProcessTaskStack1[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask2;
-static UINT8                    gProcessTaskStack2[PROC_TASK_STACK_SIZE];
-
-process0SM 	gProc0State = PROCESS0_STATE_IDLE;
-process1SM 	gProc1State = PROCESS1_STATE_IDLE;
-process2SM 	gProc2State = PROCESS2_STATE_IDLE;
-
-#define PROC0_STATE_SWITCH(a)  (gProc0State = a)
-#define PROC1_STATE_SWITCH(a)  (gProc1State = a)
-#define PROC2_STATE_SWITCH(a)  (gProc2State = a)
-
-static void appBeforeHib(void *pdata, slpManLpState state)
-{
-    uint32_t *p_param = (uint32_t *)pdata;
-
-    ECOMM_TRACE(UNILOG_PLA_APP, appBeforeHib_1, P_SIG, 1, "Before Hibernate = %x",*p_param);
-
-}
-
-static void appAfterHib(void *pdata, slpManLpState state)
-{
-    ECOMM_TRACE(UNILOG_PLA_APP, appAfterHib_1, P_SIG, 0, "Try Hibernate Failed, Interrupt Pending. Only sleep failed this function will excute");
-}
-
-
-static void appBeforeSlp1(void *pdata, slpManLpState state)
-{
-    ECOMM_TRACE(UNILOG_PLA_APP, appBeforeSlp1_1, P_SIG, 0, "Before Sleep1");
-}
-
-static void appAfterSlp1(void *pdata, slpManLpState state)
-{
-    ECOMM_TRACE(UNILOG_PLA_APP, appAfterSlp1_1, P_SIG, 0, "After Sleep1, no matter sleep success or not this function will excute");
-}
-
-
-static void appBeforeSlp2(void *pdata, slpManLpState state)
-{
-    ECOMM_TRACE(UNILOG_PLA_APP, appBeforeSlp2_1, P_SIG, 0, "Before Sleep2");
-}
-
-static void appAfterSlp2(void *pdata, slpManLpState state)
-{
-    ECOMM_TRACE(UNILOG_PLA_APP, appAfterSlp2_1, P_SIG, 0, "Sleep2 Failed, Interrupt Pending. Only sleep failed this function will excute");
-}
-
-static void process0AppTask(void* arg)
-{
-    NetSocDisplay(0,LED_TURN_OFF);
-    NetSocDisplay(1,LED_TURN_OFF);
-    NetSocDisplay(2,LED_TURN_OFF);
-    NetSocDisplay(3,LED_TURN_OFF);
-    NetSocDisplay(4,LED_TURN_OFF);
-    uint32_t inParam = 0xAABBCCDD;
-    uint32_t cnt;
-    slpManSetPmuSleepMode(true,SLP_HIB_STATE,false);
-    slpManApplyPlatVoteHandle("process0slp",&process0SlpHandler);
-    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);
-
-    slpManSlpState_t slpstate = slpManGetLastSlpState();
-    UINT8 Can_index = 0;
-    UINT8 Uart_index = 0;
-    uint32_t sleep_index = 0;
-    NVIC_EnableIRQ(PXIC_Timer0_IRQn);
-    PROC0_STATE_SWITCH(PROCESS0_STATE_IDLE);
-    while(1)
-    {
-        switch(gProc0State)
-        {
-            case PROCESS0_STATE_IDLE:
-            {   
-                slpManPlatVoteDisableSleep(process0SlpHandler, SLP_SLP2_STATE); 
-                PROC0_STATE_SWITCH(PROCESS0_STATE_WORK);
-                break;
-            }
-            case PROCESS0_STATE_WORK:
-            {
-                NetSocDisplay(0,LED_TURN_ON);
-                osDelay(10);//10ms
-                Can_index++;
-                Uart_index++;
-                sleep_index++;
-                if (Uart_index >10)//Uart 100ms 调用一次
-                {
-                    PROC2_STATE_SWITCH(PROCESS2_STATE_WORK);
-                    Uart_index = 0;
-                }
-                if (Can_index >=100)//Can 1000ms 调用一次
-                {
-                    PROC1_STATE_SWITCH(PROCESS1_STATE_WORK);
-                    Can_index = 0;
-                }
-                if (sleep_index >=1000)
-                {
-                    PROC0_STATE_SWITCH(PROCESS0_STATE_SLEEP);
-                    PROC1_STATE_SWITCH(PROCESS1_STATE_SLEEP);
-                    PROC2_STATE_SWITCH(PROCESS2_STATE_SLEEP);
-                    sleep_index = 0;
-                }
-                break;
-                
-            }
-            case PROCESS0_STATE_SLEEP:
-            {
-
-                slpManSlpState_t State;
-                uint8_t cnt;
-                slpManPlatVoteEnableSleep(process0SlpHandler,SLP_SLP2_STATE);
-                slpManPlatVoteDisableSleep(process0SlpHandler, SLP_HIB_STATE); 
-                slpManDeepSlpTimerStart(deepslpTimerID, 10000); // create a 10s timer, DeepSleep Timer is always oneshoot
-                while(1)                // now app can enter hib, but ps and phy maybe not, so wait here
-                {
-                    NetSocDisplay(0,LED_TURN_OFF);
-                    osDelay(3000);
-                }
-            }
-        }
-    }
-}
-static void process1AppTask(void* arg)
-{
-	PROC1_STATE_SWITCH(PROCESS1_STATE_IDLE);
-    NVIC_EnableIRQ(PadWakeup1_IRQn);
-    slpManApplyPlatVoteHandle("process1slp",&process1SlpHandler);
-    while(1)
-    {
-        switch(gProc1State)
-        {
-            case PROCESS1_STATE_IDLE:
-            {
-                slpManPlatVoteDisableSleep(process1SlpHandler, SLP_SLP2_STATE); 
-                break;
-            }
-            case PROCESS1_STATE_WORK:
-            {
-                NetSocDisplay(1,LED_TURN_ON);
-                break;
-            }
-            case PROCESS1_STATE_SLEEP:
-            {   
-                slpManPlatVoteEnableSleep(process1SlpHandler, SLP_SLP2_STATE); 
-                slpManPlatVoteDisableSleep(process1SlpHandler, SLP_HIB_STATE);   
-                while(1)
-                {
-                    osDelay(3000);
-                }                              
-                break;
-            }
-        }
-    }
-}
-static void process2AppTask(void* arg)
-{
-	PROC2_STATE_SWITCH(PROCESS2_STATE_IDLE);
-    NVIC_EnableIRQ(PadWakeup1_IRQn);
-    slpManApplyPlatVoteHandle("process2slp",&process2SlpHandler);
-    while(1)
-    {
-        switch(gProc2State)
-        {
-            case PROCESS2_STATE_IDLE:
-            {   
-                slpManPlatVoteDisableSleep(process2SlpHandler, SLP_SLP2_STATE);
-                break;
-            }
-            case PROCESS2_STATE_WORK:
-            {
-                NetSocDisplay(2,LED_TURN_ON);
-                break;
-            }
-            case PROCESS2_STATE_SLEEP:
-            {
-                slpManPlatVoteEnableSleep(process2SlpHandler, SLP_SLP2_STATE);  
-                slpManPlatVoteDisableSleep(process2SlpHandler, SLP_HIB_STATE);  
-                while(1)
-                {
-                    osDelay(3000);
-                }                     
-                break;
-            }
-        }
-    }
-}
-/**
-  \fn          process0Init(void)
-  \brief       process0Init function.
-  \return
-*/
-void process0Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack0, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process0AppTask";
-    task_attr.stack_mem = gProcessTaskStack0;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask0;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process0AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process1Init(void)
-  \brief       process1Init function.
-  \return
-*/
-void process1Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack1, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process1AppTask";
-    task_attr.stack_mem = gProcessTaskStack1;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask1;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process1AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process2Init(void)
-  \brief       process2Init function.
-  \return
-*/
-void process2Init(void)
-{
-    osThreadAttr_t task_attr;
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack2, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process2AppTask";
-    task_attr.stack_mem = gProcessTaskStack2;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask2;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process2AppTask, NULL, &task_attr);
-}
-/**
-  \fn          appInit(void)
-  \brief       appInit function.
-  \return
-*/
-void appInit(void *arg)
-{   
-    process0Init();
-	process1Init();
-    process2Init();
-}
-
-/**
-  \fn          int main_entry(void)
-  \brief       main entry function.
-  \return
-*/
-void main_entry(void) {
-
-    BSP_CommonInit();
-    osKernelInitialize();
-
-    registerAppEntry(appInit, NULL);
-    if (osKernelGetState() == osKernelReady)
-    {
-        osKernelStart();
-    }
-    while(1);
-}

+ 0 - 671
app_1_3.c

@@ -1,671 +0,0 @@
-/****************************************************************************
- *
- * Copy right:   2020-, Copyrigths of QIXIANG TECH Ltd.
- * File name:    app.c
- * Description:  QX app source file 
- * History:      Rev1.0   2020-10-16
- * Athuor:       chenjie 
- *
- ****************************************************************************/
-//include 
-#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
-// app task static stack and control block
-#define PROC_TASK_STACK_SIZE    (1024)
-
-
-//uart def
-#define Uart_Send_LEN         (8)
-#define Uart_Rece_LEN         (16)
-#define RTE_UART_RX_IO_MODE      RTE_UART1_RX_IO_MODE
-
-//statement variable
-extern ARM_DRIVER_USART Driver_USART1;
-static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
-
-/** \brief usart receive buffer */
-uint8_t Uart_Data_buffer[8];
-
-/** \brief usart send buffer */
-
-/** \brief receive timeout flag */
-volatile bool isRecvTimeout = false;
-
-/** \brief receive complete flag */
-volatile bool isRecvComplete = false;
-
-uint8_t process0SlpHandler     = 0xff;
-uint8_t process1SlpHandler     = 0xff;
-uint8_t process2SlpHandler     = 0xff;
-uint8_t deepslpTimerID         = 0;
-
-/** \brief 电压传输 */
-
-uint8_t Uart_Rece_BattCellU1_U4[8];
-uint8_t Uart_Rece_BattCellU5_U8[8];
-uint8_t Uart_Rece_BattCellU9_U12[8];
-uint8_t Uart_Rece_BattCellU13_U14[8];
-uint8_t Uart_Rece_BattT[8];
-int16_t Uart_Rece_BattI;
-uint8_t Uart_Rece_Batt_states[6];
-uint16_t Uart_Rece_BattU;
-uint16_t Uart_Rece_Batt_MaxcellU;
-uint16_t Uart_Rece_Batt_MincellU;
-typedef enum
-{
-    PROCESS0_STATE_IDLE = 0,
-    PROCESS0_STATE_WORK,
-    PROCESS0_STATE_SLEEP
-}process0SM;
-typedef enum
-{
-    PROCESS1_STATE_IDLE = 0,
-    PROCESS1_STATE_WORK,
-    PROCESS1_STATE_SLEEP
-}process1SM;
-typedef enum
-{
-    PROCESS2_STATE_IDLE = 0,
-    PROCESS2_STATE_WORK,
-    PROCESS2_STATE_SLEEP
-}process2SM;
-
-static StaticTask_t           gProcessTask0;
-static UINT8                    gProcessTaskStack0[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask1;
-static UINT8                    gProcessTaskStack1[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask2;
-static UINT8                    gProcessTaskStack2[PROC_TASK_STACK_SIZE];
-
-process0SM 	gProc0State = PROCESS0_STATE_IDLE;
-process1SM 	gProc1State = PROCESS1_STATE_IDLE;
-process2SM 	gProc2State = PROCESS2_STATE_IDLE;
-#define PROC0_STATE_SWITCH(a)  (gProc0State = a)
-#define PROC1_STATE_SWITCH(a)  (gProc1State = a)
-#define PROC2_STATE_SWITCH(a)  (gProc2State = a)
-
-
-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;
-}
-
-uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg)
-{
-    uint8_t Uart_Rece_buffer[Uart_Rece_LEN];
-    uint16_t CRC_Reve_buffer;
-    uint16_t CRC_chk_buffer;
-    uint8_t Uart_Send_buffer[8];
-    uint8_t Rece_Data_Len;
-    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;
-    Uart_Rece_buffer[0]=0xfe;
-    uint32_t timeout=0;
-    USARTdrv->Send(Uart_Send_buffer,8);
-    USARTdrv->Receive(Uart_Rece_buffer,13);
-    Rece_Data_Len = 11;
-    while((isRecvTimeout == false) && (isRecvComplete == false))// 未收到数据不叫时间超时,收到数据但是不全叫时间超时
-    {
-        timeout++;
-        if (timeout>7000000)
-        {
-            timeout =0;
-            isRecvTimeout = true;
-            break;
-        }
-    }
-    if (isRecvComplete == true)
-    {
-        isRecvComplete = false;
-        CRC_chk_buffer =Uart_Rece_buffer[12]<<8|Uart_Rece_buffer[11];
-        CRC_Reve_buffer = crc_chk(Uart_Rece_buffer,11);
-        if (CRC_Reve_buffer == CRC_chk_buffer)//满足校验
-        {
-            for (uint8_t i = 0; i < 8; i++)
-            {
-                Uart_Data_buffer[i]=Uart_Rece_buffer[i+3];
-            }
-            return Uart_Data_buffer;
-        }
-        else //接收数据的校验不过暂时屏蔽
-        {
-            for (uint8_t i = 0; i < 8; i++)
-            {
-                Uart_Data_buffer[i]=0xff;
-            }
-            return Uart_Data_buffer;
-        }
-    }
-    if (isRecvTimeout == true)//没收到数据,全部为空值
-    {
-        Uart_Data_buffer[0] = 0x00;
-        Uart_Data_buffer[1] = 0x00;
-        Uart_Data_buffer[2] = 0x00;
-        Uart_Data_buffer[3] = 0x00;
-        Uart_Data_buffer[4] = 0x00;
-        Uart_Data_buffer[5] = 0x00;
-        Uart_Data_buffer[6] = 0x00;
-        Uart_Data_buffer[7] = 0xff;
-        isRecvTimeout = false;
-        osDelay(1000);
-        return Uart_Data_buffer;
-    }
-}
-void USART_callback(uint32_t event)
-{
-    if(event & ARM_USART_EVENT_RX_TIMEOUT)
-    {
-        isRecvTimeout = true;
-    }
-    if(event & ARM_USART_EVENT_RECEIVE_COMPLETE)
-    {
-        isRecvComplete = true;
-    }
-}
-
-static void process0AppTask(void* arg)
-{
-    uint32_t inParam = 0xAABBCCDD;
-    uint32_t cnt;
-    slpManSetPmuSleepMode(true,SLP_HIB_STATE,false);
-    slpManApplyPlatVoteHandle("process0slp",&process0SlpHandler);
-    slpManSlpState_t slpstate = slpManGetLastSlpState();
-    UINT8 Can_index = 0;
-    UINT8 Uart_index = 0;
-    uint32_t sleep_index = 0;
-    PROC0_STATE_SWITCH(PROCESS0_STATE_IDLE);
-    slpManPlatVoteDisableSleep(process0SlpHandler, SLP_SLP2_STATE); 
-    while(1)
-    {
-        switch(gProc0State)
-        {
-            case PROCESS0_STATE_IDLE:
-            {   
-                PROC0_STATE_SWITCH(PROCESS0_STATE_WORK);
-                break;
-            }
-            case PROCESS0_STATE_WORK:
-            {
-                osDelay(10);//10ms
-                Can_index++;
-                Uart_index++;
-                sleep_index++;
-                if (Uart_index >10)//Uart 100ms 调用一次
-                {
-                    PROC2_STATE_SWITCH(PROCESS2_STATE_WORK);
-                    Uart_index = 0;
-                }
-                if (Can_index >=100)//Can 1000ms 调用一次
-                {
-                    PROC1_STATE_SWITCH(PROCESS1_STATE_WORK);
-                    Can_index = 0;
-                }
-                if (sleep_index >=1000)
-                {
-                    PROC0_STATE_SWITCH(PROCESS0_STATE_SLEEP);
-                    sleep_index = 0;
-                }
-                break;
-                
-            }
-            case PROCESS0_STATE_SLEEP:
-            {
-
-                slpManSlpState_t State;
-                uint8_t cnt;
-                PROC1_STATE_SWITCH(PROCESS1_STATE_SLEEP);
-                PROC2_STATE_SWITCH(PROCESS2_STATE_SLEEP);
-                slpManPlatVoteEnableSleep(process0SlpHandler,SLP_SLP2_STATE);
-                slpManPlatVoteDisableSleep(process0SlpHandler, SLP_HIB_STATE); 
-                slpManDeepSlpTimerStart(deepslpTimerID, 100000); // create a 10s timer, DeepSleep Timer is always oneshoot
-                while(1)                // now app can enter hib, but ps and phy maybe not, so wait here
-                {
-                    osDelay(3000);
-                }
-            }
-        }
-    }
-}
-static void process1AppTask(void* arg)
-{
-	PROC1_STATE_SWITCH(PROCESS1_STATE_IDLE);
-    uint32_t Can_ID;
-    NVIC_EnableIRQ(PadWakeup1_IRQn);
-    Can_InitType param;
-    Can_TxMsgType Can_TxMsg;
-    param.baudrate = CAN_500Kbps;
-    param.mode = REQOP_NORMAL;
-    param.TxStdIDH = 0x00;
-    param.TxStdIDL = 0x00;
-    param.RxStdIDH[0] = 0x00;
-    param.RxStdIDL[0] = 0x00;
-    /*stdid 0000 0000 001x*/
-    param.RxStdIDH[1] = 0x00;
-    param.RxStdIDL[1] = 0x20;
-    /*stdid 0000 0000 010x */
-    param.RxStdIDH[2] = 0x00;
-    param.RxStdIDL[2] = 0x40;
-    /*stdid 0000 0000 011x*/
-    param.RxStdIDH[3] = 0x00;
-    param.RxStdIDL[3] =0x60;
-    /*stdid 0000 0000 100x */
-    param.RxStdIDH[4] = 0x00;
-    param.RxStdIDL[4] = 0x80;
-    /*stdid 0000 0000 101x*/
-    param.RxStdIDH[5] = 0x00;
-    param.RxStdIDL[5] =0xa0;
-    param.packType = STD_PACK;
-    HAL_Can_Init(param);
-    int send_index = 0;
-    slpManPlatVoteDisableSleep(process1SlpHandler, SLP_SLP2_STATE);
-    while(1)
-    {
-        switch(gProc1State)
-        {
-            case PROCESS1_STATE_IDLE:
-            {
-                send_index = 0;
-                FaultDisplay(LED_TURN_OFF);
-                break;
-            }
-            case PROCESS1_STATE_WORK:
-            {
-                switch(send_index)
-                {
-                    case 0:
-                    {
-                        Can_ID = 0x001;
-                        for (int i = 0; i < 8; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU1_U4[i];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 1:
-                    {
-                        Can_ID = 0x013;
-                        for (int i = 0; i < 8; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU5_U8[i];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 2:
-                    {
-                        Can_ID = 0x021;
-                        for (int i = 0; i < 8; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU9_U12[i];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 3:
-                    {
-                        Can_ID = 0x031;
-                        for (int i = 0; i < 4; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU13_U14[i];
-                        }
-                        Can_TxMsg.Data[4] = 0x00;
-                        Can_TxMsg.Data[5] = 0x00;
-                        Can_TxMsg.Data[6] = 0x00;
-                        Can_TxMsg.Data[7] = 0x00;
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 4:
-                    {
-                        Can_ID  = 0x101;
-                        for (int i = 0; i < 4; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattT[i*2+1];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 5:
-                    {
-                        Can_ID = 0x201;
-                        Can_TxMsg.Data[0] = Uart_Rece_BattU>>8;
-                        Can_TxMsg.Data[1] = Uart_Rece_BattU;
-                        Can_TxMsg.Data[2] = 0x00;
-                        Can_TxMsg.Data[3] = 0x00;//外电压
-                        Can_TxMsg.Data[4] = 0x00;
-                        Can_TxMsg.Data[5] = 0x00;//累加电压
-                        Can_TxMsg.Data[6] = Uart_Rece_BattI>>8;
-                        Can_TxMsg.Data[7] = Uart_Rece_BattI;
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-
-                    }
-                    default:
-                    {
-                        PROC1_STATE_SWITCH(PROCESS1_STATE_IDLE);
-                    }
-                }
-                send_index ++;
-                FaultDisplay(LED_TURN_ON);	
-                break;
-            }
-            case PROCESS1_STATE_SLEEP:
-            {   
-                slpManPlatVoteEnableSleep(process1SlpHandler, SLP_SLP2_STATE); 
-                slpManPlatVoteDisableSleep(process1SlpHandler, SLP_HIB_STATE);   
-                while(1)
-                {
-                    osDelay(3000);
-                }                                     
-                break;
-            }
-        }
-    }
-}
-static void process2AppTask(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);
-    int Rece_index = 0;
-    uint8_t *Uart_Reve_Point = NULL;
-    Uart_Receive_Type Uart_Receive_Msg;
-	PROC2_STATE_SWITCH(PROCESS2_STATE_IDLE);
-    slpManPlatVoteDisableSleep(process2SlpHandler, SLP_SLP2_STATE);
-    while(1)
-    {
-        switch(gProc2State)
-        {
-            case PROCESS2_STATE_IDLE:
-            {   
-                Rece_index = 0;
-                NetSocDisplay(3,LED_TURN_OFF);
-                break;
-            }
-            case PROCESS2_STATE_WORK:
-            {
-                Uart_Receive_Msg.Bms_Address = 0x01;
-                Uart_Receive_Msg.Bms_Read_Funcode = 0x03;
-                switch(Rece_index)
-                {
-                    case 0://读取电压1-4
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L = 0x02;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU1_U4[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 1://读取电压5-8
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x06;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU5_U8[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 2:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x0A;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU9_U12[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 3:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x0E;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU13_U14[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 4:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x14;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattT[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 5:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x10;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        Uart_Rece_BattI = *(Uart_Reve_Point+0)<<8 | *(Uart_Reve_Point+1);
-                        for (int i = 0; i < 6; i++)
-                        {
-                            Uart_Rece_Batt_states[i] = *(Uart_Reve_Point+2+i);
-                        }
-                        break;
-                    }
-                    case 6:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x2B;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        Uart_Rece_BattU = *(Uart_Reve_Point+0)<<8 | *(Uart_Reve_Point+1);
-                        Uart_Rece_Batt_MaxcellU = *(Uart_Reve_Point+2)<<8 | *(Uart_Reve_Point+3);
-                        Uart_Rece_Batt_MincellU = *(Uart_Reve_Point+4)<<8 | *(Uart_Reve_Point+5);
-                        break;
-                    }
-                    default:
-                    {
-                        PROC2_STATE_SWITCH(PROCESS2_STATE_IDLE);
-                        break;
-                    }
-                }
-                Rece_index++;
-                NetSocDisplay(3,LED_TURN_ON);
-                break;
-            }
-            case PROCESS2_STATE_SLEEP:
-            {	
-                slpManPlatVoteEnableSleep(process2SlpHandler, SLP_SLP2_STATE);  
-                slpManPlatVoteDisableSleep(process2SlpHandler, SLP_HIB_STATE);  
-                while(1)
-                {
-                    osDelay(3000);
-                }           
-                //此处写休眠程序
-                break;
-            }
-        }
-    }
-}
-/**
-  \fn          process0Init(void)
-  \brief       process0Init function.
-  \return
-*/
-void process0Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack0, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process0AppTask";
-    task_attr.stack_mem = gProcessTaskStack0;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask0;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process0AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process1Init(void)
-  \brief       process1Init function.
-  \return
-*/
-void process1Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack1, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process1AppTask";
-    task_attr.stack_mem = gProcessTaskStack1;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask1;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process1AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process2Init(void)
-  \brief       process2Init function.
-  \return
-*/
-void process2Init(void)
-{
-    osThreadAttr_t task_attr;
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack2, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process2AppTask";
-    task_attr.stack_mem = gProcessTaskStack2;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask2;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process2AppTask, NULL, &task_attr);
-}
-/**
-  \fn          appInit(void)
-  \brief       appInit function.
-  \return
-*/
-void appInit(void *arg)
-{   
-    process0Init();
-	process1Init();
-    process2Init();
-}
-
-/**
-  \fn          int main_entry(void)
-  \brief       main entry function.
-  \return
-*/
-void main_entry(void) {
-
-    BSP_CommonInit();
-    osKernelInitialize();
-
-    registerAppEntry(appInit, NULL);
-    if (osKernelGetState() == osKernelReady)
-    {
-        osKernelStart();
-    }
-    while(1);
-}

+ 0 - 703
app_1_4.c

@@ -1,703 +0,0 @@
-/****************************************************************************
- *
- * Copy right:   2020-, Copyrigths of QIXIANG TECH Ltd.
- * File name:    app.c
- * Description:  QX app source file 
- * History:      Rev1.0   2020-10-16
- * Athuor:       chenjie 
- *
- ****************************************************************************/
-//include 
-#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
-// app task static stack and control block
-#define PROC_TASK_STACK_SIZE    (1024)
-
-
-//uart def
-#define Uart_Send_LEN         (8)
-#define Uart_Rece_LEN         (16)
-#define RTE_UART_RX_IO_MODE      RTE_UART1_RX_IO_MODE
-
-//statement variable
-extern ARM_DRIVER_USART Driver_USART1;
-static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
-
-/** \brief usart receive buffer */
-uint8_t Uart_Data_buffer[8];
-
-/** \brief usart send buffer */
-
-/** \brief receive timeout flag */
-volatile bool isRecvTimeout = false;
-
-/** \brief receive complete flag */
-volatile bool isRecvComplete = false;
-
-uint8_t process0SlpHandler     = 0xff;
-uint8_t process1SlpHandler     = 0xff;
-uint8_t process2SlpHandler     = 0xff;
-uint8_t deepslpTimerID         = 7;
-
-/** \brief 电压传输 */
-
-uint8_t Uart_Rece_BattCellU1_U4[8];
-uint8_t Uart_Rece_BattCellU5_U8[8];
-uint8_t Uart_Rece_BattCellU9_U12[8];
-uint8_t Uart_Rece_BattCellU13_U14[8];
-uint8_t Uart_Rece_BattT[8];
-int16_t Uart_Rece_BattI=0x0000;
-uint8_t Uart_Rece_Batt_states[6];
-uint16_t Uart_Rece_BattU;
-uint16_t Uart_Rece_Batt_MaxcellU;
-uint16_t Uart_Rece_Batt_MincellU;
-typedef enum
-{
-    PROCESS_STATE_IDLE = 0,
-    PROCESS_STATE_WORK,
-    PROCESS_STATE_SLEEP
-}processSM;
-typedef enum
-{
-    PROCESS_Uart_STATE_IDLE = 0,
-    PROCESS_Uart_STATE_WORK,
-    PROCESS_Uart_STATE_CHECK,
-    PROCESS_Uart_STATE_SLEEP
-}process_Uart;
-
-static StaticTask_t           gProcessTask0;
-static UINT8                    gProcessTaskStack0[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask1;
-static UINT8                    gProcessTaskStack1[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask2;
-static UINT8                    gProcessTaskStack2[PROC_TASK_STACK_SIZE];
-
-processSM 	    gProc0State = PROCESS_STATE_IDLE;
-process_Uart 	gProc1State = PROCESS_Uart_STATE_IDLE;
-processSM 	    gProc2State = PROCESS_STATE_IDLE;
-#define PROC_Task_STATE_SWITCH(a)  (gProc0State = a) //任务调度切换
-#define PROC_Uart_STATE_SWITCH(a)  (gProc1State = a) //uart 状态切换
-#define PROC_Can_STATE_SWITCH(a)  (gProc2State = a) //can 状态切换
-
-
-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;
-}
-
-uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg)
-{
-    uint8_t Uart_Rece_buffer[Uart_Rece_LEN];
-    uint16_t CRC_Reve_buffer;
-    uint16_t CRC_chk_buffer;
-    uint8_t Uart_Send_buffer[8];
-    uint8_t Rece_Data_Len;
-    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;
-    Uart_Rece_buffer[0]=0xfe;
-    uint32_t timeout=0;
-    USARTdrv->Send(Uart_Send_buffer,8);
-    USARTdrv->Receive(Uart_Rece_buffer,13);
-    Rece_Data_Len = 11;
-    while((isRecvTimeout == false) && (isRecvComplete == false))// 未收到数据不叫时间超时,收到数据但是不全叫时间超时
-    {
-        timeout++;
-        if (timeout>7000000)
-        {
-            timeout =0;
-            isRecvTimeout = true;
-            break;
-        }
-    }
-    if (isRecvComplete == true)
-    {
-        isRecvComplete = false;
-        CRC_chk_buffer =Uart_Rece_buffer[12]<<8|Uart_Rece_buffer[11];
-        CRC_Reve_buffer = crc_chk(Uart_Rece_buffer,11);
-        if (CRC_Reve_buffer == CRC_chk_buffer)//满足校验
-        {
-            for (uint8_t i = 0; i < 8; i++)
-            {
-                Uart_Data_buffer[i]=Uart_Rece_buffer[i+3];
-            }
-            return Uart_Data_buffer;
-        }
-        else //接收数据的校验不过暂时屏蔽
-        {
-            for (uint8_t i = 0; i < 8; i++)
-            {
-                Uart_Data_buffer[i]=0xff;
-            }
-            return Uart_Data_buffer;
-        }
-    }
-    if (isRecvTimeout == true)//没收到数据,全部为空值
-    {
-        Uart_Data_buffer[0] = 0x00;
-        Uart_Data_buffer[1] = 0x00;
-        Uart_Data_buffer[2] = 0x00;
-        Uart_Data_buffer[3] = 0x00;
-        Uart_Data_buffer[4] = 0x00;
-        Uart_Data_buffer[5] = 0x00;
-        Uart_Data_buffer[6] = 0x00;
-        Uart_Data_buffer[7] = 0xff;
-        isRecvTimeout = false;
-        osDelay(1000);
-        return Uart_Data_buffer;
-    }
-}
-void USART_callback(uint32_t event)
-{
-    if(event & ARM_USART_EVENT_RX_TIMEOUT)
-    {
-        isRecvTimeout = true;
-    }
-    if(event & ARM_USART_EVENT_RECEIVE_COMPLETE)
-    {
-        isRecvComplete = true;
-    }
-}
-
-static void process0AppTask(void* arg)
-{
-    uint32_t inParam = 0xAABBCCDD;
-    uint32_t cnt;
-    slpManSetPmuSleepMode(true,SLP_HIB_STATE,false);
-    slpManApplyPlatVoteHandle("process0slp",&process0SlpHandler);
-    slpManSlpState_t slpstate = slpManGetLastSlpState();
-    UINT8 Can_index = 0;
-    UINT8 Uart_index = 0;
-    uint32_t sleep_index = 0;
-    PROC_Task_STATE_SWITCH(PROCESS_STATE_IDLE);
-    slpManPlatVoteDisableSleep(process0SlpHandler, SLP_SLP2_STATE); 
-    NetSocDisplay(0,LED_TURN_OFF);
-    NetSocDisplay(1,LED_TURN_OFF);
-    NetSocDisplay(2,LED_TURN_OFF);
-    NetSocDisplay(3,LED_TURN_OFF);
-    NetSocDisplay(4,LED_TURN_OFF);
-
-    while(1)
-    {
-        switch(gProc0State)
-        {
-            case PROCESS_STATE_IDLE:
-            {   
-                PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_CHECK);
-                NetSocDisplay(0,LED_TURN_ON);
-                osDelay(100);//delay 100ms
-                if(Uart_Rece_BattI!=0x0000)
-                {
-                    PROC_Task_STATE_SWITCH(PROCESS_STATE_WORK);
-                }
-                sleep_index++;
-                if(sleep_index>=100)
-                {
-                    NetSocDisplay(0,LED_TURN_OFF);
-                    sleep_index=0;
-                    PROC_Task_STATE_SWITCH(PROCESS_STATE_SLEEP);
-                }
-                break;
-            }
-            case PROCESS_STATE_WORK:
-            {
-                osDelay(10);//10ms
-                Can_index++;
-                Uart_index++;
-                if (Uart_index >10)//Uart 100ms 调用一次
-                {
-                    PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_WORK);
-                    Uart_index = 0;
-                }
-                if (Can_index >=100)//Can 1000ms 调用一次
-                {
-                    PROC_Can_STATE_SWITCH(PROCESS_STATE_WORK);
-                    Can_index = 0;
-                }
-                if(Uart_Rece_BattI==0x0000)
-                {
-                    sleep_index++;
-                }
-                else
-                {
-                    sleep_index = 0;
-                }
-
-                if (sleep_index >=6000)
-                {
-                    PROC_Task_STATE_SWITCH(PROCESS_STATE_SLEEP);
-                    sleep_index = 0;
-                }
-                break;
-                
-            }
-            case PROCESS_STATE_SLEEP:
-            {
-
-                slpManSlpState_t State;
-                uint8_t cnt;
-                PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_SLEEP);
-                PROC_Can_STATE_SWITCH(PROCESS_STATE_SLEEP);
-                slpManPlatVoteEnableSleep(process0SlpHandler,SLP_SLP2_STATE);
-                slpManPlatVoteDisableSleep(process0SlpHandler, SLP_HIB_STATE); 
-                slpManDeepSlpTimerStart(deepslpTimerID, 300000); // create a 10s timer, DeepSleep Timer is always oneshoot
-                while(1)                // now app can enter hib, but ps and phy maybe not, so wait here
-                {
-                    osDelay(3000);
-                }
-            }
-        }
-    }
-}
-
-static void process1AppTask(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);
-    int Rece_index = 0;
-    uint8_t *Uart_Reve_Point = NULL;
-    Uart_Receive_Type Uart_Receive_Msg;
-	PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE);
-    slpManPlatVoteDisableSleep(process2SlpHandler, SLP_SLP2_STATE);
-    Uart_Receive_Msg.Bms_Address = 0x01;
-    Uart_Receive_Msg.Bms_Read_Funcode = 0x03;
-    while(1)
-    {
-        switch(gProc1State)
-        {
-            case PROCESS_Uart_STATE_IDLE:
-            {   
-                NetSocDisplay(1,LED_TURN_ON);        
-                Rece_index = 0;
-                break;
-            }
-            case PROCESS_Uart_STATE_CHECK:
-            {
-                NetSocDisplay(1,LED_TURN_OFF);
-                Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                Uart_Receive_Msg.Reg_Begin_L= 0x10;
-                Uart_Receive_Msg.Reg_Num_H = 0x00;
-                Uart_Receive_Msg.Reg_Num_L = 0x04;
-                Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                Uart_Rece_BattI = *(Uart_Reve_Point+0)<<8 | *(Uart_Reve_Point+1);
-                PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE);
-                break;
-            }
-            case PROCESS_Uart_STATE_WORK:
-            {
-                switch(Rece_index)
-                {
-                    case 0://读取电压1-4
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L = 0x02;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU1_U4[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 1://读取电压5-8
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x06;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU5_U8[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 2:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x0A;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU9_U12[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 3:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x0E;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU13_U14[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 4:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x14;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattT[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 5:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x10;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        Uart_Rece_BattI = *(Uart_Reve_Point+0)<<8 | *(Uart_Reve_Point+1);
-                        for (int i = 0; i < 6; i++)
-                        {
-                            Uart_Rece_Batt_states[i] = *(Uart_Reve_Point+2+i);
-                        }
-                        break;
-                    }
-                    case 6:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x2B;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        Uart_Rece_BattU = *(Uart_Reve_Point+0)<<8 | *(Uart_Reve_Point+1);
-                        Uart_Rece_Batt_MaxcellU = *(Uart_Reve_Point+2)<<8 | *(Uart_Reve_Point+3);
-                        Uart_Rece_Batt_MincellU = *(Uart_Reve_Point+4)<<8 | *(Uart_Reve_Point+5);
-                        break;
-                    }
-                    default:
-                    {
-                       PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE);
-                        break;
-                    }
-                }
-                Rece_index++;
-                break;
-            }
-            case PROCESS_Uart_STATE_SLEEP:
-            {	
-                slpManPlatVoteEnableSleep(process2SlpHandler, SLP_SLP2_STATE);  
-                slpManPlatVoteDisableSleep(process2SlpHandler, SLP_HIB_STATE);  
-                while(1)
-                {
-                    osDelay(3000);
-                }           
-                //此处休眠
-                break;
-            }
-        }
-    }
-}
-static void process2AppTask(void* arg)
-{
-	PROC_Can_STATE_SWITCH(PROCESS_STATE_IDLE);
-    uint32_t Can_ID;
-    NVIC_EnableIRQ(PadWakeup1_IRQn);
-    Can_InitType param;
-    Can_TxMsgType Can_TxMsg;
-    param.baudrate = CAN_500Kbps;
-    param.mode = REQOP_NORMAL;
-    param.TxStdIDH = 0x00;
-    param.TxStdIDL = 0x00;
-    param.RxStdIDH[0] = 0x00;
-    param.RxStdIDL[0] = 0x00;
-    /*stdid 0000 0000 001x*/
-    param.RxStdIDH[1] = 0x00;
-    param.RxStdIDL[1] = 0x20;
-    /*stdid 0000 0000 010x */
-    param.RxStdIDH[2] = 0x00;
-    param.RxStdIDL[2] = 0x40;
-    /*stdid 0000 0000 011x*/
-    param.RxStdIDH[3] = 0x00;
-    param.RxStdIDL[3] =0x60;
-    /*stdid 0000 0000 100x */
-    param.RxStdIDH[4] = 0x00;
-    param.RxStdIDL[4] = 0x80;
-    /*stdid 0000 0000 101x*/
-    param.RxStdIDH[5] = 0x00;
-    param.RxStdIDL[5] =0xa0;
-    param.packType = STD_PACK;
-    HAL_Can_Init(param);
-    int send_index = 0;
-    slpManPlatVoteDisableSleep(process1SlpHandler, SLP_SLP2_STATE);
-    while(1)
-    {
-        switch(gProc2State)
-        {
-            case PROCESS_STATE_IDLE:
-            {
-                send_index = 0;
-                break;
-            }
-            case PROCESS_STATE_WORK:
-            {
-                switch(send_index)
-                {
-                    case 0:
-                    {
-                        Can_ID = 0x001;
-                        for (int i = 0; i < 8; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU1_U4[i];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 1:
-                    {
-                        Can_ID = 0x013;
-                        for (int i = 0; i < 8; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU5_U8[i];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 2:
-                    {
-                        Can_ID = 0x021;
-                        for (int i = 0; i < 8; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU9_U12[i];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 3:
-                    {
-                        Can_ID = 0x031;
-                        for (int i = 0; i < 4; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU13_U14[i];
-                        }
-                        Can_TxMsg.Data[4] = 0x00;
-                        Can_TxMsg.Data[5] = 0x00;
-                        Can_TxMsg.Data[6] = 0x00;
-                        Can_TxMsg.Data[7] = 0x00;
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 4:
-                    {
-                        Can_ID  = 0x101;
-                        for (int i = 0; i < 4; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattT[i*2+1];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 5:
-                    {
-                        Can_ID = 0x201;
-                        Can_TxMsg.Data[0] = Uart_Rece_BattU>>8;
-                        Can_TxMsg.Data[1] = Uart_Rece_BattU;
-                        Can_TxMsg.Data[2] = 0x00;
-                        Can_TxMsg.Data[3] = 0x00;//外电压
-                        Can_TxMsg.Data[4] = 0x00;
-                        Can_TxMsg.Data[5] = 0x00;//累加电压
-                        Can_TxMsg.Data[6] = Uart_Rece_BattI>>8;
-                        Can_TxMsg.Data[7] = Uart_Rece_BattI;
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-
-                    }
-                    default:
-                    {
-                       PROC_Can_STATE_SWITCH(PROCESS_STATE_IDLE);
-                    }
-                }
-                send_index ++;	
-                break;
-            }
-            case PROCESS_STATE_SLEEP:
-            {   
-                slpManPlatVoteEnableSleep(process1SlpHandler, SLP_SLP2_STATE); 
-                slpManPlatVoteDisableSleep(process1SlpHandler, SLP_HIB_STATE);   
-                while(1)
-                {
-                    osDelay(3000);
-                }                                     
-                break;
-            }
-        }
-    }
-}
-/**
-  \fn          process0Init(void)
-  \brief       process0Init function.
-  \return
-*/
-void process0Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack0, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process0AppTask";
-    task_attr.stack_mem = gProcessTaskStack0;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask0;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process0AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process1Init(void)
-  \brief       process1Init function.
-  \return
-*/
-void process1Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack1, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process1AppTask";
-    task_attr.stack_mem = gProcessTaskStack1;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask1;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process1AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process2Init(void)
-  \brief       process2Init function.
-  \return
-*/
-void process2Init(void)
-{
-    osThreadAttr_t task_attr;
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack2, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process2AppTask";
-    task_attr.stack_mem = gProcessTaskStack2;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask2;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process2AppTask, NULL, &task_attr);
-}
-/**
-  \fn          appInit(void)
-  \brief       appInit function.
-  \return
-*/
-void appInit(void *arg)
-{   
-    process0Init();//任务调度和检测程序
-	process1Init();//Uart程序
-    process2Init();//Can程序
-}
-
-/**
-  \fn          int main_entry(void)
-  \brief       main entry function.
-  \return
-*/
-void main_entry(void) {
-
-    BSP_CommonInit();
-    osKernelInitialize();
-
-    registerAppEntry(appInit, NULL);
-    if (osKernelGetState() == osKernelReady)
-    {
-        osKernelStart();
-    }
-    while(1);
-}

+ 0 - 714
app_1_5.c

@@ -1,714 +0,0 @@
-/****************************************************************************
- *
- * Copy right:   2020-, Copyrigths of QIXIANG TECH Ltd.
- * File name:    app.c
- * Description:  QX app source file 
- * History:      Rev1.0   2020-10-16
- * Athuor:       chenjie 
- *
- ****************************************************************************/
-//include 
-#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
-// app task static stack and control block
-#define PROC_TASK_STACK_SIZE    (1024)
-
-
-//uart def
-#define Uart_Send_LEN         (8)
-#define Uart_Rece_LEN         (16)
-#define RTE_UART_RX_IO_MODE      RTE_UART1_RX_IO_MODE
-
-//statement variable
-extern ARM_DRIVER_USART Driver_USART1;
-static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
-
-/** \brief usart receive buffer */
-uint8_t Uart_Data_buffer[8];
-
-/** \brief usart send buffer */
-
-/** \brief receive timeout flag */
-volatile bool isRecvTimeout = false;
-
-/** \brief receive complete flag */
-volatile bool isRecvComplete = false;
-
-uint8_t process0SlpHandler     = 0xff;
-uint8_t process1SlpHandler     = 0xff;
-uint8_t process2SlpHandler     = 0xff;
-uint8_t deepslpTimerID         = 7;
-
-/** \brief 电压传输 */
-
-uint8_t Uart_Rece_BattCellU1_U4[8];
-uint8_t Uart_Rece_BattCellU5_U8[8];
-uint8_t Uart_Rece_BattCellU9_U12[8];
-uint8_t Uart_Rece_BattCellU13_U14[8];
-uint8_t Uart_Rece_BattT[8];
-int16_t Uart_Rece_BattI=0x0000;
-uint8_t Uart_Rece_Batt_states[6];
-uint16_t Uart_Rece_BattU;
-uint16_t Uart_Rece_Batt_MaxcellU;
-uint16_t Uart_Rece_Batt_MincellU;
-typedef enum
-{
-    PROCESS_STATE_IDLE = 0,
-    PROCESS_STATE_WORK,
-    PROCESS_STATE_SLEEP
-}processSM;
-typedef enum
-{
-    PROCESS_Uart_STATE_IDLE = 0,
-    PROCESS_Uart_STATE_WORK,
-    PROCESS_Uart_STATE_CHECK,
-    PROCESS_Uart_STATE_SLEEP
-}process_Uart;
-
-static StaticTask_t           gProcessTask0;
-static UINT8                    gProcessTaskStack0[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask1;
-static UINT8                    gProcessTaskStack1[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask2;
-static UINT8                    gProcessTaskStack2[PROC_TASK_STACK_SIZE];
-
-processSM 	    gProc0State = PROCESS_STATE_IDLE;
-process_Uart 	gProc1State = PROCESS_Uart_STATE_IDLE;
-processSM 	    gProc2State = PROCESS_STATE_IDLE;
-#define PROC_Task_STATE_SWITCH(a)  (gProc0State = a) //任务调度切换
-#define PROC_Uart_STATE_SWITCH(a)  (gProc1State = a) //uart 状态切换
-#define PROC_Can_STATE_SWITCH(a)  (gProc2State = a) //can 状态切换
-
-
-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;
-}
-
-uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg)
-{
-    uint8_t Uart_Rece_buffer[Uart_Rece_LEN];
-    uint16_t CRC_Reve_buffer;
-    uint16_t CRC_chk_buffer;
-    uint8_t Uart_Send_buffer[8];
-    uint8_t Rece_Data_Len;
-    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;
-    Uart_Rece_buffer[0]=0xfe;
-    uint32_t timeout=0;
-    USARTdrv->Send(Uart_Send_buffer,8);
-    USARTdrv->Receive(Uart_Rece_buffer,13);
-    Rece_Data_Len = 11;
-    while((isRecvTimeout == false) && (isRecvComplete == false))// 未收到数据不叫时间超时,收到数据但是不全叫时间超时
-    {
-        timeout++;
-        if (timeout>7000000)
-        {
-            timeout =0;
-            isRecvTimeout = true;
-            break;
-        }
-    }
-    if (isRecvComplete == true)
-    {
-        isRecvComplete = false;
-        CRC_chk_buffer =Uart_Rece_buffer[12]<<8|Uart_Rece_buffer[11];
-        CRC_Reve_buffer = crc_chk(Uart_Rece_buffer,11);
-        if (CRC_Reve_buffer == CRC_chk_buffer)//满足校验
-        {
-            for (uint8_t i = 0; i < 8; i++)
-            {
-                Uart_Data_buffer[i]=Uart_Rece_buffer[i+3];
-            }
-            return Uart_Data_buffer;
-        }
-        else //接收数据的校验不过暂时屏蔽
-        {
-            for (uint8_t i = 0; i < 8; i++)
-            {
-                Uart_Data_buffer[i]=0xff;
-            }
-            return Uart_Data_buffer;
-        }
-    }
-    if (isRecvTimeout == true)//没收到数据,全部为空值
-    {
-        Uart_Data_buffer[0] = 0x00;
-        Uart_Data_buffer[1] = 0x00;
-        Uart_Data_buffer[2] = 0x00;
-        Uart_Data_buffer[3] = 0x00;
-        Uart_Data_buffer[4] = 0x00;
-        Uart_Data_buffer[5] = 0x00;
-        Uart_Data_buffer[6] = 0x00;
-        Uart_Data_buffer[7] = 0xff;
-        isRecvTimeout = false;
-        osDelay(1000);
-        return Uart_Data_buffer;
-    }
-}
-void USART_callback(uint32_t event)
-{
-    if(event & ARM_USART_EVENT_RX_TIMEOUT)
-    {
-        isRecvTimeout = true;
-    }
-    if(event & ARM_USART_EVENT_RECEIVE_COMPLETE)
-    {
-        isRecvComplete = true;
-    }
-}
-
-static void process0AppTask(void* arg)
-{
-    uint32_t inParam = 0xAABBCCDD;
-    uint32_t cnt;
-
-    UINT8 Can_index = 0;
-    UINT8 Uart_index = 0;
-    uint32_t sleep_index = 0;
-    PROC_Task_STATE_SWITCH(PROCESS_STATE_IDLE);
-    NetSocDisplay(0,LED_TURN_OFF);
-    NetSocDisplay(1,LED_TURN_OFF);
-    NetSocDisplay(2,LED_TURN_OFF);
-    NetSocDisplay(3,LED_TURN_OFF);
-    NetSocDisplay(4,LED_TURN_OFF);
-
-
-    slpManSetPmuSleepMode(true,SLP_HIB_STATE,false);
-    slpManApplyPlatVoteHandle("process0slp",&process0SlpHandler);
-    slpManPlatVoteDisableSleep(process0SlpHandler, SLP_SLP2_STATE); 
-    slpManSlpState_t slpstate = slpManGetLastSlpState();
-    if((slpstate == SLP_SLP2_STATE) || (slpstate == SLP_HIB_STATE))
-    {
-        PROC_Task_STATE_SWITCH(PROCESS_STATE_IDLE);
-    }
-    else
-    {
-        PROC_Task_STATE_SWITCH(PROCESS_STATE_WORK);
-    }
-    
-    while(1)
-    {
-        switch(gProc0State)
-        {
-            case PROCESS_STATE_IDLE:
-            {   
-                PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_CHECK);
-                NetSocDisplay(0,LED_TURN_ON);
-                osDelay(100);//delay 100ms
-                if(Uart_Rece_BattI!=0x0000)
-                {
-                    PROC_Task_STATE_SWITCH(PROCESS_STATE_WORK);
-                }
-                sleep_index++;
-                if(sleep_index>=100)
-                {
-                    NetSocDisplay(0,LED_TURN_OFF);
-                    sleep_index=0;
-                    PROC_Task_STATE_SWITCH(PROCESS_STATE_SLEEP);
-                }
-                break;
-            }
-            case PROCESS_STATE_WORK:
-            {
-                osDelay(10);//10ms
-                Can_index++;
-                Uart_index++;
-                if (Uart_index >10)//Uart 100ms 调用一次
-                {
-                    PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_WORK);
-                    Uart_index = 0;
-                }
-                if (Can_index >=100)//Can 1000ms 调用一次
-                {
-                    PROC_Can_STATE_SWITCH(PROCESS_STATE_WORK);
-                    Can_index = 0;
-                }
-                if(Uart_Rece_BattI==0x0000)
-                {
-                    sleep_index++;
-                }
-                else
-                {
-                    sleep_index = 0;
-                }
-
-                if (sleep_index >=6000)
-                {
-                    PROC_Task_STATE_SWITCH(PROCESS_STATE_SLEEP);
-                    sleep_index = 0;
-                }
-                break;
-                
-            }
-            case PROCESS_STATE_SLEEP:
-            {
-
-                slpManSlpState_t State;
-                uint8_t cnt;
-                PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_SLEEP);
-                PROC_Can_STATE_SWITCH(PROCESS_STATE_SLEEP);
-                slpManPlatVoteEnableSleep(process0SlpHandler,SLP_SLP2_STATE);
-                slpManPlatVoteDisableSleep(process0SlpHandler, SLP_HIB_STATE); 
-                slpManDeepSlpTimerStart(deepslpTimerID, 300000); // create a 10s timer, DeepSleep Timer is always oneshoot
-                while(1)                // now app can enter hib, but ps and phy maybe not, so wait here
-                {
-                    osDelay(3000);
-                }
-            }
-        }
-    }
-}
-
-static void process1AppTask(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);
-    int Rece_index = 0;
-    uint8_t *Uart_Reve_Point = NULL;
-    Uart_Receive_Type Uart_Receive_Msg;
-	PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE);
-    slpManPlatVoteDisableSleep(process2SlpHandler, SLP_SLP2_STATE);
-    Uart_Receive_Msg.Bms_Address = 0x01;
-    Uart_Receive_Msg.Bms_Read_Funcode = 0x03;
-    while(1)
-    {
-        switch(gProc1State)
-        {
-            case PROCESS_Uart_STATE_IDLE:
-            {   
-                NetSocDisplay(1,LED_TURN_ON);        
-                Rece_index = 0;
-                break;
-            }
-            case PROCESS_Uart_STATE_CHECK:
-            {
-                NetSocDisplay(1,LED_TURN_OFF);
-                Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                Uart_Receive_Msg.Reg_Begin_L= 0x10;
-                Uart_Receive_Msg.Reg_Num_H = 0x00;
-                Uart_Receive_Msg.Reg_Num_L = 0x04;
-                Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                Uart_Rece_BattI = *(Uart_Reve_Point+0)<<8 | *(Uart_Reve_Point+1);
-                PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE);
-                break;
-            }
-            case PROCESS_Uart_STATE_WORK:
-            {
-                switch(Rece_index)
-                {
-                    case 0://读取电压1-4
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L = 0x02;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU1_U4[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 1://读取电压5-8
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x06;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU5_U8[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 2:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x0A;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU9_U12[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 3:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x0E;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU13_U14[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 4:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x14;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattT[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 5:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x10;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        Uart_Rece_BattI = *(Uart_Reve_Point+0)<<8 | *(Uart_Reve_Point+1);
-                        for (int i = 0; i < 6; i++)
-                        {
-                            Uart_Rece_Batt_states[i] = *(Uart_Reve_Point+2+i);
-                        }
-                        break;
-                    }
-                    case 6:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x2B;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        Uart_Rece_BattU = *(Uart_Reve_Point+0)<<8 | *(Uart_Reve_Point+1);
-                        Uart_Rece_Batt_MaxcellU = *(Uart_Reve_Point+2)<<8 | *(Uart_Reve_Point+3);
-                        Uart_Rece_Batt_MincellU = *(Uart_Reve_Point+4)<<8 | *(Uart_Reve_Point+5);
-                        break;
-                    }
-                    default:
-                    {
-                       PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE);
-                        break;
-                    }
-                }
-                Rece_index++;
-                break;
-            }
-            case PROCESS_Uart_STATE_SLEEP:
-            {	
-                slpManPlatVoteEnableSleep(process2SlpHandler, SLP_SLP2_STATE);  
-                slpManPlatVoteDisableSleep(process2SlpHandler, SLP_HIB_STATE);  
-                while(1)
-                {
-                    osDelay(3000);
-                }           
-                //此处休眠
-                break;
-            }
-        }
-    }
-}
-static void process2AppTask(void* arg)
-{
-	PROC_Can_STATE_SWITCH(PROCESS_STATE_IDLE);
-    uint32_t Can_ID;
-    NVIC_EnableIRQ(PadWakeup1_IRQn);
-    Can_InitType param;
-    Can_TxMsgType Can_TxMsg;
-    param.baudrate = CAN_500Kbps;
-    param.mode = REQOP_NORMAL;
-    param.TxStdIDH = 0x00;
-    param.TxStdIDL = 0x00;
-    param.RxStdIDH[0] = 0x00;
-    param.RxStdIDL[0] = 0x00;
-    /*stdid 0000 0000 001x*/
-    param.RxStdIDH[1] = 0x00;
-    param.RxStdIDL[1] = 0x20;
-    /*stdid 0000 0000 010x */
-    param.RxStdIDH[2] = 0x00;
-    param.RxStdIDL[2] = 0x40;
-    /*stdid 0000 0000 011x*/
-    param.RxStdIDH[3] = 0x00;
-    param.RxStdIDL[3] =0x60;
-    /*stdid 0000 0000 100x */
-    param.RxStdIDH[4] = 0x00;
-    param.RxStdIDL[4] = 0x80;
-    /*stdid 0000 0000 101x*/
-    param.RxStdIDH[5] = 0x00;
-    param.RxStdIDL[5] =0xa0;
-    param.packType = STD_PACK;
-    HAL_Can_Init(param);
-    int send_index = 0;
-    slpManPlatVoteDisableSleep(process1SlpHandler, SLP_SLP2_STATE);
-    while(1)
-    {
-        switch(gProc2State)
-        {
-            case PROCESS_STATE_IDLE:
-            {
-                send_index = 0;
-                break;
-            }
-            case PROCESS_STATE_WORK:
-            {
-                switch(send_index)
-                {
-                    case 0:
-                    {
-                        Can_ID = 0x001;
-                        for (int i = 0; i < 8; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU1_U4[i];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 1:
-                    {
-                        Can_ID = 0x013;
-                        for (int i = 0; i < 8; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU5_U8[i];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 2:
-                    {
-                        Can_ID = 0x021;
-                        for (int i = 0; i < 8; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU9_U12[i];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 3:
-                    {
-                        Can_ID = 0x031;
-                        for (int i = 0; i < 4; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU13_U14[i];
-                        }
-                        Can_TxMsg.Data[4] = 0x00;
-                        Can_TxMsg.Data[5] = 0x00;
-                        Can_TxMsg.Data[6] = 0x00;
-                        Can_TxMsg.Data[7] = 0x00;
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 4:
-                    {
-                        Can_ID  = 0x101;
-                        for (int i = 0; i < 4; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattT[i*2+1];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 5:
-                    {
-                        Can_ID = 0x201;
-                        Can_TxMsg.Data[0] = Uart_Rece_BattU>>8;
-                        Can_TxMsg.Data[1] = Uart_Rece_BattU;
-                        Can_TxMsg.Data[2] = 0x00;
-                        Can_TxMsg.Data[3] = 0x00;//外电压
-                        Can_TxMsg.Data[4] = 0x00;
-                        Can_TxMsg.Data[5] = 0x00;//累加电压
-                        Can_TxMsg.Data[6] = Uart_Rece_BattI>>8;
-                        Can_TxMsg.Data[7] = Uart_Rece_BattI;
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-
-                    }
-                    default:
-                    {
-                       PROC_Can_STATE_SWITCH(PROCESS_STATE_IDLE);
-                    }
-                }
-                send_index ++;	
-                break;
-            }
-            case PROCESS_STATE_SLEEP:
-            {   
-                slpManPlatVoteEnableSleep(process1SlpHandler, SLP_SLP2_STATE); 
-                slpManPlatVoteDisableSleep(process1SlpHandler, SLP_HIB_STATE);   
-                while(1)
-                {
-                    osDelay(3000);
-                }                                     
-                break;
-            }
-        }
-    }
-}
-/**
-  \fn          process0Init(void)
-  \brief       process0Init function.
-  \return
-*/
-void process0Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack0, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process0AppTask";
-    task_attr.stack_mem = gProcessTaskStack0;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask0;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process0AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process1Init(void)
-  \brief       process1Init function.
-  \return
-*/
-void process1Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack1, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process1AppTask";
-    task_attr.stack_mem = gProcessTaskStack1;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask1;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process1AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process2Init(void)
-  \brief       process2Init function.
-  \return
-*/
-void process2Init(void)
-{
-    osThreadAttr_t task_attr;
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack2, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process2AppTask";
-    task_attr.stack_mem = gProcessTaskStack2;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask2;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process2AppTask, NULL, &task_attr);
-}
-/**
-  \fn          appInit(void)
-  \brief       appInit function.
-  \return
-*/
-void appInit(void *arg)
-{   
-    process0Init();//任务调度和检测程序
-	process1Init();//Uart程序
-    process2Init();//Can程序
-}
-
-/**
-  \fn          int main_entry(void)
-  \brief       main entry function.
-  \return
-*/
-void main_entry(void) {
-
-    BSP_CommonInit();
-    osKernelInitialize();
-
-    registerAppEntry(appInit, NULL);
-    if (osKernelGetState() == osKernelReady)
-    {
-        osKernelStart();
-    }
-    while(1);
-}

+ 0 - 717
app_1_6.c

@@ -1,717 +0,0 @@
-/****************************************************************************
- *
- * Copy right:   2020-, Copyrigths of QIXIANG TECH Ltd.
- * File name:    app.c
- * Description:  QX app source file 
- * History:      Rev1.0   2020-10-16
- * Athuor:       chenjie 
- *
- ****************************************************************************/
-//include 
-#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
-// app task static stack and control block
-#define PROC_TASK_STACK_SIZE    (1024)
-
-
-//uart def
-#define Uart_Send_LEN         (8)
-#define Uart_Rece_LEN         (16)
-#define RTE_UART_RX_IO_MODE      RTE_UART1_RX_IO_MODE
-
-//statement variable
-extern ARM_DRIVER_USART Driver_USART1;
-static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
-
-/** \brief usart receive buffer */
-uint8_t Uart_Data_buffer[8];
-
-/** \brief usart send buffer */
-
-/** \brief receive timeout flag */
-volatile bool isRecvTimeout = false;
-
-/** \brief receive complete flag */
-volatile bool isRecvComplete = false;
-
-uint8_t process0SlpHandler     = 0xff;
-uint8_t process1SlpHandler     = 0xff;
-uint8_t process2SlpHandler     = 0xff;
-uint8_t deepslpTimerID         = 7;
-
-/** \brief 电压传输 */
-
-uint8_t Uart_Rece_BattCellU1_U4[8];
-uint8_t Uart_Rece_BattCellU5_U8[8];
-uint8_t Uart_Rece_BattCellU9_U12[8];
-uint8_t Uart_Rece_BattCellU13_U14[8];
-uint8_t Uart_Rece_BattT[8];
-int16_t Uart_Rece_BattI=0x0000;
-uint8_t Uart_Rece_Batt_states[6];
-uint16_t Uart_Rece_BattU;
-uint16_t Uart_Rece_Batt_MaxcellU;
-uint16_t Uart_Rece_Batt_MincellU;
-
-uint8_t Can_Rece_buffer[8];
-typedef enum
-{
-    PROCESS_STATE_IDLE = 0,
-    PROCESS_STATE_WORK,
-    PROCESS_STATE_SLEEP
-}processSM;
-typedef enum
-{
-    PROCESS_Uart_STATE_IDLE = 0,
-    PROCESS_Uart_STATE_WORK,
-    PROCESS_Uart_STATE_CHECK,
-    PROCESS_Uart_STATE_SLEEP
-}process_Uart;
-
-static StaticTask_t           gProcessTask0;
-static UINT8                    gProcessTaskStack0[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask1;
-static UINT8                    gProcessTaskStack1[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask2;
-static UINT8                    gProcessTaskStack2[PROC_TASK_STACK_SIZE];
-
-processSM 	    gProc0State = PROCESS_STATE_IDLE;
-process_Uart 	gProc1State = PROCESS_Uart_STATE_IDLE;
-processSM 	    gProc2State = PROCESS_STATE_IDLE;
-#define PROC_Task_STATE_SWITCH(a)  (gProc0State = a) //任务调度切换
-#define PROC_Uart_STATE_SWITCH(a)  (gProc1State = a) //uart 状态切换
-#define PROC_Can_STATE_SWITCH(a)  (gProc2State = a) //can 状态切换
-
-
-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;
-}
-
-uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg)
-{
-    uint8_t Uart_Rece_buffer[Uart_Rece_LEN];
-    uint16_t CRC_Reve_buffer;
-    uint16_t CRC_chk_buffer;
-    uint8_t Uart_Send_buffer[8];
-    uint8_t Rece_Data_Len;
-    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;
-    Uart_Rece_buffer[0]=0xfe;
-    uint32_t timeout=0;
-    USARTdrv->Send(Uart_Send_buffer,8);
-    USARTdrv->Receive(Uart_Rece_buffer,13);
-    Rece_Data_Len = 11;
-    while((isRecvTimeout == false) && (isRecvComplete == false))// 未收到数据不叫时间超时,收到数据但是不全叫时间超时
-    {
-        timeout++;
-        if (timeout>7000000)
-        {
-            timeout =0;
-            isRecvTimeout = true;
-            break;
-        }
-    }
-    if (isRecvComplete == true)
-    {
-        isRecvComplete = false;
-        CRC_chk_buffer =Uart_Rece_buffer[12]<<8|Uart_Rece_buffer[11];
-        CRC_Reve_buffer = crc_chk(Uart_Rece_buffer,11);
-        if (CRC_Reve_buffer == CRC_chk_buffer)//满足校验
-        {
-            for (uint8_t i = 0; i < 8; i++)
-            {
-                Uart_Data_buffer[i]=Uart_Rece_buffer[i+3];
-            }
-            return Uart_Data_buffer;
-        }
-        else //接收数据的校验不过暂时屏蔽
-        {
-            for (uint8_t i = 0; i < 8; i++)
-            {
-                Uart_Data_buffer[i]=0xff;
-            }
-            return Uart_Data_buffer;
-        }
-    }
-    if (isRecvTimeout == true)//没收到数据,全部为空值
-    {
-        Uart_Data_buffer[0] = 0x00;
-        Uart_Data_buffer[1] = 0x00;
-        Uart_Data_buffer[2] = 0x00;
-        Uart_Data_buffer[3] = 0x00;
-        Uart_Data_buffer[4] = 0x00;
-        Uart_Data_buffer[5] = 0x00;
-        Uart_Data_buffer[6] = 0x00;
-        Uart_Data_buffer[7] = 0xff;
-        isRecvTimeout = false;
-        osDelay(1000);
-        return Uart_Data_buffer;
-    }
-}
-void USART_callback(uint32_t event)
-{
-    if(event & ARM_USART_EVENT_RX_TIMEOUT)
-    {
-        isRecvTimeout = true;
-    }
-    if(event & ARM_USART_EVENT_RECEIVE_COMPLETE)
-    {
-        isRecvComplete = true;
-    }
-}
-
-static void process0AppTask(void* arg)
-{
-    uint32_t inParam = 0xAABBCCDD;
-    uint32_t cnt;
-    UINT8 Can_index = 0;
-    UINT8 Uart_index = 0;
-    uint32_t sleep_index = 0;
-    PROC_Task_STATE_SWITCH(PROCESS_STATE_IDLE);
-    NetSocDisplay(0,LED_TURN_OFF);
-    NetSocDisplay(1,LED_TURN_OFF);
-    NetSocDisplay(2,LED_TURN_OFF);
-    NetSocDisplay(3,LED_TURN_OFF);
-    NetSocDisplay(4,LED_TURN_OFF);
-
-
-    slpManSetPmuSleepMode(true,SLP_HIB_STATE,false);
-    slpManApplyPlatVoteHandle("process0slp",&process0SlpHandler);
-    slpManPlatVoteDisableSleep(process0SlpHandler, SLP_SLP2_STATE); 
-    slpManSlpState_t slpstate = slpManGetLastSlpState();
-    if((slpstate == SLP_SLP2_STATE) || (slpstate == SLP_HIB_STATE))
-    {
-        PROC_Task_STATE_SWITCH(PROCESS_STATE_IDLE);
-    }
-    else
-    {
-        PROC_Task_STATE_SWITCH(PROCESS_STATE_WORK);
-    }
-    
-    while(1)
-    {
-        switch(gProc0State)
-        {
-            case PROCESS_STATE_IDLE:
-            {   
-                PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_CHECK);
-                NetSocDisplay(0,LED_TURN_ON);
-                osDelay(100);//delay 100ms
-                if(Uart_Rece_BattI!=0x0000)
-                {
-                    PROC_Task_STATE_SWITCH(PROCESS_STATE_WORK);
-                }
-                sleep_index++;
-                if(sleep_index>=100)
-                {
-                    NetSocDisplay(0,LED_TURN_OFF);
-                    sleep_index=0;
-                    PROC_Task_STATE_SWITCH(PROCESS_STATE_SLEEP);
-                }
-                break;
-            }
-            case PROCESS_STATE_WORK:
-            {
-                osDelay(10);//10ms
-                Can_index++;
-                Uart_index++;
-                if (Uart_index >10)//Uart 100ms 调用一次
-                {
-                    PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_WORK);
-                    Uart_index = 0;
-                }
-                if (Can_index >=100)//Can 1000ms 调用一次
-                {
-                    PROC_Can_STATE_SWITCH(PROCESS_STATE_WORK);
-                    Can_index = 0;
-                }
-                if((Uart_Rece_BattI==0x0000)&&(Can_Rece_buffer[0]==0xff))
-                {
-                    sleep_index++;
-                }
-                else
-                {
-                    sleep_index = 0;
-                }
-
-                if (sleep_index >=6000)
-                {
-                    PROC_Task_STATE_SWITCH(PROCESS_STATE_SLEEP);
-                    sleep_index = 0;
-                }
-                break;
-                
-            }
-            case PROCESS_STATE_SLEEP:
-            {
-
-                slpManSlpState_t State;
-                uint8_t cnt;
-                PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_SLEEP);
-                PROC_Can_STATE_SWITCH(PROCESS_STATE_SLEEP);
-                slpManPlatVoteEnableSleep(process0SlpHandler,SLP_SLP2_STATE);
-                slpManPlatVoteDisableSleep(process0SlpHandler, SLP_HIB_STATE); 
-                slpManDeepSlpTimerStart(deepslpTimerID, 300000); // create a 10s timer, DeepSleep Timer is always oneshoot
-                while(1)                // now app can enter hib, but ps and phy maybe not, so wait here
-                {
-                    osDelay(3000);
-                }
-            }
-        }
-    }
-}
-
-static void process1AppTask(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);
-    int Rece_index = 0;
-    uint8_t *Uart_Reve_Point = NULL;
-    Uart_Receive_Type Uart_Receive_Msg;
-	PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE);
-    slpManPlatVoteDisableSleep(process2SlpHandler, SLP_SLP2_STATE);
-    Uart_Receive_Msg.Bms_Address = 0x01;
-    Uart_Receive_Msg.Bms_Read_Funcode = 0x03;
-    while(1)
-    {
-        switch(gProc1State)
-        {
-            case PROCESS_Uart_STATE_IDLE:
-            {   
-                NetSocDisplay(1,LED_TURN_ON);        
-                Rece_index = 0;
-                break;
-            }
-            case PROCESS_Uart_STATE_CHECK:
-            {
-                NetSocDisplay(1,LED_TURN_OFF);
-                Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                Uart_Receive_Msg.Reg_Begin_L= 0x10;
-                Uart_Receive_Msg.Reg_Num_H = 0x00;
-                Uart_Receive_Msg.Reg_Num_L = 0x04;
-                Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                Uart_Rece_BattI = *(Uart_Reve_Point+0)<<8 | *(Uart_Reve_Point+1);
-                PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE);
-                break;
-            }
-            case PROCESS_Uart_STATE_WORK:
-            {
-                switch(Rece_index)
-                {
-                    case 0://读取电压1-4
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L = 0x02;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU1_U4[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 1://读取电压5-8
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x06;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU5_U8[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 2:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x0A;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU9_U12[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 3:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x0E;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU13_U14[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 4:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x14;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattT[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 5:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x10;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        Uart_Rece_BattI = *(Uart_Reve_Point+0)<<8 | *(Uart_Reve_Point+1);
-                        for (int i = 0; i < 6; i++)
-                        {
-                            Uart_Rece_Batt_states[i] = *(Uart_Reve_Point+2+i);
-                        }
-                        break;
-                    }
-                    case 6:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x2B;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        Uart_Rece_BattU = *(Uart_Reve_Point+0)<<8 | *(Uart_Reve_Point+1);
-                        Uart_Rece_Batt_MaxcellU = *(Uart_Reve_Point+2)<<8 | *(Uart_Reve_Point+3);
-                        Uart_Rece_Batt_MincellU = *(Uart_Reve_Point+4)<<8 | *(Uart_Reve_Point+5);
-                        break;
-                    }
-                    default:
-                    {
-                       PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE);
-                        break;
-                    }
-                }
-                Rece_index++;
-                break;
-            }
-            case PROCESS_Uart_STATE_SLEEP:
-            {	
-                slpManPlatVoteEnableSleep(process2SlpHandler, SLP_SLP2_STATE);  
-                slpManPlatVoteDisableSleep(process2SlpHandler, SLP_HIB_STATE);  
-                while(1)
-                {
-                    osDelay(3000);
-                }           
-                //此处休眠
-                break;
-            }
-        }
-    }
-}
-static void process2AppTask(void* arg)
-{
-	PROC_Can_STATE_SWITCH(PROCESS_STATE_IDLE);
-    uint32_t Can_ID;
-    NVIC_EnableIRQ(PadWakeup1_IRQn);
-    Can_InitType param;
-    Can_TxMsgType Can_TxMsg;
-    param.baudrate = CAN_500Kbps;
-    param.mode = REQOP_NORMAL;
-    param.TxStdIDH = 0x00;
-    param.TxStdIDL = 0x00;
-    param.RxStdIDH[0] = 0x00;
-    param.RxStdIDL[0] = 0x00;
-    /*stdid 0000 0000 001x*/
-    param.RxStdIDH[1] = 0x00;
-    param.RxStdIDL[1] = 0x20;
-    /*stdid 0000 0000 010x */
-    param.RxStdIDH[2] = 0x00;
-    param.RxStdIDL[2] = 0x40;
-    /*stdid 0000 0000 011x*/
-    param.RxStdIDH[3] = 0x00;
-    param.RxStdIDL[3] =0x60;
-    /*stdid 0000 0000 100x */
-    param.RxStdIDH[4] = 0x00;
-    param.RxStdIDL[4] = 0x80;
-    /*stdid 0000 0000 101x*/
-    param.RxStdIDH[5] = 0x00;
-    param.RxStdIDL[5] =0xa0;
-    param.packType = STD_PACK;
-    HAL_Can_Init(param);
-    int send_index = 0;
-    slpManPlatVoteDisableSleep(process1SlpHandler, SLP_SLP2_STATE);
-    while(1)
-    {
-        switch(gProc2State)
-        {
-            case PROCESS_STATE_IDLE:
-            {
-                HAL_Can_Receive(Can_Rece_buffer);
-                send_index = 0;
-                break;
-            }
-            case PROCESS_STATE_WORK:
-            {
-                switch(send_index)
-                {
-                    case 0:
-                    {
-                        Can_ID = 0x001;
-                        for (int i = 0; i < 8; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU1_U4[i];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 1:
-                    {
-                        Can_ID = 0x013;
-                        for (int i = 0; i < 8; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU5_U8[i];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 2:
-                    {
-                        Can_ID = 0x021;
-                        for (int i = 0; i < 8; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU9_U12[i];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 3:
-                    {
-                        Can_ID = 0x031;
-                        for (int i = 0; i < 4; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU13_U14[i];
-                        }
-                        Can_TxMsg.Data[4] = 0x00;
-                        Can_TxMsg.Data[5] = 0x00;
-                        Can_TxMsg.Data[6] = 0x00;
-                        Can_TxMsg.Data[7] = 0x00;
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 4:
-                    {
-                        Can_ID  = 0x101;
-                        for (int i = 0; i < 4; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattT[i*2+1];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 5:
-                    {
-                        Can_ID = 0x201;
-                        Can_TxMsg.Data[0] = Uart_Rece_BattU>>8;
-                        Can_TxMsg.Data[1] = Uart_Rece_BattU;
-                        Can_TxMsg.Data[2] = 0x00;
-                        Can_TxMsg.Data[3] = 0x00;//外电压
-                        Can_TxMsg.Data[4] = 0x00;
-                        Can_TxMsg.Data[5] = 0x00;//累加电压
-                        Can_TxMsg.Data[6] = Uart_Rece_BattI>>8;
-                        Can_TxMsg.Data[7] = Uart_Rece_BattI;
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-
-                    }
-                    default:
-                    {
-                       PROC_Can_STATE_SWITCH(PROCESS_STATE_IDLE);
-                       Can_Rece_buffer[0]=0xff;
-                    }
-                }
-                send_index ++;	
-                break;
-            }
-            case PROCESS_STATE_SLEEP:
-            {   
-                slpManPlatVoteEnableSleep(process1SlpHandler, SLP_SLP2_STATE); 
-                slpManPlatVoteDisableSleep(process1SlpHandler, SLP_HIB_STATE);   
-                while(1)
-                {
-                    osDelay(3000);
-                }                                     
-                break;
-            }
-        }
-    }
-}
-/**
-  \fn          process0Init(void)
-  \brief       process0Init function.
-  \return
-*/
-void process0Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack0, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process0AppTask";
-    task_attr.stack_mem = gProcessTaskStack0;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask0;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process0AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process1Init(void)
-  \brief       process1Init function.
-  \return
-*/
-void process1Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack1, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process1AppTask";
-    task_attr.stack_mem = gProcessTaskStack1;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask1;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process1AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process2Init(void)
-  \brief       process2Init function.
-  \return
-*/
-void process2Init(void)
-{
-    osThreadAttr_t task_attr;
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack2, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process2AppTask";
-    task_attr.stack_mem = gProcessTaskStack2;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask2;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process2AppTask, NULL, &task_attr);
-}
-/**
-  \fn          appInit(void)
-  \brief       appInit function.
-  \return
-*/
-void appInit(void *arg)
-{   
-    process0Init();//任务调度和检测程序
-	process1Init();//Uart程序
-    process2Init();//Can程序
-}
-
-/**
-  \fn          int main_entry(void)
-  \brief       main entry function.
-  \return
-*/
-void main_entry(void) {
-
-    BSP_CommonInit();
-    osKernelInitialize();
-
-    registerAppEntry(appInit, NULL);
-    if (osKernelGetState() == osKernelReady)
-    {
-        osKernelStart();
-    }
-    while(1);
-}

+ 0 - 735
app_1_7.c

@@ -1,735 +0,0 @@
-/****************************************************************************
- *
- * Copy right:   2020-, Copyrigths of QIXIANG TECH Ltd.
- * File name:    app.c
- * Description:  QX app source file 
- * History:      Rev1.0   2020-10-16
- * Athuor:       chenjie 
- *
- ****************************************************************************/
-//include 
-#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
-// app task static stack and control block
-#define PROC_TASK_STACK_SIZE    (1024)
-
-
-//uart def
-#define Uart_Send_LEN         (8)
-#define Uart_Rece_LEN         (16)
-#define RTE_UART_RX_IO_MODE      RTE_UART1_RX_IO_MODE
-
-//statement variable
-extern ARM_DRIVER_USART Driver_USART1;
-static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
-
-/** \brief usart receive buffer */
-uint8_t Uart_Data_buffer[8];
-
-/** \brief usart send buffer */
-
-/** \brief receive timeout flag */
-volatile bool isRecvTimeout = false;
-
-/** \brief receive complete flag */
-volatile bool isRecvComplete = false;
-
-uint8_t process0SlpHandler     = 0xff;
-uint8_t process1SlpHandler     = 0xff;
-uint8_t process2SlpHandler     = 0xff;
-uint8_t deepslpTimerID         = 7;
-
-/** \brief 电压传输 */
-
-uint8_t Uart_Rece_BattCellU1_U4[8];
-uint8_t Uart_Rece_BattCellU5_U8[8];
-uint8_t Uart_Rece_BattCellU9_U12[8];
-uint8_t Uart_Rece_BattCellU13_U14[8];
-uint8_t Uart_Rece_BattT[8];
-int16_t Uart_Rece_BattI=0x0000;
-uint8_t Uart_Rece_Batt_states[6];
-uint16_t Uart_Rece_BattU;
-uint16_t Uart_Rece_Batt_MaxcellU;
-uint16_t Uart_Rece_Batt_MincellU;
-
-uint8_t Can_Rece_buffer[8];
-typedef enum
-{
-    PROCESS_STATE_IDLE = 0,
-    PROCESS_STATE_WORK,
-    PROCESS_STATE_SLEEP
-}processSM;
-typedef enum
-{
-    PROCESS_Uart_STATE_IDLE = 0,
-    PROCESS_Uart_STATE_WORK,
-    PROCESS_Uart_STATE_CHECK,
-    PROCESS_Uart_STATE_SLEEP
-}process_Uart;
-
-static StaticTask_t           gProcessTask0;
-static UINT8                    gProcessTaskStack0[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask1;
-static UINT8                    gProcessTaskStack1[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask2;
-static UINT8                    gProcessTaskStack2[PROC_TASK_STACK_SIZE];
-
-processSM 	    gProc0State = PROCESS_STATE_IDLE;
-process_Uart 	gProc1State = PROCESS_Uart_STATE_IDLE;
-processSM 	    gProc2State = PROCESS_STATE_IDLE;
-#define PROC_Task_STATE_SWITCH(a)  (gProc0State = a) //任务调度切换
-#define PROC_Uart_STATE_SWITCH(a)  (gProc1State = a) //uart 状态切换
-#define PROC_Can_STATE_SWITCH(a)  (gProc2State = a) //can 状态切换
-
-
-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;
-}
-
-uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg)
-{
-    uint8_t Uart_Rece_buffer[Uart_Rece_LEN];
-    uint16_t CRC_Reve_buffer;
-    uint16_t CRC_chk_buffer;
-    uint8_t Uart_Send_buffer[8];
-    uint8_t Rece_Data_Len;
-    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;
-    Uart_Rece_buffer[0]=0xfe;
-    uint32_t timeout=0;
-    USARTdrv->Send(Uart_Send_buffer,8);
-    USARTdrv->Receive(Uart_Rece_buffer,13);
-    Rece_Data_Len = 11;
-    while((isRecvTimeout == false) && (isRecvComplete == false))// 未收到数据不叫时间超时,收到数据但是不全叫时间超时
-    {
-        timeout++;
-        if (timeout>7000000)
-        {
-            timeout =0;
-            isRecvTimeout = true;
-            break;
-        }
-    }
-    if (isRecvComplete == true)
-    {
-        isRecvComplete = false;
-        CRC_chk_buffer =Uart_Rece_buffer[12]<<8|Uart_Rece_buffer[11];
-        CRC_Reve_buffer = crc_chk(Uart_Rece_buffer,11);
-        if (CRC_Reve_buffer == CRC_chk_buffer)//满足校验
-        {
-            for (uint8_t i = 0; i < 8; i++)
-            {
-                Uart_Data_buffer[i]=Uart_Rece_buffer[i+3];
-            }
-            return Uart_Data_buffer;
-        }
-        else //接收数据的校验不过暂时屏蔽
-        {
-            for (uint8_t i = 0; i < 8; i++)
-            {
-                Uart_Data_buffer[i]=0xff;
-            }
-            return Uart_Data_buffer;
-        }
-    }
-    if (isRecvTimeout == true)//没收到数据,全部为空值
-    {
-        Uart_Data_buffer[0] = 0x00;
-        Uart_Data_buffer[1] = 0x00;
-        Uart_Data_buffer[2] = 0x00;
-        Uart_Data_buffer[3] = 0x00;
-        Uart_Data_buffer[4] = 0x00;
-        Uart_Data_buffer[5] = 0x00;
-        Uart_Data_buffer[6] = 0x00;
-        Uart_Data_buffer[7] = 0xff;
-        isRecvTimeout = false;
-        osDelay(1000);
-        return Uart_Data_buffer;
-    }
-}
-void USART_callback(uint32_t event)
-{
-    if(event & ARM_USART_EVENT_RX_TIMEOUT)
-    {
-        isRecvTimeout = true;
-    }
-    if(event & ARM_USART_EVENT_RECEIVE_COMPLETE)
-    {
-        isRecvComplete = true;
-    }
-}
-
-static void process0AppTask(void* arg)
-{
-    uint32_t inParam = 0xAABBCCDD;
-    uint32_t cnt;
-    UINT8 Can_index = 0;
-    UINT8 Uart_index = 0;
-    uint32_t sleep_index = 0;
-    PROC_Task_STATE_SWITCH(PROCESS_STATE_IDLE);
-    NetSocDisplay(0,LED_TURN_OFF);
-    NetSocDisplay(1,LED_TURN_OFF);
-    NetSocDisplay(2,LED_TURN_OFF);
-    NetSocDisplay(3,LED_TURN_OFF);
-    NetSocDisplay(4,LED_TURN_OFF);
-
-
-    slpManSetPmuSleepMode(true,SLP_HIB_STATE,false);
-    slpManApplyPlatVoteHandle("process0slp",&process0SlpHandler);
-    slpManPlatVoteDisableSleep(process0SlpHandler, SLP_SLP2_STATE); 
-    slpManSlpState_t slpstate = slpManGetLastSlpState();
-    if((slpstate == SLP_SLP2_STATE) || (slpstate == SLP_HIB_STATE))
-    {
-        PROC_Task_STATE_SWITCH(PROCESS_STATE_IDLE);
-    }
-    else
-    {
-        PROC_Task_STATE_SWITCH(PROCESS_STATE_WORK);
-    }
-    
-    while(1)
-    {
-        switch(gProc0State)
-        {
-            case PROCESS_STATE_IDLE:
-            {   
-                PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_CHECK);
-                NetSocDisplay(0,LED_TURN_ON);
-                osDelay(100);//delay 100ms
-                if(Uart_Rece_BattI!=0x0000)
-                {
-                    PROC_Task_STATE_SWITCH(PROCESS_STATE_WORK);
-                }
-                sleep_index++;
-                if(sleep_index>=100)
-                {
-                    NetSocDisplay(0,LED_TURN_OFF);
-                    sleep_index=0;
-                    PROC_Task_STATE_SWITCH(PROCESS_STATE_SLEEP);
-                }
-                break;
-            }
-            case PROCESS_STATE_WORK:
-            {
-                osDelay(10);//10ms
-                Can_index++;
-                Uart_index++;
-                if (Uart_index >10)//Uart 100ms 调用一次
-                {
-                    PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_WORK);
-                    Uart_index = 0;
-                }
-                if (Can_index >=100)//Can 1000ms 调用一次
-                {
-                    PROC_Can_STATE_SWITCH(PROCESS_STATE_WORK);
-                    Can_index = 0;
-                }
-                if((Uart_Rece_BattI==0x0000)&&(Can_Rece_buffer[0]==0xff))
-                {
-                    sleep_index++;
-                }
-                else
-                {
-                    sleep_index = 0;
-                }
-
-                if (sleep_index >=6000)
-                {
-                    PROC_Task_STATE_SWITCH(PROCESS_STATE_SLEEP);
-                    sleep_index = 0;
-                }
-                break;
-                
-            }
-            case PROCESS_STATE_SLEEP:
-            {
-
-                slpManSlpState_t State;
-                uint8_t cnt;
-                PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_SLEEP);
-                PROC_Can_STATE_SWITCH(PROCESS_STATE_SLEEP);
-                slpManPlatVoteEnableSleep(process0SlpHandler,SLP_SLP2_STATE);
-                slpManPlatVoteDisableSleep(process0SlpHandler, SLP_HIB_STATE); 
-                slpManDeepSlpTimerStart(deepslpTimerID, 300000); // create a 10s timer, DeepSleep Timer is always oneshoot
-                while(1)                // now app can enter hib, but ps and phy maybe not, so wait here
-                {
-                    osDelay(3000);
-                }
-            }
-        }
-    }
-}
-
-static void process1AppTask(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);
-    int Rece_index = 0;
-    uint8_t *Uart_Reve_Point = NULL;
-    Uart_Receive_Type Uart_Receive_Msg;
-	PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE);
-    slpManPlatVoteDisableSleep(process2SlpHandler, SLP_SLP2_STATE);
-    Uart_Receive_Msg.Bms_Address = 0x01;
-    Uart_Receive_Msg.Bms_Read_Funcode = 0x03;
-    while(1)
-    {
-        switch(gProc1State)
-        {
-            case PROCESS_Uart_STATE_IDLE:
-            {   
-                NetSocDisplay(1,LED_TURN_OFF);     
-                Rece_index = 0;
-                break;
-            }
-            case PROCESS_Uart_STATE_CHECK:
-            {
-                Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                Uart_Receive_Msg.Reg_Begin_L= 0x10;
-                Uart_Receive_Msg.Reg_Num_H = 0x00;
-                Uart_Receive_Msg.Reg_Num_L = 0x04;
-                Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                Uart_Rece_BattI = *(Uart_Reve_Point+0)<<8 | *(Uart_Reve_Point+1);
-                PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE);
-                break;
-            }
-            case PROCESS_Uart_STATE_WORK:
-            {
-                NetSocDisplay(1,LED_TURN_ON);
-                switch(Rece_index)
-                {
-                    case 0://读取电压1-4
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L = 0x02;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU1_U4[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 1://读取电压5-8
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x06;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU5_U8[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 2:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x0A;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU9_U12[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 3:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x0E;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU13_U14[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 4:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x14;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattT[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 5:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x10;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        Uart_Rece_BattI = *(Uart_Reve_Point+0)<<8 | *(Uart_Reve_Point+1);
-                        for (int i = 0; i < 6; i++)
-                        {
-                            Uart_Rece_Batt_states[i] = *(Uart_Reve_Point+2+i);
-                        }
-                        break;
-                    }
-                    case 6:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x2B;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        Uart_Rece_BattU = *(Uart_Reve_Point+0)<<8 | *(Uart_Reve_Point+1);
-                        Uart_Rece_Batt_MaxcellU = *(Uart_Reve_Point+2)<<8 | *(Uart_Reve_Point+3);
-                        Uart_Rece_Batt_MincellU = *(Uart_Reve_Point+4)<<8 | *(Uart_Reve_Point+5);
-                        break;
-                    }
-                    default:
-                    {
-                       PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE);
-                        break;
-                    }
-                }
-                Rece_index++;
-                break;
-            }
-            case PROCESS_Uart_STATE_SLEEP:
-            {	
-                slpManPlatVoteEnableSleep(process2SlpHandler, SLP_SLP2_STATE);  
-                slpManPlatVoteDisableSleep(process2SlpHandler, SLP_HIB_STATE);  
-                while(1)
-                {
-                    osDelay(3000);
-                }           
-                //此处休眠
-                break;
-            }
-        }
-    }
-}
-static void process2AppTask(void* arg)
-{
-	PROC_Can_STATE_SWITCH(PROCESS_STATE_IDLE);
-    uint32_t Can_ID;
-    NVIC_EnableIRQ(PadWakeup1_IRQn);
-    Can_InitType param;
-    Can_TxMsgType Can_TxMsg;
-    param.baudrate = CAN_500Kbps;
-    param.mode = REQOP_NORMAL;
-    param.TxStdIDH = 0x00;
-    param.TxStdIDL = 0x00;
-    param.RxStdIDH[0] = 0x00;
-    param.RxStdIDL[0] = 0x00;
-    /*stdid 0000 0000 001x*/
-    param.RxStdIDH[1] = 0x00;
-    param.RxStdIDL[1] = 0x20;
-    /*stdid 0000 0000 010x */
-    param.RxStdIDH[2] = 0x00;
-    param.RxStdIDL[2] = 0x40;
-    /*stdid 0000 0000 011x*/
-    param.RxStdIDH[3] = 0x00;
-    param.RxStdIDL[3] =0x60;
-    /*stdid 0000 0000 100x */
-    param.RxStdIDH[4] = 0x00;
-    param.RxStdIDL[4] = 0x80;
-    /*stdid 0000 0000 101x*/
-    param.RxStdIDH[5] = 0x00;
-    param.RxStdIDL[5] =0xa0;
-    param.packType = STD_PACK;
-    HAL_Can_Init(param);
-    int send_index = 0;
-    slpManPlatVoteDisableSleep(process1SlpHandler, SLP_SLP2_STATE);
-    while(1)
-    {
-        switch(gProc2State)
-        {
-            case PROCESS_STATE_IDLE:
-            {
-                HAL_Can_Receive(Can_Rece_buffer);
-                send_index = 0;
-                break;
-            }
-            case PROCESS_STATE_WORK:
-            {
-                switch(send_index)
-                {
-                    case 0:
-                    {
-                        Can_ID = 0x001;
-                        for (int i = 0; i < 8; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU1_U4[i];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 1:
-                    {
-                        Can_ID = 0x013;
-                        for (int i = 0; i < 8; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU5_U8[i];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 2:
-                    {
-                        Can_ID = 0x021;
-                        for (int i = 0; i < 8; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU9_U12[i];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 3:
-                    {
-                        Can_ID = 0x031;
-                        for (int i = 0; i < 4; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU13_U14[i];
-                        }
-                        Can_TxMsg.Data[4] = 0x00;
-                        Can_TxMsg.Data[5] = 0x00;
-                        Can_TxMsg.Data[6] = 0x00;
-                        Can_TxMsg.Data[7] = 0x00;
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 4:
-                    {
-                        Can_ID  = 0x101;
-                        for (int i = 0; i < 4; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattT[i*2+1];
-                        }
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-                    }
-                    case 5:
-                    {
-                        Can_ID = 0x201;
-                        Can_TxMsg.Data[0] = Uart_Rece_BattU>>8;
-                        Can_TxMsg.Data[1] = Uart_Rece_BattU;
-                        Can_TxMsg.Data[2] = 0x00;
-                        Can_TxMsg.Data[3] = 0x00;//外电压
-                        Can_TxMsg.Data[4] = 0x00;
-                        Can_TxMsg.Data[5] = 0x00;//累加电压
-                        Can_TxMsg.Data[6] = Uart_Rece_BattI>>8;
-                        Can_TxMsg.Data[7] = Uart_Rece_BattI;
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-
-                    }
-                    case 6:
-                    {
-                        Can_ID = 0x211;
-                        Can_TxMsg.Data[0] = Uart_Rece_Batt_MaxcellU>>8;
-                        Can_TxMsg.Data[1] = Uart_Rece_Batt_MaxcellU;
-                        Can_TxMsg.Data[2] = Uart_Rece_Batt_MincellU>>8;
-                        Can_TxMsg.Data[3] = Uart_Rece_Batt_MincellU;
-                        Can_TxMsg.Data[4] = 0x00;
-                        Can_TxMsg.Data[5] = 0x00;
-                        Can_TxMsg.Data[6] = 0x00;
-                        Can_TxMsg.Data[7] = 0x00;
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-
-                    }
-                    default:
-                    {
-                       PROC_Can_STATE_SWITCH(PROCESS_STATE_IDLE);
-                       Can_Rece_buffer[0]=0xff;
-                    }
-                }
-                send_index ++;	
-                break;
-            }
-            case PROCESS_STATE_SLEEP:
-            {   
-                slpManPlatVoteEnableSleep(process1SlpHandler, SLP_SLP2_STATE); 
-                slpManPlatVoteDisableSleep(process1SlpHandler, SLP_HIB_STATE);   
-                while(1)
-                {
-                    osDelay(3000);
-                }                                     
-                break;
-            }
-        }
-    }
-}
-/**
-  \fn          process0Init(void)
-  \brief       process0Init function.
-  \return
-*/
-void process0Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack0, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process0AppTask";
-    task_attr.stack_mem = gProcessTaskStack0;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask0;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process0AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process1Init(void)
-  \brief       process1Init function.
-  \return
-*/
-void process1Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack1, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process1AppTask";
-    task_attr.stack_mem = gProcessTaskStack1;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask1;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process1AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process2Init(void)
-  \brief       process2Init function.
-  \return
-*/
-void process2Init(void)
-{
-    osThreadAttr_t task_attr;
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack2, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process2AppTask";
-    task_attr.stack_mem = gProcessTaskStack2;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask2;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process2AppTask, NULL, &task_attr);
-}
-/**
-  \fn          appInit(void)
-  \brief       appInit function.
-  \return
-*/
-void appInit(void *arg)
-{   
-    process0Init();//任务调度和检测程序
-	process1Init();//Uart程序
-    process2Init();//Can程序
-}
-
-/**
-  \fn          int main_entry(void)
-  \brief       main entry function.
-  \return
-*/
-void main_entry(void) {
-
-    BSP_CommonInit();
-    osKernelInitialize();
-
-    registerAppEntry(appInit, NULL);
-    if (osKernelGetState() == osKernelReady)
-    {
-        osKernelStart();
-    }
-    while(1);
-}

+ 0 - 421
app_1_8.c

@@ -1,421 +0,0 @@
-/****************************************************************************
- *
- * Copy right:   2020-, Copyrigths of QIXIANG TECH Ltd.
- * File name:    app.c
- * Description:  QX app source file 
- * History:      Rev1.0   2020-10-16
- * Athuor:       chenjie 
- *
- ****************************************************************************/
-//include 
-#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
-// app task static stack and control block
-#define PROC_TASK_STACK_SIZE    (1024)
-
-
-//uart def
-#define Uart_Send_LEN         (8)
-#define Uart_Rece_LEN         (16)
-#define RTE_UART_RX_IO_MODE      RTE_UART1_RX_IO_MODE
-
-//statement variable
-extern ARM_DRIVER_USART Driver_USART1;
-static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
-
-/** \brief usart receive buffer */
-uint8_t Uart_Data_buffer[8];
-
-/** \brief usart send buffer */
-
-/** \brief receive timeout flag */
-volatile bool isRecvTimeout = false;
-
-/** \brief receive complete flag */
-volatile bool isRecvComplete = false;
-
-uint8_t process0SlpHandler     = 0xff;
-uint8_t process1SlpHandler     = 0xff;
-uint8_t process2SlpHandler     = 0xff;
-
-/** \brief 电压传输 */
-
-uint8_t Uart_Rece_BattCellU1_U4[8];
-uint8_t Uart_Rece_BattCellU5_U8[8];
-uint8_t Uart_Rece_BattCellU9_U12[8];
-uint8_t Uart_Rece_BattCellU13_U14[8];
-uint8_t Uart_Rece_BattT[8];
-int16_t Uart_Rece_BattI;
-uint8_t Uart_Rece_Batt_states[6];
-uint16_t Uart_Rece_BattU;
-uint16_t Uart_Rece_Batt_MaxcellU;
-uint16_t Uart_Rece_Batt_MincellU;
-typedef enum
-{
-    PROCESS1_STATE_IDLE = 0,
-    PROCESS1_STATE_WORK,
-    PROCESS1_STATE_SLEEP
-}process1SM;
-typedef enum
-{
-    PROCESS2_STATE_IDLE = 0,
-    PROCESS2_STATE_WORK,
-    PROCESS2_STATE_SLEEP
-}process2SM;
-
-static StaticTask_t           gProcessTask0;
-static UINT8                    gProcessTaskStack0[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask1;
-static UINT8                    gProcessTaskStack1[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask2;
-static UINT8                    gProcessTaskStack2[PROC_TASK_STACK_SIZE];
-
-process1SM 	gProc1State = PROCESS1_STATE_IDLE;
-process2SM 	gProc2State = PROCESS2_STATE_IDLE;
-#define PROC1_STATE_SWITCH(a)  (gProc1State = a)
-#define PROC2_STATE_SWITCH(a)  (gProc2State = a)
-
-
-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;
-}
-uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg)
-{
-    uint8_t Uart_Rece_buffer[Uart_Rece_LEN];
-    uint16_t CRC_Reve_buffer;
-    uint16_t CRC_chk_buffer;
-    uint8_t Uart_Send_buffer[8];
-    uint8_t Rece_Data_Len;
-    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;
-    Uart_Rece_buffer[0]=0xfe;
-    uint32_t timeout=0;
-    USARTdrv->Send(Uart_Send_buffer,8);
-    USARTdrv->Receive(Uart_Rece_buffer,13);
-    Rece_Data_Len = 11;
-    while((isRecvTimeout == false) && (isRecvComplete == false))// 未收到数据不叫时间超时,收到数据但是不全叫时间超时
-    {
-        timeout++;
-        if (timeout>7000000)
-        {
-            timeout =0;
-            isRecvTimeout = true;
-            break;
-        }
-    }
-    if (isRecvComplete == true)
-    {
-        isRecvComplete = false;
-        CRC_chk_buffer =Uart_Rece_buffer[12]<<8|Uart_Rece_buffer[11];
-        CRC_Reve_buffer = crc_chk(Uart_Rece_buffer,11);
-        if (CRC_Reve_buffer == CRC_chk_buffer)//满足校验
-        {
-            for (uint8_t i = 0; i < 8; i++)
-            {
-                Uart_Data_buffer[i]=Uart_Rece_buffer[i+3];
-            }
-            return Uart_Data_buffer;
-        }
-        else //接收数据的校验不过暂时屏蔽
-        {
-            for (uint8_t i = 0; i < 8; i++)
-            {
-                Uart_Data_buffer[i]=0xff;
-            }
-            return Uart_Data_buffer;
-        }
-    }
-    if (isRecvTimeout == true)//没收到数据,全部为空值
-    {
-        Uart_Data_buffer[0] = 0x00;
-        Uart_Data_buffer[1] = 0x00;
-        Uart_Data_buffer[2] = 0x00;
-        Uart_Data_buffer[3] = 0x00;
-        Uart_Data_buffer[4] = 0x00;
-        Uart_Data_buffer[5] = 0x00;
-        Uart_Data_buffer[6] = 0x00;
-        Uart_Data_buffer[7] = 0xff;
-        isRecvTimeout = false;
-        osDelay(1000);
-        return Uart_Data_buffer;
-    }
-}
-void USART_callback(uint32_t event)
-{
-    if(event & ARM_USART_EVENT_RX_TIMEOUT)
-    {
-        isRecvTimeout = true;
-    }
-    if(event & ARM_USART_EVENT_RECEIVE_COMPLETE)
-    {
-        isRecvComplete = true;
-    }
-}
-
-static void process0AppTask(void* arg)
-{
-    uint32_t inParam = 0xAABBCCDD;
-    uint32_t cnt;
-    slpManSetPmuSleepMode(true,SLP_HIB_STATE,false);
-    slpManApplyPlatVoteHandle("process0slp",&process0SlpHandler);
-    slpManSlpState_t slpstate = slpManGetLastSlpState();
-    UINT8 Can_index = 0;
-    UINT8 Uart_index = 0;
-    while(1)
-    {
-        osDelay(10);//10ms
-        Can_index++;
-        Uart_index++;
-        if (Uart_index >10)//Uart 100ms 调用一次
-        {
-            PROC2_STATE_SWITCH(PROCESS2_STATE_WORK);
-            Uart_index = 0;
-        }
-        if (Can_index >=100)//Can 1000ms 调用一次
-        {
-            PROC1_STATE_SWITCH(PROCESS1_STATE_WORK);
-            Can_index = 0;
-        } 
-    }
-}
-void TcpCallBack(void)
-{
-    #ifdef USING_PRINTF
-        printf("[%d]TcpCallBacl",__LINE__);
-    #endif
-}
-static void process1AppTask(void* arg)
-{
-    int TcpConnectID = -1;
-    int TcpSendID = 0;
-    uint8_t TcpSendBuffer[71] = {0x23,0x23,0x01,0xfe,0x54,
-                                0x54,0x54,0x54,0x54,0x54,
-                                0x54,0x54,0x54,0x54,0x54,
-                                0x54,0x54,0x54,0x30,0x30,
-                                0x31,0x01,0x00,0x2e,0x11,
-                                0x03,0x10,0x09,0x39,0x37,
-                                0x00,0x02,0x38,0x39,0x38,
-                                0x36,0x30,0x32,0x62,0x34,
-                                0x32,0x32,0x31,0x36,0x63,
-                                0x30,0x32,0x39,0x39,0x35,
-                                0x31,0x39,0x01,0x10,0x01,
-                                0x00,0x15,0x01,0x20,0x01,
-                                0x01,0x92,0x01,0x00,0x05,
-                                0x0f,0x04,0x01,0x00,0x01,
-                                0x5F};
-	PROC1_STATE_SWITCH(PROCESS1_STATE_IDLE);
-    CHAR   serverip[] = "47.97.127.222";
-    UINT16 serverport = 8712;
-    UINT16 localport = NULL;
-    while(1)
-    {
-        switch(gProc1State)
-        {
-            case PROCESS1_STATE_IDLE:
-            {
-                FaultDisplay(LED_TURN_OFF);
-                break;
-            }
-            case PROCESS1_STATE_WORK:
-            {
-                while(TcpConnectID<=0)
-                {
-                    TcpConnectID = tcpipConnectionCreate(1,PNULL,PNULL,serverip,serverport,TcpCallBack);
-                }
-                TcpSendID  = tcpipConnectionSend(TcpConnectID,TcpSendBuffer,71,PNULL,PNULL,PNULL);
-                #ifdef USING_PRINTF
-                    printf("[%d]TcpConnectID:%d \r\n",__LINE__,TcpConnectID);
-                #endif
-                #ifdef USING_PRINTF
-                    printf("[%d]TcpSendID:%d \r\n",__LINE__,TcpSendID);
-                #endif
-                ECOMM_TRACE(UNILOG_PLA_APP, ec_autoReg102, P_SIG, 0, "ECOMM_Test");
-                FaultDisplay(LED_TURN_ON);
-                PROC1_STATE_SWITCH(PROCESS1_STATE_SLEEP);	
-                break;
-            }
-            case PROCESS1_STATE_SLEEP:
-            {                                     
-                break;
-            }
-        }
-    }
-}
-static void process2AppTask(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);
-    int Rece_index = 0;
-    uint8_t *Uart_Reve_Point = NULL;
-    Uart_Receive_Type Uart_Receive_Msg;
-	PROC2_STATE_SWITCH(PROCESS2_STATE_IDLE);
-    while(1)
-    {
-        switch(gProc2State)
-        {
-            case PROCESS2_STATE_IDLE:
-            {   
-                NetSocDisplay(3,LED_TURN_OFF);
-                break;
-            }
-            case PROCESS2_STATE_WORK:
-            {
-                break;
-            }
-            case PROCESS2_STATE_SLEEP:
-            {	        
-                //此处写休眠程序
-                break;
-            }
-        }
-    }
-}
-/**
-  \fn          process0Init(void)
-  \brief       process0Init function.
-  \return
-*/
-void process0Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack0, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process0AppTask";
-    task_attr.stack_mem = gProcessTaskStack0;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask0;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process0AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process1Init(void)
-  \brief       process1Init function.
-  \return
-*/
-void process1Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack1, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process1AppTask";
-    task_attr.stack_mem = gProcessTaskStack1;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask1;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process1AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process2Init(void)
-  \brief       process2Init function.
-  \return
-*/
-void process2Init(void)
-{
-    osThreadAttr_t task_attr;
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack2, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process2AppTask";
-    task_attr.stack_mem = gProcessTaskStack2;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask2;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process2AppTask, NULL, &task_attr);
-}
-/**
-  \fn          appInit(void)
-  \brief       appInit function.
-  \return
-*/
-void appInit(void *arg)
-{   
-    process0Init();
-	process1Init();
-    process2Init();
-}
-
-/**
-  \fn          int main_entry(void)
-  \brief       main entry function.
-  \return
-*/
-void main_entry(void) {
-
-    BSP_CommonInit();
-    osKernelInitialize();
-
-    registerAppEntry(appInit, NULL);
-    if (osKernelGetState() == osKernelReady)
-    {
-        osKernelStart();
-    }
-    while(1);
-}

+ 0 - 280
app_1_8_1.c

@@ -1,280 +0,0 @@
-/****************************************************************************
- *
- * Copy right:   2020-, Copyrigths of QIXIANG TECH Ltd.
- * File name:    app.c
- * Description:  QX app source file 
- * History:      Rev1.0   2020-10-16
- * Athuor:       chenjie 
- *
- ****************************************************************************/
-//include 
-#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
-// app task static stack and control block
-#define PROC_TASK_STACK_SIZE    (1024)
-
-
-//uart def
-#define Uart_Send_LEN         (8)
-#define Uart_Rece_LEN         (16)
-#define RTE_UART_RX_IO_MODE      RTE_UART1_RX_IO_MODE
-
-//statement variable
-extern ARM_DRIVER_USART Driver_USART1;
-static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
-
-/** \brief usart receive buffer */
-uint8_t Uart_Data_buffer[8];
-
-/** \brief usart send buffer */
-
-/** \brief receive timeout flag */
-volatile bool isRecvTimeout = false;
-
-/** \brief receive complete flag */
-volatile bool isRecvComplete = false;
-
-uint8_t process0SlpHandler     = 0xff;
-uint8_t process1SlpHandler     = 0xff;
-uint8_t process2SlpHandler     = 0xff;
-
-/** \brief 电压传输 */
-
-typedef enum
-{
-    PROCESS1_STATE_IDLE = 0,
-    PROCESS1_STATE_WORK,
-    PROCESS1_STATE_SLEEP
-}process1SM;
-typedef enum
-{
-    PROCESS2_STATE_IDLE = 0,
-    PROCESS2_STATE_WORK,
-    PROCESS2_STATE_SLEEP
-}process2SM;
-
-static StaticTask_t           gProcessTask0;
-static UINT8                    gProcessTaskStack0[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask1;
-static UINT8                    gProcessTaskStack1[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask2;
-static UINT8                    gProcessTaskStack2[PROC_TASK_STACK_SIZE];
-
-process1SM 	gProc1State = PROCESS1_STATE_IDLE;
-process2SM 	gProc2State = PROCESS2_STATE_IDLE;
-#define PROC1_STATE_SWITCH(a)  (gProc1State = a)
-#define PROC2_STATE_SWITCH(a)  (gProc2State = a)
-
-
-static void process0AppTask(void* arg)
-{
-    uint32_t inParam = 0xAABBCCDD;
-    uint32_t cnt;
-    slpManSetPmuSleepMode(true,SLP_HIB_STATE,false);
-    slpManApplyPlatVoteHandle("process0slp",&process0SlpHandler);
-    slpManSlpState_t slpstate = slpManGetLastSlpState();
-    UINT8 Can_index = 0;
-    UINT8 Uart_index = 0;
-    while(1)
-    {
-        osDelay(10);//10ms
-        Can_index++;
-        Uart_index++;
-        if (Uart_index >10)//Uart 100ms 调用一次
-        {
-            PROC2_STATE_SWITCH(PROCESS2_STATE_WORK);
-            Uart_index = 0;
-        }
-        if (Can_index >=100)//Can 1000ms 调用一次
-        {
-            PROC1_STATE_SWITCH(PROCESS1_STATE_WORK);
-            Can_index = 0;
-        } 
-    }
-}
-void TcpCallBack(void)
-{
-    #ifdef USING_PRINTF
-        printf("[%d]TcpCallBacl",__LINE__);
-    #endif
-}
-static void process1AppTask(void* arg)
-{
-    int TcpConnectID = -1;
-    int TcpSendID = 0;
-    time_t timesec;
-    OsaUtcTimeTValue timestracture;
-    uint8_t TcpSendBuffer[92] = {0x23,0x23,0x02,0xFE,0x47,0x59,0x54,0x45,0x53,0x54,
-                                0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,
-                                0x31,0x01,0x00,0x43,0x14,0x0B,0x07,0x0E,0x39,0x37,
-                                0x8C,0x14,0x0B,0x07,0x0E,0x39,0x37,0x1A,0x00,0x00,
-                                0x00,0x00,0x00,0x02,0x15,0x02,0x15,0x03,0x43,0x64,
-                                0x0E,0x00,0x00,0x00,0x00,0x0E,0x53,0x0E,0x53,0x0E,
-                                0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,
-                                0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,
-                                0x53,0x0E,0x53,0x05,0x13,0x13,0x13,0x13,0x13,0x00,
-                                0x00,0x2D};
-	PROC1_STATE_SWITCH(PROCESS1_STATE_IDLE);
-    CHAR   serverip[] = "47.97.127.222";
-    UINT16 serverport = 8712;
-    while(1)
-    {
-        switch(gProc1State)
-        {
-            case PROCESS1_STATE_IDLE:
-            {
-                FaultDisplay(LED_TURN_OFF);
-                break;
-            }
-            case PROCESS1_STATE_WORK:
-            {
-                while(TcpConnectID<=0)
-                {
-                    TcpConnectID = tcpipConnectionCreate(1,PNULL,PNULL,serverip,serverport,TcpCallBack);
-                }
-                TcpSendID  = tcpipConnectionSend(TcpConnectID,TcpSendBuffer,92,PNULL,PNULL,PNULL);
-                appGetSystemTimeSecsSync(&timesec);
-                appGetSystemTimeUtcSync(&timestracture);
-                #ifdef USING_PRINTF
-                    printf("[%d]TcpConnectID:%d \r\n",__LINE__,TcpConnectID);
-                #endif
-                #ifdef USING_PRINTF
-                    printf("[%d]TcpSendID:%d \r\n",__LINE__,TcpSendID);
-                #endif
-                #ifdef USING_PRINTF
-                    printf("[%d]Time:%d \r\n",__LINE__,timesec);
-                #endif
-                #ifdef USING_PRINTF
-                    printf("[%d]Time1:%x TIme2:%x \r\n",__LINE__,timestracture.UTCtimer1,timestracture.UTCtimer2);
-                #endif
-                ECOMM_TRACE(UNILOG_PLA_APP, ec_autoReg102, P_SIG, 0, "ECOMM_Test");
-                FaultDisplay(LED_TURN_ON);
-                PROC1_STATE_SWITCH(PROCESS1_STATE_SLEEP);	
-                break;
-            }
-            case PROCESS1_STATE_SLEEP:
-            {                                     
-                break;
-            }
-        }
-    }
-}
-/**
-  \fn          process0Init(void)
-  \brief       process0Init function.
-  \return
-*/
-void process0Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack0, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process0AppTask";
-    task_attr.stack_mem = gProcessTaskStack0;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask0;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process0AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process1Init(void)
-  \brief       process1Init function.
-  \return
-*/
-void process1Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack1, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process1AppTask";
-    task_attr.stack_mem = gProcessTaskStack1;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask1;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process1AppTask, NULL, &task_attr);
-}
-/**
-  \fn          process2Init(void)
-  \brief       process2Init function.
-  \return
-*/
-void process2Init(void)
-{
-    osThreadAttr_t task_attr;
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack2, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process2AppTask";
-    task_attr.stack_mem = gProcessTaskStack2;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask2;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process2AppTask, NULL, &task_attr);
-}
-/**
-  \fn          appInit(void)
-  \brief       appInit function.
-  \return
-*/
-void appInit(void *arg)
-{   
-    process0Init();
-	process1Init();
-    process2Init();
-}
-
-/**
-  \fn          int main_entry(void)
-  \brief       main entry function.
-  \return
-*/
-void main_entry(void) {
-
-    BSP_CommonInit();
-    osKernelInitialize();
-
-    registerAppEntry(appInit, NULL);
-    if (osKernelGetState() == osKernelReady)
-    {
-        osKernelStart();
-    }
-    while(1);
-}

+ 0 - 390
app_1_8_2.c

@@ -1,390 +0,0 @@
-/****************************************************************************
- *
- * Copy right:   2020-, Copyrigths of QIXIANG TECH Ltd.
- * File name:    app.c
- * Description:  QX app source file 
- * History:      Rev1.0   2020-10-16
- * Athuor:       chenjie 
- *
- ****************************************************************************/
-//include 
-#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
-// app task static stack and control block
-#define PROC_TASK_STACK_SIZE    (1024)
-
-
-//uart def
-#define Uart_Send_LEN         (8)
-#define Uart_Rece_LEN         (16)
-#define RTE_UART_RX_IO_MODE      RTE_UART1_RX_IO_MODE
-
-//statement variable
-extern ARM_DRIVER_USART Driver_USART1;
-static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
-
-/** \brief usart receive buffer */
-uint8_t Uart_Data_buffer[8];
-
-/** \brief usart send buffer */
-
-/** \brief receive timeout flag */
-volatile bool isRecvTimeout = false;
-
-/** \brief receive complete flag */
-volatile bool isRecvComplete = false;
-
-uint8_t process0SlpHandler     = 0xff;
-uint8_t process1SlpHandler     = 0xff;
-uint8_t process2SlpHandler     = 0xff;
-uint8_t deepslpTimerID         = 7;
-
-/** \brief 电压传输 */
-
-uint8_t Uart_Rece_BattCellU1_U4[8];
-uint8_t Uart_Rece_BattCellU5_U8[8];
-uint8_t Uart_Rece_BattCellU9_U12[8];
-uint8_t Uart_Rece_BattCellU13_U14[8];
-uint8_t Uart_Rece_BattT[8];
-int16_t Uart_Rece_BattI=0x0000;
-uint8_t Uart_Rece_Batt_states[6];
-uint16_t Uart_Rece_BattU;
-uint16_t Uart_Rece_Batt_MaxcellU;
-uint16_t Uart_Rece_Batt_MincellU;
-
-uint8_t Can_Rece_buffer[8];
-typedef enum
-{
-    PROCESS_STATE_IDLE = 0,
-    PROCESS_STATE_WORK,
-    PROCESS_STATE_SLEEP
-}processSM;
-typedef enum
-{
-    PROCESS_Uart_STATE_IDLE = 0,
-    PROCESS_Uart_STATE_WORK,
-    PROCESS_Uart_STATE_CHECK,
-    PROCESS_Uart_STATE_SLEEP
-}process_Uart;
-
-static StaticTask_t           gProcessTask0;
-static UINT8                    gProcessTaskStack0[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask1;
-static UINT8                    gProcessTaskStack1[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask2;
-static UINT8                    gProcessTaskStack2[PROC_TASK_STACK_SIZE];
-static StaticTask_t           gProcessTask3;
-static UINT8                    gProcessTaskStack3[PROC_TASK_STACK_SIZE];
-
-processSM 	    gProc0State = PROCESS_STATE_IDLE;
-process_Uart 	gProc1State = PROCESS_Uart_STATE_IDLE;
-processSM 	    gProc2State = PROCESS_STATE_IDLE;
-processSM 	    gProc3State = PROCESS_STATE_IDLE;
-#define PROC_Task_STATE_SWITCH(a)  (gProc0State = a) //任务调度切换
-#define PROC_Uart_STATE_SWITCH(a)  (gProc1State = a) //uart 状态切换
-#define PROC_Can_STATE_SWITCH(a)  (gProc2State = a) //can 状态切换
-#define PROC_NB_STATE_SWITCH(a)  (gProc3State = a) //can 状态切换
-
-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;
-}
-uint8_t bcc_chk(uint8_t* data, uint8_t length)
-{
-    uint8_t bcc_chk_return = 0x00;
-    uint8_t count = 0;
-    while (count<length)
-    {
-        bcc_chk_return^=data[count];
-        count++;
-    }
-    return  bcc_chk_return;
-}
-void TcpCallBack(void)
-{
-    #ifdef USING_PRINTF
-        printf("[%d]TcpCallBacl\n",__LINE__);
-    #endif
-}
-static void process0AppTask(void* arg)
-{
-    uint32_t inParam = 0xAABBCCDD;
-    uint32_t cnt;
-    UINT8 Can_index = 0;
-    UINT8 Uart_index = 0;
-    uint32_t sleep_index = 0;
-    PROC_Task_STATE_SWITCH(PROCESS_STATE_IDLE);
-    NetSocDisplay(0,LED_TURN_OFF);
-    NetSocDisplay(1,LED_TURN_OFF);
-    NetSocDisplay(2,LED_TURN_OFF);
-    NetSocDisplay(3,LED_TURN_OFF);
-    NetSocDisplay(4,LED_TURN_OFF);
-
-
-    slpManSetPmuSleepMode(true,SLP_HIB_STATE,false);
-    slpManApplyPlatVoteHandle("process0slp",&process0SlpHandler);
-    slpManPlatVoteDisableSleep(process0SlpHandler, SLP_SLP2_STATE); 
-    slpManSlpState_t slpstate = slpManGetLastSlpState();
-    if((slpstate == SLP_SLP2_STATE) || (slpstate == SLP_HIB_STATE))
-    {
-        PROC_Task_STATE_SWITCH(PROCESS_STATE_IDLE);
-    }
-    else
-    {
-        PROC_Task_STATE_SWITCH(PROCESS_STATE_WORK);
-    }
-    
-    while(1)
-    {
-        switch(gProc0State)
-        {
-            case PROCESS_STATE_IDLE:
-            {   
-                PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_CHECK);
-                NetSocDisplay(0,LED_TURN_ON);
-                osDelay(100);//delay 100ms
-                if(Uart_Rece_BattI!=0x0000)
-                {
-                    PROC_Task_STATE_SWITCH(PROCESS_STATE_WORK);
-                }
-                sleep_index++;
-                if(sleep_index>=100)
-                {
-                    NetSocDisplay(0,LED_TURN_OFF);
-                    sleep_index=0;
-                    PROC_Task_STATE_SWITCH(PROCESS_STATE_SLEEP);
-                }
-                break;
-            }
-            case PROCESS_STATE_WORK:
-            {
-                osDelay(10);//10ms
-                Can_index++;
-                Uart_index++;
-                if (Uart_index >10)//Uart 100ms 调用一次
-                {
-                    PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_WORK);
-                    Uart_index = 0;
-                }
-                if (Can_index >=100)//Can 1000ms 调用一次
-                {
-                    PROC_Can_STATE_SWITCH(PROCESS_STATE_WORK);
-                    PROC_NB_STATE_SWITCH(PROCESS_STATE_WORK);
-                    Can_index = 0;
-                }
-                if((Uart_Rece_BattI==0x0000)&&(Can_Rece_buffer[0]==0xff))
-                {
-                    sleep_index++;
-                }
-                else
-                {
-                    sleep_index = 0;
-                }
-
-                if (sleep_index >=6000)
-                {
-                    PROC_Task_STATE_SWITCH(PROCESS_STATE_SLEEP);
-                    sleep_index = 0;
-                }
-                break;
-                
-            }
-            case PROCESS_STATE_SLEEP:
-            {
-
-                slpManSlpState_t State;
-                uint8_t cnt;
-                PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_SLEEP);
-                PROC_Can_STATE_SWITCH(PROCESS_STATE_SLEEP);
-                slpManPlatVoteEnableSleep(process0SlpHandler,SLP_SLP2_STATE);
-                slpManPlatVoteDisableSleep(process0SlpHandler, SLP_HIB_STATE); 
-                slpManDeepSlpTimerStart(deepslpTimerID, 300000); // create a 10s timer, DeepSleep Timer is always oneshoot
-                while(1)                // now app can enter hib, but ps and phy maybe not, so wait here
-                {
-                    osDelay(3000);
-                }
-            }
-        }
-    }
-}
-
-static void process3AppTask(void* arg)
-{
-    CHAR   serverip[] = "47.97.127.222";
-    UINT16 serverport = 8712;
-    int TcpConnectID = -1;
-    int TcpSendID = -1;
-    OsaUtcTimeTValue timestracture;
-    uint8_t TcpSendBuffer[92] = {0x23,0x23,0x02,0xFE,0x47,0x59,0x54,0x45,0x53,0x54,
-                                0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,
-                                0x32,0x01,0x00,0x43,0x14,0x0B,0x07,0x0E,0x39,0x37,
-                                0x80,0x14,0x0B,0x07,0x0E,0x39,0x37,0x1A,0x00,0x00,
-                                0x00,0x00,0x00,0x02,0x15,0x02,0x15,0x03,0x43,0x64,
-                                0x00,0x00,0x00,0x00,0x0E,0x0E,0x53,0x0E,0x53,0x0E,
-                                0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,
-                                0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,
-                                0x53,0x0E,0x53,0x05,0x13,0x13,0x13,0x13,0x13,0x00,
-                                0x00,0x00};
-	PROC_NB_STATE_SWITCH(PROCESS_STATE_IDLE);
-    while(1)
-    {
-        switch(gProc3State)
-        {
-            case PROCESS_STATE_IDLE:
-            {
-                break;
-            }
-            case PROCESS_STATE_WORK:
-            {	
-                while(TcpConnectID<0)
-                {
-                    TcpConnectID = tcpipConnectionCreate(1,PNULL,PNULL,serverip,serverport,TcpCallBack);
-                }
-                 appGetSystemTimeUtcSync(&timestracture);
-                TcpSendBuffer[91] = bcc_chk(TcpSendBuffer,91);
-                TcpSendBuffer[24] = timestracture.UTCtimer1>>16;
-                TcpSendBuffer[24] = TcpSendBuffer[24]-0x07D0;
-                TcpSendBuffer[25] = timestracture.UTCtimer1>>8;
-                TcpSendBuffer[26] = timestracture.UTCtimer1;
-                TcpSendBuffer[27] = timestracture.UTCtimer2>>24;
-                TcpSendBuffer[28] = timestracture.UTCtimer2>>16;
-                TcpSendBuffer[29] = timestracture.UTCtimer2>>8;
-                TcpSendID  = tcpipConnectionSend(TcpConnectID,TcpSendBuffer,92,PNULL,PNULL,PNULL);
-                #ifdef USING_PRINTF
-                    printf("[%d]TcpConnectID:%d \r\n",__LINE__,TcpConnectID);
-                #endif
-                #ifdef USING_PRINTF
-                    printf("[%d]TcpSendID:%d \r\n",__LINE__,TcpSendID);
-                #endif
-                #ifdef USING_PRINTF
-                    printf("[%d]Time1:%x TIme2:%x \r\n",__LINE__,timestracture.UTCtimer1,timestracture.UTCtimer2);
-                #endif
-                for (int i = 0; i < 92; i++)
-                {
-                    #ifdef USING_PRINTF
-                        printf("%x ",TcpSendBuffer[i]);
-                    #endif
-                }
-                #ifdef USING_PRINTF
-                        printf("\r\n ");
-                #endif
-                PROC_NB_STATE_SWITCH(PROCESS_STATE_IDLE);
-                break;
-            }
-            case PROCESS_STATE_SLEEP:
-            {   
-                while(1)
-                {
-                    osDelay(3000);
-                }                                     
-                break;
-            }
-        }
-    }
-}
-/**
-  \fn          process0Init(void)
-  \brief       process0Init function.
-  \return
-*/
-void process0Init(void)
-{
-    osThreadAttr_t task_attr;
-#ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-#endif
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack0, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process0AppTask";
-    task_attr.stack_mem = gProcessTaskStack0;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask0;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process0AppTask, NULL, &task_attr);
-}
-
-void process3Init(void)
-{
-    osThreadAttr_t task_attr;
-
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcessTaskStack3, 0xA5,PROC_TASK_STACK_SIZE);
-    task_attr.name = "Process3AppTask";
-    task_attr.stack_mem = gProcessTaskStack3;
-    task_attr.stack_size = PROC_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
-    task_attr.cb_mem = &gProcessTask3;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(process3AppTask, NULL, &task_attr);
-}
-/**
-  \fn          appInit(void)
-  \brief       appInit function.
-  \return
-*/
-void appInit(void *arg)
-{   
-    process0Init();//任务调度和检测程序
-
-    process3Init();//NB程序
-}
-
-/**
-  \fn          int main_entry(void)
-  \brief       main entry function.
-  \return
-*/
-void main_entry(void) {
-
-    BSP_CommonInit();
-    osKernelInitialize();
-
-    registerAppEntry(appInit, NULL);
-    if (osKernelGetState() == osKernelReady)
-    {
-        osKernelStart();
-    }
-    while(1);
-}

+ 0 - 263
app_socket.c

@@ -1,263 +0,0 @@
-/****************************************************************************
- *
- * Copy right:   2017-, Copyrigths of EigenComm Ltd.
- * File name:    app.c
- * Description:  EC616 socket demo entry source file
- * History:      Rev1.0   2018-10-12
- *
- ****************************************************************************/
-#include "bsp.h"
-#include "bsp_custom.h"
-#include "osasys.h"
-#include "ostask.h"
-#include "queue.h"
-#include "ps_event_callback.h"
-//#include "psproxytask.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 "debug_log.h"
-#include "slpman_ec616.h"
-#include "plat_config.h"
-
-typedef enum {
-    UDP_CLIENT,
-    UDP_SERVER,
-    TCP_CLIENT,
-    TCP_SERVER
-} socketCaseNum;
-
-// Choose which test case to run
-static socketCaseNum testCaseNum = TCP_CLIENT;
-uint8_t socketSlpHandler           = 0xff;
-
-
-// app task static stack and control block
-#define INIT_TASK_STACK_SIZE    (1024)
-#define RINGBUF_READY_FLAG      (0x06)
-#define APP_EVENT_QUEUE_SIZE    (10)
-#define MAX_PACKET_SIZE         (256)
-
-static StaticTask_t             initTask;
-static UINT8                    appTaskStack[INIT_TASK_STACK_SIZE];
-static volatile UINT32          Event;
-static QueueHandle_t            psEventQueueHandle;
-static UINT8                    gImsi[16] = {0};
-static INT32                    sockfd = -1;
-static UINT32                   gCellID = 0;
-
-
-static void sendQueueMsg(UINT32 msgId, UINT32 xTickstoWait)
-{
-    eventCallbackMessage_t *queueMsg = NULL;
-    queueMsg = malloc(sizeof(eventCallbackMessage_t));
-    queueMsg->messageId = msgId;
-    if (psEventQueueHandle)
-    {
-        if (pdTRUE != xQueueSend(psEventQueueHandle, &queueMsg, xTickstoWait))
-        {
-            ECOMM_TRACE(UNILOG_PLA_APP, sendQueueMsg_1, P_ERROR, 0, "xQueueSend error");
-        }
-    }
-}
-
-static INT32 socketRegisterPSUrcCallback(urcID_t eventID, void *param, UINT32 paramLen)
-{
-    CmiSimImsiStr *imsi = NULL;
-    CmiPsCeregInd *cereg = NULL;
-
-    UINT8 rssi = 0, index = 0;
-    NmAtiNetifInfo *netif = NULL;
-
-    switch(eventID)
-    {
-        case NB_URC_ID_SIM_READY:
-        {
-            imsi = (CmiSimImsiStr *)param;
-            memcpy(gImsi, imsi->contents, imsi->length);
-            ECOMM_STRING(UNILOG_PLA_STRING, socketRegisterPSUrcCallback_0, P_INFO, "SIM ready(imsi=%s)", (UINT8 *)imsi->contents);
-            break;
-        }
-        case NB_URC_ID_MM_SIGQ:
-        {
-            rssi = *(UINT8 *)param;
-            ECOMM_TRACE(UNILOG_PLA_APP, socketRegisterPSUrcCallback_1, P_INFO, 1, "RSSI signal=%d", rssi);
-            break;
-        }
-        case NB_URC_ID_PS_BEARER_ACTED:
-        {
-            ECOMM_TRACE(UNILOG_PLA_APP, socketRegisterPSUrcCallback_2, P_INFO, 0, "Default bearer activated");
-            break;
-        }
-        case NB_URC_ID_PS_BEARER_DEACTED:
-        {
-            ECOMM_TRACE(UNILOG_PLA_APP, socketRegisterPSUrcCallback_3, P_INFO, 0, "Default bearer Deactivated");
-            break;
-        }
-        case NB_URC_ID_PS_CEREG_CHANGED:
-        {
-            cereg = (CmiPsCeregInd *)param;
-            gCellID = cereg->celId;
-            ECOMM_TRACE(UNILOG_PLA_APP, pslibPSUrcCallback_4, P_INFO, 4, "URCCallBack:CEREG changed act:%d celId:%d locPresent:%d tac:%d", cereg->act, cereg->celId, cereg->locPresent, cereg->tac);
-            break;
-        }
-        case NB_URC_ID_PS_NETINFO:
-        {
-            netif = (NmAtiNetifInfo *)param;
-            if (netif->netStatus == NM_NETIF_ACTIVATED)
-                sendQueueMsg(QMSG_ID_NW_IP_READY, 0);
-            break;
-        }
-    }
-    return 0;
-}
-
-
-static void testCaseTcpClient()
-{
-    eventCallbackMessage_t *queueItem = NULL;
-    INT32 recvTimeout = 10;
-    INT32  result;
-    UINT32 cliLen;
-    fd_set readfds;
-    struct timeval tv;
-
-    struct addrinfo hints, *server_res;
-
-    CHAR   serverip[] = "39.156.69.79";
-    CHAR serverport[] = "80";
-    memset( &hints, 0, sizeof( hints ) );
-    hints.ai_socktype = SOCK_STREAM;
-    hints.ai_protocol = IPPROTO_TCP;
-
-    while(1){
-        if (xQueueReceive(psEventQueueHandle, &queueItem, portMAX_DELAY))
-        {
-            #ifdef USING_PRINTF
-                printf("[%d]Queue receive->0x%x \r\n",__LINE__,queueItem->messageId);
-            #endif
-
-            switch(queueItem->messageId)
-            {
-                case QMSG_ID_NW_IP_READY:
-                    #ifdef USING_PRINTF
-                        printf("[%d]IP got ready\r\n",__LINE__);
-                    #endif
-                    if (getaddrinfo( serverip, serverport , &hints, &server_res ) != 0 ) 
-                    {
-                        #ifdef USING_PRINTF
-                            printf("[%d]TCP connect unresolved dns\r\n",__LINE__);
-                        #endif
-                    }
-                    sockfd = socket(AF_INET, SOCK_STREAM, 0);
-                    if (sockfd < 0)
-                    {
-                        #ifdef USING_PRINTF
-                            printf("[%d]socket create error\r\n",__LINE__);
-                        #endif
-                    }
-                    if (connect(sockfd, (struct sockaddr *) server_res->ai_addr, server_res->ai_addrlen) < 0 && errno != EINPROGRESS) 
-                    {
-                        #ifdef USING_PRINTF
-                            printf("[%d]socket connect fail\r\n",__LINE__);
-                        #endif
-                        close(sockfd);
-                        break;
-                    }
-                    #ifdef USING_PRINTF
-                            printf("[%d]socket connect success\r\n",__LINE__);
-                    #endif
-
-                    sendQueueMsg(QMSG_ID_SOCK_SENDPKG, 0);
-                    break;
-                case QMSG_ID_NW_IP_NOREACHABLE:
-                case QMSG_ID_NW_IP_SUSPEND:
-                    if (sockfd > 0)
-                    {
-                       close(sockfd);
-                       sockfd = -1;
-                    }
-                    break;
-                case QMSG_ID_SOCK_SENDPKG:
-                    send( sockfd, "hello", 6, 0 );
-                    osDelay(2000);
-                    #ifdef USING_PRINTF
-                            printf("[%d]socket send success\r\n",__LINE__);
-                    #endif
-                    sendQueueMsg(QMSG_ID_SOCK_SENDPKG, 0);
-                    break;
-            }
-            free(queueItem);
-        }
-        }
-
-
-}
-
-static void socketAppTask(void *arg)
-{
-    psEventQueueHandle = xQueueCreate(APP_EVENT_QUEUE_SIZE, sizeof(eventCallbackMessage_t*));
-    if (psEventQueueHandle == NULL)
-    {
-        ECOMM_TRACE(UNILOG_PLA_APP, socketAppTask_1, P_ERROR, 0, "psEventQueue create error!");
-        return;
-    }
-
-    switch(testCaseNum)
-    {
-        case TCP_CLIENT:
-            testCaseTcpClient();
-            break;
-        case TCP_SERVER:
-            break;
-    }
-}
-
-static void appInit(void *arg)
-{
-    osThreadAttr_t task_attr;
-
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-
-    slpManApplyPlatVoteHandle("SOCKET",&socketSlpHandler);
-    registerPSEventCallback(NB_GROUP_ALL_MASK, socketRegisterPSUrcCallback);
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(appTaskStack, 0xA5,INIT_TASK_STACK_SIZE);
-    task_attr.name = "app";
-    task_attr.stack_mem = appTaskStack;
-    task_attr.stack_size = INIT_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;
-    task_attr.cb_mem = &initTask;//task control block
-    task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
-
-    osThreadNew(socketAppTask, NULL, &task_attr);
-    
-    //abupfotaInit();
-}
-
-/**
-  \fn          int main_entry(void)
-  \brief       main entry function.
-  \return
-*/
-void main_entry(void) {
-
-    BSP_CommonInit();
-    osKernelInitialize();
-    registerAppEntry(appInit, NULL);
-    if (osKernelGetState() == osKernelReady)
-    {
-        osKernelStart();
-    }
-    while(1);
-
-}
-

+ 0 - 216
bsp_custom.c

@@ -1,216 +0,0 @@
-/****************************************************************************
- *
- * Copy right:   2018 Copyrigths of EigenComm Ltd.
- * File name:    bsp_custom.c
- * Description:
- * History:
- *
- ****************************************************************************/
-#include <stdio.h>
-#include <stdarg.h>
-#include "clock_ec616.h"
-#include "bsp_custom.h"
-#include "slpman_ec616.h"
-#include "plat_config.h"
-#include "debug_log.h"
-
-void GPR_SetUartClk(void)
-{
-#if 0
-	GPR_ClockDisable(GPR_UART0FuncClk);
-	GPR_SetClockSrc(GPR_UART0FuncClk, GPR_UART0ClkSel_26M);
-	GPR_ClockEnable(GPR_UART0FuncClk);
-	GPR_SWReset(GPR_ResetUART0Func);
-#else
-	GPR_ClockDisable(GPR_UART1FuncClk);
-	GPR_SetClockSrc(GPR_UART1FuncClk, GPR_UART1ClkSel_26M);
-	GPR_ClockEnable(GPR_UART1FuncClk);
-	GPR_SWReset(GPR_ResetUART1Func);
-#endif
-}
-
-extern ARM_DRIVER_USART Driver_USART0;
-extern ARM_DRIVER_USART Driver_USART1;
-
-/*
- *  set printf uart port
- *  Parameter:      port: for printf
- */
-static void SetPrintUart(usart_port_t port)
-{
-    if(port == PORT_USART_0)
-    {
-#if (RTE_UART0)
-        UsartPrintHandle = &CREATE_SYMBOL(Driver_USART, 0);
-        GPR_ClockDisable(GPR_UART0FuncClk);
-        GPR_SetClockSrc(GPR_UART0FuncClk, GPR_UART0ClkSel_26M);
-        GPR_ClockEnable(GPR_UART0FuncClk);
-        GPR_SWReset(GPR_ResetUART0Func);
-#endif
-    }
-    else if(port == PORT_USART_1)
-    {
-#if (RTE_UART1)
-        UsartPrintHandle = &CREATE_SYMBOL(Driver_USART, 1);
-        GPR_ClockDisable(GPR_UART1FuncClk);
-        GPR_SetClockSrc(GPR_UART1FuncClk, GPR_UART1ClkSel_26M);
-        GPR_ClockEnable(GPR_UART1FuncClk);
-        GPR_SWReset(GPR_ResetUART1Func);
-#endif
-    }
-
-    if(UsartPrintHandle == NULL)
-        return;
-
-    UsartPrintHandle->Initialize(NULL);
-    UsartPrintHandle->PowerControl(ARM_POWER_FULL);
-    UsartPrintHandle->Control(ARM_USART_MODE_ASYNCHRONOUS | ARM_USART_DATA_BITS_8 |
-                        ARM_USART_PARITY_NONE       | ARM_USART_STOP_BITS_1 |
-                        ARM_USART_FLOW_CONTROL_NONE, 115200ul);
-}
-
-#if LOW_POWER_AT_TEST
-slpManSlpState_t CheckUsrdefSlpStatus(void)
-{
-    slpManSlpState_t status = SLP_HIB_STATE;
-    if((slpManGetWakeupPinValue() & (0x1<<1)) == 0)         // pad1 value is low
-        status = SLP_IDLE_STATE;
-    else
-        status = SLP_HIB_STATE;
-
-    return status;
-}
-
-#endif
-
-static void PMU_WakeupPadInit(void)
-{
-    const padWakeupSettings_t cfg =
-    {
-        false, true,             // group0 posedge, negedge
-        false, false,             // group1 posedge, negedge
-        false, false,             // group2 posedge, negedge
-    };
-
-    slpManSetWakeupPad(cfg);
-}
-
-/*
- *  custom board related init
- *  Parameter:   none
- *  note: this function shall be called in OS task context for dependency of reading configure file
- *        which is implemented based on file system
- */
-void BSP_CustomInit(void)
-{
-    extern void mpu_init(void);
-    mpu_init();
-
-    GPR_SetUartClk();
-
-#if LOW_POWER_AT_TEST
-    slpManRegisterUsrSlpDepthCb(CheckUsrdefSlpStatus);
-#endif
-
-    plat_config_raw_flash_t* rawFlashPlatConfig;
-
-    BSP_LoadPlatConfigFromRawFlash();
-    rawFlashPlatConfig = BSP_GetRawFlashPlatConfig();
-#ifdef USING_PRINTF
-	SetPrintUart(PORT_USART_0);
-#else
-    if(rawFlashPlatConfig && (rawFlashPlatConfig->logControl != 0 ))
-    {
-        SetUnilogUart(PORT_USART_0, rawFlashPlatConfig->uartBaudRate, true);
-        uniLogInitStart(UART_0_FOR_UNILOG);
-        ECOMM_STRING(UNILOG_PLA_STRING, build_info, P_SIG, "%s", getBuildInfo());
-    }
-#endif
-
-	slpManGetPMUSettings();				
-
-	PMU_WakeupPadInit();
-	NVIC_DisableIRQ(PadWakeup0_IRQn);
-
-	slpManStartWaitATTimer();
-
-	CanSPIHandler(NULL,ARM_SPI_CPOL0_CPHA0,8,200000U);
-
-	slpManAONIOPowerOn();
-	PowerPinConfig(AON_IO);
-	PowerPinConfig(NORMAL_IO);
-	posGGAReset();
-	NetSocDisplay(LED_SOC_0,LED_TURN_ON);
-	NetSocDisplay(LED_SOC_1,LED_TURN_ON);
-	NetSocDisplay(LED_SOC_2,LED_TURN_ON);
-	NetSocDisplay(LED_SOC_3,LED_TURN_ON);
-	FaultDisplay(LED_TURN_ON);
-}
-
-/**
-  \fn        void NVIC_WakeupIntHandler(void)
-  \brief      NVIC wakeup interrupt handler
-  \param     void
- */
-void Pad0_WakeupIntHandler(void)
-{
-    if(slpManExtIntPreProcess(PadWakeup0_IRQn)==false)
-        return;
-#ifdef USING_PRINTF
-	printf("[%d]PadWakeup0_IRQn\r\n",__LINE__);
-#else	
-    ECOMM_TRACE(UNILOG_PLA_APP, pad0_Wk, P_SIG, 0, "PadWakeup0_IRQn");
-#endif
-	//CanTiggerEvt(1);
-}
-
-void Pad1_WakeupIntHandler(void)
-{
-    if(slpManExtIntPreProcess(PadWakeup1_IRQn)==false)
-        return;
-}
-
-void Pad2_WakeupIntHandler(void)
-{
-    if(slpManExtIntPreProcess(PadWakeup2_IRQn)==false)
-        return;
-
-}
-
-void Pad3_WakeupIntHandler(void)
-{
-    if(slpManExtIntPreProcess(PadWakeup3_IRQn)==false)
-        return;
-
-    // add custom code below //
-#ifdef USING_PRINTF
-	printf("[%d]PadWakeup3_IRQn\r\n",__LINE__);
-#else	
-    ECOMM_TRACE(UNILOG_PLA_APP, pad3_Wk, P_SIG, 0, "PadWakeup3_IRQn");
-#endif
-
- 	
-
-
-
-}
-
-void Pad4_WakeupIntHandler(void)
-{
-    if(slpManExtIntPreProcess(PadWakeup4_IRQn)==false)
-        return;
-    // add custom code below //
-#ifdef USING_PRINTF
-	printf("[%d]PadWakeup3_IRQn\r\n",__LINE__);
-#else	
-
-    ECOMM_TRACE(UNILOG_PLA_APP, pad4_Wk, P_SIG, 0, "PadWakeup4_IRQn");
-#endif
-
-}
-
-void Pad5_WakeupIntHandler(void)
-{
-    if(slpManExtIntPreProcess(PadWakeup5_IRQn)==false)
-        return;
-}

+ 0 - 1227
cisAsynEntry.c

@@ -1,1227 +0,0 @@
-/****************************************************************************
- *
- * Copy right:   2017-, Copyrigths of EigenComm Ltd.
- * File name:    cisAsynEntry.c
- * Description:  EC616 onenet cis async entry source file
- * History:      Rev1.0   2018-10-12
- *
- ****************************************************************************/
-#include <cis_if_sys.h>
-#include <cis_list.h>
-#include "cisAsynEntry.h"
-#include "osasys.h"
-#include "task.h"
-#if defined CHIP_EC616 || defined CHIP_EC616_Z0
-#include "slpman_ec616.h"
-#include "Flash_ec616_rt.h"
-#elif defined CHIP_EC617
-#include "slpman_ec617.h"
-#include "Flash_ec617_rt.h"
-#endif
-#include "lfs_port.h"
-#include "debug_log.h"
-
-//#define DEBUG_SLEEP_BACKUP
-#define USE_PLAIN_BOOTSTRAP         (0)
-#define ONENET_TASK_STACK_SIZE      (1024*3)
-#define CIS_ENABLE_CONTEXT_RESTORE  (1)
-
-
-#if 0
-//authcode:EC616 psk:EIGENCOMM 183.230.40.39:5684
-static const uint8_t config_hex[] = {
-    0x13, 0x00, 0x53,
-    0xf1, 0x00, 0x03,
-    0xf2, 0x00, 0x45,
-    0x05, 0x00 /*mtu*/, 0x11 /*Link & bind type*/, 0xC0 /*BS DTLS ENABLED*/,
-    0x00, 0x05 /*apn length*/, 0x43, 0x4d, 0x49, 0x4f, 0x54 /*apn: CMIOT*/,
-    0x00, 0x00 /*username length*/, /*username*/
-    0x00, 0x00 /*password length*/, /*password*/
-    0x00, 0x12 /*host length*/, 0x31, 0x38, 0x33, 0x2e, 0x32, 0x33, 0x30, 0x2e,
-    0x34, 0x30, 0x2e, 0x33, 0x39, 0x3a, 0x35, 0x36, 0x38, 0x34 /*host: 183.230.40.39:5684*/,
-    0x00, 0x1D /*userdata length*/, 
-    0x41, 0x75, 0x74, 0x68, 0x43, 0x6f, 0x64, 0x65, 
-    0x3a, 0x45, 0x43, 0x36, 0x31, 0x36, 0x3b, 0x50, 
-    0x53, 0x4b, 0x3a, 0x45, 0x49, 0x47, 0x45, 0x4E, 
-    0x43, 0x4F, 0x4D, 0x4D,0x3b /*userdata: AuthCode:EC616;PSK:EIGENCOMM;*/,
-    0xf3, 0x00, 0x08,0xe4 /*log config*/, 0x00, 0xc8 /*LogBufferSize: 200*/,
-    0x00, 0x00 /*userdata length*//*userdata*/
-    
-};
-//authcode:EC616 psk:EIGENCOMM 183.230.40.40:5683 
-static const uint8_t config_hex[] = {
-    0x13, 0x00, 0x53,
-    0xf1, 0x00, 0x03,
-    0xf2, 0x00, 0x45,
-    0x05, 0x00 /*mtu*/, 0x11 /*Link & bind type*/, 0x00 /*BS DTLS DISABLED*/,
-    0x00, 0x05 /*apn length*/, 0x43, 0x4d, 0x49, 0x4f, 0x54 /*apn: CMIOT*/,
-    0x00, 0x00 /*username length*/, /*username*/
-    0x00, 0x00 /*password length*/, /*password*/
-    0x00, 0x12 /*host length*/,
-    0x31, 0x38, 0x33, 0x2e, 0x32, 0x33, 0x30, 0x2e,
-    0x34, 0x30, 0x2e, 0x34, 0x30, 0x3a, 0x35, 0x36, 0x38, 0x33 /*host: 183.230.40.40:5683*/,
-    0x00, 0x1D /*userdata length*/, 0x41, 0x75, 0x74, 0x68, 0x43, 0x6f, 0x64, 0x65, 
-    0x3a, 0x45, 0x43, 0x36, 0x31, 0x36, 0x3b, 0x50, 
-    0x53, 0x4b, 0x3a, 0x45, 0x49, 0x47, 0x45, 0x4E,
-    0x43, 0x4F, 0x4D, 0x4D,0x3b /*userdata: AuthCode:EC616;PSK:EIGENCOMM;*/,
-    0xf3, 0x00, 0x08,0xe4 /*log config*/, 0x00, 0xc8 /*LogBufferSize: 200*/,
-    0x00, 0x00 /*userdata length*//*userdata*/   
-};
-	
-#endif
-
-//authcode: psk: 183.230.40.39:5683 enable bootstrap
-static const uint8_t config_hex[] = {
-    0x13, 0x00, 0x45,
-    0xf1, 0x00, 0x03,
-    0xf2, 0x00, 0x37,
-    0x05, 0x00 /*mtu*/, 0x11 /*Link & bind type*/, 0x80 /*BS ENABLE DTLS DISABLED*/,
-    0x00, 0x05 /*apn length*/, 0x43, 0x4d, 0x49, 0x4f, 0x54 /*apn: CMIOT*/,
-    0x00, 0x00 /*username length*/, /*username*/
-    0x00, 0x00 /*password length*/, /*password*/
-    0x00, 0x12 /*host length*/,
-    0x31, 0x38, 0x33, 0x2e, 0x32, 0x33, 0x30, 0x2e,
-    0x34, 0x30, 0x2e, 0x33, 0x39, 0x3a, 0x35, 0x36, 0x38, 0x33 /*host: 183.230.40.40:5683*/,
-    0x00, 0x0f /*userdata length*/, 0x41, 0x75, 0x74, 0x68, 0x43, 0x6f, 0x64, 0x65, 
-    0x3a, 0x3b, 0x50, 0x53, 0x4b, 0x3a, 0x3b/*userdata: AuthCode:;PSK:;*/,
-    0xf3, 0x00, 0x08,0xe4 /*log config*/, 0x00, 0xc8 /*LogBufferSize: 200*/,
-    0x00, 0x00 /*userdata length*//*userdata*/   
-};
-	
-
-static StaticTask_t              onenetTask;
-static osThreadId_t              onenetTaskId = NULL;
-static uint8_t                   onenetTaskStack[ONENET_TASK_STACK_SIZE];
-static void*                     gCisContext = NULL;
-static bool                      g_shutdown = false;
-static cis_time_t                g_lifetimeLast = 0;
-static cis_time_t                g_lifetime = 0;
-static cis_time_t                g_notifyLast = 0;
-static bool                      gNotifyOngoing = false;
-static bool                      gNotifyOnceSuccess = false;
-static struct st_callback_info*  g_callbackList = NULL;
-static struct st_observe_info*   g_observeList  = NULL;
-static st_sample_object          g_objectList[SAMPLE_OBJECT_MAX];
-static st_instance_a             g_instList_a[SAMPLE_A_INSTANCE_COUNT];
-static CHAR *defaultLocalPort    = "40962";
-static onenet_context_t          gOnenetContextRunning;
-extern observed_backup_t         g_observed_backup[MAX_OBSERVED_COUNT];
-
-//////////////////////////////////////////////////////////////////////////
-//private funcation;
-static void prvObserveNotify(void* context,cis_uri_t* uri,cis_mid_t mid)
-{
-    uint8_t index;
-    st_sample_object* object = NULL;
-    cis_data_t value;
-    for (index = 0;index < SAMPLE_OBJECT_MAX;index++)
-    {
-        if(g_objectList[index].oid ==  uri->objectId){
-            object = &g_objectList[index];
-        }
-    }
-
-    if(object == NULL){
-        ECOMM_TRACE(UNILOG_PLA_APP, prv_observeNotify_0, P_ERROR, 0, "prv_observeNotify return");
-        return;
-    }
-    ECOMM_TRACE(UNILOG_PLA_APP, prv_observeNotify_1, P_INFO, 0, "prv_observeNotify called");
-
-    if(!CIS_URI_IS_SET_INSTANCE(uri) && !CIS_URI_IS_SET_RESOURCE(uri))
-    {
-        switch(uri->objectId)
-        {
-            case SAMPLE_OID_A:
-            {
-                for(index=0;index<SAMPLE_A_INSTANCE_COUNT;index++)
-                {                   
-                    st_instance_a *inst = &g_instList_a[index];
-                    if(inst != NULL &&  inst->enabled == true)
-                    {
-                        cis_data_t tmpdata[4];
-                        tmpdata[0].type = cis_data_type_integer;
-                        tmpdata[0].value.asInteger = inst->instance.intValue;
-                        uri->instanceId = inst->instId;
-                        uri->resourceId = attributeA_intValue;
-                        cis_uri_update(uri);
-                        cis_notify_ec(context,uri,&tmpdata[0],mid,CIS_NOTIFY_CONTINUE,true, PS_SOCK_RAI_NO_INFO);
-
-                        tmpdata[2].type = cis_data_type_bool;
-                        tmpdata[2].value.asBoolean = inst->instance.boolValue;
-                        uri->resourceId = attributeA_boolValue;
-                        uri->instanceId = inst->instId;
-                        cis_uri_update(uri);
-                        cis_notify_ec(context,uri,&tmpdata[2],mid,CIS_NOTIFY_CONTINUE,true, PS_SOCK_RAI_NO_INFO);
-
-                        tmpdata[3].type = cis_data_type_string;
-                        tmpdata[3].asBuffer.length = strlen(inst->instance.strValue);
-                        tmpdata[3].asBuffer.buffer = (uint8_t*)(inst->instance.strValue);
-                        uri->resourceId = attributeA_stringValue;
-                        uri->instanceId = inst->instId;
-                        cis_uri_update(uri);
-                        cis_notify_ec(context,uri,&tmpdata[3],mid,CIS_NOTIFY_CONTENT,true, PS_SOCK_RAI_NO_INFO);
-                    }
-                }
-            }
-            break;
-        }
-    }else if(CIS_URI_IS_SET_INSTANCE(uri))
-    {
-        switch(object->oid)
-        {
-            case SAMPLE_OID_A:
-            {
-                if(uri->instanceId > SAMPLE_A_INSTANCE_COUNT){
-                    return;
-                }
-                st_instance_a *inst = &g_instList_a[uri->instanceId];
-                if(inst == NULL || inst->enabled == false){
-                    return;
-                }
-
-                if(CIS_URI_IS_SET_RESOURCE(uri)){
-                    if(uri->resourceId == attributeA_intValue)
-                    {
-                        value.type = cis_data_type_integer;
-                        value.value.asInteger = inst->instance.intValue;
-                    }
-                    else if(uri->resourceId == attributeA_boolValue)
-                    {
-                        value.type = cis_data_type_bool;
-                        value.value.asBoolean = inst->instance.boolValue;
-                    }
-                    else if(uri->resourceId == attributeA_stringValue)
-                    {
-                        value.type = cis_data_type_string;
-                        value.asBuffer.length = strlen(inst->instance.strValue);
-                        value.asBuffer.buffer = (uint8_t*)(inst->instance.strValue);
-                    }else{
-                        return;
-                    }
-
-                    cis_notify_ec(context,uri,&value,mid,CIS_NOTIFY_CONTENT,true, PS_SOCK_RAI_NO_INFO);
-
-                }else{
-                    cis_data_t tmpdata[4];
-
-                    tmpdata[0].type = cis_data_type_integer;
-                    tmpdata[0].value.asInteger = inst->instance.intValue;
-                    uri->resourceId = attributeA_intValue;
-                    cis_uri_update(uri);
-                    cis_notify_ec(context,uri,&tmpdata[0],mid,CIS_NOTIFY_CONTINUE,true, PS_SOCK_RAI_NO_INFO);
-
-
-                    tmpdata[2].type = cis_data_type_bool;
-                    tmpdata[2].value.asBoolean = inst->instance.boolValue;
-                    uri->resourceId = attributeA_boolValue;
-                    cis_uri_update(uri);
-                    cis_notify_ec(context,uri,&tmpdata[2],mid,CIS_NOTIFY_CONTINUE,true, PS_SOCK_RAI_NO_INFO);
-
-                    tmpdata[3].type = cis_data_type_string;
-                    tmpdata[3].asBuffer.length = strlen(inst->instance.strValue);
-                    tmpdata[3].asBuffer.buffer = (uint8_t*)(inst->instance.strValue);
-                    uri->resourceId = attributeA_stringValue;
-                    cis_uri_update(uri);
-                    cis_notify_ec(context,uri,&tmpdata[3],mid,CIS_NOTIFY_CONTENT,true, PS_SOCK_RAI_NO_INFO);
-                }
-            }
-            break;
-        }
-    }
-}
-
-static void prvReadResponse(void* context,cis_uri_t* uri,cis_mid_t mid)
-{
-    uint8_t index;
-    st_sample_object* object = NULL;
-    cis_data_t value;
-    for (index = 0;index < SAMPLE_OBJECT_MAX;index++)
-    {
-        if(g_objectList[index].oid ==  uri->objectId){
-            object = &g_objectList[index];
-        }
-    }
-
-    if(object == NULL){
-        return;
-    }
-
-    if(!CIS_URI_IS_SET_INSTANCE(uri) && !CIS_URI_IS_SET_RESOURCE(uri)) // one object
-    {
-        switch(uri->objectId)
-        {
-            case SAMPLE_OID_A:
-            {
-                for(index=0;index<SAMPLE_A_INSTANCE_COUNT;index++)
-                {                   
-                    st_instance_a *inst = &g_instList_a[index];
-                    if(inst != NULL &&  inst->enabled == true)
-                    {
-                        cis_data_t tmpdata[4];
-                        tmpdata[0].type = cis_data_type_integer;
-                        tmpdata[0].value.asInteger = inst->instance.intValue;
-                        uri->instanceId = inst->instId;
-                        uri->resourceId = attributeA_intValue;
-                        cis_uri_update(uri);
-                        cis_response(context,uri,&tmpdata[0],mid,CIS_RESPONSE_CONTINUE, PS_SOCK_RAI_NO_INFO);
-
-
-                        tmpdata[2].type = cis_data_type_bool;
-                        tmpdata[2].value.asBoolean = inst->instance.boolValue;
-                        uri->resourceId = attributeA_boolValue;
-                        uri->instanceId = inst->instId;
-                        cis_uri_update(uri);
-                        cis_response(context,uri,&tmpdata[2],mid,CIS_RESPONSE_CONTINUE, PS_SOCK_RAI_NO_INFO);
-
-                        tmpdata[3].type = cis_data_type_string;
-                        tmpdata[3].asBuffer.length = strlen(inst->instance.strValue);
-                        tmpdata[3].asBuffer.buffer = (uint8_t*)strdup(inst->instance.strValue);
-                        uri->resourceId = attributeA_stringValue;
-                        uri->instanceId = inst->instId;
-                        cis_uri_update(uri);
-                        cis_response(context,uri,&tmpdata[3],mid,CIS_RESPONSE_CONTINUE, PS_SOCK_RAI_NO_INFO);
-                    }
-                }
-            }
-            break;
-        }
-        cis_response(context,NULL,NULL,mid,CIS_RESPONSE_READ, PS_SOCK_RAI_NO_INFO);
-
-    }else
-    {
-        switch(object->oid)
-        {
-            case SAMPLE_OID_A:
-            {
-                if(uri->instanceId > SAMPLE_A_INSTANCE_COUNT){
-                    return;
-                }
-                st_instance_a *inst = &g_instList_a[uri->instanceId];
-                if(inst == NULL || inst->enabled == false){
-                    return;
-                }
-
-                if(CIS_URI_IS_SET_RESOURCE(uri)){
-                    if(uri->resourceId == attributeA_intValue)
-                    {
-                        value.type = cis_data_type_integer;
-                        value.value.asInteger = inst->instance.intValue;
-                    }
-                    else if(uri->resourceId == attributeA_boolValue)
-                    {
-                        value.type = cis_data_type_bool;
-                        value.value.asBoolean = inst->instance.boolValue;
-                    }
-                    else if(uri->resourceId == attributeA_stringValue)
-                    {
-                        value.type = cis_data_type_string;
-                        value.asBuffer.length = strlen(inst->instance.strValue);
-                        value.asBuffer.buffer = (uint8_t*)strdup(inst->instance.strValue);
-                    }else{
-                        return;
-                    }
-
-                    cis_response(context,uri,&value,mid,CIS_RESPONSE_READ, PS_SOCK_RAI_NO_INFO);
-                }else{
-                    cis_data_t tmpdata[4];
-
-                    tmpdata[0].type = cis_data_type_integer;
-                    tmpdata[0].value.asInteger = inst->instance.intValue;
-                    uri->resourceId = attributeA_intValue;
-                    cis_uri_update(uri);
-                    cis_response(context,uri,&tmpdata[0],mid,CIS_RESPONSE_CONTINUE, PS_SOCK_RAI_NO_INFO);
-
-                    tmpdata[2].type = cis_data_type_bool;
-                    tmpdata[2].value.asBoolean = inst->instance.boolValue;
-                    uri->resourceId = attributeA_boolValue;
-                    cis_uri_update(uri);
-                    cis_response(context,uri,&tmpdata[2],mid,CIS_RESPONSE_CONTINUE, PS_SOCK_RAI_NO_INFO);
-
-                    tmpdata[3].type = cis_data_type_string;
-                    tmpdata[3].asBuffer.length = strlen(inst->instance.strValue);
-                    tmpdata[3].asBuffer.buffer = (uint8_t*)strdup(inst->instance.strValue);
-                    uri->resourceId = attributeA_stringValue;
-                    cis_uri_update(uri);
-                    cis_response(context,uri,&tmpdata[3],mid,CIS_RESPONSE_READ, PS_SOCK_RAI_NO_INFO);
-                }
-            }
-            break;
-        }
-    }
-}
-
-
-static void prvDiscoverResponse(void* context,cis_uri_t* uri,cis_mid_t mid)
-{
-    uint8_t index;
-    st_sample_object* object = NULL;
-
-    for (index = 0;index < SAMPLE_OBJECT_MAX;index++)
-    {
-        if(g_objectList[index].oid ==  uri->objectId){
-            object = &g_objectList[index];
-        }
-    }
-
-    if(object == NULL){
-        return;
-    }
-
-
-    switch(uri->objectId)
-    {
-        case SAMPLE_OID_A:
-        {
-            uri->objectId = SAMPLE_OID_A;
-            uri->instanceId = 0;
-            uri->resourceId = attributeA_intValue;
-            cis_uri_update(uri);
-            cis_response(context,uri,NULL,mid,CIS_RESPONSE_CONTINUE, PS_SOCK_RAI_NO_INFO);
-
-            uri->objectId = SAMPLE_OID_A;
-            uri->instanceId = 0;
-            uri->resourceId = attributeA_boolValue;
-            cis_uri_update(uri);
-            cis_response(context,uri,NULL,mid,CIS_RESPONSE_CONTINUE, PS_SOCK_RAI_NO_INFO);
-
-            uri->objectId = SAMPLE_OID_A;
-            uri->instanceId = 0;
-            uri->resourceId = attributeA_stringValue;
-            cis_uri_update(uri);
-            cis_response(context,uri,NULL,mid,CIS_RESPONSE_CONTINUE, PS_SOCK_RAI_NO_INFO);
-
-        }
-        break;
-    }
-    cis_response(context,NULL,NULL,mid,CIS_RESPONSE_DISCOVER, PS_SOCK_RAI_NO_INFO);
-}
-
-
-static void prvWriteResponse(void* context,cis_uri_t* uri,const cis_data_t* value,cis_attrcount_t count,cis_mid_t mid)
-{
-
-    uint8_t index;
-    st_sample_object* object = NULL;
-    
-
-    if(!CIS_URI_IS_SET_INSTANCE(uri))
-    {
-        return;
-    }
-
-    for (index = 0;index < SAMPLE_OBJECT_MAX;index++)
-    {
-        if(g_objectList[index].oid ==  uri->objectId){
-            object = &g_objectList[index];
-        }
-    }
-
-    if(object == NULL){
-        return;
-    }
-
-    switch(object->oid)
-    {
-        case SAMPLE_OID_A:
-        {
-            if(uri->instanceId > SAMPLE_A_INSTANCE_COUNT){
-                return;
-            }
-            st_instance_a *inst = &g_instList_a[uri->instanceId];
-            if(inst == NULL || inst->enabled == false){
-                return;
-            }
-
-            for (int i=0;i<count;i++)
-            {
-                ECOMM_TRACE(UNILOG_PLA_APP, prvWriteResponse_1, P_INFO, 3, "prvWriteResponse:write %d/%d/%d", uri->objectId,uri->instanceId,value[i].id);
-                switch(value[i].id)
-                {
-                case attributeA_intValue:
-                    {
-                        if(value[i].type == cis_data_type_string){
-                            inst->instance.intValue = atoi((const char*)value[i].asBuffer.buffer);
-                        }else{
-                            inst->instance.intValue = value[i].value.asInteger;
-                        }
-                    }
-                    break;
-                case attributeA_boolValue:
-                    {
-                        if(value[i].type == cis_data_type_string){
-                            inst->instance.boolValue = atoi((const char*)value[i].asBuffer.buffer);
-                        }else{
-                            inst->instance.boolValue = value[i].value.asBoolean;
-                        }
-                    }
-                    break;
-                case  attributeA_stringValue:
-                    {
-                        memset(inst->instance.strValue,0,sizeof(inst->instance.strValue));
-                        strncpy(inst->instance.strValue,(char*)value[i].asBuffer.buffer,value[i].asBuffer.length);
-                    }
-                    break;
-                }
-            }
-        }
-        break;
-    }
-
-    cis_response(context,NULL,NULL,mid,CIS_RESPONSE_WRITE, PS_SOCK_RAI_NO_INFO);
-}
-
-
-static void prvExecResponse(void* context,cis_uri_t* uri,const uint8_t* value,uint32_t length,cis_mid_t mid)
-{
-
-    uint8_t index;
-    st_sample_object* object = NULL;
-
-    for (index = 0;index < SAMPLE_OBJECT_MAX;index++)
-    {
-        if(g_objectList[index].oid ==  uri->objectId){
-            object = &g_objectList[index];
-        }
-    }
-
-    if(object == NULL){
-        return;
-    }
-
-
-    switch(object->oid)
-    {
-    case SAMPLE_OID_A:
-        {
-            if(uri->instanceId > SAMPLE_A_INSTANCE_COUNT){
-                return;
-            }
-            st_instance_a *inst = &g_instList_a[uri->instanceId];
-            if(inst == NULL || inst->enabled == false){
-                return;
-            }
-
-            if(uri->resourceId == actionA_1)
-            {
-                /*
-                *\call action;
-                */
-                ECOMM_TRACE(UNILOG_PLA_APP, prvExecResponse_1, P_INFO, 0, "exec actionA_action");
-                cis_response(context,NULL,NULL,mid,CIS_RESPONSE_EXECUTE, PS_SOCK_RAI_NO_INFO);
-            }else{
-                return;
-            }
-        }
-        break;
-    }
-};
-
-
-static void prvParamsResponse (void* context, cis_uri_t* uri, cis_observe_attr_t parameters, cis_mid_t mid)
-{
-    uint8_t index;
-    st_sample_object* object = NULL;
-
-    if(CIS_URI_IS_SET_RESOURCE(uri)){
-        ECOMM_TRACE(UNILOG_PLA_APP, prvParamsResponse_1, P_INFO, 3, "prvParamsResponse (%d/%d/%d)", uri->objectId,uri->instanceId,uri->resourceId);
-    }
-
-    if(!CIS_URI_IS_SET_INSTANCE(uri))
-    {
-        return;
-    }
-
-    for (index = 0;index < SAMPLE_OBJECT_MAX;index++)
-    {
-        if(g_objectList[index].oid ==  uri->objectId){
-            object = &g_objectList[index];
-        }
-    }
-
-    if(object == NULL){
-        return;
-    }
-
-    /*set parameter to observe resource*/
-    ECOMM_TRACE(UNILOG_PLA_APP, prvParamsResponse_2, P_INFO, 2, "prvParamsResponse set:%x,clr:%x", parameters.toSet, parameters.toClear);
-    ECOMM_TRACE(UNILOG_PLA_APP, prvParamsResponse_3, P_INFO, 5, "prvParamsResponse min:%d,max:%d,gt:%f,lt:%f,st:%f", parameters.minPeriod,parameters.maxPeriod,parameters.greaterThan,parameters.lessThan,parameters.step);
-
-    cis_response(context,NULL,NULL,mid,CIS_RESPONSE_OBSERVE_PARAMS, PS_SOCK_RAI_NO_INFO);
-
-}
-
-static cis_data_t* prvDataDup(const cis_data_t* value,cis_attrcount_t attrcount)
-{
-    cis_attrcount_t index;
-    cis_data_t* newData;
-    newData =(cis_data_t*)cissys_malloc(attrcount * sizeof(cis_data_t));
-    if(newData == NULL)
-    {
-        return NULL;
-    }
-    for (index =0;index < attrcount;index++)
-    {
-        newData[index].id = value[index].id;
-        newData[index].type = value[index].type;
-        newData[index].asBuffer.length = value[index].asBuffer.length;
-        newData[index].asBuffer.buffer = (uint8_t*)cissys_malloc(value[index].asBuffer.length);
-        memcpy(newData[index].asBuffer.buffer,value[index].asBuffer.buffer,value[index].asBuffer.length);
-        memcpy(&newData[index].value.asInteger,&value[index].value.asInteger,sizeof(newData[index].value));
-    }
-    return newData;
-}
-
-static void prvUpdateObserveContext()
-{
-    struct st_observe_info* node = g_observeList;
-    uint8_t i = 0;
-    while(node != NULL)
-    {
-        ECOMM_TRACE(UNILOG_PLA_APP, prvUpdateObserveContext_0, P_INFO, 1, "prvUpdateObserveContext mid=%d", node->mid);
-        node = node->next;
-        i++;
-    }
-    gOnenetContextRunning.observeObjNum = i;
-    
- #ifdef DEBUG_SLEEP_BACKUP
-    printf("prvUpdateObserveContext:");
-    for(int j= 0; j < sizeof(observed_backup_t); j ++)
-        printf("%d ", ((UINT8*)&(g_observed_backup[0]))[j]);
-    printf("\n");
- #endif
- 
-    memcpy((uint8_t *)&(gOnenetContextRunning.gObservedBackup[0]), &(g_observed_backup[0]), MAX_OBSERVED_COUNT*sizeof(observed_backup_t));
-
-    if(BSP_QSPI_Erase_Safe(APP_BACKUP_NONXIP_ADDR, APP_BACKUP_SIZE) != QSPI_OK) //erase
-    {
-        ECOMM_TRACE(UNILOG_PLA_APP, prvUpdateObserveContext_1, P_ERROR, 0, "erase flash error!!!");
-    }
-    ECOMM_TRACE(UNILOG_PLA_APP, prvUpdateObserveContext_2, P_INFO, 0, "prvUpdateObserveContext BSP_QSPI_Write_Safe");
-    if(BSP_QSPI_Write_Safe((uint8_t *)&gOnenetContextRunning, APP_BACKUP_NONXIP_ADDR, sizeof(onenet_context_t))!=QSPI_OK) //programe
-    {
-        ECOMM_TRACE(UNILOG_PLA_APP, prvUpdateObserveContext_3, P_ERROR, 0, "write flash error!!!");
-    }
-}
-void prvMakeUserdata()
-{
-    int i = 0;
-    cis_instcount_t instIndex;
-    cis_instcount_t instCount;
-    for (i= 0;i < SAMPLE_OBJECT_MAX; i++)
-    {
-        st_sample_object* obj = &g_objectList[i];
-        switch(i){
-            case 0:
-            {
-                obj->oid = SAMPLE_OID_A;
-                obj->instBitmap = SAMPLE_A_INSTANCE_BITMAP;
-                instCount = SAMPLE_A_INSTANCE_COUNT;
-                for (instIndex = 0;instIndex < instCount;instIndex++)
-                {
-                    if(obj->instBitmap[instIndex] != '1'){
-                        g_instList_a[instIndex].instId = instIndex;
-                        g_instList_a[instIndex].enabled = false;
-                    }
-                    else
-                    {
-                        g_instList_a[instIndex].instId = instIndex;
-                        g_instList_a[instIndex].enabled = true;
-
-                        g_instList_a[instIndex].instance.boolValue = true;
-                        g_instList_a[instIndex].instance.intValue = cissys_rand() % 100;
-                        strcpy(g_instList_a[instIndex].instance.strValue,"temp test");
-                    }
-                }
-                obj->attrCount = sizeof(const_AttrIds_a) / sizeof(cis_rid_t);
-                obj->attrListPtr = const_AttrIds_a;
-
-                obj->actCount = 0;
-                obj->actListPtr = NULL;
-            }
-            break;
-
-        }
-    }
-}
-
-//////////////////////////////////////////////////////////////////////////
-cis_coapret_t cisAsynOnRead(void* context,cis_uri_t* uri,cis_mid_t mid)
-{
-    struct st_callback_info* newNode = (struct st_callback_info*)cissys_malloc(sizeof(struct st_callback_info));
-    newNode->next = NULL;
-    newNode->flag = (et_callback_type_t)CIS_CALLBACK_READ;
-    newNode->mid = mid;
-    newNode->uri = *uri;
-    g_callbackList = (struct st_callback_info*)CIS_LIST_ADD(g_callbackList,newNode);
-
-    ECOMM_TRACE(UNILOG_PLA_APP, cisAsynOnRead_1, P_SIG, 3, "cisAsynOnRead (%d/%d/%d)", uri->objectId,uri->instanceId,uri->resourceId);
-    return CIS_CALLBACK_CONFORM;
-}
-
-cis_coapret_t cisAsynOnDiscover(void* context,cis_uri_t* uri,cis_mid_t mid)
-{
-    struct st_callback_info* newNode = (struct st_callback_info*)cissys_malloc(sizeof(struct st_callback_info));
-    newNode->next = NULL;
-    newNode->flag = (et_callback_type_t)CIS_CALLBACK_DISCOVER;
-    newNode->mid = mid;
-    newNode->uri = *uri;
-    g_callbackList = (struct st_callback_info*)CIS_LIST_ADD(g_callbackList,newNode);
-
-    ECOMM_TRACE(UNILOG_PLA_APP, cisAsynOnDiscover_1, P_SIG, 3, "cisAsynOnDiscover (%d/%d/%d)", uri->objectId,uri->instanceId,uri->resourceId);
-    return CIS_CALLBACK_CONFORM;
-}
-
-cis_coapret_t cisAsynOnWrite(void* context,cis_uri_t* uri,const cis_data_t* value,cis_attrcount_t attrcount,cis_mid_t mid)
-{
-
-    if(CIS_URI_IS_SET_RESOURCE(uri)){      
-        ECOMM_TRACE(UNILOG_PLA_APP, cisAsynOnWrite_1, P_SIG, 3, "cisAsynOnWrite (%d/%d/%d)", uri->objectId,uri->instanceId,uri->resourceId);
-    }
-    else{     
-        ECOMM_TRACE(UNILOG_PLA_APP, cisAsynOnWrite_2, P_SIG, 2, "cisAsynOnWrite (%d/%d)", uri->objectId,uri->instanceId);
-    }
-
-    struct st_callback_info* newNode = (struct st_callback_info*)cissys_malloc(sizeof(struct st_callback_info));
-    newNode->next = NULL;
-    newNode->flag = (et_callback_type_t)CIS_CALLBACK_WRITE;
-    newNode->mid = mid;
-    newNode->uri = *uri;
-    newNode->param.asWrite.count = attrcount;
-    newNode->param.asWrite.value = prvDataDup(value,attrcount);
-    g_callbackList = (struct st_callback_info*)CIS_LIST_ADD(g_callbackList,newNode);
-
-
-    return CIS_CALLBACK_CONFORM;
-   
-}
-
-
-cis_coapret_t cisAsynOnExec(void* context,cis_uri_t* uri,const uint8_t* value,uint32_t length,cis_mid_t mid)
-{
-    if(CIS_URI_IS_SET_RESOURCE(uri))
-    {
-        ECOMM_TRACE(UNILOG_PLA_APP, cisAsynOnExec_1, P_SIG, 3, "cisAsynOnExec (%d/%d/%d)", uri->objectId,uri->instanceId,uri->resourceId);
-    }
-    else{
-        return CIS_CALLBACK_METHOD_NOT_ALLOWED;
-    }
-
-    if(!CIS_URI_IS_SET_INSTANCE(uri))
-    {
-        return CIS_CALLBACK_BAD_REQUEST;
-    }
-
-    struct st_callback_info* newNode = (struct st_callback_info*)cissys_malloc(sizeof(struct st_callback_info));
-    newNode->next = NULL;
-    newNode->flag = (et_callback_type_t)CIS_CALLBACK_EXECUTE;
-    newNode->mid = mid;
-    newNode->uri = *uri;
-    newNode->param.asExec.buffer = (uint8_t*)cissys_malloc(length);
-    newNode->param.asExec.length = length;
-    memcpy(newNode->param.asExec.buffer,value,length);
-    g_callbackList = (struct st_callback_info*)CIS_LIST_ADD(g_callbackList,newNode);
-
-
-    return CIS_CALLBACK_CONFORM;
-}
-
-
-cis_coapret_t cisAsynOnObserve(void* context,cis_uri_t* uri,bool flag,cis_mid_t mid)
-{
-
-    ECOMM_TRACE(UNILOG_PLA_APP, cisAsynOnObserve_1, P_SIG, 3, "cisAsynOnObserve mid:%d uri:(%d/%d/%d)",mid,uri->objectId,uri->instanceId,uri->resourceId);
-    if(!CIS_URI_IS_SET_INSTANCE(uri))
-    {
-        return CIS_CALLBACK_BAD_REQUEST;
-    }
-    
-    struct st_callback_info* newNode = (struct st_callback_info*)cissys_malloc(sizeof(struct st_callback_info));
-    newNode->next = NULL;
-    newNode->flag = (et_callback_type_t)CIS_CALLBACK_OBSERVE;
-    newNode->mid = mid;
-    newNode->uri = *uri;
-    newNode->param.asObserve.flag = flag;
-    
-    g_callbackList = (struct st_callback_info*)CIS_LIST_ADD(g_callbackList,newNode);
-
-    return CIS_CALLBACK_CONFORM;
-}
-
-
-cis_coapret_t cisAsynOnParams(void* context,cis_uri_t* uri,cis_observe_attr_t parameters,cis_mid_t mid)
-{
-    if(CIS_URI_IS_SET_RESOURCE(uri)){
-        ECOMM_TRACE(UNILOG_PLA_APP, cisAsynOnParams_0, P_SIG, 3, "cisAsynOnParams=(%d/%d/%d)", uri->objectId,uri->instanceId,uri->resourceId); 
-    }
-    
-    if(!CIS_URI_IS_SET_INSTANCE(uri))
-    {
-        return CIS_CALLBACK_BAD_REQUEST;
-    }
-
-    struct st_callback_info* newNode = (struct st_callback_info*)cissys_malloc(sizeof(struct st_callback_info));
-    newNode->next = NULL;
-    newNode->flag = (et_callback_type_t)CIS_CALLBACK_SETPARAMS;
-    newNode->mid = mid;
-    newNode->uri = *uri;
-    newNode->param.asObserveParam.params = parameters;
-    g_callbackList = (struct st_callback_info*)CIS_LIST_ADD(g_callbackList,newNode);
-
-    return CIS_CALLBACK_CONFORM;
-}
-
-
-
-void cisAsynOnEvent(void* context,cis_evt_t eid,void* param)
-{
-    ECOMM_TRACE(UNILOG_PLA_APP, cisAsynOnEvent_0, P_SIG, 1, "cisAsynOnEvent=%d", eid); 
-    switch(eid)
-    {
-        case CIS_EVENT_RESPONSE_FAILED:
-        case CIS_EVENT_NOTIFY_FAILED:       
-            gNotifyOngoing = false;
-            ECOMM_TRACE(UNILOG_PLA_APP, cisAsynOnEvent_2, P_INFO, 1, "cisAsynOnEvent response failed mid:%d", (int32_t)param); 
-            break;
-        case CIS_EVENT_NOTIFY_SUCCESS:
-            gNotifyOngoing = false;
-            cisAsynSetNotifyOnceStatus(true);
-            break;
-        case CIS_EVENT_UPDATE_NEED:
-            ECOMM_TRACE(UNILOG_PLA_APP, cisAsynOnEvent_3, P_INFO, 1, "cisAsynOnEvent need to update,reserve time:%ds", (int32_t)param); 
-            cis_update_reg(gCisContext,LIFETIME_INVALID,false, PS_SOCK_RAI_NO_INFO);
-            break;
-        case CIS_EVENT_REG_SUCCESS:
-            {
-                ECOMM_TRACE(UNILOG_PLA_APP, cisAsynOnEvent_4, P_INFO, 1, "cisAsynOnEvent=CIS_EVENT_REG_SUCCESS, will clean g_observeList"); 
-                struct st_observe_info* delnode;
-                while(g_observeList != NULL){
-                    g_observeList =(struct st_observe_info *)CIS_LIST_RM((cis_list_t *)g_observeList,g_observeList->mid,(cis_list_t **)&delnode);
-                    cissys_free(delnode);
-                }
-            }
-            break;
-         case CIS_EVENT_OBSERVE_ADD:
-         case CIS_EVENT_OBSERVE_CANCEL:
-            prvUpdateObserveContext();
-            break;
-        default:
-            break;
-    }
-    
-}
-
-bool cisAsynGetShutdown(void)
-{
-    return g_shutdown;
-}
-void cisAsynSetShutdown(bool shutdown)
-{
-    g_shutdown = shutdown;
-}
-
-bool cisAsynGetNotifyOnceStatus(void)
-{
-    return gNotifyOnceSuccess;
-}
-
-void cisAsynSetNotifyOnceStatus(bool success)
-{
-    gNotifyOnceSuccess = success;
-}
-
-static void cisAsyncProcessTask(void* lpParam)
-{
-
-    while(1)
-    {
-        struct st_callback_info* node;
-        if(g_callbackList == NULL || g_shutdown == TRUE)
-        {
-            cissys_sleepms(1000);
-            continue;
-        }
-        node = g_callbackList;
-        g_callbackList = g_callbackList->next;
-        
-        switch (node->flag)
-        {
-            case 0:
-                break;
-            case CIS_CALLBACK_READ:
-                {               
-                    ECOMM_TRACE(UNILOG_PLA_APP, cisProcessThread_0, P_SIG, 0, "cisProcessThread CIS_CALLBACK_READ");
-                    cis_uri_t uriLocal;
-                    uriLocal = node->uri;
-                    prvReadResponse(gCisContext,&uriLocal,node->mid);
-                }
-                break;
-            case CIS_CALLBACK_DISCOVER:
-                {                    
-                    ECOMM_TRACE(UNILOG_PLA_APP, cisProcessThread_1, P_SIG, 0, "cisProcessThread CIS_CALLBACK_DISCOVER");
-                    cis_uri_t uriLocal;
-                    uriLocal = node->uri;
-                    prvDiscoverResponse(gCisContext,&uriLocal,node->mid);
-                }
-                break;
-            case CIS_CALLBACK_WRITE:
-                {                   
-                    ECOMM_TRACE(UNILOG_PLA_APP, cisProcessThread_2, P_SIG, 0, "cisProcessThread CIS_CALLBACK_WRITE");
-                    prvWriteResponse(gCisContext,&node->uri,node->param.asWrite.value,node->param.asWrite.count,node->mid);
-                    cis_data_t* data = node->param.asWrite.value;
-                    cis_attrcount_t count = node->param.asWrite.count;
-
-                    for (int i=0;i<count;i++)
-                    {
-                        if(data[i].type == cis_data_type_string || data[i].type == cis_data_type_opaque)
-                        {
-                            if(data[i].asBuffer.buffer != NULL)
-                                cissys_free(data[i].asBuffer.buffer);
-                        }
-                    }
-                    cissys_free(data);
-                }
-                break;
-            case CIS_CALLBACK_EXECUTE:
-                {
-                    ECOMM_TRACE(UNILOG_PLA_APP, cisProcessThread_3, P_SIG, 0, "cisProcessThread CIS_CALLBACK_EXECUTE");
-                    prvExecResponse(gCisContext,&node->uri,node->param.asExec.buffer,node->param.asExec.length,node->mid);
-                    cissys_free(node->param.asExec.buffer);
-                }
-                break;
-            case CIS_CALLBACK_SETPARAMS:
-                {
-                    ECOMM_TRACE(UNILOG_PLA_APP, cisProcessThread_4, P_SIG, 0, "cisProcessThread CIS_CALLBACK_SETPARAMS");
-                    //set parameters and notify
-                    prvParamsResponse(gCisContext,&node->uri,node->param.asObserveParam.params,node->mid);
-                }
-                break;
-            case CIS_CALLBACK_OBSERVE:
-                {
-                    
-                    LOGD("observe callback mid=%d flag=%d\r\n", node->mid, node->param.asObserve.flag);
-                    if(node->param.asObserve.flag)
-                    {
-                        uint16_t count = 0;
-                        struct st_observe_info* observe_new = (struct st_observe_info*)cissys_malloc(sizeof(struct st_observe_info));
-                        observe_new->mid = node->mid;
-                        observe_new->uri = node->uri;
-                        observe_new->next = NULL;
-                        // mid change every time once register
-                        g_observeList = (struct st_observe_info*)cis_list_add((cis_list_t*)g_observeList,(cis_list_t*)observe_new);
-                        
-                        cis_response(gCisContext,NULL,NULL,node->mid,CIS_RESPONSE_OBSERVE, PS_SOCK_RAI_NO_INFO);
-
-                        ECOMM_TRACE(UNILOG_PLA_APP, cisProcessThread_5, P_INFO, 4, "cisProcessThread CIS_CALLBACK_OBSERVE set(%d): %d/%d/%d",
-                                        count,
-                                        observe_new->uri.objectId,
-                                        CIS_URI_IS_SET_INSTANCE(&observe_new->uri)?observe_new->uri.instanceId:-1,
-                                        CIS_URI_IS_SET_RESOURCE(&observe_new->uri)?observe_new->uri.resourceId:-1);
-
-                    }
-                    else
-                    {
-                        struct st_observe_info* delnode = g_observeList;
-
-                        while (delnode) {
-                            if (node->uri.flag == delnode->uri.flag && node->uri.objectId == delnode->uri.objectId) {
-                                if (node->uri.instanceId == delnode->uri.instanceId) {
-                                    if (node->uri.resourceId == delnode->uri.resourceId) {
-                                        break;
-                                    }
-                                }
-                            }
-                            delnode = delnode->next;
-                        }
-                        if (delnode != NULL) {
-                            g_observeList = (struct st_observe_info *)cis_list_remove((cis_list_t *)g_observeList, delnode->mid, (cis_list_t **)&delnode);
-
-                            ECOMM_TRACE(UNILOG_PLA_APP, cisProcessThread_6, P_INFO, 3, "cis_on_observe cancel: %d/%d/%d\n",
-                                        delnode->uri.objectId,
-                                        CIS_URI_IS_SET_INSTANCE(&delnode->uri) ? delnode->uri.instanceId : -1,
-                                        CIS_URI_IS_SET_RESOURCE(&delnode->uri) ? delnode->uri.resourceId : -1);
-
-                            cis_free(delnode);
-                            cis_response(gCisContext, NULL, NULL, node->mid, CIS_RESPONSE_OBSERVE, PS_SOCK_RAI_NO_INFO);
-                        }
-                        else {
-                            return;
-                        }
-                    }                    
-                }
-                break;
-            default:
-                break;
-        }
-
-        cissys_free(node);
-    }
-}
-
-
-void cisAsyncUpdatePumpState(et_client_state_t state)
-{
-    if(gOnenetContextRunning.pumpState != state)
-        gOnenetContextRunning.pumpState = state;
-}
-
-void cisAsyncAddObject()
-{
-    int index = 0;
-    for (index= 0;index < SAMPLE_OBJECT_MAX ; index++)
-    {
-        cis_inst_bitmap_t bitmap;
-        cis_res_count_t  rescount;
-        cis_instcount_t instCount,instBytes;
-        const char* instAsciiPtr;
-        uint8_t * instPtr;
-        cis_oid_t oid;
-        int16_t i;
-        st_sample_object* obj = &g_objectList[index];
-
-        oid = obj->oid;
-        instCount = strlen(obj->instBitmap);
-        instBytes = (instCount - 1) / 8 + 1;
-        instAsciiPtr = obj->instBitmap;
-
-        instPtr = (uint8_t*)cissys_malloc(instBytes);
-        memset(instPtr,0,instBytes);
-        
-        for (i = 0;i < instCount;i++)
-        {
-            cis_instcount_t instBytePos = i / 8;
-            cis_instcount_t instByteOffset = 7 - (i % 8);
-            if(instAsciiPtr[i] == '1'){
-                instPtr[instBytePos] += 0x01 << instByteOffset;
-            }
-        }
-
-        bitmap.instanceCount = instCount;
-        bitmap.instanceBitmap = instPtr;
-        bitmap.instanceBytes = instBytes;
-
-        rescount.attrCount = obj->attrCount;
-        rescount.actCount = obj->actCount;
-
-        cis_addobject(gCisContext,oid,&bitmap,&rescount);
-        cissys_free(instPtr);
-    }
-}
-
-void cisAsyncRegister()
-{
-    g_lifetime = 36000;
-    cis_callback_t callback;
-    callback.onRead = cisAsynOnRead;
-    callback.onWrite = cisAsynOnWrite;
-    callback.onExec = cisAsynOnExec;
-    callback.onObserve = cisAsynOnObserve;
-    callback.onSetParams = cisAsynOnParams;
-    callback.onEvent = cisAsynOnEvent;
-    callback.onDiscover = cisAsynOnDiscover;
-    cis_register(gCisContext,g_lifetime,&callback);
-}
-
-bool cisAsyncCheckNotificationReady()
-{
-    if (gCisContext == NULL)
-        return FALSE;
-    else
-        return ((((st_context_t*)gCisContext)->stateStep == PUMP_STATE_READY) &&
-                (((st_context_t*)gCisContext)->observedList != NULL));
-}
-void cisAsyncBackup(void *pdata, slpManLpState state)
-{
-    ECOMM_TRACE(UNILOG_PLA_APP, cisAsyncBackup_0, P_ERROR, 0, "Enter cisAsyncBackup");
-    memcpy((uint8_t *)&(gOnenetContextRunning.gObservedBackup[0]), &(g_observed_backup[0]), MAX_OBSERVED_COUNT*sizeof(observed_backup_t));
- #if USE_LITTLEFS
-    int32_t ret;
-    lfs_file_t file;
-    ret = LFS_FileOpen(&file, "cisSlpCntxt", LFS_O_WRONLY);
-    OsaCheck(ret == 0,0,0,0);
-
-
-    ret = LFS_FileWrite(&file, &gOnenetContextRunning, sizeof(onenet_context_t));  
-    OsaCheck(ret == sizeof(onenet_context_t),ret,0,0);
-
-    LFS_FileClose(&file);
-
-#endif
-}
-
-void cisAsyncRestore()
-{
-    uint8_t i;
-    ECOMM_TRACE(UNILOG_PLA_APP, cisAsyncRestore_0, P_SIG, 0, "Enter cisAsyncRestore");
-#if USE_LITTLEFS
-
-    int32_t ret;
-    lfs_file_t file;
-    ret = LFS_FileOpen(&file, "cisSlpCntxt", LFS_O_RDONLY | LFS_O_CREAT);
-    OsaCheck(ret == 0,0,0,0);
-
-    ret = LFS_FileRead(&file, &gOnenetContextRunning, sizeof(onenet_context_t));
-    OsaCheck(ret >= 0,ret,0,0);
-
-    LFS_FileClose(&file);
-#else
-    memcpy((uint8_t *)&gOnenetContextRunning,(void*)APP_BACKUP_XIP_ADDR,sizeof(onenet_context_t));
-    
-#endif
-    // Restore for cis core using
-    memcpy((uint8_t *)(&(g_observed_backup[0])), (uint8_t *)&(gOnenetContextRunning.gObservedBackup[0]),  MAX_OBSERVED_COUNT*sizeof(observed_backup_t));
-    // Restore for cis app using
-    LOGD("observeObjNum =%d\r\n", gOnenetContextRunning.observeObjNum);
-    for (i = 0; i < gOnenetContextRunning.observeObjNum; i++)
-    {
-        struct st_observe_info* observe_new = (struct st_observe_info*)cissys_malloc(sizeof(struct st_observe_info));
-        memset((uint8_t *)observe_new, 0, sizeof(struct st_observe_info));
-        observe_new->mid = g_observed_backup[i].msgid;
-        LOGD("mid=%d\r\n", observe_new->mid);
-        cis_memcpy(&(observe_new->uri), &(g_observed_backup[i].uri), sizeof(st_uri_t));
-        cis_memcpy(&(observe_new->params), &(g_observed_backup[i].params), sizeof(cis_observe_attr_t));
-        observe_new->next = NULL;
-        g_observeList = (struct st_observe_info*)cis_list_add((cis_list_t*)g_observeList,(cis_list_t*)observe_new);
-    }
-}
-
-void cisDataObserveReport()
-{
-    uint32_t nowtime;
-    /*data observe data report*/
-    nowtime = cissys_gettime();
-    struct st_observe_info* node = g_observeList;
-    if (node == NULL)
-        return;
-    ECOMM_TRACE(UNILOG_PLA_APP, cisDataObserveReport_0, P_INFO, 2, "cisDataObserveReport g_notifyLast=%d nowtime=%d", g_notifyLast, nowtime);
-    // if diff time is more than 10S, continue to allow to report
-    if((nowtime - g_notifyLast > 10*1000) && (!gNotifyOngoing))
-    {
-        g_notifyLast = nowtime;
-        while(node != NULL)
-        {
-             if(node->mid == 0)
-             {
-                ECOMM_TRACE(UNILOG_PLA_APP, cisDataObserveReport_1, P_INFO, 0, "cisDataObserveReport mid = 0");
-                node = node->next;
-                continue;
-             }
-             if(node->uri.flag == 0)
-             {
-                ECOMM_TRACE(UNILOG_PLA_APP, cisDataObserveReport_2, P_INFO, 0, "cisDataObserveReport uri flag = 0");
-                node = node->next;
-                continue;
-             }
-             cis_uri_t uriLocal;
-             uriLocal = node->uri;
-             prvObserveNotify(gCisContext,&uriLocal,node->mid);
-             node = node->next;
-             ECOMM_TRACE(UNILOG_PLA_APP, cisDataObserveReport_3, P_INFO, 0, "cisDataObserveReport");
-             gNotifyOngoing = true;
-        }
-    }
-    if ((nowtime - g_notifyLast > 20*100)&&(gNotifyOngoing))
-    {
-        ECOMM_TRACE(UNILOG_PLA_APP, cisDataObserveReport_4, P_ERROR, 0, "cisDataObserveReport too long reset gNotifyOngoing");
-        gNotifyOngoing = false;
-    }
-    
-
-}
-
-
-void cisAsyncProcess(void *arg)
-{
-
-    if(cis_init(&gCisContext,(void *)config_hex,sizeof(config_hex),NULL, defaultLocalPort) != CIS_RET_OK){
-        ECOMM_TRACE(UNILOG_PLA_APP, cis_sample_entry_1, P_ERROR, 0, "cis entry init failed.");
-        LOGD("cis entry init failed.\n");
-        if (gCisContext != NULL)
-            cis_deinit(&gCisContext);
-
-        return;
-    }
-    
-    if(pmuBWakeupFromHib() || pmuBWakeupFromSleep2())
-    {
-        cisAsyncRestore();
-        ECOMM_TRACE(UNILOG_PLA_APP, cis_sample_entry_0, P_INFO, 1, "wakeup from hib continue pumpState=%d", gOnenetContextRunning.pumpState);
-        if (gOnenetContextRunning.pumpState == PUMP_STATE_READY || gOnenetContextRunning.pumpState == PUMP_STATE_CONNECTING)
-        {
-#if CIS_ENABLE_CONTEXT_RESTORE
-            ((st_context_t*)gCisContext)->ignoreRegistration = true;
-            ((st_context_t*)gCisContext)->stateStep = PUMP_STATE_CONNECTING;
-#else
-            ((st_context_t*)gCisContext)->stateStep = PUMP_STATE_INITIAL;
-#endif
-            cisAsyncUpdatePumpState(((st_context_t*)gCisContext)->stateStep);
-        }
-        
-        observe_read_retention_data(gCisContext);    
-        cisAsyncAddObject();
-        cisAsyncRegister();
-    }
-    else
-    {
-        cisAsyncAddObject();
-        cisAsyncRegister();
-    }
-    g_shutdown = false;
-    xTaskCreate(cisAsyncProcessTask,"cisAsyncProc", 512, NULL, osPriorityBelowNormal7, NULL);
-    while(1)
-    {
-        uint32_t nowtime;
-        if (g_shutdown)
-        {
-            cissys_sleepms(3000);
-            continue;
-        }
-           
-        /*pump function*/
-        cis_pump(gCisContext);
-        cisAsyncUpdatePumpState(((st_context_t*)gCisContext)->stateStep);
-        cissys_sleepms(1000);
-        /*update lifetime*/
-        nowtime = cissys_gettime();
-        if(nowtime - g_lifetimeLast > ((g_lifetime * 1000) * 0.6)){
-            g_lifetimeLast = cissys_gettime();
-            cis_update_reg(gCisContext,LIFETIME_INVALID,false, PS_SOCK_RAI_NO_INFO);
-        }
-    }
-}
-
-void cisAsyncTask(void *arg)
-{   
-    while(1)
-    {
-        cisAsyncProcess(arg);
-        cissys_sleepms(1000);
-    }
-}
-
-void cisOnenetInit()
-{
-    osThreadAttr_t task_attr;
-    slpManRet_t ret;
-    ret = slpManRegisterUsrdefinedBackupCb(cisAsyncBackup, NULL,SLPMAN_HIBERNATE_STATE);
-    OsaCheck(ret == RET_TRUE,0,0,0);
-
-    memset(&task_attr, 0, sizeof(osThreadAttr_t));
-    task_attr.name        = "cisAsyncTask";
-    task_attr.stack_mem   = onenetTaskStack;
-    task_attr.stack_size  = ONENET_TASK_STACK_SIZE;
-    task_attr.priority    = osPriorityBelowNormal7;
-    task_attr.cb_mem      = &onenetTask;
-    task_attr.cb_size     = sizeof(StaticTask_t);
-    memset(onenetTaskStack, 0xA5, ONENET_TASK_STACK_SIZE);
-    memset((uint8_t *)&gOnenetContextRunning, 0x00, sizeof(gOnenetContextRunning));
-    onenetTaskId = osThreadNew(cisAsyncTask, NULL,&task_attr);
-}
-
-void cisOnenetDeinit()
-{
-    slpManUnregisterUsrdefinedBackupCb(cisAsyncBackup);
-    osThreadTerminate(onenetTaskId);
-    onenetTaskId = NULL;
-}
-
-

+ 0 - 1512
hal_module_adapter.c

@@ -1,1512 +0,0 @@
-#include "bsp.h"
-#include "osasys.h"
-#include "ostask.h"
-#include "queue.h"
-#include "debug_log.h"
-#include "slpman_ec616.h"
-#include "plat_config.h"
-#include "hal_uart.h"
-#include "hal_adc.h"
-#include "adc_ec616.h"
-#include "gpio_ec616.h"
-#include "hal_module_adapter.h"
-/*
-	gps
-*/
-#define GPS_DATA_RECV_BUFFER_SIZE     						(256)
-static posGGACallBack gGPSDataCBfunc =NULL;
-// GSENSOR device addr
-#define GSENSOR_DEVICE_ADDR               						(SC7A20_IIC_ADDRESS)
-#define ZM01_DEVICE_ADDR									(0x2a)
-
-/*
-	i2c
-*/
-#define HAL_I2C_RECV_TASK_QUEUE_CREATED          			 (0x1)
-#define I2C_RECV_QUEUE_BUF_SIZE                        			 (0x10)
-#define I2C_RECV_TASK_STACK_SIZE             					 (1536)
-
-/*
-	power control
-*/
-#define AON_GPS_POWER2									 (4)
-#define AON_RELAY_DRV										 (5)
-#define AON_WAKEUP											 (8)
-#define GPIO_MOS_DRV1										 (14)
-#define GPIO_MOS_DRV2										 (15)
-#define GPIO_POWER_LED										 (9)
-/*GPS*/
-#define FEM_GPS_RSTN										 (6)
-#define FEM_GPS_BLK											 (7)
-#define FEM_GPS_PPS											 (9)
-/*
-	I2C
-*/
-#define I2C_RECV_CONTROL_FLAG         			 (0x1)
-static UINT32 g_halI2CInitFlag = 0;
-static osEventFlagsId_t  g_i2CRecvFlag;
-static StaticQueue_t      i2c_recv_queue_cb;
-static StaticTask_t  i2c_recv_task;
-static UINT8  i2c_recv_task_stack[I2C_RECV_TASK_STACK_SIZE];
-static UINT8   i2c_recv_queue_buf[I2C_RECV_QUEUE_BUF_SIZE*sizeof(i2c_recv_msgqueue_obj_t)];
-// message queue id
-static osMessageQueueId_t i2c_recv_msgqueue;
-
-/*
-	adc
-*/
-#define ADC_TASK_STACK_SIZE   								 (512)
-#define ADC_MSG_MAX_NUM        								 (7)
-#define ADC_AioResDivRatioDefault                                              (ADC_AioResDivRatio10Over16)
-#define REV_AioResDivRatioDefault								 16/10
-#define NTC_REQ_UPDATE_DATA    							       (0x01)
-#define ADC_MSG_TIMEOUT      								 (1000)
-
-#define ADC_RECV_CONTROL_FLAG         						 (0x1)
-typedef struct
-{
-    UINT8 flagC4;
-    UINT32 request;
-    UINT32 NTCvalue[7];
-}NtcResult_t;
-
-NtcResult_t gNtcDev;
-volatile static UINT32 vbatChannelResult = 0;
-volatile static UINT32 thermalChannelResult = 0;
-volatile static UINT32  NTCChannelResult[NTC_ChannelMax];
-
-QueueHandle_t adcMsgHandle = NULL;
-static osEventFlagsId_t adcEvtHandle = NULL;
-static osEventFlagsId_t adcTrigerHandle = NULL;
-static osThreadId_t adcTaskHandle = NULL;
-static StaticTask_t adcTask = NULL;
-static UINT8 adcTaskStack[ADC_TASK_STACK_SIZE];
-/*
-	can
-*/
-static osMessageQueueId_t can_recv_msgqueue;
-static StaticQueue_t      can_recv_queue_cb;
-#define CAN_RECV_QUEUE_BUF_SIZE                        			 (0x10)
-static UINT8   can_recv_queue_buf[CAN_RECV_QUEUE_BUF_SIZE];
-
-#define CAN_RECV_CONTROL_FLAG         						 (0x1)
-//#define SPI_ANALOG	
-#ifdef SPI_ANALOG
-#define USING_SPI0							0
-#endif
-/*spi0*/
-#ifdef SPI_ANALOG
-#if USING_SPI0
-#define SPI_SSN_GPIO_INSTANCE  				 RTE_SPI0_SSN_GPIO_INSTANCE
-#define SPI_SSN_GPIO_INDEX      				 RTE_SPI0_SSN_GPIO_INDEX
-#define SPI_SSN_GPIO_PAD_ADDR                      21
-
-#define SPI_CLK_GPIO_INSTANCE				 0	
-#define SPI_CLK_GPIO_INDEX                             15
-#define SPI_CLK_GPIO_PAD_ADDR                      24
-
-#define SPI_MOSI_GPIO_INSTANCE				 0
-#define SPI_MOSI_GPIO_INDEX				 11
-#define SPI_MOSI_GPIO_PAD_ADDR                    22
-
-#define SPI_MISO_GPIO_INSTANCE				 0
-#define SPI_MISO_GPIO_INDEX				 14
-#define SPI_MISO_GPIO_PAD_ADDR			 23
-
-#else //SPI1
-#define SPI_SSN_GPIO_INSTANCE  				 RTE_SPI1_SSN_GPIO_INSTANCE
-#define SPI_SSN_GPIO_INDEX      				 RTE_SPI1_SSN_GPIO_INDEX
-#define SPI_SSN_GPIO_PAD_ADDR				 13
-
-#define SPI_CLK_GPIO_INSTANCE				 0	
-#define SPI_CLK_GPIO_INDEX                             5
-#define SPI_CLK_GPIO_PAD_ADDR                      16
-
-#define SPI_MOSI_GPIO_INSTANCE				 0
-#define SPI_MOSI_GPIO_INDEX				 3
-#define SPI_MOSI_GPIO_PAD_ADDR                    14
-
-#define SPI_MISO_GPIO_INSTANCE				 0
-#define SPI_MISO_GPIO_INDEX				 4
-#define SPI_MISO_GPIO_PAD_ADDR			 15
-#endif
-#else
-#define SPI_SSN_GPIO_INSTANCE  				 RTE_SPI1_SSN_GPIO_INSTANCE
-#define SPI_SSN_GPIO_INDEX      				 RTE_SPI1_SSN_GPIO_INDEX
-#endif
-extern ARM_DRIVER_I2C Driver_I2C0;
-extern ARM_DRIVER_SPI Driver_SPI0;
-extern ARM_DRIVER_SPI Driver_SPI1;
-extern ARM_DRIVER_USART Driver_USART2;
-uint8_t gps_uart_recv_buf[GPS_DATA_RECV_BUFFER_SIZE];
-static ARM_DRIVER_SPI   *spiMasterDrv = &CREATE_SYMBOL(Driver_SPI, 1);
-static ARM_DRIVER_I2C   *i2cDrvInstance = &CREATE_SYMBOL(Driver_I2C, 0);
-static ARM_DRIVER_USART *usartHandle =  &CREATE_SYMBOL(Driver_USART, 2);
-//LED define pin index
-#define LED_INX_MAX    										 (5)
-#define LED_PORT_0      										 (0)
-#define LED_PORT_1     										 (1)
-/*
-	pin1~pin4 for soc display
-	pin5  for  fault display
-*/
-#define LED_GPIO_PIN_1  										 (6)
-#define LED_PAD_INDEX1           								 (17)
-
-#define LED_GPIO_PIN_2  										 (7)
-#define LED_PAD_INDEX2								              (18)
-
-#define LED_GPIO_PIN_3 										 (0)
-#define LED_PAD_INDEX3           								 (21)
-
-#define LED_GPIO_PIN_4 										 (11)
-#define LED_PAD_INDEX4								              (22)
-
-#define LED_GPIO_PIN_5   									 (1)
-#define LED_PAD_INDEX5								              (27)
-
-led_pin_config_t gLedCfg[LED_INX_MAX]={{LED_PORT_0,LED_GPIO_PIN_1,LED_PAD_INDEX1, PAD_MuxAlt0},\
-									 {LED_PORT_0,LED_GPIO_PIN_2,LED_PAD_INDEX2, PAD_MuxAlt0},\
-									 {LED_PORT_1,LED_GPIO_PIN_3,LED_PAD_INDEX3, PAD_MuxAlt0},\
-									 {LED_PORT_0,LED_GPIO_PIN_4,LED_PAD_INDEX4, PAD_MuxAlt0},\
-								       {LED_PORT_1,LED_GPIO_PIN_5,LED_PAD_INDEX5, PAD_MuxAlt0}};
-
-#if 0
-/**
-  \fn        void NetSocDisplay(UINT8 soc)
-  \param[in]  void
-  \brief       RSSI display on led
-  \return    
-*/
-#define RSSI_LEVEL_0										 (0)
-#define RSSI_LEVEL_10										 (10)
-#define RSSI_LEVEL_20										 (20)
-#define RSSI_LEVEL_25										 (25)
-#define RSSI_LEVEL_30										 (30)
-void NetSocDisplay(UINT8 soc)
-{
-	UINT16 pinLevel[LED_INX_MAX-1] ={0};
-	gpio_pin_config_t nGpioCfg={0};
-	nGpioCfg.pinDirection = GPIO_DirectionOutput;
-	nGpioCfg.misc.initOutput = 1;
-	for(int8_t i=0;i< LED_INX_MAX-1;i++){
-		GPIO_PinConfig(gLedCfg[i].pinPort, gLedCfg[i].pinInx, &nGpioCfg);
-	}
-	
-	if(RSSI_LEVEL_0 < soc && soc <=RSSI_LEVEL_10)
-	{
-		pinLevel[0]=1;
-		pinLevel[1]=pinLevel[2]=pinLevel[3]=0;
-	}
-	else if(RSSI_LEVEL_10 < soc && soc <=RSSI_LEVEL_20)
-	{
-		pinLevel[0]=pinLevel[1]=1;
-		pinLevel[2]=pinLevel[3]=0;
-	}
-	else if(RSSI_LEVEL_20 < soc && soc <=RSSI_LEVEL_25)
-	{
-		pinLevel[0]=pinLevel[1]=pinLevel[2]=1;
-		pinLevel[3]=0;
-	}
-	else if(RSSI_LEVEL_25 < soc && soc <=RSSI_LEVEL_30)
-	{
-		pinLevel[0]=pinLevel[1]=pinLevel[2]=pinLevel[3]=1;
-	}
-	for(UINT8 i=0; i<LED_INX_MAX-1; i++)
-	{
-		GPIO_PinWrite(gLedCfg[i].pinPort, 1<<gLedCfg[i].pinInx, pinLevel[i]<<gLedCfg[i].pinInx);
-	}
-
-}
-#endif
-void NetSocDisplay(ledInx_t  Inx , ledStaus_t level)
-{
-	UINT16 pinLevel[LED_INX_MAX-1] ={0};
-	gpio_pin_config_t nGpioCfg={0};
-	nGpioCfg.pinDirection = GPIO_DirectionOutput;
-	nGpioCfg.misc.initOutput = 1;
-
-	pad_config_t padConfig;
-	PAD_GetDefaultConfig(&padConfig);
-
-	padConfig.mux = gLedCfg[Inx].padMutex;
-	PAD_SetPinConfig(gLedCfg[Inx].padInx, &padConfig);
-      PAD_SetPinPullConfig(gLedCfg[Inx].padInx, PAD_InternalPullDown);
-
-	GPIO_PinConfig(gLedCfg[Inx].pinPort, gLedCfg[Inx].pinInx, &nGpioCfg);
-	GPIO_PinWrite(gLedCfg[Inx].pinPort, 1<<gLedCfg[Inx].pinInx, level <<gLedCfg[Inx].pinInx);
-}
-
-/**
-  \fn      void FaultDisplay(ledStaus_t status)
-  \param[in]  status equal to 1 ,turn on red led ; status equal to 0 ,turn off red led
-  \brief       RSSI display on led
-  \return    
-*/
-void FaultDisplay(ledStaus_t status)
-{
-	gpio_pin_config_t nGpioCfg={0};
-	nGpioCfg.pinDirection = GPIO_DirectionOutput;
-	nGpioCfg.misc.initOutput = 1;
- 	pad_config_t padConfig;
-	PAD_GetDefaultConfig(&padConfig);
-
-	padConfig.mux = gLedCfg[4].padMutex;
-	PAD_SetPinConfig(gLedCfg[4].padInx, &padConfig);
-	PAD_SetPinPullConfig(gLedCfg[4].padInx, PAD_InternalPullDown);
-	
-	GPIO_PinConfig(gLedCfg[4].pinPort, gLedCfg[4].pinInx, &nGpioCfg);
-	GPIO_PinWrite(gLedCfg[4].pinPort, 1<<gLedCfg[4].pinInx, status<<gLedCfg[4].pinInx);
-}
-
-/**
-* @brief      
-* @param
-* @return   
-*/
-void SPI_CS_High(void)
-{
-    GPIO_PinWrite(SPI_SSN_GPIO_INSTANCE, 1 << SPI_SSN_GPIO_INDEX, 1 << SPI_SSN_GPIO_INDEX);
-      
-}
-/**
-* @brief      
-* @param
-* @return   
-*/
-void SPI_CS_Low(void)
-{
-    GPIO_PinWrite(SPI_SSN_GPIO_INSTANCE, 1 << SPI_SSN_GPIO_INDEX, 0);
-}
-#ifdef SPI_ANALOG
-/**
-* @brief      
-* @param
-* @return   
-*/
-void SPI_Clk_High(void)
-{
-   	GPIO_PinWrite(SPI_CLK_GPIO_INSTANCE, 1<<SPI_CLK_GPIO_INDEX,1<<SPI_CLK_GPIO_INDEX);      
-}
-/**
-* @brief      
-* @param
-* @return   
-*/
-void SPI_Clk_Low(void)
-{
-   	GPIO_PinWrite(SPI_CLK_GPIO_INSTANCE, 1<<SPI_CLK_GPIO_INDEX,0);
-}
-/**
-* @brief      
-* @param
-* @return   
-*/
-void SPI_Mosi_High(void)
-{
-   	GPIO_PinWrite(SPI_MOSI_GPIO_INSTANCE, 1<<SPI_MOSI_GPIO_INDEX,1<<SPI_MOSI_GPIO_INDEX);     
-}
-/**
-* @brief      
-* @param
-* @return   
-*/
-void SPI_Mosi_Low(void)
-{
-   GPIO_PinWrite(SPI_MOSI_GPIO_INSTANCE, 1<<SPI_MOSI_GPIO_INDEX,0);
-}
-/**
-* @brief      
-* @param
-* @return   
-*/
-UINT8 SPI_MISO_Read(void)
-{
-	return GPIO_PinRead(SPI_MISO_GPIO_INSTANCE,SPI_MISO_GPIO_INDEX);
-}
-#endif
-/**
-  * @brief Software SPI_Flash bus driver basic function, send a single byte to MOSI,
-  *        and accept MISO data at the same time.
-  * @param[in] u8Data:Data sent on the MOSI data line
-  * @return    u8Out: Data received on the MISO data line
-  */
-UINT8 SPI_Write_Byte(UINT8 u8Data)
-{
-  UINT8 data = u8Data;
-#ifdef SPI_ANALOG
-	UINT8 i=0;
-      for(i=0;i<8;i++){
-		SPI_Clk_Low();
-		if((u8Data<<i)&0x80)
-			SPI_Mosi_High();
-		else
-			SPI_Mosi_Low();
-		SPI_Clk_High();
-	}
-	SPI_Clk_Low();
-#else
-	spiMasterDrv->Transfer(&u8Data,&data,1);
-#endif
-    return 0;
-}
-
-#ifdef SPI_ANALOG
-/**
-* @brief      
-* @param
-* @return   
-*/
-UINT8 SPI_Read_Byte(void)
-{
-	UINT8 i=0;
-	UINT8 rByte=0;
-	SPI_Clk_Low();
-		  
-      for(i=0;i<8;i++){
-		SPI_Clk_High();
-		rByte<<=1;
-		rByte |= SPI_MISO_Read();
-		SPI_Clk_Low();
-	}
-
-    return rByte;
-}
-#endif
-/**
-  \fn          INT32 CAN_ReadReg(UINT8 addr)
-  \param[in]   addr    CAN register addr
-  \brief       write can register
-  \return     
-*/
-INT32 CAN_WriteReg(UINT8 addr, UINT8 value)
-{
-	SPI_CS_Low();
-	SPI_Write_Byte(CAN_WRITE);
-	SPI_Write_Byte(addr);
-	SPI_Write_Byte(value);
-	SPI_CS_High();
-   	return 0;
-}
-/**
-  \fn    INT32 CAN_ReadReg(UINT8 reg, UINT8 len, UINT8 *buf)
-  \param[in]   reg:  can register addr 
-  \brief       read can register
-  \return     
-*/
-INT32 CAN_ReadReg(UINT8 reg, UINT8 len, UINT8 *buf)
-{
-	UINT8 i =0;
-	UINT8 data=0;
-	INT32 res;
-	if(buf == NULL) return -1;
-	
-	SPI_CS_Low();
-	SPI_Write_Byte(CAN_READ);
-	SPI_Write_Byte(reg);
-#ifdef SPI_ANALOG
-	for(i=0;i<len;i++){
-  		buf[i]= SPI_Read_Byte();
-	}
-#else
-	for(i=0;i<len;i++){
-		spiMasterDrv->Transfer(&data,&buf[i],1);
-	}
-#endif
-	SPI_CS_High();
-	return i;
-}
-/**
-  \fn   UINT8 CanTriggerEvtInit(void)
-  \param[in] 
-  \brief       generate irq,then notify app
-  \return     1 fail; 0 ok;
-*/
-UINT8 CanTriggerEvtInit(void)
-{
-	/*for msg queue create*/
-	osMessageQueueAttr_t queue_attr;
-	memset(&queue_attr, 0, sizeof(queue_attr));
-	queue_attr.cb_mem = &can_recv_queue_cb;
-	queue_attr.cb_size    = sizeof(can_recv_queue_cb);
-	queue_attr.mq_mem  = can_recv_queue_buf;
-	queue_attr.mq_size   = sizeof(can_recv_queue_buf);
-	can_recv_msgqueue = osMessageQueueNew(I2C_RECV_QUEUE_BUF_SIZE,1, &queue_attr);
-	printf("CanTriggerEvtInit \r\n");
-	return 0;
-}
-/**
-  \fn   void CanWaitEvt(UINT32 timeout)
-  \param[in]  
-  \brief       
-  \return     
-*/
-void CanWaitEvt(UINT32 timeout)
-{
-	osStatus_t status;
-	UINT8 msg = 0;
-	UINT32 mask;
-	status = osMessageQueueGet(can_recv_msgqueue, &msg, 0 , osWaitForever);
-	printf("msg = %#x\r\n",msg);
-}
-/**
-  \fn    void CanTiggerEvt(UINT8 cmd)
-  \param[in]  
-  \brief      
-  \return     
-*/
-void CanTiggerEvt(UINT8 cmd)
-{
-	 osStatus_t status;
-	 UINT8 msg = cmd;
-	 status = osMessageQueuePut(can_recv_msgqueue, &msg, 0, 0);
-}
-/*******************************************************************************
-* o����y??  : MCP2515_Reset
-* ?����?    : ����?��?��????��?����?t?��??MCP2515
-* ��?��?    : ?T
-* ��?3?    : ?T
-* ����???��  : ?T
-* ?��?��    : ???��2???��??��?��???a������?���䨬?,2��???��?t����?��?a?????�꨺?
-*******************************************************************************/
-INT32  HAL_Can_Reset(void)
-{
-	SPI_CS_Low();
-	SPI_Write_Byte(CAN_RESET);
-	SPI_CS_High();
-	return 0;
-}
-
-/*******************************************************************************
-* o����y??  : MCP2515_Init
-* ?����?    : MCP25153?��??��????
-* ��?��?    : ?T
-* ��?3?    : ?T
-* ����???��  : ?T
-* ?��?��    : 3?��??���㨹������o����?t?��???��1�����2����??������???�������?��??��1?????�̨�?��
-*******************************************************************************/
-void HAL_Can_Init(Can_InitType param)
-{
-	UINT8 temp=0,temp1=0;
-    INT32 res = -1;
-
-	HAL_Can_Reset();	//����?��?��????��?����?t?��??MCP2515
-	osDelay(100/portTICK_PERIOD_MS);		
-    CAN_WriteReg(CANCTRL,OPMODE_CONFIG |CLKOUT_ENABLED);
-    CAN_ReadReg(CANCTRL,1,&temp);//?����?CAN���䨬???��??�¦�??��
-   #ifdef USING_PRINTF   
-	printf("[%d] CANCTRL = %#x \r\n",__LINE__,temp);
-   #endif  
-	CAN_WriteReg(CNF1,param.baudrate);
-	CAN_WriteReg(CNF2,0x80|PHSEG1_3TQ|PRSEG_1TQ);
-	CAN_WriteReg(CNF3,PHSEG2_3TQ);
-	
-	if(param.packType == STD_PACK){
-		 /*?����???2��??��??��*/
-		CAN_WriteReg(TXB0SIDH,0xFF&(param.TxStdIDH));//����?��?o3??��0������?������?��?????
-		CAN_WriteReg(TXB0SIDL,0xE0&(param.TxStdIDL));//����?��?o3??��0������?������?��?�̨�??		
-
-		CAN_WriteReg(RXM0SIDH,0xFF);
-		CAN_WriteReg(RXM0SIDL,0xE0);
-		CAN_WriteReg(RXM1SIDH,0xFF);
-		CAN_WriteReg(RXM1SIDL,0xE0);
-
-		/*?����???2��??��??��*/
-		CAN_WriteReg(RXF0SIDH,0xFF&(param.RxStdIDH[0]));
-		CAN_WriteReg(RXF0SIDL,0xE0&(param.RxStdIDL[0]));
-		
-		CAN_WriteReg(RXF1SIDH,0xFF&(param.RxStdIDH[1]));
-		CAN_WriteReg(RXF1SIDL,0xE0&(param.RxStdIDL[1]));
-#if 0
-	CAN_WriteReg(RXF2SIDH,0x00);
-	CAN_WriteReg(RXF2SIDL,0xa0);
-	CAN_WriteReg(RXF3SIDH,0x00);
-	CAN_WriteReg(RXF3SIDL,0x40);
-	CAN_WriteReg(RXF4SIDH,0x00);
-	CAN_WriteReg(RXF4SIDL,0x60);
-	CAN_WriteReg(RXF5SIDH,0x00);
-	CAN_WriteReg(RXF5SIDL,0x80);
-#else
-		CAN_WriteReg(RXF2SIDH,0xFF&(param.RxStdIDH[2]));
-		CAN_WriteReg(RXF2SIDL,0xE0&(param.RxStdIDL[2]));
-		CAN_WriteReg(RXF3SIDH,0xFF&(param.RxStdIDH[3]));
-		CAN_WriteReg(RXF3SIDL,0xE0&(param.RxStdIDL[3]));
-		CAN_WriteReg(RXF4SIDH,0xFF&(param.RxStdIDH[4]));
-		CAN_WriteReg(RXF4SIDL,0xE0&(param.RxStdIDL[4]));
-		CAN_WriteReg(RXF5SIDH,0xFF&(param.RxStdIDH[5]));
-		CAN_WriteReg(RXF5SIDL,0xE0&(param.RxStdIDL[5]));
-#endif
-	
-		CAN_WriteReg(RXB0CTRL,RXM_VALID_STD);
-		CAN_WriteReg(RXB0DLC,DLC_8);
-		
-		CAN_WriteReg(RXB1CTRL,RXM_VALID_STD|FILHIT1_FLTR_2);
-		CAN_WriteReg(RXB1DLC,DLC_8);
-	
-	}
-	else if(param.packType == EXT_PACK)
-	{
-		/*TXB0*/
-		CAN_WriteReg(TXB0SIDH,0xFF&(param.TxStdIDH));
-		CAN_WriteReg(TXB0SIDL,(0xEB&(param.TxStdIDL))|0x08);
-		CAN_WriteReg(TXB0EID8,0xFF&(param.TxExtIDH));
-		CAN_WriteReg(TXB0EID0,0xFF&(param.TxExtIDL));
-		
-		 /*?����???2��??��??��*/
-		CAN_WriteReg(RXM0SIDH,0xFF);
-		CAN_WriteReg(RXM0SIDL,0xE3);
-		CAN_WriteReg(RXM0EID8,0xFF);
-		CAN_WriteReg(RXM0EID0,0xFF);
-
-		/*?����???2��??��??��*/
-		CAN_WriteReg(RXF0SIDH,0xFF&(param.RxStdIDH[0]));
-		CAN_WriteReg(RXF0SIDL,(0xEB&(param.RxStdIDL[0]))|0x08);
-		CAN_WriteReg(RXF0EID8,0xFF&(param.RxExtIDH[0]));
-		CAN_WriteReg(RXF0EID8,0xFF&(param.RxExtIDL[0]));
-
-		CAN_WriteReg(RXF1SIDH,0xFF&(param.RxStdIDH[1]));
-		CAN_WriteReg(RXF1SIDL,(0xEB&(param.RxStdIDL[1]))|0x08);
-		CAN_WriteReg(RXF1EID8,0xFF&(param.RxExtIDH[1]));
-		CAN_WriteReg(RXF1EID8,0xFF&(param.RxExtIDL[1]));
-
-		CAN_WriteReg(RXF2SIDH,0xFF&(param.RxStdIDH[2]));
-		CAN_WriteReg(RXF2SIDL,(0xEB&(param.RxStdIDL[2]))|0x08);
-		CAN_WriteReg(RXF2EID8,0xFF&(param.RxExtIDH[2]));
-		CAN_WriteReg(RXF2EID8,0xFF&(param.RxExtIDL[2]));
-
-		CAN_WriteReg(RXF3SIDH,0xFF&(param.RxStdIDH[3]));
-		CAN_WriteReg(RXF3SIDL,(0xEB&(param.RxStdIDL[3]))|0x08);
-		CAN_WriteReg(RXF3EID8,0xFF&(param.RxExtIDH[3]));
-		CAN_WriteReg(RXF3EID8,0xFF&(param.RxExtIDL[3]));
-
-		CAN_WriteReg(RXF4SIDH,0xFF&(param.RxStdIDH[4]));
-		CAN_WriteReg(RXF4SIDL,(0xEB&(param.RxStdIDL[4]))|0x08);
-		CAN_WriteReg(RXF4EID8,0xFF&(param.RxExtIDH[4]));
-		CAN_WriteReg(RXF4EID8,0xFF&(param.RxExtIDL[4]));
-
-		CAN_WriteReg(RXF5SIDH,0xFF&(param.RxStdIDH[5]));
-		CAN_WriteReg(RXF5SIDL,(0xEB&(param.RxStdIDL[5]))|0x08);
-		CAN_WriteReg(RXF5EID8,0xFF&(param.RxExtIDH[5]));
-		CAN_WriteReg(RXF5EID8,0xFF&(param.RxExtIDL[5]));
-		
-	
-		CAN_WriteReg(RXB0CTRL,RXM_VALID_EXT);
-		CAN_WriteReg(RXB0DLC,DLC_8);
-		
-		CAN_WriteReg(RXB1CTRL,RXM_VALID_EXT|FILHIT1_FLTR_2);
-		CAN_WriteReg(RXB1DLC,DLC_8);
-	
-	}
-
-	CAN_WriteReg(CANINTE,0x43);
-	CAN_WriteReg(CANINTF,0x00);
-	
-	CAN_WriteReg(CANCTRL,param.mode |CLKOUT_ENABLED);//??MCP2515����???a?y3��?�꨺?,��?3??????�꨺? REQOP_NORMAL|CLKOUT_ENABLED
-    CAN_ReadReg(CANSTAT,1,&temp);//?����?CAN���䨬???��??�¦�??��
-	if(OPMODE_NORMAL !=(temp&0xE0))//?D??MCP2515��?��?��??-??��??y3��?�꨺?
-	{
-    		CAN_WriteReg(CANCTRL,param.mode|CLKOUT_ENABLED);//?����???MCP2515����???a?y3��?�꨺?,��?3??????�꨺?REQOP_NORMAL
-	}
-}
-
-/*******************************************************************************
-* o����y??  : HAL_Can_Transmit
-* ?����?    : CAN����?��???��3��?����?��y?Y
-* ��?��?    : *CAN_TX_Buf(��y����?����y?Y?o3???????),len(��y����?����y?Y3��?��)
-* ��?3?    : ?T
-* ����???��  : ?T
-* ?��?��    : ?T
-*******************************************************************************/
-INT32  HAL_Can_Transmit(Can_TxMsgType Can_TxMsg)
-{
-	UINT8 tryTim,count,value,i;
-
-	count=0;	
-	while(count<Can_TxMsg.DLC)
-	{
-		tryTim=0;
-		CAN_ReadReg(TXB0CTRL,1,&value);
-		while((value&0x08) && (tryTim<50))//?��?��?��?3D?���䨬???��?,�̨���yTXREQ����????��?
-		{
-			CAN_ReadReg(TXB0CTRL,1,&value);
-			osDelay(1/portTICK_PERIOD_MS);
-			tryTim++;
-		}
-		/*TXB0*/
-		CAN_WriteReg(TXB0SIDH,0xFF&(Can_TxMsg.stdIDH));//����?��?o3??��0������?������?��?????
-		CAN_WriteReg(TXB0SIDL,0xE0&(Can_TxMsg.stdIDL));//����?��?o3??��0������?������?��?�̨�??	
-		for(i=0;i<8;)
-		{
-			CAN_WriteReg(TXB0D0+i,Can_TxMsg.Data[count++]);//??��y����?����?��y?YD�䨨?����?��?o3???��??��
-			i++;
-			if(count>=Can_TxMsg.DLC) break;
-		}
-		CAN_WriteReg(TXB0DLC,i);//??��???��y����?����?��y?Y3��?��D�䨨?����?��?o3??��0��?����?��3��?��??��??��
-		SPI_CS_Low();
-		CAN_WriteReg(TXB0CTRL,0x08);//???������?������??
-		SPI_CS_High();
-	}
-}
-
-/*******************************************************************************
-* o����y??  :  HAL_Can_Receive(UINT8 *CAN_RX_Buf)
-* ?����?    : CAN?����?��???��y?Y
-* ��?��?    : *CAN_TX_Buf(��y?����?��y?Y?o3???????)
-* ��?3?    : ?T
-* ����???��  : len(?����?��?��y?Y��?3��?��,0~8��??��)
-* ?��?��    : ?T
-*******************************************************************************/
-UINT8  HAL_Can_Receive(UINT8 *CAN_RX_Buf)
-{
-	UINT8 i=0,len=0,temp=0;
- 
-	CAN_ReadReg(CANINTF,1,&temp);
-	if(temp & 0x01)
-	{
-		CAN_ReadReg(RXB0DLC,1,&len);
-		while(i<len)
-		{	
-			CAN_ReadReg(RXB0D0+i,1,&CAN_RX_Buf[i]);
-			i++;
-		}
-		
-	}else if(temp & 0x02){
-		CAN_ReadReg(RXB1DLC,1,&len);
-		while(i<len)
-		{	
-			CAN_ReadReg(RXB1D0+i,1,&CAN_RX_Buf[i]);
-			i++;
-		}
-	}
-	
-	CAN_WriteReg(CANINTF,0);
-	return len;
-}
-
-/**
-  \fn          void CanHandleDataCallback(UINT32 event)
-  \param[in]  event    spi irq event
-  \brief         base on event,handle different situation
-  \return      
-*/
-void CanHandleDataCallback(UINT32 event)
-{
-    if(event & ARM_SPI_EVENT_TRANSFER_COMPLETE)
-    {
-       
-    }
-   else if(event & ARM_SPI_EVENT_DATA_LOST)
-   {
-
-   }
-   else if(event & ARM_SPI_EVENT_MODE_FAULT)
-   {
-
-   }
-#if 0
-#ifdef USING_PRINTF
-		printf("[%d] CanHandleDataCallback :%d\r\n",__LINE__,event);
-#else				
-    		ECOMM_TRACE(UNILOG_PLA_APP,CAN_CB1, P_INFO, 1, "SPI event [%u] coming!",event);
-#endif
-#endif
-}
-/**
-  \fn          void CanSPIHandler(ARM_SPI_SignalEvent_t cb_event)
-  \param[in]  cb_event   :
-  \brief        init spi module
-  \return      
-*/
-void CanSPIHandler(ARM_SPI_SignalEvent_t cb_event,UINT8 mode,UINT8 dataBits, UINT32 spiRate )
-{
-#ifdef SPI_ANALOG
-	gpio_pin_config_t nGpioCfg={0};
-	nGpioCfg.pinDirection = GPIO_DirectionOutput;
-	nGpioCfg.misc.initOutput = 1;
-
-	pad_config_t padConfig;
-	PAD_GetDefaultConfig(&padConfig);
-	/*cs*/
-	padConfig.mux = PAD_MuxAlt0;
-	PAD_SetPinConfig(SPI_SSN_GPIO_PAD_ADDR, &padConfig);
-      PAD_SetPinPullConfig(SPI_SSN_GPIO_PAD_ADDR, PAD_InternalPullDown);
-
-	GPIO_PinConfig(SPI_SSN_GPIO_INSTANCE, SPI_SSN_GPIO_INDEX, &nGpioCfg);
-	GPIO_PinWrite(SPI_SSN_GPIO_INSTANCE, 1<<SPI_SSN_GPIO_INDEX,0);
-	/*
-		clk
-	*/
-	padConfig.mux = PAD_MuxAlt0;
-	PAD_SetPinConfig(SPI_CLK_GPIO_PAD_ADDR, &padConfig);
-      PAD_SetPinPullConfig(SPI_CLK_GPIO_PAD_ADDR, PAD_InternalPullDown);
-
-	GPIO_PinConfig(SPI_CLK_GPIO_INSTANCE, SPI_CLK_GPIO_INDEX, &nGpioCfg);
-	GPIO_PinWrite(SPI_CLK_GPIO_INSTANCE, 1<<SPI_CLK_GPIO_INDEX,0);
-
-	/*mosi*/
-	padConfig.mux = PAD_MuxAlt0;
-	PAD_SetPinConfig(SPI_MOSI_GPIO_PAD_ADDR, &padConfig);
-      PAD_SetPinPullConfig(SPI_MOSI_GPIO_PAD_ADDR, PAD_InternalPullDown);
-
-	GPIO_PinConfig(SPI_MOSI_GPIO_INSTANCE, SPI_MOSI_GPIO_INDEX, &nGpioCfg);
-	GPIO_PinWrite(SPI_MOSI_GPIO_INSTANCE, 1<<SPI_MOSI_GPIO_INDEX,0);
-	/*miso*/
-	nGpioCfg.pinDirection = GPIO_DirectionInput;
-	nGpioCfg.misc.initOutput = 0;
-
-	padConfig.mux = PAD_MuxAlt0;
-	padConfig.pullSelect = PAD_PullInternal;
-	padConfig.pullUpEnable = PAD_PullUpDisable;
-	padConfig.pullDownEnable = PAD_PullDownEnable;
-	PAD_SetPinConfig(SPI_MISO_GPIO_PAD_ADDR, &padConfig);
-
-	GPIO_PinConfig(SPI_MISO_GPIO_INSTANCE, SPI_MISO_GPIO_INDEX, &nGpioCfg);
-		
-#else
-    // Initialize master spi
-   spiMasterDrv->Initialize(NULL);
-    // Power on
-    spiMasterDrv->PowerControl(ARM_POWER_FULL);	
-	// Configure slave spi bus
-    spiMasterDrv->Control(ARM_SPI_MODE_MASTER | mode | ARM_SPI_DATA_BITS(dataBits) |ARM_SPI_MSB_LSB | ARM_SPI_SS_MASTER_SW, spiRate);
-#endif
-}
-/**
-  \fn   INT32 ZM01RecvParam(UINT8 *param)
-  \param[in]   
-  \brief       read ZM01 register
-  \return    execution_status
-*/
-INT32 ZM01RecvParam(UINT8 *param)
-{
-    INT32 res = 0;
-    UINT8 tempBuffer = 0xaa;
-   if(param == NULL) return -7;
-   res = i2cDrvInstance->MasterTransmit(ZM01_DEVICE_ADDR, &tempBuffer, 1, true);
-
-    res = i2cDrvInstance->MasterReceive(ZM01_DEVICE_ADDR, param, 1, true);
-
-    return res;
-}
-/**
-  \fn         INT32 GSENSOR_WriteReg(UINT8 addr, UINT8 value)
-  \param[in]   addr    GSENSOR register addr
-  \brief       Write to GSENSOR register
-  \return     
-*/
-INT32 GSENSOR_WriteReg(UINT8 addr, UINT8 value)
-{
-    UINT8 tempBuffer[2];
-    INT32 res = -1;
-    tempBuffer[0] = addr;
-    tempBuffer[1] = value;
-    return (i2cDrvInstance->MasterTransmit(GSENSOR_DEVICE_ADDR, tempBuffer, sizeof(tempBuffer), true));
-}
-/**
-  \fn         INT32 GSENSOR_ReadReg(UINT8 reg, UINT8 len, UINT8 *buf)
-  \param[in]   addr    GSENSOR register addr
-  \brief       read GSENSOR register
-  \return      register value of GSENSOR
-*/
-INT32 GSENSOR_ReadReg(UINT8 reg, UINT8 len, UINT8 *buf)
-{
-    INT32 res = -1;
-    if(len > 8 || buf == NULL) return -1;
-	
-    res = i2cDrvInstance->MasterTransmit(GSENSOR_DEVICE_ADDR, &reg, 1, true);
-
-    res = i2cDrvInstance->MasterReceive(GSENSOR_DEVICE_ADDR, buf, len, true);
-
-    return res;
-
-}
-/**
-  \fn         void GsensorI2CCallback(UINT32 event)
-  \param[in]  event   : i2c irq event
-  \brief        i2c irq event ,callback function
-  \return      
-*/
-void GsensorI2CCallback(UINT32 event)
-{
-	switch(event)
-	{
-		case ARM_I2C_EVENT_TRANSFER_DONE:
-
-		break;
-		case ARM_I2C_EVENT_TRANSFER_INCOMPLETE:
-
-		break;
-		case ARM_I2C_EVENT_ADDRESS_NACK:
-
-		break;
-		case ARM_I2C_EVENT_BUS_ERROR:
-
-		break;
-		case ARM_I2C_EVENT_BUS_CLEAR:
-
-		break;
-		default:
-		break;
-	}
-
-}
-/**
-  \fn  void HAL_I2C_CreateRecvTaskAndQueue(uint32_t event)
-  \param[in]  
-  \brief       RECV data
-  \return      
-*/
-void HAL_I2C_RecvControl(bool on)
-{
-    EC_ASSERT(g_i2CRecvFlag, g_i2CRecvFlag, 0, 0);
-
-    if(on == true)
-    {
-        osEventFlagsClear(g_i2CRecvFlag, I2C_RECV_CONTROL_FLAG);
-    }
-    else
-    {
-        osEventFlagsSet(g_i2CRecvFlag, I2C_RECV_CONTROL_FLAG);
-    }
-}
-void GsensorTriggerEvent(UINT32 event ,UINT32 data)
-{
-	 osStatus_t status;
-	 i2c_recv_msgqueue_obj_t msg={0};
-
-	 msg.event = event;
-	 msg.value = data;
-	 status = osMessageQueuePut(i2c_recv_msgqueue, &msg, 0, 0);
-        if(status == osErrorResource)
-        {
-            //ECOMM_TRACE(UNILOG_PLA_DRIVER, GsensorTriggerEvent_0, P_WARNING, 0, "I2C recv queue error");
-        }
-
-}
-
-static INT32 	I2CEvtProcess(uint32_t evt)
-{
-    INT32 ret;
-#if SL_SC7A20_16BIT_8BIT
-    INT16 xyzData[7];
-#else
-    INT8 xyzData[7];
-#endif
-    HAL_I2C_RecvControl(true);
-
-    if(evt & I2C_INT1_REQ_BITMAP)
-    {
-
-    }
-
-    if(evt & I2C_INT2_REQ_BITMAP)
-    {
-	SL_SC7A20_Read_XYZ_Data(xyzData);
-    }
-   
-    return 0;
-}
-
-static void HAL_I2C_RecvTaskEntry(void)
-{
-	while(1)
-	{
-		uint32_t flag,mask;
-		osStatus_t status;
-		i2c_recv_msgqueue_obj_t msg;
-
-		flag = osEventFlagsWait(g_i2CRecvFlag, I2C_RECV_CONTROL_FLAG, osFlagsNoClear | osFlagsWaitAll, osWaitForever);
-
- 		EC_ASSERT(flag == I2C_RECV_CONTROL_FLAG, flag, 0, 0);
-
-		status = osMessageQueueGet(i2c_recv_msgqueue, &msg, 0 , osWaitForever);
-		if(status == osOK)
-		{
-
-		      mask = SaveAndSetIRQMask();
-			//handle data
-			//I2CEvtProcess(msg.event);
-#ifdef USING_PRINTF
-			printf("[%d]i2c recv event\r\n",__LINE__);
-#else				
-    			ECOMM_TRACE(UNILOG_PLA_DRIVER, I2C_GSENSOR_D, P_INFO, 0, "i2c recv event");
-#endif
-			RestoreIRQMask(mask);  
-		}
-	}
-
-}
-static void HAL_I2C_CreateRecvTaskAndQueue(void)
-{
-	if(g_halI2CInitFlag & HAL_I2C_RECV_TASK_QUEUE_CREATED)
-	{
-		return;
-	}
-	/*
-	    for task create
-	*/
-	osThreadId_t threadId;
-	
-	osThreadAttr_t task_attr;
-	/*for msg queue create*/
-	osMessageQueueAttr_t queue_attr;
-	
-	g_i2CRecvFlag =  osEventFlagsNew(NULL);
-
-   	EC_ASSERT(g_i2CRecvFlag, g_i2CRecvFlag, 0, 0);
-
-	memset(&queue_attr, 0, sizeof(queue_attr));
-	queue_attr.cb_mem = &i2c_recv_queue_cb;
-	queue_attr.cb_size    = sizeof(i2c_recv_queue_cb);
-	queue_attr.mq_mem  = i2c_recv_queue_buf;
-	queue_attr.mq_size   = sizeof(i2c_recv_queue_buf);
-
-	i2c_recv_msgqueue = osMessageQueueNew(I2C_RECV_QUEUE_BUF_SIZE,sizeof(i2c_recv_msgqueue_obj_t), &queue_attr);
-	EC_ASSERT(i2c_recv_msgqueue, i2c_recv_msgqueue, 0, 0);
-
-	memset(& task_attr, 0, sizeof(task_attr));
-	memset(i2c_recv_task_stack, 0xA5, I2C_RECV_TASK_STACK_SIZE);
-
-	task_attr.name = "GsensorRecv";
-	task_attr.stack_size = I2C_RECV_TASK_STACK_SIZE;
-	task_attr.stack_mem = i2c_recv_task_stack;
-	task_attr.priority = osPriorityNormal;
-	task_attr.cb_mem = &i2c_recv_task;
-	task_attr.cb_size = sizeof(StaticTask_t);
-
-	threadId =  osThreadNew(HAL_I2C_RecvTaskEntry, NULL, &task_attr);
-
-	EC_ASSERT(threadId, threadId, 0, 0);
-	
-	g_halI2CInitFlag |=  HAL_I2C_RECV_TASK_QUEUE_CREATED;
-	
-}
-/**
-  \fn         void GsensorI2CCallback(uint32_t event)
-  \param[in]  event   : i2c irq event
-  \brief        i2c irq event ,callback function
-  \return      
-*/
-void GsensorI2CHandler(ARM_I2C_SignalEvent_t cb_event)
-{
-    // Initialize with callback
-     i2cDrvInstance->Initialize(cb_event);
-    // Power on
-     i2cDrvInstance->PowerControl(ARM_POWER_FULL);
-     // Configure I2C bus
-     i2cDrvInstance->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_STANDARD);
-     i2cDrvInstance->Control(ARM_I2C_BUS_CLEAR, 0);
-     HAL_I2C_CreateRecvTaskAndQueue();	 
-#ifdef USING_PRINTF
-   printf("[%d] i2c config ok\r\n",__LINE__);
-#else	 
-     ECOMM_TRACE(UNILOG_PLA_DRIVER, I2C_GSENSOR_I, P_INFO, 0, "i2c config ok");
-#endif
-}
-/**
-  \fn    void GpsDataRecvCallback(uint32_t event, void* dataPtr, uint32_t dataLen)
-  \param[in]  event   :Data receiving timeout processing and data receiving completion processing;
-  \		    dataPtr : Point to receive data buff
-  \		    dataLen : Received data length	
-  \brief        i2c irq event ,callback function
-  \return      
-*/
-void GpsDataRecvCallback(UINT32 event, void* dataPtr, UINT32 dataLen)
-{
-    UINT8 GPS[256];
-    slpManStartWaitATTimer(); 
-   if((event == ARM_USART_EVENT_RX_TIMEOUT) || (event == ARM_USART_EVENT_RECEIVE_COMPLETE))
-    {
-        //parse data
-         memcpy(GPS, dataPtr, dataLen);
-	   gGPSDataCBfunc(dataLen,GPS);
-#if 0	   
-#ifdef USING_PRINTF	
-	printf("GPS:len=%d,data=%s\r\n",datalen,GPS);
-#else
-       ECOMM_STRING(UNILOG_PLA_STRING, GPS_RECV_DATA, P_INFO, "GPS:%s", GPS);
-#endif
-#endif
-    }
-}
-/**
-  \fn     void GPSUsartHandler(ARM_DRIVER_USART * uartDriverHandler, uint32_t baudRate)
-  \param[in]  baudRate for gps usart port;
-  \brief       config gps usart port
-  \return      
-*/
-void GPSUsartHandler(UINT32 baudRate)
-{
-	hal_uart_config_t halUartConfig = {0};
-
-	hal_uart_hardware_config_t hwConfig = {
-	                                        ARM_POWER_FULL,
-	                                        ARM_USART_MODE_ASYNCHRONOUS | ARM_USART_DATA_BITS_8 |
-	                                        ARM_USART_PARITY_NONE       | ARM_USART_STOP_BITS_1 |
-	                                        ARM_USART_FLOW_CONTROL_NONE,
-	                                        baudRate
-	                                       };
-
-
-
-	halUartConfig.uartDriverHandler = usartHandle;
-	halUartConfig.recv_cb = GpsDataRecvCallback;
-	halUartConfig.recvBuffPtr = gps_uart_recv_buf;
-	halUartConfig.recvBuffSize = GPS_DATA_RECV_BUFFER_SIZE;
-	HAL_UART_InitHandler(PORT_USART_2, &halUartConfig, &hwConfig, HAL_UART_TASK_CREATE_FLAG_SEND_RECV);
-
-}
-
-/**
-  \fn  INT32 AdcSendReq(UINT32 req,UINT32 * param ,UINT32 timeout)
-  \param[in]  req : ADC_REQ_BITMAP_VBAT ADC_REQ_BITMAP_TEMP; timeout = 0 at irq ,otherwize equal to ADC_MSG_TIMEOUT
-  \brief     return bat value ,trigger deinit
-  \return    1 FAIL  , 0 OK
-*/
-INT32 AdcSendReq(UINT32 req,UINT32 * param , UINT8 len ,UINT32 timeout)
-{
-    INT32 ret;
-    adcReqMsg ReqMsg;
-	
-    ReqMsg.request = req;
-    ReqMsg.param[NTC_Channel1] =   ReqMsg.param[NTC_Channel2] =  ReqMsg.param[NTC_Channel3] =  ReqMsg.param[NTC_Channel4] =  ReqMsg.param[NTC_Channel5] =ADC_AioResDivRatio10Over16  ;
-    ret = osMessageQueuePut(adcMsgHandle, &ReqMsg, 0, timeout);
-
-    if(ret != osOK)
-    {
-        return ret;
-    }
-    else
-    {
-  	 ret = osEventFlagsWait(adcTrigerHandle, ADC_RECV_CONTROL_FLAG, osFlagsWaitAll, timeout);
-	   //to do 	  
-	  switch(req)
-	  {
-		case ADC_REQ_BITMAP_VBAT:
-		param[0] = gNtcDev.NTCvalue[0];
-		break;
-	      case ADC_REQ_BITMAP_TEMP:
- 		param[0] = gNtcDev.NTCvalue[1];
-		break;
-		case ADC_REQ_BITMAP_CH1:
-		param[0] = gNtcDev.NTCvalue[2+NTC_Channel1];	
-		break;
-		case ADC_REQ_BITMAP_CH2:
-		param[0] = gNtcDev.NTCvalue[2+NTC_Channel2];	
-		break;
-		case ADC_REQ_BITMAP_CH3:
-		param[0] = gNtcDev.NTCvalue[2+NTC_Channel3];	
-		break;
-		case ADC_REQ_BITMAP_CH4:
-		param[0] = gNtcDev.NTCvalue[2+NTC_Channel4];	
-		break;
-		case ADC_REQ_BITMAP_CH5:
-		param[0] = gNtcDev.NTCvalue[2+NTC_Channel5];	
-		break;
-	  }
-	  osEventFlagsClear(adcTrigerHandle, ADC_RECV_CONTROL_FLAG);
-        return ret;
-    }
-}
-/**
-  \fn   static void ADC_VbatChannelCallback(uint32_t result)
-  \param[in]  
-  \brief     return bat value ,trigger deinit
-  \return      
-*/
-static void ADC_VbatChannelCallback(uint32_t result)
-{
-    vbatChannelResult = result;
-    osEventFlagsSet(adcEvtHandle, ADC_REQ_BITMAP_VBAT);
-}
-/**
-  \fn   static void ADC_ThermalChannelCallback(uint32_t result)
-  \param[in]  
-  \brief     return thermal value ,trigger deinit
-  \return      
-*/
-static void ADC_ThermalChannelCallback(uint32_t result)
-{
-    thermalChannelResult = result;
-    osEventFlagsSet(adcEvtHandle, ADC_REQ_BITMAP_TEMP);
-}
-
-static void ADC_NTC1ChannelCallback(uint32_t result)
-{
-    NTCChannelResult[NTC_Channel1] = result;
-    osEventFlagsSet(adcEvtHandle, ADC_REQ_BITMAP_CH1);
-}
-static void ADC_NTC2ChannelCallback(uint32_t result)
-{
-    NTCChannelResult[NTC_Channel2] = result;
-    osEventFlagsSet(adcEvtHandle, ADC_REQ_BITMAP_CH2);
-}
-static void ADC_NTC3ChannelCallback(uint32_t result)
-{
-    NTCChannelResult[NTC_Channel3] = result;
-    osEventFlagsSet(adcEvtHandle, ADC_REQ_BITMAP_CH3);
-}
-static void ADC_NTC4OR5ChannelCallback(uint32_t result)
-{
-    if(gNtcDev.flagC4){
-	    NTCChannelResult[NTC_Channel4] = result;
-	    osEventFlagsSet(adcEvtHandle, ADC_REQ_BITMAP_CH4);
-    }else{
-	    NTCChannelResult[NTC_Channel5] = result;
-	    osEventFlagsSet(adcEvtHandle, ADC_REQ_BITMAP_CH5);
-    }
-}
-
-/**
-  \fn   void AdcProcess(void* arg)
-  \param[in]  
-  \brief       handle adc init ,deinit and convert process
-  \return      
-*/
-static void AdcProcess(void* arg)
-{
-    adcReqMsg regMsg;
-    INT32 ret;
-
-    while(1)
-    {
-    	/*
-		
-	*/
-	 osMessageQueueGet(adcMsgHandle, &regMsg, 0, osWaitForever);
-	 /*
-			handle event
-	 */
-	adc_config_t adcConfig;
-
-	ADC_GetDefaultConfig(&adcConfig);
-
-	osEventFlagsClear(adcEvtHandle, regMsg.request);
-
-	if(regMsg.request & ADC_REQ_BITMAP_VBAT)
-	{
-		adcConfig.channelConfig.vbatResDiv = ADC_VbatResDivRatio3Over16;
-		ADC_ChannelInit(ADC_ChannelVbat, ADC_UserAPP, &adcConfig, ADC_VbatChannelCallback);
-		ADC_StartConversion(ADC_ChannelVbat, ADC_UserAPP);
-	}
-
-	if(regMsg.request & ADC_REQ_BITMAP_TEMP)
-	{
-		adcConfig.channelConfig.thermalInput = ADC_ThermalInputVbat;
-		ADC_ChannelInit(ADC_ChannelThermal, ADC_UserAPP, &adcConfig, ADC_ThermalChannelCallback);
-		ADC_StartConversion(ADC_ChannelThermal, ADC_UserAPP);
-	}
-
-	if(regMsg.request & ADC_REQ_BITMAP_CH1)
-	{
-		if(regMsg.param[NTC_Channel1]>=ADC_AioResDivRatio1 && regMsg.param[NTC_Channel1]<=ADC_AioResDivRatio1Over16){
-			adcConfig.channelConfig.aioResDiv = regMsg.param[NTC_Channel1];
-		}else{
-			adcConfig.channelConfig.aioResDiv = ADC_AioResDivRatioDefault;
-		}
-	  	ADC_ChannelInit(ADC_ChannelAio1, ADC_UserAPP, &adcConfig, ADC_NTC1ChannelCallback);
-	  	ADC_StartConversion(ADC_ChannelAio1, ADC_UserAPP);
-	}
-	
-	if(regMsg.request & ADC_REQ_BITMAP_CH2)
-	{
-		if(regMsg.param[NTC_Channel2]>=ADC_AioResDivRatio1 && regMsg.param[NTC_Channel2]<=ADC_AioResDivRatio1Over16){
-			adcConfig.channelConfig.aioResDiv = regMsg.param[NTC_Channel2];
-		}else{
-			adcConfig.channelConfig.aioResDiv = ADC_AioResDivRatioDefault;
-		}
-		ADC_ChannelInit(ADC_ChannelAio2, ADC_UserAPP, &adcConfig, ADC_NTC2ChannelCallback);
-		ADC_StartConversion(ADC_ChannelAio2, ADC_UserAPP);
-	}
-	
-	if(regMsg.request & ADC_REQ_BITMAP_CH3)
-	{
-		if(regMsg.param[NTC_Channel3]>=ADC_AioResDivRatio1 && regMsg.param[NTC_Channel3]<=ADC_AioResDivRatio1Over16){
-			adcConfig.channelConfig.aioResDiv = regMsg.param[NTC_Channel3];
-		}else{
-			adcConfig.channelConfig.aioResDiv = ADC_AioResDivRatioDefault;
-		}
-		ADC_ChannelInit(ADC_ChannelAio3, ADC_UserAPP, &adcConfig, ADC_NTC3ChannelCallback);
-		ADC_StartConversion(ADC_ChannelAio3, ADC_UserAPP);
-	}
-	if(regMsg.request & ADC_REQ_BITMAP_CH4 ||regMsg.request & ADC_REQ_BITMAP_CH5)
-	{
-		if(regMsg.request & ADC_REQ_BITMAP_CH4){
-			gNtcDev.flagC4 = 1;
-			GPIO_PinWrite(0, 1, 1);
-			
-			if(regMsg.param[NTC_Channel4]>=ADC_AioResDivRatio1 && regMsg.param[NTC_Channel4]<=ADC_AioResDivRatio1Over16){
-				adcConfig.channelConfig.aioResDiv = regMsg.param[NTC_Channel4];
-			}else{
-				adcConfig.channelConfig.aioResDiv = ADC_AioResDivRatioDefault;
-			}
-
-			
-		}else{
-			GPIO_PinWrite(0, 1, 0);
-			gNtcDev.flagC4 = 0;
-			if(regMsg.param[NTC_Channel5]>=ADC_AioResDivRatio1 && regMsg.param[NTC_Channel5]<=ADC_AioResDivRatio1Over16){
-				adcConfig.channelConfig.aioResDiv = regMsg.param[NTC_Channel5];
-			}else{
-				adcConfig.channelConfig.aioResDiv = ADC_AioResDivRatioDefault;
-			}
-
-		}
-		ADC_ChannelInit(ADC_ChannelAio4, ADC_UserAPP, &adcConfig, ADC_NTC4OR5ChannelCallback);
-		ADC_StartConversion(ADC_ChannelAio4, ADC_UserAPP);
-	}
-	
-	ret = osEventFlagsWait(adcEvtHandle, regMsg.request, osFlagsWaitAll, ADC_GET_RESULT_TIMOUT);
-
-	if(regMsg.request & ADC_REQ_BITMAP_VBAT)
-	{
-	    ADC_ChannelDeInit(ADC_ChannelVbat, ADC_UserAPP);
-	   gNtcDev.NTCvalue[0] = HAL_ADC_CalibrateRawCode(vbatChannelResult) * 16 / 3;
-	}
-
-	if(regMsg.request & ADC_REQ_BITMAP_TEMP)
-	{
-	    ADC_ChannelDeInit(ADC_ChannelThermal, ADC_UserAPP);
-	    gNtcDev.NTCvalue[1] = HAL_ADC_ConvertThermalRawCodeToTemperature(thermalChannelResult);
-	}
-
-	if(regMsg.request & ADC_REQ_BITMAP_CH1)
-	{
-	 	ADC_ChannelDeInit(ADC_ChannelAio1, ADC_UserAPP);
-		gNtcDev.NTCvalue[2+NTC_Channel1]= HAL_ADC_CalibrateRawCode(NTCChannelResult[NTC_Channel1])*REV_AioResDivRatioDefault;
-	}
-	if(regMsg.request & ADC_REQ_BITMAP_CH2)
-	{
-		ADC_ChannelDeInit(ADC_ChannelAio2, ADC_UserAPP);
-		gNtcDev.NTCvalue[2+NTC_Channel2]= HAL_ADC_CalibrateRawCode(NTCChannelResult[NTC_Channel2])*REV_AioResDivRatioDefault;
-	}
-	if(regMsg.request & ADC_REQ_BITMAP_CH3)
-	{
-		ADC_ChannelDeInit(ADC_ChannelAio3, ADC_UserAPP);
-		gNtcDev.NTCvalue[2+NTC_Channel3]= HAL_ADC_CalibrateRawCode(NTCChannelResult[NTC_Channel3])*REV_AioResDivRatioDefault;
-	}
-	if(regMsg.request & ADC_REQ_BITMAP_CH4 ||regMsg.request & ADC_REQ_BITMAP_CH5)
-	{
-		ADC_ChannelDeInit(ADC_ChannelAio4, ADC_UserAPP);
-		if(gNtcDev.flagC4){
-			gNtcDev.NTCvalue[2+NTC_Channel4]= HAL_ADC_CalibrateRawCode(NTCChannelResult[NTC_Channel4])*REV_AioResDivRatioDefault;
-		}else{
-			gNtcDev.NTCvalue[2+NTC_Channel5]= HAL_ADC_CalibrateRawCode(NTCChannelResult[NTC_Channel5])*REV_AioResDivRatioDefault;
-		}
-	}
-	 osEventFlagsSet(adcTrigerHandle, ADC_RECV_CONTROL_FLAG);
-	  	
-    }
-}
-
-/**
-  \fn    INT32 AdcTaskInit(void)
-  \param[in]  
-  \brief       create task for checking bat level
-  \return      
-*/
-INT32 AdcTaskInit(void)
-{
-	gpio_pin_config_t config;
-	config.pinDirection = GPIO_DirectionOutput;
-	config.misc.initOutput = 1;
-	pad_config_t padConfig;
-	PAD_GetDefaultConfig(&padConfig);
-
-	padConfig.mux = PAD_MuxAlt0;
-	PAD_SetPinConfig(11, &padConfig);
-		
-	GPIO_PinConfig(0, 0, &config);
-	GPIO_PinWrite(0, 1, 1);
-	memset(&gNtcDev , 0 ,sizeof(NtcResult_t));
-	
-	if(adcMsgHandle == NULL)
-	{
-		adcMsgHandle = osMessageQueueNew(ADC_MSG_MAX_NUM,sizeof(adcReqMsg), NULL);
-		if(adcMsgHandle == NULL)
-			return 1;
-	}
-
-	if(adcTrigerHandle == NULL)
-	{
-		adcTrigerHandle = osEventFlagsNew(NULL);
-		if(adcTrigerHandle == NULL)
-			return 1;
-	}
-	if(adcEvtHandle == NULL)
-	{
-		adcEvtHandle = osEventFlagsNew(NULL);
-		if(adcEvtHandle == NULL)
-			return 1;
-	}
-
-	if(adcTaskHandle == NULL)
-	{
-		osThreadAttr_t task_attr;
-		memset(&task_attr , 0 , sizeof(task_attr));
-		task_attr.name = "batAdc";
-		task_attr.priority = osPriorityNormal1;
-		task_attr.cb_mem = &adcTask;
-		task_attr.cb_size = sizeof(StaticTask_t);
-		task_attr.stack_mem = adcTaskStack;
-		task_attr.stack_size =ADC_TASK_STACK_SIZE;
-		memset(& adcTaskStack, 0xa5, ADC_TASK_STACK_SIZE);
-		adcTaskHandle = osThreadNew(AdcProcess , NULL,&task_attr);
-		if(adcTaskHandle == NULL)
-			return 1;
-	}
-	
-	return 0;
-}
-/**
-  \fn   void PowerPinConfig(IOType iotype)
-  \param[in]  
-  \brief    config PWR pin to gpiol
-  \return      
-*/
-void PowerPinConfig(IOType iotype)
-{
-	gpio_pin_config_t config;
-	config.pinDirection = GPIO_DirectionOutput;
-	config.misc.initOutput = 1;
-
-	pad_config_t padConfig;
-	PAD_GetDefaultConfig(&padConfig);
-	
-	
-	
-      if(iotype == AON_IO)
-	{
-		padConfig.mux = PAD_MuxAlt0;
-		
-		PAD_SetPinConfig(31, &padConfig);
-		GPIO_PinConfig(1, AON_GPS_POWER2, &config);
-		GPIO_PinWrite(1, 1 << AON_GPS_POWER2, 0);
-
-		PAD_SetPinConfig(32, &padConfig);
-		GPIO_PinConfig(1, AON_RELAY_DRV, &config);
-		GPIO_PinWrite(1, 1 << AON_RELAY_DRV, 1 << AON_RELAY_DRV);
-
-		PAD_SetPinConfig(35, &padConfig);
-		GPIO_PinConfig(1, AON_WAKEUP, &config);
-		GPIO_PinWrite(1, 1 << AON_WAKEUP, 1 << AON_WAKEUP);
-
-		padConfig.mux = PAD_MuxAlt7;
-		PAD_SetPinConfig(5, &padConfig);
-	
-		GPIO_PinConfig(1, FEM_GPS_RSTN, &config);
-		GPIO_PinWrite(1, 1 << FEM_GPS_RSTN, 1 << FEM_GPS_RSTN);
-#if 1		
-		padConfig.mux = PAD_MuxAlt7;
-		padConfig.pullSelect = PAD_PullInternal;
-		padConfig.pullUpEnable = PAD_PullUpEnable;
-		padConfig.pullDownEnable = PAD_PullDownDisable;
-		PAD_SetPinConfig(8, &padConfig);
-		
-		config.pinDirection = GPIO_DirectionInput;
-       	config.misc.initOutput = 0;
-		GPIO_PinConfig(1, FEM_GPS_PPS, &config);
-#else
-		padConfig.mux = PAD_MuxAlt7;
-		PAD_SetPinConfig(8, &padConfig);
-		GPIO_PinWrite(1, 1 << FEM_GPS_PPS, 1 << FEM_GPS_PPS);
-#endif
-	
-      	}
-	else
-	{
-	      	/*Normal IO*/
-#if 0			
-		GPIO_PinConfig(0, GPIO_MOS_DRV1, &config);
-		GPIO_PinWrite(0, 1 << GPIO_MOS_DRV1, 1 << GPIO_MOS_DRV1);
-		
-		GPIO_PinConfig(0, GPIO_MOS_DRV2, &config);
-		GPIO_PinWrite(0, 1 << GPIO_MOS_DRV2, 1 << GPIO_MOS_DRV2);
-#endif		
-		padConfig.mux = PAD_MuxAlt0;
-		PAD_SetPinConfig(28, &padConfig);
-		GPIO_PinConfig(0, GPIO_POWER_LED, &config);
-		GPIO_PinWrite(0, 1 << GPIO_POWER_LED, 1 << GPIO_POWER_LED);
-      	}
-}
-/**
-  \fn   void posGGAReset(void)
-  \param[in]  
-  \brief    reset gps
-  \return      
-*/
-void posGGAReset(void)
-{
-	gpio_pin_config_t config;
-	config.pinDirection = GPIO_DirectionOutput;
-	config.misc.initOutput = 1;
-	pad_config_t padConfig;
-	PAD_GetDefaultConfig(&padConfig);
-
-	padConfig.mux = PAD_MuxAlt7;
-	PAD_SetPinConfig(5, &padConfig);
-		
-	GPIO_PinConfig(1, FEM_GPS_RSTN, &config);
-	GPIO_PinWrite(1, 1 << FEM_GPS_RSTN, 0);
-	
-	osDelay(1000/portTICK_PERIOD_MS);
-	
-	GPIO_PinConfig(1, FEM_GPS_RSTN, &config);
-	GPIO_PinWrite(1, 1 << FEM_GPS_RSTN, 1 << FEM_GPS_RSTN);
-	
-}
-/**
-  \fn   void GPSPowerCtr(bool )
-  \param[in]  
-  \brief    reset gps
-  \return      
-*/
-void GPSPowerCtr(bool on)
-{
-	gpio_pin_config_t config;
-	config.pinDirection = GPIO_DirectionOutput;
-	config.misc.initOutput = 1;
-
-	pad_config_t padConfig;
-	PAD_GetDefaultConfig(&padConfig);
-
-
-	padConfig.mux = PAD_MuxAlt0;
-
-	PAD_SetPinConfig(31, &padConfig);
-	GPIO_PinConfig(1, AON_GPS_POWER2, &config);
-	if(on){
-		GPIO_PinWrite(1, 1 << AON_GPS_POWER2, 0);
-	}else{
-		GPIO_PinWrite(1, 1 << AON_GPS_POWER2, 1<<AON_GPS_POWER2);
-	}
-}
-/**
-  \fn   void posGGAServiceStart(posGGACallBack )
-  \param[in]  
-  \brief    powr on gps
-  \return      
-*/
-INT32 posGGAServiceStart( posGGACallBack callBack)
-{
-	if(callBack == NULL){
-		return -1;
-	}else{
-		GPSPowerCtr(true);
-		GPSUsartHandler(9600);
-		gGPSDataCBfunc = callBack;
-		return 0;
-	}
-}
-/**
-  \fn   void posGGAServiceStop(void )
-  \param[in]  
-  \brief    stop gps
-  \return      
-*/
-void posGGAServiceStop( void)
-{	
-	HAL_UART_DeInitHandler(PORT_USART_2);
-	GPSPowerCtr(false);
-	gGPSDataCBfunc = NULL;
-}

+ 241 - 0
inc/RTE_Device.h

@@ -0,0 +1,241 @@
+#ifndef __RTE_DEVICE_H
+#define __RTE_DEVICE_H
+
+#include "ec616.h"
+
+/*  Peripheral IO Mode Select, Must Configure First !!!
+    Note, when receiver works in DMA_MODE, interrupt is also enabled to transfer tailing bytes.
+*/
+
+#define POLLING_MODE            	0x1
+#define DMA_MODE                		0x2
+#define IRQ_MODE                		0x3
+#define UNILOG_MODE            		0x4
+
+#define RTE_UART0_TX_IO_MODE    UNILOG_MODE
+#define RTE_UART0_RX_IO_MODE    DMA_MODE
+
+#define RTE_UART1_TX_IO_MODE    POLLING_MODE
+#define RTE_UART1_RX_IO_MODE    DMA_MODE
+
+#define RTE_UART2_TX_IO_MODE    POLLING_MODE
+#define RTE_UART2_RX_IO_MODE    DMA_MODE
+
+#define RTE_SPI0_IO_MODE           POLLING_MODE
+
+#define RTE_SPI1_IO_MODE           POLLING_MODE
+
+#define I2C0_INIT_MODE               POLLING_MODE
+#define I2C1_INIT_MODE               POLLING_MODE
+
+
+// I2C0 (Inter-integrated Circuit Interface) [Driver_I2C0]
+// Configuration settings for Driver_I2C0 in component ::Drivers:I2C
+#define RTE_I2C0                        1
+
+// { PAD_PIN25},  // 0 : gpio10 / 1 : I2C0 SCL
+// { PAD_PIN26},  // 0 : gpio8  / 1 : I2C0 SDA
+#define RTE_I2C0_SCL_BIT                25
+#define RTE_I2C0_SCL_FUNC               PAD_MuxAlt1
+
+#define RTE_I2C0_SDA_BIT                26
+#define RTE_I2C0_SDA_FUNC               PAD_MuxAlt1
+
+// DMA
+//   Tx
+//     Channel     <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
+#define RTE_I2C0_DMA_TX_EN              0
+#define RTE_I2C0_DMA_TX_REQID           DMA_RequestI2C0TX
+//   Rx
+//     Channel     <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
+#define RTE_I2C0_DMA_RX_EN              0
+#define RTE_I2C0_DMA_RX_REQID           DMA_RequestI2C0RX
+
+// I2C1 (Inter-integrated Circuit Interface) [Driver_I2C1]
+// Configuration settings for Driver_I2C1 in component ::Drivers:I2C
+#define RTE_I2C1                        0
+
+// { PAD_PIN27},  // 0 : gpio17 / 1 : I2C1 SCL
+// { PAD_PIN28},  // 0 : gpio9  / 1 : I2C1 SDA
+#define RTE_I2C1_SCL_BIT                27
+#define RTE_I2C1_SCL_FUNC               PAD_MuxAlt1
+
+#define RTE_I2C1_SDA_BIT                28
+#define RTE_I2C1_SDA_FUNC               PAD_MuxAlt1
+
+// DMA
+//   Tx
+//     Channel     <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
+#define RTE_I2C1_DMA_TX_EN              1
+#define RTE_I2C1_DMA_TX_REQID           DMA_RequestI2C1TX
+//   Rx
+//     Channel     <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
+#define RTE_I2C1_DMA_RX_EN              1
+#define RTE_I2C1_DMA_RX_REQID           DMA_RequestI2C1RX
+
+
+// UART0 (Universal asynchronous receiver transmitter) [Driver_USART0]
+// Configuration settings for Driver_USART0 in component ::Drivers:USART
+#define RTE_UART0                       1
+#define RTE_UART0_CTS_PIN_EN            0
+#define RTE_UART0_RTS_PIN_EN            0
+#if 1
+// { PAD_PIN23},  // 0 : gpio14 / 1 : UART1 RXD  / 2 :SPI0_MISO /3 : UART0_RXD
+// { PAD_PIN24},  // 0 : gpio15 / 1 : UART1 TXD  / 2: SPI0_SCLK /3 : UART0_TXD
+#define RTE_UART0_RX_BIT                23
+#define RTE_UART0_RX_FUNC               PAD_MuxAlt3
+
+#define RTE_UART0_TX_BIT                24
+#define RTE_UART0_TX_FUNC               PAD_MuxAlt3
+#else
+// { PAD_PIN13},  // 0 : gpio2 / 1 : UART0 RTSn / 3 : SPI1 SSn
+// { PAD_PIN14},  // 0 : gpio3 / 1 : UART0 CTSn / 3 : SPI1 MOSI
+// { PAD_PIN15},  // 0 : gpio4 / 1 : UART0 RXD  / 3 : SPI1 MISO
+// { PAD_PIN16},  // 0 : gpio5 / 1 : UART0 TXD  / 3 : SPI1 SCLK
+#define RTE_UART0_RTS_BIT               13
+#define RTE_UART0_RTS_FUNC              PAD_MuxAlt1
+
+#define RTE_UART0_CTS_BIT               14
+#define RTE_UART0_CTS_FUNC              PAD_MuxAlt1
+
+#define RTE_UART0_RX_BIT                15
+#define RTE_UART0_RX_FUNC               PAD_MuxAlt1
+
+#define RTE_UART0_TX_BIT                16
+#define RTE_UART0_TX_FUNC               PAD_MuxAlt1
+#endif
+
+// DMA
+//  Tx
+//    Channel     <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
+#define RTE_UART0_DMA_TX_REQID          DMA_RequestUSART0TX
+//  Rx
+//    Channel    <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
+#define RTE_UART0_DMA_RX_REQID          DMA_RequestUSART0RX
+
+// UART1 (Universal asynchronous receiver transmitter) [Driver_USART1]
+// Configuration settings for Driver_USART1 in component ::Drivers:USART
+#define RTE_UART1                       1
+#define RTE_UART1_CTS_PIN_EN            0
+#define RTE_UART1_RTS_PIN_EN            0
+// { PAD_PIN17},  // 0 : gpio6   / 3 : UART1 RTS
+// { PAD_PIN18},  // 0 : gpio7   / 3 : UART1 CTS
+// { PAD_PIN19},  // 0 : gpio13  / 3 : UART1 RXD
+// { PAD_PIN20},  // 0 : gpio12  / 3 : UART1 TXD
+#define RTE_UART1_RTS_BIT               17
+#define RTE_UART1_RTS_FUNC              PAD_MuxAlt3
+
+#define RTE_UART1_CTS_BIT               18
+#define RTE_UART1_CTS_FUNC              PAD_MuxAlt3
+
+#define RTE_UART1_RX_BIT                19
+#define RTE_UART1_RX_FUNC               PAD_MuxAlt3
+
+#define RTE_UART1_TX_BIT                20
+#define RTE_UART1_TX_FUNC               PAD_MuxAlt3
+
+// DMA
+//   Tx
+//     Channel     <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
+#define RTE_UART1_DMA_TX_REQID          DMA_RequestUSART1TX
+//   Rx
+//     Channel    <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
+#define RTE_UART1_DMA_RX_REQID          DMA_RequestUSART1RX
+
+// UART2 (Universal asynchronous receiver transmitter) [Driver_USART2]
+// Configuration settings for Driver_USART2 in component ::Drivers:USART
+#define RTE_UART2                       1
+#define RTE_UART2_CTS_PIN_EN            0
+#define RTE_UART2_RTS_PIN_EN            0
+
+// { PAD_PIN29},  // 0 : gpio18 / 1 : UART2 RXD
+// { PAD_PIN30},  // 0 : gpio19 / 1 : UART2 TXD
+#define RTE_UART2_RX_BIT                29
+#define RTE_UART2_RX_FUNC               PAD_MuxAlt1
+
+#define RTE_UART2_TX_BIT                30
+#define RTE_UART2_TX_FUNC               PAD_MuxAlt1
+
+
+// DMA
+//   Tx
+//     Channel     <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
+#define RTE_UART2_DMA_TX_REQID          DMA_RequestUSART2TX
+//   Rx
+//     Channel    <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
+#define RTE_UART2_DMA_RX_REQID          DMA_RequestUSART2RX
+
+// SPI0 (Serial Peripheral Interface) [Driver_SPI0]
+// Configuration settings for Driver_SPI0 in component ::Drivers:SPI
+#define RTE_SPI0                        0
+
+// { PAD_PIN21},  // 0 : gpio16 / 1 : UART1 RTS / 2 : SPI0 SSn
+// { PAD_PIN22},  // 0 : gpio11 / 1 : UART1 CTS / 2 : SPI0 MOSI
+// { PAD_PIN23},  // 0 : gpio14 / 1 : UART1 RXD / 2 : SPI0 MISO
+// { PAD_PIN24},  // 0 : gpio15 / 1 : UART1 TXD / 2 : SPI0 SCLK
+#define RTE_SPI0_SSN_BIT                21
+#define RTE_SPI0_SSN_FUNC               PAD_MuxAlt2
+
+#define RTE_SPI0_MOSI_BIT               22
+#define RTE_SPI0_MOSI_FUNC              PAD_MuxAlt2
+
+#define RTE_SPI0_MISO_BIT               23
+#define RTE_SPI0_MISO_FUNC              PAD_MuxAlt2
+
+#define RTE_SPI0_SCLK_BIT               24
+#define RTE_SPI0_SCLK_FUNC              PAD_MuxAlt2
+
+#define RTE_SPI0_SSN_GPIO_INSTANCE      1
+#define RTE_SPI0_SSN_GPIO_INDEX         0
+
+// DMA
+//   Tx
+//     Channel     <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
+#define RTE_SPI0_DMA_TX_REQID           DMA_RequestSPI0TX
+
+//   Rx
+//     Channel     <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
+#define RTE_SPI0_DMA_RX_REQID           DMA_RequestSPI0RX
+
+// SPI1 (Serial Peripheral Interface) [Driver_SPI1]
+// Configuration settings for Driver_SPI1 in component ::Drivers:SPI
+#define RTE_SPI1                        1
+
+// { PAD_PIN13},  // 0 : gpio2 / 1 : UART0 RTSn / 3 : SPI1 SSn
+// { PAD_PIN14},  // 0 : gpio3 / 1 : UART0 CTSn / 3 : SPI1 MOSI
+// { PAD_PIN15},  // 0 : gpio4 / 1 : UART0 RXD  / 3 : SPI1 MISO
+// { PAD_PIN16},  // 0 : gpio5 / 1 : UART0 TXD  / 3 : SPI1 SCLK
+#define RTE_SPI1_SSN_BIT                13
+#define RTE_SPI1_SSN_FUNC               PAD_MuxAlt3
+
+#define RTE_SPI1_MOSI_BIT               14
+#define RTE_SPI1_MOSI_FUNC              PAD_MuxAlt3
+
+#define RTE_SPI1_MISO_BIT               15
+#define RTE_SPI1_MISO_FUNC              PAD_MuxAlt3
+
+#define RTE_SPI1_SCLK_BIT               16
+#define RTE_SPI1_SCLK_FUNC              PAD_MuxAlt3
+
+#define RTE_SPI1_SSN_GPIO_INSTANCE      0
+#define RTE_SPI1_SSN_GPIO_INDEX         2
+
+// DMA
+//   Tx
+//     Channel     <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
+#define RTE_SPI1_DMA_TX_REQID           DMA_RequestSPI1TX
+
+//   Rx
+//     Channel     <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
+#define RTE_SPI1_DMA_RX_REQID           DMA_RequestSPI1RX
+
+
+// PWM0 Controller [Driver_PWM0]
+// Configuration settings for Driver_PWM0 in component ::Drivers:PWM
+#define RTE_PWM                         1
+
+#define EFUSE_INIT_MODE POLLING_MODE
+
+#define FLASH_BARE_RW_MODE 1
+
+#endif  /* __RTE_DEVICE_H */

+ 58 - 0
inc/app.h

@@ -0,0 +1,58 @@
+/****************************************************************************
+ *
+ * Copy right:   2017-, Copyrigths of EigenComm Ltd.
+ * File name:    app.h
+ * Description:  EC616 onenet demo entry header file
+ * History:      Rev1.0   2018-07-12
+ *
+ ****************************************************************************/
+#ifndef  APP_H
+#define  APP_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "cisAsynEntry.h"
+
+// #define QMSG_ID_BASE               (0x160) 
+// #define QMSG_ID_NW_IPV4_READY      (QMSG_ID_BASE)
+// #define QMSG_ID_NW_IPV6_READY      (QMSG_ID_BASE + 1)
+// #define QMSG_ID_NW_IPV4_6_READY    (QMSG_ID_BASE + 2)
+// #define QMSG_ID_NW_DISCONNECT      (QMSG_ID_BASE + 3)
+// #define QMSG_ID_SOCK_SENDPKG       (QMSG_ID_BASE + 4)
+// #define QMSG_ID_SOCK_RECVPKG       (QMSG_ID_BASE + 5)
+
+#define QMSG_ID_BASE               (0x160) 
+#define QMSG_ID_NW_IP_READY        (QMSG_ID_BASE)
+#define QMSG_ID_NW_IP_SUSPEND      (QMSG_ID_BASE + 1)
+#define QMSG_ID_NW_IP_NOREACHABLE  (QMSG_ID_BASE + 2)
+#define QMSG_ID_SOCK_SENDPKG       (QMSG_ID_BASE + 4)
+#define QMSG_ID_SOCK_RECVPKG       (QMSG_ID_BASE + 5)
+
+typedef enum
+{
+    APP_INIT_STATE,
+    APP_DEACTIVE_STATE,
+    APP_IPREADY_STATE,
+    APP_REPORT_STATE,
+    APP_IDLE_STATE,
+    APP_WAIT_STATE
+} appRunningState_t;
+
+typedef struct Uart_Receive_Type
+{
+    uint8_t Bms_Address; 
+    uint8_t Bms_Read_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* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg,uint8_t* Uart_Rece_buffer);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* APP_H */

+ 16 - 0
inc/bsp_custom.h

@@ -0,0 +1,16 @@
+#ifndef  BSP_CUSTOM_H
+#define  BSP_CUSTOM_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "bsp.h"
+#include "hal_module_adapter.h"
+void BSP_CustomInit(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* BSP_CUSTOM_H */

+ 428 - 0
inc/can.h

@@ -0,0 +1,428 @@
+#ifndef __MCP2515_H
+#define __MCP2515_H
+
+#include "commontypedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+/* Configuration Registers */
+#define CANSTAT         0x0E
+#define CANCTRL         0x0F
+#define BFPCTRL         0x0C
+#define TEC             0x1C
+#define REC             0x1D
+#define CNF3            0x28
+#define CNF2            0x29
+#define CNF1            0x2A
+#define CANINTE         0x2B
+#define CANINTF         0x2C
+#define EFLG            0x2D
+#define TXRTSCTRL       0x0D
+
+/*  Recieve Filters */
+#define RXF0SIDH        0x00
+#define RXF0SIDL        0x01
+#define RXF0EID8        0x02
+#define RXF0EID0        0x03
+#define RXF1SIDH        0x04
+#define RXF1SIDL        0x05
+#define RXF1EID8        0x06
+#define RXF1EID0        0x07
+#define RXF2SIDH        0x08
+#define RXF2SIDL        0x09
+#define RXF2EID8        0x0A
+#define RXF2EID0        0x0B
+#define RXF3SIDH        0x10
+#define RXF3SIDL        0x11
+#define RXF3EID8        0x12
+#define RXF3EID0        0x13
+#define RXF4SIDH        0x14
+#define RXF4SIDL        0x15
+#define RXF4EID8        0x16
+#define RXF4EID0        0x17
+#define RXF5SIDH        0x18
+#define RXF5SIDL        0x19
+#define RXF5EID8        0x1A
+#define RXF5EID0        0x1B
+
+/* Receive Masks */
+#define RXM0SIDH        0x20
+#define RXM0SIDL        0x21
+#define RXM0EID8        0x22
+#define RXM0EID0        0x23
+#define RXM1SIDH        0x24
+#define RXM1SIDL        0x25
+#define RXM1EID8        0x26
+#define RXM1EID0        0x27
+
+/* Tx Buffer 0 */
+#define TXB0CTRL        0x30
+#define TXB0SIDH        0x31
+#define TXB0SIDL        0x32
+#define TXB0EID8        0x33
+#define TXB0EID0        0x34
+#define TXB0DLC         0x35
+#define TXB0D0          0x36
+#define TXB0D1          0x37
+#define TXB0D2          0x38
+#define TXB0D3          0x39
+#define TXB0D4          0x3A
+#define TXB0D5          0x3B
+#define TXB0D6          0x3C
+#define TXB0D7          0x3D
+
+/* Tx Buffer 1 */
+#define TXB1CTRL        0x40
+#define TXB1SIDH        0x41
+#define TXB1SIDL        0x42
+#define TXB1EID8        0x43
+#define TXB1EID0        0x44
+#define TXB1DLC         0x45
+#define TXB1D0          0x46
+#define TXB1D1          0x47
+#define TXB1D2          0x48
+#define TXB1D3          0x49
+#define TXB1D4          0x4A
+#define TXB1D5          0x4B
+#define TXB1D6          0x4C
+#define TXB1D7          0x4D
+
+/* Tx Buffer 2 */
+#define TXB2CTRL        0x50
+#define TXB2SIDH        0x51
+#define TXB2SIDL        0x52
+#define TXB2EID8        0x53
+#define TXB2EID0        0x54
+#define TXB2DLC         0x55
+#define TXB2D0          0x56
+#define TXB2D1          0x57
+#define TXB2D2          0x58
+#define TXB2D3          0x59
+#define TXB2D4          0x5A
+#define TXB2D5          0x5B
+#define TXB2D6          0x5C
+#define TXB2D7          0x5D
+
+/* Rx Buffer 0 */
+#define RXB0CTRL        0x60
+#define RXB0SIDH        0x61
+#define RXB0SIDL        0x62
+#define RXB0EID8        0x63
+#define RXB0EID0        0x64
+#define RXB0DLC         0x65
+#define RXB0D0          0x66
+#define RXB0D1          0x67
+#define RXB0D2          0x68
+#define RXB0D3          0x69
+#define RXB0D4          0x6A
+#define RXB0D5          0x6B
+#define RXB0D6          0x6C
+#define RXB0D7          0x6D
+
+/* Rx Buffer 1 */
+#define RXB1CTRL        0x70
+#define RXB1SIDH        0x71
+#define RXB1SIDL        0x72
+#define RXB1EID8        0x73
+#define RXB1EID0        0x74
+#define RXB1DLC         0x75
+#define RXB1D0          0x76
+#define RXB1D1          0x77
+#define RXB1D2          0x78
+#define RXB1D3          0x79
+#define RXB1D4          0x7A
+#define RXB1D5          0x7B
+#define RXB1D6          0x7C
+#define RXB1D7          0x7D
+
+
+/*******************************************************************
+ *               Bit register masks                                *
+ *******************************************************************/
+
+/* TXBnCTRL */
+#define TXREQ           0x08
+#define TXP             0x03
+
+/* RXBnCTRL */
+#define RXM             0x60
+#define BUKT            0x04
+
+/* CANCTRL */
+#define REQOP           0xE0
+#define ABAT            0x10
+#define	OSM             0x08
+#define CLKEN           0x04
+#define CLKPRE          0x03
+
+/* CANSTAT */
+#define REQOP           0xE0
+#define ICOD            0x0E
+
+/* CANINTE */
+#define RX0IE           0x01
+#define RX1IE           0x02
+#define TX0IE           0x04
+#define TX1IE           0x80
+#define TX2IE           0x10
+#define ERRIE           0x20
+#define WAKIE           0x40
+#define MERRE           0x80
+
+/* CANINTF */
+#define RX0IF           0x01
+#define RX1IF           0x02
+#define TX0IF           0x04
+#define TX1IF           0x80
+#define TX2IF           0x10
+#define ERRIF           0x20
+#define WAKIF           0x40
+#define MERRF           0x80
+
+/* BFPCTRL */
+#define B1BFS           0x20
+#define B0BFS           0x10
+#define B1BFE           0x08
+#define B0BFE           0x04
+#define B1BFM           0x02
+#define B0BFM           0x01
+
+/* CNF1 Masks */
+#define SJW             0xC0
+#define BRP             0x3F
+
+/* CNF2 Masks */
+#define BTLMODE         0x80
+#define SAM             0x40
+#define PHSEG1          0x38
+#define PRSEG           0x07
+
+/* CNF3 Masks */
+#define WAKFIL          0x40
+#define PHSEG2          0x07
+
+/* TXRTSCTRL Masks */
+#define TXB2RTS         0x04
+#define TXB1RTS         0x02
+#define TXB0RTS         0x01
+
+
+/*******************************************************************
+ *                    Bit Timing Configuration                     *
+ *******************************************************************/
+ 
+/* CNF1 */
+#define SJW_1TQ         0x40
+#define SJW_2TQ         0x80
+#define SJW_3TQ         0x90
+#define SJW_4TQ         0xC0
+
+/* CNF2 */
+#define BTLMODE_CNF3    0x80
+#define BTLMODE_PH1_IPT 0x00
+
+#define SMPL_3X         0x40
+#define SMPL_1X         0x00
+
+#define PHSEG1_8TQ      0x38
+#define PHSEG1_7TQ      0x30
+#define PHSEG1_6TQ      0x28
+#define PHSEG1_5TQ      0x20
+#define PHSEG1_4TQ      0x18
+#define PHSEG1_3TQ      0x10
+#define PHSEG1_2TQ      0x08
+#define PHSEG1_1TQ      0x00
+
+#define PRSEG_8TQ       0x07
+#define PRSEG_7TQ       0x06
+#define PRSEG_6TQ       0x05
+#define PRSEG_5TQ       0x04
+#define PRSEG_4TQ       0x03
+#define PRSEG_3TQ       0x02
+#define PRSEG_2TQ       0x01
+#define PRSEG_1TQ       0x00
+
+/* CNF3 */
+#define PHSEG2_8TQ      0x07
+#define PHSEG2_7TQ      0x06
+#define PHSEG2_6TQ      0x05
+#define PHSEG2_5TQ      0x04
+#define PHSEG2_4TQ      0x03
+#define PHSEG2_3TQ      0x02
+#define PHSEG2_2TQ      0x01
+#define PHSEG2_1TQ      0x00
+
+#define SOF_ENABLED     0x80
+#define WAKFIL_ENABLED  0x40
+#define WAKFIL_DISABLED 0x00
+
+
+/*******************************************************************
+ *                  Control/Configuration Registers                *
+ *******************************************************************/
+
+/* CANINTE */
+#define RX0IE_ENABLED   0x01
+#define RX0IE_DISABLED  0x00
+#define RX1IE_ENABLED   0x02
+#define RX1IE_DISABLED  0x00
+#define G_RXIE_ENABLED  0x03
+#define G_RXIE_DISABLED 0x00
+
+#define TX0IE_ENABLED   0x04
+#define TX0IE_DISABLED  0x00
+#define TX1IE_ENABLED   0x08
+#define TX2IE_DISABLED  0x00
+#define TX2IE_ENABLED   0x10
+#define TX2IE_DISABLED  0x00
+#define G_TXIE_ENABLED  0x1C
+#define G_TXIE_DISABLED 0x00
+
+#define ERRIE_ENABLED   0x20
+#define ERRIE_DISABLED  0x00
+#define WAKIE_ENABLED   0x40
+#define WAKIE_DISABLED  0x00
+#define IVRE_ENABLED    0x80
+#define IVRE_DISABLED   0x00
+
+/* CANINTF */
+#define RX0IF_SET       0x01
+#define RX0IF_RESET     0x00
+#define RX1IF_SET       0x02
+#define RX1IF_RESET     0x00
+#define TX0IF_SET       0x04
+#define TX0IF_RESET     0x00
+#define TX1IF_SET       0x08
+#define TX2IF_RESET     0x00
+#define TX2IF_SET       0x10
+#define TX2IF_RESET     0x00
+#define ERRIF_SET       0x20
+#define ERRIF_RESET     0x00
+#define WAKIF_SET       0x40
+#define WAKIF_RESET     0x00
+#define IVRF_SET        0x80
+#define IVRF_RESET      0x00
+
+/* CANCTRL */ 
+#define REQOP_CONFIG    0x80
+#define REQOP_LISTEN    0x60
+#define REQOP_LOOPBACK  0x40
+#define REQOP_SLEEP     0x20
+#define REQOP_NORMAL    0x00
+
+#define ABORT           0x10
+
+#define OSM_ENABLED     0x08
+
+#define CLKOUT_ENABLED  0x04
+#define CLKOUT_DISABLED 0x00
+#define CLKOUT_PRE_8    0x03
+#define CLKOUT_PRE_4    0x02
+#define CLKOUT_PRE_2    0x01
+#define CLKOUT_PRE_1    0x00
+
+/* CANSTAT */
+#define OPMODE_CONFIG   0x80
+#define OPMODE_LISTEN   0x60
+#define OPMODE_LOOPBACK 0x40
+#define OPMODE_SLEEP    0x20
+#define OPMODE_NORMAL   0x00
+
+
+/* RXBnCTRL */
+#define RXM_RCV_ALL     0x60
+#define RXM_VALID_EXT   0x40
+#define RXM_VALID_STD   0x20
+#define RXM_VALID_ALL   0x00
+
+#define RXRTR_REMOTE    0x08
+#define RXRTR_NO_REMOTE 0x00
+
+#define BUKT_ROLLOVER    0x04
+#define BUKT_NO_ROLLOVER 0x00
+
+#define FILHIT0_FLTR_1  0x01
+#define FILHIT0_FLTR_0  0x00
+
+#define FILHIT1_FLTR_5  0x05
+#define FILHIT1_FLTR_4  0x04
+#define FILHIT1_FLTR_3  0x03
+#define FILHIT1_FLTR_2  0x02
+#define FILHIT1_FLTR_1  0x01
+#define FILHIT1_FLTR_0  0x00
+
+
+/* TXBnCTRL */
+#define TXREQ_SET       0x08
+#define TXREQ_CLEAR     0x00
+
+#define TXP_HIGHEST     0x03
+#define TXP_INTER_HIGH  0x02
+#define TXP_INTER_LOW   0x01
+#define TXP_LOWEST      0x00
+    
+
+/*******************************************************************
+ *                  Register Bit Masks                             *
+ *******************************************************************/
+ 
+ #define DLC_0          0x00
+ #define DLC_1          0x01
+ #define DLC_2          0x02
+ #define DLC_3          0x03
+ #define DLC_4          0x04
+ #define DLC_5          0x05
+ #define DLC_6          0x06
+ #define DLC_7          0x07    
+ #define DLC_8          0x08
+ 
+
+/*******************************************************************
+ *                  CAN SPI commands                               *
+ *******************************************************************/
+
+#define CAN_RESET       0xC0
+#define CAN_READ        0x03
+#define CAN_WRITE       0x02
+#define CAN_RTS         0x80
+#define CAN_RTS_TXB0    0x81
+#define CAN_RTS_TXB1    0x82
+#define CAN_RTS_TXB2    0x84
+#define CAN_RD_STATUS   0xA0
+#define CAN_BIT_MODIFY  0x05  
+#define CAN_RX_STATUS   0xB0
+#define CAN_RD_RX_BUFF  0x90
+#define CAN_LOAD_TX     0X40  
+
+
+/*******************************************************************
+ *                  Miscellaneous                                  *
+ *******************************************************************/
+
+#define DUMMY_BYTE      0x00
+#define TXB0            0x31
+#define TXB1            0x41
+#define TXB2            0x51
+#define RXB0            0x61
+#define RXB1            0x71
+#define EXIDE_SET       0x08
+#define EXIDE_RESET     0x00
+
+
+/*MCP2515²¨ÌØÂÊÔ¤·ÖƵ*/
+#define	CAN_10Kbps	0x31
+#define CAN_25Kbps	0x13
+#define CAN_50Kbps	0x09
+#define CAN_100Kbps	0x04
+#define CAN_125Kbps	0x03
+#define CAN_250Kbps	0x01
+#define	CAN_500Kbps	0x00
+
+#ifdef __cplusplus
+}
+#endif
+#endif

+ 143 - 0
inc/cisAsynEntry.h

@@ -0,0 +1,143 @@
+#ifndef _OBJECT_DEFS_H_
+#define _OBJECT_DEFS_H_
+
+#include "cis_api.h"
+#include "cis_internals.h"
+
+#define SAMPLE_OBJECT_MAX              1
+#define SAMPLE_OID_A                   (3306)
+#define SAMPLE_A_INSTANCE_COUNT        1
+#define SAMPLE_A_INSTANCE_BITMAP       "1"
+
+typedef struct st_sample_object
+{
+    cis_oid_t         oid;
+    cis_instcount_t   instCount;
+    const char*       instBitmap;
+    const cis_rid_t*  attrListPtr;
+    uint16_t          attrCount;
+    const cis_rid_t*  actListPtr;
+    uint16_t          actCount;
+} st_sample_object;
+
+
+//////////////////////////////////////////////////////////////////////////
+//a object
+
+typedef struct st_object_a{
+    int32_t intValue;
+    float   floatValue;
+    bool    boolValue;
+    char    strValue[1024];
+    uint8_t update;
+} st_object_a;
+
+
+typedef struct st_instance_a
+{
+    cis_iid_t   instId;
+    bool        enabled;
+    st_object_a instance;
+} st_instance_a;
+
+
+enum{
+    attributeA_intValue     = 5851,
+    attributeA_boolValue    = 5850,
+    attributeA_stringValue  = 5750,
+};
+
+enum{
+    actionA_1           = 100,
+};
+
+                        
+//at+mipldiscoverrsp=0,msgid1,1,14,"5750;5850;5851" string bool integer
+static const cis_rid_t const_AttrIds_a[] = {
+    attributeA_intValue,
+    attributeA_boolValue,
+    attributeA_stringValue,
+};
+
+
+static const cis_rid_t const_ActIds_a[] = {
+    actionA_1,
+};
+
+typedef enum{
+    CIS_CALLBACK_UNKNOWN = 0,
+    CIS_CALLBACK_READ,
+    CIS_CALLBACK_WRITE,
+    CIS_CALLBACK_EXECUTE,
+    CIS_CALLBACK_OBSERVE,
+    CIS_CALLBACK_SETPARAMS,
+    CIS_CALLBACK_DISCOVER,
+} et_callback_type_t1;
+
+
+
+struct st_observe_info
+{
+    struct st_observe_info* next;
+    cis_listid_t    mid;
+    cis_uri_t       uri;
+    cis_observe_attr_t params;
+};
+
+struct store_observe_info
+{
+    cis_listid_t    mid;
+    cis_uri_t       uri;
+    cis_observe_attr_t params;
+};
+
+struct st_callback_info
+{
+    struct st_callback_info* next;
+    cis_listid_t       mid;
+    et_callback_type_t flag; 
+    cis_uri_t          uri;
+
+    union
+    {
+        struct{
+            cis_data_t* value;
+            cis_attrcount_t count;
+        }asWrite;
+
+        struct{
+            uint8_t* buffer;
+            uint32_t length;
+        }asExec;
+        
+        struct  
+        {
+            bool flag;
+        }asObserve;
+        
+        struct  
+        {
+            cis_observe_attr_t params;
+        }asObserveParam;
+    }param;
+    
+};
+typedef struct {
+    et_client_state_t pumpState;
+    uint8_t observeObjNum;
+    observed_backup_t gObservedBackup[MAX_OBSERVED_COUNT]; // For CIS core save use
+} onenet_context_t;
+
+bool cisAsynGetShutdown(void);
+void cisAsynSetShutdown(bool shutdown);
+bool cisAsynGetNotifyOnceStatus(void);
+void cisAsynSetNotifyOnceStatus(bool success);
+
+bool cisAsyncCheckNotificationReady(void);
+
+void prvMakeUserdata(void);
+void cisOnenetInit(void);
+void cisDataObserveReport(void);
+
+
+#endif//_OBJECT_DEFS_H_

+ 143 - 0
inc/hal_module_adapter.h

@@ -0,0 +1,143 @@
+#ifndef  HAL_MODULE_ADAPTER_H
+#define  HAL_MODULE_ADAPTER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include "commontypedef.h"
+#include "sensor.h"
+#include "can.h"
+
+#define I2C_INT1_REQ_BITMAP    								 (0x1)
+#define I2C_INT2_REQ_BITMAP    								 (0x2)
+
+
+#define ADC_REQ_BITMAP_VBAT    							       (0x01)
+#define ADC_REQ_BITMAP_TEMP   							       (0x02)
+#define ADC_REQ_BITMAP_CH1								 (0x04)
+#define ADC_REQ_BITMAP_CH2								 (0x08)
+#define ADC_REQ_BITMAP_CH3								 (0x10)
+#define ADC_REQ_BITMAP_CH4								 (0x20)
+#define ADC_REQ_BITMAP_CH5								 (0x40)
+#define ADC_GET_RESULT_TIMOUT 								 (2000)
+typedef enum _ntc_channel
+{
+    NTC_Channel1 ,	         
+    NTC_Channel2 ,                
+    NTC_Channel3 ,               
+    NTC_Channel4 ,               
+    NTC_Channel5 ,           
+    NTC_ChannelMax	
+} ntc_channel_t;
+
+typedef enum{
+	LED_SOC_0,
+	LED_SOC_1,
+	LED_SOC_2,
+	LED_SOC_3,
+	LED_MAX_INX
+}ledInx_t;
+
+typedef enum
+{
+	AON_IO = 0,
+	NORMAL_IO = 1,
+}IOType;
+
+typedef enum{
+	LED_TURN_ON,
+	LED_TURN_OFF
+}ledStaus_t;
+
+typedef struct
+{
+    UINT32 request;
+    UINT32 param[5];
+}adcReqMsg;
+
+typedef struct
+{
+    UINT32 event;
+    UINT32 value;
+} i2c_recv_msgqueue_obj_t;
+
+
+typedef struct _led_pin_config
+{
+    INT32  pinPort; 
+    INT32  pinInx; 
+    INT32  padInx;
+    pad_mux_t padMutex;
+} led_pin_config_t;
+
+typedef enum
+{
+	STD_PACK ,
+	EXT_PACK ,
+	PACK_MAX
+}PackType;
+
+typedef struct _can_initType
+{
+	INT32 baudrate; 
+	INT16 mode;
+	
+	INT8 TxStdIDH; 
+	/*
+		std : sid0 - sid2 ->bit5-bit7
+		ext :eid17: bit1 
+		ext: eid16 :bit0
+	*/
+	INT8 TxStdIDL; 
+	
+	INT8 TxExtIDH;
+	INT8 TxExtIDL;
+	
+	INT8 RxStdIDH[6];
+	INT8 RxStdIDL[6]; 
+
+	INT8 RxExtIDH[6]; 
+	INT8 RxExtIDL[6];
+	
+	PackType packType; //0   STID; 1 EXTID;
+}Can_InitType;
+
+typedef struct _Can_TxMsgType
+{
+    UINT16 stdIDH; 
+	UINT16 stdIDL;
+    UINT8 DLC;
+    UINT8 Data[8];
+}Can_TxMsgType;
+
+typedef void (*posGGACallBack )(UINT8 res, UINT8 * params);
+void PowerPinConfig(IOType iotype);
+
+INT32 posGGAServiceStart( posGGACallBack callBack);
+void posGGAServiceStop( void);
+void posGGAReset(void);
+
+
+void NetSocDisplay(ledInx_t  Inx , ledStaus_t status);
+void FaultDisplay(ledStaus_t status);
+
+INT32 AdcSendReq(UINT32 req,UINT32 * param , UINT8 len ,UINT32 timeout);
+INT32 AdcTaskInit(void);
+
+void CanSPIHandler(ARM_SPI_SignalEvent_t cb_event,UINT8 mode,UINT8 dataBits, UINT32 spiRate );
+#if 1
+UINT8 CanTriggerEvtInit(void);
+void CanWaitEvt(UINT32 timeout);
+void CanTiggerEvt(UINT8 cmd);
+#endif
+INT32 CAN_WriteReg(UINT8 addr, UINT8 value);
+INT32 CAN_ReadReg(UINT8 reg, UINT8 len, UINT8 *buf);
+ void HAL_Can_Init(Can_InitType param);
+ INT32 HAL_Can_Reset(void);
+ INT32 HAL_Can_Transmit(Can_TxMsgType Can_TxMsg);
+ UINT8  HAL_Can_Receive(UINT8 *CAN_RX_Buf);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_MODULE_ADAPTER_H */

+ 173 - 0
inc/sensor.h

@@ -0,0 +1,173 @@
+#ifndef  _SC7A20_H
+#define   _SC7A20_H
+
+
+#include "commontypedef.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+/***使用驱动前请根据实际接线情况配置******/
+/**SC7A20的SDO 脚接地:  0****************/
+/**SC7A20的SDO 脚接电源:1****************/
+#define SC7A20_SDO_VDD_GND           						0
+/*****************************************/
+
+/***使用驱动前请根据实际IIC情况进行配置***/
+/**SC7A20的IIC 接口地址类型 7bits:  0****/
+/**SC7A20的IIC 接口地址类型 8bits:  1****/
+#define SC7A20_IIC_7BITS_8BITS       						0
+/*****************************************/
+
+#define  SL_SC7A20_16BIT_8BIT         						0
+/**SC7A20的数据位数选择  16bits:    1****/
+/**SC7A20的数据位数选择   8bits:    0****/
+/*****************************************/
+#define SL_6D4D2D1D_SEL    							      1
+
+#if SC7A20_SDO_VDD_GND==0
+#define SC7A20_IIC_7BITS_ADDR        						0x18
+#define SC7A20_IIC_8BITS_ADDR        						0x30
+#else
+#define SC7A20_IIC_7BITS_ADDR       						0x19
+#define SC7A20_IIC_8BITS_ADDR       						0x32
+#endif
+
+
+#if SC7A20_IIC_7BITS_8BITS==0
+#define SC7A20_IIC_ADDRESS  							SC7A20_IIC_7BITS_ADDR
+#else
+#define SC7A20_IIC_ADDRESS  							SC7A20_IIC_8BITS_ADDR
+#endif
+
+
+#define SC7A20_CHIP_ID_ADDRESS    						(UINT8)(0x0F)
+#define SC7A20_CHIP_ID_VALUE      						(UINT8)(0x11)
+
+#define  SL_SC7A20_CTRL_REG1      						(UINT8)(0x20)
+#define  SL_SC7A20_CTRL_REG2     						(UINT8)(0x21)
+#define  SL_SC7A20_CTRL_REG3     						(UINT8)(0x22)
+#define  SL_SC7A20_CTRL_REG4      						(UINT8)(0x23) 
+#define  SL_SC7A20_CTRL_REG5      						(UINT8)(0x24)
+#define  SL_SC7A20_CTRL_REG6     						(UINT8)(0x25)
+
+#define  SL_SC7A20_STATUS_REG     						(UINT8)(0x27)
+
+#define  SL_SC7A20_OUT_X_L        						(UINT8)(0x28)
+#define  SL_SC7A20_OUT_X_H        						(UINT8)(0x29)
+#define  SL_SC7A20_OUT_Y_L       							(UINT8)(0x2A)
+#define  SL_SC7A20_OUT_Y_H        						(UINT8)(0x2B)
+#define  SL_SC7A20_OUT_Z_L        							(UINT8)(0x2C)
+#define  SL_SC7A20_OUT_Z_H       							(UINT8)(0x2D)
+
+#define  SL_SC7A20_FIFO_CTRL_REG 						(UINT8)(0x2E)
+#define  SL_SC7A20_FIFO_SRC_REG   						(UINT8)(0x2F)
+
+#define  SL_SC7A20_INT1_CFG    	 						(UINT8)(0x30)
+#define  SL_SC7A20_INT1_SRC       						(UINT8)(0x31)
+#define  SL_SC7A20_INT1_THS    	  						(UINT8)(0x32)
+#define  SL_SC7A20_INT1_DURATION 						(UINT8)(0x33)
+
+#define  SL_SC7A20_INT2_CFG    	 						(UINT8)(0x34)
+#define  SL_SC7A20_INT2_SRC      							(UINT8)(0x35)
+#define  SL_SC7A20_INT2_THS    	 						(UINT8)(0x36)
+#define  SL_SC7A20_INT2_DURATION  						(UINT8)(0x37)
+#define  SL_SC7A20_CLICK_CFG   	  						(UINT8)(0x38)
+#define  SL_SC7A20_CLICK_SRC   	 						(UINT8)(0x39)
+#define  SL_SC7A20_CLICK_THS   	 						(UINT8)(0x3A)
+#define  SL_SC7A20_TIME_LIMIT     						(UINT8)(0x3B)
+#define  SL_SC7A20_TIME_LATENCY   						(UINT8)(0x3C)
+#define  SL_SC7A20_TIME_WINDOW    						(UINT8)(0x3D)
+#define  SL_SC7A20_ACT_THS        						(UINT8)(0x3E)
+#define  SL_SC7A20_ACT_DURATION 						(UINT8)(0x3F)
+	
+/*连续读取数据时的数据寄存器地址*/
+#define  SL_SC7A20_DATA_OUT       						(UINT8)(SL_SC7A20_OUT_X_L|0x80)
+
+/**********特殊功能寄存器**********/
+/*非原厂技术人员请勿修改*/
+#define  SL_SC7A20_MTP_ENABLE    	             			(0x00)
+#define  SL_SC7A20_MTP_CFG    	  						(UINT8)(0x1E)
+#define  SL_SC7A20_MTP_VALUE   	  						(UINT8)(0x05)
+#define  SL_SC7A20_SDOI2C_PU_CFG  						(UINT8)(0x57)
+#define  SL_SC7A20_SDO_PU_MSK     						(UINT8)(0x08)
+#define  SL_SC7A20_I2C_PU_MSK     						(UINT8)(0x04)
+#define  SL_SC7A20_HR_ENABLE      						(UINT8)(0X08)
+#define  SL_SC7A20_BOOT_ENABLE   						(UINT8)(0X80)   
+/*非原厂技术人员请勿修改*/
+
+
+/***************数据更新速率**加速度计使能**********/
+#define  SL_SC7A20_ODR_POWER_DOWN 					(UINT8)(0x00)
+#define  SL_SC7A20_ODR_1HZ        						(UINT8)(0x17)
+#define  SL_SC7A20_ODR_10HZ       						(UINT8)(0x27)
+#define  SL_SC7A20_ODR_25HZ       						(UINT8)(0x37)
+#define  SL_SC7A20_ODR_50HZ       						(UINT8)(0x47)
+#define  SL_SC7A20_ODR_100HZ      						(UINT8)(0x57)
+#define  SL_SC7A20_ODR_200HZ      						(UINT8)(0x67)
+#define  SL_SC7A20_ODR_400HZ      						(UINT8)(0x77)
+#define  SL_SC7A20_ODR_1600HZ     						(UINT8)(0x87)
+#define  SL_SC7A20_ODR_1250HZ     						(UINT8)(0x97)
+#define  SL_SC7A20_ODR_5000HZ    						(UINT8)(0x9F)
+    
+#define  SL_SC7A20_LOWER_POWER_ODR_1HZ        			(UINT8)(0x1F)
+#define  SL_SC7A20_LOWER_POWER_ODR_10HZ       		(UINT8)(0x2F)
+#define  SL_SC7A20_LOWER_POWER_ODR_25HZ       		(UINT8)(0x3F)
+#define  SL_SC7A20_LOWER_POWER_ODR_50HZ       		(UINT8)(0x4F)
+#define  SL_SC7A20_LOWER_POWER_ODR_100HZ      		(UINT8)(0x5F)
+#define  SL_SC7A20_LOWER_POWER_ODR_200HZ     			(UINT8)(0x6F)
+#define  SL_SC7A20_LOWER_POWER_ODR_400HZ      		(UINT8)(0x7F)
+/***************数据更新速率**加速度计使能**********/
+
+
+/***************传感器量程设置**********************/
+#define  SL_SC7A20_FS_2G        							(UINT8)(0x00)	
+#define  SL_SC7A20_FS_4G        							(UINT8)(0x10)
+#define  SL_SC7A20_FS_8G       							(UINT8)(0x20)
+#define  SL_SC7A20_FS_16G         							(UINT8)(0x30)
+/***************传感器量程设置**********************/
+
+
+/***取值在0-127之间,此处仅举例****/
+#define SL_SC7A20_INT_THS_5PERCENT  					 (UINT8)(0x06)
+#define SL_SC7A20_INT_THS_10PERCENT					 (UINT8)(0x0C)
+#define SL_SC7A20_INT_THS_20PERCENT 					 (UINT8)(0x18)
+#define SL_SC7A20_INT_THS_40PERCENT 					 (UINT8)(0x32)
+#define SL_SC7A20_INT_THS_80PERCENT 					 (UINT8)(0x60)
+
+
+/***取值在0-127之间,此处仅举例 乘以ODR单位时间****/
+#define SL_SC7A20_INT_DURATION_2CLK 					 (UINT8)(0x02)
+#define SL_SC7A20_INT_DURATION_5CLK 					 (UINT8)(0x05)
+#define SL_SC7A20_INT_DURATION_10CLK					 (UINT8)(0x0A)
+#define SL_SC7A20_INT_DURATION_30CLK					 (UINT8)(0x2E)
+
+/***中断有效时的电平设置,高电平相当于上升沿,低电平相当于下降沿****/
+#define SL_SC7A20_INT_ACTIVE_LOWER_LEVEL				 (UINT8)(0x02) //0x02:中断时INT1脚输出 低电平
+#define SL_SC7A20_INT_ACTIVE_HIGH_LEVEL				 (UINT8)(0x00) //0x00:中断时INT1脚输出 高电平 
+
+/***中断有效时的电平设置,高电平相当于上升沿,低电平相当于下降沿****/
+#define SL_SC7A20_INT_AOI1_INT1         					 (UINT8)(0x40) //AOI1 TO INT1
+#define SL_SC7A20_INT_AOI2_INT1          					 (UINT8)(0x20) //AOI2 TO INT1
+
+
+extern INT32 GSENSOR_WriteReg(UINT8 addr, UINT8 value);
+extern INT32 GSENSOR_ReadReg(UINT8 reg, UINT8 len, UINT8 *buf);
+
+INT8  SL_SC7A20_Online_Test(void);
+INT8  SL_SC7A20_BOOT(void);
+INT8  SL_SC7A20_FS_Config(UINT8 Sc7a20_FS_Reg);
+INT8  SL_SC7A20_INT_Config(void);
+INT8  SL_SC7A20_INT_RESET(void);
+INT8  SL_SC7A20_Power_Config(UINT8 Power_Config_Reg);
+#if   SL_SC7A20_16BIT_8BIT==0
+INT8  SL_SC7A20_Read_XYZ_Data(INT8 *SL_SC7A20_Data_XYZ_Buf);
+#elif SL_SC7A20_16BIT_8BIT==1
+INT8  SL_SC7A20_Read_XYZ_Data(INT16 *SL_SC7A20_Data_XYZ_Buf);
+#endif
+
+void GsensorInit(void);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SC7A20_H */

BIN
软件版本修改记录及备份.xlsx