diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2025-11-07 14:55:14 -0500 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2025-11-07 14:55:14 -0500 |
| commit | 085c7bba8dce915f098e5cdc53c2003b6f89769a (patch) | |
| tree | fa45030f644acbc64b17c2a47e9e294f32e2ecae /fw/table.c | |
| parent | 9719160dec4d26c1c4d4a3bc1fbe355906f540eb (diff) | |
| download | can-gauge-interface-085c7bba8dce915f098e5cdc53c2003b6f89769a.zip | |
int serialization functions
Diffstat (limited to 'fw/table.c')
| -rw-r--r-- | fw/table.c | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -4,19 +4,23 @@ #include "types.h" #include "can.h" #include "eeprom.h" +#include "signal.h" +#include "serial.h" #include "table.h" Status tabWrite(const Table *tab, U8 k, U32 key, U16 val) { + U16 addr; + U8 row[sizeof(key) + sizeof(val)]; + if (k >= TAB_ROWS) { return FAIL; } - U16 addr = tab->offset + k*TAB_ROW_SIZE; - U8 row[sizeof(key) + sizeof(val)] = { - (key>>0u)&0xFF, (key>>8u)&0xFF, (key>>16u)&0xFF, (key>>24u)&0xFF, // LE - (val>>0u)&0xFF, (val>>8u)&0xFF}; // LE + addr = tab->offset + k*TAB_ROW_SIZE; + serU32Be(row, key); + serU16Be(row+sizeof(key), val); return eepromWrite(addr, row, sizeof(row)); } @@ -32,8 +36,8 @@ tabRead(const Table *tab, U8 k, U32 *key, U16 *val) { addr = tab->offset + k*TAB_ROW_SIZE; status = eepromRead(addr, row, sizeof(row)); - *key = ((U32)row[0u]<<0u) | ((U32)row[1u]<<8u) | ((U32)row[2u]<<16u) | ((U32)row[3u]<<24u); // LE - *val = ((U16)row[4u]<<0u) | ((U16)row[5u]<<8u); // LE + *key = deserU32Be(row); + *val = deserU16Be(row+sizeof(U32)); return status; } |