mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-31 05:52:55 +08:00
add tusbh_msc_status
reanme PRINTF_TARGET_DEBUG_CONSOLE to PRINTF_TARGET_SEMIHOST add read10 implementation able to read fat root sector
This commit is contained in:
parent
cf65f859be
commit
1fee50b9fe
@ -78,7 +78,7 @@
|
||||
//--------------------------------------------------------------------+
|
||||
// PRINTF TARGET DEFINE
|
||||
//--------------------------------------------------------------------+
|
||||
#define PRINTF_TARGET_DEBUG_CONSOLE 1 // IDE semihosting console
|
||||
#define PRINTF_TARGET_SEMIHOST 1
|
||||
#define PRINTF_TARGET_UART 2
|
||||
#define PRINTF_TARGET_SWO 3 // aka SWV, ITM
|
||||
#define PRINTF_TARGET_NONE 4
|
||||
|
@ -66,6 +66,7 @@
|
||||
|
||||
#include "oem_base_board/pca9532.h" // LEDs
|
||||
|
||||
|
||||
//#define CFG_PRINTF_TARGET PRINTF_TARGET_SWO
|
||||
#define CFG_PRINTF_TARGET PRINTF_TARGET_UART // FIXME keil's cmsis rtx does not work with UART (work with SWO)
|
||||
|
||||
|
@ -56,7 +56,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define CFG_PRINTF_TARGET PRINTF_TARGET_DEBUG_CONSOLE
|
||||
#define CFG_PRINTF_TARGET PRINTF_TARGET_SEMIHOST
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -56,7 +56,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define CFG_PRINTF_TARGET PRINTF_TARGET_DEBUG_CONSOLE
|
||||
#define CFG_PRINTF_TARGET PRINTF_TARGET_SEMIHOST
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -65,7 +65,7 @@
|
||||
#define CFG_LED_ON (1)
|
||||
#define CFG_LED_OFF (0)
|
||||
|
||||
#define CFG_PRINTF_TARGET PRINTF_TARGET_DEBUG_CONSOLE
|
||||
#define CFG_PRINTF_TARGET PRINTF_TARGET_SEMIHOST
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -57,7 +57,7 @@
|
||||
#define CFG_LED_PORT (0)
|
||||
#define CFG_LED_PIN (22)
|
||||
|
||||
#define CFG_PRINTF_TARGET PRINTF_TARGET_DEBUG_CONSOLE
|
||||
#define CFG_PRINTF_TARGET PRINTF_TARGET_SEMIHOST
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -60,7 +60,7 @@
|
||||
#include "lpc11uxx/gpio.h"
|
||||
#include "lpc11uxx/uart.h"
|
||||
|
||||
#define CFG_PRINTF_TARGET PRINTF_TARGET_DEBUG_CONSOLE
|
||||
#define CFG_PRINTF_TARGET PRINTF_TARGET_SEMIHOST
|
||||
|
||||
#define CFG_LED_PORT (1)
|
||||
#define CFG_LED_PIN (31)
|
||||
|
@ -56,7 +56,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define CFG_PRINTF_TARGET PRINTF_TARGET_DEBUG_CONSOLE
|
||||
#define CFG_PRINTF_TARGET PRINTF_TARGET_SEMIHOST
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -38,7 +38,7 @@
|
||||
|
||||
#include "board.h"
|
||||
|
||||
#if CFG_PRINTF_TARGET != PRINTF_TARGET_DEBUG_CONSOLE
|
||||
#if CFG_PRINTF_TARGET != PRINTF_TARGET_SEMIHOST
|
||||
|
||||
#if CFG_PRINTF_TARGET == PRINTF_TARGET_UART
|
||||
#define retarget_getchar() board_uart_getchar()
|
||||
@ -146,4 +146,4 @@ void _ttywrch(int ch)
|
||||
|
||||
#endif
|
||||
|
||||
#endif // CFG_PRINTF_TARGET != PRINTF_TARGET_DEBUG_CONSOLE
|
||||
#endif // CFG_PRINTF_TARGET != PRINTF_TARGET_SEMIHOST
|
||||
|
@ -480,7 +480,7 @@
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>1</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>189</TopLine>
|
||||
<TopLine>193</TopLine>
|
||||
<CurrentLine>200</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\src\main.c</PathWithFileName>
|
||||
@ -496,7 +496,7 @@
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>0</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>94</TopLine>
|
||||
<TopLine>127</TopLine>
|
||||
<CurrentLine>145</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\src\cdc_serial_app.c</PathWithFileName>
|
||||
@ -512,7 +512,7 @@
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>0</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>136</TopLine>
|
||||
<TopLine>169</TopLine>
|
||||
<CurrentLine>180</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\src\keyboard_app.c</PathWithFileName>
|
||||
@ -528,7 +528,7 @@
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>44</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>120</TopLine>
|
||||
<TopLine>121</TopLine>
|
||||
<CurrentLine>127</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\src\mouse_app.c</PathWithFileName>
|
||||
@ -576,7 +576,7 @@
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>30</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>63</TopLine>
|
||||
<TopLine>68</TopLine>
|
||||
<CurrentLine>75</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\src\cli.c</PathWithFileName>
|
||||
@ -616,7 +616,7 @@
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>0</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>136</TopLine>
|
||||
<TopLine>137</TopLine>
|
||||
<CurrentLine>142</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\bsp\boards\embedded_artists\board_ea4357.c</PathWithFileName>
|
||||
@ -630,10 +630,10 @@
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>25</ColumnNumber>
|
||||
<ColumnNumber>6</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>100</TopLine>
|
||||
<CurrentLine>132</CurrentLine>
|
||||
<TopLine>128</TopLine>
|
||||
<CurrentLine>135</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\bsp\boards\printf_retarget.c</PathWithFileName>
|
||||
<FilenameWithoutPath>printf_retarget.c</FilenameWithoutPath>
|
||||
@ -768,7 +768,7 @@
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>0</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>25</TopLine>
|
||||
<TopLine>58</TopLine>
|
||||
<CurrentLine>76</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\..\tinyusb\tusb.c</PathWithFileName>
|
||||
@ -832,7 +832,7 @@
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>0</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>483</TopLine>
|
||||
<TopLine>494</TopLine>
|
||||
<CurrentLine>501</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\..\tinyusb\host\usbh.c</PathWithFileName>
|
||||
@ -848,7 +848,7 @@
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>0</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>599</TopLine>
|
||||
<TopLine>600</TopLine>
|
||||
<CurrentLine>605</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\..\tinyusb\host\ehci\ehci.c</PathWithFileName>
|
||||
@ -1006,10 +1006,10 @@
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>47</ColumnNumber>
|
||||
<ColumnNumber>0</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>3</TopLine>
|
||||
<CurrentLine>13</CurrentLine>
|
||||
<TopLine>1</TopLine>
|
||||
<CurrentLine>1</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\..\tinyusb\class\msc_host.c</PathWithFileName>
|
||||
<FilenameWithoutPath>msc_host.c</FilenameWithoutPath>
|
||||
@ -1032,7 +1032,7 @@
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>0</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>533</TopLine>
|
||||
<TopLine>546</TopLine>
|
||||
<CurrentLine>553</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\bsp\lpc43xx\CMSIS_LPC43xx_DriverLib\src\lpc43xx_uart.c</PathWithFileName>
|
||||
@ -1136,7 +1136,7 @@
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>26</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>145</TopLine>
|
||||
<TopLine>147</TopLine>
|
||||
<CurrentLine>154</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\bsp\lpc43xx\startup_keil\startup_LPC43xx.s</PathWithFileName>
|
||||
@ -1158,10 +1158,10 @@
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>56</ColumnNumber>
|
||||
<ColumnNumber>0</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>1</TopLine>
|
||||
<CurrentLine>20</CurrentLine>
|
||||
<TopLine>13</TopLine>
|
||||
<CurrentLine>23</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\..\vendor\fatfs\diskio.c</PathWithFileName>
|
||||
<FilenameWithoutPath>diskio.c</FilenameWithoutPath>
|
||||
|
@ -84,14 +84,37 @@ void tusbh_msc_mounted_cb(uint8_t dev_addr)
|
||||
printf("LBA 0-0x%X Block Size: %d\n", last_lba, block_size);
|
||||
|
||||
//------------- file system (only 1 LUN support) -------------//
|
||||
DSTATUS stat = disk_initialize(0);
|
||||
// DSTATUS stat = disk_initialize(0);
|
||||
disk_state = 0;
|
||||
|
||||
if ( disk_is_ready(0) )
|
||||
{
|
||||
f_mount(0, &fatfs[dev_addr-1]);
|
||||
if ( f_mount(0, &fatfs[dev_addr-1]) != FR_OK )
|
||||
{
|
||||
puts("mount failed");
|
||||
return;
|
||||
}
|
||||
|
||||
DIR root_dir;
|
||||
if ( f_opendir(&root_dir, "/") != FR_OK )
|
||||
{
|
||||
puts("open root dir failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tusbh_msc_unmounted_isr(uint8_t dev_addr)
|
||||
{
|
||||
disk_state = STA_NOINIT;
|
||||
puts("--");
|
||||
}
|
||||
|
||||
void tusbh_msc_isr(uint8_t dev_addr, tusb_event_t event, uint32_t xferred_bytes)
|
||||
{
|
||||
putchar('x');
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// IMPLEMENTATION
|
||||
//--------------------------------------------------------------------+
|
||||
|
@ -64,6 +64,10 @@ enum {
|
||||
MSC_SUBCLASS_SCSI
|
||||
};
|
||||
|
||||
enum {
|
||||
MSC_CBW_SIGNATURE = 0x43425355,
|
||||
};
|
||||
|
||||
// CBI only approved to use with full-speed floopy disk & should not used with highspeed or device other than floopy
|
||||
enum {
|
||||
MSC_PROTOCOL_CBI = 0,
|
||||
@ -171,13 +175,16 @@ typedef ATTR_PACKED_STRUCT(struct)
|
||||
|
||||
STATIC_ASSERT(sizeof(scsi_inquiry_data_t) == 36, "size is not correct");
|
||||
|
||||
// test unit ready
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// SCSI Block Command (SBC-3)
|
||||
// NOTE: All data in SCSI command are in Big Endian
|
||||
//--------------------------------------------------------------------+
|
||||
typedef ATTR_PACKED_STRUCT(struct) {
|
||||
uint8_t cmd_code;
|
||||
uint8_t reserved1;
|
||||
uint32_t logical_block_addr;
|
||||
uint32_t lba;
|
||||
uint16_t reserved2;
|
||||
uint8_t partial_medium_indicator;
|
||||
uint8_t control;
|
||||
@ -192,6 +199,19 @@ typedef struct {
|
||||
|
||||
STATIC_ASSERT(sizeof(scsi_read_capacity10_data_t) == 8, "size is not correct");
|
||||
|
||||
typedef ATTR_PACKED_STRUCT(struct) {
|
||||
uint8_t cmd_code;
|
||||
uint8_t reserved; // has LUN according to wiki
|
||||
uint32_t lba;
|
||||
uint8_t reserved2;
|
||||
uint16_t block_count;
|
||||
uint8_t control;
|
||||
} scsi_read10_t;
|
||||
|
||||
STATIC_ASSERT(sizeof(scsi_read10_t) == 10, "size is not correct");
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -53,6 +53,7 @@
|
||||
//--------------------------------------------------------------------+
|
||||
STATIC_VAR msch_interface_t msch_data[TUSB_CFG_HOST_DEVICE_MAX] TUSB_CFG_ATTR_USBRAM;
|
||||
|
||||
|
||||
//------------- Initalization Data -------------//
|
||||
OSAL_SEM_DEF(msch_semaphore);
|
||||
static osal_semaphore_handle_t msch_sem_hdl;
|
||||
@ -69,9 +70,8 @@ ATTR_ALIGNED(4) STATIC_VAR uint8_t msch_buffer[sizeof(scsi_inquiry_data_t)] TUSB
|
||||
//--------------------------------------------------------------------+
|
||||
bool tusbh_msc_is_mounted(uint8_t dev_addr)
|
||||
{
|
||||
return tusbh_device_is_configured(dev_addr) &&
|
||||
pipehandle_is_valid(msch_data[dev_addr-1].bulk_in) &&
|
||||
pipehandle_is_valid(msch_data[dev_addr-1].bulk_out);
|
||||
return tusbh_device_is_configured(dev_addr) && // is configured can be omitted
|
||||
msch_data[dev_addr-1].is_initialized;
|
||||
}
|
||||
|
||||
uint8_t const* tusbh_msc_get_vendor_name(uint8_t dev_addr)
|
||||
@ -95,12 +95,32 @@ tusb_error_t tusbh_msc_get_capacity(uint8_t dev_addr, uint32_t* p_last_lba, uint
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
tusb_interface_status_t tusbh_msc_status(uint8_t dev_addr)
|
||||
{
|
||||
if ( !tusbh_msc_is_mounted(dev_addr) ) return TUSB_INTERFACE_STATUS_INVALID_PARA;
|
||||
|
||||
if ( hcd_pipe_is_busy(msch_data[dev_addr-1].bulk_in) ) return TUSB_INTERFACE_STATUS_BUSY;
|
||||
if ( hcd_pipe_is_stalled(msch_data[dev_addr-1].bulk_in) ) return TUSB_INTERFACE_STATUS_ERROR;
|
||||
|
||||
return TUSB_INTERFACE_STATUS_READY;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// CLASS-USBH API (don't require to verify parameters)
|
||||
//--------------------------------------------------------------------+
|
||||
static tusb_error_t msch_command_xfer(msch_interface_t * p_msch, void* p_buffer) ATTR_WARN_UNUSED_RESULT;
|
||||
static tusb_error_t msch_command_xfer(msch_interface_t * p_msch, void* p_buffer)
|
||||
{
|
||||
ASSERT_STATUS( hcd_pipe_xfer(p_msch->bulk_out, &p_msch->cbw, sizeof(msc_cmd_block_wrapper_t), false) );
|
||||
ASSERT_STATUS( hcd_pipe_queue_xfer(p_msch->bulk_in , p_buffer, p_msch->cbw.xfer_bytes) );
|
||||
ASSERT_STATUS( hcd_pipe_xfer(p_msch->bulk_in , &p_msch->csw, sizeof(msc_cmd_status_wrapper_t), true) );
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
static tusb_error_t scsi_command_send(msch_interface_t * p_msch, scsi_cmd_type_t cmd_code, uint8_t lun, uint8_t* p_data)
|
||||
{
|
||||
p_msch->cbw.signature = 0x43425355;
|
||||
p_msch->cbw.signature = MSC_CBW_SIGNATURE;
|
||||
p_msch->cbw.tag = 0xCAFECAFE;
|
||||
p_msch->cbw.lun = lun;
|
||||
|
||||
@ -113,7 +133,7 @@ static tusb_error_t scsi_command_send(msch_interface_t * p_msch, scsi_cmd_type_t
|
||||
|
||||
scsi_inquiry_t cmd_inquiry =
|
||||
{
|
||||
.cmd_code = SCSI_CMD_INQUIRY,
|
||||
.cmd_code = cmd_code,
|
||||
.alloc_length = sizeof(scsi_inquiry_data_t)
|
||||
};
|
||||
|
||||
@ -127,8 +147,8 @@ static tusb_error_t scsi_command_send(msch_interface_t * p_msch, scsi_cmd_type_t
|
||||
|
||||
scsi_read_capacity10_t cmd_read_capacity10 =
|
||||
{
|
||||
.cmd_code = SCSI_CMD_READ_CAPACITY_10,
|
||||
.logical_block_addr = 0,
|
||||
.cmd_code = cmd_code,
|
||||
.lba = 0,
|
||||
.partial_medium_indicator = 0
|
||||
};
|
||||
|
||||
@ -139,6 +159,7 @@ static tusb_error_t scsi_command_send(msch_interface_t * p_msch, scsi_cmd_type_t
|
||||
break;
|
||||
|
||||
case SCSI_CMD_READ_10:
|
||||
|
||||
break;
|
||||
|
||||
case SCSI_CMD_WRITE_10:
|
||||
@ -151,7 +172,7 @@ static tusb_error_t scsi_command_send(msch_interface_t * p_msch, scsi_cmd_type_t
|
||||
|
||||
scsi_request_sense_t cmd_request_sense =
|
||||
{
|
||||
.cmd_code = SCSI_CMD_REQUEST_SENSE,
|
||||
.cmd_code = cmd_code,
|
||||
.alloc_length = 18
|
||||
};
|
||||
|
||||
@ -162,9 +183,36 @@ static tusb_error_t scsi_command_send(msch_interface_t * p_msch, scsi_cmd_type_t
|
||||
return TUSB_ERROR_MSCH_UNKNOWN_SCSI_COMMAND;
|
||||
}
|
||||
|
||||
ASSERT_STATUS( hcd_pipe_xfer(p_msch->bulk_out, (uint8_t*) &p_msch->cbw, sizeof(msc_cmd_block_wrapper_t), false) );
|
||||
ASSERT_STATUS( hcd_pipe_queue_xfer(p_msch->bulk_in , p_data, p_msch->cbw.xfer_bytes) );
|
||||
ASSERT_STATUS( hcd_pipe_xfer(p_msch->bulk_in , &p_msch->csw, sizeof(msc_cmd_status_wrapper_t), true) );
|
||||
ASSERT_STATUS( msch_command_xfer(p_msch, p_data) );
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
tusb_error_t tusbh_msc_read10(uint8_t dev_addr, uint8_t lun, void * p_buffer, uint32_t lba, uint32_t block_count)
|
||||
{
|
||||
msch_interface_t* p_msch = &msch_data[dev_addr-1];
|
||||
|
||||
//------------- Command Block Wrapper -------------//
|
||||
p_msch->cbw.signature = MSC_CBW_SIGNATURE;
|
||||
p_msch->cbw.tag = 0xCAFECAFE;
|
||||
p_msch->cbw.lun = lun;
|
||||
p_msch->cbw.xfer_bytes = p_msch->block_size*block_count; // Number of bytes
|
||||
p_msch->cbw.flags = TUSB_DIR_DEV_TO_HOST_MASK;
|
||||
p_msch->cbw.cmd_len = sizeof(scsi_read10_t);
|
||||
|
||||
//------------- SCSI command -------------//
|
||||
scsi_read10_t cmd_read10 =
|
||||
{
|
||||
.cmd_code = SCSI_CMD_READ_10,
|
||||
.lba = __le2be(lba),
|
||||
.block_count = ((uint8_t)block_count) << 8 // TODO a proper le to be for uint16_t
|
||||
};
|
||||
|
||||
memcpy(p_msch->cbw.command, &cmd_read10, p_msch->cbw.cmd_len);
|
||||
|
||||
ASSERT_STATUS ( msch_command_xfer(p_msch, p_buffer));
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
void msch_init(void)
|
||||
@ -269,6 +317,7 @@ tusb_error_t msch_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t con
|
||||
msch_data[dev_addr-1].last_lba = __be2le( ((scsi_read_capacity10_data_t*)msch_buffer)->last_lba );
|
||||
msch_data[dev_addr-1].block_size = (uint16_t) __be2le( ((scsi_read_capacity10_data_t*)msch_buffer)->block_size );
|
||||
|
||||
msch_data[dev_addr-1].is_initialized = true;
|
||||
tusbh_msc_mounted_cb(dev_addr);
|
||||
|
||||
OSAL_SUBTASK_END
|
||||
@ -280,7 +329,13 @@ void msch_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes
|
||||
{
|
||||
if ( pipehandle_is_equal(pipe_hdl, msch_data[pipe_hdl.dev_addr-1].bulk_in) )
|
||||
{
|
||||
osal_semaphore_post(msch_sem_hdl);
|
||||
if (msch_data[pipe_hdl.dev_addr-1].is_initialized)
|
||||
{
|
||||
tusbh_msc_isr(pipe_hdl.dev_addr, event, xferred_bytes);
|
||||
}else
|
||||
{ // still initializing under open subtask
|
||||
osal_semaphore_post(msch_sem_hdl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -291,6 +346,8 @@ void msch_close(uint8_t dev_addr)
|
||||
|
||||
memclr_(&msch_data[dev_addr-1], sizeof(msch_interface_t));
|
||||
osal_semaphore_reset(msch_sem_hdl);
|
||||
|
||||
tusbh_msc_unmounted_isr(dev_addr); // invoke Application Callback
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
|
@ -64,12 +64,13 @@ uint8_t const* tusbh_msc_get_vendor_name(uint8_t dev_addr);
|
||||
uint8_t const* tusbh_msc_get_product_name(uint8_t dev_addr);
|
||||
tusb_error_t tusbh_msc_get_capacity(uint8_t dev_addr, uint32_t* p_last_lba, uint32_t* p_block_size);
|
||||
|
||||
tusb_error_t tusbh_msc_inquiry(uint8_t dev_addr, scsi_inquiry_data_t * p_inquiry_data) ATTR_WARN_UNUSED_RESULT;
|
||||
tusb_error_t tusbh_msc_test_unit_ready(uint8_t dev_addr) ATTR_WARN_UNUSED_RESULT;
|
||||
tusb_error_t tusbh_msc_read_capacity10(uint8_t dev_addr, scsi_read_capacity10_t * p_buffer) ATTR_WARN_UNUSED_RESULT;
|
||||
tusb_error_t tusbh_msc_read10(uint8_t dev_addr, void * p_buffer, uint32_t length) ATTR_WARN_UNUSED_RESULT;
|
||||
tusb_error_t tusbh_msc_read10(uint8_t dev_addr, uint8_t lun, void * p_buffer, uint32_t lba, uint32_t block_count) ATTR_WARN_UNUSED_RESULT;
|
||||
tusb_error_t tusbh_msc_write10(uint8_t dev_addr, void const * p_data, uint32_t length) ATTR_WARN_UNUSED_RESULT;
|
||||
|
||||
//tusb_error_t tusbh_msc_test_unit_ready(uint8_t dev_addr) ATTR_WARN_UNUSED_RESULT;
|
||||
//tusb_error_t tusbh_msc_inquiry(uint8_t dev_addr, scsi_inquiry_data_t * p_inquiry_data) ATTR_WARN_UNUSED_RESULT;
|
||||
//tusb_error_t tusbh_msc_read_capacity10(uint8_t dev_addr, scsi_read_capacity10_t * p_buffer) ATTR_WARN_UNUSED_RESULT;
|
||||
|
||||
//tusb_error_t tusbh_msc_scsi_send(uint8_t dev_addr, uint8_t lun, bool is_direction_in,
|
||||
// uint8_t const * p_command, uint8_t cmd_len,
|
||||
// uint8_t * p_response, uint32_t resp_len) ATTR_WARN_UNUSED_RESULT;
|
||||
@ -77,7 +78,7 @@ tusb_error_t tusbh_msc_write10(uint8_t dev_addr, void const * p_data, uint32_t
|
||||
//------------- Application Callback -------------//
|
||||
void tusbh_msc_mounted_cb(uint8_t dev_addr);
|
||||
void tusbh_msc_unmounted_isr(uint8_t dev_addr);
|
||||
void tusbh_msc_isr(uint8_t dev_addr, tusb_event_t event);
|
||||
void tusbh_msc_isr(uint8_t dev_addr, tusb_event_t event, uint32_t xferred_bytes);
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@ -93,6 +94,7 @@ typedef struct {
|
||||
uint16_t block_size;
|
||||
uint32_t last_lba; // last logical block address
|
||||
|
||||
bool is_initialized;
|
||||
uint8_t vendor_id[8];
|
||||
uint8_t product_id[16];
|
||||
|
||||
|
@ -132,6 +132,9 @@
|
||||
|
||||
// built-in function to convert 32-bit Big-Endian to Little-Endian
|
||||
#define __be2le __builtin_bswap32
|
||||
#define __le2be __be2le
|
||||
|
||||
//#define __le2be_16 __builtin_bswap16
|
||||
|
||||
|
||||
/** You can use the built-in function \b __builtin_constant_p to determine if a value is known to be constant at compile time and hence that GCC can perform constant-folding on expressions involving that value. The argument of the function is the value to test. The function returns the integer 1 if the argument is known to be a compile-time constant and 0 if it is not known to be a compile-time constant. A return of 0 does not indicate that the value is not a constant, but merely that GCC cannot prove it is a constant with the specified value of the -O option.
|
||||
|
@ -85,6 +85,7 @@
|
||||
|
||||
// built-in function to convert 32-bit Big-Endian to Little-Endian
|
||||
#define __be2le __REV
|
||||
#define __le2be __be2le
|
||||
|
||||
#if 0
|
||||
|
||||
|
24
vendor/fatfs/diskio.c
vendored
24
vendor/fatfs/diskio.c
vendored
@ -36,19 +36,18 @@
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
#include "boards/board.h"
|
||||
#include "tusb.h"
|
||||
|
||||
#include "diskio.h"
|
||||
|
||||
#if TUSB_CFG_HOST_MSC
|
||||
//--------------------------------------------------------------------+
|
||||
// INCLUDE
|
||||
//--------------------------------------------------------------------+
|
||||
#include "diskio.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
static volatile DSTATUS disk_state = STA_NOINIT;
|
||||
volatile DSTATUS disk_state = STA_NOINIT;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INTERNAL OBJECT & FUNCTION DECLARATION
|
||||
@ -70,7 +69,7 @@ DSTATUS disk_status (BYTE pdrv)
|
||||
}
|
||||
|
||||
//pdrv
|
||||
// Specifies the physical drive number.
|
||||
// Specifies the physical drive number --> == dev_addr-1
|
||||
//buff
|
||||
// Pointer to the byte array to store the read data. The size of buffer must be in sector size * sector count.
|
||||
//sector
|
||||
@ -80,7 +79,20 @@ DSTATUS disk_status (BYTE pdrv)
|
||||
// must not be split into single sector transactions to the device, or you may not get good read performance.
|
||||
DRESULT disk_read (BYTE pdrv, BYTE*buff, DWORD sector, BYTE count)
|
||||
{
|
||||
uint8_t usb_addr = pdrv+1;
|
||||
tusbh_msc_read10(usb_addr, 0, buff, sector, count);
|
||||
|
||||
#if TUSB_CFG_OS == TUSB_OS_NONE
|
||||
while ( tusbh_msc_status(usb_addr) == TUSB_INTERFACE_STATUS_BUSY )
|
||||
{
|
||||
// timeout here
|
||||
}
|
||||
return tusbh_msc_status(usb_addr) == TUSB_INTERFACE_STATUS_READY ? RES_OK : RES_ERROR;
|
||||
#else
|
||||
#error semaphore instead of blocking
|
||||
#endif
|
||||
|
||||
return RES_ERROR;
|
||||
}
|
||||
|
||||
|
||||
@ -114,3 +126,5 @@ DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff)
|
||||
// .day_in_month = 21,
|
||||
// };
|
||||
//}
|
||||
|
||||
#endif
|
||||
|
2
vendor/fatfs/diskio.h
vendored
2
vendor/fatfs/diskio.h
vendored
@ -18,6 +18,8 @@ extern "C" {
|
||||
/* Status of Disk Functions */
|
||||
typedef BYTE DSTATUS;
|
||||
|
||||
extern volatile DSTATUS disk_state;
|
||||
|
||||
/* Results of Disk Functions */
|
||||
typedef enum {
|
||||
RES_OK = 0, /* 0: Successful */
|
||||
|
Loading…
x
Reference in New Issue
Block a user