Skip to content

Commit f4f6f43

Browse files
author
yuplus
committed
style: format code with clang-format [skip ci]
1 parent 5013be8 commit f4f6f43

2 files changed

Lines changed: 298 additions & 229 deletions

File tree

bsp/nxp/mcx/mcxa/Libraries/drivers/drv_can.c

Lines changed: 94 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
#include "fsl_clock.h"
1818
#include "fsl_flexcan.h"
1919

20-
#define TX_MB_IDX (0)
21-
#define RX_MB_IDX (1)
22-
#define RX_MB_COUNT (1)
23-
#define CAN_TX_WAIT_MS (2000U)
20+
#define TX_MB_IDX (0)
21+
#define RX_MB_IDX (1)
22+
#define RX_MB_COUNT (1)
23+
#define CAN_TX_WAIT_MS (2000U)
2424

2525
enum
2626
{
@@ -34,20 +34,20 @@ enum
3434

3535
struct imxrt_can
3636
{
37-
char *name;
38-
CAN_Type *base;
39-
IRQn_Type irqn;
40-
uint32_t instance;
41-
clock_div_name_t clock_div_name;
42-
clock_attach_id_t clock_attach_id;
43-
flexcan_handle_t handle;
44-
struct rt_can_device can_dev;
45-
flexcan_frame_t frame[RX_MB_COUNT];
37+
char *name;
38+
CAN_Type *base;
39+
IRQn_Type irqn;
40+
uint32_t instance;
41+
clock_div_name_t clock_div_name;
42+
clock_attach_id_t clock_attach_id;
43+
flexcan_handle_t handle;
44+
struct rt_can_device can_dev;
45+
flexcan_frame_t frame[RX_MB_COUNT];
4646
#ifdef RT_CAN_USING_CANFD
47-
flexcan_fd_frame_t framefd[RX_MB_COUNT];
48-
rt_bool_t fd_enabled;
47+
flexcan_fd_frame_t framefd[RX_MB_COUNT];
48+
rt_bool_t fd_enabled;
4949
#endif
50-
rt_uint32_t filter_mask;
50+
rt_uint32_t filter_mask;
5151
};
5252

5353
static void _can_dump_err(struct imxrt_can *can, const char *stage)
@@ -129,18 +129,72 @@ static rt_uint8_t _can_dlc2len(rt_uint8_t dlc)
129129

130130
static rt_uint8_t _can_len2dlc(rt_uint8_t len)
131131
{
132-
static const rt_uint8_t table[] =
133-
{
134-
0, 1, 2, 3, 4, 5, 6, 7, 8,
135-
9, 9, 9, 9,
136-
10, 10, 10, 10,
137-
11, 11, 11, 11,
138-
12, 12, 12, 12,
139-
13, 13, 13, 13, 13, 13, 13, 13,
140-
14, 14, 14, 14, 14, 14, 14, 14,
141-
14, 14, 14, 14, 14, 14, 14, 14,
142-
15, 15, 15, 15, 15, 15, 15, 15,
143-
15, 15, 15, 15, 15, 15, 15, 15,
132+
static const rt_uint8_t table[] = {
133+
0,
134+
1,
135+
2,
136+
3,
137+
4,
138+
5,
139+
6,
140+
7,
141+
8,
142+
9,
143+
9,
144+
9,
145+
9,
146+
10,
147+
10,
148+
10,
149+
10,
150+
11,
151+
11,
152+
11,
153+
11,
154+
12,
155+
12,
156+
12,
157+
12,
158+
13,
159+
13,
160+
13,
161+
13,
162+
13,
163+
13,
164+
13,
165+
13,
166+
14,
167+
14,
168+
14,
169+
14,
170+
14,
171+
14,
172+
14,
173+
14,
174+
14,
175+
14,
176+
14,
177+
14,
178+
14,
179+
14,
180+
14,
181+
14,
182+
15,
183+
15,
184+
15,
185+
15,
186+
15,
187+
15,
188+
15,
189+
15,
190+
15,
191+
15,
192+
15,
193+
15,
194+
15,
195+
15,
196+
15,
197+
15,
144198
};
145199

146200
if (len <= 64)
@@ -202,8 +256,7 @@ static void _can_parse_classic_frame(struct rt_can_msg *msg, const flexcan_frame
202256
msg->data[7] = frame->dataByte7;
203257
}
204258

205-
struct imxrt_can flexcans[] =
206-
{
259+
struct imxrt_can flexcans[] = {
207260
#ifdef BSP_USING_CAN0
208261
{
209262
.name = "can0",
@@ -381,9 +434,9 @@ static void _can_start_rx(struct imxrt_can *can)
381434
static void _can_enable_controller_irq(struct imxrt_can *can)
382435
{
383436
FLEXCAN_EnableInterrupts(can->base, (uint32_t)kFLEXCAN_BusOffInterruptEnable |
384-
(uint32_t)kFLEXCAN_ErrorInterruptEnable |
385-
(uint32_t)kFLEXCAN_RxWarningInterruptEnable |
386-
(uint32_t)kFLEXCAN_TxWarningInterruptEnable);
437+
(uint32_t)kFLEXCAN_ErrorInterruptEnable |
438+
(uint32_t)kFLEXCAN_RxWarningInterruptEnable |
439+
(uint32_t)kFLEXCAN_TxWarningInterruptEnable);
387440
EnableIRQ(can->irqn);
388441
}
389442

@@ -480,7 +533,7 @@ static rt_err_t _can_config(struct rt_can_device *can_dev, struct can_configure
480533
#ifdef RT_CAN_USING_CANFD
481534
|| (cfg->enable_canfd == 0)
482535
#endif
483-
)
536+
)
484537
{
485538
config.enableTransceiverDelayMeasure = false;
486539
}
@@ -496,12 +549,10 @@ static rt_err_t _can_config(struct rt_can_device *can_dev, struct can_configure
496549

497550
if (can->fd_enabled)
498551
{
499-
bool brs_enable = _can_is_loopback(cfg) ? false :
500-
(cfg->baud_rate_fd > cfg->baud_rate);
552+
bool brs_enable = _can_is_loopback(cfg) ? false : (cfg->baud_rate_fd > cfg->baud_rate);
501553
bool timing_ok;
502554

503-
config.bitRateFD = _can_is_loopback(cfg) ? config.baudRate :
504-
(cfg->baud_rate_fd ? cfg->baud_rate_fd : 2000000U);
555+
config.bitRateFD = _can_is_loopback(cfg) ? config.baudRate : (cfg->baud_rate_fd ? cfg->baud_rate_fd : 2000000U);
505556

506557
timing_ok = FLEXCAN_FDCalculateImprovedTimingValues(can->base, config.baudRate,
507558
config.bitRateFD, clk_freq, &timing_config);
@@ -986,12 +1037,11 @@ static rt_ssize_t _can_sendmsg_nonblocking(struct rt_can_device *can_dev, const
9861037
return (ret == kStatus_Success) ? RT_EOK : -RT_ERROR;
9871038
}
9881039

989-
static struct rt_can_ops imxrt_can_ops =
990-
{
991-
.configure = _can_config,
992-
.control = _can_control,
993-
.sendmsg = _can_sendmsg,
994-
.recvmsg = _can_recvmsg,
1040+
static struct rt_can_ops imxrt_can_ops = {
1041+
.configure = _can_config,
1042+
.control = _can_control,
1043+
.sendmsg = _can_sendmsg,
1044+
.recvmsg = _can_recvmsg,
9951045
.sendmsg_nonblocking = _can_sendmsg_nonblocking
9961046
};
9971047

0 commit comments

Comments
 (0)