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

🐞 fix:替换can的厂家库

parent f4fc76dc
......@@ -2,7 +2,7 @@
******************************************************************************
* @file can.c
* @author MCD Application Team
* @version V1.0.2
* @version V1.0.1
* @date 2-April-2024
* @brief This file provides firmware functions to manage the following
* functionalities of the Controller area network (CAN) peripheral:
......
......@@ -3,10 +3,9 @@
#include "isr.h"
#include "rte_can.h"
CANBuffList_t CanBufList = {0};
CANMSG_Type* CANMSG;
CanTxRxMsg CAN_RecvMsg;
CANBuffList_t CanBufList = {0};
can_rx_callback can_rx_handler = NULL;
uint8_t Read_RingBuff(CanTxRxMsg *data)
......@@ -20,29 +19,34 @@ uint8_t Read_RingBuff(CanTxRxMsg *data)
CanBufList.length--;
return 1;
}
/**
* @brief CAN就收完成回调
*
* @param msg
*/
static void can_recv_handler(void *msg)
static void can_recv_handler(void)
{
INTC_ClearPendingIRQ(CAN0REC_IRQn);
if (CAN_GetFlagStatus(CAN0, CAN_FLAG_REC) != RESET)
{
CAN_ClearFlag(CAN0, CAN_FLAG_REC);
CAN_Receive_IT(CAN0, &CanBufList);
Read_RingBuff(&CAN_RecvMsg);
CAN_Receive(CAN0,&CAN_RecvMsg,100);
if (can_rx_handler != NULL)
{
can_rx_handler(&CAN_RecvMsg);
}
}
}
static void can_error_handler(void)
{
INTC_ClearPendingIRQ(CAN0ERR_IRQn);
CANErr_Recover(CAN0);
}
/**
* @brief CAN初始�?
*
......@@ -97,11 +101,13 @@ uint8_t rte_can_init(can_config_st_t *config)
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);
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);
......
......@@ -31,7 +31,7 @@ typedef enum
} CAN_CH;
#pragma pack(4)
typedef struct
typedef struct __attribute__((aligned(4)))
{
CAN_CH ch;
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