diff --git a/bsp/at32/libraries/rt_drivers/drv_can.c b/bsp/at32/libraries/rt_drivers/drv_can.c index 7a0f7ba49c..6b60187aab 100644 --- a/bsp/at32/libraries/rt_drivers/drv_can.c +++ b/bsp/at32/libraries/rt_drivers/drv_can.c @@ -192,13 +192,13 @@ static rt_err_t _can_config(struct rt_can_device *can, struct can_configure *cfg case RT_CAN_MODE_NORMAL: can_instance->config.base_init_struct.mode_selection = CAN_MODE_COMMUNICATE; break; - case RT_CAN_MODE_LISEN: + case RT_CAN_MODE_LISTEN: can_instance->config.base_init_struct.mode_selection = CAN_MODE_LISTENONLY; break; case RT_CAN_MODE_LOOPBACK: can_instance->config.base_init_struct.mode_selection = CAN_MODE_LOOPBACK; break; - case RT_CAN_MODE_LOOPBACKANLISEN: + case RT_CAN_MODE_LOOPBACKANLISTEN: can_instance->config.base_init_struct.mode_selection = CAN_MODE_LISTENONLY_LOOPBACK; break; } @@ -432,9 +432,9 @@ static rt_err_t _can_control(struct rt_can_device *can, int cmd, void *arg) case RT_CAN_CMD_SET_MODE: argval = (rt_uint32_t) arg; if (argval != RT_CAN_MODE_NORMAL && - argval != RT_CAN_MODE_LISEN && + argval != RT_CAN_MODE_LISTEN && argval != RT_CAN_MODE_LOOPBACK && - argval != RT_CAN_MODE_LOOPBACKANLISEN) + argval != RT_CAN_MODE_LOOPBACKANLISTEN) { return -RT_ERROR; } diff --git a/bsp/essemi/es32f0654/drivers/drv_can.c b/bsp/essemi/es32f0654/drivers/drv_can.c index c58ae1f2b2..76a8ddd662 100644 --- a/bsp/essemi/es32f0654/drivers/drv_can.c +++ b/bsp/essemi/es32f0654/drivers/drv_can.c @@ -108,13 +108,13 @@ static rt_err_t _can_config(struct rt_can_device *can_device, struct can_configu case RT_CAN_MODE_NORMAL: drv_can->CanHandle.init.mode = CAN_MODE_NORMAL; break; - case RT_CAN_MODE_LISEN: + case RT_CAN_MODE_LISTEN: drv_can->CanHandle.init.mode = CAN_MODE_SILENT; break; case RT_CAN_MODE_LOOPBACK: drv_can->CanHandle.init.mode = CAN_MODE_LOOPBACK; break; - case RT_CAN_MODE_LOOPBACKANLISEN: + case RT_CAN_MODE_LOOPBACKANLISTEN: drv_can->CanHandle.init.mode = CAN_MODE_SILENT_LOOPBACK; break; } @@ -295,9 +295,9 @@ static rt_err_t _can_control(struct rt_can_device *can_device, int cmd, void *ar case RT_CAN_CMD_SET_MODE: argval = (rt_uint32_t) arg; if (argval != RT_CAN_MODE_NORMAL && - argval != RT_CAN_MODE_LISEN && + argval != RT_CAN_MODE_LISTEN && argval != RT_CAN_MODE_LOOPBACK && - argval != RT_CAN_MODE_LOOPBACKANLISEN) + argval != RT_CAN_MODE_LOOPBACKANLISTEN) { return -RT_ERROR; } diff --git a/bsp/essemi/es32f369x/drivers/drv_can.c b/bsp/essemi/es32f369x/drivers/drv_can.c index 81936c33ac..c95fb780ce 100644 --- a/bsp/essemi/es32f369x/drivers/drv_can.c +++ b/bsp/essemi/es32f369x/drivers/drv_can.c @@ -107,13 +107,13 @@ static rt_err_t _can_config(struct rt_can_device *can_device, struct can_configu case RT_CAN_MODE_NORMAL: drv_can->CanHandle.init.mode = CAN_MODE_NORMAL; break; - case RT_CAN_MODE_LISEN: + case RT_CAN_MODE_LISTEN: drv_can->CanHandle.init.mode = CAN_MODE_SILENT; break; case RT_CAN_MODE_LOOPBACK: drv_can->CanHandle.init.mode = CAN_MODE_LOOPBACK; break; - case RT_CAN_MODE_LOOPBACKANLISEN: + case RT_CAN_MODE_LOOPBACKANLISTEN: drv_can->CanHandle.init.mode = CAN_MODE_SILENT_LOOPBACK; break; } @@ -289,9 +289,9 @@ static rt_err_t _can_control(struct rt_can_device *can_device, int cmd, void *ar case RT_CAN_CMD_SET_MODE: argval = (rt_uint32_t) arg; if (argval != RT_CAN_MODE_NORMAL && - argval != RT_CAN_MODE_LISEN && + argval != RT_CAN_MODE_LISTEN && argval != RT_CAN_MODE_LOOPBACK && - argval != RT_CAN_MODE_LOOPBACKANLISEN) + argval != RT_CAN_MODE_LOOPBACKANLISTEN) { return -RT_ERROR; } diff --git a/bsp/hc32/libraries/hc32_drivers/drv_can.c b/bsp/hc32/libraries/hc32_drivers/drv_can.c index 8482a10dbe..726eab12d5 100644 --- a/bsp/hc32/libraries/hc32_drivers/drv_can.c +++ b/bsp/hc32/libraries/hc32_drivers/drv_can.c @@ -124,13 +124,13 @@ static rt_uint32_t _get_can_work_mode(rt_uint32_t mode) case RT_CAN_MODE_NORMAL: work_mode = CAN_WORK_MD_NORMAL; break; - case RT_CAN_MODE_LISEN: + case RT_CAN_MODE_LISTEN: work_mode = CAN_WORK_MD_SILENT; break; case RT_CAN_MODE_LOOPBACK: work_mode = CAN_WORK_MD_ELB; break; - case RT_CAN_MODE_LOOPBACKANLISEN: + case RT_CAN_MODE_LOOPBACKANLISTEN: work_mode = CAN_WORK_MD_ELB_SILENT; break; default: @@ -298,9 +298,9 @@ static rt_err_t _can_control(struct rt_can_device *can, int cmd, void *arg) case RT_CAN_CMD_SET_MODE: argval = (rt_uint32_t) arg; if (argval != RT_CAN_MODE_NORMAL && - argval != RT_CAN_MODE_LISEN && + argval != RT_CAN_MODE_LISTEN && argval != RT_CAN_MODE_LOOPBACK && - argval != RT_CAN_MODE_LOOPBACKANLISEN) + argval != RT_CAN_MODE_LOOPBACKANLISTEN) { return -RT_ERROR; } diff --git a/bsp/imxrt/libraries/drivers/drv_can.c b/bsp/imxrt/libraries/drivers/drv_can.c index c44ec9ab69..6af614418c 100644 --- a/bsp/imxrt/libraries/drivers/drv_can.c +++ b/bsp/imxrt/libraries/drivers/drv_can.c @@ -135,12 +135,12 @@ static rt_err_t can_cfg(struct rt_can_device *can_dev, struct can_configure *cfg case RT_CAN_MODE_NORMAL: /* default mode */ break; - case RT_CAN_MODE_LISEN: + case RT_CAN_MODE_LISTEN: break; case RT_CAN_MODE_LOOPBACK: config.enableLoopBack = true; break; - case RT_CAN_MODE_LOOPBACKANLISEN: + case RT_CAN_MODE_LOOPBACKANLISTEN: break; } FLEXCAN_Init(can->base, &config, GetCanSrcFreq()); diff --git a/bsp/loongson/ls1cdev/drivers/drv_can.c b/bsp/loongson/ls1cdev/drivers/drv_can.c index cf0e00f00a..78fc021ecb 100644 --- a/bsp/loongson/ls1cdev/drivers/drv_can.c +++ b/bsp/loongson/ls1cdev/drivers/drv_can.c @@ -156,14 +156,14 @@ static void bxcan_init(CAN_TypeDef *pcan, rt_uint32_t baud, rt_uint32_t mode) case RT_CAN_MODE_NORMAL: CAN_InitStructure.CAN_Mode = 0x00; break; - case RT_CAN_MODE_LISEN: + case RT_CAN_MODE_LISTEN: CAN_InitStructure.CAN_Mode = CAN_Mode_LOM; break; case RT_CAN_MODE_LOOPBACK: CAN_InitStructure.CAN_Mode = CAN_Mode_STM; break; - case RT_CAN_MODE_LOOPBACKANLISEN: + case RT_CAN_MODE_LOOPBACKANLISTEN: CAN_InitStructure.CAN_Mode = CAN_Mode_STM|CAN_Mode_LOM; break; } @@ -272,9 +272,9 @@ static rt_err_t control(struct rt_can_device *can, int cmd, void *arg) case RT_CAN_CMD_SET_MODE: argval = (rt_uint32_t) arg; if (argval != RT_CAN_MODE_NORMAL || - argval != RT_CAN_MODE_LISEN || + argval != RT_CAN_MODE_LISTEN || argval != RT_CAN_MODE_LOOPBACK || - argval != RT_CAN_MODE_LOOPBACKANLISEN) + argval != RT_CAN_MODE_LOOPBACKANLISTEN) { return RT_ERROR; } diff --git a/bsp/loongson/ls1cdev/libraries/ls1c_can.h b/bsp/loongson/ls1cdev/libraries/ls1c_can.h index b2b0f8efa8..fcf6e31d5c 100644 --- a/bsp/loongson/ls1cdev/libraries/ls1c_can.h +++ b/bsp/loongson/ls1cdev/libraries/ls1c_can.h @@ -1,9 +1,9 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2022, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * - * Change Logs: (Pelican Mode) + * Change Logs: (Pelican Mode) * Date Author Notes * 2018-01-06 sundm75 first version */ @@ -54,9 +54,9 @@ #define CAN_RTR_Remote 1 #define CAN_MODE_NORMAL 0 -#define CAN_MODE_LISEN 1 +#define CAN_MODE_LISTEN 1 #define CAN_MODE_LOOPBACK 2 -#define CAN_MODE_LOOPBACKANLISEN 3 +#define CAN_MODE_LOOPBACKANLISTEN 3 /*!< CAN 控制状态寄存器 */ /************************** CAN_MOD 寄存器位定义*******************************/ @@ -84,7 +84,7 @@ #define CAN_SR_TS ((unsigned char)0x20) /*!< 发送状态1: 发送 0: 空闲*/ #define CAN_SR_ES ((unsigned char)0x40) /*!< 出错状态1:出错 0: 正常 */ #define CAN_SR_BS ((unsigned char)0x80) /*!< 总线状态1: 关闭 0: 开启 */ - + /************************** CAN_IR 中断寄存器位定义****************************/ #define CAN_IR_RI ((unsigned char)0x01) /*!< 接收中断 */ #define CAN_IR_TI ((unsigned char)0x02) /*!< 发送中断 */ @@ -94,7 +94,7 @@ #define CAN_IR_EPI ((unsigned char)0x20) /*!< 错误消极中断 */ #define CAN_IR_ALI ((unsigned char)0x40) /*!< 仲裁丢失中断 */ #define CAN_IR_BEI ((unsigned char)0x80) /*!< 总线错误中断 */ - + /************************* CAN_IER 中断使能寄存器位定义************************/ #define CAN_IER_RIE ((unsigned char)0x01) /*!< 接收中断使能 */ #define CAN_IER_TIE ((unsigned char)0x02) /*!< 发送中断使能 */ @@ -104,17 +104,17 @@ #define CAN_IER_EPIE ((unsigned char)0x20) /*!< 错误消极中断使能 */ #define CAN_IER_ALIE ((unsigned char)0x40) /*!< 仲裁丢失中断使能 */ #define CAN_IER_BEIE ((unsigned char)0x80) /*!< 总线错误中断使能 */ - -typedef enum + +typedef enum { - LS1C_CAN1MBaud=0, // 1 MBit/sec - LS1C_CAN800kBaud, // 800 kBit/sec - LS1C_CAN500kBaud, // 500 kBit/sec - LS1C_CAN250kBaud, // 250 kBit/sec - LS1C_CAN125kBaud, // 125 kBit/sec - LS1C_CAN100kBaud, // 100 kBit/sec - LS1C_CAN50kBaud, // 50 kBit/sec - LS1C_CAN40kBaud, // 40 kBit/sec + LS1C_CAN1MBaud=0, // 1 MBit/sec + LS1C_CAN800kBaud, // 800 kBit/sec + LS1C_CAN500kBaud, // 500 kBit/sec + LS1C_CAN250kBaud, // 250 kBit/sec + LS1C_CAN125kBaud, // 125 kBit/sec + LS1C_CAN100kBaud, // 100 kBit/sec + LS1C_CAN50kBaud, // 50 kBit/sec + LS1C_CAN40kBaud, // 40 kBit/sec }Ls1c_CanBPS_t; typedef struct @@ -143,12 +143,12 @@ typedef struct typedef struct { - unsigned char CAN_Prescaler; /* 波特率分频系数1 to 31. */ + unsigned char CAN_Prescaler; /* 波特率分频系数1 to 31. */ unsigned char CAN_Mode; /*0x10:睡眠0x08:单,双滤波 0x40:正常工作0x20:只听 0x01:复位*/ unsigned char CAN_SJW; /*同步跳转宽度 */ unsigned char CAN_BS1; /*时间段1计数值*/ - unsigned char CAN_BS2; /*时间段2计数值*/ - + unsigned char CAN_BS2; /*时间段2计数值*/ + } CAN_InitTypeDef; typedef struct diff --git a/bsp/n32g452xx/Libraries/rt_drivers/drv_can.c b/bsp/n32g452xx/Libraries/rt_drivers/drv_can.c index 280e749d5c..22d8a04450 100644 --- a/bsp/n32g452xx/Libraries/rt_drivers/drv_can.c +++ b/bsp/n32g452xx/Libraries/rt_drivers/drv_can.c @@ -104,13 +104,13 @@ static uint8_t get_can_mode_rtt2n32(uint8_t rtt_can_mode) case RT_CAN_MODE_NORMAL: mode = CAN_Normal_Mode; break; - case RT_CAN_MODE_LISEN: + case RT_CAN_MODE_LISTEN: mode = CAN_Silent_Mode; break; case RT_CAN_MODE_LOOPBACK: mode = CAN_LoopBack_Mode; break; - case RT_CAN_MODE_LOOPBACKANLISEN: + case RT_CAN_MODE_LOOPBACKANLISTEN: mode = CAN_Silent_LoopBack_Mode; break; } @@ -413,9 +413,9 @@ static rt_err_t _can_control(struct rt_can_device *can, int cmd, void *arg) case RT_CAN_CMD_SET_MODE: argval = (rt_uint32_t)arg; if (argval != RT_CAN_MODE_NORMAL && - argval != RT_CAN_MODE_LISEN && + argval != RT_CAN_MODE_LISTEN && argval != RT_CAN_MODE_LOOPBACK && - argval != RT_CAN_MODE_LOOPBACKANLISEN) + argval != RT_CAN_MODE_LOOPBACKANLISTEN) { return -RT_ERROR; } diff --git a/bsp/nuvoton/libraries/m2354/rtt_port/drv_can.c b/bsp/nuvoton/libraries/m2354/rtt_port/drv_can.c index 511fb592a2..3327901cd1 100644 --- a/bsp/nuvoton/libraries/m2354/rtt_port/drv_can.c +++ b/bsp/nuvoton/libraries/m2354/rtt_port/drv_can.c @@ -256,13 +256,13 @@ static rt_err_t nu_can_configure(struct rt_can_device *can, struct can_configure CAN_EnterTestMode(base, CAN_TEST_BASIC_Msk); #endif break; - case RT_CAN_MODE_LISEN: + case RT_CAN_MODE_LISTEN: CAN_EnterTestMode(base, CAN_TEST_BASIC_Msk | CAN_TEST_SILENT_Msk); break; case RT_CAN_MODE_LOOPBACK: CAN_EnterTestMode(base, CAN_TEST_BASIC_Msk | CAN_TEST_LBACK_Msk); break; - case RT_CAN_MODE_LOOPBACKANLISEN: + case RT_CAN_MODE_LOOPBACKANLISTEN: CAN_EnterTestMode(base, CAN_TEST_BASIC_Msk | CAN_TEST_SILENT_Msk | CAN_TEST_LBACK_Msk); break; default: @@ -328,9 +328,9 @@ static rt_err_t nu_can_control(struct rt_can_device *can, int cmd, void *arg) case RT_CAN_CMD_SET_MODE: if ((argval == RT_CAN_MODE_NORMAL) || - (argval == RT_CAN_MODE_LISEN) || + (argval == RT_CAN_MODE_LISTEN) || (argval == RT_CAN_MODE_LOOPBACK) || - (argval == RT_CAN_MODE_LOOPBACKANLISEN)) + (argval == RT_CAN_MODE_LOOPBACKANLISTEN)) { if (argval != can->config.mode) { diff --git a/bsp/nuvoton/libraries/m480/rtt_port/drv_can.c b/bsp/nuvoton/libraries/m480/rtt_port/drv_can.c index 14926076c3..c9915aee95 100644 --- a/bsp/nuvoton/libraries/m480/rtt_port/drv_can.c +++ b/bsp/nuvoton/libraries/m480/rtt_port/drv_can.c @@ -307,13 +307,13 @@ static rt_err_t nu_can_configure(struct rt_can_device *can, struct can_configure CAN_EnterTestMode(base, CAN_TEST_BASIC_Msk); #endif break; - case RT_CAN_MODE_LISEN: + case RT_CAN_MODE_LISTEN: CAN_EnterTestMode(base, CAN_TEST_BASIC_Msk | CAN_TEST_SILENT_Msk); break; case RT_CAN_MODE_LOOPBACK: CAN_EnterTestMode(base, CAN_TEST_BASIC_Msk | CAN_TEST_LBACK_Msk); break; - case RT_CAN_MODE_LOOPBACKANLISEN: + case RT_CAN_MODE_LOOPBACKANLISTEN: CAN_EnterTestMode(base, CAN_TEST_BASIC_Msk | CAN_TEST_SILENT_Msk | CAN_TEST_LBACK_Msk); break; default: @@ -379,9 +379,9 @@ static rt_err_t nu_can_control(struct rt_can_device *can, int cmd, void *arg) case RT_CAN_CMD_SET_MODE: if ((argval == RT_CAN_MODE_NORMAL) || - (argval == RT_CAN_MODE_LISEN) || + (argval == RT_CAN_MODE_LISTEN) || (argval == RT_CAN_MODE_LOOPBACK) || - (argval == RT_CAN_MODE_LOOPBACKANLISEN)) + (argval == RT_CAN_MODE_LOOPBACKANLISTEN)) { if (argval != can->config.mode) { diff --git a/bsp/nuvoton/libraries/n9h30/rtt_port/drv_can.c b/bsp/nuvoton/libraries/n9h30/rtt_port/drv_can.c index aedd61f018..ebbda12689 100644 --- a/bsp/nuvoton/libraries/n9h30/rtt_port/drv_can.c +++ b/bsp/nuvoton/libraries/n9h30/rtt_port/drv_can.c @@ -256,13 +256,13 @@ static rt_err_t nu_can_configure(struct rt_can_device *can, struct can_configure CAN_EnterTestMode(base, CAN_TEST_BASIC_Msk); #endif break; - case RT_CAN_MODE_LISEN: + case RT_CAN_MODE_LISTEN: CAN_EnterTestMode(base, CAN_TEST_BASIC_Msk | CAN_TEST_SILENT_Msk); break; case RT_CAN_MODE_LOOPBACK: CAN_EnterTestMode(base, CAN_TEST_BASIC_Msk | CAN_TEST_LBACK_Msk); break; - case RT_CAN_MODE_LOOPBACKANLISEN: + case RT_CAN_MODE_LOOPBACKANLISTEN: CAN_EnterTestMode(base, CAN_TEST_BASIC_Msk | CAN_TEST_SILENT_Msk | CAN_TEST_LBACK_Msk); break; default: @@ -328,9 +328,9 @@ static rt_err_t nu_can_control(struct rt_can_device *can, int cmd, void *arg) case RT_CAN_CMD_SET_MODE: if ((argval == RT_CAN_MODE_NORMAL) || - (argval == RT_CAN_MODE_LISEN) || + (argval == RT_CAN_MODE_LISTEN) || (argval == RT_CAN_MODE_LOOPBACK) || - (argval == RT_CAN_MODE_LOOPBACKANLISEN)) + (argval == RT_CAN_MODE_LOOPBACKANLISTEN)) { if (argval != can->config.mode) { diff --git a/bsp/nuvoton/libraries/nuc980/rtt_port/drv_can.c b/bsp/nuvoton/libraries/nuc980/rtt_port/drv_can.c index fcdbbe8d74..385f9e4123 100644 --- a/bsp/nuvoton/libraries/nuc980/rtt_port/drv_can.c +++ b/bsp/nuvoton/libraries/nuc980/rtt_port/drv_can.c @@ -280,13 +280,13 @@ static rt_err_t nu_can_configure(struct rt_can_device *can, struct can_configure CAN_EnterTestMode(base, CAN_TEST_BASIC_Msk); #endif break; - case RT_CAN_MODE_LISEN: + case RT_CAN_MODE_LISTEN: CAN_EnterTestMode(base, CAN_TEST_BASIC_Msk | CAN_TEST_SILENT_Msk); break; case RT_CAN_MODE_LOOPBACK: CAN_EnterTestMode(base, CAN_TEST_BASIC_Msk | CAN_TEST_LBACK_Msk); break; - case RT_CAN_MODE_LOOPBACKANLISEN: + case RT_CAN_MODE_LOOPBACKANLISTEN: CAN_EnterTestMode(base, CAN_TEST_BASIC_Msk | CAN_TEST_SILENT_Msk | CAN_TEST_LBACK_Msk); break; default: @@ -352,9 +352,9 @@ static rt_err_t nu_can_control(struct rt_can_device *can, int cmd, void *arg) case RT_CAN_CMD_SET_MODE: if ((argval == RT_CAN_MODE_NORMAL) || - (argval == RT_CAN_MODE_LISEN) || + (argval == RT_CAN_MODE_LISTEN) || (argval == RT_CAN_MODE_LOOPBACK) || - (argval == RT_CAN_MODE_LOOPBACKANLISEN)) + (argval == RT_CAN_MODE_LOOPBACKANLISTEN)) { if (argval != can->config.mode) { diff --git a/bsp/renesas/libraries/HAL_Drivers/drv_can.c b/bsp/renesas/libraries/HAL_Drivers/drv_can.c index f87e0d9155..60b64565b3 100644 --- a/bsp/renesas/libraries/HAL_Drivers/drv_can.c +++ b/bsp/renesas/libraries/HAL_Drivers/drv_can.c @@ -134,7 +134,7 @@ rt_err_t ra_can_control(struct rt_can_device *can_dev, int cmd, void *arg) case RT_CAN_CMD_SET_MODE: argval = (rt_uint32_t) arg; if (argval != RT_CAN_MODE_NORMAL && - argval != RT_CAN_MODE_LISEN && + argval != RT_CAN_MODE_LISTEN && argval != RT_CAN_MODE_LOOPBACK) { return -RT_ERROR; @@ -147,7 +147,7 @@ rt_err_t ra_can_control(struct rt_can_device *can_dev, int cmd, void *arg) { case RT_CAN_MODE_NORMAL: mode_to_set = CAN_TEST_MODE_DISABLED; - case RT_CAN_MODE_LISEN: + case RT_CAN_MODE_LISTEN: mode_to_set = CAN_TEST_MODE_LISTEN; case RT_CAN_MODE_LOOPBACK: mode_to_set = CAN_TEST_MODE_LOOPBACK_INTERNAL; diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_can.c b/bsp/stm32/libraries/HAL_Drivers/drv_can.c index a3959a2083..1cb003bdf4 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_can.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_can.c @@ -149,13 +149,13 @@ static rt_err_t _can_config(struct rt_can_device *can, struct can_configure *cfg case RT_CAN_MODE_NORMAL: drv_can->CanHandle.Init.Mode = CAN_MODE_NORMAL; break; - case RT_CAN_MODE_LISEN: + case RT_CAN_MODE_LISTEN: drv_can->CanHandle.Init.Mode = CAN_MODE_SILENT; break; case RT_CAN_MODE_LOOPBACK: drv_can->CanHandle.Init.Mode = CAN_MODE_LOOPBACK; break; - case RT_CAN_MODE_LOOPBACKANLISEN: + case RT_CAN_MODE_LOOPBACKANLISTEN: drv_can->CanHandle.Init.Mode = CAN_MODE_SILENT_LOOPBACK; break; } @@ -410,9 +410,9 @@ static rt_err_t _can_control(struct rt_can_device *can, int cmd, void *arg) case RT_CAN_CMD_SET_MODE: argval = (rt_uint32_t) arg; if (argval != RT_CAN_MODE_NORMAL && - argval != RT_CAN_MODE_LISEN && + argval != RT_CAN_MODE_LISTEN && argval != RT_CAN_MODE_LOOPBACK && - argval != RT_CAN_MODE_LOOPBACKANLISEN) + argval != RT_CAN_MODE_LOOPBACKANLISTEN) { return -RT_ERROR; } diff --git a/components/drivers/Kconfig b/components/drivers/Kconfig index d432faee05..00c4a07998 100755 --- a/components/drivers/Kconfig +++ b/components/drivers/Kconfig @@ -53,6 +53,9 @@ if RT_USING_CAN config RT_CAN_USING_HDR bool "Enable CAN hardware filter" default n + config RT_CAN_USING_CANFD + bool "Enable CANFD support" + default n endif config RT_USING_HWTIMER diff --git a/components/drivers/can/can.c b/components/drivers/can/can.c index 358220013f..f110bc9e1f 100644 --- a/components/drivers/can/can.c +++ b/components/drivers/can/can.c @@ -924,7 +924,7 @@ int cmd_canstat(int argc, void **argv) rt_kprintf(" Can't find can device %s\n", argv[1]); return -1; } - rt_kprintf(" Finded can device: %s...", argv[1]); + rt_kprintf(" Found can device: %s...", argv[1]); rt_device_control(candev, RT_CAN_CMD_GET_STATUS, &status); rt_kprintf("\n Receive...error..count: %010ld. Send.....error....count: %010ld.", @@ -954,9 +954,9 @@ int cmd_canstat(int argc, void **argv) rt_kprintf("%s.", ErrCode[3]); break; } - rt_kprintf("\n Total.receive.packages: %010ld. Droped.receive.packages: %010ld.", + rt_kprintf("\n Total.receive.packages: %010ld. Dropped.receive.packages: %010ld.", status.rcvpkg, status.dropedrcvpkg); - rt_kprintf("\n Total..send...packages: %010ld. Droped...send..packages: %010ld.\n", + rt_kprintf("\n Total..send...packages: %010ld. Dropped...send..packages: %010ld.\n", status.sndpkg + status.dropedsndpkg, status.dropedsndpkg); } else diff --git a/components/drivers/include/drivers/can.h b/components/drivers/include/drivers/can.h index bb05317d4f..553e145e92 100644 --- a/components/drivers/include/drivers/can.h +++ b/components/drivers/include/drivers/can.h @@ -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 * @@ -7,6 +7,7 @@ * Date Author Notes * 2015-05-14 aubrcool@qq.com first version * 2015-07-06 Bernard remove RT_CAN_USING_LED. + * 2022-05-08 hpmicro add CANFD support, fixed typos */ #ifndef CAN_H_ @@ -21,6 +22,26 @@ #define RT_CANSND_BOX_NUM 1 #endif +enum CAN_DLC +{ + CAN_MSG_0BYTE = 0, + CAN_MSG_1BYTE, + CAN_MSG_2BYTES, + CAN_MSG_3BYTES, + CAN_MSG_4BYTES, + CAN_MSG_5BYTES, + CAN_MSG_6BYTES, + CAN_MSG_7BYTES, + CAN_MSG_8BYTES, + CAN_MSG_12BYTES, + CAN_MSG_16BYTES, + CAN_MSG_20BYTES, + CAN_MSG_24BYTES, + CAN_MSG_32BYTES, + CAN_MSG_48BYTES, + CAN_MSG_64BYTES, +}; + enum CANBAUD { CAN1MBaud = 1000UL * 1000,/* 1 MBit/sec */ @@ -35,9 +56,9 @@ enum CANBAUD }; #define RT_CAN_MODE_NORMAL 0 -#define RT_CAN_MODE_LISEN 1 +#define RT_CAN_MODE_LISTEN 1 #define RT_CAN_MODE_LOOPBACK 2 -#define RT_CAN_MODE_LOOPBACKANLISEN 3 +#define RT_CAN_MODE_LOOPBACKANLISTEN 3 #define RT_CAN_MODE_PRIV 0x01 #define RT_CAN_MODE_NOPRIV 0x00 @@ -96,6 +117,27 @@ struct rt_can_filter_config struct rt_can_filter_item *items; }; +struct rt_can_bit_timing +{ + rt_uint16_t prescaler; /* Pre-scaler */ + rt_uint16_t num_seg1; /* Bit Timing Segment 1, in terms of Tq */ + rt_uint16_t num_seg2; /* Bit Timing Segment 2, in terms of Tq */ + rt_uint8_t num_sjw; /* Synchronization Jump Width, in terms of Tq */ + rt_uint8_t num_sspoff; /* Secondary Sample Point Offset, in terms of Tq */ +}; + +/** + * CAN bit timing configuration list + * NOTE: + * items[0] always for CAN2.0/CANFD Arbitration Phase + * items[1] always for CANFD (if it exists) + */ +struct rt_can_bit_timing_config +{ + rt_uint32_t count; + struct rt_can_bit_timing *items; +}; + struct can_configure { rt_uint32_t baud_rate; @@ -108,6 +150,17 @@ struct can_configure #ifdef RT_CAN_USING_HDR rt_uint32_t maxhdr; #endif + +#ifdef RT_CAN_USING_CANFD + rt_uint32_t baud_rate_fd; /* CANFD data bit rate*/ + rt_uint32_t use_bit_timing: 8; /* Use the bit timing for CAN timing configuration */ + rt_uint32_t enable_canfd : 8; /* Enable CAN-FD mode */ + rt_uint32_t reserved1 : 16; + + /* The below fields take effect only if use_bit_timing is non-zero */ + struct rt_can_bit_timing can_timing; /* CAN bit-timing /CANFD bit-timing for arbitration phase */ + struct rt_can_bit_timing canfd_timing; /* CANFD bit-timing for datat phase */ +#endif }; #define CANDEFAULTCONFIG \ @@ -126,6 +179,9 @@ struct rt_can_ops; #define RT_CAN_CMD_GET_STATUS 0x17 #define RT_CAN_CMD_SET_STATUS_IND 0x18 #define RT_CAN_CMD_SET_BUS_HOOK 0x19 +#define RT_CAN_CMD_SET_CANFD 0x1A +#define RT_CAN_CMD_SET_BAUD_FD 0x1B +#define RT_CAN_CMD_SET_BITTIMING 0x1C #define RT_DEVICE_CAN_INT_ERR 0x1000 @@ -222,8 +278,17 @@ struct rt_can_msg rt_uint32_t len : 8; rt_uint32_t priv : 8; rt_int32_t hdr : 8; +#ifdef RT_CAN_USING_CANFD + rt_uint32_t fd_frame : 1; + rt_uint32_t reserved : 7; +#else rt_uint32_t reserved : 8; +#endif +#ifdef RT_CAN_USING_CANFD + rt_uint8_t data[64]; +#else rt_uint8_t data[8]; +#endif }; typedef struct rt_can_msg *rt_can_msg_t;