summaryrefslogtreecommitdiff
path: root/zbootloader.h
diff options
context:
space:
mode:
Diffstat (limited to 'zbootloader.h')
-rw-r--r--zbootloader.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/zbootloader.h b/zbootloader.h
new file mode 100644
index 0000000..2d1aff6
--- /dev/null
+++ b/zbootloader.h
@@ -0,0 +1,58 @@
+#ifndef ZBOOTLOADER_H
+#define ZBOOTLOADER_H
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <stddef.h>
+#include <assert.h>
+
+#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