mirror of
https://github.com/candle-usb/candleLight_fw.git
synced 2025-02-04 06:12:55 +08:00
can: can_enable: move the mode flags evaluation into the CAN drivers
...having so many arguments doesn't scale.
This commit is contained in:
parent
45424cf541
commit
206de0067a
@ -48,7 +48,7 @@ typedef struct {
|
|||||||
|
|
||||||
void can_init(can_data_t *channel, CAN_TypeDef *instance);
|
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);
|
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, bool loop_back, bool listen_only, bool one_shot);
|
void can_enable(can_data_t *channel, uint32_t mode);
|
||||||
void can_disable(can_data_t *channel);
|
void can_disable(can_data_t *channel);
|
||||||
bool can_is_enabled(can_data_t *channel);
|
bool can_is_enabled(can_data_t *channel);
|
||||||
|
|
||||||
|
@ -78,22 +78,30 @@ bool can_set_bittiming(can_data_t *channel, uint16_t brp, uint8_t phase_seg1, ui
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void can_enable(can_data_t *channel, bool loop_back, bool listen_only, bool one_shot)
|
void can_enable(can_data_t *channel, uint32_t mode)
|
||||||
{
|
{
|
||||||
CAN_TypeDef *can = channel->instance;
|
CAN_TypeDef *can = channel->instance;
|
||||||
|
|
||||||
uint32_t mcr = CAN_MCR_INRQ
|
uint32_t mcr = CAN_MCR_INRQ
|
||||||
| CAN_MCR_ABOM
|
| CAN_MCR_ABOM
|
||||||
| CAN_MCR_TXFP
|
| CAN_MCR_TXFP;
|
||||||
| (one_shot ? CAN_MCR_NART : 0);
|
|
||||||
|
if (mode & GS_CAN_MODE_ONE_SHOT) {
|
||||||
|
mcr |= CAN_MCR_NART;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t btr = ((uint32_t)(channel->sjw-1)) << 24
|
uint32_t btr = ((uint32_t)(channel->sjw-1)) << 24
|
||||||
| ((uint32_t)(channel->phase_seg1-1)) << 16
|
| ((uint32_t)(channel->phase_seg1-1)) << 16
|
||||||
| ((uint32_t)(channel->phase_seg2-1)) << 20
|
| ((uint32_t)(channel->phase_seg2-1)) << 20
|
||||||
| (channel->brp - 1)
|
| (channel->brp - 1);
|
||||||
| (loop_back ? CAN_MODE_LOOPBACK : 0)
|
|
||||||
| (listen_only ? CAN_MODE_SILENT : 0);
|
|
||||||
|
|
||||||
|
if (mode & GS_CAN_MODE_LISTEN_ONLY) {
|
||||||
|
btr |= CAN_MODE_SILENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode & GS_CAN_MODE_LOOP_BACK) {
|
||||||
|
btr |= CAN_MODE_LOOPBACK;
|
||||||
|
}
|
||||||
|
|
||||||
// Reset CAN peripheral
|
// Reset CAN peripheral
|
||||||
can->MCR |= CAN_MCR_RESET;
|
can->MCR |= CAN_MCR_RESET;
|
||||||
|
@ -532,12 +532,7 @@ static uint8_t USBD_GS_CAN_EP0_RxReady(USBD_HandleTypeDef *pdev) {
|
|||||||
hcan->timestamps_enabled = (mode->flags & GS_CAN_MODE_HW_TIMESTAMP) != 0;
|
hcan->timestamps_enabled = (mode->flags & GS_CAN_MODE_HW_TIMESTAMP) != 0;
|
||||||
hcan->pad_pkts_to_max_pkt_size = (mode->flags & GS_CAN_MODE_PAD_PKTS_TO_MAX_PKT_SIZE) != 0;
|
hcan->pad_pkts_to_max_pkt_size = (mode->flags & GS_CAN_MODE_PAD_PKTS_TO_MAX_PKT_SIZE) != 0;
|
||||||
|
|
||||||
can_enable(channel,
|
can_enable(channel, mode->flags);
|
||||||
(mode->flags & GS_CAN_MODE_LOOP_BACK) != 0,
|
|
||||||
(mode->flags & GS_CAN_MODE_LISTEN_ONLY) != 0,
|
|
||||||
(mode->flags & GS_CAN_MODE_ONE_SHOT) != 0
|
|
||||||
// triple sampling not supported on bxCAN
|
|
||||||
);
|
|
||||||
|
|
||||||
led_set_mode(&channel->leds, LED_MODE_NORMAL);
|
led_set_mode(&channel->leds, LED_MODE_NORMAL);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user