From 38427060c8f781589d7f78148cf6204b97f20d4b Mon Sep 17 00:00:00 2001 From: Thomas Guillermo Albers Raviola Date: Sat, 4 Oct 2025 20:52:39 +0200 Subject: Restructure project --- include/zeta/zbootloader.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 include/zeta/zbootloader.h (limited to 'include/zeta/zbootloader.h') diff --git a/include/zeta/zbootloader.h b/include/zeta/zbootloader.h new file mode 100644 index 0000000..2d1aff6 --- /dev/null +++ b/include/zeta/zbootloader.h @@ -0,0 +1,58 @@ +#ifndef ZBOOTLOADER_H +#define ZBOOTLOADER_H + +#include +#include +#include +#include + +#ifdef __GNUC__ +#define PACKED __attribute__((packed)) +#else +#define PACKED +#endif + +enum header_type { + CMD_PING, + CMD_INFO, + CMD_BOOT, + CMD_READ, + CMD_WRITE, + CMD_IO_READ, + CMD_IO_WRITE, + CMD_ECHO +}; + +struct header { + uint8_t type; + uint8_t bank; + uint16_t address; + uint16_t length; + uint16_t checksum; +} PACKED; + +static_assert(sizeof(struct header) == 8, "struct header is not PACKED"); + +enum ack { + ACK = 0x00, + NACK = 0xFF +}; + +enum error { + ERR_TIMEOUT = -1 +}; + +#define LEN(x) ((size_t)(sizeof(x) / sizeof(x[0]))) + +#define FIFO_LEN 32 +#define MAX_PACKET_SIZE 256 +#define TIMEOUT_MS 500 +#define MAX_ATTEMPTS 3 +#define MAX_TRANS_ATTEMPTS 5 + +// static_assert(FIFO_LEN % 2 == 0, "FIFO_LEN is not a power of 2"); + +uint16_t +crc16(const void *buf, size_t len); + +#endif // ZBOOTLOADER_H -- cgit v1.2.3