浏览代码

j1939协议更新

樊春春 3 月之前
父节点
当前提交
1a83d2c1b3

+ 2 - 0
CMakeLists.txt

@@ -34,6 +34,7 @@ file(GLOB_RECURSE C_SRCS
         ${CMAKE_CURRENT_SOURCE_DIR}/packages/multi_button/multi_button.c
         ${CMAKE_CURRENT_SOURCE_DIR}/packages/j1939/source/*.c
         ${CMAKE_CURRENT_SOURCE_DIR}/app/*.c
+        ${CMAKE_CURRENT_SOURCE_DIR}/ble/*.c
         ${CMAKE_CURRENT_SOURCE_DIR}/cli/*.c
         ${CMAKE_CURRENT_SOURCE_DIR}/dev/*.c
         ${CMAKE_CURRENT_SOURCE_DIR}/hal/*.c
@@ -57,6 +58,7 @@ set(INC_C_DIRS
         ${CMAKE_CURRENT_SOURCE_DIR}/packages/multi_button
         ${CMAKE_CURRENT_SOURCE_DIR}/packages/j1939/source
         ${CMAKE_CURRENT_SOURCE_DIR}/app
+        ${CMAKE_CURRENT_SOURCE_DIR}/ble
         ${CMAKE_CURRENT_SOURCE_DIR}/cli
         ${CMAKE_CURRENT_SOURCE_DIR}/dev
         ${CMAKE_CURRENT_SOURCE_DIR}/hal

+ 9 - 9
app/app_task.c

@@ -1,9 +1,12 @@
 #include "app_task.h"
+#include "J1939.H"
 #include "app_eeprom.h"
+#include "ble_core.h"
 #include "cli.h"
 #include "dev_at24cxx.h"
 #include "dev_can.h"
 #include "hal_systick.h"
+#include "stm32f4xx_tim.h"
 #include <stdint.h>
 #include <stdio.h>
 
@@ -46,6 +49,7 @@ static void app_task_10ms(void)
 {
     app_eeprom_read_task();
     app_eeprom_write_task();
+    J1939_Poll();
 }
 
 /*----------------------------------------
@@ -66,6 +70,7 @@ static void app_task_50ms(void)
     if (dev_key.dev_key_state.bits.key_up_state_flag == 1)
     {
         buf[0] = 10;
+        ble_send();
         // dev_at24cxx_write_bytes(0, &buf[99], 1);
         app_eeprom_write_50_zhuzu();
         dev_key.dev_key_state.bits.key_up_state_flag = 0;
@@ -154,10 +159,10 @@ static void app_task_500ms(void)
 ----------------------------------------*/
 static void app_task_1000ms(void)
 {
-    static volatile uint8_t state = 0;
-    dev_led_on_off(1, state);
-    state = !state;
-    dev_led_on_off(0, state);
+    // static volatile uint8_t state = 0;
+    // dev_led_on_off(1, state);
+    // state = !state;
+    // dev_led_on_off(0, state);
     systick_ms_clock++;
     // printf("debug\r\n");
     // dev_led_on_off(1, !state);
@@ -194,11 +199,6 @@ void app_task_schdule(void)
         app_task_5ms();
         dev_task_flag.bits.task0_flag = 0;
     }
-    // if (dev_task_flag.bits.task1_flag && (!(dev_task_flag.all & task1_mask)))
-    // {
-    //     app_task_10ms();
-    //     dev_task_flag.bits.task1_flag = 0;
-    // }
     if (dev_task_flag.bits.task1_flag)
     {
         app_task_10ms();

+ 63 - 0
ble/ble_core.c

@@ -0,0 +1,63 @@
+/************************************************************************************************
+ *                                          Include                                              *
+ ************************************************************************************************/
+#include "ble_core.h"
+#include "hal_systick.h"
+#include "hal_uart.h"
+#include "stm32f4xx_gpio.h"
+#include <stdint.h>
+/************************************************************************************************
+ *                                          Config                                                *
+ ************************************************************************************************/
+
+/************************************************************************************************
+ *                                          Data structs                                         *
+ ************************************************************************************************/
+void ble_init(void)
+{
+    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
+    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
+
+    GPIO_InitTypeDef GPIO_StructInit;
+    GPIO_StructInit.GPIO_Mode  = GPIO_Mode_OUT;
+    GPIO_StructInit.GPIO_OType = GPIO_OType_PP;
+    GPIO_StructInit.GPIO_Speed = GPIO_Speed_100MHz;
+    GPIO_StructInit.GPIO_PuPd  = GPIO_PuPd_UP;
+    GPIO_StructInit.GPIO_Pin   = BT_RST_PIN;
+    GPIO_Init(BT_RST_PORT, &GPIO_StructInit);
+
+    GPIO_ResetBits(BT_RST_PORT, BT_RST_PIN);
+    ms_delay(1);
+    GPIO_SetBits(BT_RST_PORT, BT_RST_PIN);
+
+    GPIO_StructInit.GPIO_Mode  = GPIO_Mode_IN;
+    GPIO_StructInit.GPIO_OType = GPIO_OType_PP;
+    GPIO_StructInit.GPIO_Speed = GPIO_Speed_100MHz;
+    GPIO_StructInit.GPIO_PuPd  = GPIO_PuPd_NOPULL;
+    GPIO_StructInit.GPIO_Pin   = BT_BUSY_IND_PIN;
+    GPIO_Init(BT_BUSY_IND_PORT, &GPIO_StructInit);
+
+    GPIO_StructInit.GPIO_Mode  = GPIO_Mode_IN;
+    GPIO_StructInit.GPIO_OType = GPIO_OType_PP;
+    GPIO_StructInit.GPIO_Speed = GPIO_Speed_100MHz;
+    GPIO_StructInit.GPIO_PuPd  = GPIO_PuPd_UP;
+    GPIO_StructInit.GPIO_Pin   = BT_CONN_IND_PIN;
+    GPIO_Init(BT_CONN_IND_PORT, &GPIO_StructInit);
+}
+uint8_t conn_sta = 0;
+uint8_t busy_sta = 0;
+void    ble_send(void)
+{
+    conn_sta     = GPIO_ReadInputDataBit(BT_CONN_IND_PORT, BT_CONN_IND_PIN);
+    busy_sta     = GPIO_ReadInputDataBit(BT_BUSY_IND_PORT, BT_BUSY_IND_PIN);
+    uint8_t a[5] = {0};
+    a[0]         = 0x01;
+    a[1]         = 0xFC;
+    a[2]         = 0x00;
+    a[3]         = 0x01;
+    a[4]         = 0x01;
+    usart_send_it(&usart2_context, a, 5);
+}
+/************************************************************************************************
+ *                                          implements                                           *
+ ************************************************************************************************/

+ 51 - 0
ble/ble_core.h

@@ -0,0 +1,51 @@
+#ifndef __BLE_CORE_H
+#define __BLE_CORE_H
+
+#ifdef __cplusplus
+extern 'C'
+{
+#endif
+#ifdef __BLE_CORE_H_GLOBAL
+#define __BLE_CORE_H_EXTERN
+#else
+#define __BLE_CORE_H_EXTERN extern
+#endif
+
+    /************************************************************************************************
+     *                                          Version                                              *
+     ************************************************************************************************/
+
+    /************************************************************************************************
+     *                                          How to use                                           *
+     ************************************************************************************************/
+
+    /************************************************************************************************
+     *                                          Enable config                                         *
+     ************************************************************************************************/
+
+    /************************************************************************************************
+     *                                          Includes                                             *
+     ************************************************************************************************/
+
+#include "hal_uart.h"
+
+    /************************************************************************************************
+     *                                          Defines                                              *
+     ************************************************************************************************/
+#define BT_BUSY_IND_PORT GPIOB
+#define BT_BUSY_IND_PIN  GPIO_Pin_12
+#define BT_CONN_IND_PORT GPIOB
+#define BT_CONN_IND_PIN  GPIO_Pin_13
+#define BT_RST_PORT      GPIOC
+#define BT_RST_PIN       GPIO_Pin_2
+
+    void ble_init(void);
+    void ble_send(void);
+/************************************************************************************************
+ *                                          Defines                                              *
+ ************************************************************************************************/
+#ifdef __cplusplus
+};
+#endif
+
+#endif // __BLE_CORE_H

+ 94 - 33
dev/dev_can.c

@@ -1,5 +1,7 @@
 #include "dev_can.h"
+#include "J1939.H"
 #include "core_cmFunc.h"
+#include "dev_can_id.h"
 #include "dev_iap.h"
 #include "hal_can.h"
 #include "hal_conf.h"
@@ -8,6 +10,14 @@
 #include <stdlib.h>
 #include <string.h>
 
+queue_entry(pdu_tag, 40) can_rx_queue;
+
+queue_entry(pdu_tag, 40) can_tx_queue;
+
+uint8_t PGN_00B000H_Ary[20] = {0};
+
+extern void j1939_msg_push_queue(p_pdu_tag rec_msg);
+
 double pow_branch(double x, long long N)
 {
     double ans = 1.0;
@@ -77,7 +87,8 @@ uint8_t push_can_message_to_queue(uint32_t id, uint8_t len, uint8_t *p_data)
 
 #if 1
     __disable_irq();
-    result_status = en_queue(&can_tx_queue, response_msg);
+    en_queue(&can_tx_queue, response_msg, result_status);
+    // result_status = en_queue(&can_tx_queue, response_msg);
     __enable_irq();
 
     if (result_status != Q_OK)
@@ -126,7 +137,11 @@ void can_tx_callback(void)
 {
     pdu_tag tx_data;
     // de_queue(can_tx, &tx_data);
-    if (de_queue(&can_tx_queue, tx_data) == Q_OK) // 返回值为1代表读取成功
+    QUEUE_STATUS result_status;
+
+    de_queue(&can_tx_queue, tx_data, result_status);
+
+    if (result_status == Q_OK) // 返回值为1代表读取成功
     {
         can_tx_frame(tx_data);
         CAN_ITConfig(CAN1, CAN_IT_TME, ENABLE);
@@ -139,27 +154,32 @@ void can_tx_callback(void)
 
 void can_rx_callback(CanRxMsg rx_message)
 {
-    pdu_tag data;
-    uint8_t ps;
-    uint8_t pf;
+    pdu_tag      data;
+    uint8_t      ps;
+    uint8_t      pf;
+    QUEUE_STATUS result;
+
     switch (rx_message.ExtId)
     {
     case 0x18011801:
         data.id.r    = 0x18011801;
         data.reg.dlc = rx_message.DLC;
         memcpy(&data.data.u8_buf[0], rx_message.Data, rx_message.DLC);
-        en_queue(&can_rx_queue, data);
-    case 0x18DFF4E1:
-        data.id.r    = 0x18DFF4E1;
-        data.reg.dlc = rx_message.DLC;
-        memcpy(&data.data.u8_buf[0], rx_message.Data, rx_message.DLC);
-        en_queue(&can_rx_queue, data);
+        // en_queue(&can_rx_queue, data);
+        en_queue(&can_rx_queue, data, result);
+    // case 0x18DFF4E1:
+    //     data.id.r    = 0x18DFF4E1;
+    //     data.reg.dlc = rx_message.DLC;
+    //     memcpy(&data.data.u8_buf[0], rx_message.Data, rx_message.DLC);
+    //     // en_queue(&can_rx_queue, data);
+    //     en_queue(&can_rx_queue, data, result);
     case 0x18011802:
         data.id.r    = 0x18011802;
         data.reg.dlc = rx_message.DLC;
         memcpy(&data.data.u8_buf[0], rx_message.Data, rx_message.DLC);
 #if 1
-        en_queue(&can_rx_queue, data);
+        // en_queue(&can_rx_queue, data);
+        en_queue(&can_rx_queue, data, result);
 #else
         en_queue(can_rx, &data, 1);
 #endif
@@ -171,23 +191,31 @@ void can_rx_callback(CanRxMsg rx_message)
             data.id.r   = rx_message.ExtId;
             recv_can_id = data.id.b.sa;
             memcpy(&data.data.u8_buf[0], rx_message.Data, rx_message.DLC);
-#if 1
-            en_queue(&can_rx_queue, data);
-#else
-            en_queue(can_rx, &data, 1);
-#endif
+            en_queue(&can_rx_queue, data, result);
         }
         else
         {
-            // ps = (rx_message.ExtId & CAN_PGN_PS) >> 8;
-            // if (ps == 0xF4)
-            // {
-            // }
-#if 1
-            en_queue(&can_rx_queue, data);
-#else
-            en_queue(can_rx, &data, 1);
-#endif
+            ps = (rx_message.ExtId & CAN_PGN_PS) >> 8;
+            if (ps == 0xF4)
+            {
+                data.id.r    = rx_message.ExtId;
+                recv_can_id  = data.id.b.sa;
+                data.reg.dlc = rx_message.DLC;
+                memcpy(&data.data.u8_buf[0], rx_message.Data, rx_message.DLC);
+
+                if (data.id.b.pf == g_can_iap)
+                {
+                    en_queue(&can_rx_queue, data, result);
+                }
+                else
+                {
+                    en_queue(&can_rx_queue, data, result);
+                }
+            }
+            else
+            {
+                en_queue(&can_rx_queue, data, result);
+            }
         }
     }
 }
@@ -197,7 +225,7 @@ void can_rx_ctl(pdu_tag rec_msg)
 {
     // rec_msg.data.u8_buf[0];
     // LED2    = !LED2;
-    tx_flag = 1;
+    J1939_TP_TX_Message(0x00B300, 0xE1, PGN_00B000H_Ary, 20, 1);
 }
 uint8_t tx_data[8] = {0};
 uint8_t flag       = 0;
@@ -230,12 +258,13 @@ void can_rx_update(pdu_tag rec_msg)
     }
 }
 
+#define ota_id 0xDF
 can_rx_tab can_tab[] = {
     0x18011802,
     can_rx_param,
     0x18011801,
     can_rx_ctl,
-    0x18DFF4E1,
+    ota_id,
     iap_rec_handler,
 
 };
@@ -245,8 +274,10 @@ can_rx_tab can_tab[] = {
 
 void can_start_send(void)
 {
-    pdu_tag tx_msg;
+    pdu_tag      tx_msg;
+    QUEUE_STATUS result_status;
 
+    // if (RESET == CAN_GetITStatus(CAN1, CAN_IT_TME))
     if (0 == ((CAN1->IER) & 0x1))
     {
 #if 0
@@ -257,7 +288,9 @@ void can_start_send(void)
             CAN_ITConfig(CAN1, CAN_IT_TME, ENABLE);
         }
 #else
-        if (de_queue(&can_tx_queue, tx_msg) == Q_OK) // 返回值为1代表读取成功
+        de_queue(&can_tx_queue, tx_msg, result_status);
+
+        if (result_status == Q_OK) // 返回值为1代表读取成功
         {
             can_tx_frame(tx_msg);
             CAN_ITConfig(CAN1, CAN_IT_TME, ENABLE);
@@ -278,7 +311,9 @@ static uint8_t can_rx_process(void)
     {
 #if 1
         __disable_irq();
-        result = de_queue(&can_rx_queue, rec_msg);
+
+        de_queue(&can_rx_queue, rec_msg, result);
+        // result = de_queue(&can_rx_queue, rec_msg);
         __enable_irq();
         if (Q_OK == result)
         {
@@ -306,7 +341,7 @@ static uint8_t can_rx_process(void)
 
             if (flg == 0)
             {
-                // j1939_msg_push_queue(rec_msg);
+                j1939_msg_push_queue(&rec_msg);
             }
             flg = 0;
         }
@@ -640,6 +675,28 @@ void can_tx_0x18011803_2_message(void)
     push_can_message_to_queue(0x18011803, 8, data);
 }
 
+void can_tx_0x18180003_message(void)
+{
+    uint8_t data[8] = {0};
+    data_bit_move(0, 16, 0);
+    data_bit_move(16, 16, 0x2710);
+    data_bit_move(32, 16, 0x4E20);
+    data_bit_move(48, 16, 0x7530);
+    product_array(data);
+    push_can_message_to_queue(0x18190006, 8, data);
+}
+
+void can_tx_0x18190007_message(void)
+{
+    uint8_t data[8] = {0};
+    data_bit_move(0, 16, 0xDFFF);
+    data_bit_move(16, 16, 0xF000);
+    data_bit_move(32, 16, 0xE800);
+    data_bit_move(48, 16, 0xE13D);
+    product_array(data);
+    push_can_message_to_queue(0x18190005, 8, data);
+}
+
 void send_message(void)
 {
     static volatile uint8_t times = 0;
@@ -694,6 +751,8 @@ void send_message(void)
         can_tx_0x18011802_message();
         can_tx_0x18011803_message();
         // can_tx_0x18011803_2_message();
+        can_tx_0x18180003_message();
+        can_tx_0x18190007_message();
     }
     else
     {
@@ -705,6 +764,8 @@ void send_message(void)
 void dev_can_network_init(void)
 {
     hal_can_init();
+    queue_init(&can_rx_queue);
+    queue_init(&can_tx_queue);
     hal_can_rx_back_init(can_rx_callback);
     hal_can_tx_back_init(can_tx_callback);
 }
@@ -712,6 +773,6 @@ void dev_can_network_init(void)
 void can_process(void)
 {
     can_rx_process();
-    send_message();
+    // send_message();
     can_start_send();
 }

+ 3 - 2
dev/dev_can.h

@@ -4,8 +4,9 @@
 #include "hal_conf.h"
 #include "queue.h"
 
-#define CAN_PGN_PF 0xFF
-#define CAN_PGN_PS 0xFF
+#define CAN_PGN_PF 0xFFFF00
+#define CAN_PGN_PS 0xFF00
+
 extern uint8_t recv_can_id;
 
 typedef struct

+ 67 - 0
dev/dev_can_id.c

@@ -0,0 +1,67 @@
+/************************************************************************************************
+ *                                          Include                                              *
+ ************************************************************************************************/
+#include "dev_can_id.h"
+#include <stdint.h>
+
+/************************************************************************************************
+ *                                          Config                                                *
+ ************************************************************************************************/
+union
+{
+    uint32_t r;
+    struct
+    {
+        uint8_t sa : 8;
+        uint8_t ps : 8;
+        uint8_t pf : 8;
+        uint8_t dp : 1;
+        uint8_t r  : 1;
+        uint8_t p  : 3;
+    } b;
+} new_can_id;
+
+#define CAN_PGN_PF 0xFFFF00
+#define CAN_PGN_PS 0xFF00
+
+uint32_t g_ps         = 0xF4;
+uint32_t g_can_id     = 0x18F011F4;
+uint32_t g_can_ota_id = 0x18DFE1F4;
+uint8_t  g_can_iap    = 0xDF;
+
+uint32_t get_new_can_id(uint8_t pf)
+{
+    new_can_id.r    = g_can_id;
+    new_can_id.b.ps = new_can_id.b.sa;
+    new_can_id.b.sa = g_ps;
+    new_can_id.b.pf = pf;
+
+    return new_can_id.r;
+}
+
+uint32_t set_new_can_id(uint16_t pgn)
+{
+    new_can_id.r    = g_can_id;
+    new_can_id.b.sa = g_ps;
+    new_can_id.b.ps = pgn & 0xFF;
+    new_can_id.b.pf = pgn >> 8;
+    return new_can_id.r;
+}
+
+uint32_t get_ota_id(uint8_t pf)
+{
+    new_can_id.r    = g_can_ota_id;
+    new_can_id.b.ps = new_can_id.b.sa;
+    new_can_id.b.sa = g_ps;
+    new_can_id.b.pf = pf;
+
+    return new_can_id.r;
+}
+
+/************************************************************************************************
+ *                                          Data structs                                         *
+ ************************************************************************************************/
+
+/************************************************************************************************
+ *                                          implements                                           *
+ ************************************************************************************************/

+ 49 - 0
dev/dev_can_id.h

@@ -0,0 +1,49 @@
+#ifndef __DEV_CAN_ID_H
+#define __DEV_CAN_ID_H
+
+#include <stdint.h>
+#ifdef __cplusplus
+extern 'C'
+{
+#endif
+#ifdef __DEV_CAN_ID_H_GLOBAL
+#define __DEV_CAN_ID_H_EXTERN
+#else
+#define __DEV_CAN_ID_H_EXTERN extern
+#endif
+
+    /************************************************************************************************
+     *                                          Version                                              *
+     ************************************************************************************************/
+
+    /************************************************************************************************
+     *                                          How to use                                           *
+     ************************************************************************************************/
+
+    /************************************************************************************************
+     *                                          Enable config                                         *
+     ************************************************************************************************/
+
+    /************************************************************************************************
+     *                                          Includes                                             *
+     ************************************************************************************************/
+
+    /************************************************************************************************
+     *                                          Defines                                              *
+     ************************************************************************************************/
+    extern uint32_t g_ps;
+    extern uint32_t g_can_id;
+    extern uint32_t g_can_ota_id;
+    extern uint8_t  g_can_iap;
+
+    uint32_t get_new_can_id(uint8_t pf);
+    uint32_t set_new_can_id(uint16_t pgn);
+    uint32_t get_ota_id(uint8_t pf);
+/************************************************************************************************
+ *                                          Defines                                              *
+ ************************************************************************************************/
+#ifdef __cplusplus
+};
+#endif
+
+#endif // __DEV_CAN_ID_H

+ 2 - 1
dev/dev_iap.c

@@ -3,6 +3,7 @@
  ************************************************************************************************/
 #include "dev_iap.h"
 #include "dev_at24cxx.h"
+#include "dev_can_id.h"
 #include "hal_flash.h"
 #include "queue.h"
 #include <stdint.h>
@@ -302,5 +303,5 @@ void iap_rec_handler(pdu_tag rec_msg)
         }
     }
 
-    push_can_message_to_queue(0x18DFE1F4, 8, send_buff);
+    push_can_message_to_queue(get_ota_id(g_can_iap), 8, send_buff);
 }

+ 2 - 2
dev/dev_led.c

@@ -12,12 +12,12 @@ void dev_led_on_off(uint8_t leds, uint8_t on_off)
     {
         if (0x00 == on_off)
         {
-            HAL_GPIO_LED0(0x00);
+            // HAL_GPIO_LED0(0x00);
             dev_led.dev_led_state.bits.led0_state_flag = 0;
         }
         else
         {
-            HAL_GPIO_LED0(0x01);
+            // HAL_GPIO_LED0(0x01);
             dev_led.dev_led_state.bits.led0_state_flag = 1;
         }
         break;

二进制
docs/原理图/2.4'&2.8' TFTLCD_V2.1_SCH.pdf


二进制
docs/原理图/3.5' TFTLCD_V1.2_SCH.pdf


二进制
docs/原理图/4.3' TFTLCD_V1.2_SCH.pdf


二进制
docs/原理图/Explorer STM32F4_V2.2_SCH.pdf


二进制
docs/原理图/OV2640_V1.2_SCH.pdf


+ 15 - 0
docs/原理图/readme.txt

@@ -0,0 +1,15 @@
+本目录下包含了ALIENTEK探索者STM32F4开发板的所有电路原理图以及模块尺寸图,有的文档有多页,请滚动鼠标滚轮查看!!!
+
+注意:ALIENTEK 新出的产品,都会有产品资料,相关原理图及封装库等资料,均不放到该目录下了,移放至:9,增值资料-->1,ALIENTEK 产品资料 文件夹。
+
+
+
+
+
+		广州市星翼电子科技有限公司
+                电话:020-38271790
+                传真:020-36773971
+	       	购买:http://shop62103354.taobao.com
+                      http://shop62057469.taobao.com
+                公司网站:www.alientek.com
+         	技术论坛:www.openedv.com

二进制
docs/原理图/各模块尺寸图/2.4'&2.8' TFTLCD_V2.1_尺寸图.pdf


二进制
docs/原理图/各模块尺寸图/3.5' TFTLCD_V1.3_尺寸图.pdf


二进制
docs/原理图/各模块尺寸图/Explorer STM32F4_V2.2_尺寸图.pdf


二进制
docs/原理图/各模块尺寸图/OV2640_V1.2_尺寸图.pdf


二进制
docs/原理图/探索者IO引脚分配表.xlsx


+ 6 - 38
hal/hal_can.c

@@ -42,7 +42,7 @@ u8 hal_can1_mode_init(uint8_t tsjw, uint8_t tbs2, uint8_t tbs1, uint16_t brp, ui
 
     // CAN单元设置
     CAN_InitStructure.CAN_TTCM      = DISABLE; // 非时间触发通信模式
-    CAN_InitStructure.CAN_ABOM      = DISABLE; // 软件自动离线管理
+    CAN_InitStructure.CAN_ABOM      = ENABLE;  // 软件自动离线管理
     CAN_InitStructure.CAN_AWUM      = DISABLE; // 睡眠模式通过软件唤醒(清除CAN->MCR的SLEEP位)
     CAN_InitStructure.CAN_NART      = DISABLE; // 禁止报文自动传送
     CAN_InitStructure.CAN_RFLM      = DISABLE; // 报文不锁定,新的覆盖旧的
@@ -79,11 +79,11 @@ u8 hal_can1_mode_init(uint8_t tsjw, uint8_t tbs2, uint8_t tbs1, uint16_t brp, ui
     NVIC_Init(&NVIC_InitStructure);
 
     // CAN_ITConfig(CAN1, CAN_IT_TME, ENABLE); // FIFO0消息挂号中断允许.
-    // NVIC_InitStructure.NVIC_IRQChannel                   = CAN1_TX_IRQn;
-    // NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; // 主优先级为1
-    // NVIC_InitStructure.NVIC_IRQChannelSubPriority        = 0; // 次优先级为0
-    // NVIC_InitStructure.NVIC_IRQChannelCmd                = ENABLE;
-    // NVIC_Init(&NVIC_InitStructure);
+    NVIC_InitStructure.NVIC_IRQChannel                   = CAN1_TX_IRQn;
+    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; // 主优先级为1
+    NVIC_InitStructure.NVIC_IRQChannelSubPriority        = 0; // 次优先级为0
+    NVIC_InitStructure.NVIC_IRQChannelCmd                = ENABLE;
+    NVIC_Init(&NVIC_InitStructure);
     ////////////////////////////////////////////////
 
     return 0;
@@ -106,38 +106,6 @@ void hal_can_init(void)
 #endif
 }
 
-//(固定格式:ID为0X12,标准帧,数据帧)
-// len:数据长度(最大为8)
-// msg:数据指针,最大为8个字节.
-// 返回值:0,成功;
-//		 其他,失败;
-/****************************************************
- *  函数功能:can1发送一组数据
- *  入口参数:msg 数据  len  数据长度  can_id  CAN id
- *  说    明:group_id 从1开始
- *****************************************************/
-// u8 CAN1_Send_Msg(u8 *msg, u8 len, u32 can_id)
-// {
-//     u16      mbox, i;
-//     CanTxMsg TxMessage;
-
-//     TxMessage.StdId = 0x00;            // 标准标识符为0
-//     TxMessage.ExtId = can_id;          // 设置扩展标示符(29位)
-//     TxMessage.IDE   = CAN_Id_Extended; // 使用扩展标识符
-//     TxMessage.RTR   = CAN_RTR_Data;    // 消息类型为数据帧
-//     TxMessage.DLC   = len;             // 发送两帧信息
-
-//     for (i = 0; i < len; i++)
-//         TxMessage.Data[i] = msg[i]; // 第一帧信息
-//     mbox = CAN_Transmit(CAN1, &TxMessage);
-//     i    = 0;
-//     while ((CAN_TransmitStatus(CAN1, mbox) == CAN_TxStatus_Failed) && (i < 0XFFF))
-//         i++; // 等待发送结束
-//     if (i >= 0XFFF)
-//         return 1;
-//     return 0;
-// }
-
 uint8_t hal_can_msg_tx(uint32_t id, uint8_t id_type, uint8_t *p_data, uint8_t len)
 {
     uint8_t flg = 0;

+ 1 - 1
hal/hal_conf.h

@@ -5,7 +5,7 @@
 #include "hal_flash.h"
 #include "hal_gpio.h"
 #include "hal_i2c1.h"
+#include "hal_pwm.h"
 #include "hal_systick.h"
 #include "hal_uart.h"
-
 #endif // __APP_TASK_H

+ 2 - 2
hal/hal_gpio.c

@@ -23,9 +23,9 @@ void hal_led_init(void)
     GPIO_StructInit.GPIO_OType = GPIO_OType_PP;
     GPIO_StructInit.GPIO_Speed = GPIO_Speed_100MHz;
     GPIO_StructInit.GPIO_PuPd  = GPIO_PuPd_UP;
-    GPIO_StructInit.GPIO_Pin   = HAL_GPIO_LED0_PIN | HAL_GPIO_LED1_PIN;
+    GPIO_StructInit.GPIO_Pin   = HAL_GPIO_LED1_PIN;
 
-    GPIO_Init(HAL_GPIO_LED0_PORT, &GPIO_StructInit);
+    GPIO_Init(HAL_GPIO_LED1_PORT, &GPIO_StructInit);
 }
 
 void hal_key_init(void)

+ 5 - 5
hal/hal_gpio.h

@@ -3,10 +3,10 @@
 
 #include "stm32f4xx.h"
 
-#define HAL_GPIO_BEEP_PORT   GPIOF
-#define HAL_GPIO_BEEP_PIN    GPIO_Pin_8
-#define HAL_GPIO_LED0_PORT   GPIOF
-#define HAL_GPIO_LED0_PIN    GPIO_Pin_9
+#define HAL_GPIO_BEEP_PORT GPIOF
+#define HAL_GPIO_BEEP_PIN  GPIO_Pin_8
+// #define HAL_GPIO_LED0_PORT   GPIOF
+// #define HAL_GPIO_LED0_PIN    GPIO_Pin_9
 #define HAL_GPIO_LED1_PORT   GPIOF
 #define HAL_GPIO_LED1_PIN    GPIO_Pin_10
 #define HAL_GPIO_KEY_UP_PORT GPIOA
@@ -18,7 +18,7 @@
 #define HAL_GPIO_KEY2_PORT   GPIOE
 #define HAL_GPIO_KEY2_PIN    GPIO_Pin_2
 
-#define HAL_GPIO_LED0(on_off)      ((on_off == 0) ? (GPIO_ResetBits(HAL_GPIO_LED0_PORT, HAL_GPIO_LED0_PIN)) : (GPIO_SetBits(HAL_GPIO_LED0_PORT, HAL_GPIO_LED0_PIN)))
+// #define HAL_GPIO_LED0(on_off)      ((on_off == 0) ? (GPIO_ResetBits(HAL_GPIO_LED0_PORT, HAL_GPIO_LED0_PIN)) : (GPIO_SetBits(HAL_GPIO_LED0_PORT, HAL_GPIO_LED0_PIN)))
 #define HAL_GPIO_LED1(on_off)      ((on_off == 0) ? (GPIO_ResetBits(HAL_GPIO_LED1_PORT, HAL_GPIO_LED1_PIN)) : (GPIO_SetBits(HAL_GPIO_LED1_PORT, HAL_GPIO_LED1_PIN)))
 #define HAL_GPIO_BEEP(beep_status) ((beep_status == 0) ? (GPIO_ResetBits(HAL_GPIO_BEEP_PORT, HAL_GPIO_BEEP_PIN)) : (GPIO_SetBits(HAL_GPIO_BEEP_PORT, HAL_GPIO_BEEP_PIN)))
 

+ 91 - 0
hal/hal_pwm.c

@@ -0,0 +1,91 @@
+#include "hal_pwm.h"
+#include "stm32f4xx_tim.h"
+
+void pwm_init(pwm_content_t *pwm_content)
+{
+    RCC_APB1PeriphClockCmd(pwm_content->pwm_timer_rcu, ENABLE);
+    RCC_AHB1PeriphClockCmd(pwm_content->pwm_gpio_rcu, ENABLE);
+
+    // GPIO初始化
+    GPIO_PinAFConfig(pwm_content->pwm_gpio_port, pwm_content->pwm_gpio_af, pwm_content->pwm_time_af);
+    GPIO_InitTypeDef GPIO_InitStructure;
+    GPIO_InitStructure.GPIO_Pin   = pwm_content->pwm_gpio_pin;
+    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
+    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
+    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
+    GPIO_Init(pwm_content->pwm_gpio_port, &GPIO_InitStructure);
+
+    // 定时器初始化
+    TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
+    TIM_TimeBaseStructure.TIM_Period            = pwm_content->pwm_period;    // 定时时间的配置,也就是配置重载值,而重载值会传递给计数值
+    TIM_TimeBaseStructure.TIM_Prescaler         = pwm_content->pwm_prescaler; // 配置分频值,确定定时器的时钟频率
+    TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
+    TIM_TimeBaseStructure.TIM_ClockDivision     = TIM_CKD_DIV1;
+    TIM_TimeBaseStructure.TIM_CounterMode       = TIM_CounterMode_Up; // 向上计数,0->TIM_Period就会触发中断请求
+    TIM_TimeBaseInit(pwm_content->pwm_timer, &TIM_TimeBaseStructure);
+
+    // PWM初始化
+    TIM_OCInitTypeDef TIM_OCInitStructure;
+    TIM_OCInitStructure.TIM_OCMode       = pwm_content->pwm_timer_ch;
+    TIM_OCInitStructure.TIM_OutputState  = TIM_OutputState_Enable; // 输出状态使能
+    TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;
+    TIM_OCInitStructure.TIM_Pulse        = pwm_content->pwm_pulse;
+    TIM_OCInitStructure.TIM_OCPolarity   = TIM_OCPolarity_High; // 有效状态为高电平
+    TIM_OCInitStructure.TIM_OCNPolarity  = TIM_OCNPolarity_High;
+    TIM_OCInitStructure.TIM_OCIdleState  = TIM_OCIdleState_Reset;
+    TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset;
+    TIM_OC1Init(pwm_content->pwm_timer, &TIM_OCInitStructure);
+
+    // PWM设置
+    TIM_OC1PreloadConfig(pwm_content->pwm_timer, TIM_OCPreload_Enable);
+
+    // 自动重装
+    TIM_ARRPreloadConfig(pwm_content->pwm_timer, ENABLE);
+
+    // 使能定时器
+    TIM_Cmd(pwm_content->pwm_timer, ENABLE);
+}
+void pwm_mode(pwm_content_t *pwm_content, uint8_t status)
+{
+    if (1 == status)
+    {
+        if (pwm_content->pwm_status == 0)
+        {
+            TIM_Cmd(pwm_content->pwm_timer, ENABLE);
+            pwm_content->pwm_status = 1;
+        }
+    }
+
+    if (0 == status)
+    {
+        if (pwm_content->pwm_status == 1)
+        {
+            TIM_Cmd(pwm_content->pwm_timer, DISABLE);
+            GPIO_InitTypeDef GPIO_InitStructure;
+            GPIO_InitStructure.GPIO_Pin   = pwm_content->pwm_gpio_pin;
+            GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
+            GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
+            GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+            GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
+            GPIO_Init(pwm_content->pwm_gpio_port, &GPIO_InitStructure);
+            // GPIO_ResetBits(pwm_content->pwm_gpio_port, pwm_content->pwm_gpio_pin);
+            pwm_content->pwm_status = 0;
+        }
+    }
+}
+
+pwm_content_t pwm_timer3_content = {
+    .pwm_gpio_port = GPIOF,
+    .pwm_gpio_pin  = GPIO_Pin_9,
+    .pwm_gpio_rcu  = RCC_AHB1Periph_GPIOF,
+    .pwm_gpio_af   = GPIO_PinSource9,
+    .pwm_time_af   = GPIO_AF_TIM14,
+    .pwm_timer_rcu = RCC_APB1Periph_TIM14,
+    .pwm_timer     = TIM14,
+    .pwm_timer_ch  = TIM_OCMode_PWM1,
+    .pwm_prescaler = 84 - 1,
+    .pwm_period    = 500 - 1,
+    .pwm_pulse     = 50,
+    .pwm_status    = 0,
+};

+ 62 - 0
hal/hal_pwm.h

@@ -0,0 +1,62 @@
+#ifndef __HAL_PWM_H
+#define __HAL_PWM_H
+
+#include <stdint.h>
+#ifdef __cplusplus
+extern 'C'
+{
+#endif
+#ifdef __HAL_PWM_H_GLOBAL
+#define __HAL_PWM_H_EXTERN
+#else
+#define __HAL_PWM_H_EXTERN extern
+#endif
+
+    /************************************************************************************************
+     *                                          Version                                              *
+     ************************************************************************************************/
+
+    /************************************************************************************************
+     *                                          How to use                                           *
+     ************************************************************************************************/
+
+    /************************************************************************************************
+     *                                          Enable config                                         *
+     ************************************************************************************************/
+
+    /************************************************************************************************
+     *                                          Includes                                             *
+     ************************************************************************************************/
+#include "stm32f4xx_gpio.h"
+#include "stm32f4xx_tim.h"
+    /************************************************************************************************
+     *                                          Defines                                              *
+     ************************************************************************************************/
+    typedef struct
+    {
+        GPIO_TypeDef *pwm_gpio_port;
+        uint32_t      pwm_gpio_pin;
+        uint32_t      pwm_gpio_rcu;
+        uint16_t      pwm_gpio_af;
+        uint8_t       pwm_time_af;
+        TIM_TypeDef  *pwm_timer;
+        uint32_t      pwm_timer_rcu;
+        uint32_t      pwm_timer_ch;
+        uint32_t      pwm_prescaler;
+        uint32_t      pwm_period;
+        uint32_t      pwm_pulse;
+        uint8_t       pwm_status;
+    } pwm_content_t;
+
+    void pwm_init(pwm_content_t * pwm_content);
+    void pwm_mode(pwm_content_t * pwm_content, uint8_t status);
+
+    extern pwm_content_t pwm_timer3_content;
+/************************************************************************************************
+ *                                          Defines                                              *
+ ************************************************************************************************/
+#ifdef __cplusplus
+};
+#endif
+
+#endif // __HAL_PWM_H

+ 65 - 0
hal/hal_systick.c

@@ -1,9 +1,11 @@
 #include "hal_systick.h"
+#include <stdint.h>
 
 static u8  fac_us = 0; // us延时倍乘数
 static u16 fac_ms = 0; // ms延时倍乘数
 
 volatile uint32_t systick_ms = 0;
+volatile uint32_t systick_us = 0;
 
 void hal_systick_init(void)
 {
@@ -29,9 +31,72 @@ uint32_t get_systick_ms(void)
     return tick_ms;
 }
 
+uint32_t get_systick_us(void)
+{
+    uint32_t tick, tick_us;
+    __disable_irq();
+    tick    = (SYSTICK_EXT_CLOCK_1MS_CNT - SysTick->VAL);
+    tick_us = tick / (SYSTICK_EXT_CLOCK_1MS_CNT / 1000);
+    tick_us = tick_us + systick_us;
+    __enable_irq();
+
+    return tick_us;
+}
+
+void ms_delay(uint8_t ms_time)
+{
+    uint32_t end_count = 0, current_count = 0;
+
+    current_count = get_systick_ms();
+    end_count     = current_count + ms_time;
+
+    if (end_count == current_count)
+    {
+        return;
+    }
+    else if (end_count > current_count)
+    {
+        while (get_systick_ms() < end_count)
+            ;
+    }
+    else
+    {
+        while (get_systick_ms() >= current_count)
+            ;
+        while (get_systick_ms() < end_count)
+            ;
+    }
+}
+
+void us_delay(uint8_t us_time)
+{
+    uint32_t end_count = 0, current_count = 0;
+
+    current_count = get_systick_us();
+    end_count     = current_count + us_time;
+
+    if (end_count == current_count)
+    {
+        return;
+    }
+    else if (end_count > current_count)
+    {
+        while (get_systick_us() < end_count)
+            ;
+    }
+    else
+    {
+        while (get_systick_us() >= current_count)
+            ;
+        while (get_systick_us() < end_count)
+            ;
+    }
+}
+
 void systick_handler(void)
 {
     __disable_irq();
     systick_ms += 1;
+    systick_us += 1000;
     __enable_irq();
 }

+ 1 - 0
hal/hal_systick.h

@@ -10,4 +10,5 @@ uint32_t get_systick_ms(void);
 
 void systick_handler(void);
 
+void ms_delay(uint8_t ms_time);
 #endif // __HAL_SYSTICK_H

+ 63 - 2
hal/hal_uart.c

@@ -6,6 +6,9 @@
 static uint8_t usart1_tx_buf[256];
 static uint8_t usart1_rx_buf[256];
 
+static uint8_t usart2_tx_buf[256];
+static uint8_t usart2_rx_buf[256];
+
 #define HAL_UART1_TX_PORT   GPIOA
 #define HAL_UART1_TX_PIN    GPIO_Pin_9
 #define HAL_UART1_TX_SOURCE GPIO_PinSource9
@@ -13,6 +16,13 @@ static uint8_t usart1_rx_buf[256];
 #define HAL_UART1_RX_PIN    GPIO_Pin_10
 #define HAL_UART1_RX_SOURCE GPIO_PinSource10
 
+#define HAL_UART2_TX_PORT   GPIOA
+#define HAL_UART2_TX_PIN    GPIO_Pin_2
+#define HAL_UART2_TX_SOURCE GPIO_PinSource2
+#define HAL_UART2_RX_PORT   GPIOA
+#define HAL_UART2_RX_PIN    GPIO_Pin_3
+#define HAL_UART2_RX_SOURCE GPIO_PinSource3
+
 int usart1_snd_tx_cnt = 0;
 
 // 加入以下代码,支持printf函数,而不需要选择use MicroLIB
@@ -180,6 +190,37 @@ static void usart1_deconfig(void)
 {
 }
 
+static void usart2_config(void)
+{
+    GPIO_InitTypeDef GPIO_StructInit;
+    NVIC_InitTypeDef NVIC_InitStructure;
+    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
+    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
+
+    GPIO_StructInit.GPIO_Mode  = GPIO_Mode_AF;
+    GPIO_StructInit.GPIO_OType = GPIO_OType_PP;
+    GPIO_StructInit.GPIO_Speed = GPIO_Speed_100MHz;
+    GPIO_StructInit.GPIO_PuPd  = GPIO_PuPd_UP;
+    GPIO_StructInit.GPIO_Pin   = HAL_UART2_TX_PIN;
+    GPIO_PinAFConfig(HAL_UART2_TX_PORT, HAL_UART2_TX_SOURCE, GPIO_AF_USART2);
+    GPIO_Init(HAL_UART2_TX_PORT, &GPIO_StructInit);
+
+    GPIO_StructInit.GPIO_Pin = HAL_UART2_RX_PIN;
+    GPIO_PinAFConfig(HAL_UART2_RX_PORT, HAL_UART2_RX_SOURCE, GPIO_AF_USART2);
+    GPIO_Init(HAL_UART2_RX_PORT, &GPIO_StructInit);
+
+    // Usart1 NVIC 配置
+    NVIC_InitStructure.NVIC_IRQChannel                   = USART2_IRQn; // 串口1中断通道
+    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;           // 抢占优先级
+    NVIC_InitStructure.NVIC_IRQChannelSubPriority        = 0;           // 子优先级
+    NVIC_InitStructure.NVIC_IRQChannelCmd                = ENABLE;      // IRQ通道使能
+    NVIC_Init(&NVIC_InitStructure);
+}
+
+static void usart2_deconfig(void)
+{
+}
+
 usart_context_t usart1_context = {
     USART1,
     usart1_tx_buf,
@@ -195,6 +236,21 @@ usart_context_t usart1_context = {
     usart1_config,
     usart1_deconfig};
 
+usart_context_t usart2_context = {
+    USART2,
+    usart2_tx_buf,
+    sizeof(usart2_tx_buf),
+    0,
+    0,
+    0,
+    usart2_rx_buf,
+    sizeof(usart2_rx_buf),
+    0,
+    0,
+    0,
+    usart2_config,
+    usart2_deconfig};
+
 void usart_config_init(usart_context_t *p_usart_content, uint32_t band_rate)
 {
     p_usart_content->config();
@@ -207,11 +263,11 @@ void usart_config_init(usart_context_t *p_usart_content, uint32_t band_rate)
     USART_InitStructure.USART_Parity              = USART_Parity_No;
     USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
     USART_InitStructure.USART_Mode                = USART_Mode_Rx | USART_Mode_Tx;
-    USART_Init(p_usart_content->usart_periph, &USART_InitStructure); // 初始化串口1
+    USART_Init(p_usart_content->usart_periph, &USART_InitStructure); // 初始化串口
 
     USART_ITConfig(p_usart_content->usart_periph, USART_IT_RXNE, ENABLE);
 
-    USART_Cmd(USART1, ENABLE); // 使能串口1
+    USART_Cmd(p_usart_content->usart_periph, ENABLE); // 使能串口
 }
 
 void usart_config_deinit(usart_context_t *p_usart_content)
@@ -356,4 +412,9 @@ void usart_it(usart_context_t *p_usart_content)
 void USART1_IRQHandler(void)
 {
     usart_it(&usart1_context);
+}
+
+void USART2_IRQHandler(void)
+{
+    usart_it(&usart2_context);
 }

+ 1 - 0
hal/hal_uart.h

@@ -38,4 +38,5 @@ void    u_tm_log(char *args, ...);
 void    u_log(char *arg, ...);
 
 extern usart_context_t usart1_context;
+extern usart_context_t usart2_context;
 #endif

+ 0 - 104
hal/queue.c

@@ -1,104 +0,0 @@
-#include "queue.h"
-
-///   front   ...         rear      数据方向 ->
-/* 队列的顺序存储结构(循环队列) */
-
-can_queue_tag can_tx_queue;
-can_queue_tag can_rx_queue;
-
-/****************************************************
- *  函 数 名:init_queue
- *  函数功能:初始化队列
- *  入口参数:无
- *  说    明:
- ****************************************************/
-void queue_init(p_can_queue_tag p_queue)
-{                                      /* 构造一个空队列Q */
-    p_queue->head = p_queue->tail = 0; /*空队列*/
-    p_queue->count                = 0;
-}
-
-/****************************************************
- *  函 数 名:is_queue_empty
- *  函数功能:查询队列是否为空
- *  入口参数:Q 队列
- *  说    明:空队列,返回SUCCESS;否则返回ERROR
- ****************************************************/
-uint8_t queue_empty(p_can_queue_tag p_queue)
-{ /* 若*/
-    return p_queue->count == 0;
-}
-
-uint8_t queue_full(p_can_queue_tag p_queue)
-{ /* 若*/
-    return p_queue->count == MAX_QSIZE;
-}
-
-/****************************************************
- *  函 数 名:queue_length
- *  函数功能:初始化长度
- *  入口参数:Q 队列
- *  说    明:
- ****************************************************/
-uint16_t queue_length(can_queue_tag p_queue)
-{ /* 返回Q的元素个数,即队列的长度 */
-    return (p_queue.tail - p_queue.head + MAX_QSIZE) % MAX_QSIZE;
-}
-
-/****************************************************
- *  函 数 名:get_head
- *  函数功能:获取对头数据
- *  入口参数:Q 队列
- *  说    明:
- ****************************************************/
-uint8_t get_head(
-    can_queue_tag *p_queue,
-    pdu_tag       *e)
-{                                       /* 若队列不空,则用e返回Q的队头元素,并返回OK;否则返回ERROR*/
-    if (p_queue->head == p_queue->tail) /* 队列空 */
-        return Q_ERR;
-    *e = p_queue->can_message[p_queue->head];
-
-    p_queue->head = (p_queue->head + 1) % MAX_QSIZE;
-    return Q_OK;
-}
-
-/****************************************************
- *  函 数 名:insert_queue
- *  函数功能:队列插入数据
- *  入口参数:Q 待插入队列    e 待插入数据
- *  说    明:
- ****************************************************/
-QUEUE_STATUS en_queue(p_can_queue_tag p_queue,
-                      pdu_tag         data)
-{
-    if (queue_full(p_queue))
-        return Q_FULL;
-    p_queue->count++;
-    p_queue->can_message[p_queue->head] = data;
-    p_queue->head                       = (p_queue->head + 1) % MAX_QSIZE;
-    return Q_OK;
-    /* 插入元素e为Q的新的队尾元素 */
-    // if ((p_queue->tail + 1) % MAX_QSIZE == p_queue->head) /* 队列满 */
-    //     return ERROR;
-    // p_queue->can_message[p_queue->tail] = e;
-    // p_queue->tail                       = (p_queue->tail + 1) % MAX_QSIZE;
-    // return SUCCESS;
-}
-
-QUEUE_STATUS de_queue(p_can_queue_tag p_queue,
-                      pdu_tag         data)
-{ /* 插入元素e为Q的新的队尾元素 */
-    // if ((p_queue->tail + 1) % MAX_QSIZE == p_queue->head) /* 队列满 */
-    //     return ERROR;
-    // p_queue->can_message[p_queue->tail] = e;
-    // p_queue->tail                       = (p_queue->tail + 1) % MAX_QSIZE;
-    // return SUCCESS;
-    if (queue_empty(p_queue))
-        return Q_EMPTY;
-    data          = p_queue->can_message[p_queue->tail];
-    p_queue->tail = (p_queue->tail + 1) % MAX_QSIZE;
-    p_queue->count--;
-
-    return Q_OK;
-}

+ 104 - 0
hal/queue.c111

@@ -0,0 +1,104 @@
+// #include "queue.h"
+
+// ///   front   ...         rear      数据方向 ->
+// /* 队列的顺序存储结构(循环队列) */
+
+// can_queue_tag can_tx_queue;
+// can_queue_tag can_rx_queue;
+
+// /****************************************************
+//  *  函 数 名:init_queue
+//  *  函数功能:初始化队列
+//  *  入口参数:无
+//  *  说    明:
+//  ****************************************************/
+// void queue_init(p_can_queue_tag p_queue)
+// {                                      /* 构造一个空队列Q */
+//     p_queue->head = p_queue->tail = 0; /*空队列*/
+//     p_queue->count                = 0;
+// }
+
+// /****************************************************
+//  *  函 数 名:is_queue_empty
+//  *  函数功能:查询队列是否为空
+//  *  入口参数:Q 队列
+//  *  说    明:空队列,返回SUCCESS;否则返回ERROR
+//  ****************************************************/
+// uint8_t queue_empty(p_can_queue_tag p_queue)
+// { /* 若*/
+//     return p_queue->count == 0;
+// }
+
+// uint8_t queue_full(p_can_queue_tag p_queue)
+// { /* 若*/
+//     return p_queue->count == MAX_QSIZE;
+// }
+
+// /****************************************************
+//  *  函 数 名:queue_length
+//  *  函数功能:初始化长度
+//  *  入口参数:Q 队列
+//  *  说    明:
+//  ****************************************************/
+// uint16_t queue_length(can_queue_tag p_queue)
+// { /* 返回Q的元素个数,即队列的长度 */
+//     return (p_queue.tail - p_queue.head + MAX_QSIZE) % MAX_QSIZE;
+// }
+
+// /****************************************************
+//  *  函 数 名:get_head
+//  *  函数功能:获取对头数据
+//  *  入口参数:Q 队列
+//  *  说    明:
+//  ****************************************************/
+// uint8_t get_head(
+//     can_queue_tag *p_queue,
+//     pdu_tag       *e)
+// {                                       /* 若队列不空,则用e返回Q的队头元素,并返回OK;否则返回ERROR*/
+//     if (p_queue->head == p_queue->tail) /* 队列空 */
+//         return Q_ERR;
+//     *e = p_queue->can_message[p_queue->head];
+
+//     p_queue->head = (p_queue->head + 1) % MAX_QSIZE;
+//     return Q_OK;
+// }
+
+// /****************************************************
+//  *  函 数 名:insert_queue
+//  *  函数功能:队列插入数据
+//  *  入口参数:Q 待插入队列    e 待插入数据
+//  *  说    明:
+//  ****************************************************/
+// QUEUE_STATUS en_queue(p_can_queue_tag p_queue,
+//                       pdu_tag         data)
+// {
+//     if (queue_full(p_queue))
+//         return Q_FULL;
+//     p_queue->count++;
+//     p_queue->can_message[p_queue->head] = data;
+//     p_queue->head                       = (p_queue->head + 1) % MAX_QSIZE;
+//     return Q_OK;
+//     /* 插入元素e为Q的新的队尾元素 */
+//     // if ((p_queue->tail + 1) % MAX_QSIZE == p_queue->head) /* 队列满 */
+//     //     return ERROR;
+//     // p_queue->can_message[p_queue->tail] = e;
+//     // p_queue->tail                       = (p_queue->tail + 1) % MAX_QSIZE;
+//     // return SUCCESS;
+// }
+
+// QUEUE_STATUS de_queue(p_can_queue_tag p_queue,
+//                       pdu_tag         data)
+// { /* 插入元素e为Q的新的队尾元素 */
+//     // if ((p_queue->tail + 1) % MAX_QSIZE == p_queue->head) /* 队列满 */
+//     //     return ERROR;
+//     // p_queue->can_message[p_queue->tail] = e;
+//     // p_queue->tail                       = (p_queue->tail + 1) % MAX_QSIZE;
+//     // return SUCCESS;
+//     if (queue_empty(p_queue))
+//         return Q_EMPTY;
+//     data          = p_queue->can_message[p_queue->tail];
+//     p_queue->tail = (p_queue->tail + 1) % MAX_QSIZE;
+//     p_queue->count--;
+
+//     return Q_OK;
+// }

+ 51 - 27
hal/queue.h

@@ -2,10 +2,6 @@
 #define __QUEUE_H
 #include "stdio.h"
 
-#define MAX_QSIZE (60u) /* 最大队列长度 */
-
-typedef unsigned long long u64;
-
 typedef struct
 {
     struct
@@ -32,24 +28,10 @@ typedef struct
         uint8_t  u8_buf[8];
         uint16_t u16_buf[4];
         uint32_t u32_buf[2];
-        u64      u64_buf;
+        uint64_t u64_buf;
     } data;
 } pdu_tag, *p_pdu_tag;
 
-typedef struct
-{
-    uint8_t  buf[8];
-    uint32_t can_id;
-} CanData_TypeDef;
-
-typedef struct
-{
-    uint16_t head;
-    uint16_t tail;
-    uint16_t count;
-    pdu_tag  can_message[MAX_QSIZE];
-} can_queue_tag, *p_can_queue_tag;
-
 typedef enum
 {
     Q_OK,
@@ -58,13 +40,55 @@ typedef enum
     Q_EMPTY,
 } QUEUE_STATUS;
 
-extern can_queue_tag can_tx_queue;
-extern can_queue_tag can_rx_queue;
+#define queue_entry(type, size) \
+    struct                      \
+    {                           \
+        uint8_t head;           \
+        uint8_t tail;           \
+        uint8_t count;          \
+        type    message[size];  \
+    }
+
+#define queue_init(name)                 \
+    {                                    \
+        (name)->head = (name)->tail = 0; \
+        (name)->count               = 0; \
+    }
+
+/* List functions. */
+#define queue_empty(name) ((name)->count == 0)
+#define queue_max(name)   ((sizeof((name)->message)) / (sizeof((name)->message[0])))
+#define queue_full(name)  ((name)->count == ((sizeof((name)->message)) / (sizeof((name)->message[0]))))
+#define en_queue(name, field, ret)                                                \
+    do                                                                            \
+    {                                                                             \
+        if (queue_full(name))                                                     \
+        {                                                                         \
+            ret = Q_FULL;                                                         \
+        }                                                                         \
+        else                                                                      \
+        {                                                                         \
+            (name)->count++;                                                      \
+            (name)->message[(name)->head] = field;                                \
+            (name)->head                  = ((name)->head + 1) % queue_max(name); \
+            ret                           = Q_OK;                                 \
+        }                                                                         \
+    } while (0)
+
+#define de_queue(name, field, ret)                               \
+    do                                                           \
+    {                                                            \
+        if (queue_empty(name))                                   \
+        {                                                        \
+            ret = Q_EMPTY;                                       \
+        }                                                        \
+        else                                                     \
+        {                                                        \
+            field        = (name)->message[(name)->tail];        \
+            (name)->tail = ((name)->tail + 1) % queue_max(name); \
+            (name)->count--;                                     \
+            ret = Q_OK;                                          \
+        }                                                        \
+    } while (0)
 
-void         queue_init(p_can_queue_tag);  // 初始化队列
-uint8_t      queue_empty(p_can_queue_tag); // 查询队列是否为空
-uint8_t      queue_full(p_can_queue_tag);
-uint8_t      get_head(can_queue_tag *p_queue, pdu_tag *data); // 获取对头数据
-QUEUE_STATUS en_queue(p_can_queue_tag, pdu_tag);              // 队列插入数据
-QUEUE_STATUS de_queue(p_can_queue_tag, pdu_tag);
 #endif

+ 118 - 0
hal/queue.h111

@@ -0,0 +1,118 @@
+#ifndef __QUEUE_H
+#define __QUEUE_H
+#include "stdio.h"
+
+#define MAX_QSIZE (60u) /* 最大队列长度 */
+
+typedef unsigned long long u64;
+
+typedef struct
+{
+    struct
+    {
+        uint8_t ide;
+        uint8_t rtr;
+        uint8_t dlc;
+    } reg;
+    union
+    {
+        uint32_t r;
+        struct
+        {
+            uint8_t sa : 8;
+            uint8_t ps : 8;
+            uint8_t pf : 8;
+            uint8_t dp : 1;
+            uint8_t r  : 1;
+            uint8_t p  : 3;
+        } b;
+    } id;
+    union
+    {
+        uint8_t  u8_buf[8];
+        uint16_t u16_buf[4];
+        uint32_t u32_buf[2];
+        u64      u64_buf;
+    } data;
+} pdu_tag, *p_pdu_tag;
+
+typedef struct
+{
+    uint8_t  buf[8];
+    uint32_t can_id;
+} CanData_TypeDef;
+
+typedef struct
+{
+    uint16_t head;
+    uint16_t tail;
+    uint16_t count;
+    pdu_tag  can_message[MAX_QSIZE];
+} can_queue_tag, *p_can_queue_tag;
+
+typedef enum
+{
+    Q_OK,
+    Q_ERR,
+    Q_FULL,
+    Q_EMPTY,
+} QUEUE_STATUS;
+
+#define QUEUE_ENTRY(type, size) \
+    struct                      \
+    {                           \
+        uint8_t head;           \
+        uint8_t tail;           \
+        uint8_t count;          \
+        type    message[size];  \
+    }
+
+#define QUEUE_INIT(name)                 \
+    {                                    \
+        (name)->head = (name)->tail = 0; \
+        (name)->count               = 0; \
+    }
+
+/* List functions. */
+#define QUEUE_EMPTY(name) ((name)->count == 0)
+#define QUEUE_MAX(name)   ((sizeof((name)->message)) / (sizeof((name)->message[0])))
+#define QUEUE_FULL(name)  ((name)->count == ((sizeof((name)->message)) / (sizeof((name)->message[0]))))
+#define EN_QUEUE(name, field, ret)                                                \
+    do                                                                            \
+    {                                                                             \
+        if (QUEUE_FULL(name))                                                     \
+        {                                                                         \
+            ret = Q_FULL;                                                         \
+        }                                                                         \
+        else                                                                      \
+        {                                                                         \
+            (name)->count++;                                                      \
+            (name)->message[(name)->head] = field;                                \
+            (name)->head                  = ((name)->head + 1) % QUEUE_MAX(name); \
+            ret                           = Q_OK;                                 \
+        }                                                                         \
+    } while (0)
+
+#define DE_QUEUE(name, field, ret)                               \
+    do                                                           \
+    {                                                            \
+        if (QUEUE_EMPTY(name))                                   \
+        {                                                        \
+            ret = Q_EMPTY;                                       \
+        }                                                        \
+        else                                                     \
+        {                                                        \
+            field        = (name)->message[(name)->tail];        \
+            (name)->tail = ((name)->tail + 1) % QUEUE_MAX(name); \
+            (name)->count--;                                     \
+            ret = Q_OK;                                          \
+        }                                                        \
+    } while (0)
+
+void         queue_init(p_can_queue_tag);  // 初始化队列
+uint8_t      queue_empty(p_can_queue_tag); // 查询队列是否为空
+uint8_t      queue_full(p_can_queue_tag);
+uint8_t      get_head(can_queue_tag *p_queue, pdu_tag *data); // 获取对头数据
+QUEUE_STATUS en_queue(p_can_queue_tag, pdu_tag);              // 队列插入数据
+QUEUE_STATUS de_queue(p_can_queue_tag, pdu_tag);
+#endif

+ 94 - 23
packages/j1939/source/J1939.c

@@ -50,6 +50,11 @@
 #define ADDRESS_CLAIM_TX 1 /**< 进入地址竞争发送处理模式*/
 #define ADDRESS_CLAIM_RX 2 /**< 进入地址竞争接受处理模式*/
 
+// queue_entry(J1939_MESSAGE, 10)
+// j1939_rx_queue;
+
+extern uint8_t PGN_00B000H_Ary[20];
+
 // 全局变量。
 /** 设备的标称符
  *
@@ -111,6 +116,9 @@ J1939_MESSAGE TXQueue_4[J1939_TX_QUEUE_SIZE];
 
 struct Request_List REQUEST_LIST;
 
+// #define REQUEST_PGN_MAX (10)
+// struct Request_List RequestListArray[REQUEST_PGN_MAX];
+
 #if J1939_TP_RX_TX
 // TP协议全局变量
 J1939_TP_Flags          J1939_TP_Flags_t;
@@ -422,6 +430,7 @@ j1939_uint8_t J1939_Send_Message(J1939_MESSAGE *MsgPtr, CAN_NODE _Can_Node)
 void j1939_msg_push_queue(p_pdu_tag rec_msg)
 {
     J1939_MESSAGE _msg;
+    QUEUE_STATUS  status;
 
     _msg.Mxe.DataPage      = rec_msg->id.b.dp;
     _msg.Mxe.Priority      = rec_msg->id.b.p;
@@ -435,7 +444,7 @@ void j1939_msg_push_queue(p_pdu_tag rec_msg)
     {
         _msg.Mxe.Data[index] = rec_msg->data.u8_buf[index];
     }
-    // en_queue(&j1939_rx_queue, _msg);
+    en_queue(&j1939_rx_queue, _msg, status);
 }
 
 /**
@@ -486,7 +495,7 @@ void J1939_Initialization()
     REQUEST_LIST.update   = J1939_NULL;
     REQUEST_LIST.lenght   = 0;
     REQUEST_LIST.Can_Node = Select_CAN_NODE_Null;
-    REQUEST_LIST.next     = J1939_NULL;
+    // REQUEST_LIST.next     = J1939_NULL;
     /*将TP协议置为空闲*/
 #if J1939_TP_RX_TX
     J1939_TP_Flags_t.state          = J1939_TP_NULL;
@@ -506,6 +515,26 @@ void J1939_Initialization()
 #endif
 }
 
+#define PGN_00B000 0x00B000
+
+void PGN0_ResponseDataUpdate(void)
+{
+    PGN_00B000H_Ary[0] = 1;
+    PGN_00B000H_Ary[1] = 1;
+    PGN_00B000H_Ary[2] = 1;
+    PGN_00B000H_Ary[3] = 1;
+    PGN_00B000H_Ary[4] = 1;
+    PGN_00B000H_Ary[5] = 1;
+    PGN_00B000H_Ary[5] = 1;
+    PGN_00B000H_Ary[6] = 1;
+    PGN_00B000H_Ary[7] = 1;
+}
+
+void J1939_InitResponsePGN(void)
+{
+    J1939_Create_Response(PGN_00B000H_Ary, 23, PGN_00B000, PGN0_ResponseDataUpdate, Select_CAN_NODE_1);
+}
+
 /**
 * @note 这个函数被调用,当设备产生CAN中断(可能是接受中断,也可能是发送中断)\n
         首先我们要清除中断标识位\n
@@ -545,24 +574,33 @@ void J1939_ISR(void)
 void J1939_TP_Poll();
 void J1939_Poll()
 {
+    static j1939_uint8_t gpn_init_flg = 0;
+
+    if (!gpn_init_flg)
+    {
+        gpn_init_flg = 1;
+        queue_init(&j1939_rx_queue);
+        J1939_Initialization();
+        J1939_InitResponsePGN();
+    }
     // 我们必须调用J1939_ReceiveMessages接受函数,在时间被重置为0之前。
 #if J1939_POLL_ECAN == J1939_TRUE
     Can_Node      = Select_CAN_NODE_1;
     J1939_Address = NodeAddress_1;
     J1939_ReceiveMessages();
-    J1939_TransmitMessages();
-    Can_Node      = Select_CAN_NODE_2;
-    J1939_Address = NodeAddress_2;
-    J1939_ReceiveMessages();
-    J1939_TransmitMessages();
-    Can_Node      = Select_CAN_NODE_3;
-    J1939_Address = NodeAddress_3;
-    J1939_ReceiveMessages();
-    J1939_TransmitMessages();
-    Can_Node      = Select_CAN_NODE_4;
-    J1939_Address = NodeAddress_4;
-    J1939_ReceiveMessages();
-    J1939_TransmitMessages();
+    // J1939_TransmitMessages();
+    // Can_Node      = Select_CAN_NODE_2;
+    // J1939_Address = NodeAddress_2;
+    // J1939_ReceiveMessages();
+    // J1939_TransmitMessages();
+    // Can_Node      = Select_CAN_NODE_3;
+    // J1939_Address = NodeAddress_3;
+    // J1939_ReceiveMessages();
+    // J1939_TransmitMessages();
+    // Can_Node      = Select_CAN_NODE_4;
+    // J1939_Address = NodeAddress_4;
+    // J1939_ReceiveMessages();
+    // J1939_TransmitMessages();
 #if J1939_TP_RX_TX
     J1939_TP_Poll();
 #endif // J1939_TP_RX_TX
@@ -1128,7 +1166,11 @@ void J1939_TP_DT_Packet_send(void)
         }
 
         /*可能队列已满,发不出去,但是这里不能靠返回值进行无限的死等*/
-        J1939_EnqueueMessage(&_msg, Can_Node);
+        // J1939_EnqueueMessage(&_msg, Can_Node);
+        {
+            _msg.Mxe.SourceAddress = J1939_Address;
+            Port_CAN_Transmit(&_msg);
+        }
     }
     else
     {
@@ -1164,7 +1206,12 @@ void J1939_CM_Start(void)
     _msg.Mxe.Data[5]            = (j1939_uint8_t)(pgn_num & 0xff);
 
     /*可能队列已满,发不出去,但是这里不能靠返回值进行无限的死等*/
-    J1939_EnqueueMessage(&_msg, Can_Node);
+    // J1939_EnqueueMessage(&_msg, Can_Node);
+
+    {
+        _msg.Mxe.SourceAddress = J1939_Address;
+        Port_CAN_Transmit(&_msg);
+    }
 
     /*刷新等待时间,触发下一个步骤()*/
     TP_TX_MSG.time  = J1939_TP_T3;
@@ -1195,7 +1242,11 @@ void J1939_TP_TX_Abort(void)
     _msg.Mxe.Data[5]            = (j1939_uint8_t)(pgn_num & 0xff);
 
     /*可能队列已满,发不出去,但是这里不能靠返回值进行无限的死等*/
-    J1939_EnqueueMessage(&_msg, Can_Node);
+    // J1939_EnqueueMessage(&_msg, Can_Node);
+    {
+        _msg.Mxe.SourceAddress = J1939_Address;
+        Port_CAN_Transmit(&_msg);
+    }
     /*结束发送*/
     TP_TX_MSG.state = J1939_TX_DONE;
 }
@@ -1224,7 +1275,11 @@ void J1939_TP_RX_Abort(void)
     _msg.Mxe.Data[5]            = (j1939_uint8_t)(pgn_num & 0xff);
 
     /*可能队列已满,发不出去,但是这里不能靠返回值进行无限的死等*/
-    J1939_EnqueueMessage(&_msg, Can_Node);
+    // J1939_EnqueueMessage(&_msg, Can_Node);
+    {
+        _msg.Mxe.SourceAddress = J1939_Address;
+        Port_CAN_Transmit(&_msg);
+    }
     /*结束发送*/
     TP_RX_MSG.state = J1939_RX_DONE;
 }
@@ -1303,7 +1358,11 @@ void J1939_read_DT_Packet()
         _msg.Mxe.Data[6] = (j1939_uint8_t)(pgn_num >> 8 & 0xff);
         _msg.Mxe.Data[5] = (j1939_uint8_t)(pgn_num & 0xff);
         /*可能队列已满,发不出去,但是这里不能靠返回值进行无限的死等*/
-        J1939_EnqueueMessage(&_msg, Can_Node);
+        // J1939_EnqueueMessage(&_msg, Can_Node);
+        {
+            _msg.Mxe.SourceAddress = J1939_Address;
+            Port_CAN_Transmit(&_msg);
+        }
         return;
     }
     if (TP_RX_MSG.packets_total > TP_RX_MSG.packets_ok_num)
@@ -1320,7 +1379,11 @@ void J1939_read_DT_Packet()
             _msg.Mxe.Data[6] = (j1939_uint8_t)(pgn_num >> 8 & 0xff);
             _msg.Mxe.Data[5] = (j1939_uint8_t)(pgn_num & 0xff);
             /*可能队列已满,发不出去,但是这里不能靠返回值进行无限的死等*/
-            J1939_EnqueueMessage(&_msg, Can_Node);
+            // J1939_EnqueueMessage(&_msg, Can_Node);
+            {
+                _msg.Mxe.SourceAddress = J1939_Address;
+                Port_CAN_Transmit(&_msg);
+            }
             TP_RX_MSG.state = J1939_TP_RX_DATA_WAIT;
             return;
         }
