Definition in file ushell_task.c.
#include "nlao_usart.h"
#include <stdio.h>
#include <string.h>
#include "compiler.h"
#include "board.h"
#include "gpio.h"
#include "usart.h"
#include "FreeRTOS.h"
#include "task.h"
#include "ctrl_access.h"
#include "fat.h"
#include "file.h"
#include "navigation.h"
#include "conf_usb.h"
#include "usb_drv.h"
#include "cycle_counter.h"
#include "usb_host_enum.h"
#include "usb_host_task.h"
#include "host_mass_storage_task.h"
#include "ushell_task.h"
Go to the source code of this file.
Defines | |
#define | FILE_ALLOC_SIZE ((1024*1024L)/512L) |
#define | SIZE_OF_EXT_BUFFER 8 |
#define | USHELL_HISTORY 10 |
#define | USHELL_MAX_NB_ARG 2 |
#define | USHELL_NB_COL 80 |
#define | USHELL_NB_LINE 20 |
#define | USHELL_SIZE_CMD_LINE 70 |
Shell USART Configuration | |
#define | SHL_USART (&AVR32_USART2) |
#define | SHL_USART_BAUDRATE 57600 |
#define | SHL_USART_RX_FUNCTION AVR32_USART2_RXD_0_1_FUNCTION |
#define | SHL_USART_RX_PIN AVR32_USART2_RXD_0_1_PIN |
#define | SHL_USART_TX_FUNCTION AVR32_USART2_TXD_0_1_FUNCTION |
#define | SHL_USART_TX_PIN AVR32_USART2_TXD_0_1_PIN |
Functions | |
void | ushell_clean_cmd_line (void) |
Cleans the command line on the display. | |
void | ushell_cmd_append_file (void) |
Minimalist file editor to append char to a file. | |
void | ushell_cmd_cat (Bool b_more) |
Manage cat command. | |
void | ushell_cmd_cd (void) |
This function enter in a directory. | |
void | ushell_cmd_copy (void) |
This function copys a file to other location. | |
U8 | ushell_cmd_decode (void) |
decodes full command line into command type and arguments | |
void | ushell_cmd_format (void) |
This function formats a drive. | |
void | ushell_cmd_free_space (void) |
This function displays the free space of each drive present. | |
void | ushell_cmd_gotoparent (void) |
This function go back to parent directory. | |
void | ushell_cmd_help (void) |
This function display the help. | |
void | ushell_cmd_ls (Bool b_more) |
This function manages the ls command. | |
void | ushell_cmd_mkdir (void) |
This function create a directory. | |
void | ushell_cmd_mount (void) |
This function mount a drive. | |
void | ushell_cmd_nb_drive (void) |
This function display all drives present. | |
void | ushell_cmd_perform (void) |
Perform transfer between two devices. | |
void | ushell_cmd_perform_access (Bool b_sens_write, Fs_file_segment seg) |
Fs_file_segment | ushell_cmd_perform_alloc (U8 lun, U16 size_alloc) |
void | ushell_cmd_perform_extaccess (Bool b_sens_write, Fs_file_segment seg) |
void | ushell_cmd_perform_transfer (Fs_file_segment seg_src, Fs_file_segment seg_dest) |
void | ushell_cmd_rename (void) |
This function renames a file or a directory. | |
void | ushell_cmd_rm (void) |
This function delete a file or directory. | |
Bool | ushell_cmd_scan (void) |
Get the full command line to be interpreted. | |
void | ushell_cmd_space (void) |
This function displays the disk space of current drive. | |
Bool | ushell_cmd_sync (void) |
Synchronize a path with an other path. | |
void | ushell_cmd_touch (void) |
This function create a file. | |
void | ushell_cmdusb_ls (void) |
In host mode, display basic lowlevel information about the device connected. | |
void | ushell_cmdusb_resume (void) |
In host mode, resume host from suspend mode. | |
void | ushell_cmdusb_suspend (void) |
In host mode, set host in suspend mode. | |
void | ushell_history_display (void) |
Displays the current history. | |
void | ushell_history_down (void) |
Selects the next command in history list. | |
void | ushell_history_up (void) |
Selects the previous command in history list. | |
Bool | ushell_more_wait (void) |
This function wait a key press. | |
void | ushell_path_valid_syntac (char *path) |
Appends the '\' char at the end of path. | |
void | ushell_task (void *pvParameters) |
Entry point of the explorer task management. | |
void | ushell_task_init (U32 pba_hz) |
This function initializes the hardware/software ressources required for ushell task. | |
Variables | |
static Bool | g_b_ushell_task_run = FALSE |
static Fs_index | g_mark_index |
static char | g_s_arg [USHELL_MAX_NB_ARG][USHELL_SIZE_CMD_LINE] |
static char | g_s_cmd [USHELL_SIZE_CMD_LINE] |
static char | g_s_cmd_his [USHELL_HISTORY][USHELL_SIZE_CMD_LINE] |
static U32 | g_u32_ushell_pba_hz |
static U8 | g_u8_cmd_size = 0 |
static U8 | g_u8_escape_sequence = 0 |
static U8 | g_u8_history_pos = 0 |
static U8 | g_u8_history_pos_search = 0 |
static U8 | u8_ext_buffer [512 *SIZE_OF_EXT_BUFFER] |
#define FILE_ALLOC_SIZE ((1024*1024L)/512L) |
#define SHL_USART (&AVR32_USART2) |
Definition at line 117 of file ushell_task.c.
Referenced by ushell_cmd_append_file(), ushell_cmd_scan(), ushell_more_wait(), and ushell_task_init().
#define SHL_USART_BAUDRATE 57600 |
#define SHL_USART_RX_FUNCTION AVR32_USART2_RXD_0_1_FUNCTION |
#define SHL_USART_RX_PIN AVR32_USART2_RXD_0_1_PIN |
#define SHL_USART_TX_FUNCTION AVR32_USART2_TXD_0_1_FUNCTION |
#define SHL_USART_TX_PIN AVR32_USART2_TXD_0_1_PIN |
#define SIZE_OF_EXT_BUFFER 8 |
#define USHELL_HISTORY 10 |
Definition at line 128 of file ushell_task.c.
Referenced by ushell_cmd_decode(), ushell_history_down(), ushell_history_up(), and ushell_task_init().
#define USHELL_MAX_NB_ARG 2 |
#define USHELL_NB_COL 80 |
Definition at line 130 of file ushell_task.c.
#define USHELL_NB_LINE 20 |
#define USHELL_SIZE_CMD_LINE 70 |
Definition at line 132 of file ushell_task.c.
Referenced by ushell_cmd_ls(), ushell_cmd_scan(), and ushell_cmd_sync().
void ushell_clean_cmd_line | ( | void | ) |
Cleans the command line on the display.
Definition at line 691 of file ushell_task.c.
References ASCII_BKSPACE, and g_u8_cmd_size.
Referenced by ushell_cmd_scan().
00691 { 00692 // Clean command line display 00693 while( 0 != g_u8_cmd_size ) 00694 { 00695 // Remove the last character on cmd line buffer 00696 putchar(ASCII_BKSPACE); // Send a backspace to go in previous character 00697 putchar(' '); // Send a space to erase previous character 00698 putchar(ASCII_BKSPACE); // Send a backspace to go in new end position (=previous character position) 00699 g_u8_cmd_size--; 00700 } 00701 } 00702
void ushell_cmd_append_file | ( | void | ) |
Minimalist file editor to append char to a file.
//! hit ^q to exit and save file //!
Definition at line 1140 of file ushell_task.c.
References ASCII_CR, ASCII_CTRL_Q, ASCII_LF, g_s_arg, MSG_APPEND_WELCOME, MSG_ER_UNKNOWN_FILE, MSG_KO, and SHL_USART.
Referenced by ushell_task().
01140 { 01141 int c_key; 01142 01143 if( g_s_arg[0][0] == 0 ) 01144 return; 01145 01146 // Select file or directory 01147 if( !nav_setcwd( (FS_STRING)g_s_arg[0], TRUE, FALSE ) ) 01148 { 01149 fputs(MSG_ER_UNKNOWN_FILE, stdout); 01150 return; 01151 } 01152 // Open file 01153 if( !file_open(FOPEN_MODE_APPEND) ) 01154 { 01155 fputs(MSG_KO, stdout); 01156 return; 01157 } 01158 01159 // Append file 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; // ^q to quit 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 // Close file 01179 file_close(); 01180 putchar(ASCII_CR);putchar(ASCII_LF); 01181 } 01182
void ushell_cmd_cat | ( | Bool | b_more | ) |
Manage cat command.
b_more | enable the '|more' management |
Definition at line 1029 of file ushell_task.c.
References ASCII_CR, ASCII_LF, g_s_arg, MSG_ER_UNKNOWN_FILE, ushell_more_wait(), and USHELL_NB_LINE.
Referenced by ushell_task().
01029 { 01030 char c_file_character; 01031 U8 n_line=0; 01032 01033 if( g_s_arg[0][0] == 0 ) 01034 return; 01035 01036 // Select file 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 // Open file 01044 file_open(FOPEN_MODE_R); 01045 while (file_eof()==FALSE) 01046 { 01047 // Check 'b_more' option 01048 if( b_more && (n_line >= USHELL_NB_LINE)) 01049 { 01050 n_line = 0; 01051 if( !ushell_more_wait() ) 01052 break; // Stop cat command 01053 } 01054 01055 // Display a character 01056 c_file_character = file_getc(); 01057 putchar( c_file_character ); 01058 01059 // Count the line number 01060 if (c_file_character==ASCII_LF) 01061 n_line++; 01062 } 01063 file_close(); 01064 01065 // Jump in a new line 01066 putchar(ASCII_CR);putchar(ASCII_LF); 01067 } 01068
void ushell_cmd_cd | ( | void | ) |
This function enter in a directory.
Definition at line 999 of file ushell_task.c.
References g_s_arg, MSG_ER_UNKNOWN_FILE, and ushell_path_valid_syntac().
Referenced by ushell_task().
00999 { 01000 if( g_s_arg[0][0] == 0 ) 01001 return; 01002 01003 // Add '\' at the end of path, else the nav_setcwd select the directory but don't enter into. 01004 ushell_path_valid_syntac( g_s_arg[0] ); 01005 01006 // Call file system routine 01007 if( nav_setcwd((FS_STRING)g_s_arg[0],TRUE,FALSE) == FALSE ) 01008 { 01009 fputs(MSG_ER_UNKNOWN_FILE, stdout); 01010 } 01011 } 01012
void ushell_cmd_copy | ( | void | ) |
This function copys a file to other location.
Definition at line 1187 of file ushell_task.c.
References g_mark_index, g_s_arg, MAX_FILE_PATH_LENGTH, MSG_ER_PASTE, MSG_ER_UNKNOWN_FILE, and MSG_KO.
Referenced by ushell_task().
01187 { 01188 Fs_index sav_index; 01189 U8 u8_status_copy; 01190 01191 if( g_s_arg[0][0] == 0 ) 01192 return; 01193 01194 // Save the position 01195 sav_index = nav_getindex(); 01196 01197 // Select source file 01198 if( !nav_setcwd( (FS_STRING)g_s_arg[0], TRUE, FALSE ) ) 01199 { 01200 fputs(MSG_ER_UNKNOWN_FILE, stdout); 01201 return; 01202 } 01203 // Get name of source to be used as same destination name 01204 nav_file_name( (FS_STRING)g_s_arg[0], MAX_FILE_PATH_LENGTH, FS_NAME_GET, TRUE ); 01205 // Mark this selected file like source file 01206 if( !nav_file_copy()) 01207 { 01208 fputs(MSG_KO, stdout); 01209 goto cp_end; 01210 } 01211 01212 // Select destination 01213 if( g_s_arg[1][0]==0 ) 01214 { 01215 // g_s_arg[1] is NULL, using mark 01216 if( !nav_gotoindex(&g_mark_index) ) 01217 goto cp_end; 01218 } 01219 else 01220 { 01221 // g_s_arg[1] exists, then go to this destination 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 // Set the name destination and start paste 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 // Performs copy 01237 do 01238 { 01239 u8_status_copy = nav_file_paste_state( FALSE ); 01240 }while( u8_status_copy == COPY_BUSY ); 01241 01242 // Check status of copy action 01243 if( u8_status_copy == COPY_FAIL ) 01244 { 01245 fputs(MSG_ER_PASTE, stdout); 01246 goto cp_end; 01247 } 01248 01249 cp_end: 01250 // Restore the position 01251 nav_gotoindex(&sav_index); 01252 } 01253
U8 ushell_cmd_decode | ( | void | ) |
decodes full command line into command type and arguments
//! The arguments are storage in g_s_arg global array //!
Definition at line 572 of file ushell_task.c.
References CMD_APPEND, CMD_CAT, CMD_CAT_MORE, CMD_CD, CMD_CP, CMD_DF, CMD_FORMAT, CMD_GOTO_ID, CMD_HELP, CMD_LS, CMD_LS_MORE, CMD_LS_USB, CMD_MKDIR, CMD_MOUNT, CMD_MV, CMD_NB_DRIVE, CMD_NONE, CMD_PERFORM, CMD_RM, CMD_SET_ID, CMD_SPACE, CMD_SYNC, CMD_TOUCH, CMD_UP, CMD_USB_RESUME, CMD_USB_SUSPEND, g_s_arg, g_s_cmd, g_s_cmd_his, g_u8_cmd_size, g_u8_history_pos, g_u8_history_pos_search, MSG_ER_CMD_NOT_FOUND, MSG_PROMPT, STR_APPEND, STR_CAT, STR_CAT_MORE, STR_CD, STR_CP, STR_DF, STR_DISK, STR_FORMAT, STR_GOTO, STR_HELP, STR_LS, STR_LS_MORE, STR_LS_USB, STR_MARK, STR_MKDIR, STR_MOUNT, STR_MV, STR_PERFORM, STR_RM, STR_SPACE, STR_SYNC, STR_TOUCH, STR_UP, STR_USB_RESUME, STR_USB_SUSPEND, USHELL_HISTORY, and USHELL_MAX_NB_ARG.
Referenced by ushell_task().
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 // Command line empty 00580 fputs(MSG_PROMPT, stdout); 00581 return CMD_NONE; 00582 } 00583 00584 // Get command string and Change command to lower case 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 // Get arguments strings 00594 for( u8_j=0; u8_j<USHELL_MAX_NB_ARG; u8_j++ ) 00595 { 00596 u8_i++; // Jump space character 00597 // Check " 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++; // Jump last " 00612 } 00613 g_s_arg[u8_j][u8_k] = 0; 00614 } 00615 00616 // Reset command size and update history 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 // Decode command type 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
void ushell_cmd_format | ( | void | ) |
This function formats a drive.
Definition at line 830 of file ushell_task.c.
References g_s_arg, and MSG_ER_FORMAT.
Referenced by ushell_task().
00830 { 00831 if( g_s_arg[0][0] == 0 ) 00832 return; 00833 00834 // Select drive to format 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
void ushell_cmd_free_space | ( | void | ) |
This function displays the free space of each drive present.
Definition at line 799 of file ushell_task.c.
References g_s_arg.
Referenced by ushell_task().
00799 { 00800 U8 u8_tmp; 00801 Fs_index sav_index = nav_getindex(); // Save current position 00802 for( u8_tmp=0; u8_tmp<nav_drive_nb(); u8_tmp++ ) 00803 { 00804 nav_drive_set( u8_tmp ); // Select drive 00805 if( !nav_partition_mount() ) // Mount drive 00806 continue; 00807 00808 // Display drive letter name (a, b...) 00809 printf("%c: %s\r\n", 'a'+u8_tmp, mem_name(u8_tmp) ); 00810 if( g_s_arg[0][0]=='l' ) // Choose command option 00811 { 00812 // Long and exact fonction 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 // Otherwise use fast command 00820 printf("Free space: %u %%\n\r", nav_partition_freespace_percent() ); 00821 } 00822 } 00823 nav_gotoindex(&sav_index); // Restore position 00824 } 00825
void ushell_cmd_gotoparent | ( | void | ) |
This function go back to parent directory.
Definition at line 1017 of file ushell_task.c.
Referenced by ushell_task().
void ushell_cmd_help | ( | void | ) |
This function display the help.
Definition at line 1073 of file ushell_task.c.
References MSG_HELP.
Referenced by ushell_task().
01073 { 01074 fputs(MSG_HELP, stdout); 01075 } 01076
void ushell_cmd_ls | ( | Bool | b_more | ) |
This function manages the ls command.
b_more | enable the '|more' management when TRUE otherwise no '|more' management |
Definition at line 901 of file ushell_task.c.
References g_s_arg, MAX_FILE_PATH_LENGTH, ushell_more_wait(), USHELL_NB_LINE, and USHELL_SIZE_CMD_LINE.
Referenced by ushell_task().
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 //** Print drive name 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 //** Print directory name 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 //** Check extension filter in extra parameters 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 //** Print files list 00947 printf(" Size Name\n\r"); 00948 // Init loop at the begining of directory 00949 nav_filelist_reset(); 00950 u16_nb_file=0; 00951 u16_nb_dir=0; 00952 last_i=0; 00953 // For each file in list 00954 while( nav_filelist_set(0,FS_FIND_NEXT) ) 00955 { 00956 if(!ext_filter) 00957 { 00958 // No extension filter 00959 if( nav_file_isdir() ) 00960 { 00961 printf("Dir "); 00962 u16_nb_dir++; // count the number of directory 00963 }else{ 00964 printf(" "); 00965 } 00966 } 00967 else 00968 { 00969 // If extension filter then ignore directories 00970 if(nav_file_isdir()) 00971 continue; 00972 // Check extension 00973 if(!nav_file_checkext((FS_STRING)g_s_arg[0])) 00974 continue; 00975 } 00976 u16_nb_file++; // count the total of files (directories and files) 00977 00978 // Check 'more' step 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; // Exit LS command 00984 } 00985 00986 // Display file 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 // Display total number 00991 printf(" %4i Files\r\n", u16_nb_file-u16_nb_dir ); 00992 printf(" %4i Dir\r\n", u16_nb_dir ); 00993 } 00994
void ushell_cmd_mkdir | ( | void | ) |
This function create a directory.
Definition at line 1081 of file ushell_task.c.
References g_s_arg, and MSG_KO.
Referenced by ushell_task().
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
void ushell_cmd_mount | ( | void | ) |
This function mount a drive.
Definition at line 847 of file ushell_task.c.
References g_s_arg, MSG_ER_DRIVE, and MSG_ER_MOUNT.
Referenced by ushell_task().
00847 { 00848 U8 u8_drive_lun; 00849 Fs_index sav_index; 00850 00851 if( g_s_arg[0][0] == 0 ) 00852 return; 00853 00854 // Compute the logical unit number of drive 00855 u8_drive_lun=g_s_arg[0][0]-'a'; 00856 // Check lun number 00857 if( u8_drive_lun >= nav_drive_nb() ) 00858 { 00859 fputs(MSG_ER_DRIVE, stdout); 00860 return; 00861 } 00862 00863 // Mount drive 00864 sav_index = nav_getindex(); // Save previous position 00865 if( nav_drive_set(u8_drive_lun)) 00866 { 00867 if( nav_partition_mount() ) 00868 return; // Here, drive mounted 00869 } 00870 fputs(MSG_ER_MOUNT, stdout); 00871 nav_gotoindex(&sav_index); // Restore previous position 00872 } 00873
void ushell_cmd_nb_drive | ( | void | ) |
This function display all drives present.
Definition at line 784 of file ushell_task.c.
Referenced by ushell_task().
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 // Display drive letter name (a, b...) 00791 printf("%c: %s\r\n", 'a'+u8_tmp, mem_name(u8_tmp) ); 00792 } 00793 } 00794
void ushell_cmd_perform | ( | void | ) |
Perform transfer between two devices.
Definition at line 1603 of file ushell_task.c.
References FILE_ALLOC_SIZE, FS_NAV_ID_COPYFILE, FS_NAV_ID_USHELL_CMD, g_s_arg, ushell_cmd_perform_access(), ushell_cmd_perform_alloc(), ushell_cmd_perform_extaccess(), and ushell_cmd_perform_transfer().
Referenced by ushell_task().
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(); // Save the position 01611 01612 // Alloc a file on each devices 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 // Restore the position 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 // Restore the position 01633 nav_gotoindex(&sav_index); 01634 return; 01635 } 01636 01637 // Transfert data from device 1 to device 2 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 // Delete files allocated 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 // Restore the position 01664 nav_gotoindex(&sav_index); 01665 printf("End of test\n\r"); 01666 return; 01667 } 01668
void ushell_cmd_perform_access | ( | Bool | b_sens_write, | |
Fs_file_segment | seg | |||
) |
Definition at line 1510 of file ushell_task.c.
References g_u32_ushell_pba_hz.
Referenced by ushell_cmd_perform().
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 // Stop access after 8s 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
Fs_file_segment ushell_cmd_perform_alloc | ( | U8 | lun, | |
U16 | size_alloc | |||
) |
Definition at line 1433 of file ushell_task.c.
Referenced by ushell_cmd_perform().
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 // Open file 01453 if( !file_open(FOPEN_MODE_W) ) 01454 { 01455 nav_file_del(FALSE); 01456 return g_recorder_seg; 01457 } 01458 // Define the size of segment to alloc (unit 512B) 01459 // Note: you can alloc more in case of you don't know total size 01460 g_recorder_seg.u16_size = size_alloc; 01461 // Alloc in FAT a cluster list equal or inferior at segment size 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; //** File open and FAT allocated 01469 } 01470
void ushell_cmd_perform_extaccess | ( | Bool | b_sens_write, | |
Fs_file_segment | seg | |||
) |
Definition at line 1550 of file ushell_task.c.
References g_u32_ushell_pba_hz, host_read_10_extram(), host_write_10_extram(), and SIZE_OF_EXT_BUFFER.
Referenced by ushell_cmd_perform().
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); // to align access with usual memory mapping 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 // Stop access after 8s 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
void ushell_cmd_perform_transfer | ( | Fs_file_segment | seg_src, | |
Fs_file_segment | seg_dest | |||
) |
Definition at line 1472 of file ushell_task.c.
References g_u32_ushell_pba_hz.
Referenced by ushell_cmd_perform().
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 // The test time must be inferior at 8s 01504 break; 01505 } 01506 } 01507 } 01508
void ushell_cmd_rename | ( | void | ) |
This function renames a file or a directory.
Definition at line 1258 of file ushell_task.c.
References g_s_arg, MSG_ER_UNKNOWN_FILE, and MSG_KO.
Referenced by ushell_task().
01258 { 01259 if( g_s_arg[0][0] == 0 ) 01260 return; 01261 if( g_s_arg[1][0] == 0 ) 01262 return; 01263 01264 // Select source file 01265 if( !nav_setcwd( (FS_STRING)g_s_arg[0], TRUE, FALSE ) ) 01266 { 01267 fputs(MSG_ER_UNKNOWN_FILE, stdout); 01268 return; 01269 } 01270 // Rename file or directory 01271 if( !nav_file_rename( (FS_STRING)g_s_arg[1] ) ) 01272 { 01273 fputs(MSG_KO, stdout); 01274 return; 01275 } 01276 } 01277
void ushell_cmd_rm | ( | void | ) |
This function delete a file or directory.
Definition at line 1104 of file ushell_task.c.
References g_s_arg, and MSG_KO.
Referenced by ushell_task().
01104 { 01105 U8 u8_i = 0; 01106 Fs_index sav_index; 01107 01108 if( g_s_arg[0][0] == 0 ) 01109 return; 01110 01111 // Save the position 01112 sav_index = nav_getindex(); 01113 01114 while( 1 ) 01115 { 01116 // Restore the position 01117 nav_gotoindex(&sav_index); 01118 // Select file or directory 01119 if( !nav_setcwd( (FS_STRING)g_s_arg[0], TRUE, FALSE ) ) 01120 break; 01121 // Delete file or directory 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
Bool ushell_cmd_scan | ( | void | ) |
Get the full command line to be interpreted.
Definition at line 458 of file ushell_task.c.
References ASCII_BKSPACE, ASCII_CR, ASCII_ESCAPE, ASCII_LF, g_s_cmd_his, g_u8_cmd_size, g_u8_escape_sequence, g_u8_history_pos, SHL_USART, ushell_clean_cmd_line(), ushell_history_display(), ushell_history_down(), ushell_history_up(), and USHELL_SIZE_CMD_LINE.
Referenced by ushell_task().
00459 { 00460 int c_key; 00461 00462 // Something new of the UART ? 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 //** Decode escape sequence 00472 if( 1 == g_u8_escape_sequence ) 00473 { 00474 if( 0x5B != c_key ) 00475 { 00476 g_u8_escape_sequence=0; 00477 return FALSE; // Escape sequence cancel 00478 } 00479 g_u8_escape_sequence=2; 00480 } 00481 else 00482 { 00483 // Decode value of the sequence 00484 switch (c_key) 00485 { 00486 /* 00487 Note: OVERRUN error on USART with an RTOS and USART without interrupt management 00488 If you want support "Escape sequence", then you have to implement USART interrupt management 00489 case 0x41: // UP command 00490 ushell_clean_cmd_line(); 00491 ushell_history_up(); 00492 ushell_history_display(); 00493 break; 00494 case 0x42: // DOWN command 00495 ushell_clean_cmd_line(); 00496 ushell_history_down(); 00497 ushell_history_display(); 00498 break; 00499 */ 00500 default: // Ignore other command 00501 break; 00502 } 00503 g_u8_escape_sequence=0; // End of Escape sequence 00504 } 00505 return FALSE; 00506 } 00507 00508 //** Normal sequence 00509 switch (c_key) 00510 { 00511 //** Command validation 00512 case ASCII_CR: 00513 putchar(ASCII_CR); // Echo 00514 putchar(ASCII_LF); // Add new line flag 00515 g_s_cmd_his[g_u8_history_pos][g_u8_cmd_size]=0; // Add NULL terminator at the end of command line 00516 return TRUE; 00517 00518 //** Enter in escape sequence 00519 case ASCII_ESCAPE: 00520 g_u8_escape_sequence=1; 00521 break; 00522 00523 //** backspace 00524 case ASCII_BKSPACE: 00525 if(g_u8_cmd_size>0) // Beginning of line ? 00526 { 00527 // Remove the last character on terminal 00528 putchar(ASCII_BKSPACE); // Send a backspace to go in previous character 00529 putchar(' '); // Send a space to erase previous character 00530 putchar(ASCII_BKSPACE); // Send a backspace to go in new end position (=previous character position) 00531 // Remove the last character on cmd line buffer 00532 g_u8_cmd_size--; 00533 } 00534 break; 00535 00536 // History management 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 //** Other char 00549 default: 00550 if( (0x1F<c_key) && (c_key<0x7F) && (USHELL_SIZE_CMD_LINE!=g_u8_cmd_size) ) 00551 { 00552 // Accept char 00553 putchar(c_key); // Echo 00554 g_s_cmd_his[g_u8_history_pos][g_u8_cmd_size++] = c_key; // append to cmd line 00555 } 00556 break; 00557 } 00558 return FALSE; 00559 } 00560
void ushell_cmd_space | ( | void | ) |
This function displays the disk space of current drive.
Definition at line 878 of file ushell_task.c.
Referenced by ushell_task().
00878 { 00879 U32 u32_space; 00880 // Display drive letter name (a, b...) 00881 fputs( mem_name(nav_drive_get()), stdout); 00882 putchar(' '); 00883 putchar( nav_drive_get()+'a'); 00884 // Otherwise use fast command 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
Bool ushell_cmd_sync | ( | void | ) |
Synchronize a path with an other path.
Definition at line 1284 of file ushell_task.c.
References FS_NAV_ID_COPYFILE, FS_NAV_ID_USHELL_CMD, g_s_arg, ushell_path_valid_syntac(), and USHELL_SIZE_CMD_LINE.
Referenced by ushell_task().
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 // Add '\' at the end of path, else the nav_setcwd select the directory but don't enter into. 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(); // Save the position 01298 01299 // Select source directory in COPYFILE navigator handle 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 // Select destination directory in USHELL navigator handle 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 // loop to scan and create ALL folders and files 01314 while(1) 01315 { 01316 while(1) 01317 { 01318 // Loop to Search files or directories 01319 // Reselect Source 01320 nav_select( FS_NAV_ID_COPYFILE ); 01321 if( nav_filelist_set( 0 , FS_FIND_NEXT ) ) 01322 break; // a next file and directory is found 01323 01324 // No other dir or file in current dir then go to parent dir on Source and Destination disk 01325 if( 0 == u8_folder_level ) 01326 { 01327 // end of update folder 01328 //********* END OF COPY ************** 01329 goto ushell_cmd_sync_finish; 01330 } 01331 01332 printf("Go to parent\n\r"); 01333 // Remark, nav_dir_gotoparent() routine go to in parent dir and select the children dir in list 01334 u8_folder_level--; 01335 if( !nav_dir_gotoparent() ) 01336 goto ushell_cmd_sync_error; 01337 // Select Destination navigator and go to the same dir of Source 01338 nav_select( FS_NAV_ID_USHELL_CMD ); 01339 if( !nav_dir_gotoparent() ) 01340 goto ushell_cmd_sync_error; 01341 } // end of while (1) 01342 01343 if( nav_file_isdir()) 01344 { 01345 printf("Dir found - create dir: "); 01346 //** here, a new directory is found and is selected 01347 // Get name of current selection (= dir name on Source) 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 // Enter in dir (on Source) 01351 if( !nav_dir_cd()) 01352 goto ushell_cmd_sync_error; 01353 u8_folder_level++; 01354 // Select Destination disk 01355 nav_select( FS_NAV_ID_USHELL_CMD ); 01356 // Create folder in Destination disk 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 // here, error the name exist 01364 } 01365 // Here the navigator have selected the folder on Destination 01366 if( !nav_dir_cd()) 01367 { 01368 if( FS_ERR_NO_DIR == fs_g_status ) 01369 { 01370 // FYC -> Copy impossible, because a file have the same name of folder 01371 } 01372 goto ushell_cmd_sync_error; 01373 } 01374 // here, the folder is created and the navigatorS is entered in this dir 01375 } 01376 else 01377 { 01378 printf("File found - copy file: "); 01379 //** here, a new file is found and is selected 01380 // Get name of current selection (= file name on Source) 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 // Paste file in current dir of Destination disk 01389 nav_select( FS_NAV_ID_USHELL_CMD ); 01390 while( !nav_file_paste_start( (FS_STRING)g_s_arg[0] ) ) 01391 { 01392 // Error 01393 if( fs_g_status != FS_ERR_FILE_EXIST ) 01394 goto ushell_cmd_sync_error; 01395 // File exists then deletes this one 01396 printf("File exists then deletes this one.\n\r"); 01397 if( !nav_file_del( TRUE ) ) 01398 goto ushell_cmd_sync_error; 01399 // here, retry PASTE 01400 } 01401 // Copy running 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 } // if dir OR file 01412 } // end of first while(1) 01413 01414 ushell_cmd_sync_error: 01415 // Restore the position 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 // Restore the position 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
void ushell_cmd_touch | ( | void | ) |
This function create a file.
Definition at line 1093 of file ushell_task.c.
References g_s_arg.
Referenced by ushell_task().
01093 { 01094 if( g_s_arg[0][0] == 0 ) 01095 return; 01096 01097 nav_file_create((FS_STRING)g_s_arg[0]); 01098 } 01099
void ushell_cmdusb_ls | ( | void | ) |
In host mode, display basic lowlevel information about the device connected.
Definition at line 1699 of file ushell_task.c.
References ASCII_CR, ASCII_LF, MSG_BUS_POWERED, MSG_DEVICE_FULL_SPEED, MSG_DEVICE_HIGH_SPEED, MSG_DEVICE_LOW_SPEED, MSG_NO_DEVICE, MSG_REMOTE_WAKEUP_KO, MSG_SELF_POWERED, and MSG_USB_SUSPENDED.
Referenced by ushell_task().
01699 { 01700 U8 i,j; 01701 01702 // Check USB host status 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
void ushell_cmdusb_resume | ( | void | ) |
In host mode, resume host from suspend mode.
Definition at line 1766 of file ushell_task.c.
References MSG_NO_DEVICE.
Referenced by ushell_task().
01766 { 01767 if( !Is_host_suspended() ) 01768 { 01769 fputs(MSG_NO_DEVICE, stdout); 01770 } 01771 Host_request_resume(); 01772 } 01773
void ushell_cmdusb_suspend | ( | void | ) |
In host mode, set host in suspend mode.
Definition at line 1755 of file ushell_task.c.
References MSG_NO_DEVICE.
Referenced by ushell_task().
01755 { 01756 if( !Is_host_ready() ) 01757 { 01758 fputs(MSG_NO_DEVICE, stdout); 01759 } 01760 Host_request_suspend(); 01761 } 01762
void ushell_history_display | ( | void | ) |
Displays the current history.
Definition at line 750 of file ushell_task.c.
References g_s_cmd_his, g_u8_cmd_size, g_u8_history_pos, and g_u8_history_pos_search.
Referenced by ushell_cmd_scan().
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
void ushell_history_down | ( | void | ) |
Selects the next command in history list.
Definition at line 729 of file ushell_task.c.
References g_u8_history_pos, g_u8_history_pos_search, and USHELL_HISTORY.
Referenced by ushell_cmd_scan(), and ushell_history_up().
00729 { 00730 if( g_u8_history_pos_search == g_u8_history_pos ) 00731 return; // End of history list 00732 if( g_u8_history_pos == 0 ) 00733 { 00734 if( (USHELL_HISTORY-1) == g_u8_history_pos_search ) 00735 return; // End of history list 00736 g_u8_history_pos_search++; 00737 }else{ 00738 if( (g_u8_history_pos_search+1) == g_u8_history_pos ) 00739 return; // End of history list 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
void ushell_history_up | ( | void | ) |
Selects the previous command in history list.
Definition at line 707 of file ushell_task.c.
References g_s_cmd_his, g_u8_history_pos, g_u8_history_pos_search, USHELL_HISTORY, and ushell_history_down().
Referenced by ushell_cmd_scan().
00707 { 00708 if( g_u8_history_pos_search == 0 ) 00709 { 00710 if( (USHELL_HISTORY-1) == g_u8_history_pos ) 00711 return; // End of history list 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; // End of history list 00716 g_u8_history_pos_search--; 00717 } 00718 if( 0 == g_s_cmd_his[g_u8_history_pos_search][0] ) 00719 { 00720 // History empty then go to previous selection 00721 ushell_history_down(); 00722 } 00723 } 00724
Bool ushell_more_wait | ( | void | ) |
This function wait a key press.
Definition at line 767 of file ushell_task.c.
References SHL_USART.
Referenced by ushell_cmd_cat(), and ushell_cmd_ls().
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
void ushell_path_valid_syntac | ( | char * | path | ) |
Appends the '\' char at the end of path.
Definition at line 1675 of file ushell_task.c.
References MAX_FILE_PATH_LENGTH.
Referenced by ushell_cmd_cd(), and ushell_cmd_sync().
01675 { 01676 U8 u8_tmp; 01677 01678 // Compute size of substitute 01679 for( u8_tmp=0; u8_tmp<MAX_FILE_PATH_LENGTH; u8_tmp++ ) 01680 { 01681 if( path[u8_tmp]==0) 01682 break; 01683 } 01684 // Append the '\' char for the nav_setcwd to enter the found directory 01685 if ( path[u8_tmp-1] != '\\') 01686 { 01687 path[u8_tmp]='\\'; 01688 path[u8_tmp+1]=0; 01689 } 01690 } 01691
void ushell_task | ( | void * | pvParameters | ) |
Entry point of the explorer task management.
This function performs uShell decoding to access file-system functions.
pvParameters | Unused. |
Definition at line 258 of file ushell_task.c.
References CMD_APPEND, CMD_CAT, CMD_CAT_MORE, CMD_CD, CMD_CP, CMD_DF, CMD_FORMAT, CMD_GOTO_ID, CMD_HELP, CMD_LS, CMD_LS_MORE, CMD_LS_USB, CMD_MKDIR, CMD_MOUNT, CMD_MV, CMD_NB_DRIVE, CMD_PERFORM, CMD_RM, CMD_SET_ID, CMD_SPACE, CMD_SYNC, CMD_TOUCH, CMD_UP, CMD_USB_RESUME, CMD_USB_SUSPEND, configTSK_USHELL_PERIOD, FS_NAV_ID_USHELL_CMD, g_b_ushell_task_run, g_mark_index, MSG_ER_CMD_NOT_FOUND, MSG_EXIT, MSG_PROMPT, MSG_WELCOME, ushell_cmd_append_file(), ushell_cmd_cat(), ushell_cmd_cd(), ushell_cmd_copy(), ushell_cmd_decode(), ushell_cmd_format(), ushell_cmd_free_space(), ushell_cmd_gotoparent(), ushell_cmd_help(), ushell_cmd_ls(), ushell_cmd_mkdir(), ushell_cmd_mount(), ushell_cmd_nb_drive(), ushell_cmd_perform(), ushell_cmd_rename(), ushell_cmd_rm(), ushell_cmd_scan(), ushell_cmd_space(), ushell_cmd_sync(), ushell_cmd_touch(), ushell_cmdusb_ls(), ushell_cmdusb_resume(), and ushell_cmdusb_suspend().
Referenced by main(), and ushell_task_init().
00266 { 00267 00268 #ifdef FREERTOS_USED 00269 //** Inifinit loop for RTOS because it is a RTOS task 00270 portTickType xLastWakeTime; 00271 00272 xLastWakeTime = xTaskGetTickCount(); 00273 while (TRUE) 00274 { 00275 vTaskDelayUntil(&xLastWakeTime, configTSK_USHELL_PERIOD); 00276 #else 00277 //** No loop with the basic scheduler 00278 { 00279 #endif // FREERTOS_USED 00280 00281 00282 //** Check the USB mode and autorize/unautorize ushell 00283 if(!g_b_ushell_task_run) 00284 { 00285 if( Is_usb_id_device() ) 00286 #ifdef FREERTOS_USED 00287 continue; // Continue in the RTOS task 00288 #else 00289 return; // Exit of the task scheduled 00290 #endif 00291 g_b_ushell_task_run = TRUE; 00292 // Display shell startup 00293 fputs(MSG_WELCOME, stdout); 00294 ushell_cmd_nb_drive(); 00295 fputs(MSG_PROMPT, stdout); 00296 00297 // Reset the embedded FS on ushell navigator and on first drive 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; // Continue in the RTOS task 00309 #else 00310 return; // Exit of the task scheduled 00311 #endif 00312 } 00313 } 00314 00315 //** Scan shell command 00316 if( !ushell_cmd_scan() ) 00317 #ifdef FREERTOS_USED 00318 continue; // Continue in the RTOS task 00319 #else 00320 return; // Exit of the task scheduled 00321 #endif 00322 00323 //** Command ready then decode and execute this one 00324 switch( ushell_cmd_decode() ) 00325 { 00326 // Displays number of drives 00327 case CMD_NB_DRIVE: 00328 ushell_cmd_nb_drive(); 00329 break; 00330 00331 // Displays free space information for all connected drives 00332 case CMD_DF: 00333 ushell_cmd_free_space(); 00334 break; 00335 00336 // Formats disk 00337 case CMD_FORMAT: 00338 ushell_cmd_format(); 00339 break; 00340 00341 // Mounts a drive (e.g. "b:") 00342 case CMD_MOUNT: 00343 ushell_cmd_mount(); 00344 break; 00345 00346 // Displays the space information for current drive 00347 case CMD_SPACE: 00348 ushell_cmd_space(); 00349 break; 00350 00351 // Lists the files present in current directory (e.g. "ls") 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 // Enters in a directory (e.g. "cd folder_toto") 00360 case CMD_CD: 00361 ushell_cmd_cd(); 00362 break; 00363 00364 // Enters in parent directory ("cd..") 00365 case CMD_UP: 00366 ushell_cmd_gotoparent(); 00367 break; 00368 00369 // Displays a text file 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 // Displays the help 00378 case CMD_HELP: 00379 ushell_cmd_help(); 00380 break; 00381 00382 // Creates directory 00383 case CMD_MKDIR: 00384 ushell_cmd_mkdir(); 00385 break; 00386 00387 // Creates file 00388 case CMD_TOUCH: 00389 ushell_cmd_touch(); 00390 break; 00391 00392 // Deletes files or directories 00393 case CMD_RM: 00394 ushell_cmd_rm(); 00395 break; 00396 00397 // Appends char to selected file 00398 case CMD_APPEND: 00399 ushell_cmd_append_file(); 00400 break; 00401 00402 // Index routines (= specific shortcut from ATMEL FileSystem) 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 // Copys file to other location 00411 case CMD_CP: 00412 ushell_cmd_copy(); 00413 break; 00414 00415 // Renames file 00416 case CMD_MV: 00417 ushell_cmd_rename(); 00418 break; 00419 00420 // Synchronize folders 00421 case CMD_SYNC: 00422 ushell_cmd_sync(); 00423 break; 00424 00425 case CMD_PERFORM: 00426 ushell_cmd_perform(); 00427 break; 00428 00429 // USB commands 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 // Unknown command 00443 default: 00444 fputs(MSG_ER_CMD_NOT_FOUND, stdout); 00445 break; 00446 } 00447 00448 fputs(MSG_PROMPT, stdout); 00449 00450 } 00451 }
void ushell_task_init | ( | U32 | pba_hz | ) |
This function initializes the hardware/software ressources required for ushell task.
Definition at line 191 of file ushell_task.c.
References configTSK_USHELL_NAME, configTSK_USHELL_PRIORITY, configTSK_USHELL_STACK_SIZE, g_b_ushell_task_run, g_s_cmd_his, g_u32_ushell_pba_hz, MSG_EXIT, SHL_USART, SHL_USART_BAUDRATE, SHL_USART_RX_FUNCTION, SHL_USART_RX_PIN, SHL_USART_TX_FUNCTION, SHL_USART_TX_PIN, USHELL_HISTORY, and ushell_task().
Referenced by main().
00192 { 00193 U8 u8_i; 00194 00195 //** Initialize the USART used by uShell with the configured parameters 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 //** Configure standard I/O streams as unbuffered. 00225 #if (defined __GNUC__) 00226 setbuf(stdin, NULL); 00227 #endif 00228 setbuf(stdout, NULL); 00229 00230 // Set default state of ushell 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; // Set end of line for all cmd line history 00234 } 00235 00236 fputs(MSG_EXIT, stdout ); 00237 00238 g_u32_ushell_pba_hz = pba_hz; // Save value to manage a time counter during perform command 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 }
Bool g_b_ushell_task_run = FALSE [static] |
Fs_index g_mark_index [static] |
char g_s_arg[USHELL_MAX_NB_ARG][USHELL_SIZE_CMD_LINE] [static] |
Definition at line 149 of file ushell_task.c.
Referenced by ushell_cmd_append_file(), ushell_cmd_cat(), ushell_cmd_cd(), ushell_cmd_copy(), ushell_cmd_decode(), ushell_cmd_format(), ushell_cmd_free_space(), ushell_cmd_ls(), ushell_cmd_mkdir(), ushell_cmd_mount(), ushell_cmd_perform(), ushell_cmd_rename(), ushell_cmd_rm(), ushell_cmd_sync(), and ushell_cmd_touch().
char g_s_cmd[USHELL_SIZE_CMD_LINE] [static] |
char g_s_cmd_his[USHELL_HISTORY][USHELL_SIZE_CMD_LINE] [static] |
Definition at line 147 of file ushell_task.c.
Referenced by ushell_cmd_decode(), ushell_cmd_scan(), ushell_history_display(), ushell_history_up(), and ushell_task_init().
U32 g_u32_ushell_pba_hz [static] |
Definition at line 140 of file ushell_task.c.
Referenced by ushell_cmd_perform_access(), ushell_cmd_perform_extaccess(), ushell_cmd_perform_transfer(), and ushell_task_init().
U8 g_u8_cmd_size = 0 [static] |
Definition at line 144 of file ushell_task.c.
Referenced by ushell_clean_cmd_line(), ushell_cmd_decode(), ushell_cmd_scan(), and ushell_history_display().
U8 g_u8_escape_sequence = 0 [static] |
U8 g_u8_history_pos = 0 [static] |
Definition at line 145 of file ushell_task.c.
Referenced by ushell_cmd_decode(), ushell_cmd_scan(), ushell_history_display(), ushell_history_down(), and ushell_history_up().
U8 g_u8_history_pos_search = 0 [static] |
Definition at line 146 of file ushell_task.c.
Referenced by ushell_cmd_decode(), ushell_history_display(), ushell_history_down(), and ushell_history_up().
U8 u8_ext_buffer[512 *SIZE_OF_EXT_BUFFER] [static] |
Definition at line 1548 of file ushell_task.c.