STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
emmc_port.h
Go to the documentation of this file.
1#ifndef STAR_EMMC_PORT_H
2#define STAR_EMMC_PORT_H
3
4/*
5 * The seam between the flight log and the eMMC hardware.
6 *
7 * The log (emmc_log.c) never calls HAL. It sees the eMMC as an array of
8 * 512-byte blocks through these callbacks. On the board they are
9 * emmc_stm32.c (SDMMC1, 4-bit, IDMA); on a laptop they are a RAM disk
10 * (tests/emmc). See EMMC-ARCHITECTURE.md.
11 */
12
13#include <stdint.h>
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19/* JEDEC eMMC sector; DATA_SECTOR_SIZE = 0 (512 B) on THGBMTG5D1LBAIL. */
20#define EMMC_BLOCK_SIZE 512U
21
22typedef enum {
24 EMMC_ERR_IO, /* the card or bus reported an error (CRC, status) */
25 EMMC_ERR_TIMEOUT, /* no completion within budget_ms */
26 EMMC_ERR_NOT_READY, /* start() not run or failed */
27 EMMC_ERR_PARAM /* bad LBA/count/buffer (alignment, DMA reach) */
29
30typedef struct {
31 /*
32 * Bring the card up once per power-up: release RST_n, identification at
33 * <= 400 kHz, 4-bit bus, data clock <= 26 MHz (legacy timing). Report the
34 * user-area size in blocks (EXT_CSD SEC_COUNT). The log calls it once;
35 * the datasheet warns that repeated CMD0/CMD1 loops cause read disturb.
36 */
37 emmc_status_t (*start)(void* context, uint32_t* block_count);
38
39 /*
40 * Blocking transfers of `count` whole blocks at block address `lba`.
41 * `buffer` is 32-byte aligned and DMA-reachable (on the H723: AXI SRAM,
42 * never DTCM). Return only after the card is back in the transfer state
43 * (writes: programming finished), or EMMC_ERR_TIMEOUT after budget_ms.
44 */
45 emmc_status_t (*read)(void* context, uint32_t lba, void* buffer,
46 uint32_t count, uint32_t budget_ms);
47 emmc_status_t (*write)(void* context, uint32_t lba, const void* buffer,
48 uint32_t count, uint32_t budget_ms);
49
50 /*
51 * Optional (NULL = single context). Guards the log's chunk queue between
52 * the tasks that append records and the task that writes. Held only for
53 * memcpy-sized work, never across a transfer.
54 */
55 void (*lock)(void* context);
56 void (*unlock)(void* context);
58
59#ifdef __cplusplus
60}
61#endif
62#endif
emmc_status_t
Definition emmc_port.h:22
@ EMMC_ERR_NOT_READY
Definition emmc_port.h:26
@ EMMC_ERR_IO
Definition emmc_port.h:24
@ EMMC_ERR_PARAM
Definition emmc_port.h:27
@ EMMC_ERR_TIMEOUT
Definition emmc_port.h:25
@ EMMC_OK
Definition emmc_port.h:23
size_type count(const key_type &key) const
Definition json.hpp:19264
emmc_status_t(* write)(void *context, uint32_t lba, const void *buffer, uint32_t count, uint32_t budget_ms)
Definition emmc_port.h:47
void(* unlock)(void *context)
Definition emmc_port.h:56
emmc_status_t(* read)(void *context, uint32_t lba, void *buffer, uint32_t count, uint32_t budget_ms)
Definition emmc_port.h:45
void(* lock)(void *context)
Definition emmc_port.h:55
emmc_status_t(* start)(void *context, uint32_t *block_count)
Definition emmc_port.h:37