diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2025-01-14 15:57:01 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2025-02-02 18:43:34 -0500 |
commit | 9fd415d3f55e4be7e0b0b49a0b65cd8c174e01da (patch) | |
tree | 9a8f372292f3d507be08d5381f8b168dcad68aad /src/rp2040 | |
parent | b7366ae3fc57d3d50542ac297c41db76217a9094 (diff) | |
download | kutter-9fd415d3f55e4be7e0b0b49a0b65cd8c174e01da.tar.gz kutter-9fd415d3f55e4be7e0b0b49a0b65cd8c174e01da.tar.xz kutter-9fd415d3f55e4be7e0b0b49a0b65cd8c174e01da.zip |
rp2040: Add support for reporting canbus state
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/rp2040')
-rw-r--r-- | src/rp2040/can.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/rp2040/can.c b/src/rp2040/can.c index 1f4c281e..0e62ac3b 100644 --- a/src/rp2040/can.c +++ b/src/rp2040/can.c @@ -1,6 +1,6 @@ // Serial over CAN emulation for rp2040 using can2040 software canbus // -// Copyright (C) 2022 Kevin O'Connor <kevin@koconnor.net> +// Copyright (C) 2022-2025 Kevin O'Connor <kevin@koconnor.net> // // This file may be distributed under the terms of the GNU GPLv3 license. @@ -41,6 +41,23 @@ canhw_set_filter(uint32_t id) // Filter not implemented (and not necessary) } +static uint32_t last_tx_retries; + +// Report interface status +void +canhw_get_status(struct canbus_status *status) +{ + struct can2040_stats stats; + can2040_get_statistics(&cbus, &stats); + uint32_t tx_extra = stats.tx_attempt - stats.tx_total; + if (last_tx_retries != tx_extra) + last_tx_retries = tx_extra - 1; + + status->rx_error = stats.parse_error; + status->tx_retries = last_tx_retries; + status->bus_state = CANBUS_STATE_ACTIVE; +} + // can2040 callback function - handle rx and tx notifications static void can2040_cb(struct can2040 *cd, uint32_t notify, struct can2040_msg *msg) |