Procházet zdrojové kódy

CAN驱动分离一下

樊春春 před 3 měsíci
rodič
revize
7222924b07

+ 111 - 135
CMakeLists.txt

@@ -18,89 +18,90 @@ set(CMAKE_CXX_EXTENSIONS ON)
 add_definitions(-w)
 
 # MCU 参数设置
-set(MCU_PARAMS
-        -mthumb
-        -mcpu=cortex-m4
-#        -mfpu=fpv5-d16
-        # -mfloat-abi=soft
-        )
+set(TARGET_FLAGS
+    -mthumb
+    -mcpu=cortex-m4
+    -mfpu=fpv4-sp-d16
+    -mfloat-abi=hard
+    )
 
 # C 源文件
 file(GLOB_RECURSE C_SRCS
-        ${CMAKE_CURRENT_SOURCE_DIR}/applications/*.c
-        ${CMAKE_CURRENT_SOURCE_DIR}/common/src/*.c
-        ${CMAKE_CURRENT_SOURCE_DIR}/dev/*.c
-        ${CMAKE_CURRENT_SOURCE_DIR}/drivers/can/*.c
-        ${CMAKE_CURRENT_SOURCE_DIR}/drivers/flash/*.c
-        ${CMAKE_CURRENT_SOURCE_DIR}/drivers/gpio/*.c
-        ${CMAKE_CURRENT_SOURCE_DIR}/drivers/i2c/*.c
-        ${CMAKE_CURRENT_SOURCE_DIR}/drivers/pwm/*.c
-        ${CMAKE_CURRENT_SOURCE_DIR}/drivers/systick/*.c
-        ${CMAKE_CURRENT_SOURCE_DIR}/drivers/uart/*.c
-        ${CMAKE_CURRENT_SOURCE_DIR}/modules/ble/*.c
-        ${CMAKE_CURRENT_SOURCE_DIR}/modules/can/*.c
-        ${CMAKE_CURRENT_SOURCE_DIR}/modules/cli/*.c
-        ${CMAKE_CURRENT_SOURCE_DIR}/modules/eeprom/*.c
-        ${CMAKE_CURRENT_SOURCE_DIR}/modules/esp8266/*.c
-        ${CMAKE_CURRENT_SOURCE_DIR}/modules/gpio/*.c
-        ${CMAKE_CURRENT_SOURCE_DIR}/modules/iap/*.c
-        ${CMAKE_CURRENT_SOURCE_DIR}/modules/task/*.c
-        ${CMAKE_CURRENT_SOURCE_DIR}/modules/uart/*.c
-        ${CMAKE_CURRENT_SOURCE_DIR}/project/*.c
-        ${CMAKE_CURRENT_SOURCE_DIR}/project/startup/gcc/startup_stm32f40_41xxx.s
-        ${CMAKE_CURRENT_SOURCE_DIR}/vendors/ST/STM32F4xx_StdPeriph_Driver/src/*.c
-        ${CMAKE_CURRENT_SOURCE_DIR}/vendors/multi_button/multi_button.c
-        ${CMAKE_CURRENT_SOURCE_DIR}/vendors/j1939/source/*.c
-        )
+    ${CMAKE_CURRENT_SOURCE_DIR}/applications/*.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/common/src/*.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/drivers/can/*.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/drivers/flash/*.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/drivers/gpio/*.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/drivers/i2c/*.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/drivers/pwm/*.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/drivers/systick/*.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/drivers/uart/*.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/modules/ble/*.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/modules/can/*.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/modules/cli/*.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/modules/eeprom/*.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/modules/esp8266/*.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/modules/gpio/*.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/modules/iap/*.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/modules/task/*.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/modules/uart/*.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/project/*.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/project/startup/gcc/startup_stm32f40_41xxx.s
+    ${CMAKE_CURRENT_SOURCE_DIR}/vendors/ST/STM32F4xx_StdPeriph_Driver/src/*.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/vendors/multi_button/multi_button.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/vendors/j1939/source/*.c
+    )
 file(GLOB_RECURSE R_SRCS
-        ${CMAKE_CURRENT_SOURCE_DIR}/vendors/ST/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_qspi.c
-        ${CMAKE_CURRENT_SOURCE_DIR}/vendors/ST/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_fmpi2c.c
-        ${CMAKE_CURRENT_SOURCE_DIR}/vendors/ST/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_fmc.c
-        ${CMAKE_CURRENT_SOURCE_DIR}/vendors/ST/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_cec.c
-        ${CMAKE_CURRENT_SOURCE_DIR}/vendors/ST/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_spdifrx.c
-        )
+    ${CMAKE_CURRENT_SOURCE_DIR}/vendors/ST/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_qspi.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/vendors/ST/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_fmpi2c.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/vendors/ST/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_fmc.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/vendors/ST/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_cec.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/vendors/ST/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_spdifrx.c
+    )
 
 list(REMOVE_ITEM C_SRCS ${R_SRCS})
 
 # C .h文件
 set(INC_C_DIRS
-        ${CMAKE_CURRENT_SOURCE_DIR}/applications
-        ${CMAKE_CURRENT_SOURCE_DIR}/applications/task
-        ${CMAKE_CURRENT_SOURCE_DIR}/common/inc
-        ${CMAKE_CURRENT_SOURCE_DIR}/dev
-        ${CMAKE_CURRENT_SOURCE_DIR}/drivers/can
-        ${CMAKE_CURRENT_SOURCE_DIR}/drivers/flash
-        ${CMAKE_CURRENT_SOURCE_DIR}/drivers/gpio
-        ${CMAKE_CURRENT_SOURCE_DIR}/drivers/i2c
-        ${CMAKE_CURRENT_SOURCE_DIR}/drivers/pwm
-        ${CMAKE_CURRENT_SOURCE_DIR}/drivers/systick
-        ${CMAKE_CURRENT_SOURCE_DIR}/drivers/uart
-        ${CMAKE_CURRENT_SOURCE_DIR}/modules/ble
-        ${CMAKE_CURRENT_SOURCE_DIR}/modules/can
-        ${CMAKE_CURRENT_SOURCE_DIR}/modules/cli
-        ${CMAKE_CURRENT_SOURCE_DIR}/modules/eeprom
-        ${CMAKE_CURRENT_SOURCE_DIR}/modules/esp8266
-        ${CMAKE_CURRENT_SOURCE_DIR}/modules/gpio
-        ${CMAKE_CURRENT_SOURCE_DIR}/modules/iap
-        ${CMAKE_CURRENT_SOURCE_DIR}/modules/task
-        ${CMAKE_CURRENT_SOURCE_DIR}/modules/uart
-        ${CMAKE_CURRENT_SOURCE_DIR}/project
-        ${CMAKE_CURRENT_SOURCE_DIR}/vendors/ST/CMSIS/Include
-        ${CMAKE_CURRENT_SOURCE_DIR}/vendors/ST/CMSIS/Device/ST/STM32F4xx/Include
-        ${CMAKE_CURRENT_SOURCE_DIR}/vendors/ST/STM32F4xx_StdPeriph_Driver/inc
-        ${CMAKE_CURRENT_SOURCE_DIR}/vendors/multi_button
-        ${CMAKE_CURRENT_SOURCE_DIR}/vendors/j1939/source
-        )
+    ${CMAKE_CURRENT_SOURCE_DIR}/applications
+    ${CMAKE_CURRENT_SOURCE_DIR}/applications/task
+    ${CMAKE_CURRENT_SOURCE_DIR}/common/inc
+    ${CMAKE_CURRENT_SOURCE_DIR}/dev
+    ${CMAKE_CURRENT_SOURCE_DIR}/drivers/can
+    ${CMAKE_CURRENT_SOURCE_DIR}/drivers/flash
+    ${CMAKE_CURRENT_SOURCE_DIR}/drivers/gpio
+    ${CMAKE_CURRENT_SOURCE_DIR}/drivers/i2c
+    ${CMAKE_CURRENT_SOURCE_DIR}/drivers/pwm
+    ${CMAKE_CURRENT_SOURCE_DIR}/drivers/systick
+    ${CMAKE_CURRENT_SOURCE_DIR}/drivers/uart
+    ${CMAKE_CURRENT_SOURCE_DIR}/modules/ble
+    ${CMAKE_CURRENT_SOURCE_DIR}/modules/can
+    ${CMAKE_CURRENT_SOURCE_DIR}/modules/cli
+    ${CMAKE_CURRENT_SOURCE_DIR}/modules/eeprom
+    ${CMAKE_CURRENT_SOURCE_DIR}/modules/esp8266
+    ${CMAKE_CURRENT_SOURCE_DIR}/modules/gpio
+    ${CMAKE_CURRENT_SOURCE_DIR}/modules/iap
+    ${CMAKE_CURRENT_SOURCE_DIR}/modules/task
+    ${CMAKE_CURRENT_SOURCE_DIR}/modules/uart
+    ${CMAKE_CURRENT_SOURCE_DIR}/project
+    ${CMAKE_CURRENT_SOURCE_DIR}/vendors/ST/CMSIS/Include
+    ${CMAKE_CURRENT_SOURCE_DIR}/vendors/ST/CMSIS/Device/ST/STM32F4xx/Include
+    ${CMAKE_CURRENT_SOURCE_DIR}/vendors/ST/STM32F4xx_StdPeriph_Driver/inc
+    ${CMAKE_CURRENT_SOURCE_DIR}/vendors/multi_button
+    ${CMAKE_CURRENT_SOURCE_DIR}/vendors/j1939/source
+    )
 
 set(INC_CXX_DIRS)
+
 set(INC_ASM_DIRS)
 
 # 链接定义
 set(C_SYMB
-        "DEBUG"
-        "STM32F40_41xxx"
-        "USE_STDPERIPH_DRIVER"
-        )
+    "DEBUG"
+    "STM32F40_41xxx"
+    "USE_STDPERIPH_DRIVER"
+    )
+
 set(CXX_SYMB)
 set(ASM_SYMB)
 
@@ -110,15 +111,16 @@ set(LINK_LIBS)
 
 # 链接脚本
 set(LINK_SRC
-        ${CMAKE_CURRENT_SOURCE_DIR}/project/STM32F417IG_FLASH.ld
-        )
+    ${CMAKE_CURRENT_SOURCE_DIR}/project/STM32F417IG_FLASH.ld
+    )
 
 # 编译器参数
-set(compiler_OPTS)
+set(COMPILER_OPTS)
 
 # 链接脚本参数
-set(LINK_OPTS)
-
+set(LINK_OPTS
+    --specs=nosys.specs
+    )
 
 link_directories(${CMAKE_PROJECT_NAME} ${LINK_DIRS})
 add_executable(${CMAKE_PROJECT_NAME})
@@ -126,80 +128,54 @@ target_sources(${CMAKE_PROJECT_NAME} PUBLIC ${C_SRCS})
 
 # 添加 include 路径
 target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE
-        $<$<COMPILE_LANGUAGE:C>: ${INC_C_DIRS}>
-        $<$<COMPILE_LANGUAGE:CXX>: ${INC_CXX_DIRS}>
-        $<$<COMPILE_LANGUAGE:ASM>: ${INC_ASM_DIRS}>
-        )
+    $<$<COMPILE_LANGUAGE:C>:   ${INC_C_DIRS}>
+    $<$<COMPILE_LANGUAGE:CXX>: ${INC_CXX_DIRS}>
+    $<$<COMPILE_LANGUAGE:ASM>: ${INC_ASM_DIRS}>
+    )
 
 # 添加 链接 文件
 target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE
-        $<$<COMPILE_LANGUAGE:C>: ${C_SYMB}>
-        $<$<COMPILE_LANGUAGE:CXX>: ${CXX_SYMB}>
-        $<$<COMPILE_LANGUAGE:ASM>: ${ASM_SYMB}>
-
-        $<$<CONFIG:Debug>:DEBUG>
-        $<$<CONFIG:Release>: >
-        )
+    $<$<COMPILE_LANGUAGE:C>:   ${C_SYMB}>
+    $<$<COMPILE_LANGUAGE:CXX>: ${CXX_SYMB}>
+    $<$<COMPILE_LANGUAGE:ASM>: ${ASM_SYMB}>
+    $<$<CONFIG:Debug>:DEBUG>
+    $<$<CONFIG:Release>: >
+    )
 
 target_link_libraries(${CMAKE_PROJECT_NAME} ${LINK_LIBS})
 
 # 编译器参数
 target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE
-        ${MCU_PARAMS}
-        ${compiler_OPTS}
-        -Wall
-        -Wextra
-        -Wpedantic
-        $<$<COMPILE_LANGUAGE:C>: >
-        $<$<COMPILE_LANGUAGE:CXX>:
-
-        # 去除编译警告
-        -Wno-unused-variable
-        -Wno-pointer-sign
-        -Wno-unused-but-set-variable
-        -Wno-unused-function
-        -Wno-unused-parameter
-        -Wno-format=
-        # -Wno-volatile
-        # -Wold-style-cast
-        # -Wuseless-cast
-        # -Wsuggest-override
-        >
-        $<$<COMPILE_LANGUAGE:ASM>:-x assembler-with-cpp -MMD -MP>
-        $<$<CONFIG:Debug>:-Og -g3 -ggdb>
-        $<$<CONFIG:Release>:-Og -g0>
-        )
+    ${TARGET_FLAGS}
+    ${COMPILER_OPTS}
+    $<$<COMPILE_LANGUAGE:C>: >
+    $<$<COMPILE_LANGUAGE:CXX>: >
+    $<$<COMPILE_LANGUAGE:ASM>: >
+    $<$<CONFIG:Debug>:-Og -g3 -ggdb>
+    $<$<CONFIG:Release>:-Og -g0>
+    )
 
 # 链接参数
 target_link_options(${CMAKE_PROJECT_NAME} PRIVATE
-        -T${LINK_SRC}
-        ${MCU_PARAMS}
-        ${LINK_OPTS}
-        -Wl,-Map=${CMAKE_PROJECT_NAME}.map
-        # -u _printf_float
-        --specs=nosys.specs
-        -Wl,--start-group
-        -lc
-        -lm
-        -lstdc++
-        -lsupc++
-        -Wl,--end-group
-        # Allow good software remapping across address space (with proper GCC section making)
-        -Wl,-z,max-page-size=8
-        -Wl,--print-memory-usage
-        )
+    ${TARGET_FLAGS}
+    -T${LINK_SRC}
+    ${LINK_OPTS}
+    -Wl,-Map=${CMAKE_PROJECT_NAME}.map
+    -Wl,--gc-sections
+    -Wl,--start-group
+    -lc
+    -lm
+    -lstdc++
+    -lsupc++
+    -Wl,--end-group
+    # Allow good software remapping across address space (with proper GCC section making)
+    -Wl,-z,max-page-size=8
+    -Wl,--print-memory-usage
+    )
 
 # post-build
-add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
-        COMMAND ${CMAKE_SIZE} $<TARGET_FILE:${CMAKE_PROJECT_NAME}>
-        )
-
+add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_SIZE} $<TARGET_FILE:${CMAKE_PROJECT_NAME}>)
 # 生成 hex 文件
-add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
-        COMMAND ${CMAKE_OBJCOPY} -O ihex $<TARGET_FILE:${CMAKE_PROJECT_NAME}> ${CMAKE_PROJECT_NAME}.hex
-        )
-
+add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_OBJCOPY} -O ihex $<TARGET_FILE:${CMAKE_PROJECT_NAME}> ${CMAKE_PROJECT_NAME}.hex)
 # 生成 bin 文件
-add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
-        COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:${CMAKE_PROJECT_NAME}> ${CMAKE_PROJECT_NAME}.bin
-        )
+add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:${CMAKE_PROJECT_NAME}> ${CMAKE_PROJECT_NAME}.bin)

+ 5 - 3
cmake/gcc-arm-none-eabi.cmake

@@ -4,12 +4,14 @@ set(CMAKE_SYSTEM_PROCESSOR          arm)
 # Some default GCC settings
 # arm-none-eabi- must be part of path environment
 set(TOOLCHAIN_PREFIX                arm-none-eabi-)
-set(FLAGS                           "-fdata-sections -ffunction-sections --specs=nano.specs -Wl,--gc-sections")
+set(C_FLAGS                         "-Wall -Wextra -Wpedantic -fdata-sections -ffunction-sections --specs=nano.specs -Wl,--gc-sections")
+set(ASM_FLAGS                       "-x assembler-with-cpp -MMD -MP")
 set(CPP_FLAGS                       "-fno-rtti -fno-exceptions -fno-threadsafe-statics")
 
-set(CMAKE_C_COMPILER                ${TOOLCHAIN_PREFIX}gcc ${FLAGS})
+set(CMAKE_C_COMPILER                ${TOOLCHAIN_PREFIX}gcc ${C_FLAGS})
 set(CMAKE_ASM_COMPILER              ${CMAKE_C_COMPILER})
-set(CMAKE_CXX_COMPILER              ${TOOLCHAIN_PREFIX}g++ ${FLAGS} ${CPP_FLAGS})
+set(CMAKE_CXX_COMPILER              ${TOOLCHAIN_PREFIX}g++ ${C_FLAGS} ${CPP_FLAGS})
+set(CMAKE_LINKER                    ${TOOLCHAIN_PREFIX}g++)
 set(CMAKE_OBJCOPY                   ${TOOLCHAIN_PREFIX}objcopy)
 set(CMAKE_SIZE                      ${TOOLCHAIN_PREFIX}size)
 

+ 0 - 31
common/inc/queue.h

@@ -1,36 +1,5 @@
 #ifndef __QUEUE_H
 #define __QUEUE_H
-#include "stdint.h"
-
-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];
-        uint64_t u64_buf;
-    } data;
-} pdu_tag, *p_pdu_tag;
 
 typedef enum
 {

+ 8 - 0
common/inc/utils.h

@@ -26,13 +26,21 @@ extern "C" {
  *                                          Includes                                             *
  ************************************************************************************************/
 
+#include "stdint.h"
+
 /************************************************************************************************
  *                                          Defines                                              *
  ************************************************************************************************/
+
 #define ARR_SIZE(a) sizeof(a) / sizeof((a)[0])
+
 /************************************************************************************************
  *                                          Defines                                              *
  ************************************************************************************************/
+
+void data_bit_move(uint8_t start_bit, uint8_t bit_len, uint64_t data);
+void product_array(uint8_t send_array[8]);
+
 #ifdef __cplusplus
 };
 #endif

