STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
emmc_card.h
Go to the documentation of this file.
1#ifndef STAR_EMMC_CARD_H
2#define STAR_EMMC_CARD_H
3
4/*
5 * Reads the eMMC's identity registers (CID, EXT_CSD) and checks them against
6 * the THGBMTG5D1LBAIL datasheet (KIOXIA, rev 1.0, 2021-10-07). Pure parsing,
7 * no I/O: the board adapter reads the registers, this decides what they
8 * mean. Values quoted are the datasheet's (pp. 5-11).
9 */
10
11#include <stdbool.h>
12#include <stdint.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18#define EMMC_CARD_MID_KIOXIA 0x11U /* CID MID */
19#define EMMC_CARD_PNM "004GA1" /* CID PNM */
20#define EMMC_CARD_SEC_COUNT 0x00760000UL /* 3,959,422,976 B */
21#define EMMC_CARD_EXT_CSD_REV_MIN 7U /* eMMC 5.0 */
22
23/* EXT_CSD byte offsets used here (JEDEC JESD84-B50). */
24#define EMMC_EXT_CSD_CACHE_CTRL 33U
25#define EMMC_EXT_CSD_RST_N_FUNCTION 162U
26#define EMMC_EXT_CSD_WR_REL_SET 167U
27#define EMMC_EXT_CSD_BUS_WIDTH 183U
28#define EMMC_EXT_CSD_HS_TIMING 185U
29#define EMMC_EXT_CSD_REV 192U
30#define EMMC_EXT_CSD_DEVICE_TYPE 196U
31#define EMMC_EXT_CSD_SEC_COUNT 212U /* 4 bytes, little-endian */
32#define EMMC_EXT_CSD_PRE_EOL_INFO 267U
33#define EMMC_EXT_CSD_LIFE_TIME_A 268U
34#define EMMC_EXT_CSD_LIFE_TIME_B 269U
35
36typedef struct {
37 uint8_t mid;
38 char pnm[7]; /* six characters + NUL */
39 uint8_t prv;
40 uint32_t psn; /* serial number: worth logging with each session */
41 uint8_t ext_csd_rev;
42 uint32_t sec_count;
43 uint8_t device_type;
44 uint8_t pre_eol; /* 1 normal, 2 warning (80 % reserve used), 3 urgent */
45 uint8_t life_a; /* 1 = 0-10 % of rated life used ... 0x0B exceeded */
46 uint8_t life_b;
47 uint8_t rst_n_function; /* 0: RST_n pin ignored (shipped value) */
48 uint8_t cache_ctrl; /* 0: volatile cache off (shipped value) */
49 uint8_t wr_rel_set; /* bit 0: reliable writes in the user area */
51
52/* Why a card is not the one the datasheet describes, or is wearing out. */
53typedef enum {
55 EMMC_CARD_WRONG_MAKER = 1U << 0, /* MID != 0x11 */
56 EMMC_CARD_WRONG_PART = 1U << 1, /* PNM != "004GA1" */
57 EMMC_CARD_WRONG_SIZE = 1U << 2, /* SEC_COUNT != 0x760000 */
58 EMMC_CARD_OLD_REVISION = 1U << 3, /* EXT_CSD_REV < 7 */
59 EMMC_CARD_WEAR_WARNING = 1U << 4, /* PRE_EOL >= 2 or life >= 0x09 */
60 EMMC_CARD_NO_RELIABLE_WRITE = 1U << 5, /* WR_REL_SET bit 0 clear */
61 EMMC_CARD_CACHE_ON = 1U << 6 /* a power cut can lose cached data */
63
64/*
65 * `cid` is the CID as four 32-bit words, cid[0] = bits 127..96 (the order
66 * the STM32 SDMMC response registers and HAL's hmmc->CID use). `ext_csd` is
67 * the 512-byte EXT_CSD.
68 */
69void emmc_card_parse(const uint32_t cid[4], const uint8_t ext_csd[512],
70 emmc_card_info_t* out);
71
72/*
73 * Bitwise OR of emmc_card_issue_t; EMMC_CARD_OK (0) when nothing is off.
74 * None of these stops the log (it works on any eMMC 4.4+ with 512 B
75 * sectors); they are reported. Whether one blocks Arm is the open failure
76 * policy question (#137 section 7).
77 */
79
80#ifdef __cplusplus
81}
82#endif
83#endif
static board_sleep_info_t info
Definition board_sleep.c:14
emmc_card_issue_t
Definition emmc_card.h:53
@ EMMC_CARD_WRONG_SIZE
Definition emmc_card.h:57
@ EMMC_CARD_WRONG_PART
Definition emmc_card.h:56
@ EMMC_CARD_WEAR_WARNING
Definition emmc_card.h:59
@ EMMC_CARD_CACHE_ON
Definition emmc_card.h:61
@ EMMC_CARD_OK
Definition emmc_card.h:54
@ EMMC_CARD_NO_RELIABLE_WRITE
Definition emmc_card.h:60
@ EMMC_CARD_OLD_REVISION
Definition emmc_card.h:58
@ EMMC_CARD_WRONG_MAKER
Definition emmc_card.h:55
uint32_t emmc_card_check(const emmc_card_info_t *info)
Definition emmc_card.c:34
void emmc_card_parse(const uint32_t cid[4], const uint8_t ext_csd[512], emmc_card_info_t *out)
Definition emmc_card.c:5
uint8_t rst_n_function
Definition emmc_card.h:47
uint32_t sec_count
Definition emmc_card.h:42
uint8_t cache_ctrl
Definition emmc_card.h:48
uint8_t device_type
Definition emmc_card.h:43
uint8_t ext_csd_rev
Definition emmc_card.h:41
uint8_t wr_rel_set
Definition emmc_card.h:49
uint8_t pre_eol
Definition emmc_card.h:44