#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