diff options
| author | hathach <[email protected]> | 2013-10-01 16:11:34 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2013-10-01 16:11:34 +0700 |
| commit | 18b3179bc65a4080b71d3928baf5d64b43f2a53e (patch) | |
| tree | 0b9fd3cd6bc8ab1ebe1dc42f98f144d73ee3ab08 | |
| parent | 640b0ec5467eadf153c4a09d53e0a38bae752685 (diff) | |
refractor msc host app examples
| -rw-r--r-- | demos/host/host_os_none/host_os_none.uvopt | 92 | ||||
| -rw-r--r-- | demos/host/src/cli.c | 37 | ||||
| -rw-r--r-- | demos/host/src/msc_app.c | 10 | ||||
| -rw-r--r-- | vendor/fatfs/diskio.h | 3 | ||||
| -rw-r--r-- | vendor/fatfs/ffconf.h | 3 |
5 files changed, 105 insertions, 40 deletions
diff --git a/demos/host/host_os_none/host_os_none.uvopt b/demos/host/host_os_none/host_os_none.uvopt index 83c427785..89f85a6cf 100644 --- a/demos/host/host_os_none/host_os_none.uvopt +++ b/demos/host/host_os_none/host_os_none.uvopt @@ -162,7 +162,7 @@ <Bp> <Number>0</Number> <Type>0</Type> - <LineNumber>375</LineNumber> + <LineNumber>297</LineNumber> <EnabledFlag>1</EnabledFlag> <Address>0</Address> <ByteObject>0</ByteObject> @@ -171,7 +171,23 @@ <SizeOfObject>0</SizeOfObject> <BreakByAccess>0</BreakByAccess> <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> <Expression></Expression> </Bp> @@ -391,7 +407,23 @@ <Bp> <Number>0</Number> <Type>0</Type> - <LineNumber>375</LineNumber> + <LineNumber>297</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\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> @@ -400,7 +432,7 @@ <SizeOfObject>0</SizeOfObject> <BreakByAccess>0</BreakByAccess> <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\msc_app.c</Filename> <ExecCommand></ExecCommand> <Expression></Expression> </Bp> @@ -460,7 +492,7 @@ <Focus>0</Focus> <ColumnNumber>25</ColumnNumber> <tvExpOptDlg>0</tvExpOptDlg> - <TopLine>152</TopLine> + <TopLine>153</TopLine> <CurrentLine>160</CurrentLine> <bDave2>0</bDave2> <PathWithFileName>..\src\main.c</PathWithFileName> @@ -474,10 +506,10 @@ <FileType>1</FileType> <tvExp>0</tvExp> <Focus>0</Focus> - <ColumnNumber>17</ColumnNumber> + <ColumnNumber>0</ColumnNumber> <tvExpOptDlg>0</tvExpOptDlg> - <TopLine>126</TopLine> - <CurrentLine>129</CurrentLine> + <TopLine>1</TopLine> + <CurrentLine>1</CurrentLine> <bDave2>0</bDave2> <PathWithFileName>..\src\cdc_serial_app.c</PathWithFileName> <FilenameWithoutPath>cdc_serial_app.c</FilenameWithoutPath> @@ -492,8 +524,8 @@ <Focus>0</Focus> <ColumnNumber>0</ColumnNumber> <tvExpOptDlg>0</tvExpOptDlg> - <TopLine>128</TopLine> - <CurrentLine>135</CurrentLine> + <TopLine>1</TopLine> + <CurrentLine>1</CurrentLine> <bDave2>0</bDave2> <PathWithFileName>..\src\keyboard_app.c</PathWithFileName> <FilenameWithoutPath>keyboard_app.c</FilenameWithoutPath> @@ -522,10 +554,10 @@ <FileType>1</FileType> <tvExp>0</tvExp> <Focus>0</Focus> - <ColumnNumber>1</ColumnNumber> + <ColumnNumber>0</ColumnNumber> <tvExpOptDlg>0</tvExpOptDlg> - <TopLine>66</TopLine> - <CurrentLine>86</CurrentLine> + <TopLine>1</TopLine> + <CurrentLine>1</CurrentLine> <bDave2>0</bDave2> <PathWithFileName>..\src\rndis_app.c</PathWithFileName> <FilenameWithoutPath>rndis_app.c</FilenameWithoutPath> @@ -554,10 +586,10 @@ <FileType>1</FileType> <tvExp>0</tvExp> <Focus>0</Focus> - <ColumnNumber>33</ColumnNumber> + <ColumnNumber>0</ColumnNumber> <tvExpOptDlg>0</tvExpOptDlg> - <TopLine>74</TopLine> - <CurrentLine>77</CurrentLine> + <TopLine>1</TopLine> + <CurrentLine>1</CurrentLine> <bDave2>0</bDave2> <PathWithFileName>..\src\cli.c</PathWithFileName> <FilenameWithoutPath>cli.c</FilenameWithoutPath> @@ -810,10 +842,10 @@ <FileType>1</FileType> <tvExp>0</tvExp> <Focus>0</Focus> - <ColumnNumber>19</ColumnNumber> + <ColumnNumber>21</ColumnNumber> <tvExpOptDlg>0</tvExpOptDlg> - <TopLine>1</TopLine> - <CurrentLine>18</CurrentLine> + <TopLine>2</TopLine> + <CurrentLine>8</CurrentLine> <bDave2>0</bDave2> <PathWithFileName>..\..\..\tinyusb\host\usbh.c</PathWithFileName> <FilenameWithoutPath>usbh.c</FilenameWithoutPath> @@ -988,8 +1020,8 @@ <Focus>0</Focus> <ColumnNumber>0</ColumnNumber> <tvExpOptDlg>0</tvExpOptDlg> - <TopLine>241</TopLine> - <CurrentLine>249</CurrentLine> + <TopLine>1</TopLine> + <CurrentLine>1</CurrentLine> <bDave2>0</bDave2> <PathWithFileName>..\..\..\tinyusb\class\msc_host.c</PathWithFileName> <FilenameWithoutPath>msc_host.c</FilenameWithoutPath> @@ -1060,7 +1092,7 @@ <Focus>0</Focus> <ColumnNumber>3</ColumnNumber> <tvExpOptDlg>0</tvExpOptDlg> - <TopLine>573</TopLine> + <TopLine>574</TopLine> <CurrentLine>580</CurrentLine> <bDave2>0</bDave2> <PathWithFileName>..\..\bsp\lpc43xx\CMSIS_LPC43xx_DriverLib\src\lpc43xx_cgu.c</PathWithFileName> @@ -1114,10 +1146,10 @@ <FileType>2</FileType> <tvExp>0</tvExp> <Focus>0</Focus> - <ColumnNumber>0</ColumnNumber> + <ColumnNumber>10</ColumnNumber> <tvExpOptDlg>0</tvExpOptDlg> - <TopLine>146</TopLine> - <CurrentLine>151</CurrentLine> + <TopLine>145</TopLine> + <CurrentLine>147</CurrentLine> <bDave2>0</bDave2> <PathWithFileName>..\..\bsp\lpc43xx\startup_keil\startup_LPC43xx.s</PathWithFileName> <FilenameWithoutPath>startup_LPC43xx.s</FilenameWithoutPath> @@ -1138,10 +1170,10 @@ <FileType>1</FileType> <tvExp>0</tvExp> <Focus>0</Focus> - <ColumnNumber>52</ColumnNumber> + <ColumnNumber>23</ColumnNumber> <tvExpOptDlg>0</tvExpOptDlg> <TopLine>107</TopLine> - <CurrentLine>108</CurrentLine> + <CurrentLine>113</CurrentLine> <bDave2>0</bDave2> <PathWithFileName>..\..\..\vendor\fatfs\diskio.c</PathWithFileName> <FilenameWithoutPath>diskio.c</FilenameWithoutPath> @@ -1154,10 +1186,10 @@ <FileType>1</FileType> <tvExp>0</tvExp> <Focus>0</Focus> - <ColumnNumber>0</ColumnNumber> + <ColumnNumber>66</ColumnNumber> <tvExpOptDlg>0</tvExpOptDlg> - <TopLine>0</TopLine> - <CurrentLine>0</CurrentLine> + <TopLine>2021</TopLine> + <CurrentLine>2037</CurrentLine> <bDave2>0</bDave2> <PathWithFileName>..\..\..\vendor\fatfs\ff.c</PathWithFileName> <FilenameWithoutPath>ff.c</FilenameWithoutPath> diff --git a/demos/host/src/cli.c b/demos/host/src/cli.c index 80fe9f7ef..31ecbbdf0 100644 --- a/demos/host/src/cli.c +++ b/demos/host/src/cli.c @@ -142,6 +142,25 @@ static char cli_buffer[CLI_MAX_BUFFER]; uint8_t fileread_buffer[CLI_FILE_READ_BUFFER] TUSB_CFG_ATTR_USBRAM; 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 //--------------------------------------------------------------------+ @@ -149,10 +168,10 @@ static char volume_label[20]; void cli_command_prompt(void) { 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", - 'E'+cli_buffer[0]-'0', - cli_buffer+1); + cli_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 ( 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; diff --git a/demos/host/src/msc_app.c b/demos/host/src/msc_app.c index 99b41814d..8c1ff0dbe 100644 --- a/demos/host/src/msc_app.c +++ b/demos/host/src/msc_app.c @@ -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); //------------- file system (only 1 LUN support) -------------// + // TODO MSC refractor this hack // DSTATUS stat = disk_initialize(0); uint8_t phy_disk = dev_addr-1; disk_state[phy_disk] = 0; 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"); return; @@ -112,9 +113,12 @@ void tusbh_msc_mounted_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"); + + 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) diff --git a/vendor/fatfs/diskio.h b/vendor/fatfs/diskio.h index bd3688580..b6aa881fb 100644 --- a/vendor/fatfs/diskio.h +++ b/vendor/fatfs/diskio.h @@ -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) { - return (disk_status(pdrv) & (STA_NOINIT | STA_NODISK)) == 0; + return (pdrv < TUSB_CFG_HOST_DEVICE_MAX) && + ( (disk_status(pdrv) & (STA_NOINIT | STA_NODISK)) == 0 ); } diff --git a/vendor/fatfs/ffconf.h b/vendor/fatfs/ffconf.h index 2ba90f251..75c5c15af 100644 --- a/vendor/fatfs/ffconf.h +++ b/vendor/fatfs/ffconf.h @@ -9,6 +9,7 @@ #ifndef _FFCONF #define _FFCONF 82786 /* Revision ID */ +#include "tusb_config.h" /*---------------------------------------------------------------------------/ / Functions and Buffer Configurations @@ -127,7 +128,7 @@ / Physical Drive Configurations /----------------------------------------------------------------------------*/ -#define _VOLUMES 1 +#define _VOLUMES TUSB_CFG_HOST_DEVICE_MAX /* Number of volumes (logical drives) to be used. */ |
