35#ifndef _OPENLCB_MEMORYCONFIGDEFS_HXX_
36#define _OPENLCB_MEMORYCONFIGDEFS_HXX_
49 using DatagramPayload = string;
74 COMMAND_OPTIONS = 0x80,
75 COMMAND_OPTIONS_REPLY = 0x82,
76 COMMAND_INFORMATION = 0x84,
77 COMMAND_INFORMATION_REPLY = 0x86,
149 ERROR_SPACE_NOT_KNOWN = Defs::ERROR_INVALID_ARGS | 0x0001,
150 ERROR_OUT_OF_BOUNDS = Defs::ERROR_INVALID_ARGS | 0x0002,
151 ERROR_WRITE_TO_RO = Defs::ERROR_INVALID_ARGS | 0x0003,
154 static constexpr unsigned MAX_DATAGRAM_RW_BYTES = 64;
156 static bool is_special_space(uint8_t space)
161 static DatagramPayload write_datagram(
162 uint8_t space, uint32_t offset,
const string &data =
"")
165 p.reserve(7 + data.size());
168 p.push_back(0xff & (offset >> 24));
169 p.push_back(0xff & (offset >> 16));
170 p.push_back(0xff & (offset >> 8));
171 p.push_back(0xff & (offset));
172 if (is_special_space(space))
174 p[1] |= space & ~SPACE_SPECIAL;
184 static DatagramPayload read_datagram(
185 uint8_t space, uint32_t offset, uint8_t length)
191 p.push_back(0xff & (offset >> 24));
192 p.push_back(0xff & (offset >> 16));
193 p.push_back(0xff & (offset >> 8));
194 p.push_back(0xff & (offset));
195 if (is_special_space(space))
197 p[1] |= space & ~SPACE_SPECIAL;
207 static DatagramPayload read_stream_datagram(uint8_t space, uint32_t offset,
208 uint8_t dst_stream_id, uint32_t length = 0xFFFFFFFF)
214 p.push_back(0xff & (offset >> 24));
215 p.push_back(0xff & (offset >> 16));
216 p.push_back(0xff & (offset >> 8));
217 p.push_back(0xff & (offset));
218 if (is_special_space(space))
220 p[1] |= space & ~SPACE_SPECIAL;
227 p.push_back(dst_stream_id);
228 p.push_back(0xff & (length >> 24));
229 p.push_back(0xff & (length >> 16));
230 p.push_back(0xff & (length >> 8));
231 p.push_back(0xff & (length));
242 const DatagramPayload &payload,
unsigned extra)
245 size_t sz = payload.size();
259 static uint8_t
get_space(
const DatagramPayload &payload)
287 uint32_t a = bytes[2];
302 return (uint8_t *)payload.data();
Payload DatagramPayload
Contents of a Datagram message.
@ CONFIGURATION
configuration message
Static constants and helper functions related to the Memory Configuration Protocol.
flags
Possible address space information flags.
@ FLAG_RO
space is read only
@ FLAG_NZLA
space has a nonzero low address
available
Possible available options.
@ AVAIL_UW
unaligned writes supported
@ AVAIL_R0xFB
read from adddress space 0xFB available
@ AVAIL_SR
stream reads supported
@ AVAIL_W0xFB
write from adddress space 0xFB available
@ AVAIL_WUM
write under mask supported
@ AVAIL_R0xFC
read from adddress space 0xFC available
@ AVAIL_UR
unaligned reads supported
commands
Possible Commands for a configuration datagram.
@ COMMAND_WRITE_STREAM_FAILED
failed to write data using a stream
@ COMMAND_LOCK_REPLY
unlock the configuration space
@ COMMAND_READ_STREAM
command to read data using a stream
@ COMMAND_READ_REPLY
reply to read data from address space
@ COMMAND_RESET
reset node to its power on state
@ COMMAND_READ_STREAM_FAILED
failed to read data using a stream
@ COMMAND_READ
command to read data from address space
@ COMMAND_WRITE_UNDER_MASK
command to write data under mask
@ COMMAND_UNFREEZE
unfreeze operation of node
@ COMMAND_FREEZE
freeze operation of node
@ COMMAND_LOCK
lock the configuration space
@ COMMAND_UPDATE_COMPLETE
indicate that a sequence of commands is complete
@ COMMAND_WRITE
command to write data to address space
@ COMMAND_WRITE_STREAM
command to write data using a stream
@ COMMAND_UNIQUE_ID_REPLY
node unique id
@ COMMAND_FACTORY_RESET
reset node to factory defaults
@ COMMAND_REPLY_BIT_FOR_RW
This bit is present in REPLY commands for read-write commands.
@ COMMAND_WRITE_STREAM_REPLY
reply to write data using a stream
@ COMMAND_WRITE_REPLY
reply to write data to address space
@ COMMAND_READ_FAILED
failed to read data from address space
@ COMMAND_READ_STREAM_REPLY
reply to read data using a stream
@ COMMAND_UNIQUE_ID
ask for a node unique id
@ COMMAND_ENTER_BOOTLOADER
reset node in bootloader mode
@ COMMAND_PRESENT_MASK
mask for address space present bit
@ COMMAND_CDI
flags for a CDI space
@ COMMAND_PRESENT
address space is present
@ COMMAND_ALL_MEMORY
flags for an all memory space
@ COMMAND_WRITE_FAILED
failed to write data to address space
@ COMMAND_MAX_FOR_RW
command <= this value have fixed bit arrangement.
@ COMMAND_FLAG_MASK
mask for special memory space flags
@ COMMAND_CONFIG
flags for a config memory space
lengths
Possible supported write lengths.
@ LENGTH_2
write length of 2 supported
@ LENGTH_4
write length of 4 supported
@ LENGTH_1
write length of 1 supported
@ LENGTH_STREAM
stream writes supported
@ LENGTH_ARBITRARY
arbitrary write of any length supported
@ LENGTH_63
write length of 64 supported
static bool payload_min_length_check(const DatagramPayload &payload, unsigned extra)
spaces
Possible memory spaces.
@ SPACE_DCC_CV
proxy space for DCC functions
@ SPACE_SPECIAL
offset for the special memory spaces
@ SPACE_FDI
read-only for function definition XML
@ SPACE_FIRMWARE
firmware upgrade space
@ SPACE_ALL_MEMORY
all memory space
@ SPACE_ACDI_USR
read-write ACDI space
@ SPACE_CONFIG
config memory space
@ SPACE_FUNCTION
read-write for function data
@ SPACE_ACDI_SYS
read-only ACDI space
static const uint8_t * payload_bytes(const DatagramPayload &payload)
Type casts a DatagramPayload to an array of bytes.
static uint32_t get_address(const DatagramPayload &payload)
static uint8_t get_space(const DatagramPayload &payload)
MemoryConfigDefs()
Do not instantiate this class.