+ 26 - 0
common/src/utils.c

@@ -0,0 +1,26 @@
+
+#include "utils.h"
+#include "hal_math.h"
+
+static uint64_t base_data;
+
+void data_bit_move(uint8_t start_bit, uint8_t bit_len, uint64_t data)
+{
+    uint64_t mask        = 0;
+    uint64_t source_data = (uint64_t)data;
+    mask                 = hal_pow(2, bit_len) - 1;
+    base_data |= (mask & source_data) << start_bit;
+}
+
+void product_array(uint8_t send_array[8])
+{
+    send_array[0] = (uint8_t)base_data;
+    send_array[1] = (uint8_t)(base_data >> 8);
+    send_array[2] = (uint8_t)(base_data >> 16);
+    send_array[3] = (uint8_t)(base_data >> 24);
+    send_array[4] = (uint8_t)(base_data >> 32);
+    send_array[5] = (uint8_t)(base_data >> 40);
+    send_array[6] = (uint8_t)(base_data >> 48);
+    send_array[7] = (uint8_t)(base_data >> 56);
+    base_data     = 0;
+}

+ 0 - 61
drivers/can/can.c

@@ -1,12 +1,6 @@
 #include "can.h"
 #include "stm32f4xx.h"
 #include "stm32f4xx_gpio.h"
