ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_io_blockdev_usbmsc.c
Go to the documentation of this file.
1
22
24
25#include <stdint.h>
26
27#include "ra8_attributes.h"
28#include "ra8_check.h"
29#include "ra8_err.h"
30#include "ra8_io_blockdev.h"
32#include "ra8_usb_hmsc.h"
33
35static const char* const s_tag = "ra8_io_blockdev_usbmsc";
36
51
83static ra8_err_t internal_usbmsc_read(void* ctx, uint32_t lba, uint32_t count, uint8_t* buf)
84{
85 RA8_CHECK_NULL_PTR(ctx, s_tag, "ctx must not be nullptr");
86 RA8_CHECK_NULL_PTR(buf, s_tag, "buf must not be nullptr");
88 if (count > (uint32_t)k_ra8_io_usbmsc_max_transfer_blocks) {
90 }
91 return ra8_usb_hmsc_read10(st->lun, lba, (uint16_t)count, buf);
92}
93
125static ra8_err_t internal_usbmsc_write(void* ctx, uint32_t lba, uint32_t count, const uint8_t* buf)
126{
127 RA8_CHECK_NULL_PTR(ctx, s_tag, "ctx must not be nullptr");
128 RA8_CHECK_NULL_PTR(buf, s_tag, "buf must not be nullptr");
130 if (count > (uint32_t)k_ra8_io_usbmsc_max_transfer_blocks) {
132 }
133 return ra8_usb_hmsc_write10(st->lun, lba, (uint16_t)count, buf);
134}
135
167{
168 RA8_CHECK_NULL_PTR(ctx, s_tag, "ctx must not be nullptr");
169 RA8_CHECK_NULL_PTR(out, s_tag, "out must not be nullptr");
171 uint32_t blocks = 0;
172 uint32_t block_size = 0;
173 const ra8_err_t cap = ra8_usb_hmsc_read_capacity(st->lun, &blocks, &block_size);
174 if (cap != k_ra8_ok) {
175 return cap;
176 }
177 /* GCOVR_EXCL_START -- host-unreachable: everything below runs only after a
178 * completed READ CAPACITY(10), which needs a Bulk-Only Transport round trip.
179 * The plain-RAM ra8_fake_mmap backing has no USB SIE model, so the CBW push
180 * inside ra8_usb_hmsc always times out and this tail is bench territory --
181 * the same boundary ra8_usb_hmsc.c marks on its own command tails. */
182 if (block_size != (uint32_t)k_ra8_io_block_size_bytes) {
184 }
185 out->block_count = blocks;
190 out->must_erase_before_write = false;
191 out->read_only = false;
192 return k_ra8_ok;
193 /* GCOVR_EXCL_STOP */
194}
195
198 .read = internal_usbmsc_read,
199 .write = internal_usbmsc_write,
200 .erase = nullptr,
201 .get_caps = internal_usbmsc_get_caps,
202 .sync = nullptr,
203};
204
207 uint8_t lun)
208{
209 RA8_CHECK_NULL_PTR(bd, s_tag, "bd must not be nullptr");
210 RA8_CHECK_NULL_PTR(state, s_tag, "state must not be nullptr");
211 if (lun > (uint8_t)k_ra8_hmsc_max_lun) {
213 }
214 state->lun = lun;
215 bd->iface = &s_usbmsc_iface;
216 bd->ctx = state;
217 return k_ra8_ok;
218}
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_err_not_supported
Requested feature not compiled in, not wired, or not supported by this MCU variant.
Definition ra8_err.h:180
@ k_ra8_err_out_of_range
Sensor or peripheral output out of valid range.
Definition ra8_err.h:337
@ 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_usbmsc_init(ra8_io_blockdev_t *bd, ra8_io_blockdev_usbmsc_state_t *state, uint8_t lun)
Bind a hosted USB mass-storage backend into a caller-owned handle.
static const ra8_io_blockdev_iface_t s_usbmsc_iface
USB-MSC backend vtable.
static ra8_err_t internal_usbmsc_write(void *ctx, uint32_t lba, uint32_t count, const uint8_t *buf)
USB-MSC backend: write count blocks from buf at lba.
static ra8_err_t internal_usbmsc_get_caps(const void *ctx, ra8_io_blockdev_caps_t *out)
USB-MSC backend: report medium capabilities.
ra8_io_usbmsc_const_t
USB-MSC backend layout constants.
@ k_ra8_io_usbmsc_erase_unit_blocks
One logical block per erase unit.
static ra8_err_t internal_usbmsc_read(void *ctx, uint32_t lba, uint32_t count, uint8_t *buf)
USB-MSC backend: read count blocks at lba into buf.
ra8_io block-device backend over a hosted USB mass-storage device.
@ k_ra8_io_usbmsc_max_transfer_blocks
READ(10)/WRITE(10) block ceiling.
Native USB host-side MSC (Mass Storage Class) class layer.
ra8_err_t ra8_usb_hmsc_read_capacity(uint8_t target_lun, uint32_t *block_count, uint32_t *block_size)
Issue a SCSI READ CAPACITY(10) (opcode 0x25) over BBB.
@ k_ra8_hmsc_max_lun
Max LUNs the starter tracks.
ra8_err_t ra8_usb_hmsc_read10(uint8_t target_lun, uint32_t lba, uint16_t block_count, uint8_t *out_buf)
Issue a SCSI READ(10) (opcode 0x28) over BBB.
ra8_err_t ra8_usb_hmsc_write10(uint8_t target_lun, uint32_t lba, uint16_t block_count, const uint8_t *in_buf)
Issue a SCSI WRITE(10) (opcode 0x2A) over BBB.
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).
Caller-owned private state for a USB mass-storage block device.
uint8_t lun
SCSI logical unit this handle addresses (private).