![]() |
SyterKit 0.4.0.x
SyterKit is a bare-metal framework
|
#include <io.h>#include <stdarg.h>#include <stdbool.h>#include <stddef.h>#include <stdint.h>#include <types.h>#include <common.h>#include <log.h>#include <sys-sdcard.h>#include "usb.h"#include "usb_defs.h"
Classes | |
| struct | mass_trans_set |
| struct | umass_bbb_cbw_t |
| struct | umass_bbb_csw_t |
Macros | |
| #define | SUNXI_USB_STRING_LANGIDS (0) |
| #define | SUNXI_USB_STRING_IMANUFACTURER (1) |
| #define | SUNXI_USB_STRING_IPRODUCT (2) |
| #define | SUNXI_USB_STRING_ISERIALNUMBER (3) |
| #define | SUNXI_USB_MASS_DEV_MAX (4) |
| #define | SUNXI_USB_MASS_IDLE (0) |
| #define | SUNXI_USB_MASS_SETUP (1) |
| #define | SUNXI_USB_MASS_SEND_DATA (2) |
| #define | SUNXI_USB_MASS_RECEIVE_DATA (3) |
| #define | SUNXI_USB_MASS_STATUS (4) |
| #define | CBWCDBLENGTH 16 |
| #define | SUNXI_MASS_RECV_MEM_SIZE (512 * 1024) |
| #define | SUNXI_MASS_SEND_MEM_SIZE (512 * 1024) |
| #define | SCSI_CHANGE_DEF 0x40 /* Change Definition (Optional) */ |
| #define | SCSI_COMPARE 0x39 /* Compare (O) */ |
| Commands Unique to Direct Access Devices %%%. | |
| #define | SCSI_COPY 0x18 /* Copy (O) */ |
| #define | SCSI_COP_VERIFY 0x3A /* Copy and Verify (O) */ |
| #define | SCSI_INQUIRY 0x12 /* Inquiry (MANDATORY) */ |
| #define | SCSI_LOG_SELECT 0x4C /* Log Select (O) */ |
| #define | SCSI_LOG_SENSE 0x4D /* Log Sense (O) */ |
| #define | SCSI_MODE_SEL6 0x15 /* Mode Select 6-byte (Device Specific) */ |
| #define | SCSI_MODE_SEL10 0x55 /* Mode Select 10-byte (Device Specific) */ |
| #define | SCSI_MODE_SEN6 0x1A /* Mode Sense 6-byte (Device Specific) */ |
| #define | SCSI_MODE_SEN10 0x5A /* Mode Sense 10-byte (Device Specific) */ |
| #define | SCSI_READ_BUFF 0x3C /* Read Buffer (O) */ |
| #define | SCSI_REQ_SENSE 0x03 /* Request Sense (MANDATORY) */ |
| #define | SCSI_SEND_DIAG 0x1D /* Send Diagnostic (O) */ |
| #define | SCSI_TST_U_RDY 0x00 /* Test Unit Ready (MANDATORY) */ |
| #define | SCSI_WRITE_BUFF 0x3B /* Write Buffer (O) */ |
| #define | SCSI_COMPARE 0x39 /* Compare (O) */ |
| Commands Unique to Direct Access Devices %%%. | |
| #define | SCSI_FORMAT 0x04 /* Format Unit (MANDATORY) */ |
| #define | SCSI_LCK_UN_CAC 0x36 /* Lock Unlock Cache (O) */ |
| #define | SCSI_PREFETCH 0x34 /* Prefetch (O) */ |
| #define | SCSI_MED_REMOVL 0x1E /* Prevent/Allow medium Removal (O) */ |
| #define | SCSI_READ6 0x08 /* Read 6-byte (MANDATORY) */ |
| #define | SCSI_READ10 0x28 /* Read 10-byte (MANDATORY) */ |
| #define | SCSI_RD_CAPAC 0x25 /* Read Capacity (MANDATORY) */ |
| #define | SCSI_RD_DEFECT 0x37 /* Read Defect Data (O) */ |
| #define | SCSI_READ_LONG 0x3E /* Read Long (O) */ |
| #define | SCSI_REASS_BLK 0x07 /* Reassign Blocks (O) */ |
| #define | SCSI_RCV_DIAG 0x1C /* Receive Diagnostic Results (O) */ |
| #define | SCSI_RELEASE 0x17 /* Release Unit (MANDATORY) */ |
| #define | SCSI_REZERO 0x01 /* Rezero Unit (O) */ |
| #define | SCSI_SRCH_DAT_E 0x31 /* Search Data Equal (O) */ |
| #define | SCSI_SRCH_DAT_H 0x30 /* Search Data High (O) */ |
| #define | SCSI_SRCH_DAT_L 0x32 /* Search Data Low (O) */ |
| #define | SCSI_SEEK6 0x0B /* Seek 6-Byte (O) */ |
| #define | SCSI_SEEK10 0x2B /* Seek 10-Byte (O) */ |
| #define | SCSI_SEND_DIAG 0x1D /* Send Diagnostics (MANDATORY) */ |
| #define | SCSI_SET_LIMIT 0x33 /* Set Limits (O) */ |
| #define | SCSI_START_STP 0x1B /* Start/Stop Unit (O) */ |
| #define | SCSI_SYNC_CACHE 0x35 /* Synchronize Cache (O) */ |
| #define | SCSI_VERIFY 0x2F /* Verify (O) */ |
| #define | SCSI_WRITE6 0x0A /* Write 6-Byte (MANDATORY) */ |
| #define | SCSI_WRITE10 0x2A /* Write 10-Byte (MANDATORY) */ |
| #define | SCSI_WRT_VERIFY 0x2E /* Write and Verify (O) */ |
| #define | SCSI_WRITE_LONG 0x3F /* Write Long (O) */ |
| #define | SCSI_WRITE_SAME 0x41 /* Write Same (O) */ |
| #define | SCSI_RD_FMT_CAPAC 0x23 /* Read format caacity */ |
Typedefs | |
| typedef struct mass_trans_set | mass_trans_set_t |
Functions | |
| struct umass_bbb_cbw_t | __attribute__ ((packed)) |
| static int | usb_mass_usb_set_interface (struct usb_device_request *req) |
| USB MASS: Set interface. | |
| static int | usb_mass_usb_set_address (struct usb_device_request *req) |
| USB MASS: Set address. | |
| static int | usb_mass_usb_set_configuration (struct usb_device_request *req) |
| USB MASS: Set configuration. | |
| static int | usb_mass_usb_get_descriptor (struct usb_device_request *req, uint8_t *buffer) |
| usb_mass_usb_get_descriptor - Get USB descriptors | |
| static int | usb_mass_usb_get_status (struct usb_device_request *req, uint8_t *buffer) |
| usb_mass_usb_get_status - Handle a USB request to retrieve the status of the device | |
| static int | sunxi_usb_mass_init (void) |
| sunxi_usb_mass_init - Initialize the USB Mass Storage driver | |
| static int | sunxi_mass_exit (void) |
| sunxi_mass_exit - Exit the USB Mass Storage driver | |
| static void | sunxi_mass_reset (void) |
| sunxi_mass_reset - Reset the USB Mass Storage driver | |
| static void | sunxi_mass_usb_rx_dma_isr (void *p_arg) |
| sunxi_mass_usb_rx_dma_isr - Handle the USB Mass Storage RX DMA interrupt | |
| static void | sunxi_mass_usb_tx_dma_isr (void *p_arg) |
| sunxi_mass_usb_tx_dma_isr - Handle the USB Mass Storage TX DMA interrupt | |
| static int | sunxi_mass_standard_req_op (uint32_t cmd, struct usb_device_request *req, uint8_t *buffer) |
| sunxi_mass_standard_req_op - Handle standard USB Mass Storage requests | |
| static int | sunxi_mass_nonstandard_req_op (uint32_t cmd, struct usb_device_request *req, uint8_t *buffer, uint32_t data_status) |
| sunxi_mass_nonstandard_req_op - Handle non-standard USB Mass Storage requests | |
| static int | sunxi_mass_state_loop (void *buffer) |
| sunxi_mass_state_loop - State machine for USB Mass Storage operation | |
| sunxi_usb_module_init (SUNXI_USB_DEVICE_MASS, sunxi_usb_mass_init, sunxi_mass_exit, sunxi_mass_reset, sunxi_mass_standard_req_op, sunxi_mass_nonstandard_req_op, sunxi_mass_state_loop, sunxi_mass_usb_rx_dma_isr, sunxi_mass_usb_tx_dma_isr) | |
Variables | |
| const uint8_t | normal_lang_id [8] = {0x04, 0x03, 0x09, 0x04, '\0'} |
| const uint8_t | sunxi_usb_mass_serial_num0 [32] = "20240127003501" |
| const uint8_t | sunxi_usb_mass_manufacturer [32] = "Yuzuki HD" |
| const uint8_t | sunxi_usb_mass_product [32] = "USB Mass Storage" |
| uint8_t * | sunxi_usb_mass_dev [SUNXI_USB_MASS_DEV_MAX] |
| const uint8_t | inquiry_data [40] |
| const uint8_t | request_sense [20] |
| uint32_t | dCBWSignature |
| uint32_t | dCBWTag |
| uint32_t | dCBWDataTransferLength |
| uint8_t | bCBWFlags |
| uint8_t | bCBWLUN |
| uint8_t | bCDBLength |
| uint8_t | CBWCDB [CBWCDBLENGTH] |
| uint32_t | dCSWSignature |
| uint32_t | dCSWTag |
| uint32_t | dCSWDataResidue |
| uint8_t | bCSWStatus |
| static int | sunxi_usb_mass_write_enable = 0 |
| static int | sunxi_usb_mass_status = SUNXI_USB_MASS_IDLE |
| static mass_trans_set_t | trans_data |
| #define CBWCDBLENGTH 16 |
| #define SCSI_CHANGE_DEF 0x40 /* Change Definition (Optional) */ |
| #define SCSI_COMPARE 0x39 /* Compare (O) */ |
Commands Unique to Direct Access Devices %%%.
| #define SCSI_COMPARE 0x39 /* Compare (O) */ |
Commands Unique to Direct Access Devices %%%.
| #define SCSI_COP_VERIFY 0x3A /* Copy and Verify (O) */ |
| #define SCSI_COPY 0x18 /* Copy (O) */ |
| #define SCSI_FORMAT 0x04 /* Format Unit (MANDATORY) */ |
| #define SCSI_INQUIRY 0x12 /* Inquiry (MANDATORY) */ |
| #define SCSI_LCK_UN_CAC 0x36 /* Lock Unlock Cache (O) */ |
| #define SCSI_LOG_SELECT 0x4C /* Log Select (O) */ |
| #define SCSI_LOG_SENSE 0x4D /* Log Sense (O) */ |
| #define SCSI_MED_REMOVL 0x1E /* Prevent/Allow medium Removal (O) */ |
| #define SCSI_MODE_SEL10 0x55 /* Mode Select 10-byte (Device Specific) */ |
| #define SCSI_MODE_SEL6 0x15 /* Mode Select 6-byte (Device Specific) */ |
| #define SCSI_MODE_SEN10 0x5A /* Mode Sense 10-byte (Device Specific) */ |
| #define SCSI_MODE_SEN6 0x1A /* Mode Sense 6-byte (Device Specific) */ |
| #define SCSI_PREFETCH 0x34 /* Prefetch (O) */ |
| #define SCSI_RCV_DIAG 0x1C /* Receive Diagnostic Results (O) */ |
| #define SCSI_RD_CAPAC 0x25 /* Read Capacity (MANDATORY) */ |
| #define SCSI_RD_DEFECT 0x37 /* Read Defect Data (O) */ |
| #define SCSI_RD_FMT_CAPAC 0x23 /* Read format caacity */ |
| #define SCSI_READ10 0x28 /* Read 10-byte (MANDATORY) */ |
| #define SCSI_READ6 0x08 /* Read 6-byte (MANDATORY) */ |
| #define SCSI_READ_BUFF 0x3C /* Read Buffer (O) */ |
| #define SCSI_READ_LONG 0x3E /* Read Long (O) */ |
| #define SCSI_REASS_BLK 0x07 /* Reassign Blocks (O) */ |
| #define SCSI_RELEASE 0x17 /* Release Unit (MANDATORY) */ |
| #define SCSI_REQ_SENSE 0x03 /* Request Sense (MANDATORY) */ |
| #define SCSI_REZERO 0x01 /* Rezero Unit (O) */ |
| #define SCSI_SEEK10 0x2B /* Seek 10-Byte (O) */ |
| #define SCSI_SEEK6 0x0B /* Seek 6-Byte (O) */ |
| #define SCSI_SEND_DIAG 0x1D /* Send Diagnostic (O) */ |
| #define SCSI_SEND_DIAG 0x1D /* Send Diagnostics (MANDATORY) */ |
| #define SCSI_SET_LIMIT 0x33 /* Set Limits (O) */ |
| #define SCSI_SRCH_DAT_E 0x31 /* Search Data Equal (O) */ |
| #define SCSI_SRCH_DAT_H 0x30 /* Search Data High (O) */ |
| #define SCSI_SRCH_DAT_L 0x32 /* Search Data Low (O) */ |
| #define SCSI_START_STP 0x1B /* Start/Stop Unit (O) */ |
| #define SCSI_SYNC_CACHE 0x35 /* Synchronize Cache (O) */ |
| #define SCSI_TST_U_RDY 0x00 /* Test Unit Ready (MANDATORY) */ |
| #define SCSI_VERIFY 0x2F /* Verify (O) */ |
| #define SCSI_WRITE10 0x2A /* Write 10-Byte (MANDATORY) */ |
| #define SCSI_WRITE6 0x0A /* Write 6-Byte (MANDATORY) */ |
| #define SCSI_WRITE_BUFF 0x3B /* Write Buffer (O) */ |
| #define SCSI_WRITE_LONG 0x3F /* Write Long (O) */ |
| #define SCSI_WRITE_SAME 0x41 /* Write Same (O) */ |
| #define SCSI_WRT_VERIFY 0x2E /* Write and Verify (O) */ |
| #define SUNXI_MASS_RECV_MEM_SIZE (512 * 1024) |
| #define SUNXI_MASS_SEND_MEM_SIZE (512 * 1024) |
| #define SUNXI_USB_MASS_DEV_MAX (4) |
| #define SUNXI_USB_MASS_IDLE (0) |
| #define SUNXI_USB_MASS_RECEIVE_DATA (3) |
| #define SUNXI_USB_MASS_SEND_DATA (2) |
| #define SUNXI_USB_MASS_SETUP (1) |
| #define SUNXI_USB_MASS_STATUS (4) |
| #define SUNXI_USB_STRING_IMANUFACTURER (1) |
| #define SUNXI_USB_STRING_IPRODUCT (2) |
| #define SUNXI_USB_STRING_ISERIALNUMBER (3) |
| #define SUNXI_USB_STRING_LANGIDS (0) |
| typedef struct mass_trans_set mass_trans_set_t |
| struct umass_bbb_cbw_t __attribute__ | ( | (packed) | ) |
|
static |
sunxi_mass_exit - Exit the USB Mass Storage driver
This function frees the memory allocated for data transmission and exits the USB Mass Storage driver.
|
static |
sunxi_mass_nonstandard_req_op - Handle non-standard USB Mass Storage requests
This function handles non-standard USB Mass Storage requests by calling the corresponding functions based on the request type and request code.
| cmd | The command code for the request |
| req | Pointer to the USB device request structure |
| buffer | Pointer to the data buffer |
| data_status | The status of the data transfer |
|
static |
sunxi_mass_reset - Reset the USB Mass Storage driver
This function resets the USB Mass Storage driver by setting initial values.
|
static |
sunxi_mass_standard_req_op - Handle standard USB Mass Storage requests
This function handles standard USB Mass Storage requests by calling the corresponding functions based on the command.
| cmd | The command code for the request |
| req | Pointer to the USB device request structure |
| buffer | Pointer to the data buffer |
|
static |
sunxi_mass_state_loop - State machine for USB Mass Storage operation
This function implements a state machine for USB Mass Storage operation. It handles the different stages of the operation, such as sending/receiving data, checking status, and handling errors.
| buffer | Pointer to the data buffer |
|
static |
sunxi_mass_usb_rx_dma_isr - Handle the USB Mass Storage RX DMA interrupt
This function is called when a USB Mass Storage RX DMA interrupt occurs. It sets a flag to indicate that the USB host is ready to write data.
| p_arg | Pointer to a void argument (not used) |
|
static |
sunxi_mass_usb_tx_dma_isr - Handle the USB Mass Storage TX DMA interrupt
This function is called when a USB Mass Storage TX DMA interrupt occurs. It currently does not perform any action.
| p_arg | Pointer to a void argument (not used) |
|
static |
sunxi_usb_mass_init - Initialize the USB Mass Storage driver
This function initializes the USB Mass Storage driver by allocating memory for data transmission and setting up initial values.
| sunxi_usb_module_init | ( | SUNXI_USB_DEVICE_MASS | , |
| sunxi_usb_mass_init | , | ||
| sunxi_mass_exit | , | ||
| sunxi_mass_reset | , | ||
| sunxi_mass_standard_req_op | , | ||
| sunxi_mass_nonstandard_req_op | , | ||
| sunxi_mass_state_loop | , | ||
| sunxi_mass_usb_rx_dma_isr | , | ||
| sunxi_mass_usb_tx_dma_isr | |||
| ) |
|
static |
usb_mass_usb_get_descriptor - Get USB descriptors
This function retrieves USB descriptors based on the provided request.
| req | Pointer to the USB device request structure |
| buffer | Pointer to the buffer to hold the descriptor data |
|
static |
usb_mass_usb_get_status - Handle a USB request to retrieve the status of the device
This function handles a USB request to retrieve the status of the USB device. The status is returned in a buffer provided by the caller.
| req | Pointer to the USB device request structure |
| buffer | Pointer to the buffer to hold the status data |
|
static |
USB MASS: Set address.
This function handles the set address request for the USB Mass Storage device. It extracts the new address from the request and calls sunxi_usb_set_address() to set the new address.
| req | The USB device request |
|
static |
USB MASS: Set configuration.
This function handles the set configuration request for the USB Mass Storage device. It checks if the requested configuration is valid. If it is, it calls sunxi_usb_ep_reset() to reset the USB endpoints. Otherwise, it prints an error message and returns SUNXI_USB_REQ_OP_ERR.
| req | The USB device request |
|
static |
USB MASS: Set interface.
This function handles the set interface request for the USB Mass Storage device. It checks if the requested interface and alternate setting are valid. If they are, it calls sunxi_usb_ep_reset() to reset the USB endpoints. Otherwise, it prints an error message and returns SUNXI_USB_REQ_OP_ERR.
| req | The USB device request |
| uint8_t bCBWFlags |
| uint8_t bCBWLUN |
| uint8_t bCDBLength |
| uint8_t bCSWStatus |
| uint8_t CBWCDB[CBWCDBLENGTH] |
| uint32_t dCBWDataTransferLength |
| uint32_t dCBWSignature |
| uint32_t dCBWTag |
| uint32_t dCSWDataResidue |
| uint32_t dCSWSignature |
| uint32_t dCSWTag |
| const uint8_t inquiry_data[40] |
| const uint8_t normal_lang_id[8] = {0x04, 0x03, 0x09, 0x04, '\0'} |
| const uint8_t request_sense[20] |
| uint8_t* sunxi_usb_mass_dev[SUNXI_USB_MASS_DEV_MAX] |
| const uint8_t sunxi_usb_mass_manufacturer[32] = "Yuzuki HD" |
| const uint8_t sunxi_usb_mass_product[32] = "USB Mass Storage" |
| const uint8_t sunxi_usb_mass_serial_num0[32] = "20240127003501" |
|
static |
|
static |
|
static |