-#include <string.h>
-
-CanTxMsg tx_message;
-CanRxMsg rx_message;
-pcan_rx  pcan_rx_back = NULL;
-pcan_tx  pcan_tx_back = NULL;
 
 // CAN初始化
 // tsjw:重新同步跳跃时间单元.范围:CAN_SJW_1tq~ CAN_SJW_4tq
@@ -105,58 +99,3 @@ void can_init(void)
 #error no can baud macro!;
 #endif
 }
-
-uint8_t can_msg_tx(uint32_t id, uint8_t id_type, uint8_t *p_data, uint8_t len)
-{
-    uint8_t flg = 0;
-    if (id_type)
-    {
-        tx_message.ExtId = id; // 设置扩展标示符(29位)
-    }
-    else
-    {
-        tx_message.StdId = id_type; // 标准标识符为0
-    }
-
-    tx_message.IDE = id_type; // 使用扩展标识符
-    tx_message.DLC = len;     // 发送两帧信息
-    if (len == 0)
-    {
-        tx_message.RTR = CAN_RTR_Remote; // 消息类型为远程帧
-    }
-    else
-    {
-        tx_message.RTR = CAN_RTR_Data; // 消息类型为数据帧
-        memcpy(tx_message.Data, p_data, len);
-    }
-    flg = CAN_Transmit(CAN1, &tx_message);
-
-    return flg;
-}
-
-void can_rx_back_init(pcan_rx p_fun)
-{
-    pcan_rx_back = p_fun;
-}
-
-void can_tx_back_init(pcan_tx p_fun)
-{
-    pcan_tx_back = p_fun;
-}
-
-void CAN1_TX_IRQHandler(void)
-{
-    if (pcan_tx_back != NULL)
-    {
-        pcan_tx_back();
-    }
-}
-
-void CAN1_RX0_IRQHandler(void)
-{
-    CAN_Receive(CAN1, CAN_FIFO0, &rx_message);
-    if (pcan_rx_back != NULL)
-    {
-        pcan_rx_back(rx_message);
-    }
-}

