From d0ceeb4e2ad98c2f5698d78513143a39c6f36b95 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Sat, 1 Nov 2025 15:23:59 -0400 Subject: serialization module --- fw/serial.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 fw/serial.h (limited to 'fw/serial.h') diff --git a/fw/serial.h b/fw/serial.h new file mode 100644 index 0000000..5a6b495 --- /dev/null +++ b/fw/serial.h @@ -0,0 +1,45 @@ +/** Serialization of structures stored in the EEPROM. + * + * Device PIC16F1459 + * Compiler: XC8 v3.00 + * + * Usage: + * + * #include + * #include + * #include "types.h" + * #include "eeprom.h" + * #include "can.h" + * #include "signal.h" + * #include "serial.h" + */ + +// Size of structures stored in ROM +enum { + SER_CANID_SIZE = sizeof(U32), + SER_SIGFMT_SIZE = 8, +}; + +// Write a CAN ID to the EEPROM. +// CAN IDs are stored in the lower 11 or 29 bits of a little-endian U32. +// Bit 31 indicates standard/extended: 0=>std, 1=>ext. +Status serWriteCanId(EepromAddr addr, const CanId *id); + +// Read a CAN ID from the EEPROM. +// CAN IDs are stored in the lower 11 or 29 bits of a little-endian U32. +// Bit 31 indicates standard/extended: 0=>std, 1=>ext. +Status serReadCanId(EepromAddr addr, CanId *id); + +// Write a SigFmt to the EEPROM. +// SigFmts use 8 bytes of space. +// The ID is stored little-endian in the first 4 bytes: 0--3. +// Start and Size occupy bytes 4 and 5. +// The Byte-order and Signedness flags are bits 0 and 1 of byte 6, respectively. +// Byte order: [6][0] = {0=>LE, 1=>BE}. +// Signedness: [6][1] = {0=>unsigned, 1=>signed}. +// Byte 7 is unused -- it's for alignment. +Status serWriteSigFmt(EepromAddr addr, const SigFmt *sig); + +// Read a SigFmt from the EEPROM. +// See serWriteSigFmt for storage format. +Status serReadSigFmt(EepromAddr addr, SigFmt *sig); -- cgit v1.2.3