ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
board_periph_sd_internal.h
Go to the documentation of this file.
1
17
18#pragma once
19
20#include <stddef.h>
21#include <stdint.h>
22
23#include "ra8_attributes.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
71
76typedef enum : uint8_t {
82
86typedef struct {
88 uint64_t image_len;
89 bool attached;
90 uint8_t fat_bits;
93 bool app_cmd;
94 bool ready;
95 uint8_t cmd[k_sd_cmd_len];
96 uint32_t cmd_idx;
98 uint32_t resp_len;
99 uint32_t resp_pos;
101 bool wr_multi;
102 uint64_t wr_off;
103 uint32_t wr_cnt;
105 bool rd_multi;
106 uint64_t rd_off;
108 uint32_t erase_start;
109 uint32_t erase_end;
111
113typedef enum : uint32_t {
114 k_sd_csd_unit = 512U * 1024U,
115 k_sd_save_max_bytes = 2U * 1024U * 1024U * 1024U,
116 k_unit_kib = 1024U,
119
122
124typedef enum : uint32_t {
128
143
164RA8_PRIV [[nodiscard]] bool priv_board_sd_format_fat16(int image_fd,
165 uint32_t total_sectors,
166 const char* label,
167 uint32_t* out_spc);
168
188RA8_PRIV [[nodiscard]] bool priv_board_sd_format_fat32(int image_fd,
189 uint32_t total_sectors,
190 const char* label,
191 uint32_t* out_spc);
192
194RA8_PRIV [[nodiscard]] bool priv_board_sd_storage_read(uint64_t offset, void* dst, size_t count);
196RA8_PRIV [[nodiscard]] bool
197priv_board_sd_storage_write(uint64_t offset, const void* src, size_t count);
199RA8_PRIV [[nodiscard]] bool priv_board_sd_storage_zero(uint64_t offset, uint64_t count);
200
216RA8_PRIV void priv_board_sd_label_field(uint8_t* dst, const char* label);
217
218#ifdef __cplusplus
219}
220#endif
bool priv_board_sd_storage_write(uint64_t offset, const void *src, size_t count)
Write exactly to the current sparse backend at a checked byte offset.
bool priv_board_sd_storage_zero(uint64_t offset, uint64_t count)
Make a checked byte range read as zero while preserving sparse storage.
board_sd_state_t g_board_sd
The single modelled SD card (defined in board_periph_sd.c).
board_sd_wr_phase_t
Block-write sub-state once a CMD24/CMD25 has been accepted.
@ k_sd_wr_idle
Not in a write transaction.
@ k_sd_wr_token
Awaiting the data-start (or stop-tran) token.
@ k_sd_wr_data
Collecting the 512 payload bytes.
@ k_sd_wr_crc
Collecting the trailing 2 CRC bytes.
sd_fat_bits_t
FAT flavour selectors shared by the formatter and the card model.
@ k_fat32_bits
FAT32 selector / label width.
@ k_fat16_bits
FAT16 selector.
board_sd_const32_t
SD sizing constants that exceed 16 bits.
@ k_sd_min_sectors
–sd-new floor: 32 KiB of sectors.
@ k_sd_save_max_bytes
–save-sd cap: 2 GiB.
@ k_sd_csd_unit
CSD v2.0 C_SIZE unit: 512 KiB.
@ k_unit_kib
Binary kilo multiplier (KiB).
bool priv_board_sd_storage_read(uint64_t offset, void *dst, size_t count)
Read exactly from the current sparse backend at a checked byte offset.
sd_fmt_const_t
FAT BPB field offsets + format constants.
@ k_fmt_fat32_pref
FAT32: preferred max clusters (bumps spc).
@ k_fmt_totsec16_max
Above this, use the 32-bit TotSec.
@ k_fmt_fat16_min
Min FAT16 data clusters.
@ k_fmt_root_ents
FAT16 root-directory entries.
@ k_fmt_volid
Arbitrary volume serial base.
@ k_fmt_fat16_max
Max FAT16 data clusters.
@ k_fmt_sec_bytes
Bytes per sector.
bool priv_board_sd_format_fat16(int image_fd, uint32_t total_sectors, const char *label, uint32_t *out_spc)
Format the attached sparse backend as a FAT16 volume.
board_sd_const_t
SD SPI-mode protocol and sizing constants (no magic numbers).
@ k_sd_csd_csize_b7
C_SIZE high byte offset in the CSD.
@ k_sd_tok_wmulti
Multi-block write data-start token.
@ k_sd_csd_v2
CSD_STRUCTURE = 01b (v2.0 / SDHC).
@ k_sd_resp_cap
R1 + token + 512 data + 2 CRC.
@ k_sd_r7_len
R1 + 4-byte tail.
@ k_sd_csd_csize
C_SIZE byte (=> 8 MiB modelled card).
@ k_sd_cmd_mask
Mask isolating the lead bits.
@ k_sd_crc_len
Trailing CRC16 bytes after a data block.
@ k_sd_data_error
Data-response token: backend write error.
@ k_sd_cmd_len
Command frame: opcode + 4 arg + crc.
@ k_sd_data_accept
Data-response token: block accepted.
@ k_sd_label_cap
Volume-label field: 11 chars + NUL.
@ k_sd_csd_off
C_SIZE LSB byte offset in the CSD.
@ k_sd_byte_bits
Bits per byte (shift amount).
@ k_sd_crc_poly
CRC16-CCITT polynomial.
@ k_sd_arg_sh1
Arg byte 1 shift.
@ k_sd_idle
Bus idle / CIPO-high byte.
@ k_sd_ocr_pwrccs
OCR byte 0: power-up done + CCS.
@ k_sd_r1_param_err
R1 parameter/backend range error.
@ k_sd_arg_sh0
Arg byte 0 (MSB) shift.
@ k_sd_idx_mask
Command index in the lead byte.
@ k_sd_ocr_volt
OCR byte 2: voltage window.
@ k_sd_block
Bytes per SD block.
@ k_sd_tok_stop
Multi-block write stop-tran token.
@ k_sd_cmd8_echo
CMD8 check pattern echo.
@ k_sd_r1_idle
R1 with IDLE set.
@ k_sd_read_error
Read data-error token: backend fault.
@ k_sd_tok_data
Single-block read / write data token.
@ k_sd_cmd_start
SPI command lead bits (01xxxxxx).
@ k_sd_csd_csize_b8
C_SIZE mid byte offset in the CSD.
@ k_sd_crc_msb
Top bit of the 16-bit CRC register.
@ k_sd_csize_b7_mask
C_SIZE field spans only 6 bits in b7.
@ k_sd_busy
CIPO held low while the card programs.
@ k_sd_csd_len
CSD register length.
@ k_sd_r1_ready
R1, card ready.
void priv_board_sd_label_field(uint8_t *dst, const char *label)
Copy a volume label into an 11-char space-padded 8.3 field.
bool priv_board_sd_format_fat32(int image_fd, uint32_t total_sectors, const char *label, uint32_t *out_spc)
Format the attached sparse backend as a FAT32 volume.
@ k_sd_byte_mask
Low-byte mask.
Definition main.c:78
Annotation-attribute framework macros for ra8-firmware.
#define RA8_PRIV
Module-private helper: shared across TUs but only inside one library.
@ k_fmt_label_len
Volume-label field width (bytes).
@ k_fmt_resv_f16
FAT12/16 reserved (boot) sectors.
@ k_fmt_spc_max
Largest sectors-per-cluster we set.
@ k_fmt_resv_f32
FAT32 reserved sectors.
The modelled card: backing image + command/response framing.
uint8_t cmd[k_sd_cmd_len]
Cmd.
uint32_t resp_pos
Resp pos.
char label[k_sd_label_cap]
Volume label (11 + NUL), for GUI.
bool ready
ACMD41 has completed.
uint32_t erase_start
CMD32 ERASE_WR_BLK_START block.
bool app_cmd
Previous command was CMD55 (APP_CMD).
uint64_t rd_off
Byte offset of the next streamed CMD18 block.
board_sd_wr_phase_t wr_phase
CMD24/CMD25 write sub-state.
bool attached
A --sd image is loaded.
bool wr_multi
Write is CMD25 (multi-block).
int image_fd
Owned anonymous sparse backing descriptor.
uint8_t fat_bits
12/16/32 if formatted by –sd-new, else 0.
bool rd_multi
An open CMD18 read stream.
uint64_t image_len
Image size in bytes (64-bit: cards > 4 GB).
uint32_t resp_len
Resp length.
uint64_t wr_off
Byte offset of the current block.
uint32_t cmd_idx
Cmd index.
uint32_t wr_cnt
Bytes seen in the data/CRC phase.
uint8_t resp[k_sd_resp_cap]
Resp.
uint8_t wr_block[k_sd_block]
Bounded block-write staging buffer.
bool collecting
Mid command-frame collection.
uint32_t erase_end
CMD33 ERASE_WR_BLK_END block.