From 0e62876578749c12a9c963ef7dd7db9f0ac35081 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Fri, 1 Jul 2016 10:32:52 -0700 Subject: [PATCH] Add types for tagged data chunks in SPI flash. --- firmware/common/spi_image.hpp | 52 +++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/firmware/common/spi_image.hpp b/firmware/common/spi_image.hpp index f8e71d62..a09c593c 100644 --- a/firmware/common/spi_image.hpp +++ b/firmware/common/spi_image.hpp @@ -30,6 +30,58 @@ namespace portapack { namespace spi_flash { +struct image_tag_t { + constexpr image_tag_t( + ) : c { 0, 0, 0, 0 } + { + } + + constexpr image_tag_t( + char c0, char c1, char c2, char c3 + ) : c { c0, c1, c2, c3 } + { + } + + image_tag_t& operator=(const image_tag_t& other) { + c[0] = other.c[0]; + c[1] = other.c[1]; + c[2] = other.c[2]; + c[3] = other.c[3]; + return *this; + } + + bool operator==(const image_tag_t& other) const { + return (c[0] == other.c[0]) && (c[1] == other.c[1]) && (c[2] == other.c[2]) && (c[3] == other.c[3]); + } + + operator bool() const { + return (c[0] != 0) || (c[1] != 0) || (c[2] != 0) || (c[3] != 0); + } + +private: + char c[4]; +}; + +constexpr image_tag_t image_tag_ais { 'P', 'A', 'I', 'S' }; +constexpr image_tag_t image_tag_am_audio { 'P', 'A', 'M', 'A' }; +constexpr image_tag_t image_tag_capture { 'P', 'C', 'A', 'P' }; +constexpr image_tag_t image_tag_ert { 'P', 'E', 'R', 'T' }; +constexpr image_tag_t image_tag_nfm_audio { 'P', 'N', 'F', 'M' }; +constexpr image_tag_t image_tag_tpms { 'P', 'T', 'P', 'M' }; +constexpr image_tag_t image_tag_wfm_audio { 'P', 'W', 'F', 'M' }; +constexpr image_tag_t image_tag_wideband_spectrum { 'P', 'S', 'P', 'E' }; +constexpr image_tag_t image_tag_hackrf { 'H', 'R', 'F', '1' }; + +struct chunk_t { + const image_tag_t tag; + const uint32_t length; + const uint8_t data[]; + + const chunk_t* next() const { + return reinterpret_cast(&data[length]); + } +}; + struct region_t { const size_t offset; const size_t size;