OpenLcbCLib 1.0 Alpha
OpenSource C Library to create OpenLcb/Lcc Nodes
Loading...
Searching...
No Matches
can_rx_statemachine.h File Reference

State machine that decodes and routes incoming CAN frames. More...

Go to the source code of this file.

Data Structures

struct  interface_can_rx_statemachine_t
 Dependency-injection interface for the CAN receive state machine. More...
 

Functions

void CanRxStatemachine_initialize (const interface_can_rx_statemachine_t *interface_can_rx_statemachine)
 Registers the dependency-injection interface for this module.
 
void CanRxStatemachine_incoming_can_driver_callback (can_msg_t *can_msg)
 Primary entry point called by the hardware CAN driver on frame reception.
 

Detailed Description

State machine that decodes and routes incoming CAN frames.

Identifies frame category (OpenLCB message vs CAN control frame), validates destination aliases, extracts framing bits, and dispatches to the appropriate handler in interface_can_rx_statemachine_t.

Author
Jim Kueneman
Date
4 Mar 2026

Function Documentation

◆ CanRxStatemachine_initialize()

void CanRxStatemachine_initialize ( const interface_can_rx_statemachine_t * interface_can_rx_statemachine)
extern

Registers the dependency-injection interface for this module.

Parameters
interface_can_rx_statemachinePointer to a populated interface_can_rx_statemachine_t. Must remain valid for the lifetime of the application. All REQUIRED pointers must be non-NULL.
Warning
NOT thread-safe - call during single-threaded initialization only.
Must be called before any CAN frames arrive.
See also
CanRxMessageHandler_initialize - initialize first
CanRxStatemachine_incoming_can_driver_callback

Registers the dependency-injection interface for this module.

◆ CanRxStatemachine_incoming_can_driver_callback()

void CanRxStatemachine_incoming_can_driver_callback ( can_msg_t * can_msg)
extern

Primary entry point called by the hardware CAN driver on frame reception.

Invokes the optional on_receive callback, then classifies the frame as an OpenLCB message or a CAN control frame and dispatches accordingly.

This function is typically called from an interrupt or receive thread and accesses shared resources (FIFOs, buffer lists). It must NOT be called while the main state machine has resources locked. Recommended approaches:

  • Interrupt: disable CAN Rx interrupt during lock_shared_resources / unlock_shared_resources.
  • Thread: suspend Rx thread or queue frames during the lock window.
Parameters
can_msgPointer to the received CAN frame. Must not be NULL. Must remain valid until this function returns.
Warning
NOT thread-safe with the main state machine resource lock.
See also
CanMainStatemachine_run - holds the resource lock briefly
interface_can_rx_statemachine_t::on_receive

Copyright (c) 2026 Jim Kueneman all rights reserved. See the License