diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2022-06-08 21:03:11 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2022-06-27 10:50:23 -0400 |
commit | 790ff4d8d7ac200527c272af3e58f0d9f06468e4 (patch) | |
tree | b021c1ec8517f6b16950394ca9aef91dcff7dc7d /src/generic/canserial.c | |
parent | c8cc98ce5dce3771cf2728eee7b1bdb026504f75 (diff) | |
download | kutter-790ff4d8d7ac200527c272af3e58f0d9f06468e4.tar.gz kutter-790ff4d8d7ac200527c272af3e58f0d9f06468e4.tar.xz kutter-790ff4d8d7ac200527c272af3e58f0d9f06468e4.zip |
usb_canbus: Initial support for USB to CAN bridge mode
Support a USB interface that shows up as a canbus adapter to linux.
Route both local and real canbus packets over that interface.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/generic/canserial.c')
-rw-r--r-- | src/generic/canserial.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/generic/canserial.c b/src/generic/canserial.c index ba0ec461..34f0ce65 100644 --- a/src/generic/canserial.c +++ b/src/generic/canserial.c @@ -224,7 +224,7 @@ canserial_notify_rx(void) DECL_CONSTANT("RECEIVE_WINDOW", ARRAY_SIZE(CanData.receive_buf)); // Handle incoming data (called from IRQ handler) -void +int canserial_process_data(struct canbus_msg *msg) { uint32_t id = msg->id; @@ -233,7 +233,7 @@ canserial_process_data(struct canbus_msg *msg) int rpos = CanData.receive_pos; uint32_t len = CANMSG_DATA_LEN(msg); if (len > sizeof(CanData.receive_buf) - rpos) - len = sizeof(CanData.receive_buf) - rpos; + return -1; memcpy(&CanData.receive_buf[rpos], msg->data, len); CanData.receive_pos = rpos + len; canserial_notify_rx(); @@ -243,12 +243,13 @@ canserial_process_data(struct canbus_msg *msg) uint32_t pushp = CanData.admin_push_pos; if (pushp >= CanData.admin_pull_pos + ARRAY_SIZE(CanData.admin_queue)) // No space - drop message - return; + return -1; uint32_t pos = pushp % ARRAY_SIZE(CanData.admin_queue); memcpy(&CanData.admin_queue[pos], msg, sizeof(*msg)); CanData.admin_push_pos = pushp + 1; canserial_notify_rx(); } + return 0; } // Remove from the receive buffer the given number of bytes |