From f76c2ed83b2b5804ca1275363b954f925492c52d Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sat, 6 Apr 2024 00:38:55 +0800 Subject: [PATCH] can: Add g_ prefix to can_dlc_to_len and len_to_can_dlc. detail: Add g_ prefix to can_dlc_to_len and len_to_can_dlc to follow NuttX coding style conventions for global symbols, improving code readability and maintainability. Signed-off-by: zhaohaiyang1 --- arch/arm/src/imxrt/imxrt_flexcan.c | 4 +- arch/arm/src/kinetis/kinetis_flexcan.c | 4 +- arch/arm/src/s32k1xx/s32k1xx_flexcan.c | 4 +- arch/arm/src/s32k3xx/s32k3xx_flexcan.c | 4 +- arch/arm/src/stm32/stm32_fdcan_sock.c | 6 +- arch/arm/src/stm32h7/stm32_fdcan_sock.c | 4 +- include/nuttx/net/can.h | 9 +- net/can/can_input.c | 166 ++++++++++++------------ 8 files changed, 101 insertions(+), 100 deletions(-) diff --git a/arch/arm/src/imxrt/imxrt_flexcan.c b/arch/arm/src/imxrt/imxrt_flexcan.c index 12a351a823..7639a6a799 100644 --- a/arch/arm/src/imxrt/imxrt_flexcan.c +++ b/arch/arm/src/imxrt/imxrt_flexcan.c @@ -696,7 +696,7 @@ static int imxrt_transmit(struct imxrt_driver_s *priv) cs.rtr = frame->can_id & FLAGRTR ? 1 : 0; - cs.dlc = len_to_can_dlc[frame->len]; + cs.dlc = g_len_to_can_dlc[frame->len]; frame_data_word = (uint32_t *)&frame->data[0]; @@ -877,7 +877,7 @@ static void imxrt_receive(struct imxrt_driver_s *priv, frame->can_id |= FLAGRTR; } - frame->len = can_dlc_to_len[rf->cs.dlc]; + frame->len = g_can_dlc_to_len[rf->cs.dlc]; frame_data_word = (uint32_t *)&frame->data[0]; diff --git a/arch/arm/src/kinetis/kinetis_flexcan.c b/arch/arm/src/kinetis/kinetis_flexcan.c index e2d578f7eb..6528457ec9 100644 --- a/arch/arm/src/kinetis/kinetis_flexcan.c +++ b/arch/arm/src/kinetis/kinetis_flexcan.c @@ -724,7 +724,7 @@ static int kinetis_transmit(struct kinetis_driver_s *priv) cs.rtr = frame->can_id & FLAGRTR ? 1 : 0; - cs.dlc = len_to_can_dlc[frame->len]; + cs.dlc = g_len_to_can_dlc[frame->len]; frame_data_word = (uint32_t *)&frame->data[0]; @@ -877,7 +877,7 @@ static void kinetis_receive(struct kinetis_driver_s *priv, frame->can_id |= FLAGRTR; } - frame->len = can_dlc_to_len[rf->cs.dlc]; + frame->len = g_can_dlc_to_len[rf->cs.dlc]; frame_data_word = (uint32_t *)&frame->data[0]; diff --git a/arch/arm/src/s32k1xx/s32k1xx_flexcan.c b/arch/arm/src/s32k1xx/s32k1xx_flexcan.c index fe5a308d36..546f733a39 100644 --- a/arch/arm/src/s32k1xx/s32k1xx_flexcan.c +++ b/arch/arm/src/s32k1xx/s32k1xx_flexcan.c @@ -728,7 +728,7 @@ static int s32k1xx_transmit(struct s32k1xx_driver_s *priv) cs.rtr = frame->can_id & FLAGRTR ? 1 : 0; - cs.dlc = len_to_can_dlc[frame->len]; + cs.dlc = g_len_to_can_dlc[frame->len]; frame_data_word = (uint32_t *)&frame->data[0]; @@ -881,7 +881,7 @@ static void s32k1xx_receive(struct s32k1xx_driver_s *priv, frame->can_id |= FLAGRTR; } - frame->len = can_dlc_to_len[rf->cs.dlc]; + frame->len = g_can_dlc_to_len[rf->cs.dlc]; frame_data_word = (uint32_t *)&frame->data[0]; diff --git a/arch/arm/src/s32k3xx/s32k3xx_flexcan.c b/arch/arm/src/s32k3xx/s32k3xx_flexcan.c index 9b55df521f..3cc2f68cec 100644 --- a/arch/arm/src/s32k3xx/s32k3xx_flexcan.c +++ b/arch/arm/src/s32k3xx/s32k3xx_flexcan.c @@ -890,7 +890,7 @@ static int s32k3xx_transmit(struct s32k3xx_driver_s *priv) cs.rtr = frame->can_id & FLAGRTR ? 1 : 0; - cs.dlc = len_to_can_dlc[frame->len]; + cs.dlc = g_len_to_can_dlc[frame->len]; frame_data_word = (uint32_t *)&frame->data[0]; @@ -1041,7 +1041,7 @@ static void s32k3xx_receive(struct s32k3xx_driver_s *priv, uint32_t flags) frame->can_id |= FLAGRTR; } - frame->len = can_dlc_to_len[rf->cs.dlc]; + frame->len = g_can_dlc_to_len[rf->cs.dlc]; frame_data_word = (uint32_t *)&frame->data[0]; diff --git a/arch/arm/src/stm32/stm32_fdcan_sock.c b/arch/arm/src/stm32/stm32_fdcan_sock.c index 65f0280bb9..073fa2c48e 100644 --- a/arch/arm/src/stm32/stm32_fdcan_sock.c +++ b/arch/arm/src/stm32/stm32_fdcan_sock.c @@ -1749,7 +1749,7 @@ static int fdcan_send(struct stm32_fdcan_s *priv) /* Set DLC */ - txbuffer[1] |= BUFFER_R1_DLC(len_to_can_dlc[frame->len]); + txbuffer[1] |= BUFFER_R1_DLC(g_len_to_can_dlc[frame->len]); /* Set flags */ @@ -2467,8 +2467,8 @@ static void fdcan_receive(struct stm32_fdcan_s *priv, /* Word R1 contains the DLC and timestamp */ - frame->len = can_dlc_to_len[((rxbuffer[1] & BUFFER_R1_DLC_MASK) >> - BUFFER_R1_DLC_SHIFT)]; + frame->len = g_can_dlc_to_len[((rxbuffer[1] & BUFFER_R1_DLC_MASK) >> + BUFFER_R1_DLC_SHIFT)]; /* Get CANFD flags */ diff --git a/arch/arm/src/stm32h7/stm32_fdcan_sock.c b/arch/arm/src/stm32h7/stm32_fdcan_sock.c index 5202ec4f2f..ad7bb1fae6 100644 --- a/arch/arm/src/stm32h7/stm32_fdcan_sock.c +++ b/arch/arm/src/stm32h7/stm32_fdcan_sock.c @@ -880,7 +880,7 @@ static int fdcan_transmit(struct fdcan_driver_s *priv) header.id.esi = (frame->can_id & CAN_ERR_FLAG) ? 1 : 0; header.id.rtr = (frame->can_id & CAN_RTR_FLAG) ? 1 : 0; - header.dlc = len_to_can_dlc[frame->len]; + header.dlc = g_len_to_can_dlc[frame->len]; header.brs = brs; /* Bitrate switching */ header.fdf = 1; /* CAN-FD frame */ header.efc = 0; /* Don't store Tx events */ @@ -1161,7 +1161,7 @@ static void fdcan_receive_work(void *arg) frame->can_id |= CAN_RTR_FLAG; } - frame->len = can_dlc_to_len[rf->header.dlc]; + frame->len = g_can_dlc_to_len[rf->header.dlc]; uint32_t *frame_data_word = (uint32_t *)&frame->data[0]; diff --git a/include/nuttx/net/can.h b/include/nuttx/net/can.h index f9cbe935be..80c406540b 100644 --- a/include/nuttx/net/can.h +++ b/include/nuttx/net/can.h @@ -52,10 +52,11 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ + #ifdef CONFIG_NET_CAN_CANFD -#define NET_CAN_PKTSIZE sizeof(struct canfd_frame) +# define NET_CAN_PKTSIZE sizeof(struct canfd_frame) #else -#define NET_CAN_PKTSIZE sizeof(struct can_frame) +# define NET_CAN_PKTSIZE sizeof(struct can_frame) #endif /**************************************************************************** @@ -70,8 +71,8 @@ /* Lookup tables convert can_dlc <-> payload len */ -extern const uint8_t can_dlc_to_len[16]; -extern const uint8_t len_to_can_dlc[65]; +extern const uint8_t g_can_dlc_to_len[16]; +extern const uint8_t g_len_to_can_dlc[65]; #endif diff --git a/net/can/can_input.c b/net/can/can_input.c index 704ae04035..f93120b4ee 100644 --- a/net/can/can_input.c +++ b/net/can/can_input.c @@ -40,92 +40,92 @@ * Public Data ****************************************************************************/ -const uint8_t can_dlc_to_len[16] = +const uint8_t g_can_dlc_to_len[16] = { - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 12, - 16, - 20, - 24, - 32, - 48, - 64, + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 12, + 16, + 20, + 24, + 32, + 48, + 64, }; -const uint8_t len_to_can_dlc[65] = +const uint8_t g_len_to_can_dlc[65] = { - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 9, - 9, - 9, - 10, - 10, - 10, - 10, - 11, - 11, - 11, - 11, - 12, - 12, - 12, - 12, - 13, - 13, - 13, - 13, - 13, - 13, - 13, - 13, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 15, - 15, - 15, - 15, - 15, - 15, - 15, - 15, - 15, - 15, - 15, - 15, - 15, - 15, - 15, - 15, + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 9, + 9, + 9, + 10, + 10, + 10, + 10, + 11, + 11, + 11, + 11, + 12, + 12, + 12, + 12, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, }; /****************************************************************************