2022-05-06 09:28:21 +08:00
|
|
|
/*
|
2022-05-31 11:53:56 +08:00
|
|
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
|
|
|
* Copyright (c) 2022, Xiaohua Semiconductor Co., Ltd.
|
2022-05-06 09:28:21 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2022-04-28 CDT first version
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __CAN_CONFIG_H__
|
|
|
|
#define __CAN_CONFIG_H__
|
|
|
|
|
|
|
|
#include <rtthread.h>
|
2022-05-15 20:57:35 +08:00
|
|
|
#include "irq_config.h"
|
2022-05-06 09:28:21 +08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef BSP_USING_CAN1
|
2022-05-15 20:57:35 +08:00
|
|
|
#ifndef CAN1_INIT_PARAMS
|
|
|
|
#define CAN1_INIT_PARAMS \
|
2022-05-06 09:28:21 +08:00
|
|
|
{ \
|
|
|
|
.name = "can1", \
|
|
|
|
}
|
2022-05-15 20:57:35 +08:00
|
|
|
#endif /* CAN1_INIT_PARAMS */
|
2022-05-06 09:28:21 +08:00
|
|
|
#endif /* BSP_USING_CAN1 */
|
|
|
|
|
|
|
|
#ifdef BSP_USING_CAN2
|
2022-05-15 20:57:35 +08:00
|
|
|
#ifndef CAN2_INIT_PARAMS
|
|
|
|
#define CAN2_INIT_PARAMS \
|
2022-05-06 09:28:21 +08:00
|
|
|
{ \
|
|
|
|
.name = "can2", \
|
|
|
|
}
|
2022-05-15 20:57:35 +08:00
|
|
|
#endif /* CAN2_INIT_PARAMS */
|
2022-05-06 09:28:21 +08:00
|
|
|
#endif /* BSP_USING_CAN2 */
|
|
|
|
|
2022-05-15 20:57:35 +08:00
|
|
|
/* Bit time config
|
|
|
|
Restrictions: u32TimeSeg1 >= u32TimeSeg2 + 1, u32TimeSeg2 >= u32SJW.
|
|
|
|
|
|
|
|
Baudrate = CANClock/(u32Prescaler*(u32TimeSeg1 + u32TimeSeg2))
|
|
|
|
TQ = u32Prescaler / CANClock.
|
|
|
|
Bit time = (u32TimeSeg2 + u32TimeSeg2) x TQ.
|
|
|
|
|
|
|
|
The following bit time configures are based on CAN Clock 40M
|
|
|
|
*/
|
|
|
|
#define CAN_BIT_TIME_CONFIG_1M_BAUD \
|
|
|
|
{ \
|
|
|
|
.u32Prescaler = 2, \
|
|
|
|
.u32TimeSeg1 = 16, \
|
|
|
|
.u32TimeSeg2 = 4, \
|
|
|
|
.u32SJW = 4 \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CAN_BIT_TIME_CONFIG_800K_BAUD \
|
|
|
|
{ \
|
|
|
|
.u32Prescaler = 2, \
|
|
|
|
.u32TimeSeg1 = 20, \
|
|
|
|
.u32TimeSeg2 = 5, \
|
|
|
|
.u32SJW = 4 \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CAN_BIT_TIME_CONFIG_500K_BAUD \
|
|
|
|
{ \
|
|
|
|
.u32Prescaler = 4, \
|
|
|
|
.u32TimeSeg1 = 16, \
|
|
|
|
.u32TimeSeg2 = 4, \
|
|
|
|
.u32SJW = 4 \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CAN_BIT_TIME_CONFIG_250K_BAUD \
|
|
|
|
{ \
|
|
|
|
.u32Prescaler = 8, \
|
|
|
|
.u32TimeSeg1 = 16, \
|
|
|
|
.u32TimeSeg2 = 4, \
|
|
|
|
.u32SJW = 4 \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CAN_BIT_TIME_CONFIG_125K_BAUD \
|
|
|
|
{ \
|
|
|
|
.u32Prescaler = 16, \
|
|
|
|
.u32TimeSeg1 = 16, \
|
|
|
|
.u32TimeSeg2 = 4, \
|
|
|
|
.u32SJW = 4 \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CAN_BIT_TIME_CONFIG_100K_BAUD \
|
|
|
|
{ \
|
|
|
|
.u32Prescaler = 20, \
|
|
|
|
.u32TimeSeg1 = 16, \
|
|
|
|
.u32TimeSeg2 = 4, \
|
|
|
|
.u32SJW = 4 \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CAN_BIT_TIME_CONFIG_50K_BAUD \
|
|
|
|
{ \
|
|
|
|
.u32Prescaler = 40, \
|
|
|
|
.u32TimeSeg1 = 16, \
|
|
|
|
.u32TimeSeg2 = 4, \
|
|
|
|
.u32SJW = 4 \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CAN_BIT_TIME_CONFIG_20K_BAUD \
|
|
|
|
{ \
|
|
|
|
.u32Prescaler = 100, \
|
|
|
|
.u32TimeSeg1 = 16, \
|
|
|
|
.u32TimeSeg2 = 4, \
|
|
|
|
.u32SJW = 4 \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CAN_BIT_TIME_CONFIG_10K_BAUD \
|
|
|
|
{ \
|
|
|
|
.u32Prescaler = 200, \
|
|
|
|
.u32TimeSeg1 = 16, \
|
|
|
|
.u32TimeSeg2 = 4, \
|
|
|
|
.u32SJW = 4 \
|
|
|
|
}
|
|
|
|
|
2022-05-06 09:28:21 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __CAN_CONFIG_H__ */
|