00001
00125
00126
00127 #include <string.h>
00128 #include "compiler.h"
00129 #include "preprocessor.h"
00130 #include "board.h"
00131 #include "print_funcs.h"
00132 #include "ctrl_access.h"
00133 #include "power_clocks_lib.h"
00134 #include "gpio.h"
00135 #include "usart.h"
00136 #include "spi.h"
00137 #include "conf_at45dbx.h"
00138 #include "fat.h"
00139 #include "file.h"
00140 #include "navigation.h"
00141
00142
00143
00144
00147
00148 #if BOARD == EVK1100
00149 # define SHL_USART (&AVR32_USART1)
00150 # define SHL_USART_RX_PIN AVR32_USART1_RXD_0_0_PIN
00151 # define SHL_USART_RX_FUNCTION AVR32_USART1_RXD_0_0_FUNCTION
00152 # define SHL_USART_TX_PIN AVR32_USART1_TXD_0_0_PIN
00153 # define SHL_USART_TX_FUNCTION AVR32_USART1_TXD_0_0_FUNCTION
00154 # define SHL_USART_BAUDRATE 57600
00155 #elif BOARD == EVK1101
00156 # define SHL_USART (&AVR32_USART1)
00157 # define SHL_USART_RX_PIN AVR32_USART1_RXD_0_0_PIN
00158 # define SHL_USART_RX_FUNCTION AVR32_USART1_RXD_0_0_FUNCTION
00159 # define SHL_USART_TX_PIN AVR32_USART1_TXD_0_0_PIN
00160 # define SHL_USART_TX_FUNCTION AVR32_USART1_TXD_0_0_FUNCTION
00161 # define SHL_USART_BAUDRATE 57600
00162 #elif BOARD == EVK1104
00163 # define SHL_USART (&AVR32_USART1)
00164 # define SHL_USART_RX_PIN AVR32_USART1_RXD_0_0_PIN
00165 # define SHL_USART_RX_FUNCTION AVR32_USART1_RXD_0_0_FUNCTION
00166 # define SHL_USART_TX_PIN AVR32_USART1_TXD_0_0_PIN
00167 # define SHL_USART_TX_FUNCTION AVR32_USART1_TXD_0_0_FUNCTION
00168 # define SHL_USART_BAUDRATE 57600
00169 #elif BOARD == EVK1105
00170 # define SHL_USART (&AVR32_USART0)
00171 # define SHL_USART_RX_PIN AVR32_USART0_RXD_0_0_PIN
00172 # define SHL_USART_RX_FUNCTION AVR32_USART0_RXD_0_0_FUNCTION
00173 # define SHL_USART_TX_PIN AVR32_USART0_TXD_0_0_PIN
00174 # define SHL_USART_TX_FUNCTION AVR32_USART0_TXD_0_0_FUNCTION
00175 # define SHL_USART_BAUDRATE 57600
00176 #elif BOARD == UC3C_EK
00177 # define SHL_USART (&AVR32_USART2)
00178 # define SHL_USART_RX_PIN AVR32_USART2_RXD_0_1_PIN
00179 # define SHL_USART_RX_FUNCTION AVR32_USART2_RXD_0_1_FUNCTION
00180 # define SHL_USART_TX_PIN AVR32_USART2_TXD_0_1_PIN
00181 # define SHL_USART_TX_FUNCTION AVR32_USART2_TXD_0_1_FUNCTION
00182 # define SHL_USART_BAUDRATE 57600
00183 #endif
00184
00185 #if !defined(SHL_USART) || \
00186 !defined(SHL_USART_RX_PIN) || \
00187 !defined(SHL_USART_RX_FUNCTION) || \
00188 !defined(SHL_USART_TX_PIN) || \
00189 !defined(SHL_USART_TX_FUNCTION) || \
00190 !defined(SHL_USART_BAUDRATE)
00191 # error The USART configuration to use in this example on your board is missing.
00192 #endif
00194
00195
00197
00198 #define CMD_NONE 0x00
00199 #define CMD_MOUNT 0x01
00200 #define CMD_LS 0x02
00201 #define CMD_CD 0x03
00202 #define CMD_CAT 0x04
00203 #define CMD_HELP 0x05
00204 #define CMD_MKDIR 0x06
00205 #define CMD_TOUCH 0x07
00206 #define CMD_RM 0x08
00207 #define CMD_APPEND 0x09
00208 #define CMD_NB_DRIVE 0x0A
00209 #define CMD_SET_ID 0x0B
00210 #define CMD_GOTO_ID 0x0C
00211 #define CMD_CP 0x0D
00212 #define CMD_DF 0x0E
00213 #define CMD_MV 0x0F
00214 #define CMD_FORMAT 0x10
00215 #define CMD_FAT 0x11
00216 #define CMD_FORMAT32 0x12
00218
00219
00221
00222 #define CR '\r'
00223 #define LF '\n'
00224 #define CTRL_C 0x03
00225 #define CTRL_Q 0x11
00226 #define BKSPACE_CHAR '\b'
00227 #define ABORT_CHAR CTRL_C
00228 #define QUIT_APPEND CTRL_Q
00229 #define HISTORY_CHAR '!'
00231
00232
00234
00235 #define STR_CD "cd"
00236 #define STR_MOUNT "mount"
00237 #define STR_CP "cp"
00238 #define STR_LS "ls"
00239 #define STR_RM "rm"
00240 #define STR_DF "df"
00241 #define STR_MKDIR "mkdir"
00242 #define STR_TOUCH "touch"
00243 #define STR_APPEND "append"
00244 #define STR_CAT "cat"
00245 #define STR_DISK "disk"
00246 #define STR_MARK "mark"
00247 #define STR_GOTO "goto"
00248 #define STR_MV "mv"
00249 #define STR_A "a:"
00250 #define STR_B "b:"
00251 #define STR_C "c:"
00252 #define STR_D "d:"
00253 #define STR_HELP "help"
00254 #define STR_FORMAT "format"
00255 #define STR_FORMAT32 "format32"
00256 #define STR_FAT "fat"
00258
00259
00261
00262 #define MSG_PROMPT "$>"
00263 #define MSG_WELCOME "\n" \
00264 "-------------------------\n" \
00265 " ATMEL AVR32 Shell\n" \
00266 "-------------------------\n"
00267 #define MSG_ER_CMD_NOT_FOUND "Command not found\n"
00268 #define MSG_ER_MOUNT "Unable to mount drive\n"
00269 #define MSG_ER_DRIVE "Drive does not exist\n"
00270 #define MSG_ER_RM "Can not erase; if the name is a directory, check it is empty\n"
00271 #define MSG_ER_UNKNOWN_FILE "Unknown file\n"
00272 #define MSG_ER_MV "Error during move\n"
00273 #define MSG_ER_FORMAT "Format fails\n"
00274 #define MSG_APPEND_WELCOME "\nSimple text editor, enter char to append, ^q to exit and save\n"
00275 #define MSG_HELP "Commands summary\n" \
00276 " a:, b:... goto selected drive mount disk(a, b...)\n" \
00277 " cd dirname ls\n" \
00278 " mkdir dirname cat filename\n" \
00279 " touch filename disk: get number of drives\n" \
00280 " append filename goto: goto bookmark\n" \
00281 " mark: bookmark current directory df: get free space information\n" \
00282 " cp filename: copy filename to bookmark fat: get FAT type for current drive\n" \
00283 " rm filename: erase file or EMPTY directory format drivename, with drivename: a, b...\n" \
00284 " mv src dst: move file or directory format32 drivename, with drivename: a, b...\n" \
00285 " help\n"
00287
00288
00289
00291 static Bool cmd;
00293 static U8 cmd_type;
00295 static Bool first_ls;
00297 static U8 i_str = 0;
00298
00300 static char cmd_str[10 + 2 * MAX_FILE_PATH_LENGTH];
00302 static char par_str1[MAX_FILE_PATH_LENGTH];
00304 static char par_str2[MAX_FILE_PATH_LENGTH];
00305
00307 static char str_buff[MAX_FILE_PATH_LENGTH];
00308
00309
00310
00311
00317 static void fat_example_parse_cmd(void)
00318 {
00319 U8 i, j;
00320
00321
00322 for (i = 0; cmd_str[i] != ' ' && i < i_str; i++);
00323
00324 if (i)
00325 {
00326 cmd = TRUE;
00327
00328 j = cmd_str[i];
00329
00330 cmd_str[i] = '\0';
00331 par_str1[0] = '\0';
00332 par_str2[0] = '\0';
00333
00334
00335 if (!strcmp(cmd_str, STR_CD )) cmd_type = CMD_CD;
00336 else if (!strcmp(cmd_str, STR_MOUNT )) cmd_type = CMD_MOUNT;
00337 else if (!strcmp(cmd_str, STR_FAT )) cmd_type = CMD_FAT;
00338 else if (!strcmp(cmd_str, STR_CP )) cmd_type = CMD_CP;
00339 else if (!strcmp(cmd_str, STR_LS )) cmd_type = CMD_LS;
00340 else if (!strcmp(cmd_str, STR_RM )) cmd_type = CMD_RM;
00341 else if (!strcmp(cmd_str, STR_DF )) cmd_type = CMD_DF;
00342 else if (!strcmp(cmd_str, STR_MKDIR )) cmd_type = CMD_MKDIR;
00343 else if (!strcmp(cmd_str, STR_TOUCH )) cmd_type = CMD_TOUCH;
00344 else if (!strcmp(cmd_str, STR_APPEND )) cmd_type = CMD_APPEND;
00345 else if (!strcmp(cmd_str, STR_CAT )) cmd_type = CMD_CAT;
00346 else if (!strcmp(cmd_str, STR_DISK )) cmd_type = CMD_NB_DRIVE;
00347 else if (!strcmp(cmd_str, STR_MARK )) cmd_type = CMD_SET_ID;
00348 else if (!strcmp(cmd_str, STR_GOTO )) cmd_type = CMD_GOTO_ID;
00349 else if (!strcmp(cmd_str, STR_MV )) cmd_type = CMD_MV;
00350 else if (!strcmp(cmd_str, STR_A )) cmd_type = CMD_MOUNT, par_str1[0] = 'a', par_str1[1] = '\0';
00351 else if (!strcmp(cmd_str, STR_B )) cmd_type = CMD_MOUNT, par_str1[0] = 'b', par_str1[1] = '\0';
00352 else if (!strcmp(cmd_str, STR_C )) cmd_type = CMD_MOUNT, par_str1[0] = 'c', par_str1[1] = '\0';
00353 else if (!strcmp(cmd_str, STR_D )) cmd_type = CMD_MOUNT, par_str1[0] = 'd', par_str1[1] = '\0';
00354 else if (!strcmp(cmd_str, STR_HELP )) cmd_type = CMD_HELP;
00355 else if (!strcmp(cmd_str, STR_FORMAT )) cmd_type = CMD_FORMAT;
00356 else if (!strcmp(cmd_str, STR_FORMAT32)) cmd_type = CMD_FORMAT32;
00357 else
00358 {
00359
00360 print(SHL_USART, MSG_ER_CMD_NOT_FOUND);
00361 cmd = FALSE;
00362 }
00363
00364 cmd_str[i] = j;
00365 }
00366
00367 if (!cmd)
00368 {
00369 print(SHL_USART, MSG_PROMPT);
00370 return;
00371 }
00372
00373
00374 if (++i < i_str)
00375 {
00376 j = 0;
00377
00378 if (cmd_str[i] == '"')
00379 {
00380 i++;
00381 for (; cmd_str[i] != '"' && i < i_str; i++, j++)
00382 {
00383 par_str1[j] = cmd_str[i];
00384 }
00385 i++;
00386 }
00387
00388 else
00389 {
00390 for(; cmd_str[i] != ' ' && i < i_str; i++, j++)
00391 {
00392 par_str1[j] = cmd_str[i];
00393 }
00394 }
00395
00396 par_str1[j] = '\0';
00397 }
00398
00399
00400 if (++i < i_str)
00401 {
00402 j = 0;
00403
00404 if (cmd_str[i] == '"')
00405 {
00406 i++;
00407 for (; cmd_str[i] != '"' && i < i_str; i++, j++)
00408 {
00409 par_str2[j] = cmd_str[i];
00410 }
00411 i++;
00412 }
00413
00414 else
00415 {
00416 for (; cmd_str[i] != ' ' && i < i_str; i++, j++)
00417 {
00418 par_str2[j] = cmd_str[i];
00419 }
00420 }
00421
00422 par_str2[j] = '\0';
00423 }
00424 }
00425
00426
00430 static void fat_example_build_cmd(void)
00431 {
00432 int c;
00433
00434
00435 usart_reset_status(SHL_USART);
00436 if (usart_read_char(SHL_USART, &c) == USART_SUCCESS)
00437 {
00438 switch (c)
00439 {
00440 case CR:
00441
00442 print_char(SHL_USART, LF);
00443
00444 cmd_str[i_str] = '\0';
00445
00446 fat_example_parse_cmd();
00447 i_str = 0;
00448 break;
00449
00450 case ABORT_CHAR:
00451
00452 i_str = 0;
00453
00454 print(SHL_USART, "\n" MSG_PROMPT);
00455 break;
00456
00457 case BKSPACE_CHAR:
00458 if (i_str > 0)
00459 {
00460
00461 print(SHL_USART, "\b \b");
00462
00463 i_str--;
00464 }
00465 break;
00466 default:
00467
00468 print_char(SHL_USART, c);
00469
00470 cmd_str[i_str++] = c;
00471 break;
00472 }
00473 }
00474 }
00475
00476
00481 static void fat_example_append_file(void)
00482 {
00483 int c;
00484
00485 print(SHL_USART, MSG_APPEND_WELCOME);
00486
00487
00488 while (TRUE)
00489 {
00490
00491 usart_reset_status(SHL_USART);
00492 if (usart_read_char(SHL_USART, &c) == USART_SUCCESS)
00493 {
00494
00495 if (c != QUIT_APPEND)
00496 {
00497
00498 print_char(SHL_USART, c);
00499
00500 file_putc(c);
00501
00502 if (c == CR)
00503 {
00504
00505 print_char(SHL_USART, LF);
00506
00507 file_putc(LF);
00508 }
00509 }
00510
00511 else
00512 {
00513
00514 break;
00515 }
00516 }
00517 }
00518 }
00519
00520
00525 static void init_shl_rs232(long pba_hz)
00526 {
00527
00528 static const gpio_map_t SHL_USART_GPIO_MAP =
00529 {
00530 {SHL_USART_RX_PIN, SHL_USART_RX_FUNCTION},
00531 {SHL_USART_TX_PIN, SHL_USART_TX_FUNCTION}
00532 };
00533
00534
00535 static const usart_options_t SHL_USART_OPTIONS =
00536 {
00537 .baudrate = SHL_USART_BAUDRATE,
00538 .charlength = 8,
00539 .paritytype = USART_NO_PARITY,
00540 .stopbits = USART_1_STOPBIT,
00541 .channelmode = USART_NORMAL_CHMODE
00542 };
00543
00544
00545 gpio_enable_module(SHL_USART_GPIO_MAP,
00546 sizeof(SHL_USART_GPIO_MAP) / sizeof(SHL_USART_GPIO_MAP[0]));
00547
00548
00549 usart_init_rs232(SHL_USART, &SHL_USART_OPTIONS, pba_hz);
00550 }
00551
00552
00555 static void at45dbx_resources_init(void)
00556 {
00557
00558 static const gpio_map_t AT45DBX_SPI_GPIO_MAP =
00559 {
00560 {AT45DBX_SPI_SCK_PIN, AT45DBX_SPI_SCK_FUNCTION },
00561 {AT45DBX_SPI_MISO_PIN, AT45DBX_SPI_MISO_FUNCTION },
00562 {AT45DBX_SPI_MOSI_PIN, AT45DBX_SPI_MOSI_FUNCTION },
00563 #define AT45DBX_ENABLE_NPCS_PIN(NPCS, unused) \
00564 {AT45DBX_SPI_NPCS##NPCS##_PIN, AT45DBX_SPI_NPCS##NPCS##_FUNCTION}, // Chip Select NPCS.
00565 MREPEAT(AT45DBX_MEM_CNT, AT45DBX_ENABLE_NPCS_PIN, ~)
00566 #undef AT45DBX_ENABLE_NPCS_PIN
00567 };
00568
00569
00570 spi_options_t spiOptions =
00571 {
00572 .reg = AT45DBX_SPI_FIRST_NPCS,
00573 .baudrate = AT45DBX_SPI_MASTER_SPEED,
00574 .bits = AT45DBX_SPI_BITS,
00575 .spck_delay = 0,
00576 .trans_delay = 0,
00577 .stay_act = 1,
00578 .spi_mode = 0,
00579 .modfdis = 1
00580 };
00581
00582
00583 gpio_enable_module(AT45DBX_SPI_GPIO_MAP,
00584 sizeof(AT45DBX_SPI_GPIO_MAP) / sizeof(AT45DBX_SPI_GPIO_MAP[0]));
00585
00586
00587 spi_initMaster(AT45DBX_SPI, &spiOptions);
00588
00589
00590 spi_selectionMode(AT45DBX_SPI, 0, 0, 0);
00591
00592
00593 spi_enable(AT45DBX_SPI);
00594
00595
00596 at45dbx_init(spiOptions, FOSC0);
00597 }
00598
00599
00602 int main(void)
00603 {
00604 U8 i, j;
00605 U16 file_size;
00606 Fs_index sav_index;
00607 static Fs_index mark_index;
00608 const char *part_type;
00609 U32 VarTemp;
00610
00611
00612 pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP);
00613
00614
00615 init_shl_rs232(FOSC0);
00616
00617
00618 at45dbx_resources_init();
00619
00620
00621 print(SHL_USART, MSG_WELCOME "\nMemory ");
00622
00623
00624 if (mem_test_unit_ready(LUN_ID_AT45DBX_MEM) == CTRL_GOOD)
00625 {
00626
00627 mem_read_capacity(LUN_ID_AT45DBX_MEM, &VarTemp);
00628 print(SHL_USART, "OK:\t");
00629 print_ulong(SHL_USART, (VarTemp + 1) >> (20 - FS_SHIFT_B_TO_SECTOR));
00630 print(SHL_USART, " MB\n");
00631 }
00632 else
00633 {
00634
00635 print(SHL_USART, "Not initialized: Check if memory is ready...\n");
00636 }
00637
00638
00639 print(SHL_USART, MSG_PROMPT);
00640
00641
00642 cmd = FALSE;
00643 cmd_type = CMD_NONE;
00644 first_ls = TRUE;
00645
00646 nav_reset();
00647
00648
00649 while (TRUE)
00650 {
00651
00652 if (!cmd)
00653 {
00654 fat_example_build_cmd();
00655 }
00656
00657 else
00658 {
00659 switch (cmd_type)
00660 {
00661
00662 case CMD_MOUNT:
00663
00664 i = par_str1[0] - 'a';
00665
00666 if (i >= nav_drive_nb())
00667 {
00668
00669 print(SHL_USART, MSG_ER_DRIVE);
00670 }
00671 else
00672 {
00673
00674 nav_reset();
00675
00676 nav_drive_set(i);
00677
00678 if (!nav_partition_mount())
00679 {
00680
00681 print(SHL_USART, MSG_ER_MOUNT);
00682
00683 first_ls = TRUE;
00684 }
00685 else
00686 {
00687
00688 first_ls = FALSE;
00689 }
00690 }
00691 break;
00692
00693 case CMD_FAT:
00694
00695 switch (nav_partition_type())
00696 {
00697 case FS_TYPE_FAT_12:
00698
00699 part_type = "Drive uses FAT12\n";
00700 break;
00701 case FS_TYPE_FAT_16:
00702
00703 part_type = "Drive uses FAT16\n";
00704 break;
00705 case FS_TYPE_FAT_32:
00706
00707 part_type = "Drive uses FAT32\n";
00708 break;
00709 default:
00710
00711 part_type = "Drive uses an unknown partition type\n";
00712 break;
00713 }
00714 print(SHL_USART, part_type);
00715 break;
00716
00717 case CMD_LS:
00718
00719 if (nav_drive_get() >= nav_drive_nb() || first_ls)
00720 {
00721 first_ls = FALSE;
00722
00723 nav_reset();
00724
00725 nav_drive_set(nav_drive_nb() - 1);
00726
00727 nav_partition_mount();
00728 }
00729
00730 nav_dir_name((FS_STRING)str_buff, MAX_FILE_PATH_LENGTH);
00731
00732 print(SHL_USART, "\nVolume is ");
00733 print_char(SHL_USART, 'A' + nav_drive_get());
00734 print(SHL_USART, ":\nDir name is ");
00735 print(SHL_USART, str_buff);
00736 print_char(SHL_USART, LF);
00737
00738 if (!nav_filelist_first(FS_DIR))
00739 {
00740
00741 nav_filelist_first(FS_FILE);
00742 }
00743
00744 print(SHL_USART, "\tSize (Bytes)\tName\n");
00745
00746 nav_filelist_reset();
00747
00748 while (nav_filelist_set(0, FS_FIND_NEXT))
00749 {
00750
00751 print(SHL_USART, (nav_file_isdir()) ? "Dir\t" : " \t");
00752 print_ulong(SHL_USART, nav_file_lgt());
00753 print(SHL_USART, "\t\t");
00754 nav_file_name((FS_STRING)str_buff, MAX_FILE_PATH_LENGTH, FS_NAME_GET, TRUE);
00755 print(SHL_USART, str_buff);
00756 print_char(SHL_USART, LF);
00757 }
00758
00759 print_ulong(SHL_USART, nav_filelist_nb(FS_FILE));
00760 print(SHL_USART, " Files\n");
00761
00762 print_ulong(SHL_USART, nav_filelist_nb(FS_DIR));
00763 print(SHL_USART, " Dir\n");
00764 break;
00765
00766 case CMD_CD:
00767
00768 i = strlen(par_str1);
00769
00770 if (par_str1[i - 1] != '/')
00771 {
00772 par_str1[i] = '/';
00773 par_str1[i + 1] = '\0';
00774 }
00775
00776 if (!nav_setcwd((FS_STRING)par_str1, TRUE, FALSE))
00777 {
00778
00779 print(SHL_USART, MSG_ER_UNKNOWN_FILE);
00780 }
00781 break;
00782
00783 case CMD_CAT:
00784
00785 if (!nav_setcwd((FS_STRING)par_str1, TRUE, FALSE))
00786 {
00787
00788 print(SHL_USART, MSG_ER_UNKNOWN_FILE);
00789 }
00790 else
00791 {
00792
00793 file_open(FOPEN_MODE_R);
00794
00795 while (!file_eof())
00796 {
00797
00798 print_char(SHL_USART, file_getc());
00799 }
00800
00801 file_close();
00802 print_char(SHL_USART, LF);
00803 }
00804 break;
00805
00806 case CMD_HELP:
00807
00808 print(SHL_USART, MSG_HELP);
00809 break;
00810
00811 case CMD_MKDIR:
00812
00813 nav_dir_make((FS_STRING)par_str1);
00814 break;
00815
00816 case CMD_TOUCH:
00817
00818 nav_file_create((FS_STRING)par_str1);
00819 break;
00820
00821 case CMD_RM:
00822
00823 sav_index = nav_getindex();
00824
00825 if (!nav_setcwd((FS_STRING)par_str1, TRUE, FALSE))
00826 {
00827
00828 print(SHL_USART, MSG_ER_UNKNOWN_FILE);
00829 }
00830
00831 else if (!nav_file_del(FALSE))
00832 {
00833
00834 print(SHL_USART, MSG_ER_RM);
00835 }
00836
00837 nav_gotoindex(&sav_index);
00838 break;
00839
00840 case CMD_APPEND:
00841
00842 if (!nav_setcwd((FS_STRING)par_str1, TRUE, TRUE))
00843 {
00844
00845 print(SHL_USART, MSG_ER_UNKNOWN_FILE);
00846 }
00847 else
00848 {
00849
00850 file_open(FOPEN_MODE_APPEND);
00851
00852 fat_example_append_file();
00853
00854 file_close();
00855
00856 print_char(SHL_USART, LF);
00857 }
00858 break;
00859
00860 case CMD_NB_DRIVE:
00861
00862 print(SHL_USART, "Nb Drive(s): ");
00863 print_char(SHL_USART, '0' + nav_drive_nb());
00864 print_char(SHL_USART, LF);
00865 break;
00866
00867 case CMD_SET_ID:
00868
00869 mark_index = nav_getindex();
00870 break;
00871
00872 case CMD_GOTO_ID:
00873
00874 nav_gotoindex(&mark_index);
00875 break;
00876
00877 case CMD_CP:
00878
00879 if (!nav_setcwd((FS_STRING)par_str1, TRUE, FALSE))
00880 {
00881
00882 print(SHL_USART, MSG_ER_UNKNOWN_FILE);
00883 }
00884 else
00885 {
00886
00887 nav_file_name((FS_STRING)par_str1, MAX_FILE_PATH_LENGTH, FS_NAME_GET, TRUE);
00888
00889 file_size = nav_file_lgtsector();
00890
00891 nav_file_copy();
00892
00893 sav_index = nav_getindex();
00894
00895 nav_gotoindex(&mark_index);
00896
00897 if (nav_partition_space() > file_size)
00898 {
00899
00900 nav_file_paste_start((FS_STRING)par_str1);
00901
00902 nav_gotoindex(&sav_index);
00903
00904 while (nav_file_paste_state(FALSE) == COPY_BUSY);
00905 }
00906
00907 nav_gotoindex(&sav_index);
00908 }
00909 break;
00910
00911 case CMD_MV:
00912
00913 sav_index = nav_getindex();
00914
00915 if (!nav_setcwd((FS_STRING)par_str1, TRUE, FALSE))
00916 {
00917
00918 print(SHL_USART, MSG_ER_UNKNOWN_FILE);
00919 }
00920
00921 else if (!nav_file_rename((FS_STRING)par_str2))
00922 {
00923
00924 print(SHL_USART, MSG_ER_MV);
00925 }
00926
00927 nav_gotoindex(&sav_index);
00928 break;
00929
00930 case CMD_DF:
00931
00932 sav_index = nav_getindex();
00933
00934 for (i = 0; i < nav_drive_nb(); i++)
00935 {
00936
00937 nav_drive_set(i);
00938
00939 if (nav_partition_mount())
00940 {
00941
00942 print(SHL_USART, mem_name(i));
00943
00944 print(SHL_USART, " (");
00945 print_char(SHL_USART, 'A' + i);
00946 print(SHL_USART, ":) Free Space: ");
00947
00948 print_ulong(SHL_USART, nav_partition_freespace() << FS_SHIFT_B_TO_SECTOR);
00949 print(SHL_USART, " Bytes / ");
00950
00951 print_ulong(SHL_USART, nav_partition_space() << FS_SHIFT_B_TO_SECTOR);
00952 print(SHL_USART, " Bytes\n");
00953 }
00954 }
00955
00956 nav_gotoindex(&sav_index);
00957 break;
00958
00959 case CMD_FORMAT:
00960
00961 i = par_str1[0] - 'a';
00962
00963 if (i >= nav_drive_nb())
00964 {
00965
00966 print(SHL_USART, MSG_ER_DRIVE);
00967 }
00968 else
00969 {
00970
00971 j = nav_drive_get();
00972
00973 nav_drive_set(i);
00974
00975 if (!nav_drive_format(FS_FORMAT_DEFAULT))
00976 {
00977
00978 print(SHL_USART, MSG_ER_FORMAT);
00979
00980 nav_drive_set(j);
00981 }
00982
00983 else if (i == j)
00984 {
00985
00986 nav_reset();
00987
00988 nav_drive_set(j);
00989
00990 if (!nav_partition_mount())
00991 {
00992
00993 print(SHL_USART, MSG_ER_MOUNT);
00994
00995 first_ls = TRUE;
00996 }
00997 else
00998 {
00999
01000 first_ls = FALSE;
01001 }
01002 }
01003
01004 else nav_drive_set(j);
01005 }
01006 break;
01007
01008 case CMD_FORMAT32:
01009
01010 i = par_str1[0] - 'a';
01011
01012 if (i >= nav_drive_nb())
01013 {
01014
01015 print(SHL_USART, MSG_ER_DRIVE);
01016 }
01017 else
01018 {
01019
01020 j = nav_drive_get();
01021
01022 nav_drive_set(i);
01023
01024 if (!nav_drive_format(FS_FORMAT_FAT32))
01025 {
01026
01027 print(SHL_USART, MSG_ER_FORMAT);
01028
01029 nav_drive_set(j);
01030 }
01031
01032 else if (i == j)
01033 {
01034
01035 nav_reset();
01036
01037 nav_drive_set(j);
01038
01039 if (!nav_partition_mount())
01040 {
01041
01042 print(SHL_USART, MSG_ER_MOUNT);
01043
01044 first_ls = TRUE;
01045 }
01046 else
01047 {
01048
01049 first_ls = FALSE;
01050 }
01051 }
01052
01053 else nav_drive_set(j);
01054 }
01055 break;
01056
01057 default:
01058
01059 print(SHL_USART, MSG_ER_CMD_NOT_FOUND);
01060 break;
01061 }
01062
01063 cmd_type = CMD_NONE;
01064 cmd = FALSE;
01065
01066 print(SHL_USART, MSG_PROMPT);
01067 }
01068 }
01069 }