Appendix E — Compile-Time Configuration Reference

All compile-time configuration is provided by the application in openlcb_user_config.h. This file must be placed on the compiler's include path. A template is provided in templates/openlcb_user_config.h.

E.1 Required Buffer Depth Macros

These macros control the static memory allocation for message buffer pools. All must be defined:

MacroPurposePer-Buffer SizeTypical Value
USER_DEFINED_BASIC_BUFFER_DEPTHNumber of BASIC message buffers16 bytes5-10
USER_DEFINED_DATAGRAM_BUFFER_DEPTHNumber of DATAGRAM message buffers72 bytes2-5
USER_DEFINED_SNIP_BUFFER_DEPTHNumber of SNIP message buffers256 bytes1-3
USER_DEFINED_STREAM_BUFFER_DEPTHNumber of STREAM message buffers512 bytes0-2
USER_DEFINED_CAN_MSG_BUFFER_DEPTHNumber of CAN frame buffers (FIFO depth)~16 bytes5-20
Buffer Limit

The sum BASIC + DATAGRAM + SNIP + STREAM must not exceed 126 on 8-bit targets. This is enforced at compile time by openlcb_config.h.

E.2 Required Node and Event Macros

MacroPurposeTypical Value
USER_DEFINED_NODE_BUFFER_DEPTHMaximum virtual nodes that can be allocated1-5
USER_DEFINED_PRODUCER_COUNTMax events a node can produce2-16
USER_DEFINED_CONSUMER_COUNTMax events a node can consume2-16
USER_DEFINED_PRODUCER_RANGE_COUNTMax producer event ranges (must be >= 1)1-4
USER_DEFINED_CONSUMER_RANGE_COUNTMax consumer event ranges (must be >= 1)1-4
USER_DEFINED_CDI_LENGTHCDI XML buffer size in bytes256-2048
USER_DEFINED_FDI_LENGTHFDI XML buffer size in bytes (train nodes)1-512

E.3 Required Config Memory Macros

MacroPurpose
USER_DEFINED_CONFIG_MEM_USER_NAME_ADDRESSAddress in config memory for user-assigned node name
USER_DEFINED_CONFIG_MEM_USER_DESCRIPTION_ADDRESSAddress in config memory for user description

E.4 Required Train Macros

These must be defined even if train support is not enabled (set to 0 if not needed):

MacroPurposeTypical Value
USER_DEFINED_TRAIN_NODE_COUNTMax train nodes that can be allocated0-8
USER_DEFINED_MAX_LISTENERS_PER_TRAINMax consist members per train0-4
USER_DEFINED_MAX_TRAIN_FUNCTIONSDCC functions per train (29 = F0-F28)0-29

E.5 Feature Flag Macros

Define these to enable optional protocol support. Each flag includes the corresponding protocol handler code and callbacks in the build:

MacroEnablesDependencies
OPENLCB_COMPILE_EVENTSEvent Transport Protocol (Producer/Consumer)None
OPENLCB_COMPILE_DATAGRAMSDatagram ProtocolNone
OPENLCB_COMPILE_MEMORY_CONFIGURATIONMemory Configuration Protocol (read/write/operations)DATAGRAMS
OPENLCB_COMPILE_FIRMWAREFirmware Upgrade Protocol (freeze/unfreeze/write)MEMORY_CONFIGURATION
OPENLCB_COMPILE_BROADCAST_TIMEBroadcast Time ProtocolEVENTS
OPENLCB_COMPILE_TRAINTrain Control ProtocolNone
OPENLCB_COMPILE_TRAIN_SEARCHTrain Search ProtocolEVENTS + TRAIN
OPENLCB_COMPILE_VERBOSECompile-time summary via #pragma messageNone

E.6 Feature Dependency Tree

flowchart TD EVT["OPENLCB_COMPILE_EVENTS"] DG["OPENLCB_COMPILE_DATAGRAMS"] MC["OPENLCB_COMPILE_MEMORY_CONFIGURATION"] FW["OPENLCB_COMPILE_FIRMWARE"] BT["OPENLCB_COMPILE_BROADCAST_TIME"] TR["OPENLCB_COMPILE_TRAIN"] TS["OPENLCB_COMPILE_TRAIN_SEARCH"] MC -->|requires| DG FW -->|requires| MC BT -->|requires| EVT TS -->|requires| EVT TS -->|requires| TR style EVT fill:#e8f5e9,stroke:#2e7d32 style DG fill:#e8f5e9,stroke:#2e7d32 style MC fill:#e3f2fd,stroke:#1565c0 style FW fill:#e3f2fd,stroke:#1565c0 style BT fill:#fff3e0,stroke:#e65100 style TR fill:#e8f5e9,stroke:#2e7d32 style TS fill:#fff3e0,stroke:#e65100

If a dependency is not met, compilation fails with a #error directive. For example, enabling OPENLCB_COMPILE_MEMORY_CONFIGURATION without OPENLCB_COMPILE_DATAGRAMS produces:

#error "OPENLCB_COMPILE_MEMORY_CONFIGURATION requires OPENLCB_COMPILE_DATAGRAMS"

E.7 Derived Constants

These constants are computed from the user-defined macros. They should not be overridden directly:

ConstantFormulaPurpose
LEN_MESSAGE_BUFFERBASIC + DATAGRAM + SNIP + STREAMTotal number of message buffers
ALIAS_MAPPING_BUFFER_DEPTHUSER_DEFINED_NODE_BUFFER_DEPTHAlias table size (one per node)
LISTENER_ALIAS_TABLE_DEPTHMAX_LISTENERS_PER_TRAIN * TRAIN_NODE_COUNTListener alias table size

E.8 No-Features Warning

If no optional features are enabled, the compiler issues a warning:

#if !defined(OPENLCB_COMPILE_EVENTS) && !defined(OPENLCB_COMPILE_DATAGRAMS) && \
    !defined(OPENLCB_COMPILE_TRAIN)
#warning "No optional features enabled. This node will only support SNIP identification."
#endif
Source Reference

Required macros are validated with #error directives in openlcb_types.h and can_types.h. Feature dependency validation and buffer sanity checks are in openlcb_config.h. The verbose compile summary is also in openlcb_config.h.

← Prev: Appendix D — Event ID Encoding Next: Appendix F — Spec Traceability →