00001
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #if (defined __GNUC__)
00049 #include "nlao_usart.h"
00050 #endif
00051 #include <stdio.h>
00052 #include <string.h>
00053 #include "compiler.h"
00054 #include "board.h"
00055 #include "gpio.h"
00056 #include "usart.h"
00057 #ifdef FREERTOS_USED
00058 #include "FreeRTOS.h"
00059 #include "task.h"
00060 #endif
00061 #include "ctrl_access.h"
00062 #include "fat.h"
00063 #include "file.h"
00064 #include "navigation.h"
00065 #include "conf_usb.h"
00066 #include "usb_drv.h"
00067 #include "cycle_counter.h"
00068 #if USB_HOST_FEATURE == ENABLED
00069 #include "usb_host_enum.h"
00070 #include "usb_host_task.h"
00071 #include "host_mass_storage_task.h"
00072 #endif
00073 #include "ushell_task.h"
00074
00075
00076
00077
00080
00081 #if BOARD == EVK1100
00082 # define SHL_USART (&AVR32_USART0)
00083 # define SHL_USART_RX_PIN AVR32_USART0_RXD_0_0_PIN
00084 # define SHL_USART_RX_FUNCTION AVR32_USART0_RXD_0_0_FUNCTION
00085 # define SHL_USART_TX_PIN AVR32_USART0_TXD_0_0_PIN
00086 # define SHL_USART_TX_FUNCTION AVR32_USART0_TXD_0_0_FUNCTION
00087 # define SHL_USART_BAUDRATE 57600
00088 #elif BOARD == EVK1101
00089 # define SHL_USART (&AVR32_USART1)
00090 # define SHL_USART_RX_PIN AVR32_USART1_RXD_0_0_PIN
00091 # define SHL_USART_RX_FUNCTION AVR32_USART1_RXD_0_0_FUNCTION
00092 # define SHL_USART_TX_PIN AVR32_USART1_TXD_0_0_PIN
00093 # define SHL_USART_TX_FUNCTION AVR32_USART1_TXD_0_0_FUNCTION
00094 # define SHL_USART_BAUDRATE 57600
00095 #elif BOARD == EVK1103
00096 # define SHL_USART (&AVR32_USART2)
00097 # define SHL_USART_RX_PIN AVR32_USART2_RXD_0_1_PIN
00098 # define SHL_USART_RX_FUNCTION AVR32_USART2_RXD_0_1_FUNCTION
00099 # define SHL_USART_TX_PIN AVR32_USART2_TXD_0_1_PIN
00100 # define SHL_USART_TX_FUNCTION AVR32_USART2_TXD_0_1_FUNCTION
00101 # define SHL_USART_BAUDRATE 57600
00102 #elif BOARD == EVK1104
00103 # define SHL_USART (&AVR32_USART1)
00104 # define SHL_USART_RX_PIN AVR32_USART1_RXD_0_0_PIN
00105 # define SHL_USART_RX_FUNCTION AVR32_USART1_RXD_0_0_FUNCTION
00106 # define SHL_USART_TX_PIN AVR32_USART1_TXD_0_0_PIN
00107 # define SHL_USART_TX_FUNCTION AVR32_USART1_TXD_0_0_FUNCTION
00108 # define SHL_USART_BAUDRATE 57600
00109 #elif BOARD == EVK1105
00110 # define SHL_USART (&AVR32_USART0)
00111 # define SHL_USART_RX_PIN AVR32_USART0_RXD_0_0_PIN
00112 # define SHL_USART_RX_FUNCTION AVR32_USART0_RXD_0_0_FUNCTION
00113 # define SHL_USART_TX_PIN AVR32_USART0_TXD_0_0_PIN
00114 # define SHL_USART_TX_FUNCTION AVR32_USART0_TXD_0_0_FUNCTION
00115 # define SHL_USART_BAUDRATE 57600
00116 #elif BOARD == UC3C_EK
00117 # define SHL_USART (&AVR32_USART2)
00118 # define SHL_USART_RX_PIN AVR32_USART2_RXD_0_1_PIN
00119 # define SHL_USART_RX_FUNCTION AVR32_USART2_RXD_0_1_FUNCTION
00120 # define SHL_USART_TX_PIN AVR32_USART2_TXD_0_1_PIN
00121 # define SHL_USART_TX_FUNCTION AVR32_USART2_TXD_0_1_FUNCTION
00122 # define SHL_USART_BAUDRATE 57600
00123 #else
00124 # error Unsupported board
00125 #endif
00127
00128 #define USHELL_HISTORY 10 // Must be 1 or more
00129 #define USHELL_NB_LINE 20
00130 #define USHELL_NB_COL 80
00131
00132 #define USHELL_SIZE_CMD_LINE 70
00133 #define USHELL_MAX_NB_ARG 2
00134
00135
00136
00137
00138
00139 static Bool g_b_ushell_task_run = FALSE;
00140 static U32 g_u32_ushell_pba_hz;
00141
00142
00143 static U8 g_u8_escape_sequence=0;
00144 static U8 g_u8_cmd_size=0;
00145 static U8 g_u8_history_pos=0;
00146 static U8 g_u8_history_pos_search=0;
00147 static char g_s_cmd_his[USHELL_HISTORY][USHELL_SIZE_CMD_LINE];
00148 static char g_s_cmd[USHELL_SIZE_CMD_LINE];
00149 static char g_s_arg[USHELL_MAX_NB_ARG][USHELL_SIZE_CMD_LINE];
00150
00151
00152 static Fs_index g_mark_index;
00153
00154
00155
00156 Bool ushell_cmd_scan ( void );
00157 U8 ushell_cmd_decode ( void );
00158 void ushell_clean_cmd_line ( void );
00159 void ushell_history_up ( void );
00160 void ushell_history_down ( void );
00161 void ushell_history_display ( void );
00162 Bool ushell_more_wait ( void );
00163
00164 void ushell_cmd_nb_drive ( void );
00165 void ushell_cmd_free_space ( void );
00166 void ushell_cmd_format ( void );
00167 void ushell_cmd_mount ( void );
00168 void ushell_cmd_space ( void );
00169 void ushell_cmd_ls ( Bool b_more );
00170 void ushell_cmd_cd ( void );
00171 void ushell_cmd_gotoparent ( void );
00172 void ushell_cmd_cat ( Bool b_more);
00173 void ushell_cmd_help ( void );
00174 void ushell_cmd_mkdir ( void );
00175 void ushell_cmd_touch ( void );
00176 void ushell_cmd_rm ( void );
00177 void ushell_cmd_append_file ( void );
00178 void ushell_cmd_copy ( void );
00179 void ushell_cmd_rename ( void );
00180 Bool ushell_cmd_sync ( void );
00181 void ushell_cmd_perform ( void );
00182 void ushell_path_valid_syntac( char *path );
00183
00184 void ushell_cmdusb_ls ( void );
00185 void ushell_cmdusb_suspend ( void );
00186 void ushell_cmdusb_resume ( void );
00187
00188
00191 void ushell_task_init(U32 pba_hz)
00192 {
00193 U8 u8_i;
00194
00195
00196 static const gpio_map_t SHL_USART_GPIO_MAP =
00197 {
00198 {SHL_USART_RX_PIN, SHL_USART_RX_FUNCTION},
00199 {SHL_USART_TX_PIN, SHL_USART_TX_FUNCTION}
00200 };
00201 #if (defined __GNUC__)
00202 set_usart_base((void *)SHL_USART);
00203 gpio_enable_module(SHL_USART_GPIO_MAP,
00204 sizeof(SHL_USART_GPIO_MAP) / sizeof(SHL_USART_GPIO_MAP[0]));
00205 usart_init(SHL_USART_BAUDRATE);
00206 #elif (defined __ICCAVR32__)
00207 static const usart_options_t SHL_USART_OPTIONS =
00208 {
00209 .baudrate = SHL_USART_BAUDRATE,
00210 .charlength = 8,
00211 .paritytype = USART_NO_PARITY,
00212 .stopbits = USART_1_STOPBIT,
00213 .channelmode = USART_NORMAL_CHMODE
00214 };
00215
00216 extern volatile avr32_usart_t *volatile stdio_usart_base;
00217 stdio_usart_base = SHL_USART;
00218 gpio_enable_module(SHL_USART_GPIO_MAP,
00219 sizeof(SHL_USART_GPIO_MAP) / sizeof(SHL_USART_GPIO_MAP[0]));
00220 usart_init_rs232(SHL_USART, &SHL_USART_OPTIONS, pba_hz);
00221 #endif
00222
00223
00224
00225 #if (defined __GNUC__)
00226 setbuf(stdin, NULL);
00227 #endif
00228 setbuf(stdout, NULL);
00229
00230
00231 g_b_ushell_task_run = FALSE;
00232 for( u8_i=0; u8_i<USHELL_HISTORY; u8_i++ ) {
00233 g_s_cmd_his[u8_i][0] = 0;
00234 }
00235
00236 fputs(MSG_EXIT, stdout );
00237
00238 g_u32_ushell_pba_hz = pba_hz;
00239
00240 #ifdef FREERTOS_USED
00241 xTaskCreate(ushell_task,
00242 configTSK_USHELL_NAME,
00243 configTSK_USHELL_STACK_SIZE,
00244 NULL,
00245 configTSK_USHELL_PRIORITY,
00246 NULL);
00247 #endif // FREERTOS_USED
00248 }
00249
00250
00251 #ifdef FREERTOS_USED
00252
00258 void ushell_task(void *pvParameters)
00259 #else
00260
00264 void ushell_task(void)
00265 #endif
00266 {
00267
00268 #ifdef FREERTOS_USED
00269
00270 portTickType xLastWakeTime;
00271
00272 xLastWakeTime = xTaskGetTickCount();
00273 while (TRUE)
00274 {
00275 vTaskDelayUntil(&xLastWakeTime, configTSK_USHELL_PERIOD);
00276 #else
00277
00278 {
00279 #endif // FREERTOS_USED
00280
00281
00282
00283 if(!g_b_ushell_task_run)
00284 {
00285 if( Is_usb_id_device() )
00286 #ifdef FREERTOS_USED
00287 continue;
00288 #else
00289 return;
00290 #endif
00291 g_b_ushell_task_run = TRUE;
00292
00293 fputs(MSG_WELCOME, stdout);
00294 ushell_cmd_nb_drive();
00295 fputs(MSG_PROMPT, stdout);
00296
00297
00298 nav_reset();
00299 nav_select( FS_NAV_ID_USHELL_CMD );
00300 nav_drive_set( 0 );
00301 }else{
00302 if( Is_usb_id_device() )
00303 {
00304 g_b_ushell_task_run = FALSE;
00305 fputs(MSG_EXIT, stdout );
00306 nav_exit();
00307 #ifdef FREERTOS_USED
00308 continue;
00309 #else
00310 return;
00311 #endif
00312 }
00313 }
00314
00315
00316 if( !ushell_cmd_scan() )
00317 #ifdef FREERTOS_USED
00318 continue;
00319 #else
00320 return;
00321 #endif
00322
00323
00324 switch( ushell_cmd_decode() )
00325 {
00326
00327 case CMD_NB_DRIVE:
00328 ushell_cmd_nb_drive();
00329 break;
00330
00331
00332 case CMD_DF:
00333 ushell_cmd_free_space();
00334 break;
00335
00336
00337 case CMD_FORMAT:
00338 ushell_cmd_format();
00339 break;
00340
00341
00342 case CMD_MOUNT:
00343 ushell_cmd_mount();
00344 break;
00345
00346
00347 case CMD_SPACE:
00348 ushell_cmd_space();
00349 break;
00350
00351
00352 case CMD_LS:
00353 ushell_cmd_ls(FALSE);
00354 break;
00355 case CMD_LS_MORE:
00356 ushell_cmd_ls(TRUE);
00357 break;
00358
00359
00360 case CMD_CD:
00361 ushell_cmd_cd();
00362 break;
00363
00364
00365 case CMD_UP:
00366 ushell_cmd_gotoparent();
00367 break;
00368
00369
00370 case CMD_CAT:
00371 ushell_cmd_cat(FALSE);
00372 break;
00373 case CMD_CAT_MORE:
00374 ushell_cmd_cat(TRUE);
00375 break;
00376
00377
00378 case CMD_HELP:
00379 ushell_cmd_help();
00380 break;
00381
00382
00383 case CMD_MKDIR:
00384 ushell_cmd_mkdir();
00385 break;
00386
00387
00388 case CMD_TOUCH:
00389 ushell_cmd_touch();
00390 break;
00391
00392
00393 case CMD_RM:
00394 ushell_cmd_rm();
00395 break;
00396
00397
00398 case CMD_APPEND:
00399 ushell_cmd_append_file();
00400 break;
00401
00402
00403 case CMD_SET_ID:
00404 g_mark_index = nav_getindex();
00405 break;
00406 case CMD_GOTO_ID:
00407 nav_gotoindex( &g_mark_index );
00408 break;
00409
00410
00411 case CMD_CP:
00412 ushell_cmd_copy();
00413 break;
00414
00415
00416 case CMD_MV:
00417 ushell_cmd_rename();
00418 break;
00419
00420
00421 case CMD_SYNC:
00422 ushell_cmd_sync();
00423 break;
00424
00425 case CMD_PERFORM:
00426 ushell_cmd_perform();
00427 break;
00428
00429
00430 #if USB_HOST_FEATURE == ENABLED
00431 case CMD_LS_USB:
00432 ushell_cmdusb_ls();
00433 break;
00434 case CMD_USB_SUSPEND:
00435 ushell_cmdusb_suspend();
00436 break;
00437 case CMD_USB_RESUME:
00438 ushell_cmdusb_resume();
00439 break;
00440 #endif
00441
00442
00443 default:
00444 fputs(MSG_ER_CMD_NOT_FOUND, stdout);
00445 break;
00446 }
00447
00448 fputs(MSG_PROMPT, stdout);
00449
00450 }
00451 }
00452
00453
00458 Bool ushell_cmd_scan(void)
00459 {
00460 int c_key;
00461
00462
00463 if (usart_read_char(SHL_USART, &c_key) != USART_SUCCESS)
00464 {
00465 usart_reset_status(SHL_USART);
00466 return FALSE;
00467 }
00468
00469 if( 0 != g_u8_escape_sequence )
00470 {
00471
00472 if( 1 == g_u8_escape_sequence )
00473 {
00474 if( 0x5B != c_key )
00475 {
00476 g_u8_escape_sequence=0;
00477 return FALSE;
00478 }
00479 g_u8_escape_sequence=2;
00480 }
00481 else
00482 {
00483
00484 switch (c_key)
00485 {
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500 default:
00501 break;
00502 }
00503 g_u8_escape_sequence=0;
00504 }
00505 return FALSE;
00506 }
00507
00508
00509 switch (c_key)
00510 {
00511
00512 case ASCII_CR:
00513 putchar(ASCII_CR);
00514 putchar(ASCII_LF);
00515 g_s_cmd_his[g_u8_history_pos][g_u8_cmd_size]=0;
00516 return TRUE;
00517
00518
00519 case ASCII_ESCAPE:
00520 g_u8_escape_sequence=1;
00521 break;
00522
00523
00524 case ASCII_BKSPACE:
00525 if(g_u8_cmd_size>0)
00526 {
00527
00528 putchar(ASCII_BKSPACE);
00529 putchar(' ');
00530 putchar(ASCII_BKSPACE);
00531
00532 g_u8_cmd_size--;
00533 }
00534 break;
00535
00536
00537 case '!':
00538 ushell_clean_cmd_line();
00539 ushell_history_up();
00540 ushell_history_display();
00541 break;
00542 case '$':
00543 ushell_clean_cmd_line();
00544 ushell_history_down();
00545 ushell_history_display();
00546 break;
00547
00548
00549 default:
00550 if( (0x1F<c_key) && (c_key<0x7F) && (USHELL_SIZE_CMD_LINE!=g_u8_cmd_size) )
00551 {
00552
00553 putchar(c_key);
00554 g_s_cmd_his[g_u8_history_pos][g_u8_cmd_size++] = c_key;
00555 }
00556 break;
00557 }
00558 return FALSE;
00559 }
00560
00561
00571 U8 ushell_cmd_decode( void )
00572 {
00573 U8 cmd_type;
00574 U8 u8_i,u8_j,u8_k;
00575 Bool b_arg_include_space;
00576
00577 if(0==g_u8_cmd_size)
00578 {
00579
00580 fputs(MSG_PROMPT, stdout);
00581 return CMD_NONE;
00582 }
00583
00584
00585 for( u8_i=0; (g_s_cmd_his[g_u8_history_pos][u8_i]!=' ') && (u8_i<=g_u8_cmd_size); u8_i++)
00586 {
00587 g_s_cmd[u8_i] = g_s_cmd_his[g_u8_history_pos][u8_i];
00588 if( ('A'<=g_s_cmd[u8_i]) && (g_s_cmd[u8_i]<='Z') )
00589 g_s_cmd[u8_i] += ('a'-'A');
00590 }
00591 g_s_cmd[u8_i]=0;
00592
00593
00594 for( u8_j=0; u8_j<USHELL_MAX_NB_ARG; u8_j++ )
00595 {
00596 u8_i++;
00597
00598 b_arg_include_space = ( g_s_cmd_his[g_u8_history_pos][u8_i] == '"' );
00599 if( b_arg_include_space ) {
00600 u8_i++;
00601 }
00602 for( u8_k=0;
00603 (b_arg_include_space || (g_s_cmd_his[g_u8_history_pos][u8_i] != ' '))
00604 && ((!b_arg_include_space) || (g_s_cmd_his[g_u8_history_pos][u8_i] != '"'))
00605 && (u8_i<=g_u8_cmd_size);
00606 u8_i++, u8_k++ )
00607 {
00608 g_s_arg[u8_j][u8_k] = g_s_cmd_his[g_u8_history_pos][u8_i];
00609 }
00610 if( b_arg_include_space ) {
00611 u8_i++;
00612 }
00613 g_s_arg[u8_j][u8_k] = 0;
00614 }
00615
00616
00617 g_u8_cmd_size=0;
00618 g_u8_history_pos++;
00619 if( g_u8_history_pos == USHELL_HISTORY)
00620 g_u8_history_pos = 0;
00621 g_u8_history_pos_search = g_u8_history_pos;
00622
00623
00624 if (!strcmp(g_s_cmd, STR_DISK ))
00625 { cmd_type=CMD_NB_DRIVE; }
00626 else if ( !strcmp(g_s_cmd, STR_DF))
00627 { cmd_type=CMD_DF; }
00628 else if ( !strcmp(g_s_cmd, STR_FORMAT))
00629 { cmd_type=CMD_FORMAT; }
00630 else if ( !strcmp(g_s_cmd, STR_MOUNT))
00631 { cmd_type=CMD_MOUNT; }
00632 else if ( g_s_cmd[1]==':' )
00633 { cmd_type=CMD_MOUNT; g_s_arg[0][0]=g_s_cmd[0];g_s_arg[0][1]='0'; }
00634 else if ( !strcmp(g_s_cmd, STR_SPACE))
00635 { cmd_type=CMD_SPACE; }
00636 else if ( !strcmp(g_s_cmd, STR_LS))
00637 { cmd_type=CMD_LS; }
00638 else if ( !strcmp(g_s_cmd, STR_LS_MORE))
00639 { cmd_type=CMD_LS_MORE; }
00640 else if (!strcmp(g_s_cmd, STR_CD))
00641 { cmd_type=CMD_CD; }
00642 else if ( !strcmp(g_s_cmd, STR_UP))
00643 { cmd_type=CMD_UP; }
00644 else if ( !strcmp(g_s_cmd, STR_CAT))
00645 { cmd_type=CMD_CAT; }
00646 else if ( !strcmp(g_s_cmd, STR_CAT_MORE))
00647 { cmd_type=CMD_CAT_MORE; }
00648 else if ( !strcmp(g_s_cmd, STR_HELP))
00649 { cmd_type=CMD_HELP; }
00650 else if ( !strcmp(g_s_cmd, STR_MKDIR))
00651 { cmd_type=CMD_MKDIR; }
00652 else if ( !strcmp(g_s_cmd, STR_TOUCH))
00653 { cmd_type=CMD_TOUCH; }
00654 else if ( !strcmp(g_s_cmd, STR_RM))
00655 { cmd_type=CMD_RM; }
00656 else if ( !strcmp(g_s_cmd, STR_APPEND))
00657 { cmd_type=CMD_APPEND; }
00658 else if ( !strcmp(g_s_cmd, STR_MARK))
00659 { cmd_type=CMD_SET_ID; }
00660 else if ( !strcmp(g_s_cmd, STR_GOTO))
00661 { cmd_type=CMD_GOTO_ID; }
00662 else if ( !strcmp(g_s_cmd, STR_CP))
00663 { cmd_type=CMD_CP; }
00664 else if ( !strcmp(g_s_cmd, STR_MV))
00665 { cmd_type=CMD_MV; }
00666 else if ( !strcmp(g_s_cmd, STR_SYNC))
00667 { cmd_type=CMD_SYNC; }
00668 else if ( !strcmp(g_s_cmd, STR_PERFORM))
00669 { cmd_type=CMD_PERFORM; }
00670 #if USB_HOST_FEATURE == ENABLED
00671 else if ( !strcmp(g_s_cmd, STR_LS_USB))
00672 { cmd_type=CMD_LS_USB; }
00673 else if ( !strcmp(g_s_cmd, STR_USB_SUSPEND))
00674 { cmd_type=CMD_USB_SUSPEND; }
00675 else if ( !strcmp(g_s_cmd, STR_USB_RESUME))
00676 { cmd_type=CMD_USB_RESUME; }
00677 #endif
00678 else
00679 {
00680 fputs(MSG_ER_CMD_NOT_FOUND, stdout);
00681 fputs(MSG_PROMPT, stdout);
00682 return CMD_NONE;
00683 }
00684 return cmd_type;
00685 }
00686
00687
00690 void ushell_clean_cmd_line( void )
00691 {
00692
00693 while( 0 != g_u8_cmd_size )
00694 {
00695
00696 putchar(ASCII_BKSPACE);
00697 putchar(' ');
00698 putchar(ASCII_BKSPACE);
00699 g_u8_cmd_size--;
00700 }
00701 }
00702
00703
00706 void ushell_history_up( void )
00707 {
00708 if( g_u8_history_pos_search == 0 )
00709 {
00710 if( (USHELL_HISTORY-1) == g_u8_history_pos )
00711 return;
00712 g_u8_history_pos_search = USHELL_HISTORY-1;
00713 }else{
00714 if( (g_u8_history_pos_search-1) == g_u8_history_pos )
00715 return;
00716 g_u8_history_pos_search--;
00717 }
00718 if( 0 == g_s_cmd_his[g_u8_history_pos_search][0] )
00719 {
00720
00721 ushell_history_down();
00722 }
00723 }
00724
00725
00728 void ushell_history_down( void )
00729 {
00730 if( g_u8_history_pos_search == g_u8_history_pos )
00731 return;
00732 if( g_u8_history_pos == 0 )
00733 {
00734 if( (USHELL_HISTORY-1) == g_u8_history_pos_search )
00735 return;
00736 g_u8_history_pos_search++;
00737 }else{
00738 if( (g_u8_history_pos_search+1) == g_u8_history_pos )
00739 return;
00740 }
00741 g_u8_history_pos_search++;
00742 if( USHELL_HISTORY == g_u8_history_pos_search )
00743 g_u8_history_pos_search = 0;
00744 }
00745
00746
00749 void ushell_history_display( void )
00750 {
00751 g_u8_cmd_size=0;
00752 while( g_s_cmd_his[g_u8_history_pos_search][g_u8_cmd_size] != 0 )
00753 {
00754 putchar( g_s_cmd_his[g_u8_history_pos_search][g_u8_cmd_size] );
00755 g_s_cmd_his[g_u8_history_pos][g_u8_cmd_size] = g_s_cmd_his[g_u8_history_pos_search][g_u8_cmd_size];
00756 g_u8_cmd_size++;
00757 }
00758 g_s_cmd_his[g_u8_history_pos][g_u8_cmd_size] = 0;
00759 }
00760
00761
00766 Bool ushell_more_wait( void )
00767 {
00768 int c_key;
00769 printf("\n\r-- space for more--");
00770 c_key=0;
00771 while( (c_key!='q') && (c_key!=' ') )
00772 {
00773 usart_reset_status(SHL_USART);
00774 while(usart_read_char(SHL_USART, &c_key) != USART_SUCCESS);
00775 }
00776 printf("\r \r");
00777 return (c_key==' ');
00778 }
00779
00780
00783 void ushell_cmd_nb_drive( void )
00784 {
00785 U8 u8_tmp;
00786
00787 printf("Memory interface available:\r\n");
00788 for( u8_tmp=0; u8_tmp<nav_drive_nb(); u8_tmp++ )
00789 {
00790
00791 printf("%c: %s\r\n", 'a'+u8_tmp, mem_name(u8_tmp) );
00792 }
00793 }
00794
00795
00798 void ushell_cmd_free_space( void )
00799 {
00800 U8 u8_tmp;
00801 Fs_index sav_index = nav_getindex();
00802 for( u8_tmp=0; u8_tmp<nav_drive_nb(); u8_tmp++ )
00803 {
00804 nav_drive_set( u8_tmp );
00805 if( !nav_partition_mount() )
00806 continue;
00807
00808
00809 printf("%c: %s\r\n", 'a'+u8_tmp, mem_name(u8_tmp) );
00810 if( g_s_arg[0][0]=='l' )
00811 {
00812
00813 printf("Free space: %llu Bytes / %llu Bytes\n\r",
00814 (U64)(nav_partition_freespace() << FS_SHIFT_B_TO_SECTOR),
00815 (U64)(nav_partition_space() << FS_SHIFT_B_TO_SECTOR));
00816 }
00817 else
00818 {
00819
00820 printf("Free space: %u %%\n\r", nav_partition_freespace_percent() );
00821 }
00822 }
00823 nav_gotoindex(&sav_index);
00824 }
00825
00826
00829 void ushell_cmd_format( void )
00830 {
00831 if( g_s_arg[0][0] == 0 )
00832 return;
00833
00834
00835 nav_drive_set( g_s_arg[0][0]-'a');
00836 if( !nav_drive_format(FS_FORMAT_DEFAULT) )
00837 {
00838 fputs(MSG_ER_FORMAT, stdout);
00839 return;
00840 }
00841 }
00842
00843
00846 void ushell_cmd_mount( void )
00847 {
00848 U8 u8_drive_lun;
00849 Fs_index sav_index;
00850
00851 if( g_s_arg[0][0] == 0 )
00852 return;
00853
00854
00855 u8_drive_lun=g_s_arg[0][0]-'a';
00856
00857 if( u8_drive_lun >= nav_drive_nb() )
00858 {
00859 fputs(MSG_ER_DRIVE, stdout);
00860 return;
00861 }
00862
00863
00864 sav_index = nav_getindex();
00865 if( nav_drive_set(u8_drive_lun))
00866 {
00867 if( nav_partition_mount() )
00868 return;
00869 }
00870 fputs(MSG_ER_MOUNT, stdout);
00871 nav_gotoindex(&sav_index);
00872 }
00873
00874
00877 void ushell_cmd_space( void )
00878 {
00879 U32 u32_space;
00880
00881 fputs( mem_name(nav_drive_get()), stdout);
00882 putchar(' ');
00883 putchar( nav_drive_get()+'a');
00884
00885 u32_space = nav_partition_space();
00886 if( 1024 >(u32_space % (2*1024)) )
00887 {
00888 u32_space = u32_space/(2*1024);
00889 }else{
00890 u32_space = (u32_space/(2*1024))+1;
00891 }
00892 printf(": space: %luMB \n\r", u32_space );
00893 }
00894
00895
00900 void ushell_cmd_ls( Bool b_more )
00901 {
00902 U8 str_char[MAX_FILE_PATH_LENGTH];
00903 U16 u16_i,u16_nb_file,u16_nb_dir,last_i;
00904 U8 ext_filter=FALSE;
00905
00906
00907 printf("%c: volume is %s\r\n", 'a'+nav_drive_get(), mem_name(nav_drive_get()) );
00908 printf("Drive uses ");
00909 switch (nav_partition_type())
00910 {
00911 case FS_TYPE_FAT_12:
00912 printf("FAT12\n\r");
00913 break;
00914
00915 case FS_TYPE_FAT_16:
00916 printf("FAT16\n\r");
00917 break;
00918
00919 case FS_TYPE_FAT_32:
00920 printf("FAT32\n\r");
00921 break;
00922
00923 default:
00924 printf("an unknown partition type\r\n");
00925 return;
00926 }
00927
00928
00929 if( !nav_dir_name( (FS_STRING)str_char, MAX_FILE_PATH_LENGTH ) )
00930 return;
00931 printf("Dir name is %s\n\r",str_char);
00932
00933
00934 if(g_s_arg[0][0]!=0)
00935 {
00936 if(g_s_arg[0][0] == '*' && g_s_arg[0][1]=='.')
00937 {
00938 ext_filter=TRUE;
00939 for(u16_i=2; u16_i<USHELL_SIZE_CMD_LINE; u16_i++)
00940 {
00941 g_s_arg[0][u16_i-2]=g_s_arg[0][u16_i];
00942 }
00943 }
00944 }
00945
00946
00947 printf(" Size Name\n\r");
00948
00949 nav_filelist_reset();
00950 u16_nb_file=0;
00951 u16_nb_dir=0;
00952 last_i=0;
00953
00954 while( nav_filelist_set(0,FS_FIND_NEXT) )
00955 {
00956 if(!ext_filter)
00957 {
00958
00959 if( nav_file_isdir() )
00960 {
00961 printf("Dir ");
00962 u16_nb_dir++;
00963 }else{
00964 printf(" ");
00965 }
00966 }
00967 else
00968 {
00969
00970 if(nav_file_isdir())
00971 continue;
00972
00973 if(!nav_file_checkext((FS_STRING)g_s_arg[0]))
00974 continue;
00975 }
00976 u16_nb_file++;
00977
00978
00979 if( b_more && ((u16_nb_file%USHELL_NB_LINE)==0) && (u16_nb_file!=0) && (last_i != u16_nb_file) )
00980 {
00981 last_i=u16_nb_file;
00982 if( !ushell_more_wait() )
00983 return;
00984 }
00985
00986
00987 nav_file_name((FS_STRING)str_char, MAX_FILE_PATH_LENGTH, FS_NAME_GET, TRUE);
00988 printf("%10lu %s\n\r", nav_file_lgt(), str_char);
00989 }
00990
00991 printf(" %4i Files\r\n", u16_nb_file-u16_nb_dir );
00992 printf(" %4i Dir\r\n", u16_nb_dir );
00993 }
00994
00995
00998 void ushell_cmd_cd( void )
00999 {
01000 if( g_s_arg[0][0] == 0 )
01001 return;
01002
01003
01004 ushell_path_valid_syntac( g_s_arg[0] );
01005
01006
01007 if( nav_setcwd((FS_STRING)g_s_arg[0],TRUE,FALSE) == FALSE )
01008 {
01009 fputs(MSG_ER_UNKNOWN_FILE, stdout);
01010 }
01011 }
01012
01013
01016 void ushell_cmd_gotoparent( void )
01017 {
01018 nav_dir_gotoparent();
01019 }
01020
01021
01028 void ushell_cmd_cat(Bool b_more)
01029 {
01030 char c_file_character;
01031 U8 n_line=0;
01032
01033 if( g_s_arg[0][0] == 0 )
01034 return;
01035
01036
01037 if( !nav_setcwd((FS_STRING)g_s_arg[0],TRUE,FALSE) )
01038 {
01039 fputs(MSG_ER_UNKNOWN_FILE, stdout);
01040 return;
01041 }
01042
01043
01044 file_open(FOPEN_MODE_R);
01045 while (file_eof()==FALSE)
01046 {
01047
01048 if( b_more && (n_line >= USHELL_NB_LINE))
01049 {
01050 n_line = 0;
01051 if( !ushell_more_wait() )
01052 break;
01053 }
01054
01055
01056 c_file_character = file_getc();
01057 putchar( c_file_character );
01058
01059
01060 if (c_file_character==ASCII_LF)
01061 n_line++;
01062 }
01063 file_close();
01064
01065
01066 putchar(ASCII_CR);putchar(ASCII_LF);
01067 }
01068
01069
01072 void ushell_cmd_help( void )
01073 {
01074 fputs(MSG_HELP, stdout);
01075 }
01076
01077
01080 void ushell_cmd_mkdir( void )
01081 {
01082 if( g_s_arg[0][0] == 0 )
01083 return;
01084
01085 if( !nav_dir_make((FS_STRING)g_s_arg[0]) )
01086 fputs(MSG_KO, stdout);
01087 }
01088
01089
01092 void ushell_cmd_touch( void )
01093 {
01094 if( g_s_arg[0][0] == 0 )
01095 return;
01096
01097 nav_file_create((FS_STRING)g_s_arg[0]);
01098 }
01099
01100
01103 void ushell_cmd_rm( void )
01104 {
01105 U8 u8_i = 0;
01106 Fs_index sav_index;
01107
01108 if( g_s_arg[0][0] == 0 )
01109 return;
01110
01111
01112 sav_index = nav_getindex();
01113
01114 while( 1 )
01115 {
01116
01117 nav_gotoindex(&sav_index);
01118
01119 if( !nav_setcwd( (FS_STRING)g_s_arg[0], TRUE, FALSE ) )
01120 break;
01121
01122 if( !nav_file_del( FALSE ) )
01123 {
01124 fputs(MSG_KO, stdout);
01125 break;
01126 }
01127 u8_i++;
01128 }
01129 printf( "%u file(s) deleted\n\r", u8_i );
01130 }
01131
01132
01139 void ushell_cmd_append_file( void )
01140 {
01141 int c_key;
01142
01143 if( g_s_arg[0][0] == 0 )
01144 return;
01145
01146
01147 if( !nav_setcwd( (FS_STRING)g_s_arg[0], TRUE, FALSE ) )
01148 {
01149 fputs(MSG_ER_UNKNOWN_FILE, stdout);
01150 return;
01151 }
01152
01153 if( !file_open(FOPEN_MODE_APPEND) )
01154 {
01155 fputs(MSG_KO, stdout);
01156 return;
01157 }
01158
01159
01160 fputs(MSG_APPEND_WELCOME, stdout);
01161 while( 1 )
01162 {
01163 usart_reset_status(SHL_USART);
01164 while(usart_read_char(SHL_USART, &c_key) != USART_SUCCESS);
01165
01166 if( c_key == ASCII_CTRL_Q )
01167 break;
01168
01169 putchar( c_key );
01170 file_putc( c_key );
01171 if( c_key == ASCII_CR )
01172 {
01173 putchar(ASCII_LF);
01174 file_putc(ASCII_LF);
01175 }
01176 }
01177
01178
01179 file_close();
01180 putchar(ASCII_CR);putchar(ASCII_LF);
01181 }
01182
01183
01186 void ushell_cmd_copy( void )
01187 {
01188 Fs_index sav_index;
01189 U8 u8_status_copy;
01190
01191 if( g_s_arg[0][0] == 0 )
01192 return;
01193
01194
01195 sav_index = nav_getindex();
01196
01197
01198 if( !nav_setcwd( (FS_STRING)g_s_arg[0], TRUE, FALSE ) )
01199 {
01200 fputs(MSG_ER_UNKNOWN_FILE, stdout);
01201 return;
01202 }
01203
01204 nav_file_name( (FS_STRING)g_s_arg[0], MAX_FILE_PATH_LENGTH, FS_NAME_GET, TRUE );
01205
01206 if( !nav_file_copy())
01207 {
01208 fputs(MSG_KO, stdout);
01209 goto cp_end;
01210 }
01211
01212
01213 if( g_s_arg[1][0]==0 )
01214 {
01215
01216 if( !nav_gotoindex(&g_mark_index) )
01217 goto cp_end;
01218 }
01219 else
01220 {
01221
01222 if( !nav_setcwd( (FS_STRING)g_s_arg[1], TRUE, FALSE ) )
01223 {
01224 fputs(MSG_ER_UNKNOWN_FILE, stdout);
01225 goto cp_end;
01226 }
01227 }
01228
01229
01230 if( !nav_file_paste_start((FS_STRING)g_s_arg[0]) )
01231 {
01232 fputs(MSG_ER_PASTE, stdout);
01233 goto cp_end;
01234 }
01235
01236
01237 do
01238 {
01239 u8_status_copy = nav_file_paste_state( FALSE );
01240 }while( u8_status_copy == COPY_BUSY );
01241
01242
01243 if( u8_status_copy == COPY_FAIL )
01244 {
01245 fputs(MSG_ER_PASTE, stdout);
01246 goto cp_end;
01247 }
01248
01249 cp_end:
01250
01251 nav_gotoindex(&sav_index);
01252 }
01253
01254
01257 void ushell_cmd_rename( void )
01258 {
01259 if( g_s_arg[0][0] == 0 )
01260 return;
01261 if( g_s_arg[1][0] == 0 )
01262 return;
01263
01264
01265 if( !nav_setcwd( (FS_STRING)g_s_arg[0], TRUE, FALSE ) )
01266 {
01267 fputs(MSG_ER_UNKNOWN_FILE, stdout);
01268 return;
01269 }
01270
01271 if( !nav_file_rename( (FS_STRING)g_s_arg[1] ) )
01272 {
01273 fputs(MSG_KO, stdout);
01274 return;
01275 }
01276 }
01277
01278
01283 Bool ushell_cmd_sync( void )
01284 {
01285 Fs_index sav_index;
01286 U8 u8_folder_level = 0;
01287
01288 if( g_s_arg[0][0] == 0 )
01289 return FALSE;
01290 if( g_s_arg[1][0] == 0 )
01291 return FALSE;
01292
01293 ushell_path_valid_syntac( g_s_arg[0] );
01294 ushell_path_valid_syntac( g_s_arg[1] );
01295
01296 printf("Synchronize folders:\n\r");
01297 sav_index = nav_getindex();
01298
01299
01300 nav_select( FS_NAV_ID_COPYFILE );
01301 printf("Select source directory\n\r");
01302 if( !nav_setcwd( (FS_STRING)g_s_arg[0], TRUE, FALSE ) )
01303 goto ushell_cmd_sync_error;
01304 nav_filelist_reset();
01305
01306
01307 nav_select( FS_NAV_ID_USHELL_CMD );
01308 printf("Select destination directory\n\r");
01309 if( !nav_setcwd( (FS_STRING)g_s_arg[1], TRUE, TRUE ) )
01310 goto ushell_cmd_sync_error;
01311 nav_filelist_reset();
01312
01313
01314 while(1)
01315 {
01316 while(1)
01317 {
01318
01319
01320 nav_select( FS_NAV_ID_COPYFILE );
01321 if( nav_filelist_set( 0 , FS_FIND_NEXT ) )
01322 break;
01323
01324
01325 if( 0 == u8_folder_level )
01326 {
01327
01328
01329 goto ushell_cmd_sync_finish;
01330 }
01331
01332 printf("Go to parent\n\r");
01333
01334 u8_folder_level--;
01335 if( !nav_dir_gotoparent() )
01336 goto ushell_cmd_sync_error;
01337
01338 nav_select( FS_NAV_ID_USHELL_CMD );
01339 if( !nav_dir_gotoparent() )
01340 goto ushell_cmd_sync_error;
01341 }
01342
01343 if( nav_file_isdir())
01344 {
01345 printf("Dir found - create dir: ");
01346
01347
01348 if( !nav_file_name( (FS_STRING)g_s_arg[0], USHELL_SIZE_CMD_LINE, FS_NAME_GET, FALSE ))
01349 goto ushell_cmd_sync_error;
01350
01351 if( !nav_dir_cd())
01352 goto ushell_cmd_sync_error;
01353 u8_folder_level++;
01354
01355 nav_select( FS_NAV_ID_USHELL_CMD );
01356
01357 printf((char*)g_s_arg[0]);
01358 printf("\n\r");
01359 if( !nav_dir_make( (FS_STRING )g_s_arg[0] ))
01360 {
01361 if( FS_ERR_FILE_EXIST != fs_g_status )
01362 goto ushell_cmd_sync_error;
01363
01364 }
01365
01366 if( !nav_dir_cd())
01367 {
01368 if( FS_ERR_NO_DIR == fs_g_status )
01369 {
01370
01371 }
01372 goto ushell_cmd_sync_error;
01373 }
01374
01375 }
01376 else
01377 {
01378 printf("File found - copy file: ");
01379
01380
01381 if( !nav_file_name( (FS_STRING)g_s_arg[0], USHELL_SIZE_CMD_LINE, FS_NAME_GET, FALSE ))
01382 goto ushell_cmd_sync_error;
01383 printf((char*)g_s_arg[0]);
01384 printf("\n\r");
01385 if( !nav_file_copy())
01386 goto ushell_cmd_sync_error;
01387
01388
01389 nav_select( FS_NAV_ID_USHELL_CMD );
01390 while( !nav_file_paste_start( (FS_STRING)g_s_arg[0] ) )
01391 {
01392
01393 if( fs_g_status != FS_ERR_FILE_EXIST )
01394 goto ushell_cmd_sync_error;
01395
01396 printf("File exists then deletes this one.\n\r");
01397 if( !nav_file_del( TRUE ) )
01398 goto ushell_cmd_sync_error;
01399
01400 }
01401
01402 {
01403 U8 status;
01404 do{
01405 status = nav_file_paste_state(FALSE);
01406 }while( COPY_BUSY == status );
01407
01408 if( COPY_FINISH != status )
01409 goto ushell_cmd_sync_error;
01410 }
01411 }
01412 }
01413
01414 ushell_cmd_sync_error:
01415
01416 nav_select( FS_NAV_ID_USHELL_CMD );
01417 nav_gotoindex(&sav_index);
01418 printf("!!!Copy fail\n\r");
01419 return FALSE;
01420
01421 ushell_cmd_sync_finish:
01422
01423 nav_select( FS_NAV_ID_USHELL_CMD );
01424 nav_gotoindex(&sav_index);
01425 printf("End of copy\n\r");
01426 return TRUE;
01427 }
01428
01429
01430 #define FILE_ALLOC_SIZE ((1024*1024L)/512L) // 1MB
01431
01432 Fs_file_segment ushell_cmd_perform_alloc( U8 lun, U16 size_alloc )
01433 {
01434 const FS_STRING file_tmp_name = "tmp.bin";
01435 Fs_file_segment g_recorder_seg;
01436 g_recorder_seg.u16_size = 0;
01437
01438 if( !nav_drive_set(lun))
01439 return g_recorder_seg;
01440
01441 if( !nav_partition_mount() )
01442 return g_recorder_seg;
01443
01444 if( !nav_file_create((FS_STRING)file_tmp_name))
01445 {
01446 if( FS_ERR_FILE_EXIST != fs_g_status)
01447 return g_recorder_seg;
01448 nav_file_del(FALSE);
01449 if( !nav_file_create((FS_STRING)file_tmp_name))
01450 return g_recorder_seg;
01451 }
01452
01453 if( !file_open(FOPEN_MODE_W) )
01454 {
01455 nav_file_del(FALSE);
01456 return g_recorder_seg;
01457 }
01458
01459
01460 g_recorder_seg.u16_size = size_alloc;
01461
01462 if( !file_write( &g_recorder_seg ))
01463 {
01464 g_recorder_seg.u16_size = 0;
01465 file_close();
01466 nav_file_del(FALSE);
01467 }
01468 return g_recorder_seg;
01469 }
01470
01471 void ushell_cmd_perform_transfer( Fs_file_segment seg_src, Fs_file_segment seg_dest )
01472 {
01473 U8 id_trans_memtomem;
01474 Ctrl_status status_stream;
01475 U16 u16_i, u16_trans_max;
01476 U32 u32_tmp, u32_time;
01477
01478 u16_trans_max = ( seg_src.u16_size < seg_dest.u16_size )? seg_src.u16_size : seg_dest.u16_size;
01479 for( u16_i=2; u16_i<=u16_trans_max; u16_i*=10 )
01480 {
01481 u32_time = Get_sys_count();
01482 id_trans_memtomem = stream_mem_to_mem( seg_src.u8_lun , seg_src.u32_addr , seg_dest.u8_lun , seg_dest.u32_addr , u16_i );
01483 if( ID_STREAM_ERR == id_trans_memtomem )
01484 {
01485 printf( "Transfert error\r\n");
01486 return;
01487 }
01488 while(1)
01489 {
01490 status_stream = stream_state( id_trans_memtomem );
01491 if( CTRL_BUSY == status_stream ) continue;
01492 if( CTRL_GOOD == status_stream ) break;
01493 if( CTRL_FAIL == status_stream ) {
01494 printf( "Transfert error\r\n");
01495 return;
01496 }
01497 }
01498 u32_time = cpu_cy_2_us(Get_sys_count()-u32_time, g_u32_ushell_pba_hz );
01499 u32_tmp = ((U32)u16_i*(1000000/2))/u32_time;
01500 printf( "Transfert rate %4luKB/s - stream size %4iKB\r\n", u32_tmp, u16_i/2 );
01501 if( (8000000) < u32_time )
01502 {
01503
01504 break;
01505 }
01506 }
01507 }
01508
01509 void ushell_cmd_perform_access( Bool b_sens_write, Fs_file_segment seg )
01510 {
01511 U16 u16_trans;
01512 U32 u32_tmp, u32_time;
01513
01514 fat_cache_flush();
01515 fat_cache_reset();
01516 u32_time = Get_sys_count();
01517 for( u16_trans=0; u16_trans<seg.u16_size; u16_trans++ )
01518 {
01519 if( b_sens_write )
01520 {
01521 if( CTRL_GOOD != ram_2_memory( seg.u8_lun , seg.u32_addr , fs_g_sector )) {
01522 printf( "Transfert error\r\n");
01523 return;
01524 }
01525 }else{
01526 if( CTRL_GOOD != memory_2_ram( seg.u8_lun , seg.u32_addr , fs_g_sector )) {
01527 printf( "Transfert error\r\n");
01528 return;
01529 }
01530 }
01531 seg.u32_addr++;
01532 if( 8000000 < cpu_cy_2_us(Get_sys_count()-u32_time, g_u32_ushell_pba_hz) )
01533 {
01534
01535 break;
01536 }
01537 }
01538 u32_time = cpu_cy_2_us(Get_sys_count()-u32_time, g_u32_ushell_pba_hz);
01539 u32_tmp = ((U32)u16_trans*(1000000/2))/u32_time;
01540 if( b_sens_write )
01541 printf( "Transfert rate - WRITE %4luKB/s\r\n", u32_tmp );
01542 else
01543 printf( "Transfert rate - READ %4luKB/s\r\n", u32_tmp );
01544 }
01545
01546 #define SIZE_OF_EXT_BUFFER 8
01547 static U8 u8_ext_buffer[512*SIZE_OF_EXT_BUFFER];
01548
01549 void ushell_cmd_perform_extaccess( Bool b_sens_write, Fs_file_segment seg )
01550 {
01551 U16 u16_trans;
01552 U32 u32_tmp, u32_time;
01553 U8 u8_nb_trans_usb=0;
01554
01555 fat_cache_flush();
01556 fat_cache_reset();
01557 u32_time = Get_sys_count();
01558 u16_trans=0;
01559 while( seg.u16_size!=0 )
01560 {
01561 if( 0 == (seg.u32_addr % SIZE_OF_EXT_BUFFER) )
01562 {
01563 u8_nb_trans_usb = SIZE_OF_EXT_BUFFER;
01564 }else{
01565 u8_nb_trans_usb = SIZE_OF_EXT_BUFFER - (seg.u32_addr % SIZE_OF_EXT_BUFFER);
01566 }
01567 if (u8_nb_trans_usb > seg.u16_size)
01568 u8_nb_trans_usb = seg.u16_size;
01569
01570 if( b_sens_write )
01571 {
01572 if( CTRL_GOOD != host_write_10_extram( seg.u32_addr , u8_ext_buffer, u8_nb_trans_usb )) {
01573 printf( "Transfert error\r\n");
01574 return;
01575 }
01576 }else{
01577 if( CTRL_GOOD != host_read_10_extram( seg.u32_addr , u8_ext_buffer, u8_nb_trans_usb )) {
01578 printf( "Transfert error\r\n");
01579 return;
01580 }
01581 }
01582 seg.u16_size -= u8_nb_trans_usb;
01583 u16_trans += u8_nb_trans_usb;
01584 seg.u32_addr += u8_nb_trans_usb;
01585 if( 8000000 < cpu_cy_2_us(Get_sys_count()-u32_time, g_u32_ushell_pba_hz) )
01586 {
01587
01588 break;
01589 }
01590 }
01591 u32_time = cpu_cy_2_us(Get_sys_count()-u32_time, g_u32_ushell_pba_hz);
01592 u32_tmp = ((U32)u16_trans*(1000000/2))/u32_time;
01593 if( b_sens_write )
01594 printf( "Transfert rate - WRITE %4luKB/s\r\n", u32_tmp);
01595 else
01596 printf( "Transfert rate - READ %4luKB/s\r\n", u32_tmp );
01597 }
01598
01599
01602 void ushell_cmd_perform( void )
01603 {
01604 Fs_index sav_index;
01605 Fs_file_segment seg1, seg2;
01606
01607 if( g_s_arg[0][0] == 0 )
01608 return;
01609
01610 sav_index = nav_getindex();
01611
01612
01613 printf("Alloc a file on each devices\n\r");
01614 seg1 = ushell_cmd_perform_alloc( (g_s_arg[0][0]-'a') , FILE_ALLOC_SIZE );
01615 if( seg1.u16_size == 0 )
01616 {
01617 printf("!!!Error allocation on device 1\n\r");
01618
01619 nav_gotoindex(&sav_index);
01620 return;
01621 }
01622 if( g_s_arg[1][0] != 0 )
01623 {
01624 nav_select( FS_NAV_ID_COPYFILE );
01625 seg2 = ushell_cmd_perform_alloc( (g_s_arg[1][0]-'a') , FILE_ALLOC_SIZE );
01626 if( seg2.u16_size == 0 )
01627 {
01628 nav_select( FS_NAV_ID_USHELL_CMD );
01629 file_close();
01630 nav_file_del(FALSE);
01631 printf("!!!Error allocation on device 2\n\r");
01632
01633 nav_gotoindex(&sav_index);
01634 return;
01635 }
01636
01637
01638 printf("Transfert data from device 1 to device 2\r\n");
01639 ushell_cmd_perform_transfer(seg1,seg2);
01640 printf("Transfert data from device 2 to device 1\r\n");
01641 ushell_cmd_perform_transfer(seg2,seg1);
01642
01643 nav_select( FS_NAV_ID_COPYFILE );
01644 file_close();
01645 nav_file_del(FALSE);
01646 nav_select( FS_NAV_ID_USHELL_CMD );
01647 }
01648 else
01649 {
01650 ushell_cmd_perform_access( FALSE, seg1 );
01651 ushell_cmd_perform_access( TRUE, seg1 );
01652 if( LUN_ID_USB <= nav_drive_get() )
01653 {
01654 printf("Transfert large buffer on USB\r\n");
01655 ushell_cmd_perform_extaccess( FALSE, seg1 );
01656 ushell_cmd_perform_extaccess( TRUE, seg1 );
01657 }
01658
01659 }
01660
01661 file_close();
01662 nav_file_del(FALSE);
01663
01664 nav_gotoindex(&sav_index);
01665 printf("End of test\n\r");
01666 return;
01667 }
01668
01669
01670
01671
01674 void ushell_path_valid_syntac( char *path )
01675 {
01676 U8 u8_tmp;
01677
01678
01679 for( u8_tmp=0; u8_tmp<MAX_FILE_PATH_LENGTH; u8_tmp++ )
01680 {
01681 if( path[u8_tmp]==0)
01682 break;
01683 }
01684
01685 if ( path[u8_tmp-1] != '\\')
01686 {
01687 path[u8_tmp]='\\';
01688 path[u8_tmp+1]=0;
01689 }
01690 }
01691
01692
01693 #if USB_HOST_FEATURE == ENABLED
01698 void ushell_cmdusb_ls(void)
01699 {
01700 U8 i,j;
01701
01702
01703 if( (!Is_host_ready()) && (!Is_host_suspended()) )
01704 {
01705 fputs(MSG_NO_DEVICE, stdout);
01706 return;
01707 }
01708 if( Is_host_suspended() )
01709 {
01710 fputs(MSG_USB_SUSPENDED, stdout);
01711 }
01712
01713 printf("VID:%04X, PID:%04X, ",Get_VID(),Get_PID());
01714 printf("MaxPower is %imA, ",2*Get_maxpower());
01715 if (Is_device_self_powered())
01716 { fputs(MSG_SELF_POWERED, stdout);}
01717 else
01718 { fputs(MSG_BUS_POWERED, stdout); }
01719 if (Is_usb_full_speed_mode())
01720 { fputs(MSG_DEVICE_FULL_SPEED, stdout);}
01721 else
01722 #if (USB_HIGH_SPEED_SUPPORT==DISABLED)
01723 { fputs(MSG_DEVICE_LOW_SPEED, stdout); }
01724 #else
01725 { fputs(MSG_DEVICE_HIGH_SPEED, stdout); }
01726 #endif
01727 if (Is_device_supports_remote_wakeup())
01728 { fputs(MSG_REMOTE_WAKEUP_KO, stdout);}
01729 else
01730 { fputs(MSG_BUS_POWERED, stdout); }
01731 printf("Supported interface(s):%02i\n\r",Get_nb_supported_interface());
01732 for(i=0;i<Get_nb_supported_interface();i++)
01733 {
01734 printf("Interface nb:%02i, AltS nb:%02i, Class:%02i, SubClass:%02i, Protocol:%02i\n\r",\
01735 Get_interface_number(i), Get_altset_nb(i), Get_class(i), Get_subclass(i), Get_protocol(i));
01736 printf(" Endpoint(s) Addr:");
01737 if(Get_nb_ep(i))
01738 {
01739 for(j=0;j<Get_nb_ep(i);j++)
01740 {
01741 printf(" %02lX", Get_ep_nbr(i,j));
01742 }
01743 }
01744 else
01745 {
01746 printf("None");
01747 }
01748 putchar(ASCII_CR);putchar(ASCII_LF);
01749 }
01750 }
01751
01754 void ushell_cmdusb_suspend(void)
01755 {
01756 if( !Is_host_ready() )
01757 {
01758 fputs(MSG_NO_DEVICE, stdout);
01759 }
01760 Host_request_suspend();
01761 }
01762
01765 void ushell_cmdusb_resume(void)
01766 {
01767 if( !Is_host_suspended() )
01768 {
01769 fputs(MSG_NO_DEVICE, stdout);
01770 }
01771 Host_request_resume();
01772 }
01773
01774 #endif // USB_HOST_FEATURE == ENABLED