8static void put16(uint8_t*
p, uint16_t v) {
10 p[1] = (uint8_t)(v >> 8);
13static void put32(uint8_t*
p, uint32_t v) {
15 p[1] = (uint8_t)(v >> 8);
16 p[2] = (uint8_t)(v >> 16);
17 p[3] = (uint8_t)(v >> 24);
20static uint16_t
get16(
const uint8_t*
p) {
21 return (uint16_t)(
p[0] | (
p[1] << 8));
24static uint32_t
get32(
const uint8_t*
p) {
25 return (uint32_t)
p[0] | ((uint32_t)
p[1] << 8) | ((uint32_t)
p[2] << 16) |
26 ((uint32_t)
p[3] << 24);
32 static const uint32_t
table[16] = {
33 0x00000000UL, 0x1DB71064UL, 0x3B6E20C8UL, 0x26D930ACUL,
34 0x76DC4190UL, 0x6B6B51F4UL, 0x4DB26158UL, 0x5005713CUL,
35 0xEDB88320UL, 0xF00F9344UL, 0xD6D6A3E8UL, 0xCB61B38CUL,
36 0x9B64C2B0UL, 0x86D3D2D4UL, 0xA00AE278UL, 0xBDBDF21CUL};
37 const uint8_t*
p = (
const uint8_t*)data;
38 uint32_t crc = 0xFFFFFFFFUL;
39 for (uint32_t i = 0; i < len; ++i) {
41 crc = (crc >> 4) ^
table[crc & 0x0FU];
42 crc = (crc >> 4) ^
table[crc & 0x0FU];
44 return crc ^ 0xFFFFFFFFUL;
121 const void* data, uint8_t len) {
184 config->flush_interval_ms == 0U ||
config->read_budget_ms == 0U ||
185 config->write_budget_ms == 0U ||
config->write_attempts == 0U ||
189 memset(log, 0,
sizeof *log);
215 uint8_t s = (uint8_t)to;
218 }
else if (was && is && from != to) {
220 uint8_t s[2] = {(uint8_t)from, (uint8_t)to};
223 }
else if (was && !is) {
225 uint8_t s = (uint8_t)to;
236 const void* data, uint8_t len) {
237 if (len > 0U && !data) {
308 uint32_t mid = lo + (hi - lo) / 2U;
342 log->
epoch = last + 1U == 0U ? 1U : last + 1U;
355 uint32_t capacity = 0;
365 const uint8_t* s = log->
scratch;
374 get32(s + 16) == capacity &&
390 uint32_t found =
end;
static emmc_status_t probe(emmc_log_t *log, uint32_t k, bool *valid, uint32_t *session)
bool emmc_log_on_state(emmc_log_t *log, flight_state_t from, flight_state_t to, uint32_t now_ms)
uint32_t emmc_log_crc32(const void *data, uint32_t len)
emmc_status_t emmc_log_service(emmc_log_t *log, uint32_t now_ms)
static emmc_status_t format(emmc_log_t *log)
emmc_status_t emmc_log_init(emmc_log_t *log, const emmc_port_t *port, void *context, const emmc_log_config_t *config, emmc_log_chunk_t *chunks, uint8_t chunk_count, uint8_t *scratch)
static emmc_status_t search(emmc_log_t *log, uint32_t lo, uint32_t hi, uint32_t *end)
static void close_block(emmc_log_t *log)
uint8_t emmc_log_backlog(const emmc_log_t *log)
bool emmc_log_append(emmc_log_t *log, uint8_t type, uint32_t t_ms, const void *data, uint8_t len)
static bool put_record(emmc_log_t *log, uint8_t type, uint32_t t_ms, const void *data, uint8_t len)
static uint32_t get32(const uint8_t *p)
static uint16_t get16(const uint8_t *p)
static void put16(uint8_t *p, uint16_t v)
static void chunk_complete(emmc_log_t *log)
static emmc_status_t mount(emmc_log_t *log)
static void stop(emmc_log_t *log, emmc_disk_state_t why)
static void seal(emmc_log_t *log)
static void put32(uint8_t *p, uint32_t v)
static bool acquire(emmc_log_t *log)
static uint8_t * block_at(emmc_log_t *log, uint8_t chunk, uint8_t block)
static void release_write_chunk(emmc_log_t *log, bool written)
void emmc_log_flush(emmc_log_t *log)
static bool keep(emmc_log_t *log, uint8_t type, uint32_t t_ms, const void *data, uint8_t len)
static void unlock(emmc_log_t *log)
emmc_log_config_t emmc_log_default_config(void)
#define EMMC_LOG_RECORD_HEADER_BYTES
#define EMMC_LOG_MAX_CHUNKS
#define EMMC_LOG_KIND_PAD
#define EMMC_LOG_HEADER_BYTES
#define EMMC_REC_SESSION_END
#define EMMC_LOG_BLOCK_MAGIC
#define EMMC_LOG_CHUNK_BYTES
#define EMMC_LOG_PAYLOAD_BYTES
#define EMMC_LOG_CHUNK_BLOCKS
#define EMMC_LOG_SUPER_MAGIC
#define EMMC_LOG_DEFAULT_DATA_START
#define EMMC_LOG_LAYOUT_VERSION
#define EMMC_LOG_KIND_DATA
#define EMMC_REC_SESSION_START
static const emmc_port_t port
std::vector< daq::SensorDataChunkCollection > chunks
bool flight_state_logs_to_emmc(flight_state_t state)
static const idle_config_t config
*brief create JSON pointer *sa reference_tokens const string_t const string_t & b
*brief create JSON pointer *sa reference_tokens end()
*brief user defined string literal for JSON values *sa std::size_t n
uint8_t bytes[EMMC_LOG_CHUNK_BYTES]
uint32_t flush_interval_ms
uint32_t unreported_drops
emmc_chunk_state_t chunk_state[EMMC_LOG_MAX_CHUNKS]
uint32_t chunk_arm[EMMC_LOG_MAX_CHUNKS]
emmc_log_chunk_t * chunks
emmc_status_t(* write)(void *context, uint32_t lba, const void *buffer, uint32_t count, uint32_t budget_ms)
void(* unlock)(void *context)
emmc_status_t(* read)(void *context, uint32_t lba, void *buffer, uint32_t count, uint32_t budget_ms)
void(* lock)(void *context)
emmc_status_t(* start)(void *context, uint32_t *block_count)
static uint8_t scratch[BS]