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

Type definitions and constants for the CAN transport layer. More...

Go to the source code of this file.

Data Structures

struct  can_msg_state_struct
 
struct  can_msg_struct
 
struct  can_main_statemachine_struct
 
struct  can_statemachine_info_struct
 
struct  alias_mapping_struct
 
struct  alias_mapping_info_struct
 
struct  listener_alias_entry_struct
 

Macros

#define USER_DEFINED_CAN_MSG_BUFFER_DEPTH   10
 Number of can_msg_t buffers in the pool (can_buffer_store.h).
 
#define ALIAS_MAPPING_BUFFER_DEPTH   USER_DEFINED_NODE_BUFFER_DEPTH
 Number of alias_mapping_t slots. Defaults to USER_DEFINED_NODE_BUFFER_DEPTH.
 
#define LEN_CAN_FIFO_BUFFER   (USER_DEFINED_CAN_MSG_BUFFER_DEPTH + 1)
 FIFO slot count — one extra slot so head==tail always means empty.
 
#define LEN_CAN_BYTE_ARRAY   8
 Number of data bytes in a CAN 2.0 frame.
 
#define OFFSET_CAN_WITHOUT_DEST_ADDRESS   0
 Pass to functions when the CAN payload starts at byte 0 (no destination alias).
 
#define OFFSET_CAN_WITH_DEST_ADDRESS   2
 Pass to functions when bytes 0-1 carry a destination alias; data starts at byte 2.
 
#define CAN_MTI_PCER_WITH_PAYLOAD_FIRST   0x0F16
 CAN framing MTI for first frame of segmented PCER-with-payload.
 
#define CAN_MTI_PCER_WITH_PAYLOAD_MIDDLE   0x0F15
 CAN framing MTI for middle frame of segmented PCER-with-payload.
 
#define CAN_MTI_PCER_WITH_PAYLOAD_LAST   0x0F14
 CAN framing MTI for last frame of segmented PCER-with-payload.
 
#define LISTENER_ALIAS_TABLE_DEPTH    (USER_DEFINED_MAX_LISTENERS_PER_TRAIN * USER_DEFINED_TRAIN_NODE_COUNT)
 Total listener alias table slots across all train nodes.
 

Typedefs

typedef uint8_t payload_bytes_can_t[LEN_CAN_BYTE_ARRAY]
 Fixed 8-byte array holding a CAN frame payload.
 
typedef struct can_msg_state_struct can_msg_state_t
 Bit-field tracking allocation status of a can_msg_t buffer.
 
typedef struct can_msg_struct can_msg_t
 Complete CAN 2.0B extended frame: 29-bit identifier + up to 8 data bytes.
 
typedef can_msg_t can_msg_array_t[USER_DEFINED_CAN_MSG_BUFFER_DEPTH]
 Pre-allocated array of can_msg_t buffers, sized USER_DEFINED_CAN_MSG_BUFFER_DEPTH.
 
typedef struct can_main_statemachine_struct can_main_statemachine_t
 Working context for the CAN main state machine.
 
typedef struct can_statemachine_info_struct can_statemachine_info_t
 Context block passed through the CAN state machine on every iteration.
 
typedef struct alias_mapping_struct alias_mapping_t
 One entry in the alias mapping table: a node_id_t / 12-bit alias pair.
 
typedef struct alias_mapping_info_struct alias_mapping_info_t
 Container for all alias_mapping_t entries plus a global duplicate flag.
 
typedef struct listener_alias_entry_struct listener_alias_entry_t
 One entry in the listener alias table: a node_id_t / 12-bit alias pair.
 

Detailed Description

Type definitions and constants for the CAN transport layer.

Defines can_msg_t, alias_mapping_t, alias_mapping_info_t, can_statemachine_info_t, listener_alias_entry_t, and all compile-time constants shared across the CAN driver modules. No executable code — types and macros only.

Author
Jim Kueneman
Date
8 Mar 2026

Macro Definition Documentation

◆ USER_DEFINED_CAN_MSG_BUFFER_DEPTH

#define USER_DEFINED_CAN_MSG_BUFFER_DEPTH   10

Number of can_msg_t buffers in the pool (can_buffer_store.h).

Override at compile time: -D USER_DEFINED_CAN_MSG_BUFFER_DEPTH=20

Warning
Maximum value is 254 (0xFE).

◆ ALIAS_MAPPING_BUFFER_DEPTH

#define ALIAS_MAPPING_BUFFER_DEPTH   USER_DEFINED_NODE_BUFFER_DEPTH

