Skip to content

Commit fcf7c6e

Browse files
henrikbrixandersenfabiobaltieri
authored andcommitted
drivers: can: mcux: flexcan: assume can_send() always provides callback
Given the recent change to the CAN controller can_send() API wrapper, assume that a callback is always provided at the driver level. This saves approximately 500 bytes of SRAM on the frdm_k64f board, while on the mimxrt1024_evk board the saving is approximately 2.5 kbytes of SRAM, both when running in default configuration. Signed-off-by: Henrik Brix Andersen <[email protected]>
1 parent d6fc3f6 commit fcf7c6e

File tree

1 file changed

+4
-24
lines changed

1 file changed

+4
-24
lines changed

drivers/can/can_mcux_flexcan.c

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ struct mcux_flexcan_rx_callback {
104104
};
105105

106106
struct mcux_flexcan_tx_callback {
107-
struct k_sem done;
108-
int status;
109107
flexcan_frame_t frame;
110108
can_tx_callback_t function;
111109
void *arg;
@@ -408,6 +406,8 @@ static int mcux_flexcan_send(const struct device *dev,
408406
status_t status;
409407
int alloc;
410408

409+
__ASSERT_NO_MSG(callback != NULL);
410+
411411
if (frame->dlc > CAN_MAX_DLC) {
412412
LOG_ERR("DLC of %d exceeds maximum (%d)", frame->dlc, CAN_MAX_DLC);
413413
return -EINVAL;
@@ -445,11 +445,6 @@ static int mcux_flexcan_send(const struct device *dev,
445445
return -EIO;
446446
}
447447

448-
if (callback == NULL) {
449-
k_sem_take(&data->tx_cbs[alloc].done, K_FOREVER);
450-
return data->tx_cbs[alloc].status;
451-
}
452-
453448
return 0;
454449
}
455450

@@ -647,13 +642,8 @@ static inline void mcux_flexcan_transfer_error_status(const struct device *dev,
647642
if (atomic_test_and_clear_bit(data->tx_allocs, alloc)) {
648643
FLEXCAN_TransferAbortSend(config->base, &data->handle,
649644
ALLOC_IDX_TO_TXMB_IDX(alloc));
650-
if (function != NULL) {
651-
function(dev, -ENETUNREACH, arg);
652-
} else {
653-
data->tx_cbs[alloc].status = -ENETUNREACH;
654-
k_sem_give(&data->tx_cbs[alloc].done);
655-
}
656645

646+
function(dev, -ENETUNREACH, arg);
657647
k_sem_give(&data->tx_allocs_sem);
658648
}
659649
}
@@ -675,12 +665,7 @@ static inline void mcux_flexcan_transfer_tx_idle(const struct device *dev,
675665
arg = data->tx_cbs[alloc].arg;
676666

677667
if (atomic_test_and_clear_bit(data->tx_allocs, alloc)) {
678-
if (function != NULL) {
679-
function(dev, 0, arg);
680-
} else {
681-
data->tx_cbs[alloc].status = 0;
682-
k_sem_give(&data->tx_cbs[alloc].done);
683-
}
668+
function(dev, 0, arg);
684669
k_sem_give(&data->tx_allocs_sem);
685670
}
686671
}
@@ -774,7 +759,6 @@ static int mcux_flexcan_init(const struct device *dev)
774759
flexcan_config_t flexcan_config;
775760
uint32_t clock_freq;
776761
int err;
777-
int i;
778762

779763
if (config->phy != NULL) {
780764
if (!device_is_ready(config->phy)) {
@@ -792,10 +776,6 @@ static int mcux_flexcan_init(const struct device *dev)
792776
k_sem_init(&data->tx_allocs_sem, MCUX_FLEXCAN_MAX_TX,
793777
MCUX_FLEXCAN_MAX_TX);
794778

795-
for (i = 0; i < ARRAY_SIZE(data->tx_cbs); i++) {
796-
k_sem_init(&data->tx_cbs[i].done, 0, 1);
797-
}
798-
799779
data->timing.sjw = config->sjw;
800780
if (config->sample_point && USE_SP_ALGO) {
801781
err = can_calc_timing(dev, &data->timing, config->bitrate,

0 commit comments

Comments
 (0)