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
15
extern
"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
36
typedef
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 */
50
}
emmc_card_info_t
;
51
52
/* Why a card is not the one the datasheet describes, or is wearing out. */
53
typedef
enum
{
54
EMMC_CARD_OK
= 0,
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 */
62
}
emmc_card_issue_t
;
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
*/
69
void
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
*/
78
uint32_t
emmc_card_check
(
const
emmc_card_info_t
*
info
);
79
80
#ifdef __cplusplus
81
}
82
#endif
83
#endif
info
static board_sleep_info_t info
Definition
board_sleep.c:14
emmc_card_issue_t
emmc_card_issue_t
Definition
emmc_card.h:53
EMMC_CARD_WRONG_SIZE
@ EMMC_CARD_WRONG_SIZE
Definition
emmc_card.h:57
EMMC_CARD_WRONG_PART
@ EMMC_CARD_WRONG_PART
Definition
emmc_card.h:56
EMMC_CARD_WEAR_WARNING
@ EMMC_CARD_WEAR_WARNING
Definition
emmc_card.h:59
EMMC_CARD_CACHE_ON
@ EMMC_CARD_CACHE_ON
Definition
emmc_card.h:61
EMMC_CARD_OK
@ EMMC_CARD_OK
Definition
emmc_card.h:54
EMMC_CARD_NO_RELIABLE_WRITE
@ EMMC_CARD_NO_RELIABLE_WRITE
Definition
emmc_card.h:60
EMMC_CARD_OLD_REVISION
@ EMMC_CARD_OLD_REVISION
Definition
emmc_card.h:58
EMMC_CARD_WRONG_MAKER
@ EMMC_CARD_WRONG_MAKER
Definition
emmc_card.h:55
emmc_card_check
uint32_t emmc_card_check(const emmc_card_info_t *info)
Definition
emmc_card.c:34
emmc_card_parse
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
emmc_card_info_t
Definition
emmc_card.h:36
emmc_card_info_t::rst_n_function
uint8_t rst_n_function
Definition
emmc_card.h:47
emmc_card_info_t::mid
uint8_t mid
Definition
emmc_card.h:37
emmc_card_info_t::sec_count
uint32_t sec_count
Definition
emmc_card.h:42
emmc_card_info_t::psn
uint32_t psn
Definition
emmc_card.h:40
emmc_card_info_t::cache_ctrl
uint8_t cache_ctrl
Definition
emmc_card.h:48
emmc_card_info_t::prv
uint8_t prv
Definition
emmc_card.h:39
emmc_card_info_t::device_type
uint8_t device_type
Definition
emmc_card.h:43
emmc_card_info_t::life_b
uint8_t life_b
Definition
emmc_card.h:46
emmc_card_info_t::ext_csd_rev
uint8_t ext_csd_rev
Definition
emmc_card.h:41
emmc_card_info_t::pnm
char pnm[7]
Definition
emmc_card.h:38
emmc_card_info_t::wr_rel_set
uint8_t wr_rel_set
Definition
emmc_card.h:49
emmc_card_info_t::life_a
uint8_t life_a
Definition
emmc_card.h:45
emmc_card_info_t::pre_eol
uint8_t pre_eol
Definition
emmc_card.h:44
firmware
Flight_Computer
src
chips
emmc_card.h
Generated by
1.15.0