ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_io_blockdev_sdhi.c
Go to the documentation of this file.
1
19
21
22#include <stdint.h>
23
24#include "ra8_attributes.h"
25#include "ra8_check.h"
26#include "ra8_err.h"
27#include "ra8_io_blockdev.h"
29#include "ra8_sdcard.h"
30
32static const char* const s_tag = "ra8_io_blockdev_sdhi";
33
40typedef enum : uint32_t {
43
75internal_sdhi_read(void* ctx, uint32_t lba, uint32_t count, uint8_t* buf)
76{
77 (void)ctx;
78 RA8_CHECK_NULL_PTR(buf, s_tag, "buf must not be nullptr");
79 return ra8_sdcard_read_blocks(lba, buf, count);
80}
81
113internal_sdhi_write(void* ctx, uint32_t lba, uint32_t count, const uint8_t* buf)
114{
115 (void)ctx;
116 RA8_CHECK_NULL_PTR(buf, s_tag, "buf must not be nullptr");
117 return ra8_sdcard_write_blocks(lba, buf, count);
118}
119
147{
148 (void)ctx;
149 RA8_CHECK_NULL_PTR(out, s_tag, "out must not be nullptr");
150 uint32_t blocks = 0;
151 const ra8_err_t cap = ra8_sdcard_get_capacity(&blocks);
152 if (cap != k_ra8_ok) {
153 return cap;
154 }
155 out->block_count = blocks;
160 out->must_erase_before_write = false;
161 out->read_only = false;
162 return k_ra8_ok;
163}
164
167 .read = internal_sdhi_read,
168 .write = internal_sdhi_write,
169 .erase = nullptr,
170 .get_caps = internal_sdhi_get_caps,
171 .sync = nullptr,
172};
173
175{
176 RA8_CHECK_NULL_PTR(bd, s_tag, "bd must not be nullptr");
177 bd->iface = &s_sdhi_iface;
178 bd->ctx = nullptr;
179 return k_ra8_ok;
180}
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Definition ra8_check.h:243
Error Code Definitions for ra8-firmware.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
ra8_io block-device fabric – one LBA vtable across every storage medium.
struct ra8_io_blockdev_iface ra8_io_blockdev_iface_t
@ k_ra8_io_erase_value_zero
Block reads back as 0x00 after erase.
@ k_ra8_io_block_size_bytes
Bytes per logical block (the only size).
Backend implementation contract for the ra8_io block-device fabric.
ra8_err_t ra8_io_blockdev_sdhi_init(ra8_io_blockdev_t *bd)
Bind the native-SDHI SD-card backend into a caller-owned handle.
static ra8_err_t internal_sdhi_write(void *ctx, uint32_t lba, uint32_t count, const uint8_t *buf)
Native-SDHI backend: write count blocks from buf at lba.
ra8_io_sdhi_const_t
Native-SDHI backend layout constants.
@ k_ra8_io_sdhi_erase_unit_blocks
One logical block per erase unit.
static ra8_err_t internal_sdhi_read(void *ctx, uint32_t lba, uint32_t count, uint8_t *buf)
Native-SDHI backend: read count blocks at lba into buf.
static ra8_err_t internal_sdhi_get_caps(const void *ctx, ra8_io_blockdev_caps_t *out)
Native-SDHI backend: report medium capabilities.
static const ra8_io_blockdev_iface_t s_sdhi_iface
Native-SDHI backend vtable.
ra8_io block-device backend over the native SDHI SD-card controller.
SD card driver layered on top of the RA8D2 SDHI peripheral.
ra8_err_t ra8_sdcard_write_blocks(uint32_t lba, const uint8_t *buf, uint32_t count)
Write count 512-byte blocks starting at lba.
Definition ra8_sdcard.c:628
ra8_err_t ra8_sdcard_get_capacity(uint32_t *out_blocks)
Return card capacity in 512-byte blocks.
Definition ra8_sdcard.c:644
ra8_err_t ra8_sdcard_read_blocks(uint32_t lba, uint8_t *buf, uint32_t count)
Read count 512-byte blocks starting at lba.
Definition ra8_sdcard.c:612
Static properties a backend reports about its medium.
uint32_t erase_unit_blocks
Erase granularity, in logical blocks.
uint32_t block_count
Total addressable logical blocks.
bool must_erase_before_write
true => program needs a prior erase.
bool read_only
true => writes/erases are rejected.
uint8_t erase_value
Post-erase byte (ra8_io_erase_value_t).
uint16_t logical_block_bytes
Logical block size (always 512).
uint32_t program_size_bytes
Minimum program granularity in bytes.
Caller-allocated block-device handle binding a backend to its context.
const ra8_io_blockdev_iface_t * iface
Bound backend vtable (private).
void * ctx
Backend-private context (private).