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

User-facing configuration struct and initialization API for OpenLcbCLib. More...

Go to the source code of this file.

Data Structures

struct  openlcb_config_t
 User configuration for OpenLcbCLib. More...
 

Functions

void OpenLcb_initialize (const openlcb_config_t *config)
 Initializes the entire OpenLCB stack with one call.
 
void OpenLcb_100ms_timer_tick (void)
 Increments the global 100ms tick counter.
 
uint8_t OpenLcb_get_global_100ms_tick (void)
 Returns the current value of the global 100ms tick counter.
 
openlcb_node_tOpenLcb_create_node (node_id_t node_id, const node_parameters_t *parameters)
 Allocates and registers a new node on the OpenLCB network.
 
void OpenLcb_run (void)
 Runs one iteration of all state machines.
 

Detailed Description

User-facing configuration struct and initialization API for OpenLcbCLib.

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.

Users populate one openlcb_config_t struct with hardware driver functions and optional application callbacks, then call OpenLcb_initialize() to bring up the entire stack.

Author
Jim Kueneman
Date
6 Mar 2026

Function Documentation

◆ OpenLcb_initialize()

void OpenLcb_initialize ( const openlcb_config_t * config)
extern

Initializes the entire OpenLCB stack with one call.

Initializes all buffer infrastructure, builds internal interface structs from the user config, and starts only the protocol modules selected by OPENLCB_COMPILE_* defines. After this returns, call OpenLcb_create_node() to allocate nodes, then call OpenLcb_run() in your main loop.

Parameters
configPointer to the openlcb_config_t to use. Must remain valid for the lifetime of the application (use static or global storage).
Warning
All required function pointers in the config struct must be non-NULL.

Initializes the entire OpenLCB stack with one call.

Algorithm:

  1. Store config pointer
  2. Initialize buffer infrastructure (store, list, FIFO)
  3. Build all internal interface structs from user config and compile flags
  4. Initialize all compiled-in protocol modules in dependency order
* @param config Pointer to the @ref openlcb_config_t to use
* 

◆ OpenLcb_100ms_timer_tick()

void OpenLcb_100ms_timer_tick ( void )
extern

Increments the global 100ms tick counter.

Call from a 100ms hardware timer interrupt or periodic task. This is the ONLY action performed by the timer context – all real protocol work runs in the main loop via OpenLcb_run().

Increments the global 100ms tick counter.

◆ OpenLcb_get_global_100ms_tick()

uint8_t OpenLcb_get_global_100ms_tick ( void )
extern

Returns the current value of the global 100ms tick counter.

Used by wiring code (openlcb_config.c, can_config.c) to read the clock and inject it into modules via parameters or interface function pointers. Individual modules should NOT call this directly — they receive the tick through their function parameters or interface.

Returns
Current tick count (wraps at 255).

◆ OpenLcb_create_node()

openlcb_node_t * OpenLcb_create_node ( node_id_t node_id,
const node_parameters_t * parameters )
extern

Allocates and registers a new node on the OpenLCB network.

Parameters
node_idUnique 48-bit node_id_t for the new node.
parametersPointer to the node_parameters_t (SNIP info, protocol flags, events).
Returns
Pointer to the allocated openlcb_node_t, or NULL if no slots available.

Allocates and registers a new node on the OpenLCB network.

* @param node_id     Unique 48-bit @ref node_id_t for the new node
* @param parameters  Pointer to @ref node_parameters_t (SNIP, protocol flags, events)
* 
Returns
Pointer to the allocated openlcb_node_t, or NULL if no slots available

◆ OpenLcb_run()

void OpenLcb_run ( void )
extern

Runs one iteration of all state machines.

Call as fast as possible in your main loop. Non-blocking — returns after processing one operation per call.

Runs one iteration of all state machines.


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