+ 1 - 9
drivers/can/can.h

@@ -1,16 +1,8 @@
 #ifndef __CAN_H
 #define __CAN_H
 
-#include "stm32f4xx.h"
-
 #define __CAN_BAUD_250K
 
-typedef void (*pcan_tx)(void);
-typedef void (*pcan_rx)(CanRxMsg);
-
-void    can_init(); // CAN初始化
-uint8_t can_msg_tx(uint32_t id, uint8_t id_type, uint8_t *p_data, uint8_t len);
-void    can_rx_back_init(pcan_rx p_fun);
-void    can_tx_back_init(pcan_tx p_fun);
+void can_init(); // CAN初始化
 
 #endif

+ 1 - 1
drivers/gpio/gpio.c

@@ -52,4 +52,4 @@ void gpio_init(void)
     led_init();
     key_init();
     beep_init();
-}
+}

+ 3 - 3
modules/can/dev_can_cali.c → modules/can/can_cali.c

@@ -1,6 +1,6 @@
-#include "dev_can_cali.h"
-#include "dev_can_id.h"
-#include "queue.h"
+#include "can_cali.h"
+#include "can_id_deal.h"
+#include "utils.h"
 #include <stdint.h>
 
 enum

+ 4 - 1
modules/can/dev_can_cali.h → modules/can/can_cali.h

@@ -25,7 +25,9 @@ extern "C" {
 /************************************************************************************************
  *                                          Includes                                             *
  ************************************************************************************************/
-#include "dev_can.h"
+
+#include "can_interface.h"
+
 /************************************************************************************************
  *                                          Defines                                              *
  ************************************************************************************************/
@@ -35,6 +37,7 @@ void can_cali_msg_analysis(pdu_tag rec_msg);
 /************************************************************************************************
  *                                          Defines                                              *
  ************************************************************************************************/
+
 #ifdef __cplusplus
 };
 #endif

