|
7 | 7 | * Date Author Notes |
8 | 8 | * 2020-02-24 heyuan the first version |
9 | 9 | * 2020-08-17 malongwei Fix something |
| 10 | + * 2025-10-27 pandafeng Fix some bugs |
10 | 11 | */ |
11 | 12 |
|
12 | 13 | #include "drv_fdcan.h" |
@@ -101,7 +102,11 @@ static uint32_t _inline_get_ArbBaudIndex(uint32_t baud_rate) |
101 | 102 | } |
102 | 103 |
|
103 | 104 | /** |
104 | | - * @brief 获取 FDCAN 数据段波特率配置索引 |
| 105 | + * @brief Get the index of the FDCAN data segment bitrate configuration. |
| 106 | + * |
| 107 | + * @param baud_rate The desired data phase baud rate (in bps). |
| 108 | + * @retval uint32_t Index of the matching data segment configuration. |
| 109 | + * Returns -1 if no matching configuration is found. |
105 | 110 | */ |
106 | 111 | static uint32_t _inline_get_DataBaudIndex(uint32_t baud_rate) |
107 | 112 | { |
@@ -156,7 +161,7 @@ static rt_err_t _inline_can_config(struct rt_can_device *can, struct can_configu |
156 | 161 | LOG_E("not support %d baudrate", cfg->baud_rate); |
157 | 162 | return -RT_ERROR; |
158 | 163 | } |
159 | | - /* 仲裁段 */ |
| 164 | + /* FDCAN arbitration segment */ |
160 | 165 | pdrv_can->fdcanHandle.Init.NominalPrescaler = st_FDCAN_ArbTiming[arb_idx].cam_bit_timing.prescaler; |
161 | 166 | pdrv_can->fdcanHandle.Init.NominalSyncJumpWidth = st_FDCAN_ArbTiming[arb_idx].cam_bit_timing.num_sjw; |
162 | 167 | pdrv_can->fdcanHandle.Init.NominalTimeSeg1 = st_FDCAN_ArbTiming[arb_idx].cam_bit_timing.num_seg1; |
@@ -345,10 +350,9 @@ static rt_err_t _inline_can_control(struct rt_can_device *can, int cmd, void *ar |
345 | 350 | break; |
346 | 351 | case RT_CAN_CMD_SET_BAUD: |
347 | 352 | argval = (rt_uint32_t) arg; |
348 | | - /* 查找仲裁相位波特率是否存在 */ |
349 | 353 | uint32_t arb_idx = _inline_get_ArbBaudIndex(argval); |
350 | 354 | if (arb_idx == (uint32_t) -1) { |
351 | | - return -RT_ERROR; // 未找到匹配波特率 |
| 355 | + return -RT_ERROR; |
352 | 356 | } |
353 | 357 | if (argval != pdrv_can->device.config.baud_rate) { |
354 | 358 | pdrv_can->device.config.baud_rate = argval; |
@@ -383,10 +387,9 @@ static rt_err_t _inline_can_control(struct rt_can_device *can, int cmd, void *ar |
383 | 387 | break; |
384 | 388 | case RT_CAN_CMD_SET_BAUD_FD: { |
385 | 389 | argval = (rt_uint32_t) arg; |
386 | | - /* 查找仲裁相位波特率是否存在 */ |
387 | 390 | uint32_t data_idx = _inline_get_DataBaudIndex(argval); |
388 | 391 | if (data_idx == (uint32_t) -1) { |
389 | | - return -RT_ERROR; // 未找到匹配波特率 |
| 392 | + return -RT_ERROR; |
390 | 393 | } |
391 | 394 | if (argval != pdrv_can->device.config.baud_rate_fd) { |
392 | 395 | pdrv_can->device.config.baud_rate_fd = argval; |
|
0 commit comments