55static const char*
s_tag =
"USBPMSC";
69typedef enum : uint8_t {
86typedef enum : uint8_t {
97typedef enum : uint8_t {
109typedef enum : uint32_t {
118typedef enum : uint32_t {
129typedef enum : uint8_t {
252 for (uint32_t i = 0U; i < len; ++i) {
274 for (uint32_t i = 0U; i < len; ++i) {
344 uint32_t data_buf_capacity,
399 if (data_buf_capacity == 0U) {
430 uint32_t data_buf_capacity,
static const char * s_tag
Logging / check tag.
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.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_hw_init_failed
Hardware peripheral failed to initialise.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_info_val(tag, message, value)
RA8 log info val.
#define ra8_log_error_val(tag, message, value)
RA8 log error val.
#define ra8_log_info(tag, message)
RA8 log info.
Native USB controller driver public API (device + host modes).
@ k_ra8_usb_ep_type_bulk
Bulk transfer.
ra8_err_t ra8_usb_device_init(ra8_usb_speed_t speed)
Bring up a USB controller in device mode.
ra8_err_t ra8_usb_device_deinit(ra8_usb_speed_t speed)
Tear down a USB controller and drop its MSTP reference.
ra8_err_t ra8_usb_configure_endpoint(ra8_usb_speed_t speed, uint8_t pipe_num, uint8_t ep_addr, ra8_usb_ep_dir_t dir, ra8_usb_ep_type_t type, uint16_t max_packet)
Configure a non-control PIPE for IN or OUT bulk / interrupt / iso transfers.
ra8_err_t ra8_usb_device_attach(ra8_usb_speed_t speed, bool attached)
Raise / drop the D+ pull-up to advertise the device to the host.
@ k_ra8_usb_ep_dir_in
Device -> host.
@ k_ra8_usb_ep_dir_out
Host -> device.
ra8_usb_speed_t
Selects which controller instance the call targets.
@ k_ra8_usb_speed_hs
High-Speed controller (USBHS @ 0x40351000).
@ k_ra8_usb_speed_fs
Full-Speed controller (USBFS @ 0x40250000).
ra8_usb_pmsc_csw_offset_t
Byte offsets inside the 13-byte CSW.
@ k_ra8_pmsc_csw_off_status
bCSWStatus.
@ k_ra8_pmsc_csw_off_signature
dCSWSignature [4].
@ k_ra8_pmsc_csw_off_tag
dCSWTag [4].
@ k_ra8_pmsc_csw_off_residue
dCSWDataResidue.
static void internal_configure_pipes(void)
Configure the two device-MSC bulk pipes against the local endpoints.
ra8_usb_pmsc_initial_tag_t
Initial value of the cached BOT dCBWTag.
@ k_ra8_pmsc_initial_tag
Reset value.
ra8_err_t ra8_usb_pmsc_close(void)
Tear down the device-MSC driver and release the controller.
static uint32_t internal_unpack_u32_le(const uint8_t *src)
Unpack a uint32 from 4 little-endian bytes.
static void internal_dispatch_advance_state(uint32_t data_len)
Advance BOT state after a successful CDB dispatch.
ra8_usb_pmsc_cbw_offset_t
Byte offsets inside the 31-byte CBW header.
@ k_ra8_pmsc_cbw_off_flags
bmCBWFlags.
@ k_ra8_pmsc_cbw_off_lun
bCBWLUN (low nib).
@ k_ra8_pmsc_cbw_off_cdb
CBWCB [16].
@ k_ra8_pmsc_cbw_off_tag
dCBWTag [4].
@ k_ra8_pmsc_cbw_off_signature
dCBWSignature [4].
@ k_ra8_pmsc_cbw_off_cdb_length
bCBWCBLength (low 5).
@ k_ra8_pmsc_cbw_off_data_length
dCBWDataTransferLen.
void priv_zero_bytes(uint8_t *dst, uint32_t len)
Zero len bytes at dst byte-by-byte.
ra8_err_t ra8_usb_pmsc_dispatch_command(uint8_t *data_buf, uint32_t data_buf_capacity, uint32_t *data_len, ra8_usb_pmsc_csw_status_t *csw_status)
Run the SCSI command currently parked in the BOT state.
ra8_usb_pmsc_state_data_t g_usb_pmsc_state
Singleton shadow state shared by both device-MSC TUs.
static void internal_pack_u32_le(uint32_t value, uint8_t *dst)
Pack a uint32 into 4 little-endian bytes.
static ra8_err_t internal_dispatch_preconditions(uint32_t data_buf_capacity)
Validate dispatch_command preconditions (driver state + bot phase + buffer capacity).
ra8_err_t ra8_usb_pmsc_init(ra8_usb_speed_t speed)
Bring up the device-MSC driver on a chosen USB controller.
ra8_err_t ra8_usb_pmsc_build_csw(ra8_usb_pmsc_csw_status_t csw_status, uint32_t residue, uint8_t *out_csw)
Build the 13-byte CSW for the in-flight command.
static void internal_copy_bytes(uint8_t *dst, const uint8_t *src, uint32_t len)
Copy len bytes from src to dst byte-by-byte.
static ra8_err_t internal_dispatch_scsi(uint8_t *data_buf, uint32_t data_buf_capacity, uint32_t *data_len, ra8_usb_pmsc_csw_status_t *csw_status)
Dispatch the cached CDB to the right SCSI handler.
ra8_usb_pmsc_signature_t
BOT wrapper signatures (USB MSC BBB rev 1.0 sec 5).
@ k_ra8_pmsc_csw_signature
'USBS' little-endian.
@ k_ra8_pmsc_cbw_signature
'USBC' little-endian.
ra8_err_t ra8_usb_pmsc_step(void)
Drive the BOT (Bulk-Only Transport) state machine forward by one step.
ra8_err_t ra8_usb_pmsc_feed_cbw(const uint8_t *cbw)
Inject a CBW directly into the BOT state machine.
ra8_usb_pmsc_cbw_flag_t
bmCBWFlags direction bit values.
@ k_ra8_pmsc_cbw_flag_data_in
Device -> host.
@ k_ra8_pmsc_cbw_flag_data_out
Host -> device.
static uint16_t internal_bulk_max_packet(ra8_usb_speed_t speed)
Pick the bulk-max-packet ceiling matching the negotiated speed.
ra8_err_t ra8_usb_pmsc_attach_storage(const ra8_usb_pmsc_storage_t *storage)
Bind a caller-owned storage backend to the device-MSC class.
ra8_usb_pmsc_lun_mask_t
Field-width masks for bCBWLUN + bCBWCBLength bytes.
@ k_ra8_pmsc_lun_field_mask
Low 4 bits of bCBWLUN.
@ k_ra8_pmsc_cdb_field_mask
Low 5 bits of bCBWCBLen.
Native USB device-side MSC (Mass Storage Class) class layer.
@ k_ra8_pmsc_pipe_bulk_out
PIPE4 -> local EP bulk OUT.
@ k_ra8_pmsc_pipe_bulk_in
PIPE3 -> local EP bulk IN.
@ k_ra8_pmsc_ep_bulk_in
Bulk-IN endpoint number.
@ k_ra8_pmsc_ep_bulk_out
Bulk-OUT endpoint number.
@ k_ra8_pmsc_bulk_max_packet_fs
Bulk size at full speed.
@ k_ra8_pmsc_bulk_max_packet_hs
Bulk size at high speed.
ra8_usb_pmsc_csw_status_t
CSW status field values the device returns after a CBW.
@ k_ra8_pmsc_csw_status_passed
Command succeeded.
@ k_ra8_pmsc_csw_status_failed
Command failed.
@ k_ra8_pmsc_scsi_write_10
WRITE(10).
@ k_ra8_pmsc_scsi_read_capacity_10
READ CAPACITY(10).
@ k_ra8_pmsc_scsi_read_10
READ(10).
@ k_ra8_pmsc_scsi_test_unit_ready
TEST UNIT READY.
@ k_ra8_pmsc_scsi_inquiry
INQUIRY.
@ k_ra8_pmsc_scsi_request_sense
REQUEST SENSE.
@ k_ra8_pmsc_scsi_mode_sense_6
MODE SENSE(6).
Cross-TU surface shared between the device-MSC BOT statemachine (ra8_usb_pmsc.c) and the SCSI command...
ra8_err_t priv_handle_write10(const uint8_t *data_buf, uint32_t *out_len)
Run a SCSI WRITE(10) – the data buffer holds the host-supplied payload.
@ k_ra8_pmsc_shift_byte3
RA8 pmsc shift byte3.
@ k_ra8_pmsc_shift_byte1
RA8 pmsc shift byte1.
@ k_ra8_pmsc_shift_byte0
RA8 pmsc shift byte0.
@ k_ra8_pmsc_shift_byte2
RA8 pmsc shift byte2.
ra8_err_t priv_handle_read10(uint8_t *data_buf, uint32_t capacity, uint32_t *out_len)
Run a SCSI READ(10).
ra8_err_t priv_handle_inquiry(uint8_t *data_buf, uint32_t capacity, uint32_t *out_len)
Build the 36-byte SCSI INQUIRY response.
@ k_ra8_pmsc_cdb_off_opcode
Operation Code (CDB byte 0).
@ k_ra8_pmsc_byte_mask
RA8 pmsc byte mask.
ra8_err_t priv_handle_mode_sense(uint8_t *data_buf, uint32_t capacity, uint32_t *out_len)
Build the minimal 4-byte MODE SENSE(6) header response.
ra8_err_t priv_handle_request_sense(uint8_t *data_buf, uint32_t capacity, uint32_t *out_len)
Build the 18-byte REQUEST SENSE response.
@ k_ra8_pmsc_cdb_max_len
CDB ceiling.
@ k_ra8_pmsc_csw_len
CSW length (BBB sec 5.2).
ra8_err_t priv_handle_read_capacity(uint8_t *data_buf, uint32_t capacity, uint32_t *out_len)
Build the 8-byte READ_CAPACITY(10) response.
@ k_ra8_pmsc_state_idle
Pre-CBW.
@ k_ra8_pmsc_state_data_tx
Push data on bulk-IN.
@ k_ra8_pmsc_state_data_rx
Pull data on bulk-OUT.
@ k_ra8_pmsc_state_cbw_rx
CBW arrived on bulk-OUT.
@ k_ra8_pmsc_state_cdb_decode
Dispatch to a SCSI handler.
@ k_ra8_pmsc_state_csw_tx
Push CSW on bulk-IN.
Singleton shadow state for the device-MSC driver.
Caller-owned storage backend bound to the device-MSC class.
ra8_usb_pmsc_get_inquiry_fn_t get_inquiry
INQUIRY hook.
ra8_usb_pmsc_read_block_fn_t read_block
Block read hook.
ra8_usb_pmsc_get_capacity_fn_t get_capacity
Capacity hook.
ra8_usb_pmsc_write_block_fn_t write_block
Block write hook.