+ 3 - 3
modules/can/dev_can_id.c → modules/can/can_id_deal.c

@@ -1,9 +1,9 @@
 /************************************************************************************************
  *                                          Include                                              *
  ************************************************************************************************/
-#include "dev_can_id.h"
-#include "dev_can.h"
-#include <stdint.h>
+
+#include "can_id_deal.h"
+#include "can_task.h"
 
 /************************************************************************************************
  *                                          Config                                                *

+ 6 - 2
modules/can/dev_can_id.h → modules/can/can_id_deal.h

@@ -1,8 +1,6 @@
 #ifndef __DEV_CAN_ID_H
 #define __DEV_CAN_ID_H
 
-#include "queue.h"
-#include <stdint.h>
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -28,9 +26,13 @@ extern "C" {
  *                                          Includes                                             *
  ************************************************************************************************/
 
+#include "can_interface.h"
+#include <stdint.h>
+
 /************************************************************************************************
  *                                          Defines                                              *
  ************************************************************************************************/
+
 extern uint32_t g_ps;
 extern uint32_t g_can_id;
 extern uint32_t g_can_ota_id;
@@ -42,9 +44,11 @@ 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);
 uint8_t  can_id_set(pdu_tag rec_msg);
+
 /************************************************************************************************
  *                                          Defines                                              *
  ************************************************************************************************/
+
 #ifdef __cplusplus
 };
 #endif

+ 62 - 0
modules/can/can_interface.c

@@ -0,0 +1,62 @@
+#include "can_interface.h"
+#include <string.h>
+
+CanTxMsg tx_message;
+CanRxMsg rx_message;
+pcan_rx  pcan_rx_back = NULL;
+pcan_tx  pcan_tx_back = NULL;
+
+void can_rx_back_init(pcan_rx p_fun)
+{
+    pcan_rx_back = p_fun;
+}
+
+void can_tx_back_init(pcan_tx p_fun)
+{
+    pcan_tx_back = p_fun;
+}
+
+uint8_t can_msg_tx(uint32_t id, uint8_t id_type, uint8_t *p_data, uint8_t len)
+{
+    uint8_t flg = 0;
+    if (id_type)
+    {
+        tx_message.ExtId = id; // 设置扩展标示符(29位)
+    }
+    else
+    {
+        tx_message.StdId = id_type; // 标准标识符为0
+    }
+
+    tx_message.IDE = id_type; // 使用扩展标识符
+    tx_message.DLC = len;     // 发送两帧信息
+    if (len == 0)
+    {
+        tx_message.RTR = CAN_RTR_Remote; // 消息类型为远程帧
+    }
+    else
+    {
+        tx_message.RTR = CAN_RTR_Data; // 消息类型为数据帧
+        memcpy(tx_message.Data, p_data, len);
+    }
+    flg = CAN_Transmit(CAN1, &tx_message);
+
+    return flg;
+}
+
+void can_tx_iqr(void)
+{
+    if (pcan_tx_back != NULL)
+    {
+        pcan_tx_back();
+    }
+}
+
+void can_rx_iqr(void)
+{
+    CAN_Receive(CAN1, CAN_FIFO0, &rx_message);
+    if (pcan_rx_back != NULL)
+    {
+        pcan_rx_back(rx_message);
+    }
+}

+ 90 - 0
modules/can/can_interface.h

@@ -0,0 +1,90 @@
+#ifndef __CAN_INTERFACE_H
+#define __CAN_INTERFACE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifdef __CAN_INTERFACE_H_GLOBAL
+#define __CAN_INTERFACE_H_EXTERN
+#else
+#define __CAN_INTERFACE_H_EXTERN extern
+#endif
+
+/************************************************************************************************
+ *                                          Version *
+ ************************************************************************************************/
+
+/************************************************************************************************
+ *                                          How to use *
+ ************************************************************************************************/
+
+/************************************************************************************************
+ *                                          Enable config                                        *
+ ************************************************************************************************/
+
+/************************************************************************************************
+ *                                          Includes *
+ ************************************************************************************************/
+
+#include "stm32f4xx_can.h"
+
+/************************************************************************************************
+ *                                          Defines                                              *
+ ************************************************************************************************/
+
+#define CAN_IER              CAN1->IER
+#define CAN_IT_TME_ENABLE()  CAN_ITConfig(CAN1, CAN_IT_TME, ENABLE)
+#define CAN_IT_TME_DISABLE() CAN_ITConfig(CAN1, CAN_IT_TME, DISABLE)
+
+/************************************************************************************************
+ *                                          Typedefs                                            *
+ ************************************************************************************************/
+
+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];
+        uint64_t u64_buf;
+    } data;
+} pdu_tag, *p_pdu_tag;
+
+typedef void (*pcan_tx)(void);
+typedef void (*pcan_rx)(CanRxMsg);
+
+/************************************************************************************************
+ *                                          Interfaces                                          *
+ ************************************************************************************************/
+
+uint8_t can_msg_tx(uint32_t id, uint8_t id_type, uint8_t *p_data, uint8_t len);
+void    can_rx_back_init(pcan_rx p_fun);
+void    can_tx_back_init(pcan_tx p_fun);
+void    can_tx_iqr(void);
+void    can_rx_iqr(void);
+
+#ifdef __cplusplus
+};
+#endif
+
+#endif // __CAN_INTERFACE_H

+ 41 - 168
modules/can/dev_can.c → modules/can/can_task.c

@@ -1,48 +1,20 @@
-#include "dev_can.h"
+#include "can_task.h"
 #include "J1939.H"
-#include "can.h"
-#include "core_cmFunc.h"
-#include "dev_can_cali.h"
-#include "dev_can_id.h"
-#include "hal_math.h"
+#include "can_cali.h"
+#include "can_id_deal.h"
+#include "can_interface.h"
 #include "iap.h"
 #include "queue.h"
+#include "utils.h"
 #include <stdint.h>
-#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};
-
+uint8_t     PGN_00B000H_Ary[20] = {0};
 extern void j1939_msg_push_queue(p_pdu_tag rec_msg);
