bxcan: move CAN_btconst to CAN driver

This commit is contained in:
Marc Kleine-Budde 2023-01-28 15:34:47 +01:00 committed by Marc Kleine-Budde
parent 206de0067a
commit ad72111d65
3 changed files with 26 additions and 25 deletions

View File

@ -46,6 +46,8 @@ typedef struct {
uint8_t nr;
} can_data_t;
extern const struct gs_device_bt_const CAN_btconst;
void can_init(can_data_t *channel, CAN_TypeDef *instance);
bool can_set_bittiming(can_data_t *channel, uint16_t brp, uint8_t phase_seg1, uint8_t phase_seg2, uint8_t sjw);
void can_enable(can_data_t *channel, uint32_t mode);

View File

@ -32,6 +32,28 @@
#include "hal_include.h"
#include "timer.h"
const struct gs_device_bt_const CAN_btconst = {
.feature =
GS_CAN_FEATURE_LISTEN_ONLY |
GS_CAN_FEATURE_LOOP_BACK |
GS_CAN_FEATURE_HW_TIMESTAMP |
GS_CAN_FEATURE_IDENTIFY |
GS_CAN_FEATURE_PAD_PKTS_TO_MAX_PKT_SIZE
#ifdef TERM_Pin
| GS_CAN_FEATURE_TERMINATION
#endif
,
.fclk_can = CAN_CLOCK_SPEED,
.tseg1_min = 1,
.tseg1_max = 16,
.tseg2_min = 1,
.tseg2_max = 8,
.sjw_max = 4,
.brp_min = 1,
.brp_max = 1024,
.brp_inc = 1,
};
// The STM32F0 only has one CAN interface, define it as CAN1 as
// well, so it doesn't need to be handled separately.
#if !defined(CAN1) && defined(CAN)

View File

@ -213,29 +213,6 @@ static const struct gs_device_config USBD_GS_CAN_dconf = {
.hw_version = 1,
};
// bit timing constraints
static const struct gs_device_bt_const USBD_GS_CAN_btconst = {
.feature =
GS_CAN_FEATURE_LISTEN_ONLY |
GS_CAN_FEATURE_LOOP_BACK |
GS_CAN_FEATURE_HW_TIMESTAMP |
GS_CAN_FEATURE_IDENTIFY |
GS_CAN_FEATURE_PAD_PKTS_TO_MAX_PKT_SIZE
#ifdef TERM_Pin
| GS_CAN_FEATURE_TERMINATION
#endif
,
.fclk_can = CAN_CLOCK_SPEED,
.tseg1_min = 1,
.tseg1_max = 16,
.tseg2_min = 1,
.tseg2_max = 8,
.sjw_max = 4,
.brp_min = 1,
.brp_max = 1024,
.brp_inc = 1,
};
/* It's unclear from the documentation, but it appears that the USB library is
* not safely reentrant. It attempts to signal errors via return values if it is
* reentered, but that code is not interrupt-safe and the error values are
@ -357,8 +334,8 @@ static uint8_t USBD_GS_CAN_Config_Request(USBD_HandleTypeDef *pdev, USBD_SetupRe
len = sizeof(struct gs_device_mode);
break;
case GS_USB_BREQ_BT_CONST:
src = &USBD_GS_CAN_btconst;
len = sizeof(USBD_GS_CAN_btconst);
src = &CAN_btconst;
len = sizeof(CAN_btconst);
break;
case GS_USB_BREQ_DEVICE_CONFIG:
src = &USBD_GS_CAN_dconf;