@@ -1334,7 +1397,11 @@ void J1939_read_DT_Packet()
         _msg.Mxe.Data[5] = (j1939_uint8_t)(pgn_num & 0xff);
 
         /*可能队列已满,发不出去,但是这里不能靠返回值进行无限的死等*/
-        J1939_EnqueueMessage(&_msg, Can_Node);
+        // J1939_EnqueueMessage(&_msg, Can_Node);
+        {
+            _msg.Mxe.SourceAddress = J1939_Address;
+            Port_CAN_Transmit(&_msg);
+        }
         TP_RX_MSG.state = J1939_TP_RX_DATA_WAIT;
         return;
     }
@@ -1350,7 +1417,11 @@ void J1939_read_DT_Packet()
         _msg.Mxe.Data[6] = (j1939_uint8_t)(pgn_num >> 8 & 0xff);
         _msg.Mxe.Data[5] = (j1939_uint8_t)(pgn_num & 0xff);
         /*可能队列已满,发不出去,但是这里不能靠返回值进行无限的死等*/
-        J1939_EnqueueMessage(&_msg, Can_Node);
+        // J1939_EnqueueMessage(&_msg, Can_Node);
+        {
+            _msg.Mxe.SourceAddress = J1939_Address;
+            Port_CAN_Transmit(&_msg);
+        }
         TP_RX_MSG.state = J1939_RX_DONE;
         return;
     }

