aboutsummaryrefslogtreecommitdiffstats
path: root/fw/serial.h
blob: b07103818cf95a64c45befffa4c6ff5d97152ef8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/** Serialization of structures stored in the EEPROM.
 *
 * Device PIC16F1459
 * Compiler: XC8 v3.00
 *
 * Usage:
 *
 * #include <stdbool.h>
 * #include <stdint.h>
 * #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 7 and 6 of byte 6, respectively.
// Byte order: [6][7] = {0=>LE, 1=>BE}.
// Signedness: [6][6] = {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);