refractor msc host app examples

This commit is contained in:
hathach 2013-10-01 16:11:34 +07:00
parent 640b0ec546
commit 18b3179bc6
5 changed files with 105 additions and 40 deletions

View File

@ -162,7 +162,7 @@
<Bp> <Bp>
<Number>0</Number> <Number>0</Number>
<Type>0</Type> <Type>0</Type>
<LineNumber>375</LineNumber> <LineNumber>297</LineNumber>
<EnabledFlag>1</EnabledFlag> <EnabledFlag>1</EnabledFlag>
<Address>0</Address> <Address>0</Address>
<ByteObject>0</ByteObject> <ByteObject>0</ByteObject>
@ -171,7 +171,23 @@
<SizeOfObject>0</SizeOfObject> <SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess> <BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount> <BreakIfRCount>0</BreakIfRCount>
<Filename>C:\Users\hathach\Dropbox\tinyusb\workspace\tinyusb\tinyusb\host\usbh.c</Filename> <Filename>C:\Users\hathach\Dropbox\tinyusb\workspace\tinyusb\demos\host\src\cli.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
<Bp>
<Number>1</Number>
<Type>0</Type>
<LineNumber>116</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount>
<Filename>C:\Users\hathach\Dropbox\tinyusb\workspace\tinyusb\demos\host\src\msc_app.c</Filename>
<ExecCommand></ExecCommand> <ExecCommand></ExecCommand>
<Expression></Expression> <Expression></Expression>
</Bp> </Bp>
@ -391,7 +407,7 @@
<Bp> <Bp>
<Number>0</Number> <Number>0</Number>
<Type>0</Type> <Type>0</Type>
<LineNumber>375</LineNumber> <LineNumber>297</LineNumber>
<EnabledFlag>1</EnabledFlag> <EnabledFlag>1</EnabledFlag>
<Address>0</Address> <Address>0</Address>
<ByteObject>0</ByteObject> <ByteObject>0</ByteObject>
@ -400,7 +416,23 @@
<SizeOfObject>0</SizeOfObject> <SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess> <BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount> <BreakIfRCount>0</BreakIfRCount>
<Filename>C:\Users\hathach\Dropbox\tinyusb\workspace\tinyusb\tinyusb\host\usbh.c</Filename> <Filename>C:\Users\hathach\Dropbox\tinyusb\workspace\tinyusb\demos\host\src\cli.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
<Bp>
<Number>1</Number>
<Type>0</Type>
<LineNumber>116</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount>
<Filename>C:\Users\hathach\Dropbox\tinyusb\workspace\tinyusb\demos\host\src\msc_app.c</Filename>
<ExecCommand></ExecCommand> <ExecCommand></ExecCommand>
<Expression></Expression> <Expression></Expression>
</Bp> </Bp>
@ -460,7 +492,7 @@
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>25</ColumnNumber> <ColumnNumber>25</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>152</TopLine> <TopLine>153</TopLine>
<CurrentLine>160</CurrentLine> <CurrentLine>160</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>..\src\main.c</PathWithFileName> <PathWithFileName>..\src\main.c</PathWithFileName>
@ -474,10 +506,10 @@
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>17</ColumnNumber> <ColumnNumber>0</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>126</TopLine> <TopLine>1</TopLine>
<CurrentLine>129</CurrentLine> <CurrentLine>1</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>..\src\cdc_serial_app.c</PathWithFileName> <PathWithFileName>..\src\cdc_serial_app.c</PathWithFileName>
<FilenameWithoutPath>cdc_serial_app.c</FilenameWithoutPath> <FilenameWithoutPath>cdc_serial_app.c</FilenameWithoutPath>
@ -492,8 +524,8 @@
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>0</ColumnNumber> <ColumnNumber>0</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>128</TopLine> <TopLine>1</TopLine>
<CurrentLine>135</CurrentLine> <CurrentLine>1</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>..\src\keyboard_app.c</PathWithFileName> <PathWithFileName>..\src\keyboard_app.c</PathWithFileName>
<FilenameWithoutPath>keyboard_app.c</FilenameWithoutPath> <FilenameWithoutPath>keyboard_app.c</FilenameWithoutPath>
@ -522,10 +554,10 @@
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>1</ColumnNumber> <ColumnNumber>0</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>66</TopLine> <TopLine>1</TopLine>
<CurrentLine>86</CurrentLine> <CurrentLine>1</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>..\src\rndis_app.c</PathWithFileName> <PathWithFileName>..\src\rndis_app.c</PathWithFileName>
<FilenameWithoutPath>rndis_app.c</FilenameWithoutPath> <FilenameWithoutPath>rndis_app.c</FilenameWithoutPath>
@ -554,10 +586,10 @@
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>33</ColumnNumber> <ColumnNumber>0</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>74</TopLine> <TopLine>1</TopLine>
<CurrentLine>77</CurrentLine> <CurrentLine>1</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>..\src\cli.c</PathWithFileName> <PathWithFileName>..\src\cli.c</PathWithFileName>
<FilenameWithoutPath>cli.c</FilenameWithoutPath> <FilenameWithoutPath>cli.c</FilenameWithoutPath>
@ -810,10 +842,10 @@
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>19</ColumnNumber> <ColumnNumber>21</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>1</TopLine> <TopLine>2</TopLine>
<CurrentLine>18</CurrentLine> <CurrentLine>8</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>..\..\..\tinyusb\host\usbh.c</PathWithFileName> <PathWithFileName>..\..\..\tinyusb\host\usbh.c</PathWithFileName>
<FilenameWithoutPath>usbh.c</FilenameWithoutPath> <FilenameWithoutPath>usbh.c</FilenameWithoutPath>
@ -988,8 +1020,8 @@
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>0</ColumnNumber> <ColumnNumber>0</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>241</TopLine> <TopLine>1</TopLine>
<CurrentLine>249</CurrentLine> <CurrentLine>1</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>..\..\..\tinyusb\class\msc_host.c</PathWithFileName> <PathWithFileName>..\..\..\tinyusb\class\msc_host.c</PathWithFileName>
<FilenameWithoutPath>msc_host.c</FilenameWithoutPath> <FilenameWithoutPath>msc_host.c</FilenameWithoutPath>
@ -1060,7 +1092,7 @@
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>3</ColumnNumber> <ColumnNumber>3</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>573</TopLine> <TopLine>574</TopLine>
<CurrentLine>580</CurrentLine> <CurrentLine>580</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>..\..\bsp\lpc43xx\CMSIS_LPC43xx_DriverLib\src\lpc43xx_cgu.c</PathWithFileName> <PathWithFileName>..\..\bsp\lpc43xx\CMSIS_LPC43xx_DriverLib\src\lpc43xx_cgu.c</PathWithFileName>
@ -1114,10 +1146,10 @@
<FileType>2</FileType> <FileType>2</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>0</ColumnNumber> <ColumnNumber>10</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>146</TopLine> <TopLine>145</TopLine>
<CurrentLine>151</CurrentLine> <CurrentLine>147</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>..\..\bsp\lpc43xx\startup_keil\startup_LPC43xx.s</PathWithFileName> <PathWithFileName>..\..\bsp\lpc43xx\startup_keil\startup_LPC43xx.s</PathWithFileName>
<FilenameWithoutPath>startup_LPC43xx.s</FilenameWithoutPath> <FilenameWithoutPath>startup_LPC43xx.s</FilenameWithoutPath>
@ -1138,10 +1170,10 @@
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>52</ColumnNumber> <ColumnNumber>23</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>107</TopLine> <TopLine>107</TopLine>
<CurrentLine>108</CurrentLine> <CurrentLine>113</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>..\..\..\vendor\fatfs\diskio.c</PathWithFileName> <PathWithFileName>..\..\..\vendor\fatfs\diskio.c</PathWithFileName>
<FilenameWithoutPath>diskio.c</FilenameWithoutPath> <FilenameWithoutPath>diskio.c</FilenameWithoutPath>
@ -1154,10 +1186,10 @@
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>0</ColumnNumber> <ColumnNumber>66</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>0</TopLine> <TopLine>2021</TopLine>
<CurrentLine>0</CurrentLine> <CurrentLine>2037</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>..\..\..\vendor\fatfs\ff.c</PathWithFileName> <PathWithFileName>..\..\..\vendor\fatfs\ff.c</PathWithFileName>
<FilenameWithoutPath>ff.c</FilenameWithoutPath> <FilenameWithoutPath>ff.c</FilenameWithoutPath>

