Lines Matching +full:timestamp +full:- +full:prescaler

4  * SPDX-License-Identifier: Apache-2.0
47 #define MCUX_FLEXCAN_MAX_TX (MCUX_FLEXCAN_MAX_MB - MCUX_FLEXCAN_MAX_RX)
60 #define TX_MBIDX_TO_ALLOC_IDX(x) (x - MCUX_FLEXCAN_MAX_RX)
124 const struct mcux_flexcan_config *config = dev->config; in mcux_flexcan_get_core_clock()
126 return clock_control_get_rate(config->clock_dev, config->clock_subsys, rate); in mcux_flexcan_get_core_clock()
139 struct mcux_flexcan_data *data = dev->data; in mcux_flexcan_set_timing()
142 return -EINVAL; in mcux_flexcan_set_timing()
145 if (data->common.started) { in mcux_flexcan_set_timing()
146 return -EBUSY; in mcux_flexcan_set_timing()
149 data->timing = *timing; in mcux_flexcan_set_timing()
158 struct mcux_flexcan_data *data = dev->data; in mcux_flexcan_set_timing_data()
161 return -EINVAL; in mcux_flexcan_set_timing_data()
164 if (data->common.started) { in mcux_flexcan_set_timing_data()
165 return -EBUSY; in mcux_flexcan_set_timing_data()
168 data->timing_data = *timing_data; in mcux_flexcan_set_timing_data()
176 __maybe_unused const struct mcux_flexcan_config *config = dev->config; in mcux_flexcan_get_capabilities()
184 if (UTIL_AND(IS_ENABLED(CONFIG_CAN_MCUX_FLEXCAN_FD), config->flexcan_fd)) { in mcux_flexcan_get_capabilities()
193 const struct mcux_flexcan_config *config = dev->config; in mcux_flexcan_mb_start()
194 struct mcux_flexcan_data *data = dev->data; in mcux_flexcan_mb_start()
198 __ASSERT_NO_MSG(alloc >= 0 && alloc < ARRAY_SIZE(data->rx_cbs)); in mcux_flexcan_mb_start()
203 if ((data->common.mode & CAN_MODE_FD) != 0U) { in mcux_flexcan_mb_start()
204 xfer.framefd = &data->rx_cbs[alloc].frame.fd; in mcux_flexcan_mb_start()
205 FLEXCAN_SetFDRxMbConfig(config->base, ALLOC_IDX_TO_RXMB_IDX(alloc), in mcux_flexcan_mb_start()
206 &data->rx_cbs[alloc].mb_config, true); in mcux_flexcan_mb_start()
207 status = FLEXCAN_TransferFDReceiveNonBlocking(config->base, &data->handle, &xfer); in mcux_flexcan_mb_start()
210 xfer.frame = &data->rx_cbs[alloc].frame.classic; in mcux_flexcan_mb_start()
211 FLEXCAN_SetRxMbConfig(config->base, ALLOC_IDX_TO_RXMB_IDX(alloc), in mcux_flexcan_mb_start()
212 &data->rx_cbs[alloc].mb_config, true); in mcux_flexcan_mb_start()
213 status = FLEXCAN_TransferReceiveNonBlocking(config->base, &data->handle, &xfer); in mcux_flexcan_mb_start()
223 const struct mcux_flexcan_config *config = dev->config; in mcux_flexcan_mb_stop()
224 struct mcux_flexcan_data *data = dev->data; in mcux_flexcan_mb_stop()
226 __ASSERT_NO_MSG(alloc >= 0 && alloc < ARRAY_SIZE(data->rx_cbs)); in mcux_flexcan_mb_stop()
229 if ((data->common.mode & CAN_MODE_FD) != 0U) { in mcux_flexcan_mb_stop()
230 FLEXCAN_TransferFDAbortReceive(config->base, &data->handle, in mcux_flexcan_mb_stop()
232 FLEXCAN_SetFDRxMbConfig(config->base, ALLOC_IDX_TO_RXMB_IDX(alloc), in mcux_flexcan_mb_stop()
236 FLEXCAN_TransferAbortReceive(config->base, &data->handle, in mcux_flexcan_mb_stop()
238 FLEXCAN_SetRxMbConfig(config->base, ALLOC_IDX_TO_RXMB_IDX(alloc), in mcux_flexcan_mb_stop()
247 const struct mcux_flexcan_config *config = dev->config; in mcux_flexcan_start()
248 struct mcux_flexcan_data *data = dev->data; in mcux_flexcan_start()
252 if (data->common.started) { in mcux_flexcan_start()
253 return -EALREADY; in mcux_flexcan_start()
256 if (config->common.phy != NULL) { in mcux_flexcan_start()
257 err = can_transceiver_enable(config->common.phy, data->common.mode); in mcux_flexcan_start()
266 config->base->ECR &= ~(CAN_ECR_TXERRCNT_MASK | CAN_ECR_RXERRCNT_MASK); in mcux_flexcan_start()
272 if (config->flexcan_fd) { in mcux_flexcan_start()
273 /* Re-add all RX filters using current mode */ in mcux_flexcan_start()
274 k_mutex_lock(&data->rx_mutex, K_FOREVER); in mcux_flexcan_start()
277 if (atomic_test_bit(data->rx_allocs, alloc)) { in mcux_flexcan_start()
280 LOG_ERR("Failed to re-add rx filter id %d (err = %d)", in mcux_flexcan_start()
282 k_mutex_unlock(&data->rx_mutex); in mcux_flexcan_start()
283 return -EIO; in mcux_flexcan_start()
288 k_mutex_unlock(&data->rx_mutex); in mcux_flexcan_start()
293 timing.preDivider = data->timing.prescaler - 1U; in mcux_flexcan_start()
294 timing.rJumpwidth = data->timing.sjw - 1U; in mcux_flexcan_start()
295 timing.phaseSeg1 = data->timing.phase_seg1 - 1U; in mcux_flexcan_start()
296 timing.phaseSeg2 = data->timing.phase_seg2 - 1U; in mcux_flexcan_start()
297 timing.propSeg = data->timing.prop_seg - 1U; in mcux_flexcan_start()
298 FLEXCAN_SetTimingConfig(config->base, &timing); in mcux_flexcan_start()
301 if (config->flexcan_fd) { in mcux_flexcan_start()
302 timing.fpreDivider = data->timing_data.prescaler - 1U; in mcux_flexcan_start()
303 timing.frJumpwidth = data->timing_data.sjw - 1U; in mcux_flexcan_start()
304 timing.fphaseSeg1 = data->timing_data.phase_seg1 - 1U; in mcux_flexcan_start()
305 timing.fphaseSeg2 = data->timing_data.phase_seg2 - 1U; in mcux_flexcan_start()
306 timing.fpropSeg = data->timing_data.prop_seg; in mcux_flexcan_start()
307 FLEXCAN_SetFDTimingConfig(config->base, &timing); in mcux_flexcan_start()
309 FLEXCAN_EnterFreezeMode(config->base); in mcux_flexcan_start()
310 config->base->FDCTRL &= ~(CAN_FDCTRL_TDCOFF_MASK); in mcux_flexcan_start()
311 config->base->FDCTRL |= FIELD_PREP(CAN_FDCTRL_TDCOFF_MASK, in mcux_flexcan_start()
312 CAN_CALC_TDCO((&data->timing_data), 1U, 31U)); in mcux_flexcan_start()
313 FLEXCAN_ExitFreezeMode(config->base); in mcux_flexcan_start()
317 data->common.started = true; in mcux_flexcan_start()
324 const struct mcux_flexcan_config *config = dev->config; in mcux_flexcan_stop()
325 struct mcux_flexcan_data *data = dev->data; in mcux_flexcan_stop()
331 if (!data->common.started) { in mcux_flexcan_stop()
332 return -EALREADY; in mcux_flexcan_stop()
335 data->common.started = false; in mcux_flexcan_stop()
339 function = data->tx_cbs[alloc].function; in mcux_flexcan_stop()
340 arg = data->tx_cbs[alloc].arg; in mcux_flexcan_stop()
342 if (atomic_test_and_clear_bit(data->tx_allocs, alloc)) { in mcux_flexcan_stop()
344 if ((data->common.mode & CAN_MODE_FD) != 0U) { in mcux_flexcan_stop()
345 FLEXCAN_TransferFDAbortSend(config->base, &data->handle, in mcux_flexcan_stop()
349 FLEXCAN_TransferAbortSend(config->base, &data->handle, in mcux_flexcan_stop()
355 function(dev, -ENETDOWN, arg); in mcux_flexcan_stop()
356 k_sem_give(&data->tx_allocs_sem); in mcux_flexcan_stop()
360 FLEXCAN_EnterFreezeMode(config->base); in mcux_flexcan_stop()
362 if (UTIL_AND(IS_ENABLED(CONFIG_CAN_MCUX_FLEXCAN_FD), config->flexcan_fd)) { in mcux_flexcan_stop()
364 * Remove all RX filters and re-add them in start() since the mode may change in mcux_flexcan_stop()
367 k_mutex_lock(&data->rx_mutex, K_FOREVER); in mcux_flexcan_stop()
370 if (atomic_test_bit(data->rx_allocs, alloc)) { in mcux_flexcan_stop()
375 k_mutex_unlock(&data->rx_mutex); in mcux_flexcan_stop()
378 if (config->common.phy != NULL) { in mcux_flexcan_stop()
379 err = can_transceiver_disable(config->common.phy); in mcux_flexcan_stop()
392 const struct mcux_flexcan_config *config = dev->config; in mcux_flexcan_set_mode()
393 struct mcux_flexcan_data *data = dev->data; in mcux_flexcan_set_mode()
397 if (data->common.started) { in mcux_flexcan_set_mode()
398 return -EBUSY; in mcux_flexcan_set_mode()
405 if (UTIL_AND(IS_ENABLED(CONFIG_CAN_MCUX_FLEXCAN_FD), config->flexcan_fd)) { in mcux_flexcan_set_mode()
411 return -ENOTSUP; in mcux_flexcan_set_mode()
416 return -ENOTSUP; in mcux_flexcan_set_mode()
419 ctrl1 = config->base->CTRL1; in mcux_flexcan_set_mode()
420 mcr = config->base->MCR; in mcux_flexcan_set_mode()
423 /* Enable loopback and self-reception */ in mcux_flexcan_set_mode()
427 /* Disable loopback and self-reception */ in mcux_flexcan_set_mode()
433 /* Enable listen-only mode */ in mcux_flexcan_set_mode()
436 /* Disable listen-only mode */ in mcux_flexcan_set_mode()
450 /* Disable auto-recovery from bus-off */ in mcux_flexcan_set_mode()
453 /* Enable auto-recovery from bus-off */ in mcux_flexcan_set_mode()
459 if (config->flexcan_fd) { in mcux_flexcan_set_mode()
466 config->base->FDCTRL &= ~(CAN_FDCTRL_TDCEN_MASK); in mcux_flexcan_set_mode()
468 config->base->FDCTRL |= CAN_FDCTRL_TDCEN_MASK; in mcux_flexcan_set_mode()
477 config->base->CTRL1 = ctrl1; in mcux_flexcan_set_mode()
478 config->base->MCR = mcr; in mcux_flexcan_set_mode()
480 data->common.mode = mode; in mcux_flexcan_set_mode()
490 if ((src->flags & CAN_FRAME_IDE) != 0) { in mcux_flexcan_from_can_frame()
491 dest->format = kFLEXCAN_FrameFormatExtend; in mcux_flexcan_from_can_frame()
492 dest->id = FLEXCAN_ID_EXT(src->id); in mcux_flexcan_from_can_frame()
494 dest->format = kFLEXCAN_FrameFormatStandard; in mcux_flexcan_from_can_frame()
495 dest->id = FLEXCAN_ID_STD(src->id); in mcux_flexcan_from_can_frame()
498 if ((src->flags & CAN_FRAME_RTR) != 0) { in mcux_flexcan_from_can_frame()
499 dest->type = kFLEXCAN_FrameTypeRemote; in mcux_flexcan_from_can_frame()
501 dest->type = kFLEXCAN_FrameTypeData; in mcux_flexcan_from_can_frame()
502 dest->dataWord0 = sys_cpu_to_be32(src->data_32[0]); in mcux_flexcan_from_can_frame()
503 dest->dataWord1 = sys_cpu_to_be32(src->data_32[1]); in mcux_flexcan_from_can_frame()
506 dest->length = src->dlc; in mcux_flexcan_from_can_frame()
514 if (src->format == kFLEXCAN_FrameFormatStandard) { in mcux_flexcan_to_can_frame()
515 dest->id = FLEXCAN_ID_TO_CAN_ID_STD(src->id); in mcux_flexcan_to_can_frame()
517 dest->flags |= CAN_FRAME_IDE; in mcux_flexcan_to_can_frame()
518 dest->id = FLEXCAN_ID_TO_CAN_ID_EXT(src->id); in mcux_flexcan_to_can_frame()
521 if (src->type == kFLEXCAN_FrameTypeRemote) { in mcux_flexcan_to_can_frame()
522 dest->flags |= CAN_FRAME_RTR; in mcux_flexcan_to_can_frame()
524 dest->data_32[0] = sys_be32_to_cpu(src->dataWord0); in mcux_flexcan_to_can_frame()
525 dest->data_32[1] = sys_be32_to_cpu(src->dataWord1); in mcux_flexcan_to_can_frame()
528 dest->dlc = src->length; in mcux_flexcan_to_can_frame()
530 dest->timestamp = src->timestamp; in mcux_flexcan_to_can_frame()
542 if ((src->flags & CAN_FRAME_IDE) != 0) { in mcux_flexcan_fd_from_can_frame()
543 dest->format = kFLEXCAN_FrameFormatExtend; in mcux_flexcan_fd_from_can_frame()
544 dest->id = FLEXCAN_ID_EXT(src->id); in mcux_flexcan_fd_from_can_frame()
546 dest->format = kFLEXCAN_FrameFormatStandard; in mcux_flexcan_fd_from_can_frame()
547 dest->id = FLEXCAN_ID_STD(src->id); in mcux_flexcan_fd_from_can_frame()
550 if ((src->flags & CAN_FRAME_RTR) != 0) { in mcux_flexcan_fd_from_can_frame()
551 dest->type = kFLEXCAN_FrameTypeRemote; in mcux_flexcan_fd_from_can_frame()
553 dest->type = kFLEXCAN_FrameTypeData; in mcux_flexcan_fd_from_can_frame()
555 for (i = 0; i < ARRAY_SIZE(dest->dataWord); i++) { in mcux_flexcan_fd_from_can_frame()
556 dest->dataWord[i] = sys_cpu_to_be32(src->data_32[i]); in mcux_flexcan_fd_from_can_frame()
560 if ((src->flags & CAN_FRAME_FDF) != 0) { in mcux_flexcan_fd_from_can_frame()
561 dest->edl = 1; in mcux_flexcan_fd_from_can_frame()
564 if ((src->flags & CAN_FRAME_BRS) != 0) { in mcux_flexcan_fd_from_can_frame()
565 dest->brs = 1; in mcux_flexcan_fd_from_can_frame()
568 dest->length = src->dlc; in mcux_flexcan_fd_from_can_frame()
578 if (src->format == kFLEXCAN_FrameFormatStandard) { in mcux_flexcan_fd_to_can_frame()
579 dest->id = FLEXCAN_ID_TO_CAN_ID_STD(src->id); in mcux_flexcan_fd_to_can_frame()
581 dest->flags |= CAN_FRAME_IDE; in mcux_flexcan_fd_to_can_frame()
582 dest->id = FLEXCAN_ID_TO_CAN_ID_EXT(src->id); in mcux_flexcan_fd_to_can_frame()
585 if (src->type == kFLEXCAN_FrameTypeRemote) { in mcux_flexcan_fd_to_can_frame()
586 dest->flags |= CAN_FRAME_RTR; in mcux_flexcan_fd_to_can_frame()
588 for (i = 0; i < ARRAY_SIZE(dest->data_32); i++) { in mcux_flexcan_fd_to_can_frame()
589 dest->data_32[i] = sys_be32_to_cpu(src->dataWord[i]); in mcux_flexcan_fd_to_can_frame()
593 if (src->edl != 0) { in mcux_flexcan_fd_to_can_frame()
594 dest->flags |= CAN_FRAME_FDF; in mcux_flexcan_fd_to_can_frame()
597 if (src->brs != 0) { in mcux_flexcan_fd_to_can_frame()
598 dest->flags |= CAN_FRAME_BRS; in mcux_flexcan_fd_to_can_frame()
601 if (src->esi != 0) { in mcux_flexcan_fd_to_can_frame()
602 dest->flags |= CAN_FRAME_ESI; in mcux_flexcan_fd_to_can_frame()
605 dest->dlc = src->length; in mcux_flexcan_fd_to_can_frame()
608 dest->timestamp = src->timestamp; in mcux_flexcan_fd_to_can_frame()
620 if ((src->flags & CAN_FILTER_IDE) != 0) { in mcux_flexcan_can_filter_to_mbconfig()
621 dest->format = kFLEXCAN_FrameFormatExtend; in mcux_flexcan_can_filter_to_mbconfig()
622 dest->id = FLEXCAN_ID_EXT(src->id); in mcux_flexcan_can_filter_to_mbconfig()
623 *mask = FLEXCAN_RX_MB_EXT_MASK(src->mask, rtr_mask, ide_mask); in mcux_flexcan_can_filter_to_mbconfig()
625 dest->format = kFLEXCAN_FrameFormatStandard; in mcux_flexcan_can_filter_to_mbconfig()
626 dest->id = FLEXCAN_ID_STD(src->id); in mcux_flexcan_can_filter_to_mbconfig()
627 *mask = FLEXCAN_RX_MB_STD_MASK(src->mask, rtr_mask, ide_mask); in mcux_flexcan_can_filter_to_mbconfig()
630 dest->type = kFLEXCAN_FrameTypeData; in mcux_flexcan_can_filter_to_mbconfig()
636 const struct mcux_flexcan_config *config = dev->config; in mcux_flexcan_get_state()
637 struct mcux_flexcan_data *data = dev->data; in mcux_flexcan_get_state()
641 if (!data->common.started) { in mcux_flexcan_get_state()
644 status_flags = FLEXCAN_GetStatusFlags(config->base); in mcux_flexcan_get_state()
660 FLEXCAN_GetBusErrCount(config->base, &err_cnt->tx_err_cnt, in mcux_flexcan_get_state()
661 &err_cnt->rx_err_cnt); in mcux_flexcan_get_state()
672 const struct mcux_flexcan_config *config = dev->config; in mcux_flexcan_send()
673 struct mcux_flexcan_data *data = dev->data; in mcux_flexcan_send()
681 ((data->common.mode & CAN_MODE_FD) != 0U))) { in mcux_flexcan_send()
682 if ((frame->flags & ~(CAN_FRAME_IDE | CAN_FRAME_RTR | in mcux_flexcan_send()
684 LOG_ERR("unsupported CAN frame flags 0x%02x", frame->flags); in mcux_flexcan_send()
685 return -ENOTSUP; in mcux_flexcan_send()
688 if ((frame->flags & CAN_FRAME_FDF) != 0) { in mcux_flexcan_send()
692 if ((frame->flags & ~(CAN_FRAME_IDE | CAN_FRAME_RTR)) != 0) { in mcux_flexcan_send()
693 LOG_ERR("unsupported CAN frame flags 0x%02x", frame->flags); in mcux_flexcan_send()
694 return -ENOTSUP; in mcux_flexcan_send()
698 if (frame->dlc > max_dlc) { in mcux_flexcan_send()
699 LOG_ERR("DLC of %d exceeds maximum (%d)", frame->dlc, max_dlc); in mcux_flexcan_send()
700 return -EINVAL; in mcux_flexcan_send()
703 if (!data->common.started) { in mcux_flexcan_send()
704 return -ENETDOWN; in mcux_flexcan_send()
709 LOG_DBG("Transmit failed, bus-off"); in mcux_flexcan_send()
710 return -ENETUNREACH; in mcux_flexcan_send()
713 if (k_sem_take(&data->tx_allocs_sem, timeout) != 0) { in mcux_flexcan_send()
714 return -EAGAIN; in mcux_flexcan_send()
718 if (!atomic_test_and_set_bit(data->tx_allocs, alloc)) { in mcux_flexcan_send()
723 data->tx_cbs[alloc].function = callback; in mcux_flexcan_send()
724 data->tx_cbs[alloc].arg = user_data; in mcux_flexcan_send()
728 if ((data->common.mode & CAN_MODE_FD) != 0U) { in mcux_flexcan_send()
729 FLEXCAN_SetFDTxMbConfig(config->base, xfer.mbIdx, true); in mcux_flexcan_send()
732 FLEXCAN_SetTxMbConfig(config->base, xfer.mbIdx, true); in mcux_flexcan_send()
737 k_mutex_lock(&data->tx_mutex, K_FOREVER); in mcux_flexcan_send()
738 config->irq_disable_func(); in mcux_flexcan_send()
741 if ((data->common.mode & CAN_MODE_FD) != 0U) { in mcux_flexcan_send()
746 status = FLEXCAN_TransferFDSendNonBlocking(config->base, &data->handle, &xfer); in mcux_flexcan_send()
753 status = FLEXCAN_TransferSendNonBlocking(config->base, &data->handle, &xfer); in mcux_flexcan_send()
758 config->irq_enable_func(); in mcux_flexcan_send()
759 k_mutex_unlock(&data->tx_mutex); in mcux_flexcan_send()
761 return -EIO; in mcux_flexcan_send()
772 const struct mcux_flexcan_config *config = dev->config; in mcux_flexcan_add_rx_filter()
773 struct mcux_flexcan_data *data = dev->data; in mcux_flexcan_add_rx_filter()
776 int alloc = -ENOSPC; in mcux_flexcan_add_rx_filter()
779 if ((filter->flags & ~(CAN_FILTER_IDE)) != 0) { in mcux_flexcan_add_rx_filter()
780 LOG_ERR("unsupported CAN filter flags 0x%02x", filter->flags); in mcux_flexcan_add_rx_filter()
781 return -ENOTSUP; in mcux_flexcan_add_rx_filter()
784 k_mutex_lock(&data->rx_mutex, K_FOREVER); in mcux_flexcan_add_rx_filter()
788 if (!atomic_test_and_set_bit(data->rx_allocs, i)) { in mcux_flexcan_add_rx_filter()
794 if (alloc == -ENOSPC) { in mcux_flexcan_add_rx_filter()
798 mcux_flexcan_can_filter_to_mbconfig(filter, &data->rx_cbs[alloc].mb_config, in mcux_flexcan_add_rx_filter()
801 data->rx_cbs[alloc].arg = user_data; in mcux_flexcan_add_rx_filter()
802 data->rx_cbs[alloc].function = callback; in mcux_flexcan_add_rx_filter()
805 FLEXCAN_EnterFreezeMode(config->base); in mcux_flexcan_add_rx_filter()
806 config->base->RXIMR[ALLOC_IDX_TO_RXMB_IDX(alloc)] = mask; in mcux_flexcan_add_rx_filter()
808 if (data->common.started) { in mcux_flexcan_add_rx_filter()
809 FLEXCAN_ExitFreezeMode(config->base); in mcux_flexcan_add_rx_filter()
814 if (!config->flexcan_fd || data->common.started) { in mcux_flexcan_add_rx_filter()
820 alloc = -ENOSPC; in mcux_flexcan_add_rx_filter()
827 k_mutex_unlock(&data->rx_mutex); in mcux_flexcan_add_rx_filter()
836 struct mcux_flexcan_data *data = dev->data; in mcux_flexcan_set_state_change_callback()
838 data->common.state_change_cb = callback; in mcux_flexcan_set_state_change_callback()
839 data->common.state_change_cb_user_data = user_data; in mcux_flexcan_set_state_change_callback()
845 const struct mcux_flexcan_config *config = dev->config; in mcux_flexcan_recover()
846 struct mcux_flexcan_data *data = dev->data; in mcux_flexcan_recover()
851 if (!data->common.started) { in mcux_flexcan_recover()
852 return -ENETDOWN; in mcux_flexcan_recover()
855 if ((data->common.mode & CAN_MODE_MANUAL_RECOVERY) == 0U) { in mcux_flexcan_recover()
856 return -ENOTSUP; in mcux_flexcan_recover()
865 config->base->CTRL1 &= ~CAN_CTRL1_BOFFREC_MASK; in mcux_flexcan_recover()
872 k_uptime_ticks() - start_time >= timeout.ticks) { in mcux_flexcan_recover()
873 ret = -EAGAIN; in mcux_flexcan_recover()
880 config->base->CTRL1 |= CAN_CTRL1_BOFFREC_MASK; in mcux_flexcan_recover()
888 struct mcux_flexcan_data *data = dev->data; in mcux_flexcan_remove_rx_filter()
895 k_mutex_lock(&data->rx_mutex, K_FOREVER); in mcux_flexcan_remove_rx_filter()
897 if (atomic_test_and_clear_bit(data->rx_allocs, filter_id)) { in mcux_flexcan_remove_rx_filter()
899 const struct mcux_flexcan_config *config = dev->config; in mcux_flexcan_remove_rx_filter()
902 if (!config->flexcan_fd || data->common.started) { in mcux_flexcan_remove_rx_filter()
909 data->rx_cbs[filter_id].function = NULL; in mcux_flexcan_remove_rx_filter()
910 data->rx_cbs[filter_id].arg = NULL; in mcux_flexcan_remove_rx_filter()
915 k_mutex_unlock(&data->rx_mutex); in mcux_flexcan_remove_rx_filter()
921 const struct mcux_flexcan_config *config = dev->config; in mcux_flexcan_transfer_error_status()
922 struct mcux_flexcan_data *data = dev->data; in mcux_flexcan_transfer_error_status()
923 const can_state_change_callback_t cb = data->common.state_change_cb; in mcux_flexcan_transfer_error_status()
924 void *cb_data = data->common.state_change_cb_user_data; in mcux_flexcan_transfer_error_status()
956 if (data->state != state) { in mcux_flexcan_transfer_error_status()
957 data->state = state; in mcux_flexcan_transfer_error_status()
965 /* Abort any pending TX frames in case of bus-off */ in mcux_flexcan_transfer_error_status()
968 function = data->tx_cbs[alloc].function; in mcux_flexcan_transfer_error_status()
969 arg = data->tx_cbs[alloc].arg; in mcux_flexcan_transfer_error_status()
971 if (atomic_test_and_clear_bit(data->tx_allocs, alloc)) { in mcux_flexcan_transfer_error_status()
973 if ((data->common.mode & CAN_MODE_FD) != 0U) { in mcux_flexcan_transfer_error_status()
974 FLEXCAN_TransferFDAbortSend(config->base, &data->handle, in mcux_flexcan_transfer_error_status()
978 FLEXCAN_TransferAbortSend(config->base, &data->handle, in mcux_flexcan_transfer_error_status()
984 function(dev, -ENETUNREACH, arg); in mcux_flexcan_transfer_error_status()
985 k_sem_give(&data->tx_allocs_sem); in mcux_flexcan_transfer_error_status()
994 struct mcux_flexcan_data *data = dev->data; in mcux_flexcan_transfer_tx_idle()
1002 function = data->tx_cbs[alloc].function; in mcux_flexcan_transfer_tx_idle()
1003 arg = data->tx_cbs[alloc].arg; in mcux_flexcan_transfer_tx_idle()
1005 if (atomic_test_and_clear_bit(data->tx_allocs, alloc)) { in mcux_flexcan_transfer_tx_idle()
1007 k_sem_give(&data->tx_allocs_sem); in mcux_flexcan_transfer_tx_idle()
1014 const struct mcux_flexcan_config *config = dev->config; in mcux_flexcan_transfer_rx_idle()
1015 struct mcux_flexcan_data *data = dev->data; in mcux_flexcan_transfer_rx_idle()
1024 function = data->rx_cbs[alloc].function; in mcux_flexcan_transfer_rx_idle()
1025 arg = data->rx_cbs[alloc].arg; in mcux_flexcan_transfer_rx_idle()
1027 if (atomic_test_bit(data->rx_allocs, alloc)) { in mcux_flexcan_transfer_rx_idle()
1029 if ((data->common.mode & CAN_MODE_FD) != 0U) { in mcux_flexcan_transfer_rx_idle()
1030 mcux_flexcan_fd_to_can_frame(&data->rx_cbs[alloc].frame.fd, &frame); in mcux_flexcan_transfer_rx_idle()
1033 mcux_flexcan_to_can_frame(&data->rx_cbs[alloc].frame.classic, &frame); in mcux_flexcan_transfer_rx_idle()
1042 if ((data->common.mode & CAN_MODE_FD) != 0U) { in mcux_flexcan_transfer_rx_idle()
1043 xfer.framefd = &data->rx_cbs[alloc].frame.fd; in mcux_flexcan_transfer_rx_idle()
1044 status = FLEXCAN_TransferFDReceiveNonBlocking(config->base, in mcux_flexcan_transfer_rx_idle()
1045 &data->handle, in mcux_flexcan_transfer_rx_idle()
1049 xfer.frame = &data->rx_cbs[alloc].frame.classic; in mcux_flexcan_transfer_rx_idle()
1050 status = FLEXCAN_TransferReceiveNonBlocking(config->base, in mcux_flexcan_transfer_rx_idle()
1051 &data->handle, in mcux_flexcan_transfer_rx_idle()
1067 const struct mcux_flexcan_config *config = data->dev->config; in FLEXCAN_CALLBACK()
1084 mcux_flexcan_transfer_error_status(data->dev, status_flags); in FLEXCAN_CALLBACK()
1088 if ((data->common.mode & CAN_MODE_FD) != 0U) { in FLEXCAN_CALLBACK()
1089 FLEXCAN_TransferFDAbortReceive(config->base, &data->handle, mb); in FLEXCAN_CALLBACK()
1092 FLEXCAN_TransferAbortReceive(config->base, &data->handle, mb); in FLEXCAN_CALLBACK()
1098 mcux_flexcan_transfer_tx_idle(data->dev, mb); in FLEXCAN_CALLBACK()
1101 CAN_STATS_RX_OVERRUN_INC(data->dev); in FLEXCAN_CALLBACK()
1107 mcux_flexcan_transfer_rx_idle(data->dev, mb); in FLEXCAN_CALLBACK()
1117 const struct mcux_flexcan_config *config = dev->config; in mcux_flexcan_isr()
1118 struct mcux_flexcan_data *data = dev->data; in mcux_flexcan_isr()
1120 FLEXCAN_TransferHandleIRQ(config->base, &data->handle); in mcux_flexcan_isr()
1125 const struct mcux_flexcan_config *config = dev->config; in mcux_flexcan_init()
1126 struct mcux_flexcan_data *data = dev->data; in mcux_flexcan_init()
1131 if (config->common.phy != NULL) { in mcux_flexcan_init()
1132 if (!device_is_ready(config->common.phy)) { in mcux_flexcan_init()
1134 return -ENODEV; in mcux_flexcan_init()
1138 if (!device_is_ready(config->clock_dev)) { in mcux_flexcan_init()
1140 return -ENODEV; in mcux_flexcan_init()
1143 k_mutex_init(&data->rx_mutex); in mcux_flexcan_init()
1144 k_mutex_init(&data->tx_mutex); in mcux_flexcan_init()
1145 k_sem_init(&data->tx_allocs_sem, MCUX_FLEXCAN_MAX_TX, in mcux_flexcan_init()
1148 err = can_calc_timing(dev, &data->timing, config->common.bitrate, in mcux_flexcan_init()
1149 config->common.sample_point); in mcux_flexcan_init()
1150 if (err == -EINVAL) { in mcux_flexcan_init()
1152 return -EIO; in mcux_flexcan_init()
1155 data->timing.prescaler, data->timing.phase_seg1, in mcux_flexcan_init()
1156 data->timing.phase_seg2); in mcux_flexcan_init()
1157 LOG_DBG("Sample-point err : %d", err); in mcux_flexcan_init()
1160 err = can_set_timing(dev, &data->timing); in mcux_flexcan_init()
1163 return -ENODEV; in mcux_flexcan_init()
1167 if (config->flexcan_fd) { in mcux_flexcan_init()
1168 err = can_calc_timing_data(dev, &data->timing_data, in mcux_flexcan_init()
1169 config->common.bitrate_data, in mcux_flexcan_init()
1170 config->common.sample_point_data); in mcux_flexcan_init()
1171 if (err == -EINVAL) { in mcux_flexcan_init()
1173 return -EIO; in mcux_flexcan_init()
1176 data->timing_data.prescaler, data->timing_data.phase_seg1, in mcux_flexcan_init()
1177 data->timing_data.phase_seg2); in mcux_flexcan_init()
1178 LOG_DBG("Sample-point err : %d", err); in mcux_flexcan_init()
1181 err = can_set_timing_data(dev, &data->timing_data); in mcux_flexcan_init()
1184 return -ENODEV; in mcux_flexcan_init()
1189 err = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT); in mcux_flexcan_init()
1196 return -EIO; in mcux_flexcan_init()
1199 data->dev = dev; in mcux_flexcan_init()
1203 flexcan_config.clkSrc = config->clk_source; in mcux_flexcan_init()
1205 (1U + data->timing.prop_seg + data->timing.phase_seg1 + in mcux_flexcan_init()
1206 data->timing.phase_seg2) / data->timing.prescaler; in mcux_flexcan_init()
1209 if (config->flexcan_fd) { in mcux_flexcan_init()
1211 (1U + data->timing_data.prop_seg + data->timing_data.phase_seg1 + in mcux_flexcan_init()
1212 data->timing_data.phase_seg2) / data->timing_data.prescaler; in mcux_flexcan_init()
1219 /* Initialize in listen-only mode since FLEXCAN_{FD}Init() exits freeze mode */ in mcux_flexcan_init()
1222 flexcan_config.timingConfig.rJumpwidth = data->timing.sjw - 1U; in mcux_flexcan_init()
1223 flexcan_config.timingConfig.propSeg = data->timing.prop_seg - 1U; in mcux_flexcan_init()
1224 flexcan_config.timingConfig.phaseSeg1 = data->timing.phase_seg1 - 1U; in mcux_flexcan_init()
1225 flexcan_config.timingConfig.phaseSeg2 = data->timing.phase_seg2 - 1U; in mcux_flexcan_init()
1228 if (config->flexcan_fd) { in mcux_flexcan_init()
1229 flexcan_config.timingConfig.frJumpwidth = data->timing_data.sjw - 1U; in mcux_flexcan_init()
1230 flexcan_config.timingConfig.fpropSeg = data->timing_data.prop_seg; in mcux_flexcan_init()
1231 flexcan_config.timingConfig.fphaseSeg1 = data->timing_data.phase_seg1 - 1U; in mcux_flexcan_init()
1232 flexcan_config.timingConfig.fphaseSeg2 = data->timing_data.phase_seg2 - 1U; in mcux_flexcan_init()
1234 FLEXCAN_FDInit(config->base, &flexcan_config, clock_freq, kFLEXCAN_64BperMB, true); in mcux_flexcan_init()
1237 FLEXCAN_Init(config->base, &flexcan_config, clock_freq); in mcux_flexcan_init()
1242 FLEXCAN_TransferCreateHandle(config->base, &data->handle, in mcux_flexcan_init()
1246 FLEXCAN_EnterFreezeMode(config->base); in mcux_flexcan_init()
1248 config->base->ECR &= ~(CAN_ECR_TXERRCNT_MASK | CAN_ECR_RXERRCNT_MASK); in mcux_flexcan_init()
1250 config->irq_config_func(dev); in mcux_flexcan_init()
1252 /* Enable auto-recovery from bus-off */ in mcux_flexcan_init()
1253 config->base->CTRL1 &= ~(CAN_CTRL1_BOFFREC_MASK); in mcux_flexcan_init()
1255 (void)mcux_flexcan_get_state(dev, &data->state, NULL); in mcux_flexcan_init()
1290 .prescaler = 0x01
1297 .prescaler = 0x100
1335 .prescaler = 0x01
1342 .prescaler = 0x400
1349 .prescaler = 0x01
1356 .prescaler = 0x400