Bouncer

A sensor gateway on a busy CAN bus needs to pick out only the messages from its own subsystem. A colleague wrote the receive loop and a software mask filter, but the gateway either hangs waiting for frames or lets the wrong traffic through.

The firmware initializes CAN1 with an accept-all hardware filter, receives five frames from FIFO 0, and applies a software mask check to decide which ones to forward over UART.

Filter rule: with FILTER_ID = 0x100 and FILTER_MASK = 0x7F0, a frame is accepted when bits 10 through 4 of its ID match those of FILTER_ID. The lower four bits are don't-care, so IDs 0x100 through 0x10F pass.

Each accepted frame prints one line in the form ACCEPTED:0x<ID> DLC:<byte count> DATA:<payload bytes in hex>, in arrival order, and DONE is printed after the fifth frame has been processed. Rejected frames print nothing.

Find and fix all the bugs so the filter correctly accepts only matching frames.

Loading the interactive arena.