Commit 1a4adee7 authored by 张金硕's avatar 张金硕

🐞 fix:替换can的厂家库

parent f4fc76dc
...@@ -384,7 +384,7 @@ typedef struct ...@@ -384,7 +384,7 @@ typedef struct
#define CAN_CCTRL_OPMODE_IDLE ((uint16_t)0x0007U) #define CAN_CCTRL_OPMODE_IDLE ((uint16_t)0x0007U)
#define CAN_CCTRL_OPMODE_NORMAL ((uint16_t)0x0106U)//0x0100U #define CAN_CCTRL_OPMODE_NORMAL ((uint16_t)0x0106U)//0x0100U
#define CAN_CCTRL_OPMODE_NORMAL_ABT ((uint16_t)0x0205U)//0x0200U #define CAN_CCTRL_OPMODE_NORMAL_ABT ((uint16_t)0x0205U)//0x0200U
#define CAN_CCTRL_OPMODE_ONLY_RX ((uint16_t)0x0304U)//0x0300U #define CAN_CCTRL_OPMODE_ONLY_RX ((uint16_t)0x0304U)//0x0300U
#define CAN_CCTRL_OPMODE_SHOT ((uint16_t)0x0403U)//0x0400U #define CAN_CCTRL_OPMODE_SHOT ((uint16_t)0x0403U)//0x0400U
#define CAN_CCTRL_OPMODE_TEST ((uint16_t)0x0502U)//0x0500U #define CAN_CCTRL_OPMODE_TEST ((uint16_t)0x0502U)//0x0500U
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
****************************************************************************** ******************************************************************************
* @file can.c * @file can.c
* @author MCD Application Team * @author MCD Application Team
* @version V1.0.2 * @version V1.0.1
* @date 2-April-2024 * @date 2-April-2024
* @brief This file provides firmware functions to manage the following * @brief This file provides firmware functions to manage the following
* functionalities of the Controller area network (CAN) peripheral: * functionalities of the Controller area network (CAN) peripheral:
......
...@@ -3,10 +3,9 @@ ...@@ -3,10 +3,9 @@
#include "isr.h" #include "isr.h"
#include "rte_can.h" #include "rte_can.h"
CANBuffList_t CanBufList = {0};
CANMSG_Type* CANMSG; CANMSG_Type* CANMSG;
CanTxRxMsg CAN_RecvMsg; CanTxRxMsg CAN_RecvMsg;
CANBuffList_t CanBufList = {0};
can_rx_callback can_rx_handler = NULL; can_rx_callback can_rx_handler = NULL;
uint8_t Read_RingBuff(CanTxRxMsg *data) uint8_t Read_RingBuff(CanTxRxMsg *data)
...@@ -20,29 +19,34 @@ uint8_t Read_RingBuff(CanTxRxMsg *data) ...@@ -20,29 +19,34 @@ uint8_t Read_RingBuff(CanTxRxMsg *data)
CanBufList.length--; CanBufList.length--;
return 1; return 1;
} }
/** /**
* @brief CAN就收完成回调 * @brief CAN就收完成回调
* *
* @param msg * @param msg
*/ */
static void can_recv_handler(void *msg) static void can_recv_handler(void)
{ {
INTC_ClearPendingIRQ(CAN0REC_IRQn); INTC_ClearPendingIRQ(CAN0REC_IRQn);
if (CAN_GetFlagStatus(CAN0, CAN_FLAG_REC) != RESET) if (CAN_GetFlagStatus(CAN0, CAN_FLAG_REC) != RESET)
{ {
CAN_ClearFlag(CAN0, CAN_FLAG_REC); CAN_ClearFlag(CAN0, CAN_FLAG_REC);
CAN_Receive_IT(CAN0, &CanBufList); CAN_Receive_IT(CAN0, &CanBufList);
Read_RingBuff(&CAN_RecvMsg); Read_RingBuff(&CAN_RecvMsg);
CAN_Receive(CAN0,&CAN_RecvMsg,100);
if (can_rx_handler != NULL) if (can_rx_handler != NULL)
{ {
can_rx_handler(&CAN_RecvMsg); can_rx_handler(&CAN_RecvMsg);
} }
} }
} }
static void can_error_handler(void)
{
INTC_ClearPendingIRQ(CAN0ERR_IRQn);
CANErr_Recover(CAN0);
}
/** /**
* @brief CAN初始�? * @brief CAN初始�?
* *
...@@ -97,11 +101,13 @@ uint8_t rte_can_init(can_config_st_t *config) ...@@ -97,11 +101,13 @@ uint8_t rte_can_init(can_config_st_t *config)
CAN_OperatingModeRequest(CAN0, CAN_OpMode_Normal); CAN_OperatingModeRequest(CAN0, CAN_OpMode_Normal);
CAN_ITConfig(CAN0, CAN_IT_REC, ENABLE); CAN_ITConfig(CAN0, CAN_IT_REC | CAN_IT_ERR_STATE | CAN_IT_ERR_PROTO, ENABLE); // |CAN_IT_TRX
ISR_Register(CAN0REC_IRQn, can_recv_handler); ISR_Register(CAN0REC_IRQn, can_recv_handler);
INTC_EnableIRQ(CAN0REC_IRQn); // ISR_Register(CAN0TRX_IRQn, can_tx_handler);
ISR_Register(CAN0ERR_IRQn, can_error_handler);
// ISR_DisRegister(CAN0REC_IRQn, can_recv_handler); // ISR_DisRegister(CAN0REC_IRQn, can_recv_handler);
......
...@@ -31,7 +31,7 @@ typedef enum ...@@ -31,7 +31,7 @@ typedef enum
} CAN_CH; } CAN_CH;
#pragma pack(4) #pragma pack(4)
typedef struct typedef struct __attribute__((aligned(4)))
{ {
CAN_CH ch; CAN_CH ch;
CAN_freq freq; CAN_freq freq;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment