mirror of
https://github.com/hathach/tinyusb.git
synced 2025-02-15 12:39:50 +00:00
Merge pull request #1750 from hathach/rework-host-msc-complete-callback
Rework host msc complete callback
This commit is contained in:
commit
081e4eecba
@ -26,5 +26,18 @@ target_include_directories(${PROJECT} PUBLIC
|
|||||||
# in hw/bsp/FAMILY/family.cmake for details.
|
# in hw/bsp/FAMILY/family.cmake for details.
|
||||||
family_configure_host_example(${PROJECT})
|
family_configure_host_example(${PROJECT})
|
||||||
|
|
||||||
# For rp2040, un-comment to enable pico-pio-usb
|
# For rp2040 enable pico-pio-usb
|
||||||
# family_add_pico_pio_usb(${PROJECT})
|
if(FAMILY STREQUAL "rp2040")
|
||||||
|
family_add_pico_pio_usb(${PROJECT})
|
||||||
|
|
||||||
|
# due to warnings from Pico-PIO-USB
|
||||||
|
target_compile_options(${PROJECT} PUBLIC
|
||||||
|
-Wno-error=shadow
|
||||||
|
-Wno-error=cast-align
|
||||||
|
-Wno-error=cast-qual
|
||||||
|
-Wno-error=redundant-decls
|
||||||
|
-Wno-error=sign-conversion
|
||||||
|
-Wno-error=conversion
|
||||||
|
-Wno-error=unused-function
|
||||||
|
)
|
||||||
|
endif()
|
@ -34,6 +34,12 @@
|
|||||||
// Board Specific Configuration
|
// Board Specific Configuration
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
|
||||||
|
#if CFG_TUSB_MCU == OPT_MCU_RP2040
|
||||||
|
// change to 1 if using pico-pio-usb as host controller for raspberry rp2040
|
||||||
|
#define CFG_TUH_RPI_PIO_USB 0
|
||||||
|
#define BOARD_TUH_RHPORT CFG_TUH_RPI_PIO_USB
|
||||||
|
#endif
|
||||||
|
|
||||||
// RHPort number used for host can be defined by board.mk, default to port 0
|
// RHPort number used for host can be defined by board.mk, default to port 0
|
||||||
#ifndef BOARD_TUH_RHPORT
|
#ifndef BOARD_TUH_RHPORT
|
||||||
#define BOARD_TUH_RHPORT 0
|
#define BOARD_TUH_RHPORT 0
|
||||||
|
@ -28,17 +28,18 @@ target_include_directories(${PROJECT} PUBLIC
|
|||||||
# in hw/bsp/FAMILY/family.cmake for details.
|
# in hw/bsp/FAMILY/family.cmake for details.
|
||||||
family_configure_host_example(${PROJECT})
|
family_configure_host_example(${PROJECT})
|
||||||
|
|
||||||
# For rp2040, un-comment to enable pico-pio-usb
|
# For rp2040 enable pico-pio-usb
|
||||||
family_add_pico_pio_usb(${PROJECT})
|
if(FAMILY STREQUAL "rp2040")
|
||||||
|
family_add_pico_pio_usb(${PROJECT})
|
||||||
|
|
||||||
# due to warnings from Pico-PIO-USB
|
# due to warnings from Pico-PIO-USB
|
||||||
target_compile_options(${PROJECT} PUBLIC
|
target_compile_options(${PROJECT} PUBLIC
|
||||||
-Wno-error=shadow
|
-Wno-error=shadow
|
||||||
-Wno-error=cast-align
|
-Wno-error=cast-align
|
||||||
-Wno-error=cast-qual
|
-Wno-error=cast-qual
|
||||||
-Wno-error=redundant-decls
|
-Wno-error=redundant-decls
|
||||||
-Wno-error=sign-conversion
|
-Wno-error=sign-conversion
|
||||||
-Wno-error=conversion
|
-Wno-error=conversion
|
||||||
-Wno-error=sign-compare
|
-Wno-error=unused-function
|
||||||
-Wno-error=unused-function
|
)
|
||||||
)
|
endif()
|
||||||
|
@ -30,8 +30,11 @@
|
|||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
static scsi_inquiry_resp_t inquiry_resp;
|
static scsi_inquiry_resp_t inquiry_resp;
|
||||||
|
|
||||||
bool inquiry_complete_cb(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const* csw)
|
bool inquiry_complete_cb(uint8_t dev_addr, tuh_msc_complete_data_t const * cb_data)
|
||||||
{
|
{
|
||||||
|
msc_cbw_t const* cbw = cb_data->cbw;
|
||||||
|
msc_csw_t const* csw = cb_data->csw;
|
||||||
|
|
||||||
if (csw->status != 0)
|
if (csw->status != 0)
|
||||||
{
|
{
|
||||||
printf("Inquiry failed\r\n");
|
printf("Inquiry failed\r\n");
|
||||||
@ -57,47 +60,12 @@ void tuh_msc_mount_cb(uint8_t dev_addr)
|
|||||||
printf("A MassStorage device is mounted\r\n");
|
printf("A MassStorage device is mounted\r\n");
|
||||||
|
|
||||||
uint8_t const lun = 0;
|
uint8_t const lun = 0;
|
||||||
tuh_msc_inquiry(dev_addr, lun, &inquiry_resp, inquiry_complete_cb);
|
tuh_msc_inquiry(dev_addr, lun, &inquiry_resp, inquiry_complete_cb, 0);
|
||||||
//
|
|
||||||
// //------------- file system (only 1 LUN support) -------------//
|
|
||||||
// uint8_t phy_disk = dev_addr-1;
|
|
||||||
// disk_initialize(phy_disk);
|
|
||||||
//
|
|
||||||
// if ( disk_is_ready(phy_disk) )
|
|
||||||
// {
|
|
||||||
// if ( f_mount(phy_disk, &fatfs[phy_disk]) != FR_OK )
|
|
||||||
// {
|
|
||||||
// puts("mount failed");
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// f_chdrive(phy_disk); // change to newly mounted drive
|
|
||||||
// f_chdir("/"); // root as current dir
|
|
||||||
//
|
|
||||||
// cli_init();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void tuh_msc_umount_cb(uint8_t dev_addr)
|
void tuh_msc_umount_cb(uint8_t dev_addr)
|
||||||
{
|
{
|
||||||
(void) dev_addr;
|
(void) dev_addr;
|
||||||
printf("A MassStorage device is unmounted\r\n");
|
printf("A MassStorage device is unmounted\r\n");
|
||||||
|
|
||||||
// uint8_t phy_disk = dev_addr-1;
|
|
||||||
//
|
|
||||||
// f_mount(phy_disk, NULL); // unmount disk
|
|
||||||
// disk_deinitialize(phy_disk);
|
|
||||||
//
|
|
||||||
// if ( phy_disk == f_get_current_drive() )
|
|
||||||
// { // active drive is unplugged --> change to other drive
|
|
||||||
// for(uint8_t i=0; i<CFG_TUH_DEVICE_MAX; i++)
|
|
||||||
// {
|
|
||||||
// if ( disk_is_ready(i) )
|
|
||||||
// {
|
|
||||||
// f_chdrive(i);
|
|
||||||
// cli_init(); // refractor, rename
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,5 +27,18 @@ target_include_directories(${PROJECT} PUBLIC
|
|||||||
# in hw/bsp/FAMILY/family.cmake for details.
|
# in hw/bsp/FAMILY/family.cmake for details.
|
||||||
family_configure_host_example(${PROJECT})
|
family_configure_host_example(${PROJECT})
|
||||||
|
|
||||||
# For rp2040, un-comment to enable pico-pio-usb
|
# For rp2040 enable pico-pio-usb
|
||||||
# family_add_pico_pio_usb(${PROJECT})
|
if(FAMILY STREQUAL "rp2040")
|
||||||
|
family_add_pico_pio_usb(${PROJECT})
|
||||||
|
|
||||||
|
# due to warnings from Pico-PIO-USB
|
||||||
|
target_compile_options(${PROJECT} PUBLIC
|
||||||
|
-Wno-error=shadow
|
||||||
|
-Wno-error=cast-align
|
||||||
|
-Wno-error=cast-qual
|
||||||
|
-Wno-error=redundant-decls
|
||||||
|
-Wno-error=sign-conversion
|
||||||
|
-Wno-error=conversion
|
||||||
|
-Wno-error=unused-function
|
||||||
|
)
|
||||||
|
endif()
|
@ -34,6 +34,12 @@
|
|||||||
// Board Specific Configuration
|
// Board Specific Configuration
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
|
||||||
|
#if CFG_TUSB_MCU == OPT_MCU_RP2040
|
||||||
|
// change to 1 if using pico-pio-usb as host controller for raspberry rp2040
|
||||||
|
#define CFG_TUH_RPI_PIO_USB 0
|
||||||
|
#define BOARD_TUH_RHPORT CFG_TUH_RPI_PIO_USB
|
||||||
|
#endif
|
||||||
|
|
||||||
// RHPort number used for host can be defined by board.mk, default to port 0
|
// RHPort number used for host can be defined by board.mk, default to port 0
|
||||||
#ifndef BOARD_TUH_RHPORT
|
#ifndef BOARD_TUH_RHPORT
|
||||||
#define BOARD_TUH_RHPORT 0
|
#define BOARD_TUH_RHPORT 0
|
||||||
|
@ -32,17 +32,18 @@ target_include_directories(${PROJECT} PUBLIC
|
|||||||
# in hw/bsp/FAMILY/family.cmake for details.
|
# in hw/bsp/FAMILY/family.cmake for details.
|
||||||
family_configure_host_example(${PROJECT})
|
family_configure_host_example(${PROJECT})
|
||||||
|
|
||||||
# For rp2040, un-comment to enable pico-pio-usb
|
# For rp2040 enable pico-pio-usb
|
||||||
family_add_pico_pio_usb(${PROJECT})
|
if(FAMILY STREQUAL "rp2040")
|
||||||
|
family_add_pico_pio_usb(${PROJECT})
|
||||||
|
|
||||||
# due to warnings from Pico-PIO-USB and fatfs
|
# due to warnings from Pico-PIO-USB
|
||||||
target_compile_options(${PROJECT} PUBLIC
|
target_compile_options(${PROJECT} PUBLIC
|
||||||
-Wno-error=shadow
|
-Wno-error=shadow
|
||||||
-Wno-error=cast-align
|
-Wno-error=cast-align
|
||||||
-Wno-error=cast-qual
|
-Wno-error=cast-qual
|
||||||
-Wno-error=redundant-decls
|
-Wno-error=redundant-decls
|
||||||
-Wno-error=sign-conversion
|
-Wno-error=sign-conversion
|
||||||
-Wno-error=conversion
|
-Wno-error=conversion
|
||||||
-Wno-error=sign-compare
|
-Wno-error=unused-function
|
||||||
-Wno-error=unused-function
|
)
|
||||||
)
|
endif()
|
||||||
|
@ -93,8 +93,11 @@ void msc_app_task(void)
|
|||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
|
||||||
|
|
||||||
bool inquiry_complete_cb(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const* csw)
|
bool inquiry_complete_cb(uint8_t dev_addr, tuh_msc_complete_data_t const * cb_data)
|
||||||
{
|
{
|
||||||
|
msc_cbw_t const* cbw = cb_data->cbw;
|
||||||
|
msc_csw_t const* csw = cb_data->csw;
|
||||||
|
|
||||||
if (csw->status != 0)
|
if (csw->status != 0)
|
||||||
{
|
{
|
||||||
printf("Inquiry failed\r\n");
|
printf("Inquiry failed\r\n");
|
||||||
@ -140,7 +143,7 @@ void tuh_msc_mount_cb(uint8_t dev_addr)
|
|||||||
printf("A MassStorage device is mounted\r\n");
|
printf("A MassStorage device is mounted\r\n");
|
||||||
|
|
||||||
uint8_t const lun = 0;
|
uint8_t const lun = 0;
|
||||||
tuh_msc_inquiry(dev_addr, lun, &inquiry_resp, inquiry_complete_cb);
|
tuh_msc_inquiry(dev_addr, lun, &inquiry_resp, inquiry_complete_cb, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tuh_msc_umount_cb(uint8_t dev_addr)
|
void tuh_msc_umount_cb(uint8_t dev_addr)
|
||||||
@ -178,9 +181,9 @@ static void wait_for_disk_io(BYTE pdrv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool disk_io_complete(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const* csw)
|
static bool disk_io_complete(uint8_t dev_addr, tuh_msc_complete_data_t const * cb_data)
|
||||||
{
|
{
|
||||||
(void) dev_addr; (void) cbw; (void) csw;
|
(void) dev_addr; (void) cb_data;
|
||||||
_disk_busy[dev_addr-1] = false;
|
_disk_busy[dev_addr-1] = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -212,7 +215,7 @@ DRESULT disk_read (
|
|||||||
uint8_t const lun = 0;
|
uint8_t const lun = 0;
|
||||||
|
|
||||||
_disk_busy[pdrv] = true;
|
_disk_busy[pdrv] = true;
|
||||||
tuh_msc_read10(dev_addr, lun, buff, sector, (uint16_t) count, disk_io_complete);
|
tuh_msc_read10(dev_addr, lun, buff, sector, (uint16_t) count, disk_io_complete, 0);
|
||||||
wait_for_disk_io(pdrv);
|
wait_for_disk_io(pdrv);
|
||||||
|
|
||||||
return RES_OK;
|
return RES_OK;
|
||||||
@ -231,7 +234,7 @@ DRESULT disk_write (
|
|||||||
uint8_t const lun = 0;
|
uint8_t const lun = 0;
|
||||||
|
|
||||||
_disk_busy[pdrv] = true;
|
_disk_busy[pdrv] = true;
|
||||||
tuh_msc_write10(dev_addr, lun, buff, sector, (uint16_t) count, disk_io_complete);
|
tuh_msc_write10(dev_addr, lun, buff, sector, (uint16_t) count, disk_io_complete, 0);
|
||||||
wait_for_disk_io(pdrv);
|
wait_for_disk_io(pdrv);
|
||||||
|
|
||||||
return RES_OK;
|
return RES_OK;
|
||||||
|
@ -64,6 +64,7 @@ typedef struct
|
|||||||
uint8_t stage;
|
uint8_t stage;
|
||||||
void* buffer;
|
void* buffer;
|
||||||
tuh_msc_complete_cb_t complete_cb;
|
tuh_msc_complete_cb_t complete_cb;
|
||||||
|
uintptr_t complete_arg;
|
||||||
|
|
||||||
msc_cbw_t cbw;
|
msc_cbw_t cbw;
|
||||||
msc_csw_t csw;
|
msc_csw_t csw;
|
||||||
@ -126,7 +127,7 @@ static inline void cbw_init(msc_cbw_t *cbw, uint8_t lun)
|
|||||||
cbw->lun = lun;
|
cbw->lun = lun;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tuh_msc_scsi_command(uint8_t dev_addr, msc_cbw_t const* cbw, void* data, tuh_msc_complete_cb_t complete_cb)
|
bool tuh_msc_scsi_command(uint8_t dev_addr, msc_cbw_t const* cbw, void* data, tuh_msc_complete_cb_t complete_cb, uintptr_t arg)
|
||||||
{
|
{
|
||||||
msch_interface_t* p_msc = get_itf(dev_addr);
|
msch_interface_t* p_msc = get_itf(dev_addr);
|
||||||
TU_VERIFY(p_msc->configured);
|
TU_VERIFY(p_msc->configured);
|
||||||
@ -137,13 +138,14 @@ bool tuh_msc_scsi_command(uint8_t dev_addr, msc_cbw_t const* cbw, void* data, tu
|
|||||||
p_msc->stage = MSC_STAGE_CMD;
|
p_msc->stage = MSC_STAGE_CMD;
|
||||||
p_msc->buffer = data;
|
p_msc->buffer = data;
|
||||||
p_msc->complete_cb = complete_cb;
|
p_msc->complete_cb = complete_cb;
|
||||||
|
p_msc->complete_arg = arg;
|
||||||
|
|
||||||
TU_ASSERT(usbh_edpt_xfer(dev_addr, p_msc->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)));
|
TU_ASSERT(usbh_edpt_xfer(dev_addr, p_msc->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tuh_msc_read_capacity(uint8_t dev_addr, uint8_t lun, scsi_read_capacity10_resp_t* response, tuh_msc_complete_cb_t complete_cb)
|
bool tuh_msc_read_capacity(uint8_t dev_addr, uint8_t lun, scsi_read_capacity10_resp_t* response, tuh_msc_complete_cb_t complete_cb, uintptr_t arg)
|
||||||
{
|
{
|
||||||
msch_interface_t* p_msc = get_itf(dev_addr);
|
msch_interface_t* p_msc = get_itf(dev_addr);
|
||||||
TU_VERIFY(p_msc->configured);
|
TU_VERIFY(p_msc->configured);
|
||||||
@ -156,10 +158,10 @@ bool tuh_msc_read_capacity(uint8_t dev_addr, uint8_t lun, scsi_read_capacity10_r
|
|||||||
cbw.cmd_len = sizeof(scsi_read_capacity10_t);
|
cbw.cmd_len = sizeof(scsi_read_capacity10_t);
|
||||||
cbw.command[0] = SCSI_CMD_READ_CAPACITY_10;
|
cbw.command[0] = SCSI_CMD_READ_CAPACITY_10;
|
||||||
|
|
||||||
return tuh_msc_scsi_command(dev_addr, &cbw, response, complete_cb);
|
return tuh_msc_scsi_command(dev_addr, &cbw, response, complete_cb, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tuh_msc_inquiry(uint8_t dev_addr, uint8_t lun, scsi_inquiry_resp_t* response, tuh_msc_complete_cb_t complete_cb)
|
bool tuh_msc_inquiry(uint8_t dev_addr, uint8_t lun, scsi_inquiry_resp_t* response, tuh_msc_complete_cb_t complete_cb, uintptr_t arg)
|
||||||
{
|
{
|
||||||
msch_interface_t* p_msc = get_itf(dev_addr);
|
msch_interface_t* p_msc = get_itf(dev_addr);
|
||||||
TU_VERIFY(p_msc->mounted);
|
TU_VERIFY(p_msc->mounted);
|
||||||
@ -178,10 +180,10 @@ bool tuh_msc_inquiry(uint8_t dev_addr, uint8_t lun, scsi_inquiry_resp_t* respons
|
|||||||
};
|
};
|
||||||
memcpy(cbw.command, &cmd_inquiry, cbw.cmd_len);
|
memcpy(cbw.command, &cmd_inquiry, cbw.cmd_len);
|
||||||
|
|
||||||
return tuh_msc_scsi_command(dev_addr, &cbw, response, complete_cb);
|
return tuh_msc_scsi_command(dev_addr, &cbw, response, complete_cb, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tuh_msc_test_unit_ready(uint8_t dev_addr, uint8_t lun, tuh_msc_complete_cb_t complete_cb)
|
bool tuh_msc_test_unit_ready(uint8_t dev_addr, uint8_t lun, tuh_msc_complete_cb_t complete_cb, uintptr_t arg)
|
||||||
{
|
{
|
||||||
msch_interface_t* p_msc = get_itf(dev_addr);
|
msch_interface_t* p_msc = get_itf(dev_addr);
|
||||||
TU_VERIFY(p_msc->configured);
|
TU_VERIFY(p_msc->configured);
|
||||||
@ -195,10 +197,10 @@ bool tuh_msc_test_unit_ready(uint8_t dev_addr, uint8_t lun, tuh_msc_complete_cb_
|
|||||||
cbw.command[0] = SCSI_CMD_TEST_UNIT_READY;
|
cbw.command[0] = SCSI_CMD_TEST_UNIT_READY;
|
||||||
cbw.command[1] = lun; // according to wiki TODO need verification
|
cbw.command[1] = lun; // according to wiki TODO need verification
|
||||||
|
|
||||||
return tuh_msc_scsi_command(dev_addr, &cbw, NULL, complete_cb);
|
return tuh_msc_scsi_command(dev_addr, &cbw, NULL, complete_cb, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tuh_msc_request_sense(uint8_t dev_addr, uint8_t lun, void *resposne, tuh_msc_complete_cb_t complete_cb)
|
bool tuh_msc_request_sense(uint8_t dev_addr, uint8_t lun, void *resposne, tuh_msc_complete_cb_t complete_cb, uintptr_t arg)
|
||||||
{
|
{
|
||||||
msc_cbw_t cbw;
|
msc_cbw_t cbw;
|
||||||
cbw_init(&cbw, lun);
|
cbw_init(&cbw, lun);
|
||||||
@ -215,10 +217,10 @@ bool tuh_msc_request_sense(uint8_t dev_addr, uint8_t lun, void *resposne, tuh_ms
|
|||||||
|
|
||||||
memcpy(cbw.command, &cmd_request_sense, cbw.cmd_len);
|
memcpy(cbw.command, &cmd_request_sense, cbw.cmd_len);
|
||||||
|
|
||||||
return tuh_msc_scsi_command(dev_addr, &cbw, resposne, complete_cb);
|
return tuh_msc_scsi_command(dev_addr, &cbw, resposne, complete_cb, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tuh_msc_read10(uint8_t dev_addr, uint8_t lun, void * buffer, uint32_t lba, uint16_t block_count, tuh_msc_complete_cb_t complete_cb)
|
bool tuh_msc_read10(uint8_t dev_addr, uint8_t lun, void * buffer, uint32_t lba, uint16_t block_count, tuh_msc_complete_cb_t complete_cb, uintptr_t arg)
|
||||||
{
|
{
|
||||||
msch_interface_t* p_msc = get_itf(dev_addr);
|
msch_interface_t* p_msc = get_itf(dev_addr);
|
||||||
TU_VERIFY(p_msc->mounted);
|
TU_VERIFY(p_msc->mounted);
|
||||||
@ -239,10 +241,10 @@ bool tuh_msc_read10(uint8_t dev_addr, uint8_t lun, void * buffer, uint32_t lba,
|
|||||||
|
|
||||||
memcpy(cbw.command, &cmd_read10, cbw.cmd_len);
|
memcpy(cbw.command, &cmd_read10, cbw.cmd_len);
|
||||||
|
|
||||||
return tuh_msc_scsi_command(dev_addr, &cbw, buffer, complete_cb);
|
return tuh_msc_scsi_command(dev_addr, &cbw, buffer, complete_cb, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tuh_msc_write10(uint8_t dev_addr, uint8_t lun, void const * buffer, uint32_t lba, uint16_t block_count, tuh_msc_complete_cb_t complete_cb)
|
bool tuh_msc_write10(uint8_t dev_addr, uint8_t lun, void const * buffer, uint32_t lba, uint16_t block_count, tuh_msc_complete_cb_t complete_cb, uintptr_t arg)
|
||||||
{
|
{
|
||||||
msch_interface_t* p_msc = get_itf(dev_addr);
|
msch_interface_t* p_msc = get_itf(dev_addr);
|
||||||
TU_VERIFY(p_msc->mounted);
|
TU_VERIFY(p_msc->mounted);
|
||||||
@ -263,7 +265,7 @@ bool tuh_msc_write10(uint8_t dev_addr, uint8_t lun, void const * buffer, uint32_
|
|||||||
|
|
||||||
memcpy(cbw.command, &cmd_write10, cbw.cmd_len);
|
memcpy(cbw.command, &cmd_write10, cbw.cmd_len);
|
||||||
|
|
||||||
return tuh_msc_scsi_command(dev_addr, &cbw, (void*)(uintptr_t) buffer, complete_cb);
|
return tuh_msc_scsi_command(dev_addr, &cbw, (void*)(uintptr_t) buffer, complete_cb, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@ -344,7 +346,17 @@ bool msch_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32
|
|||||||
// SCSI op is complete
|
// SCSI op is complete
|
||||||
p_msc->stage = MSC_STAGE_IDLE;
|
p_msc->stage = MSC_STAGE_IDLE;
|
||||||
|
|
||||||
if (p_msc->complete_cb) p_msc->complete_cb(dev_addr, cbw, csw);
|
if (p_msc->complete_cb)
|
||||||
|
{
|
||||||
|
tuh_msc_complete_data_t const cb_data =
|
||||||
|
{
|
||||||
|
.cbw = cbw,
|
||||||
|
.csw = csw,
|
||||||
|
.scsi_data = p_msc->buffer,
|
||||||
|
.user_arg = p_msc->complete_arg
|
||||||
|
};
|
||||||
|
p_msc->complete_cb(dev_addr, &cb_data);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// unknown state
|
// unknown state
|
||||||
@ -359,9 +371,9 @@ bool msch_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32
|
|||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
|
||||||
static void config_get_maxlun_complete (tuh_xfer_t* xfer);
|
static void config_get_maxlun_complete (tuh_xfer_t* xfer);
|
||||||
static bool config_test_unit_ready_complete(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const* csw);
|
static bool config_test_unit_ready_complete(uint8_t dev_addr, tuh_msc_complete_data_t const * cb_data);
|
||||||
static bool config_request_sense_complete(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const* csw);
|
static bool config_request_sense_complete(uint8_t dev_addr, tuh_msc_complete_data_t const* cb_data);
|
||||||
static bool config_read_capacity_complete(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const* csw);
|
static bool config_read_capacity_complete(uint8_t dev_addr, tuh_msc_complete_data_t const* cb_data);
|
||||||
|
|
||||||
bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *desc_itf, uint16_t max_len)
|
bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *desc_itf, uint16_t max_len)
|
||||||
{
|
{
|
||||||
@ -446,37 +458,46 @@ static void config_get_maxlun_complete (tuh_xfer_t* xfer)
|
|||||||
// TODO multiple LUN support
|
// TODO multiple LUN support
|
||||||
TU_LOG2("SCSI Test Unit Ready\r\n");
|
TU_LOG2("SCSI Test Unit Ready\r\n");
|
||||||
uint8_t const lun = 0;
|
uint8_t const lun = 0;
|
||||||
tuh_msc_test_unit_ready(daddr, lun, config_test_unit_ready_complete);
|
tuh_msc_test_unit_ready(daddr, lun, config_test_unit_ready_complete, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool config_test_unit_ready_complete(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const* csw)
|
static bool config_test_unit_ready_complete(uint8_t dev_addr, tuh_msc_complete_data_t const * cb_data)
|
||||||
{
|
{
|
||||||
|
msc_cbw_t const* cbw = cb_data->cbw;
|
||||||
|
msc_csw_t const* csw = cb_data->csw;
|
||||||
|
|
||||||
if (csw->status == 0)
|
if (csw->status == 0)
|
||||||
{
|
{
|
||||||
// Unit is ready, read its capacity
|
// Unit is ready, read its capacity
|
||||||
TU_LOG2("SCSI Read Capacity\r\n");
|
TU_LOG2("SCSI Read Capacity\r\n");
|
||||||
tuh_msc_read_capacity(dev_addr, cbw->lun, (scsi_read_capacity10_resp_t*) ((void*) _msch_buffer), config_read_capacity_complete);
|
tuh_msc_read_capacity(dev_addr, cbw->lun, (scsi_read_capacity10_resp_t*) ((void*) _msch_buffer), config_read_capacity_complete, 0);
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
// Note: During enumeration, some device fails Test Unit Ready and require a few retries
|
// Note: During enumeration, some device fails Test Unit Ready and require a few retries
|
||||||
// with Request Sense to start working !!
|
// with Request Sense to start working !!
|
||||||
// TODO limit number of retries
|
// TODO limit number of retries
|
||||||
TU_LOG2("SCSI Request Sense\r\n");
|
TU_LOG2("SCSI Request Sense\r\n");
|
||||||
TU_ASSERT(tuh_msc_request_sense(dev_addr, cbw->lun, _msch_buffer, config_request_sense_complete));
|
TU_ASSERT(tuh_msc_request_sense(dev_addr, cbw->lun, _msch_buffer, config_request_sense_complete, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool config_request_sense_complete(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const* csw)
|
static bool config_request_sense_complete(uint8_t dev_addr, tuh_msc_complete_data_t const * cb_data)
|
||||||
{
|
{
|
||||||
|
msc_cbw_t const* cbw = cb_data->cbw;
|
||||||
|
msc_csw_t const* csw = cb_data->csw;
|
||||||
|
|
||||||
TU_ASSERT(csw->status == 0);
|
TU_ASSERT(csw->status == 0);
|
||||||
TU_ASSERT(tuh_msc_test_unit_ready(dev_addr, cbw->lun, config_test_unit_ready_complete));
|
TU_ASSERT(tuh_msc_test_unit_ready(dev_addr, cbw->lun, config_test_unit_ready_complete, 0));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool config_read_capacity_complete(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const* csw)
|
static bool config_read_capacity_complete(uint8_t dev_addr, tuh_msc_complete_data_t const * cb_data)
|
||||||
{
|
{
|
||||||
|
msc_cbw_t const* cbw = cb_data->cbw;
|
||||||
|
msc_csw_t const* csw = cb_data->csw;
|
||||||
|
|
||||||
TU_ASSERT(csw->status == 0);
|
TU_ASSERT(csw->status == 0);
|
||||||
|
|
||||||
msch_interface_t* p_msc = get_itf(dev_addr);
|
msch_interface_t* p_msc = get_itf(dev_addr);
|
||||||
|
@ -41,7 +41,14 @@
|
|||||||
#define CFG_TUH_MSC_MAXLUN 4
|
#define CFG_TUH_MSC_MAXLUN 4
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef bool (*tuh_msc_complete_cb_t)(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const* csw);
|
typedef struct {
|
||||||
|
msc_cbw_t const* cbw; // SCSI command
|
||||||
|
msc_csw_t const* csw; // SCSI status
|
||||||
|
void* scsi_data; // SCSI Data
|
||||||
|
uintptr_t user_arg; // user argument
|
||||||
|
}tuh_msc_complete_data_t;
|
||||||
|
|
||||||
|
typedef bool (*tuh_msc_complete_cb_t)(uint8_t dev_addr, tuh_msc_complete_data_t const* cb_data);
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Application API
|
// Application API
|
||||||
@ -66,33 +73,33 @@ uint32_t tuh_msc_get_block_size(uint8_t dev_addr, uint8_t lun);
|
|||||||
// Perform a full SCSI command (cbw, data, csw) in non-blocking manner.
|
// Perform a full SCSI command (cbw, data, csw) in non-blocking manner.
|
||||||
// Complete callback is invoked when SCSI op is complete.
|
// Complete callback is invoked when SCSI op is complete.
|
||||||
// return true if success, false if there is already pending operation.
|
// return true if success, false if there is already pending operation.
|
||||||
bool tuh_msc_scsi_command(uint8_t dev_addr, msc_cbw_t const* cbw, void* data, tuh_msc_complete_cb_t complete_cb);
|
bool tuh_msc_scsi_command(uint8_t dev_addr, msc_cbw_t const* cbw, void* data, tuh_msc_complete_cb_t complete_cb, uintptr_t arg);
|
||||||
|
|
||||||
// Perform SCSI Inquiry command
|
// Perform SCSI Inquiry command
|
||||||
// Complete callback is invoked when SCSI op is complete.
|
// Complete callback is invoked when SCSI op is complete.
|
||||||
bool tuh_msc_inquiry(uint8_t dev_addr, uint8_t lun, scsi_inquiry_resp_t* response, tuh_msc_complete_cb_t complete_cb);
|
bool tuh_msc_inquiry(uint8_t dev_addr, uint8_t lun, scsi_inquiry_resp_t* response, tuh_msc_complete_cb_t complete_cb, uintptr_t arg);
|
||||||
|
|
||||||
// Perform SCSI Test Unit Ready command
|
// Perform SCSI Test Unit Ready command
|
||||||
// Complete callback is invoked when SCSI op is complete.
|
// Complete callback is invoked when SCSI op is complete.
|
||||||
bool tuh_msc_test_unit_ready(uint8_t dev_addr, uint8_t lun, tuh_msc_complete_cb_t complete_cb);
|
bool tuh_msc_test_unit_ready(uint8_t dev_addr, uint8_t lun, tuh_msc_complete_cb_t complete_cb, uintptr_t arg);
|
||||||
|
|
||||||
// Perform SCSI Request Sense 10 command
|
// Perform SCSI Request Sense 10 command
|
||||||
// Complete callback is invoked when SCSI op is complete.
|
// Complete callback is invoked when SCSI op is complete.
|
||||||
bool tuh_msc_request_sense(uint8_t dev_addr, uint8_t lun, void *resposne, tuh_msc_complete_cb_t complete_cb);
|
bool tuh_msc_request_sense(uint8_t dev_addr, uint8_t lun, void *resposne, tuh_msc_complete_cb_t complete_cb, uintptr_t arg);
|
||||||
|
|
||||||
// Perform SCSI Read 10 command. Read n blocks starting from LBA to buffer
|
// Perform SCSI Read 10 command. Read n blocks starting from LBA to buffer
|
||||||
// Complete callback is invoked when SCSI op is complete.
|
// Complete callback is invoked when SCSI op is complete.
|
||||||
bool tuh_msc_read10(uint8_t dev_addr, uint8_t lun, void * buffer, uint32_t lba, uint16_t block_count, tuh_msc_complete_cb_t complete_cb);
|
bool tuh_msc_read10(uint8_t dev_addr, uint8_t lun, void * buffer, uint32_t lba, uint16_t block_count, tuh_msc_complete_cb_t complete_cb, uintptr_t arg);
|
||||||
|
|
||||||
// Perform SCSI Write 10 command. Write n blocks starting from LBA to device
|
// Perform SCSI Write 10 command. Write n blocks starting from LBA to device
|
||||||
// Complete callback is invoked when SCSI op is complete.
|
// Complete callback is invoked when SCSI op is complete.
|
||||||
bool tuh_msc_write10(uint8_t dev_addr, uint8_t lun, void const * buffer, uint32_t lba, uint16_t block_count, tuh_msc_complete_cb_t complete_cb);
|
bool tuh_msc_write10(uint8_t dev_addr, uint8_t lun, void const * buffer, uint32_t lba, uint16_t block_count, tuh_msc_complete_cb_t complete_cb, uintptr_t arg);
|
||||||
|
|
||||||
// Perform SCSI Read Capacity 10 command
|
// Perform SCSI Read Capacity 10 command
|
||||||
// Complete callback is invoked when SCSI op is complete.
|
// Complete callback is invoked when SCSI op is complete.
|
||||||
// Note: during enumeration, host stack already carried out this request. Application can retrieve capacity by
|
// Note: during enumeration, host stack already carried out this request. Application can retrieve capacity by
|
||||||
// simply call tuh_msc_get_block_count() and tuh_msc_get_block_size()
|
// simply call tuh_msc_get_block_count() and tuh_msc_get_block_size()
|
||||||
bool tuh_msc_read_capacity(uint8_t dev_addr, uint8_t lun, scsi_read_capacity10_resp_t* response, tuh_msc_complete_cb_t complete_cb);
|
bool tuh_msc_read_capacity(uint8_t dev_addr, uint8_t lun, scsi_read_capacity10_resp_t* response, tuh_msc_complete_cb_t complete_cb, uintptr_t arg);
|
||||||
|
|
||||||
//------------- Application Callback -------------//
|
//------------- Application Callback -------------//
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user