-
-uint8_t recv_can_id = 0;
-
-static uint64_t base_data;
-
-void data_bit_move(uint8_t start_bit, uint8_t bit_len, uint64_t data)
-{
-    uint64_t mask        = 0;
-    uint64_t source_data = (uint64_t)data;
-    mask                 = hal_pow(2, bit_len) - 1;
-    base_data |= (mask & source_data) << start_bit;
-}
-
-void product_array(uint8_t send_array[8])
-{
-    send_array[0] = (uint8_t)base_data;
-    send_array[1] = (uint8_t)(base_data >> 8);
-    send_array[2] = (uint8_t)(base_data >> 16);
-    send_array[3] = (uint8_t)(base_data >> 24);
-    send_array[4] = (uint8_t)(base_data >> 32);
-    send_array[5] = (uint8_t)(base_data >> 40);
-    send_array[6] = (uint8_t)(base_data >> 48);
-    send_array[7] = (uint8_t)(base_data >> 56);
-    base_data     = 0;
-}
+uint8_t     recv_can_id = 0;
 
 uint8_t push_can_message_to_queue(uint32_t id, uint8_t len, uint8_t *p_data)
 {
@@ -54,77 +26,47 @@ uint8_t push_can_message_to_queue(uint32_t id, uint8_t len, uint8_t *p_data)
 
     if (id > 0x7FF)
     {
-        response_msg.reg.ide = CAN_Id_Extended;
+        response_msg.reg.ide = CAN_ID_EXT;
     }
     else
     {
-        response_msg.reg.ide = CAN_Id_Standard;
+        response_msg.reg.ide = CAN_ID_STD;
     }
 
-#if 1
     __disable_irq();
     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)
     {
         return 0;
     }
-#else
-    en_queue(can_tx, &response_msg, 1);
-#endif
     return 1;
 }
 
 static uint8_t can_tx_frame(pdu_tag can_message)
 {
-    uint8_t result = CAN_TxStatus_NoMailBox;
-    result         = can_msg_tx(can_message.id.r, can_message.reg.ide, can_message.data.u8_buf, can_message.reg.dlc);
-    return result;
-}
-
-// void can_tx_stop(CAN_TypeDef *can_perpiph, u8 mailbox_number)
-// {
-//     can_tx_mail_box_stop(can_perpiph, mailbox_number);
-// }
-
-// QUEUE_STATUS can_tx_process(p_can_queue_tag p_queue)
-// {
-//     u8 mailbox_number = 0;
-//     u8 query_result   = CAN_TxStatus_NoMailBox;
-
-//     if (queue_empty(p_queue))
-//         return Q_OK;
-//     mailbox_number = can_tx_frame(p_queue->can_message[p_queue->tail]);
-//     if (mailbox_number == CAN_TxStatus_NoMailBox)
-//         return Q_OK;
-//     query_result = can_tx_mail_box_state(CAN1, mailbox_number);
-//     if (query_result == CAN_TxStatus_Ok || query_result == CAN_TxStatus_Pending)
-//     {
-//         p_queue->tail = (p_queue->tail + 1) % MAX_QSIZE;
-//         p_queue->count--;
-//         return Q_OK;
-//     }
-//     return Q_ERR;
-// }
+
+    can_msg_tx(can_message.id.r, can_message.reg.ide, can_message.data.u8_buf, can_message.reg.dlc);
+    return 1;
+}
 
 void can_tx_callback(void)
 {
-    pdu_tag tx_data;
-    // de_queue(can_tx, &tx_data);
+    pdu_tag      tx_data;
     QUEUE_STATUS result_status;
 
     de_queue(&can_tx_queue, tx_data, result_status);
 
-    if (result_status == Q_OK) // 返回值为1代表读取成功
+    // 返回值为1代表读取成功
+    if (result_status == Q_OK)
     {
         can_tx_frame(tx_data);
-        CAN_ITConfig(CAN1, CAN_IT_TME, ENABLE);
+        CAN_IT_TME_ENABLE();
     }
     else
     {
-        CAN_ITConfig(CAN1, CAN_IT_TME, DISABLE);
+        CAN_IT_TME_DISABLE();
     }
 }
 
@@ -141,24 +83,12 @@ void can_rx_callback(CanRxMsg rx_message)
         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);
         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);
+        break;
     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, result);
-#else
-        en_queue(can_rx, &data, 1);
-#endif
         break;
     default:
         pf = (rx_message.ExtId & CAN_PGN_PF) >> 16;
@@ -179,7 +109,7 @@ void can_rx_callback(CanRxMsg rx_message)
                 data.reg.dlc = rx_message.DLC;
                 memcpy(&data.data.u8_buf[0], rx_message.Data, rx_message.DLC);
 
-                if (data.id.b.pf == CAN_IAP)
+                if (data.id.b.pf == 0xDF)
                 {
                     en_queue(&can_rx_queue, data, result);
                 }
@@ -195,20 +125,18 @@ void can_rx_callback(CanRxMsg rx_message)
         }
     }
 }
+
 uint8_t tx_flag = 0;
 
 void can_rx_ctl(pdu_tag rec_msg)
 {
-    // rec_msg.data.u8_buf[0];
-    // LED2    = !LED2;
     J1939_TP_TX_Message(0x00B300, 0xE1, PGN_00B000H_Ary, 20, 1);
 }
+
 uint8_t tx_data[8] = {0};
 uint8_t flag       = 0;
 void    can_rx_param(pdu_tag rec_msg)
 {
-    // LED2 = !LED2;
-
     tx_data[0] = rec_msg.data.u8_buf[0];
     tx_data[1] = rec_msg.data.u8_buf[1];
     tx_data[2] = rec_msg.data.u8_buf[2];
@@ -221,8 +149,6 @@ void    can_rx_param(pdu_tag rec_msg)
     {
         flag = 1;
     }
-
-    // push_can_message_to_queue(rec_msg.id.r, rec_msg.reg.dlc, rec_msg.data.u8_buf);
 }
 
 void can_rx_update(pdu_tag rec_msg)
