sdio_host/
emmc_cmd.rs

1//! eMMC-specific command definitions.
2
3use crate::common_cmd::{cmd, Cmd, R1, R3};
4
5/// CMD1: Ask all cards to send their supported OCR, or become inactive if they cannot be
6/// supported.
7pub fn send_op_cond(ocr: u32) -> Cmd<R3> {
8    cmd(1, ocr)
9}
10
11/// CMD3: Assigns relative address (RCA) to the Device
12pub fn assign_relative_address(address: u16) -> Cmd<R1> {
13    cmd(3, (address as u32) << 16)
14}
15
16/// Specifies a method of modifying a field of EXT_CSD. Used for CMD6.
17pub enum AccessMode {
18    // The 0b00 pattern corresponds to Command Set, which has different semantics.
19    SetBits = 0b01,
20    ClearBits = 0b10,
21    WriteByte = 0b11,
22}
23
24/// Uses CMD6 to modify a field of the EXT_CSD.
25pub fn modify_ext_csd(access_mode: AccessMode, index: u8, value: u8) -> Cmd<R1> {
26    let arg = 0u32 | ((access_mode as u32) << 24) | ((index as u32) << 16) | ((value as u32) << 8);
27    cmd(6, arg)
28}
29
30/// CMD8: Device sends its EXT_CSD register as a block of data.
31pub fn send_ext_csd() -> Cmd<R1> {
32    cmd(8, 0)
33}
34
35/// CMD14: Host reads the reversed bus testing data pattern from a card
36pub fn bustest_read() -> Cmd<R1> {
37    cmd(14, 0)
38}
39
40/// CMD19: Host sends bus test pattern to a card
41pub fn bustest_write() -> Cmd<R1> {
42    cmd(19, 0)
43}
44
45/// CMD23: Defines the number of blocks (read/write) for a block read or write
46/// operation
47pub fn set_block_count(blockcount: u16) -> Cmd<R1> {
48    cmd(23, blockcount as u32)
49}
50
51/// CMD35: Sets the address of the first erase group within a range to be
52/// selected for erase
53///
54/// Address is either byte address or sector address (set in OCR)
55pub fn erase_group_start(address: u32) -> Cmd<R1> {
56    cmd(35, address)
57}
58
59/// CMD36: Sets the address of the last erase group within a continuous range to
60/// be selected for erase
61///
62/// Address is either byte address or sector address (set in OCR)
63pub fn erase_group_end(address: u32) -> Cmd<R1> {
64    cmd(36, address)
65}