Skip to content

Group baton_defs

Modules > baton_defs

Frame layout, frame types, payload prefixes and byte-order helpers. More...

Public Static Functions

Type Name
uint8_t baton_ctrl (uint8_t type, bool first, uint8_t seq)
Build a control byte.
bool baton_ctrl_first (uint8_t ctrl)
FIRST flag of a control byte.
uint8_t baton_ctrl_seq (uint8_t ctrl)
Sequence number of a control byte.
uint8_t baton_ctrl_type (uint8_t ctrl)
Frame type of a control byte.
uint16_t baton_get_u16be (const uint8_t * data)
Read a big-endian 16-bit value.
uint32_t baton_get_u32le (const uint8_t * data)
Read a little-endian 32-bit value.
void baton_put_u16be (uint8_t * data, uint16_t value)
Write a 16-bit value in big-endian order.
void baton_put_u32le (uint8_t * data, uint32_t value)
Write a 32-bit value in little-endian order.

Macros

Type Name
define BATON_ACKB_VALID 0x80U
ACKB byte: bit 7 = valid, bits 3..0 = acknowledged sequence number.
define BATON_ADDR_BROADCAST 0xFFU
Destination address meaning "every other node on the bus".
define BATON_CRC_SIZE 2U
CRC-16, transmitted high byte first.
define BATON_FRAME_OVERHEAD ([**BATON\_HEADER\_SIZE**](group__baton__defs.md#define-baton_header_size) + [**BATON\_CRC\_SIZE**](group__baton__defs.md#define-baton_crc_size))
Bytes of a frame that are not payload.
define BATON_FT_ACK 3U
Slave to slave: acknowledges one DATA frame.
define BATON_FT_DATA 2U
Slave to slave: messages, acknowledged with ACK.
define BATON_FT_POLL 0U
Master to slave: grants the bus for one slot, may carry messages.
define BATON_FT_RESP 1U
Slave to master: ends the slot, may carry messages.
define BATON_HEADER_SIZE 5U
SYNC, DST, SRC, CTRL and LEN.
define BATON_SEQ_MASK 0x0FU
Mask of the sequence number in CTRL and ACKB.
define BATON_SYNC 0xA5U
First byte of every frame.
define BATON_TLV_HEADER_SIZE 2U
One message inside a payload: id, length, data (TLV).

Detailed Description

The wire format is described in docs/protocol.md: SYNC | DST | SRC | CTRL | LEN | PAYLOAD[LEN] | CRC16 (big endian), CRC-16/CCITT-FALSE over DST..PAYLOAD, CTRL = TYPE[7:6] | FIRST[5] | reserved[4] | SEQ[3:0].

Public Static Functions Documentation

function baton_ctrl

Build a control byte.

static inline uint8_t baton_ctrl (
    uint8_t type,
    bool first,
    uint8_t seq
) 

Parameters:

  • type Frame type (BATON_FT_*), 0..3.
  • first FIRST flag: set until the receiver acknowledged a frame after a restart.
  • seq Sequence number, only bits 3..0 are used.

Returns:

Control byte.


function baton_ctrl_first

FIRST flag of a control byte.

static inline bool baton_ctrl_first (
    uint8_t ctrl
) 


function baton_ctrl_seq

Sequence number of a control byte.

static inline uint8_t baton_ctrl_seq (
    uint8_t ctrl
) 


function baton_ctrl_type

Frame type of a control byte.

static inline uint8_t baton_ctrl_type (
    uint8_t ctrl
) 


function baton_get_u16be

Read a big-endian 16-bit value.

static inline uint16_t baton_get_u16be (
    const uint8_t * data
) 


function baton_get_u32le

Read a little-endian 32-bit value.

static inline uint32_t baton_get_u32le (
    const uint8_t * data
) 


function baton_put_u16be

Write a 16-bit value in big-endian order.

static inline void baton_put_u16be (
    uint8_t * data,
    uint16_t value
) 


function baton_put_u32le

Write a 32-bit value in little-endian order.

static inline void baton_put_u32le (
    uint8_t * data,
    uint32_t value
) 


Macro Definition Documentation

define BATON_ACKB_VALID

ACKB byte: bit 7 = valid, bits 3..0 = acknowledged sequence number.

#define BATON_ACKB_VALID `0x80U`


define BATON_ADDR_BROADCAST

Destination address meaning "every other node on the bus".

#define BATON_ADDR_BROADCAST `0xFFU`


define BATON_CRC_SIZE

CRC-16, transmitted high byte first.

#define BATON_CRC_SIZE `2U`


define BATON_FRAME_OVERHEAD

Bytes of a frame that are not payload.

#define BATON_FRAME_OVERHEAD `( BATON_HEADER_SIZE + BATON_CRC_SIZE )`


define BATON_FT_ACK

Slave to slave: acknowledges one DATA frame.

#define BATON_FT_ACK `3U`


define BATON_FT_DATA

Slave to slave: messages, acknowledged with ACK.

#define BATON_FT_DATA `2U`


define BATON_FT_POLL

Master to slave: grants the bus for one slot, may carry messages.

#define BATON_FT_POLL `0U`


define BATON_FT_RESP

Slave to master: ends the slot, may carry messages.

#define BATON_FT_RESP `1U`


define BATON_HEADER_SIZE

SYNC, DST, SRC, CTRL and LEN.

#define BATON_HEADER_SIZE `5U`


define BATON_SEQ_MASK

Mask of the sequence number in CTRL and ACKB.

#define BATON_SEQ_MASK `0x0FU`


define BATON_SYNC

First byte of every frame.

#define BATON_SYNC `0xA5U`


define BATON_TLV_HEADER_SIZE

One message inside a payload: id, length, data (TLV).

#define BATON_TLV_HEADER_SIZE `2U`