ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_usb_hmsc.h
Go to the documentation of this file.
1
46
47#pragma once
48
49#ifdef __cplusplus
50extern "C" {
51#endif
52
53#include <stdint.h>
54
55#include "ra8_err.h"
56#include "ra8_usb.h"
57
58/* =============================================================================
59 * Constants
60 * =============================================================================
61 */
62
77
86
101
116
126typedef enum : uint8_t {
129
143
160
174
186typedef struct {
188 uint8_t bulk_in_ep;
189 uint8_t bulk_out_ep;
190 uint8_t max_lun;
194 uint16_t vendor_id;
195 uint16_t product_id;
197
206typedef struct {
209 uint8_t removable;
210 uint8_t version;
211 uint8_t vendor_id[8];
212 uint8_t product_id[16];
213 uint8_t product_revision[4];
215
229typedef void (*ra8_usb_hmsc_attach_fn_t)(void* ctx, const ra8_usb_hmsc_device_t* device);
230
231/* =============================================================================
232 * Lifecycle
233 * =============================================================================
234 */
235
264[[nodiscard]] ra8_err_t ra8_usb_hmsc_init(ra8_usb_speed_t speed);
265
282[[nodiscard]] ra8_err_t ra8_usb_hmsc_close(void);
283
317
318/* =============================================================================
319 * Attach callback
320 * =============================================================================
321 */
322
346[[nodiscard]] ra8_err_t ra8_usb_hmsc_attach_callback(ra8_usb_hmsc_attach_fn_t on_attach, void* ctx);
347
348/* =============================================================================
349 * SCSI commands (Bulk-Only Transport)
350 * =============================================================================
351 */
352
381[[nodiscard]] ra8_err_t ra8_usb_hmsc_inquiry(uint8_t target_lun,
383
413[[nodiscard]] ra8_err_t
414ra8_usb_hmsc_read_capacity(uint8_t target_lun, uint32_t* block_count, uint32_t* block_size);
415
447[[nodiscard]] ra8_err_t
448ra8_usb_hmsc_read10(uint8_t target_lun, uint32_t lba, uint16_t block_count, uint8_t* out_buf);
449
479[[nodiscard]] ra8_err_t
480ra8_usb_hmsc_write10(uint8_t target_lun, uint32_t lba, uint16_t block_count, const uint8_t* in_buf);
481
482/* =============================================================================
483 * Test / introspection helpers
484 * =============================================================================
485 */
486
518[[nodiscard]] ra8_err_t ra8_usb_hmsc_build_cbw(uint8_t target_lun,
519 uint32_t data_transfer_length,
520 bool data_in,
521 const uint8_t* cdb,
522 uint8_t cdb_len,
523 uint8_t* out_cbw);
524
550[[nodiscard]] ra8_err_t ra8_usb_hmsc_decode_csw(const uint8_t* csw,
551 uint32_t expected_tag,
552 ra8_usb_hmsc_csw_status_t* out_status);
553
554#ifdef __cplusplus
555}
556#endif
Error Code Definitions for ra8-firmware.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
Native USB controller driver public API (device + host modes).
ra8_usb_speed_t
Selects which controller instance the call targets.
ra8_usb_hmsc_class_t
Class / subclass / protocol triplet that identifies an MSC function within an attached USB device's d...
@ k_ra8_hmsc_protocol_bbb
Bulk-Only Transport.
@ k_ra8_hmsc_class_msc
MSC interface class.
@ k_ra8_hmsc_subclass_scsi
Transparent SCSI subclass.
void(* ra8_usb_hmsc_attach_fn_t)(void *ctx, const ra8_usb_hmsc_device_t *device)
Attach-callback signature.
ra8_err_t ra8_usb_hmsc_inquiry(uint8_t target_lun, ra8_usb_hmsc_inquiry_response_t *response)
Issue a SCSI INQUIRY (opcode 0x12) over BBB.
ra8_usb_hmsc_pipe_t
PIPE numbers used by the host-MSC driver for the attached peripheral's bulk endpoints.
@ k_ra8_hmsc_pipe_bulk_in
PIPE3 -> attached EP bulk IN.
@ k_ra8_hmsc_pipe_bulk_out
PIPE4 -> attached EP bulk OUT.
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.
ra8_err_t ra8_usb_hmsc_build_cbw(uint8_t target_lun, uint32_t data_transfer_length, bool data_in, const uint8_t *cdb, uint8_t cdb_len, uint8_t *out_cbw)
Construct the 31-byte CBW header for the given SCSI command.
ra8_err_t ra8_usb_hmsc_attach_callback(ra8_usb_hmsc_attach_fn_t on_attach, void *ctx)
Register (or detach) the attach callback.
ra8_usb_hmsc_max_lun_t
Compile-time ceiling on the number of logical units the starter tracks per attached device.
@ 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_enumerate(ra8_usb_hmsc_device_t *out_device)
Enumerate the attached MSC device end to end (polled).
ra8_usb_hmsc_csw_status_t
CSW status field values returned by the device after a CBW.
@ k_ra8_hmsc_csw_status_failed
Command failed.
@ k_ra8_hmsc_csw_status_phase_error
BBB phase error – need reset recovery.
@ k_ra8_hmsc_csw_status_passed
Command succeeded.
ra8_err_t ra8_usb_hmsc_close(void)
Tear down the host-MSC driver and release the controller.
ra8_usb_hmsc_packet_t
Packet sizing for the attached device's bulk endpoints.
@ k_ra8_hmsc_bulk_max_packet_fs
Bulk size at full speed.
@ k_ra8_hmsc_bulk_max_packet_hs
Bulk size at high speed.
ra8_usb_hmsc_resp_size_t
Standard SCSI response payload sizes.
@ k_ra8_hmsc_read_capacity_resp_len
READ_CAPACITY(10).
@ k_ra8_hmsc_block_size_default
SCSI default block.
@ k_ra8_hmsc_inquiry_resp_len
INQUIRY response len.
ra8_usb_hmsc_request_t
MSC class-specific request codes the host issues to the attached device.
@ k_ra8_hmsc_req_get_max_lun
1-byte response.
@ k_ra8_hmsc_req_mass_storage_reset
0-byte payload.
ra8_err_t ra8_usb_hmsc_decode_csw(const uint8_t *csw, uint32_t expected_tag, ra8_usb_hmsc_csw_status_t *out_status)
Decode a 13-byte CSW.
ra8_usb_hmsc_scsi_t
SCSI opcodes the host-MSC class issues over BBB.
@ k_ra8_hmsc_scsi_inquiry
INQUIRY.
@ k_ra8_hmsc_scsi_request_sense
REQUEST SENSE.
@ k_ra8_hmsc_scsi_read_10
READ(10).
@ k_ra8_hmsc_scsi_write_10
WRITE(10).
@ k_ra8_hmsc_scsi_read_capacity_10
READ CAPACITY(10).
@ k_ra8_hmsc_scsi_test_unit_ready
TEST UNIT READY.
ra8_err_t ra8_usb_hmsc_init(ra8_usb_speed_t speed)
Bring up the host-MSC driver on a chosen USB controller.
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.
Snapshot of the attached MSC device, passed to the attach callback.
uint8_t interface_number
MSC bInterfaceNumber.
uint16_t vendor_id
idVendor from device descriptor.
uint8_t device_address
Assigned USB address (1..127).
uint8_t max_lun
Get-Max-LUN response (0..15).
uint8_t bulk_in_ep
Attached device's bulk IN EP num.
uint16_t bulk_out_max_packet
Attached bulk-OUT wMaxPacketSize.
uint16_t bulk_in_max_packet
Attached bulk-IN wMaxPacketSize.
uint8_t bulk_out_ep
Attached device's bulk OUT EP num.
uint16_t product_id
idProduct from device descriptor.
Decoded SCSI INQUIRY response.
uint8_t vendor_id[8]
T10 Vendor ID, ASCII.
uint8_t peripheral_device_type
Bits [4:0] of byte 0.
uint8_t version
SPC version code.
uint8_t peripheral_qualifier
Bits [7:5] of byte 0.
uint8_t removable
1 = removable medium.
uint8_t product_id[16]
Product ID, ASCII.
uint8_t product_revision[4]
Product revision, ASCII.