diff --git a/demos/host/host_os_none/host_os_none.uvopt b/demos/host/host_os_none/host_os_none.uvopt
index a00f5f25b..905eb692a 100644
--- a/demos/host/host_os_none/host_os_none.uvopt
+++ b/demos/host/host_os_none/host_os_none.uvopt
@@ -135,7 +135,7 @@
0
DLGUARM
-
+ (106=-1,-1,-1,-1,0)(107=-1,-1,-1,-1,0)
0
@@ -158,7 +158,24 @@
-O975 -S0 -C0 -FO7 -FD10000000 -FC800 -FN2 -FF0LPC18xx43xx_512_BA -FS01A000000 -FL080000 -FF1LPC18xx43xx_512_BB -FS11B000000 -FL180000)
-
+
+
+ 0
+ 0
+ 269
+ 1
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ C:\Users\hathach\Dropbox\tinyusb\workspace\tinyusb\demos\host\src\cli.c
+
+
+
+
0
@@ -188,28 +205,8 @@
5
1
- ehci_data.device[0].qhd[0]
-
-
- 6
- 1
- ehci_data.device[0].qhd[1]
-
-
- 7
- 1
msch_semaphore
-
- 8
- 1
- ehci_data.device[0].qhd[0].p_qtd_list_head
-
-
- 9
- 1
- ehci_data.device[0].qhd[1].p_qtd_list_head
-
@@ -390,7 +387,24 @@
-O975 -S0 -C0 -FO7 -FD10000000 -FC800 -FN2 -FF0LPC18xx43xx_512_BA -FS01A000000 -FL080000 -FF1LPC18xx43xx_512_BB -FS11B000000 -FL180000)
-
+
+
+ 0
+ 0
+ 269
+ 1
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ C:\Users\hathach\Dropbox\tinyusb\workspace\tinyusb\demos\host\src\cli.c
+
+
+
+
0
@@ -446,7 +460,7 @@
0
1
0
- 194
+ 195
200
0
..\src\main.c
@@ -462,7 +476,7 @@
0
0
0
- 121
+ 94
145
0
..\src\cdc_serial_app.c
@@ -478,7 +492,7 @@
0
0
0
- 163
+ 136
180
0
..\src\keyboard_app.c
@@ -494,7 +508,7 @@
0
44
0
- 122
+ 120
127
0
..\src\mouse_app.c
@@ -524,10 +538,10 @@
1
0
0
- 3
+ 1
0
- 125
- 135
+ 111
+ 125
0
..\src\msc_app.c
msc_app.c
@@ -540,10 +554,10 @@
1
0
0
- 30
+ 24
0
- 69
- 75
+ 1
+ 11
0
..\src\cli.c
cli.c
@@ -582,7 +596,7 @@
0
0
0
- 138
+ 139
142
0
..\..\bsp\boards\embedded_artists\board_ea4357.c
@@ -598,7 +612,7 @@
0
6
0
- 122
+ 95
135
0
..\..\bsp\boards\printf_retarget.c
@@ -734,7 +748,7 @@
0
0
0
- 52
+ 25
76
0
..\..\..\tinyusb\tusb.c
@@ -798,7 +812,7 @@
0
0
0
- 495
+ 483
501
0
..\..\..\tinyusb\host\usbh.c
@@ -814,7 +828,7 @@
0
0
0
- 601
+ 602
605
0
..\..\..\tinyusb\host\ehci\ehci.c
@@ -998,7 +1012,7 @@
0
0
0
- 547
+ 548
553
0
..\..\bsp\lpc43xx\CMSIS_LPC43xx_DriverLib\src\lpc43xx_uart.c
@@ -1100,10 +1114,10 @@
2
0
0
- 26
+ 0
0
- 144
- 152
+ 140
+ 158
0
..\..\bsp\lpc43xx\startup_keil\startup_LPC43xx.s
startup_LPC43xx.s
@@ -1126,7 +1140,7 @@
0
46
0
- 16
+ 17
30
0
..\..\..\vendor\fatfs\diskio.c
@@ -1150,6 +1164,22 @@
0
0
+
+ 6
+ 43
+ 1
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ ..\..\..\vendor\fatfs\ccsbcs.c
+ ccsbcs.c
+ 0
+ 0
+
diff --git a/demos/host/host_os_none/host_os_none.uvproj b/demos/host/host_os_none/host_os_none.uvproj
index a88a9e2af..a3f164cf6 100644
--- a/demos/host/host_os_none/host_os_none.uvproj
+++ b/demos/host/host_os_none/host_os_none.uvproj
@@ -626,6 +626,11 @@
1
..\..\..\vendor\fatfs\ff.c
+
+ ccsbcs.c
+ 1
+ ..\..\..\vendor\fatfs\ccsbcs.c
+
@@ -1290,6 +1295,11 @@
1
..\..\..\vendor\fatfs\ff.c
+
+ ccsbcs.c
+ 1
+ ..\..\..\vendor\fatfs\ccsbcs.c
+
diff --git a/demos/host/src/cli.c b/demos/host/src/cli.c
index 8b128f001..3236ae5a0 100644
--- a/demos/host/src/cli.c
+++ b/demos/host/src/cli.c
@@ -43,19 +43,40 @@
#include "diskio.h"
#include "boards/ansi_escape.h"
+//--------------------------------------------------------------------+
+// MACRO CONSTANT TYPEDEF
+//--------------------------------------------------------------------+
+#define CLI_MAX_BUFFER 256
+#define CLI_FILE_READ_BUFFER (4*1024)
+
+enum {
+ ASCII_BACKSPACE = 8,
+};
+
+typedef enum {
+ CLI_ERROR_NONE = 0,
+ CLI_ERROR_INVALID_PARA,
+ CLI_ERROR_INVALID_PATH,
+ CLI_ERROR_FAILED
+}cli_error_t;
+
+//--------------------------------------------------------------------+
+// CLI Database definition
+//--------------------------------------------------------------------+
+
// command, function, description
#define CLI_COMMAND_TABLE(ENTRY) \
- ENTRY(unknow, cli_cmd_unknow , NULL) \
- ENTRY(help , cli_cmd_help , NULL) \
- ENTRY(ls , cli_cmd_list , "list items in current directory") \
- ENTRY(cd , cli_cmd_changedir, "change current directory") \
- ENTRY(cat , cli_cmd_cat , "display contents of a text file") \
+ ENTRY(unknown , cli_cmd_unknown , NULL) \
+ ENTRY(help , cli_cmd_help , NULL) \
+ ENTRY(ls , cli_cmd_list , "list items in current directory") \
+ ENTRY(cd , cli_cmd_changedir, "change current directory") \
+ ENTRY(cat , cli_cmd_cat , "display contents of a text file") \
//--------------------------------------------------------------------+
// Expands the function to have the standard function signature
//--------------------------------------------------------------------+
#define CLI_PROTOTYPE_EXPAND(command, function, description) \
- tusb_error_t function(char const *);\
+ cli_error_t function(char const *);
CLI_COMMAND_TABLE(CLI_PROTOTYPE_EXPAND);
@@ -95,21 +116,25 @@ char const* const cli_description_tbl[] =
#define CMD_LOOKUP_EXPAND(command, function, description)\
[CLI_CMDTYPE_##command] = function,\
-typedef tusb_error_t (* const cli_cmdfunc_t)(char const *);
+typedef cli_error_t (* const cli_cmdfunc_t)(char const *);
static cli_cmdfunc_t cli_command_tbl[] =
{
CLI_COMMAND_TABLE(CMD_LOOKUP_EXPAND)
};
+
+
+static char const * const cli_error_message[] =
+{
+ [CLI_ERROR_NONE ] = 0,
+ [CLI_ERROR_INVALID_PARA ] = "Invalid parameter(s)",
+ [CLI_ERROR_INVALID_PATH ] = "No such file or directory",
+ [CLI_ERROR_FAILED ] = "failed to execute"
+};
+
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
-#define CLI_MAX_BUFFER 256
-#define CLI_FILE_READ_BUFFER (4*1024)
-
-enum {
- ASCII_BACKSPACE = 8,
-};
static char cli_buffer[CLI_MAX_BUFFER];
@@ -146,13 +171,15 @@ void cli_poll(char ch)
}
else if ( ch == '\r')
{ // execute command
+ //------------- Separate Command & Parameter -------------//
putchar('\n');
char* p_space = strchr(cli_buffer, ' ');
uint32_t command_len = (p_space == NULL) ? strlen(cli_buffer) : (p_space - cli_buffer);
- char* p_para = (p_space == NULL) ? NULL : (p_space+1);
+ char* p_para = (p_space == NULL) ? (cli_buffer+command_len) : (p_space+1); // point to NULL-character or after space
+ //------------- Find entered command in lookup table & execute it -------------//
cli_cmdtype_t cmd_id;
- for(cmd_id = CLI_CMDTYPE_COUNT - 1; cmd_id > 0; cmd_id--)
+ for(cmd_id = CLI_CMDTYPE_COUNT - 1; cmd_id > CLI_CMDTYPE_unknown; cmd_id--)
{
if( 0 == strncmp(cli_buffer, cli_string_tbl[cmd_id], command_len) )
{
@@ -160,8 +187,11 @@ void cli_poll(char ch)
}
}
- cli_command_tbl[cmd_id]( p_para );
+ cli_error_t error = cli_command_tbl[cmd_id]( p_para ); // command execution, (unknown command if cannot find)
+ if (CLI_ERROR_NONE != error) puts(cli_error_message[error]); // error message output if any
+
+ //------------- print out current path -------------//
f_getcwd(cli_buffer, CLI_MAX_BUFFER);
printf("\nMSC %c%s\n$ ",
'E'+cli_buffer[0]-'0',
@@ -177,16 +207,16 @@ void cli_poll(char ch)
//--------------------------------------------------------------------+
// UNKNOWN Command
//--------------------------------------------------------------------+
-tusb_error_t cli_cmd_unknow(char const * para)
+cli_error_t cli_cmd_unknown(char const * para)
{
- puts("unknown command, please type \"help\"");
- return TUSB_ERROR_NONE;
+ puts("unknown command, please type \"help\" for list of supported commands");
+ return CLI_ERROR_NONE;
}
//--------------------------------------------------------------------+
// HELP command
//--------------------------------------------------------------------+
-tusb_error_t cli_cmd_help(char const * para)
+cli_error_t cli_cmd_help(char const * para)
{
puts("current supported commands are:");
for(cli_cmdtype_t cmd_id = CLI_CMDTYPE_help+1; cmd_id < CLI_CMDTYPE_COUNT; cmd_id++)
@@ -194,19 +224,18 @@ tusb_error_t cli_cmd_help(char const * para)
printf("%s\t%s\n", cli_string_tbl[cmd_id], cli_description_tbl[cmd_id]);
}
- return TUSB_ERROR_NONE;
+ return CLI_ERROR_NONE;
}
//--------------------------------------------------------------------+
// LS Command
//--------------------------------------------------------------------+
-tusb_error_t cli_cmd_list(const char * p_para)
+cli_error_t cli_cmd_list(const char * p_para)
{
- DIR target_dir;
-
- if ( (p_para == NULL) || (strlen(p_para) == 0) ) // list current directory
+ if ( strlen(p_para) == 0 ) // list current directory
{
- ASSERT_INT( FR_OK, f_opendir(&target_dir, "."), TUSB_ERROR_FAILED) ;
+ DIR target_dir;
+ if ( FR_OK != f_opendir(&target_dir, ".") ) return CLI_ERROR_FAILED;
TCHAR long_filename[_MAX_LFN];
FILINFO dir_entry =
@@ -218,42 +247,48 @@ tusb_error_t cli_cmd_list(const char * p_para)
{
if ( dir_entry.fname[0] != '.' ) // ignore . and .. entry
{
- printf("%s%c\n",
- (dir_entry.lfname[0] != 0) ? dir_entry.lfname : dir_entry.fname,
- dir_entry.fattrib & AM_DIR ? '/' : ' ');
+ TCHAR const * const p_name = (dir_entry.lfname[0] != 0) ? dir_entry.lfname : dir_entry.fname;
+ if ( dir_entry.fattrib & AM_DIR ) // directory
+ {
+ printf("/%s", p_name);
+ }else
+ {
+ printf("%-50s%d KB", p_name, dir_entry.fsize / 1000);
+ }
+ putchar('\n');
}
}
}
else
{
puts("ls only supports list current directory only, try to cd to that folder first");
+ return CLI_ERROR_INVALID_PARA;
}
- return TUSB_ERROR_NONE;
+ return CLI_ERROR_NONE;
}
//--------------------------------------------------------------------+
// CD Command
//--------------------------------------------------------------------+
-tusb_error_t cli_cmd_changedir(const char * p_para)
+cli_error_t cli_cmd_changedir(const char * p_para)
{
- if ( (p_para == NULL) || (strlen(p_para) == 0) ) return TUSB_ERROR_INVALID_PARA;
+ if ( strlen(p_para) == 0 ) return CLI_ERROR_INVALID_PARA;
if ( FR_OK != f_chdir(p_para) )
{
- printf("%s : No such file or directory\n", p_para);
- return TUSB_ERROR_INVALID_PARA;
+ return CLI_ERROR_INVALID_PATH;
}
- return TUSB_ERROR_NONE;
+ return CLI_ERROR_NONE;
}
//--------------------------------------------------------------------+
// CAT Command
//--------------------------------------------------------------------+
-tusb_error_t cli_cmd_cat(const char *p_para)
+cli_error_t cli_cmd_cat(const char *p_para)
{
- if ( (p_para == NULL) || (strlen(p_para) == 0) ) return TUSB_ERROR_INVALID_PARA;
+ if ( strlen(p_para) == 0 ) return CLI_ERROR_INVALID_PARA;
FIL file;
@@ -262,18 +297,18 @@ tusb_error_t cli_cmd_cat(const char *p_para)
case FR_OK:
{
uint32_t bytes_read = 0;
+
if ( (FR_OK == f_read(&file, fileread_buffer, CLI_FILE_READ_BUFFER, &bytes_read)) && (bytes_read > 0) )
{
- if ( isprint( fileread_buffer[0] ) )
+ if ( file.fsize < 0x80000 ) // ~ 500KB
{
putchar('\n');
- for(uint32_t i=0; i 0) );
}else
- {
- printf("%s 's contents is not printable\n", p_para);
+ { // not display file contents if first character is not printable (high chance of binary file)
+ printf("%s 's contents is too large\n", p_para);
}
}
f_close(&file);
@@ -281,17 +316,13 @@ tusb_error_t cli_cmd_cat(const char *p_para)
break;
case FR_INVALID_NAME:
- printf("%s : No such file or directory\n", p_para);
- return TUSB_ERROR_INVALID_PARA;
- break;
+ return CLI_ERROR_INVALID_PATH;
default :
- printf("failed to open %s\n", p_para);
- return TUSB_ERROR_FAILED;
- break;
+ return CLI_ERROR_FAILED;
}
- return TUSB_ERROR_NONE;
+ return CLI_ERROR_NONE;
}
#endif