View File

@ -142,6 +142,25 @@ static char cli_buffer[CLI_MAX_BUFFER];
uint8_t fileread_buffer[CLI_FILE_READ_BUFFER] TUSB_CFG_ATTR_USBRAM; uint8_t fileread_buffer[CLI_FILE_READ_BUFFER] TUSB_CFG_ATTR_USBRAM;
static char volume_label[20]; static char volume_label[20];
static inline void drive_number2letter(char * p_path) ATTR_ALWAYS_INLINE;
static inline void drive_number2letter(char * p_path)
{
if (p_path[1] == ':')
{
p_path[0] = 'E' + p_path[0] - '0' ;
}
}
static inline void drive_letter2number(char * p_path) ATTR_ALWAYS_INLINE;
static inline void drive_letter2number(char * p_path)
{
if (p_path[1] == ':')
{
p_path[0] = p_path[0] - 'E' + '0';
}
}
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// IMPLEMENTATION // IMPLEMENTATION
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
@ -149,10 +168,10 @@ static char volume_label[20];
void cli_command_prompt(void) void cli_command_prompt(void)
{ {
f_getcwd(cli_buffer, CLI_MAX_BUFFER); f_getcwd(cli_buffer, CLI_MAX_BUFFER);
printf("\n%s %c%s\n$ ", drive_number2letter(cli_buffer);
printf("\n%s %s\n$ ",
(volume_label[0] !=0) ? volume_label : "No Label", (volume_label[0] !=0) ? volume_label : "No Label",
'E'+cli_buffer[0]-'0', cli_buffer);
cli_buffer+1);
memclr_(cli_buffer, CLI_MAX_BUFFER); memclr_(cli_buffer, CLI_MAX_BUFFER);
} }
@ -294,9 +313,17 @@ cli_error_t cli_cmd_changedir(char * p_para)
{ {
if ( strlen(p_para) == 0 ) return CLI_ERROR_INVALID_PARA; if ( strlen(p_para) == 0 ) return CLI_ERROR_INVALID_PARA;
if ( FR_OK != f_chdir(p_para) ) if ( (p_para[1] == ':') && (strlen(p_para) == 2) )
{ // change drive
p_para[0] -= 'E';
if ( ! ( disk_is_ready(p_para[0]) && FR_OK == f_chdrive(p_para[0]) )) return CLI_ERROR_INVALID_PARA;
f_getlabel(NULL, volume_label, NULL);
}else
{ {
return CLI_ERROR_INVALID_PATH; if ( FR_OK != f_chdir(p_para) )
{
return CLI_ERROR_INVALID_PATH;
}
} }
return CLI_ERROR_NONE; return CLI_ERROR_NONE;

View File

@ -84,13 +84,14 @@ void tusbh_msc_mounted_cb(uint8_t dev_addr)
printf("LBA 0-0x%X Block Size: %d\n", last_lba, block_size); printf("LBA 0-0x%X Block Size: %d\n", last_lba, block_size);
//------------- file system (only 1 LUN support) -------------// //------------- file system (only 1 LUN support) -------------//
// TODO MSC refractor this hack
// DSTATUS stat = disk_initialize(0); // DSTATUS stat = disk_initialize(0);
uint8_t phy_disk = dev_addr-1; uint8_t phy_disk = dev_addr-1;
disk_state[phy_disk] = 0; disk_state[phy_disk] = 0;
if ( disk_is_ready(phy_disk) ) if ( disk_is_ready(phy_disk) )
{ {
if ( f_mount(phy_disk, &fatfs[phy_disk]) != FR_OK ) // TODO multiple volume if ( f_mount(phy_disk, &fatfs[phy_disk]) != FR_OK )
{ {
puts("mount failed"); puts("mount failed");
return; return;
@ -112,9 +113,12 @@ void tusbh_msc_mounted_cb(uint8_t dev_addr)
void tusbh_msc_unmounted_cb(uint8_t dev_addr) void tusbh_msc_unmounted_cb(uint8_t dev_addr)
{ {
// unmount disk
disk_state[dev_addr-1] = STA_NOINIT;
puts("\na MassStorage device is unmounted"); puts("\na MassStorage device is unmounted");
uint8_t phy_disk = dev_addr-1;
f_mount(phy_disk, NULL); // unmount disk
disk_state[phy_disk] = STA_NOINIT;
} }
void tusbh_msc_isr(uint8_t dev_addr, tusb_event_t event, uint32_t xferred_bytes) void tusbh_msc_isr(uint8_t dev_addr, tusb_event_t event, uint32_t xferred_bytes)

View File

@ -84,7 +84,8 @@ DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
static inline bool disk_is_ready(BYTE pdrv); static inline bool disk_is_ready(BYTE pdrv);
static inline bool disk_is_ready(BYTE pdrv) static inline bool disk_is_ready(BYTE pdrv)
{ {
return (disk_status(pdrv) & (STA_NOINIT | STA_NODISK)) == 0; return (pdrv < TUSB_CFG_HOST_DEVICE_MAX) &&
( (disk_status(pdrv) & (STA_NOINIT | STA_NODISK)) == 0 );
} }

View File

@ -9,6 +9,7 @@
#ifndef _FFCONF #ifndef _FFCONF
#define _FFCONF 82786 /* Revision ID */ #define _FFCONF 82786 /* Revision ID */
#include "tusb_config.h"
/*---------------------------------------------------------------------------/ /*---------------------------------------------------------------------------/
/ Functions and Buffer Configurations / Functions and Buffer Configurations
@ -127,7 +128,7 @@
/ Physical Drive Configurations / Physical Drive Configurations
/----------------------------------------------------------------------------*/ /----------------------------------------------------------------------------*/
#define _VOLUMES 1 #define _VOLUMES TUSB_CFG_HOST_DEVICE_MAX
/* Number of volumes (logical drives) to be used. */ /* Number of volumes (logical drives) to be used. */