Number of alias_mapping_t slots. Defaults to USER_DEFINED_NODE_BUFFER_DEPTH.

◆ LEN_CAN_FIFO_BUFFER

#define LEN_CAN_FIFO_BUFFER   (USER_DEFINED_CAN_MSG_BUFFER_DEPTH + 1)

FIFO slot count — one extra slot so head==tail always means empty.

◆ LEN_CAN_BYTE_ARRAY

#define LEN_CAN_BYTE_ARRAY   8

Number of data bytes in a CAN 2.0 frame.

◆ OFFSET_CAN_WITHOUT_DEST_ADDRESS

#define OFFSET_CAN_WITHOUT_DEST_ADDRESS   0

Pass to functions when the CAN payload starts at byte 0 (no destination alias).

◆ OFFSET_CAN_WITH_DEST_ADDRESS

#define OFFSET_CAN_WITH_DEST_ADDRESS   2

Pass to functions when bytes 0-1 carry a destination alias; data starts at byte 2.

◆ CAN_MTI_PCER_WITH_PAYLOAD_FIRST

#define CAN_MTI_PCER_WITH_PAYLOAD_FIRST   0x0F16

CAN framing MTI for first frame of segmented PCER-with-payload.

◆ CAN_MTI_PCER_WITH_PAYLOAD_MIDDLE

#define CAN_MTI_PCER_WITH_PAYLOAD_MIDDLE   0x0F15

CAN framing MTI for middle frame of segmented PCER-with-payload.

◆ CAN_MTI_PCER_WITH_PAYLOAD_LAST

#define CAN_MTI_PCER_WITH_PAYLOAD_LAST   0x0F14

CAN framing MTI for last frame of segmented PCER-with-payload.

◆ LISTENER_ALIAS_TABLE_DEPTH

#define LISTENER_ALIAS_TABLE_DEPTH    (USER_DEFINED_MAX_LISTENERS_PER_TRAIN * USER_DEFINED_TRAIN_NODE_COUNT)

Total listener alias table slots across all train nodes.

Typedef Documentation

◆ payload_bytes_can_t

typedef uint8_t payload_bytes_can_t[LEN_CAN_BYTE_ARRAY]

Fixed 8-byte array holding a CAN frame payload.

See also
LEN_CAN_BYTE_ARRAY
can_msg_t

◆ can_msg_state_t

Bit-field tracking allocation status of a can_msg_t buffer.

See also
CanBufferStore_allocate_buffer
CanBufferStore_free_buffer

◆ can_msg_t

typedef struct can_msg_struct can_msg_t

Complete CAN 2.0B extended frame: 29-bit identifier + up to 8 data bytes.

Warning
Maximum payload is 8 bytes.
See also
can_buffer_store.h
can_buffer_fifo.h

◆ can_msg_array_t

typedef can_msg_t can_msg_array_t[USER_DEFINED_CAN_MSG_BUFFER_DEPTH]

Pre-allocated array of can_msg_t buffers, sized USER_DEFINED_CAN_MSG_BUFFER_DEPTH.

See also
can_buffer_store.c

◆ can_main_statemachine_t

Working context for the CAN main state machine.

◆ can_statemachine_info_t

Context block passed through the CAN state machine on every iteration.

Carries the current node pointer, a statically-allocated login frame buffer, a pointer to an outgoing frame from the pool, and control flags. The login buffer is always valid; outgoing_can_msg is NULL when no message is pending.

Warning
login_outgoing_can_msg points to a static variable in can_main_statemachine.c — do not free it.
outgoing_can_msg must be freed after successful transmission.
See also
can_main_statemachine.h
can_login_statemachine.h

◆ alias_mapping_t

One entry in the alias mapping table: a node_id_t / 12-bit alias pair.

Flags may be set from interrupt context and read from the main loop. Use lock/unlock around accesses shared between contexts.

See also
alias_mappings.h

◆ alias_mapping_info_t

Container for all alias_mapping_t entries plus a global duplicate flag.

has_duplicate_alias is a fast-check flag: when set, at least one entry has is_duplicate set and the main loop should scan the list to find and resolve it.

See also
alias_mappings.h
AliasMappings_set_has_duplicate_alias_flag

◆ listener_alias_entry_t

One entry in the listener alias table: a node_id_t / 12-bit alias pair.

Written by the CAN RX interrupt (AMD arrival) and read by the CAN TX main thread (alias resolution). Protected by the existing lock_shared_resources / unlock_shared_resources mechanism.

See also
listener_alias_table.h

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