Skip to content

Commit

Permalink
bxcan: move CAN_btconst to CAN driver
Browse files Browse the repository at this point in the history
  • Loading branch information
marckleinebudde committed Jan 30, 2024
1 parent 206de00 commit ad72111
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
2 changes: 2 additions & 0 deletions include/can.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 22 additions & 0 deletions src/can/bxcan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 2 additions & 25 deletions src/usbd_gs_can.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ad72111

Please sign in to comment.