@@ -235,49 +161,31 @@ void can_rx_update(pdu_tag rec_msg)
 }
 
 can_rx_tab can_tab[] = {
-    0x18011802,
-    can_rx_param,
-    0x18011801,
-    can_rx_ctl,
-    CAN_IAP,
-    iap_rec_handler,
-    CAN_CALI,
-    can_cali_msg_analysis,
+    {0x18011802, can_rx_param},
+    {0x18011801, can_rx_ctl},
+    {CAN_IAP, iap_rec_handler},
+    {CAN_CALI, can_cali_msg_analysis}
 
 };
 
-#define REG32(addr)     (*(volatile uint32_t *)(uint32_t)(addr))
-#define CAN_INTEN(canx) REG32((canx) + 0x14U)
-
 void can_start_send(void)
 {
     pdu_tag      tx_msg;
     QUEUE_STATUS result_status;
 
-    // if (RESET == CAN_GetITStatus(CAN1, CAN_IT_TME))
-    if (0 == ((CAN1->IER) & 0x1))
+    if (0 == ((CAN_IER) & 0x1))
     {
-#if 0
-        de_queue(can_tx, &tx_msg);
-        if (can_tx.ret == 1) // 返回值为1代表读取成功
-        {
-            can_tx_frame(tx_msg);
-            CAN_ITConfig(CAN1, CAN_IT_TME, ENABLE);
-        }
-#else
         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);
+            CAN_IT_TME_ENABLE();
         }
-
-#endif
     }
 }
 
-static uint8_t can_rx_process(void)
+static void can_rx_process(void)
 {
     uint8_t      i;
     uint8_t      flg = 0;
@@ -286,12 +194,10 @@ static uint8_t can_rx_process(void)
 
     for (uint8_t j = 0; j < 15; j++)
     {
-#if 1
         __disable_irq();
-
         de_queue(&can_rx_queue, rec_msg, result);
-        // result = de_queue(&can_rx_queue, rec_msg);
         __enable_irq();
+
         if (Q_OK == result)
         {
             for (i = 0; i < ARR_SIZE(can_tab); i++)
@@ -302,7 +208,7 @@ static uint8_t can_rx_process(void)
                     flg = 1;
                     break;
                 }
-                else if (can_tab[i].id == (rec_msg.id.b.pf << 8 | rec_msg.id.b.ps))
+                else if (can_tab[i].id == (uint32_t)(rec_msg.id.b.pf << 8 | rec_msg.id.b.ps))
                 {
                     can_tab[i].p_func(rec_msg);
                     flg = 1;
@@ -322,20 +228,6 @@ static uint8_t can_rx_process(void)
             }
             flg = 0;
         }
-#else
-        de_queue(can_rx, &rec_msg);
-        if (can_rx.ret == 1) // 返回值为1代表读取成功
-        {
-            for (i = 0; i < ARR_SIZE(can_tab); i++)
-            {
-                if (can_tab[i].id == rec_msg.id.r)
-                {
-                    can_tab[i].p_func(rec_msg);
-                    break;
-                }
-            }
-        }
-#endif
     }
 }
 
@@ -437,19 +329,10 @@ void can_tx_0x1801000F_message(void)
 void can_tx_0x18010010_message(void)
 {
     uint8_t data[8] = {0};
-    // data_bit_move(0, 8, 1);
-    // data_bit_move(8, 8, 1);
-    // data_bit_move(32, 8, 0);
-    // data_bit_move(40, 8, 0);
-    // product_array(data);
-    data[0] = 1;
-    data[1] = 1;
-    data[4] = 0;
-    data[5] = 0;
-    // push_can_message_to_queue(0x18010010, 8, data);
-    // data[1] = 5;
-    // push_can_message_to_queue(0x18010010, 8, data);
-    // data[1] = 10;
+    data[0]         = 1;
+    data[1]         = 1;
+    data[4]         = 0;
+    data[5]         = 0;
     push_can_message_to_queue(0x18010010, 8, data);
 }
 
@@ -569,14 +452,6 @@ void can_tx_0x1801001D_message(void)
 void can_tx_0x18010023_message(void)
 {
     uint8_t send_data[8] = {0};
-    // data[0]    = 'A';
-    // data[1]    = 'A';
-    // data[2]    = 'A';
-    // data[3]    = 'A';
-    // data[4]    = 'A';
-    // data[5]    = 'A';
-    // data[6]    = 'A';
-    // data[7]    = 'A';
     data_bit_move(0, 8, 'A');
     data_bit_move(8, 8, 'A');
     data_bit_move(16, 8, 'A');
@@ -603,8 +478,8 @@ void can_tx_0x18011802_message(void)
     {
         data[0] = (addr + fdf) & 0xFF;
         data[1] = (addr + fdf) >> 8;
-        data[2] = rand() & 0xFF;
-        data[3] = rand() >> 8;
+        data[2] = 0xFF;
+        data[3] = 8;
         fdf++;
         if (fdf == 80)
         {
@@ -738,7 +613,7 @@ void send_message(void)
         can_tx_0x18010012_message();
         can_tx_0x18011802_message();
         can_tx_0x18011803_message();
-        // can_tx_0x18011803_2_message();
+        can_tx_0x18011803_2_message();
         can_tx_0x18180003_message();
         can_tx_0x18190007_message();
     }
@@ -749,9 +624,8 @@ void send_message(void)
     times++;
 }
 
-void dev_can_network_init(void)
+void can_network_init(void)
 {
-    can_init();
     queue_init(&can_rx_queue);
     queue_init(&can_tx_queue);
     can_rx_back_init(can_rx_callback);
@@ -761,7 +635,6 @@ void dev_can_network_init(void)
 void can_process(void)
 {
     can_rx_process();
-    // send_message();
-    // can_tx_0x18190009_message();
+    send_message();
     can_start_send();
-}
+}

+ 63 - 0
modules/can/can_task.h

@@ -0,0 +1,63 @@
+#ifndef __CAN_TASK_H
+#define __CAN_TASK_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifdef __CAN_TASK_H_GLOBAL
+#define __CAN_TASK_H_EXTERN
+#else
+#define __CAN_TASK_H_EXTERN extern
+#endif
+
+/************************************************************************************************
+ *                                          Version                                             *
+ ************************************************************************************************/
+
+/************************************************************************************************
+ *                                          How to use                                          *
+ ************************************************************************************************/
+
+/************************************************************************************************
+ *                                          Enable config                                        *
+ ************************************************************************************************/
+
+/************************************************************************************************
+ *                                          Includes                                            *
+ ************************************************************************************************/
+
+#include "can_interface.h"
+
+/************************************************************************************************
+ *                                          Defines                                              *
+ ************************************************************************************************/
+
+#define CAN_PGN_PF 0xFFFF00
+#define CAN_PGN_PS 0xFF00
+
+/************************************************************************************************
+ *                                          Typedefs                                            *
+ ************************************************************************************************/
+
+typedef struct
+{
+    uint32_t id;
+    void (*p_func)(pdu_tag);
+} can_rx_tab;
+extern uint8_t recv_can_id;
+
+/************************************************************************************************
+ *                                          Interfaces                                          *
+ ************************************************************************************************/
+
+void    can_rx_callback(CanRxMsg rx_message);
+void    can_tx_callback(void);
+void    can_process(void);
+void    can_network_init(void);
+uint8_t push_can_message_to_queue(uint32_t id, uint8_t len, uint8_t *p_data);
+
+#ifdef __cplusplus
+};
+#endif
+
+#endif // __CAN_TASK_H