+ 11 - 12
packages/j1939/source/J1939_Config.H

@@ -42,6 +42,7 @@
 
 #include "J1939.H"
 #include "queue.h"
+#include <stdint.h>
 #include <string.h>
 
 extern uint8_t  push_can_message_to_queue(uint32_t id, uint8_t len, uint8_t *p_data);
@@ -49,7 +50,7 @@ extern CAN_NODE Can_Node; // CAN硬件选择
 
 /***************************J1939 地址配置*****************************/
 // 设备默认的地址(地址命名是有规定的,参考J1939的附录B 地址和标识符的分配)
-#define J1939_STARTING_ADDRESS_1 0x01
+#define J1939_STARTING_ADDRESS_1 0xF4
 #define J1939_STARTING_ADDRESS_2 244
 #define J1939_STARTING_ADDRESS_3 247
 #define J1939_STARTING_ADDRESS_4 0
@@ -208,26 +209,24 @@ void J1939_CAN_Transmit(J1939_MESSAGE *MsgPtr)
         其他(Select_CAN_NODE)保持不变。就直接返回(return 0)
 */
 
+queue_entry(J1939_MESSAGE, 10) j1939_rx_queue;
+
 int J1939_CAN_Receive(J1939_MESSAGE *MsgPtr)
 {
 
     j1939_uint8_t rec = RC_SUCCESS;
-    pdu_tag       j1939_tx_data;
-
+    QUEUE_STATUS  status;
     switch (Can_Node)
     {
     case Select_CAN_NODE_1:
     {
-        j1939_tx_data.id.b.sa = MsgPtr->Mxe.SourceAddress;
-        j1939_tx_data.id.b.ps = MsgPtr->Mxe.PDUSpecific;
-        j1939_tx_data.id.b.pf = MsgPtr->Mxe.PDUFormat;
-        j1939_tx_data.id.b.dp = 0; // MsgPtr->Mxe.DataPage;
+        de_queue(&j1939_rx_queue, (*MsgPtr), status);
 
-        j1939_tx_data.id.b.r = 0; // MsgPtr->Mxe.Res;
-        j1939_tx_data.id.b.p = MsgPtr->Mxe.Priority;
-
-        j1939_tx_data.reg.dlc = MsgPtr->Mxe.DataLength;
-        return 0;
+        if (status == Q_EMPTY)
+        {
+            return 0;
+        }
+        return 1;
         break;
     }
     case Select_CAN_NODE_2:

+ 7 - 2
user/main.c

@@ -1,9 +1,11 @@
 
 #include "app_conf.h"
-#include "core_cmFunc.h"
+// #include "core_cmFunc.h"
+#include "ble_core.h"
 #include "dev_conf.h"
 #include "hal_can.h"
 #include "hal_conf.h"
+#include "hal_pwm.h"
 #include "misc.h"
 
 #define APP_FLASH_OFFSET 0x8000
@@ -19,9 +21,12 @@ int main(void)
     NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
     hal_systick_init();
     hal_gpio_init();
-    // can_queue_init();
+    pwm_init(&pwm_timer3_content);
+    pwm_mode(&pwm_timer3_content, 1);
     dev_can_network_init();
     usart_config_init(&usart1_context, 115200);
+    usart_config_init(&usart2_context, 9600);
+    ble_init();
     hal_i2c1_init();
     dev_key_button_init();