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

Implementation of the CAN transmit state machine. More...

Functions

void CanTxStatemachine_initialize (const interface_can_tx_statemachine_t *interface_can_tx_statemachine)
 Stores the dependency-injection interface pointer.
 
bool CanTxStatemachine_send_openlcb_message (openlcb_msg_t *openlcb_msg)
 Transmits a complete OpenLCB message, blocking until all frames are sent.
 
bool CanTxStatemachine_send_can_message (can_msg_t *can_msg)
 Transmits a pre-built raw can_msg_t via the hardware handler.
 

Detailed Description

Implementation of the CAN transmit state machine.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Routes outgoing OpenLCB messages to the correct frame handler (addressed, unaddressed, datagram, or stream) and loops until the full payload is transmitted as an atomic multi-frame sequence. Also provides a pass-through path for pre-built raw CAN control frames.

Author
Jim Kueneman
Date
4 Mar 2026

Function Documentation

◆ CanTxStatemachine_initialize()

void CanTxStatemachine_initialize ( const interface_can_tx_statemachine_t * interface_can_tx_statemachine)

Stores the dependency-injection interface pointer.

Registers the dependency-injection interface for this module.

◆ CanTxStatemachine_send_openlcb_message()

bool CanTxStatemachine_send_openlcb_message ( openlcb_msg_t * openlcb_msg)

Transmits a complete OpenLCB message, blocking until all frames are sent.

Converts and transmits an openlcb_msg_t as one or more CAN frames.

Algorithm:

  1. Discard immediately if state.invalid is set (AMR scrub marked it).
  2. If dest_alias == 0 and dest_id != 0, resolve the alias via listener_find_by_node_id (DI, nullable). Drop the message if unresolvable (return true so the caller clears the outgoing slot).
  3. Return false immediately if the TX hardware buffer is busy.
  4. If payload_count == 0: send a single zero-payload frame and return.
  5. Otherwise, send the first frame; if it fails return false.
  6. Loop calling _transmit_openlcb_message until payload_index == payload_count.
  7. Return true when done.
* @param openlcb_msg Message to transmit.
* 
Returns
true if the full message was sent, false if the hardware buffer was busy or failed.
Warning
Blocks until the entire multi-frame message is sent.

◆ CanTxStatemachine_send_can_message()

bool CanTxStatemachine_send_can_message ( can_msg_t * can_msg)

Transmits a pre-built raw can_msg_t via the hardware handler.

Transmits a pre-built raw can_msg_t directly to the hardware.


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