From 8b7701ed93ac19ac386c4de460e1c3424a260262 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Mon, 27 Oct 2025 16:49:02 -0400 Subject: handle ID Control frames (wip) --- fw/tests/system/can_echo_systest.c | 48 ++++++++++++++++++++------------------ fw/tests/system/can_tx_systest.c | 2 +- 2 files changed, 26 insertions(+), 24 deletions(-) (limited to 'fw/tests') diff --git a/fw/tests/system/can_echo_systest.c b/fw/tests/system/can_echo_systest.c index 798e45f..f0e08d2 100644 --- a/fw/tests/system/can_echo_systest.c +++ b/fw/tests/system/can_echo_systest.c @@ -1,4 +1,4 @@ -/* Listen for a standard DATA FRAME with ID 123h; +/* Listen for a frame with ID 123h or 1234567h; * echo it back with each byte of the DATA FIELD incremented by 1. */ @@ -12,6 +12,19 @@ #include "spi.h" #include "can.h" +static const CanId mask0 = { + .isExt = true, + .eid = {0xFF, 0xFF, 0xFF, 0x1F}}; +static const CanId filter0 = { + .isExt = true, + .eid = {0x67, 0x45, 0x23, 0x01}}; // 1234567h +static const CanId mask1 = { + .isExt = false, + .sid = {.lo = 0xFF, .hi = 0x7}}; +static const CanId filter2 = { + .isExt = false, + .sid = {.lo = 0x23, .hi = 0x1}}; // 123h + void main(void) { sysInit(); @@ -20,20 +33,11 @@ main(void) { // Setup MCP2515 CAN controller canSetBitTiming(CAN_TIMING_10K); - CanId id = { - .type=CAN_ID_STD, - .sid = {0xFF, 0xFF}, - }; - canSetMask0(&id); // set masks - canSetMask1(&id); - canSetFilter1(&id); // set unused filters - canSetFilter2(&id); - canSetFilter3(&id); - canSetFilter4(&id); - canSetFilter5(&id); - id.sid = (U16){0x01, 0x23}; // listen for message on filter 0 - canSetFilter0(&id); - canIE(true); // enable interrupts on INT pin + canSetMask0(&mask0); // RXB0 + canSetFilter0(&filter0); + canSetMask1(&mask1); // RXB1 + canSetFilter2(&filter2); + canIE(true); // enable interrupts on MCP2515's INT pin canSetMode(CAN_MODE_NORMAL); // Enable interrupts @@ -62,24 +66,22 @@ echo(CanFrame *frame) { void __interrupt() isr(void) { - U8 status; CanFrame frame; if (INTCONbits.INTF) { - status = canRxStatus(); - switch (status & 0x7) { // check filter match + switch (canRxStatus() & 0x7) { // check filter match case 0u: // RXF0 canReadRxb0(&frame); echo(&frame); break; - case 1u: // RXF1 - canReadRxb0(&frame); // clear interrupt flag + case 2u: // RXF2 + canReadRxb1(&frame); + echo(&frame); break; default: - // Message in RXB1 - canReadRxb1(&frame); // clear interrupt flag + canReadRxb0(&frame); // clear interrupt flag + canReadRxb1(&frame); } - INTCONbits.INTF = 0; } } diff --git a/fw/tests/system/can_tx_systest.c b/fw/tests/system/can_tx_systest.c index ef1d7b0..f6651c6 100644 --- a/fw/tests/system/can_tx_systest.c +++ b/fw/tests/system/can_tx_systest.c @@ -13,7 +13,7 @@ // Frame to transmit periodically static const CanFrame frame = { .id = { - .type = CAN_ID_STD, + .isExt = false, .sid = {0x01, 0x23}, }, .rtr = false, -- cgit v1.2.3