mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-01-18 14:53:32 +08:00
格式化代码
This commit is contained in:
parent
b4b9394051
commit
66628f1061
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
@ -25,8 +25,9 @@ struct n32g45x_baud_rate_tab
|
||||
uint8_t notused;
|
||||
};
|
||||
|
||||
#define N32_CAN_BAUD_DEF(rate,rsjw,tbs1,tbs2,prescale) \
|
||||
{.baud_rate = rate, \
|
||||
#define N32_CAN_BAUD_DEF(rate, rsjw, tbs1, tbs2, prescale) \
|
||||
{ \
|
||||
.baud_rate = rate, \
|
||||
.RSJW = rsjw, \
|
||||
.TBS1 = tbs1, \
|
||||
.TBS2 = tbs2, \
|
||||
@ -37,7 +38,7 @@ struct n32g45x_baud_rate_tab
|
||||
struct n32g45x_can
|
||||
{
|
||||
char *name;
|
||||
CAN_Module * CANx;
|
||||
CAN_Module *CANx;
|
||||
CAN_InitType can_init;
|
||||
CAN_FilterInitType can_filter_init;
|
||||
struct rt_can_device device; /* inherit from can device */
|
||||
@ -51,9 +52,9 @@ struct n32g45x_can
|
||||
* baud calculation example: baud = Tclk / ((ss + bs1 + bs2) * brp)
|
||||
* 36MHz / ((1 + 5 + 3) * 4) = 1MHz
|
||||
*/
|
||||
#if defined (N32G45X)/* APB1 36MHz(max) */
|
||||
#if defined(N32G45X) /* APB1 36MHz(max) */
|
||||
static const struct n32g45x_baud_rate_tab can_baud_rate_tab[] =
|
||||
{
|
||||
{
|
||||
N32_CAN_BAUD_DEF(CAN1MBaud, CAN_RSJW_1tq, CAN_TBS1_5tq, CAN_TBS2_3tq, 4),
|
||||
N32_CAN_BAUD_DEF(CAN800kBaud, CAN_RSJW_1tq, CAN_TBS1_5tq, CAN_TBS2_3tq, 5),
|
||||
N32_CAN_BAUD_DEF(CAN500kBaud, CAN_RSJW_1tq, CAN_TBS1_5tq, CAN_TBS2_3tq, 8),
|
||||
@ -68,7 +69,7 @@ static const struct n32g45x_baud_rate_tab can_baud_rate_tab[] =
|
||||
|
||||
#ifdef BSP_USING_CAN1
|
||||
static struct n32g45x_can drv_can1 =
|
||||
{
|
||||
{
|
||||
.name = "can1",
|
||||
.CANx = CAN1,
|
||||
};
|
||||
@ -76,7 +77,7 @@ static struct n32g45x_can drv_can1 =
|
||||
|
||||
#ifdef BSP_USING_CAN2
|
||||
static struct n32g45x_can drv_can2 =
|
||||
{
|
||||
{
|
||||
.name = "can2",
|
||||
.CANx = CAN2,
|
||||
};
|
||||
@ -118,13 +119,12 @@ static uint8_t get_can_mode_rtt2n32(uint8_t rtt_can_mode)
|
||||
|
||||
static rt_err_t _can_filter_config(struct n32g45x_can *drv_can)
|
||||
{
|
||||
if(drv_can->CANx == CAN1)
|
||||
if (drv_can->CANx == CAN1)
|
||||
{
|
||||
CAN1_InitFilter(&(drv_can->can_filter_init));
|
||||
}
|
||||
#ifdef CAN2
|
||||
else
|
||||
if(drv_can->CANx == CAN2)
|
||||
else if (drv_can->CANx == CAN2)
|
||||
{
|
||||
CAN2_InitFilter(&(drv_can->can_filter_init));
|
||||
}
|
||||
@ -147,20 +147,16 @@ static rt_err_t _can_config(struct rt_can_device *can, struct can_configure *cfg
|
||||
drv_can = (struct n32g45x_can *)can->parent.user_data;
|
||||
RT_ASSERT(drv_can);
|
||||
|
||||
/* CAN1 and CAN2 register init */
|
||||
//CAN_DeInit(drv_can->CANx);
|
||||
|
||||
/* Configure CAN1 and CAN2 */
|
||||
if(drv_can->CANx == CAN1)
|
||||
if (drv_can->CANx == CAN1)
|
||||
{
|
||||
RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_CAN1 , ENABLE);
|
||||
RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_CAN1, ENABLE);
|
||||
n32_msp_can_init(CAN1);
|
||||
}
|
||||
#ifdef CAN2
|
||||
else
|
||||
if(drv_can->CANx == CAN2)
|
||||
else if (drv_can->CANx == CAN2)
|
||||
{
|
||||
RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_CAN2 , ENABLE);
|
||||
RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_CAN2, ENABLE);
|
||||
n32_msp_can_init(CAN2);
|
||||
}
|
||||
#endif
|
||||
@ -190,7 +186,7 @@ static rt_err_t _can_config(struct rt_can_device *can, struct can_configure *cfg
|
||||
drv_can->can_init.BaudRatePrescaler = can_baud_rate_tab[baud_index].PRESCALE;
|
||||
|
||||
/* init can */
|
||||
if( CAN_Init(drv_can->CANx, &(drv_can->can_init) ) != CAN_InitSTS_Success )
|
||||
if (CAN_Init(drv_can->CANx, &(drv_can->can_init)) != CAN_InitSTS_Success)
|
||||
{
|
||||
rt_kprintf("can init error2\n");
|
||||
return -RT_ERROR;
|
||||
@ -221,7 +217,7 @@ static rt_err_t _can_control(struct rt_can_device *can, int cmd, void *arg)
|
||||
switch (cmd)
|
||||
{
|
||||
case RT_DEVICE_CTRL_CLR_INT:
|
||||
argval = (rt_uint32_t) arg;
|
||||
argval = (rt_uint32_t)arg;
|
||||
if (argval == RT_DEVICE_FLAG_INT_RX)
|
||||
{
|
||||
if (CAN1 == drv_can->CANx)
|
||||
@ -277,7 +273,7 @@ static rt_err_t _can_control(struct rt_can_device *can, int cmd, void *arg)
|
||||
}
|
||||
break;
|
||||
case RT_DEVICE_CTRL_SET_INT:
|
||||
argval = (rt_uint32_t) arg;
|
||||
argval = (rt_uint32_t)arg;
|
||||
if (argval == RT_DEVICE_FLAG_INT_RX)
|
||||
{
|
||||
CAN_INTConfig(drv_can->CANx, CAN_INT_FMP0, ENABLE); /*!< DATFIFO 0 message pending Interrupt*/
|
||||
@ -385,7 +381,8 @@ static rt_err_t _can_control(struct rt_can_device *can, int cmd, void *arg)
|
||||
id_h = ((filter_cfg->items[i].id << 18) >> 13) & 0xFFFF;
|
||||
id_l = ((filter_cfg->items[i].id << 18) |
|
||||
(filter_cfg->items[i].ide << 2) |
|
||||
(filter_cfg->items[i].rtr << 1)) & 0xFFFF;
|
||||
(filter_cfg->items[i].rtr << 1)) &
|
||||
0xFFFF;
|
||||
mask_h = ((filter_cfg->items[i].mask << 21) >> 16) & 0xFFFF;
|
||||
mask_l = ((filter_cfg->items[i].mask << 21) | mask_l_tail) & 0xFFFF;
|
||||
}
|
||||
@ -394,11 +391,11 @@ static rt_err_t _can_control(struct rt_can_device *can, int cmd, void *arg)
|
||||
id_h = (filter_cfg->items[i].id >> 13) & 0xFFFF;
|
||||
id_l = ((filter_cfg->items[i].id << 3) |
|
||||
(filter_cfg->items[i].ide << 2) |
|
||||
(filter_cfg->items[i].rtr << 1)) & 0xFFFF;
|
||||
(filter_cfg->items[i].rtr << 1)) &
|
||||
0xFFFF;
|
||||
mask_h = ((filter_cfg->items[i].mask << 3) >> 16) & 0xFFFF;
|
||||
mask_l = ((filter_cfg->items[i].mask << 3) | mask_l_tail) & 0xFFFF;
|
||||
}
|
||||
|
||||
drv_can->can_filter_init.Filter_Scale = CAN_Filter_32bitScale;
|
||||
drv_can->can_filter_init.Filter_HighId = id_h;
|
||||
drv_can->can_filter_init.Filter_LowId = id_l;
|
||||
@ -414,7 +411,7 @@ static rt_err_t _can_control(struct rt_can_device *can, int cmd, void *arg)
|
||||
break;
|
||||
}
|
||||
case RT_CAN_CMD_SET_MODE:
|
||||
argval = (rt_uint32_t) arg;
|
||||
argval = (rt_uint32_t)arg;
|
||||
if (argval != RT_CAN_MODE_NORMAL &&
|
||||
argval != RT_CAN_MODE_LISEN &&
|
||||
argval != RT_CAN_MODE_LOOPBACK &&
|
||||
@ -429,7 +426,7 @@ static rt_err_t _can_control(struct rt_can_device *can, int cmd, void *arg)
|
||||
}
|
||||
break;
|
||||
case RT_CAN_CMD_SET_BAUD:
|
||||
argval = (rt_uint32_t) arg;
|
||||
argval = (rt_uint32_t)arg;
|
||||
if (argval != CAN1MBaud &&
|
||||
argval != CAN800kBaud &&
|
||||
argval != CAN500kBaud &&
|
||||
@ -449,7 +446,7 @@ static rt_err_t _can_control(struct rt_can_device *can, int cmd, void *arg)
|
||||
}
|
||||
break;
|
||||
case RT_CAN_CMD_SET_PRIV:
|
||||
argval = (rt_uint32_t) arg;
|
||||
argval = (rt_uint32_t)arg;
|
||||
if (argval != RT_CAN_MODE_PRIV &&
|
||||
argval != RT_CAN_MODE_NOPRIV)
|
||||
{
|
||||
@ -463,11 +460,6 @@ static rt_err_t _can_control(struct rt_can_device *can, int cmd, void *arg)
|
||||
break;
|
||||
case RT_CAN_CMD_GET_STATUS:
|
||||
{
|
||||
// drv_can->device.status.rcverrcnt = CAN_GetReceiveErrCounter(drv_can->CANx);
|
||||
// drv_can->device.status.snderrcnt = CAN_GetLSBTransmitErrCounter(drv_can->CANx);
|
||||
// drv_can->device.status.lasterrtype = CAN_GetLastErrCode(drv_can->CANx);
|
||||
// drv_can->device.status.errcode = CAN_GetLastErrCode(drv_can->CANx);
|
||||
|
||||
rt_uint32_t errtype;
|
||||
errtype = drv_can->CANx->ESTS;
|
||||
drv_can->device.status.rcverrcnt = errtype >> 24;
|
||||
@ -486,10 +478,10 @@ static rt_err_t _can_control(struct rt_can_device *can, int cmd, void *arg)
|
||||
/* CAN Mailbox Transmit Request */
|
||||
#define TMIDxR_TXRQ ((uint32_t)0x00000001) /* Transmit mailbox request */
|
||||
|
||||
static int _can_sendmsg_rtmsg(CAN_Module* CANx, struct rt_can_msg *pmsg, uint32_t mailbox_index)
|
||||
static int _can_sendmsg_rtmsg(CAN_Module *CANx, struct rt_can_msg *pmsg, uint32_t mailbox_index)
|
||||
{
|
||||
CanTxMessage CAN_TxMessage = {0};
|
||||
CanTxMessage* TxMessage = &CAN_TxMessage;
|
||||
CanTxMessage *TxMessage = &CAN_TxMessage;
|
||||
/* Check the parameters */
|
||||
assert_param(IS_CAN_ALL_PERIPH(CANx));
|
||||
|
||||
@ -540,12 +532,12 @@ static int _can_sendmsg_rtmsg(CAN_Module* CANx, struct rt_can_msg *pmsg, uint32_
|
||||
(((uint32_t)pmsg->data[7] << 24) |
|
||||
((uint32_t)pmsg->data[6] << 16) |
|
||||
((uint32_t)pmsg->data[5] << 8) |
|
||||
((uint32_t)pmsg->data[4]) );
|
||||
((uint32_t)pmsg->data[4]));
|
||||
CANx->sTxMailBox[mailbox_index].TMDL =
|
||||
(((uint32_t)pmsg->data[3] << 24) |
|
||||
((uint32_t)pmsg->data[2] << 16) |
|
||||
((uint32_t)pmsg->data[1] << 8) |
|
||||
((uint32_t)pmsg->data[0]) );
|
||||
((uint32_t)pmsg->data[0]));
|
||||
/* Request transmission */
|
||||
CANx->sTxMailBox[mailbox_index].TMI |= TMIDxR_TXRQ;
|
||||
|
||||
@ -554,7 +546,6 @@ static int _can_sendmsg_rtmsg(CAN_Module* CANx, struct rt_can_msg *pmsg, uint32_
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
|
||||
static int _can_sendmsg(struct rt_can_device *can, const void *buf, rt_uint32_t box_num)
|
||||
{
|
||||
struct n32g45x_can *drv_can;
|
||||
@ -565,7 +556,7 @@ static int _can_sendmsg(struct rt_can_device *can, const void *buf, rt_uint32_t
|
||||
RT_ASSERT(drv_can != RT_NULL);
|
||||
|
||||
/* Select one empty transmit mailbox */
|
||||
switch(box_num)
|
||||
switch (box_num)
|
||||
{
|
||||
case 0:
|
||||
if ((drv_can->CANx->TSTS & CAN_TSTS_TMEM0) != CAN_TSTS_TMEM0)
|
||||
@ -593,15 +584,13 @@ static int _can_sendmsg(struct rt_can_device *can, const void *buf, rt_uint32_t
|
||||
break;
|
||||
}
|
||||
//start send msg
|
||||
return _can_sendmsg_rtmsg(drv_can->CANx , ((struct rt_can_msg *) buf) ,box_num);
|
||||
return _can_sendmsg_rtmsg(drv_can->CANx, ((struct rt_can_msg *)buf), box_num);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int _can_recvmsg_rtmsg(CAN_Module* CANx, struct rt_can_msg *pmsg, uint32_t FIFONum)
|
||||
static int _can_recvmsg_rtmsg(CAN_Module *CANx, struct rt_can_msg *pmsg, uint32_t FIFONum)
|
||||
{
|
||||
CanRxMessage CAN_RxMessage = {0};
|
||||
CanRxMessage* RxMessage = &CAN_RxMessage;
|
||||
CanRxMessage *RxMessage = &CAN_RxMessage;
|
||||
/* Check the parameters */
|
||||
assert_param(IS_CAN_ALL_PERIPH(CANx));
|
||||
assert_param(IS_CAN_FIFO(FIFONum));
|
||||
@ -699,7 +688,6 @@ static int _can_recvmsg_rtmsg(CAN_Module* CANx, struct rt_can_msg *pmsg, uint32_
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
|
||||
static int _can_recvmsg(struct rt_can_device *can, void *buf, rt_uint32_t fifo)
|
||||
{
|
||||
struct n32g45x_can *drv_can;
|
||||
@ -710,11 +698,11 @@ static int _can_recvmsg(struct rt_can_device *can, void *buf, rt_uint32_t fifo)
|
||||
RT_ASSERT(drv_can != RT_NULL);
|
||||
|
||||
/* get data */
|
||||
return _can_recvmsg_rtmsg(drv_can->CANx,((struct rt_can_msg *) buf),fifo);
|
||||
return _can_recvmsg_rtmsg(drv_can->CANx, ((struct rt_can_msg *)buf), fifo);
|
||||
}
|
||||
|
||||
static const struct rt_can_ops _can_ops =
|
||||
{
|
||||
{
|
||||
_can_config,
|
||||
_can_control,
|
||||
_can_sendmsg,
|
||||
@ -732,18 +720,18 @@ static void _can_rx_isr(struct rt_can_device *can, rt_uint32_t fifo)
|
||||
{
|
||||
case CAN_FIFO0:
|
||||
/* save to user list */
|
||||
if( CAN_GetFlagSTS(drv_can->CANx, CAN_FLAG_FFMP0) && CAN_PendingMessage(drv_can->CANx, CAN_FIFO0) )
|
||||
if (CAN_GetFlagSTS(drv_can->CANx, CAN_FLAG_FFMP0) && CAN_PendingMessage(drv_can->CANx, CAN_FIFO0))
|
||||
{
|
||||
rt_hw_can_isr(can, RT_CAN_EVENT_RX_IND | fifo << 8);
|
||||
}
|
||||
/* Check FULL flag for FIFO0 */
|
||||
if( CAN_GetFlagSTS(drv_can->CANx, CAN_FLAG_FFULL0) )
|
||||
if (CAN_GetFlagSTS(drv_can->CANx, CAN_FLAG_FFULL0))
|
||||
{
|
||||
/* Clear FIFO0 FULL Flag */
|
||||
CAN_ClearFlag(drv_can->CANx, CAN_FLAG_FFULL0);
|
||||
}
|
||||
/* Check Overrun flag for FIFO0 */
|
||||
if( CAN_GetFlagSTS(drv_can->CANx, CAN_FLAG_FFOVR0) )
|
||||
if (CAN_GetFlagSTS(drv_can->CANx, CAN_FLAG_FFOVR0))
|
||||
{
|
||||
/* Clear FIFO0 Overrun Flag */
|
||||
CAN_ClearFlag(drv_can->CANx, CAN_FLAG_FFOVR0);
|
||||
@ -752,18 +740,18 @@ static void _can_rx_isr(struct rt_can_device *can, rt_uint32_t fifo)
|
||||
break;
|
||||
case CAN_FIFO1:
|
||||
/* save to user list */
|
||||
if( CAN_GetFlagSTS(drv_can->CANx, CAN_FLAG_FFMP1) && CAN_PendingMessage(drv_can->CANx, CAN_FIFO1) )
|
||||
if (CAN_GetFlagSTS(drv_can->CANx, CAN_FLAG_FFMP1) && CAN_PendingMessage(drv_can->CANx, CAN_FIFO1))
|
||||
{
|
||||
rt_hw_can_isr(can, RT_CAN_EVENT_RX_IND | fifo << 8);
|
||||
}
|
||||
/* Check FULL flag for FIFO1 */
|
||||
if( CAN_GetFlagSTS(drv_can->CANx, CAN_FLAG_FFULL1) )
|
||||
if (CAN_GetFlagSTS(drv_can->CANx, CAN_FLAG_FFULL1))
|
||||
{
|
||||
/* Clear FIFO1 FULL Flag */
|
||||
CAN_ClearFlag(drv_can->CANx, CAN_FLAG_FFULL1);
|
||||
}
|
||||
/* Check Overrun flag for FIFO1 */
|
||||
if( CAN_GetFlagSTS(drv_can->CANx, CAN_FLAG_FFOVR1) )
|
||||
if (CAN_GetFlagSTS(drv_can->CANx, CAN_FLAG_FFOVR1))
|
||||
{
|
||||
/* Clear FIFO1 Overrun Flag */
|
||||
CAN_ClearFlag(drv_can->CANx, CAN_FLAG_FFOVR1);
|
||||
@ -781,19 +769,19 @@ static void _can_rx_isr(struct rt_can_device *can, rt_uint32_t fifo)
|
||||
void CAN1_TX_IRQHandler(void)
|
||||
{
|
||||
rt_interrupt_enter();
|
||||
if(CAN_GetFlagSTS(drv_can1.CANx, CAN_FLAG_RQCPM0) )
|
||||
if (CAN_GetFlagSTS(drv_can1.CANx, CAN_FLAG_RQCPM0))
|
||||
{
|
||||
rt_hw_can_isr(&drv_can1.device, RT_CAN_EVENT_TX_DONE | (0x00 << 8) );
|
||||
rt_hw_can_isr(&drv_can1.device, RT_CAN_EVENT_TX_DONE | (0x00 << 8));
|
||||
CAN_ClearFlag(drv_can1.CANx, CAN_FLAG_RQCPM0);
|
||||
}
|
||||
if(CAN_GetFlagSTS(drv_can1.CANx, CAN_FLAG_RQCPM1) )
|
||||
if (CAN_GetFlagSTS(drv_can1.CANx, CAN_FLAG_RQCPM1))
|
||||
{
|
||||
rt_hw_can_isr(&drv_can1.device, RT_CAN_EVENT_TX_DONE | (0x01 << 8) );
|
||||
rt_hw_can_isr(&drv_can1.device, RT_CAN_EVENT_TX_DONE | (0x01 << 8));
|
||||
CAN_ClearFlag(drv_can1.CANx, CAN_FLAG_RQCPM1);
|
||||
}
|
||||
if(CAN_GetFlagSTS(drv_can1.CANx, CAN_FLAG_RQCPM2) )
|
||||
if (CAN_GetFlagSTS(drv_can1.CANx, CAN_FLAG_RQCPM2))
|
||||
{
|
||||
rt_hw_can_isr(&drv_can1.device, RT_CAN_EVENT_TX_DONE | (0x02 << 8) );
|
||||
rt_hw_can_isr(&drv_can1.device, RT_CAN_EVENT_TX_DONE | (0x02 << 8));
|
||||
CAN_ClearFlag(drv_can1.CANx, CAN_FLAG_RQCPM2);
|
||||
}
|
||||
rt_interrupt_leave();
|
||||
@ -828,7 +816,7 @@ void CAN1_SCE_IRQHandler(void)
|
||||
uint32_t errtype;
|
||||
rt_interrupt_enter();
|
||||
|
||||
if(CAN_GetIntStatus(drv_can1.CANx, CAN_INT_ERR) )
|
||||
if (CAN_GetIntStatus(drv_can1.CANx, CAN_INT_ERR))
|
||||
{
|
||||
errtype = drv_can1.CANx->ESTS;
|
||||
// ESTS -> LEC
|
||||
@ -839,7 +827,7 @@ void CAN1_SCE_IRQHandler(void)
|
||||
case RT_CAN_BUS_FORMAT_ERR:
|
||||
drv_can1.device.status.formaterrcnt++;
|
||||
break;
|
||||
case RT_CAN_BUS_ACK_ERR:/* attention !!! test ack err's unit is transmit unit */
|
||||
case RT_CAN_BUS_ACK_ERR: /* attention !!! test ack err's unit is transmit unit */
|
||||
drv_can1.device.status.ackerrcnt++;
|
||||
if (!READ_BIT(drv_can1.CANx->TSTS, CAN_TSTS_TXOKM0))
|
||||
rt_hw_can_isr(&drv_can1.device, RT_CAN_EVENT_TX_FAIL | 0 << 8);
|
||||
@ -874,20 +862,20 @@ void CAN1_SCE_IRQHandler(void)
|
||||
void CAN2_TX_IRQHandler(void)
|
||||
{
|
||||
rt_interrupt_enter();
|
||||
if(CAN_GetFlagSTS(drv_can2.CANx, CAN_FLAG_RQCPM0) )
|
||||
if (CAN_GetFlagSTS(drv_can2.CANx, CAN_FLAG_RQCPM0))
|
||||
{
|
||||
CAN_ClearFlag(drv_can2.CANx, CAN_FLAG_RQCPM0);
|
||||
rt_hw_can_isr(&drv_can2.device, RT_CAN_EVENT_TX_DONE | (0x00 << 8) );
|
||||
rt_hw_can_isr(&drv_can2.device, RT_CAN_EVENT_TX_DONE | (0x00 << 8));
|
||||
}
|
||||
if(CAN_GetFlagSTS(drv_can2.CANx, CAN_FLAG_RQCPM1) )
|
||||
if (CAN_GetFlagSTS(drv_can2.CANx, CAN_FLAG_RQCPM1))
|
||||
{
|
||||
CAN_ClearFlag(drv_can2.CANx, CAN_FLAG_RQCPM1);
|
||||
rt_hw_can_isr(&drv_can2.device, RT_CAN_EVENT_TX_DONE | (0x01 << 8) );
|
||||
rt_hw_can_isr(&drv_can2.device, RT_CAN_EVENT_TX_DONE | (0x01 << 8));
|
||||
}
|
||||
if(CAN_GetFlagSTS(drv_can2.CANx, CAN_FLAG_RQCPM2) )
|
||||
if (CAN_GetFlagSTS(drv_can2.CANx, CAN_FLAG_RQCPM2))
|
||||
{
|
||||
CAN_ClearFlag(drv_can2.CANx, CAN_FLAG_RQCPM2);
|
||||
rt_hw_can_isr(&drv_can2.device, RT_CAN_EVENT_TX_DONE | (0x02 << 8) );
|
||||
rt_hw_can_isr(&drv_can2.device, RT_CAN_EVENT_TX_DONE | (0x02 << 8));
|
||||
}
|
||||
rt_interrupt_leave();
|
||||
}
|
||||
@ -920,7 +908,7 @@ void CAN2_SCE_IRQHandler(void)
|
||||
uint32_t errtype;
|
||||
rt_interrupt_enter();
|
||||
|
||||
if(CAN_GetIntStatus(drv_can2.CANx, CAN_INT_ERR) )
|
||||
if (CAN_GetIntStatus(drv_can2.CANx, CAN_INT_ERR))
|
||||
{
|
||||
errtype = drv_can2.CANx->ESTS;
|
||||
// ESTS -> LEC
|
||||
@ -931,7 +919,7 @@ void CAN2_SCE_IRQHandler(void)
|
||||
case RT_CAN_BUS_FORMAT_ERR:
|
||||
drv_can2.device.status.formaterrcnt++;
|
||||
break;
|
||||
case RT_CAN_BUS_ACK_ERR:/* attention !!! test ack err's unit is transmit unit */
|
||||
case RT_CAN_BUS_ACK_ERR: /* attention !!! test ack err's unit is transmit unit */
|
||||
drv_can2.device.status.ackerrcnt++;
|
||||
if (!READ_BIT(drv_can2.CANx->TSTS, CAN_TSTS_TXOKM0))
|
||||
rt_hw_can_isr(&drv_can2.device, RT_CAN_EVENT_TX_FAIL | 0 << 8);
|
||||
@ -960,7 +948,6 @@ void CAN2_SCE_IRQHandler(void)
|
||||
}
|
||||
#endif /* BSP_USING_CAN2 */
|
||||
|
||||
|
||||
int rt_hw_can_init(void)
|
||||
{
|
||||
struct can_configure config = CANDEFAULTCONFIG;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
@ -12,14 +12,15 @@
|
||||
#define __DRV_CAN_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include <board.h>
|
||||
#include <rtdevice.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
int rt_hw_can_init(void);
|
||||
int rt_hw_can_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user