+ 0 - 29
modules/can/dev_can.h

@@ -1,29 +0,0 @@
-#ifndef __APP_CAN_H
-#define __APP_CAN_H
-
-#include "queue.h"
-#include "stm32f4xx_can.h"
-
-#define CAN_PGN_PF 0xFFFF00
-#define CAN_PGN_PS 0xFF00
-
-extern uint8_t recv_can_id;
-
-typedef struct
-{
-    uint32_t id;
-    void (*p_func)(pdu_tag);
-} can_rx_tab;
-
-// #define ARR_SIZE(a) sizeof(a) / a[0]
-
-#define ARR_SIZE(a) sizeof(a) / sizeof((a)[0])
-
-// #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
-void    can_rx_callback(CanRxMsg rx_message);
-void    can_tx_callback();
-void    can_process(void);
-void    dev_can_network_init();
-uint8_t push_can_message_to_queue(uint32_t id, uint8_t len, uint8_t *p_data);
-
-#endif // __APP_CAN_H

+ 2 - 2
modules/iap/iap.c

@@ -2,7 +2,7 @@
  *                                          Include                                              *
  ************************************************************************************************/
 #include "iap.h"
-#include "dev_can_id.h"
+#include "can_id_deal.h"
 #include "flash.h"
 #include "queue.h"
 #include <stdint.h>
@@ -188,7 +188,7 @@ void iap_rec_handler(pdu_tag rec_msg)
 {
     uint8_t erase_flag = 0x01;
 
-    // ota_can_id = rec_msg.id.r;
+    g_can_ota_id = rec_msg.id.r;
     if (rec_msg.data.u8_buf[0] != IAP_CMD_VERSION)
         iap_connect_clear();
 

+ 1 - 1
modules/iap/iap.h

@@ -25,7 +25,7 @@ extern "C" {
 /************************************************************************************************
  *                                          Includes                                             *
  ************************************************************************************************/
-#include "dev_can.h"
+#include "can_task.h"
 #include <stdint.h>
 
 /************************************************************************************************

+ 7 - 5
modules/task/app_task.c

@@ -1,12 +1,14 @@
+#include "app_task.h"
 #include "J1939.H"
 #include "app_eeprom.h"
 #include "ble_core.h"
+#include "can_task.h"
 #include "cli.h"
 #include "dev_at24cxx.h"
-#include "dev_can.h"
 #include "dev_task.h"
 #include "gpio.h"
 #include "key.h"
+#include "led.h"
 #include "uart_task.h"
 #include <stdint.h>
 
@@ -156,10 +158,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;
+    led_on_off(1, state);
+    state = !state;
+    led_on_off(1, state);
     systick_ms_clock++;
     // printf("debug\r\n");
     // dev_led_on_off(1, !state);

+ 4 - 2
project/main.c

@@ -1,5 +1,6 @@
 #include "app_task.h"
 #include "ble_core.h"
+#include "can.h"
 #include "gpio.h"
 #include "i2c1.h"
 #include "iap.h"
@@ -23,8 +24,9 @@ int main(void)
     systick_init();
     gpio_init();
     pwm_init(&pwm_timer3_content);
-    pwm_mode(&pwm_timer3_content, 1);
-    dev_can_network_init();
+    pwm_mode(&pwm_timer3_content, 0);
+    can_init();
+    can_network_init();
     usart_config_init(&usart1_context, 115200);
     usart_config_init(&usart2_context, 9600);
     usart_config_init(&usart3_context, 115200);

+ 11 - 0
project/stm32f4xx_it.c

@@ -29,6 +29,7 @@
 
 /* Includes ------------------------------------------------------------------*/
 #include "stm32f4xx_it.h"
+#include "can_interface.h"
 #include "dev_task.h"
 #include "iap.h"
 #include "systick.h"
@@ -166,4 +167,14 @@ void UART4_IRQHandler(void)
     uart4_it();
 }
 
+void CAN1_TX_IRQHandler(void)
+{
+    can_tx_iqr();
+}
+
+void CAN1_RX0_IRQHandler(void)
+{
+    can_rx_iqr();
+}
+
 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 1 - 0
vendors/j1939/source/J1939_Config.H

@@ -41,6 +41,7 @@
 #define __J1939_Config_H
 
 #include "J1939.H"
+#include "can_interface.h"
 #include "queue.h"
 #include <stdint.h>
 #include <string.h>