tinyusb  0.4
Click here to lend your support to tinyusb donation and make a donation at pledgie.com
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages

Functions

bool tusbh_msc_is_mounted (uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT
 Check if device supports MassStorage interface or not. More...
 
bool tusbh_msc_is_busy (uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT
 Check if the interface is currently busy or not. More...
 
uint8_t const * tusbh_msc_get_vendor_name (uint8_t dev_addr)
 Get SCSI vendor's name of MassStorage device. More...
 
uint8_t const * tusbh_msc_get_product_name (uint8_t dev_addr)
 Get SCSI product's name of MassStorage device. More...
 
tusb_error_t tusbh_msc_get_capacity (uint8_t dev_addr, uint32_t *p_last_lba, uint32_t *p_block_size)
 Get SCSI Capacity of MassStorage device. More...
 
tusb_error_t tusbh_msc_read10 (uint8_t dev_addr, uint8_t lun, void *p_buffer, uint32_t lba, uint16_t block_count) ATTR_WARN_UNUSED_RESULT
 Perform SCSI READ 10 command to read data from MassStorage device. More...
 
tusb_error_t tusbh_msc_write10 (uint8_t dev_addr, uint8_t lun, void const *p_buffer, uint32_t lba, uint16_t block_count) ATTR_WARN_UNUSED_RESULT
 Perform SCSI WRITE 10 command to write data to MassStorage device. More...
 
tusb_error_t tusbh_msc_request_sense (uint8_t dev_addr, uint8_t lun, uint8_t *p_data)
 Perform SCSI REQUEST SENSE command, used to retrieve sense data from MassStorage device. More...
 
tusb_error_t tusbh_msc_test_unit_ready (uint8_t dev_addr, uint8_t lun, msc_cmd_status_wrapper_t *p_csw) ATTR_WARN_UNUSED_RESULT
 Perform SCSI TEST UNIT READY command to test if MassStorage device is ready. More...
 
void tusbh_msc_mounted_cb (uint8_t dev_addr)
 Callback function that will be invoked when a device with MassStorage interface is mounted. More...
 
void tusbh_msc_unmounted_cb (uint8_t dev_addr)
 Callback function that will be invoked when a device with MassStorage interface is unmounted. More...
 
void tusbh_msc_isr (uint8_t dev_addr, tusb_event_t event, uint32_t xferred_bytes)
 Callback function that is invoked when an transferring event occurred. More...
 

Detailed Description

The interface API includes status checking function, data transferring function and callback functions

Function Documentation

tusb_error_t tusbh_msc_get_capacity ( uint8_t  dev_addr,
uint32_t *  p_last_lba,
uint32_t *  p_block_size 
)

Get SCSI Capacity of MassStorage device.

Parameters
[in]dev_addrdevice address
[out]p_last_lbaLast Logical Block Address of device
[out]p_block_sizeBlock Size of device in bytes
Return values
pointerto product's name or NULL if specified device does not support MassStorage
Note
MassStorage's capacity can be computed by last LBA x block size (in bytes). During enumeration, the stack has already retrieved (via SCSI READ CAPACITY 10) and store this information internally. There is no need for application to re-send SCSI READ CAPACITY 10 command
uint8_t const* tusbh_msc_get_product_name ( uint8_t  dev_addr)

Get SCSI product's name of MassStorage device.

Parameters
[in]dev_addrdevice address
Returns
pointer to product's name or NULL if specified device does not support MassStorage
Note
SCSI product's name is 16-byte length field in scsi_inquiry_data_t. During enumeration, the stack has already retrieved (via SCSI INQUIRY) and store this information internally. There is no need for application to re-send SCSI INQUIRY command or allocate buffer for this.
uint8_t const* tusbh_msc_get_vendor_name ( uint8_t  dev_addr)

Get SCSI vendor's name of MassStorage device.

Parameters
[in]dev_addrdevice address
Returns
pointer to vendor's name or NULL if specified device does not support MassStorage
Note
SCSI vendor's name is 8-byte length field in scsi_inquiry_data_t. During enumeration, the stack has already retrieved (via SCSI INQUIRY) and store this information internally. There is no need for application to re-send SCSI INQUIRY command or allocate buffer for this.
bool tusbh_msc_is_busy ( uint8_t  dev_addr)

Check if the interface is currently busy or not.

Parameters
[in]dev_addrdevice address
Return values
trueif the interface is busy meaning the stack is still transferring/waiting data from/to device
falseif the interface is not busy meaning the stack successfully transferred data from/to device
Note
This function is used to check if previous transfer is complete (success or error), so that the next transfer can be scheduled. User needs to make sure the corresponding interface is mounted (by tusbh_msc_is_mounted) before calling this function
bool tusbh_msc_is_mounted ( uint8_t  dev_addr)

Check if device supports MassStorage interface or not.

Parameters
[in]dev_addrdevice address
Return values
trueif device supports
falseif device does not support or is not mounted
void tusbh_msc_isr ( uint8_t  dev_addr,
tusb_event_t  event,
uint32_t  xferred_bytes 
)

Callback function that is invoked when an transferring event occurred.

Parameters
[in]dev_addrAddress of device
[in]eventan value from tusb_event_t
[in]xferred_bytesNumber of bytes transferred via USB bus
Note
event can be one of following
  • TUSB_EVENT_XFER_COMPLETE : previously scheduled transfer completes successfully.
  • TUSB_EVENT_XFER_ERROR : previously scheduled transfer encountered a transaction error.
  • TUSB_EVENT_XFER_STALLED : previously scheduled transfer is stalled by device.
void tusbh_msc_mounted_cb ( uint8_t  dev_addr)

Callback function that will be invoked when a device with MassStorage interface is mounted.

Parameters
[in]dev_addrAddress of newly mounted device
Note
This callback should be used by Application to set-up interface-related data
tusb_error_t tusbh_msc_read10 ( uint8_t  dev_addr,
uint8_t  lun,
void *  p_buffer,
uint32_t  lba,
uint16_t  block_count 
)

Perform SCSI READ 10 command to read data from MassStorage device.

Parameters
[in]dev_addrdevice address
[in]lunTargeted Logical Unit
[out]p_bufferBuffer used to store data read from device. Must be accessible by USB controller (see TUSB_CFG_ATTR_USBRAM)
[in]lbaStarting Logical Block Address to be read
[in]block_countNumber of Block to be read
Return values
TUSB_ERROR_NONEon success
TUSB_ERROR_INTERFACE_IS_BUSYif the interface is already transferring data with device
TUSB_ERROR_DEVICE_NOT_READYif device is not yet configured (by SET CONFIGURED request)
TUSB_ERROR_INVALID_PARAif input parameters are not correct
Note
This function is non-blocking and returns immediately. The result of USB transfer will be reported by the interface's callback function
tusb_error_t tusbh_msc_request_sense ( uint8_t  dev_addr,
uint8_t  lun,
uint8_t *  p_data 
)

Perform SCSI REQUEST SENSE command, used to retrieve sense data from MassStorage device.

Parameters
[in]dev_addrdevice address
[in]lunTargeted Logical Unit
[in]p_dataBuffer to store response's data from device. Must be accessible by USB controller (see TUSB_CFG_ATTR_USBRAM)
Return values
TUSB_ERROR_NONEon success
TUSB_ERROR_INTERFACE_IS_BUSYif the interface is already transferring data with device
TUSB_ERROR_DEVICE_NOT_READYif device is not yet configured (by SET CONFIGURED request)
TUSB_ERROR_INVALID_PARAif input parameters are not correct
Note
This function is non-blocking and returns immediately. The result of USB transfer will be reported by the interface's callback function
tusb_error_t tusbh_msc_test_unit_ready ( uint8_t  dev_addr,
uint8_t  lun,
msc_cmd_status_wrapper_t p_csw 
)

Perform SCSI TEST UNIT READY command to test if MassStorage device is ready.

Parameters
[in]dev_addrdevice address
[in]lunTargeted Logical Unit
Return values
TUSB_ERROR_NONEon success
TUSB_ERROR_INTERFACE_IS_BUSYif the interface is already transferring data with device
TUSB_ERROR_DEVICE_NOT_READYif device is not yet configured (by SET CONFIGURED request)
TUSB_ERROR_INVALID_PARAif input parameters are not correct
Note
This function is non-blocking and returns immediately. The result of USB transfer will be reported by the interface's callback function
void tusbh_msc_unmounted_cb ( uint8_t  dev_addr)

Callback function that will be invoked when a device with MassStorage interface is unmounted.

Parameters
[in]dev_addrAddress of newly unmounted device
Note
This callback should be used by Application to tear-down interface-related data
tusb_error_t tusbh_msc_write10 ( uint8_t  dev_addr,
uint8_t  lun,
void const *  p_buffer,
uint32_t  lba,
uint16_t  block_count 
)

Perform SCSI WRITE 10 command to write data to MassStorage device.

Parameters
[in]dev_addrdevice address
[in]lunTargeted Logical Unit
[in]p_bufferBuffer containing data. Must be accessible by USB controller (see TUSB_CFG_ATTR_USBRAM)
[in]lbaStarting Logical Block Address to be written
[in]block_countNumber of Block to be written
Return values
TUSB_ERROR_NONEon success
TUSB_ERROR_INTERFACE_IS_BUSYif the interface is already transferring data with device
TUSB_ERROR_DEVICE_NOT_READYif device is not yet configured (by SET CONFIGURED request)
TUSB_ERROR_INVALID_PARAif input parameters are not correct
Note
This function is non-blocking and returns immediately. The result of USB transfer will be reported by the interface's callback function