RAM Disk function using Mbed os5 standard library
Please refer following my Notebook page.
/users/kenjiArai/notebook/sd-card-control-new/#
FatFs_Mon/mon.cpp@4:6650958e6eae, 2020-05-02 (annotated)
- Committer:
- kenjiArai
- Date:
- Sat May 02 03:45:31 2020 +0000
- Revision:
- 4:6650958e6eae
- Parent:
- 1:58fc0cbd9a41
updated os5. changed starting process(wait key input)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 0:308d4fafaafb | 1 | /* |
kenjiArai | 0:308d4fafaafb | 2 | * mbed Application program for the mbed |
kenjiArai | 0:308d4fafaafb | 3 | * FatFs Check program / monitor part |
kenjiArai | 0:308d4fafaafb | 4 | * |
kenjiArai | 4:6650958e6eae | 5 | * Copyright (c) 2015,'18,'19,'20 Kenji Arai / JH1PJL |
kenjiArai | 4:6650958e6eae | 6 | * http://www7b.biglobe.ne.jp/~kenjia/ |
kenjiArai | 0:308d4fafaafb | 7 | * https://os.mbed.com/users/kenjiArai/ |
kenjiArai | 0:308d4fafaafb | 8 | * Created: May 5th, 2015 |
kenjiArai | 0:308d4fafaafb | 9 | * Revised: June 14th, 2015 |
kenjiArai | 0:308d4fafaafb | 10 | * Revised: April 7th, 2018 |
kenjiArai | 4:6650958e6eae | 11 | * Revised: May 2nd, 2020 |
kenjiArai | 0:308d4fafaafb | 12 | */ |
kenjiArai | 0:308d4fafaafb | 13 | |
kenjiArai | 0:308d4fafaafb | 14 | /* |
kenjiArai | 0:308d4fafaafb | 15 | *---------------- REFERENCE --------------------------------------------------- |
kenjiArai | 0:308d4fafaafb | 16 | * Original Source Information |
kenjiArai | 0:308d4fafaafb | 17 | * FatFs sample program |
kenjiArai | 0:308d4fafaafb | 18 | * ChaN FatFs http://elm-chan.org/ |
kenjiArai | 0:308d4fafaafb | 19 | * http://elm-chan.org/fsw/ff/00index_e.html |
kenjiArai | 0:308d4fafaafb | 20 | */ |
kenjiArai | 0:308d4fafaafb | 21 | /*----------------------------------------------------------------------*/ |
kenjiArai | 0:308d4fafaafb | 22 | /* FAT file system sample project for FatFs (C)ChaN, 2016 */ |
kenjiArai | 0:308d4fafaafb | 23 | /*----------------------------------------------------------------------*/ |
kenjiArai | 0:308d4fafaafb | 24 | |
kenjiArai | 0:308d4fafaafb | 25 | // Include -------------------------------------------------------------------- |
kenjiArai | 0:308d4fafaafb | 26 | #include "mbed.h" |
kenjiArai | 0:308d4fafaafb | 27 | #if (MBED_MAJOR_VERSION == 2) |
kenjiArai | 0:308d4fafaafb | 28 | #include "SDFileSystem.h" |
kenjiArai | 0:308d4fafaafb | 29 | #elif (MBED_MAJOR_VERSION == 5) |
kenjiArai | 0:308d4fafaafb | 30 | #include "FATFileSystem.h" |
kenjiArai | 0:308d4fafaafb | 31 | #endif |
kenjiArai | 0:308d4fafaafb | 32 | #include "ff.h" |
kenjiArai | 0:308d4fafaafb | 33 | #include "ffconf.h" |
kenjiArai | 0:308d4fafaafb | 34 | #include "diskio.h" |
kenjiArai | 0:308d4fafaafb | 35 | #include "mon.h" |
kenjiArai | 0:308d4fafaafb | 36 | |
kenjiArai | 0:308d4fafaafb | 37 | // Definition ----------------------------------------------------------------- |
kenjiArai | 0:308d4fafaafb | 38 | #define DO_DEBUG 0 |
kenjiArai | 0:308d4fafaafb | 39 | |
kenjiArai | 0:308d4fafaafb | 40 | #if DO_DEBUG |
kenjiArai | 0:308d4fafaafb | 41 | #define DEBUG_LINE pc.printf("line:%d\r\n", __LINE__); |
kenjiArai | 0:308d4fafaafb | 42 | #else |
kenjiArai | 0:308d4fafaafb | 43 | #define DEBUG_LINE {;} |
kenjiArai | 0:308d4fafaafb | 44 | #endif |
kenjiArai | 0:308d4fafaafb | 45 | |
kenjiArai | 0:308d4fafaafb | 46 | // Com |
kenjiArai | 0:308d4fafaafb | 47 | #if 1 |
kenjiArai | 0:308d4fafaafb | 48 | #define BAUD(x) pc.baud(x) |
kenjiArai | 0:308d4fafaafb | 49 | #define GETC(x) pc.getc(x) |
kenjiArai | 0:308d4fafaafb | 50 | #define PUTC(x) pc.putc(x) |
kenjiArai | 0:308d4fafaafb | 51 | #define PUTS(x) pc.puts(x) |
kenjiArai | 0:308d4fafaafb | 52 | #define PRINTF(...) pc.printf(__VA_ARGS__) |
kenjiArai | 0:308d4fafaafb | 53 | #define READABLE(x) pc.readable(x) |
kenjiArai | 0:308d4fafaafb | 54 | #else |
kenjiArai | 0:308d4fafaafb | 55 | #define BAUD(x) {;} |
kenjiArai | 0:308d4fafaafb | 56 | #define GETC(x) {;} |
kenjiArai | 0:308d4fafaafb | 57 | #define PUTC(x) {;} |
kenjiArai | 0:308d4fafaafb | 58 | #define PRINTF(...) {;} |
kenjiArai | 0:308d4fafaafb | 59 | #define READABLE(x) {;} |
kenjiArai | 0:308d4fafaafb | 60 | #endif |
kenjiArai | 0:308d4fafaafb | 61 | |
kenjiArai | 0:308d4fafaafb | 62 | #define UTC_JST_OFFSET (32400) // +9 hours |
kenjiArai | 0:308d4fafaafb | 63 | |
kenjiArai | 0:308d4fafaafb | 64 | // from ffconf.h |
kenjiArai | 0:308d4fafaafb | 65 | #define _VOLUMES 1 |
kenjiArai | 0:308d4fafaafb | 66 | |
kenjiArai | 0:308d4fafaafb | 67 | #if !defined(FF_FS_RPATH) |
kenjiArai | 0:308d4fafaafb | 68 | #define FF_FS_RPATH 0 |
kenjiArai | 0:308d4fafaafb | 69 | #endif |
kenjiArai | 0:308d4fafaafb | 70 | |
kenjiArai | 0:308d4fafaafb | 71 | #define DW_CHAR sizeof(char) |
kenjiArai | 0:308d4fafaafb | 72 | #define DW_SHORT sizeof(short) |
kenjiArai | 0:308d4fafaafb | 73 | #define DW_LONG sizeof(long) |
kenjiArai | 0:308d4fafaafb | 74 | |
kenjiArai | 0:308d4fafaafb | 75 | /* These types must be 16-bit, 32-bit or larger integer */ |
kenjiArai | 0:308d4fafaafb | 76 | typedef int INT; |
kenjiArai | 0:308d4fafaafb | 77 | typedef unsigned int UINT; |
kenjiArai | 0:308d4fafaafb | 78 | |
kenjiArai | 0:308d4fafaafb | 79 | /* These types must be 8-bit integer */ |
kenjiArai | 0:308d4fafaafb | 80 | typedef char CHAR; |
kenjiArai | 0:308d4fafaafb | 81 | typedef unsigned char UCHAR; |
kenjiArai | 0:308d4fafaafb | 82 | typedef unsigned char BYTE; |
kenjiArai | 0:308d4fafaafb | 83 | |
kenjiArai | 0:308d4fafaafb | 84 | /* These types must be 16-bit integer */ |
kenjiArai | 0:308d4fafaafb | 85 | typedef short SHORT; |
kenjiArai | 0:308d4fafaafb | 86 | typedef unsigned short USHORT; |
kenjiArai | 0:308d4fafaafb | 87 | typedef unsigned short WORD; |
kenjiArai | 0:308d4fafaafb | 88 | typedef unsigned short WCHAR; |
kenjiArai | 0:308d4fafaafb | 89 | |
kenjiArai | 0:308d4fafaafb | 90 | /* These types must be 32-bit integer */ |
kenjiArai | 0:308d4fafaafb | 91 | typedef long LONG; |
kenjiArai | 0:308d4fafaafb | 92 | typedef unsigned long ULONG; |
kenjiArai | 0:308d4fafaafb | 93 | typedef unsigned long DWORD; |
kenjiArai | 0:308d4fafaafb | 94 | /* by Kenji Arai / JH1PJL September 10th, 2012 */ |
kenjiArai | 0:308d4fafaafb | 95 | typedef unsigned long long DDWORD; |
kenjiArai | 0:308d4fafaafb | 96 | |
kenjiArai | 0:308d4fafaafb | 97 | // RAM ------------------------------------------------------------------------ |
kenjiArai | 0:308d4fafaafb | 98 | BYTE Buff[4096]; |
kenjiArai | 0:308d4fafaafb | 99 | char Linebuf[128]; // Console input buffer |
kenjiArai | 0:308d4fafaafb | 100 | FATFS Fatfs[_VOLUMES]; // File system object for each logical drive |
kenjiArai | 0:308d4fafaafb | 101 | FIL File1, File2; // File objects |
kenjiArai | 0:308d4fafaafb | 102 | FATFS_DIR* Dirx; |
kenjiArai | 0:308d4fafaafb | 103 | FILINFO Finfo; |
kenjiArai | 0:308d4fafaafb | 104 | DWORD AccSize; // Work register for fs command |
kenjiArai | 0:308d4fafaafb | 105 | WORD AccFiles, AccDirs; |
kenjiArai | 0:308d4fafaafb | 106 | |
kenjiArai | 0:308d4fafaafb | 107 | // ROM / Constant data -------------------------------------------------------- |
kenjiArai | 1:58fc0cbd9a41 | 108 | const char *const monmsg0 = "Start monitor program for FatFs File System\r\n"; |
kenjiArai | 1:58fc0cbd9a41 | 109 | const char *const monmsg1 = " <Please press any key to start the monitor>"; |
kenjiArai | 0:308d4fafaafb | 110 | |
kenjiArai | 0:308d4fafaafb | 111 | static const char HelpMsg0[] = |
kenjiArai | 0:308d4fafaafb | 112 | "dir <full_pass>\r\n" |
kenjiArai | 0:308d4fafaafb | 113 | "type <file_name>\r\n" |
kenjiArai | 0:308d4fafaafb | 114 | "vol\r\n" |
kenjiArai | 0:308d4fafaafb | 115 | "ren <org_file_name> <new_file_name>\r\n" |
kenjiArai | 0:308d4fafaafb | 116 | "copy <file_name> <file_name>\r\n" |
kenjiArai | 0:308d4fafaafb | 117 | "mkdir <dir_name>\r\n" |
kenjiArai | 0:308d4fafaafb | 118 | "cd <dir_name>\r\n" |
kenjiArai | 0:308d4fafaafb | 119 | "x extend commands mode\r\n" |
kenjiArai | 0:308d4fafaafb | 120 | "q Return to main\r\n" |
kenjiArai | 0:308d4fafaafb | 121 | "t Show current time or Adjust time\r\n" |
kenjiArai | 4:6650958e6eae | 122 | " e.g. t 20 5 2 10 11 12 -> May 02,'20, 10:11:12\r\n" |
kenjiArai | 0:308d4fafaafb | 123 | "? Help/You know the command\r\n" |
kenjiArai | 0:308d4fafaafb | 124 | "\r\n"; |
kenjiArai | 0:308d4fafaafb | 125 | |
kenjiArai | 0:308d4fafaafb | 126 | static const char HelpMsg1[] = |
kenjiArai | 0:308d4fafaafb | 127 | "[File system controls]\r\n" |
kenjiArai | 0:308d4fafaafb | 128 | " fi <ld#> [<mount>]- Force initialized the volume\r\n" |
kenjiArai | 0:308d4fafaafb | 129 | " fs [<path>] - Show volume status\r\n" |
kenjiArai | 0:308d4fafaafb | 130 | " fl [<path>] - Show a directory\r\n" |
kenjiArai | 0:308d4fafaafb | 131 | " fo <mode> <file> - Open a file\r\n" |
kenjiArai | 0:308d4fafaafb | 132 | " <mode> Read=1, Write=2\r\n" |
kenjiArai | 0:308d4fafaafb | 133 | " fc - Close the file\r\n" |
kenjiArai | 0:308d4fafaafb | 134 | " fe <ofs> - Move fp in normal seek\r\n" |
kenjiArai | 0:308d4fafaafb | 135 | " fd <len> - Read and dump the file\r\n" |
kenjiArai | 0:308d4fafaafb | 136 | " fr <len> - Read the file\r\n" |
kenjiArai | 0:308d4fafaafb | 137 | " fw <len> <val> - Write to the file\r\n" |
kenjiArai | 0:308d4fafaafb | 138 | " fn <org.name> <new.name> - Rename an object\r\n" |
kenjiArai | 0:308d4fafaafb | 139 | " fu <name> - Unlink an object\r\n" |
kenjiArai | 0:308d4fafaafb | 140 | " fv - Truncate the file at current fp\r\n" |
kenjiArai | 0:308d4fafaafb | 141 | " fk <name> - Create a directory\r\n" |
kenjiArai | 0:308d4fafaafb | 142 | " fa <atrr> <mask> <object name> - Change attribute of an object\r\n" |
kenjiArai | 0:308d4fafaafb | 143 | " ft <year> <month> <day> <hour> <min> <sec> <name>" |
kenjiArai | 0:308d4fafaafb | 144 | " - Change timestamp of an object\r\n" |
kenjiArai | 0:308d4fafaafb | 145 | " fx <src.file> <dst.file> - Copy a file\r\n" |
kenjiArai | 0:308d4fafaafb | 146 | " fg <path> - Change current directory\r\n" |
kenjiArai | 0:308d4fafaafb | 147 | " fq - Show current directory\r\n" |
kenjiArai | 0:308d4fafaafb | 148 | " fb <name> - Set volume label\r\n" |
kenjiArai | 0:308d4fafaafb | 149 | " fm <ld#> <type> <csize> - Create file system\r\n" |
kenjiArai | 0:308d4fafaafb | 150 | " fz [<len>] - Change/Show R/W length for fr/fw/fx command\r\n" |
kenjiArai | 0:308d4fafaafb | 151 | "[Disk contorls]\r\n" |
kenjiArai | 0:308d4fafaafb | 152 | " di <pd#> - Initialize disk\r\n" |
kenjiArai | 0:308d4fafaafb | 153 | " dd [<pd#> <lba>] - Dump a secrtor\r\n" |
kenjiArai | 0:308d4fafaafb | 154 | " ds <pd#> - Show disk status\r\n" |
kenjiArai | 0:308d4fafaafb | 155 | "[Buffer controls]\r\n" |
kenjiArai | 0:308d4fafaafb | 156 | " bd <ofs> - Dump working buffer\r\n" |
kenjiArai | 0:308d4fafaafb | 157 | " be <ofs> [<data>] ... - Edit working buffer\r\n" |
kenjiArai | 0:308d4fafaafb | 158 | " br <pd#> <lba> [<count>] - Read disk into working buffer\r\n" |
kenjiArai | 0:308d4fafaafb | 159 | " bw <pd#> <lba> [<count>] - Write working buffer into disk\r\n" |
kenjiArai | 0:308d4fafaafb | 160 | " bf <val> - Fill working buffer\r\n" |
kenjiArai | 0:308d4fafaafb | 161 | "[Misc commands]\r\n" |
kenjiArai | 0:308d4fafaafb | 162 | " q Return\r\n" |
kenjiArai | 0:308d4fafaafb | 163 | " ? Help\r\n" |
kenjiArai | 0:308d4fafaafb | 164 | "\r\n"; |
kenjiArai | 0:308d4fafaafb | 165 | |
kenjiArai | 0:308d4fafaafb | 166 | // Function prototypes -------------------------------------------------------- |
kenjiArai | 0:308d4fafaafb | 167 | #if (MBED_MAJOR_VERSION == 2) |
kenjiArai | 0:308d4fafaafb | 168 | extern SDFileSystem fs; |
kenjiArai | 0:308d4fafaafb | 169 | #elif (MBED_MAJOR_VERSION == 5) |
kenjiArai | 0:308d4fafaafb | 170 | extern HeapBlockDevice bd; |
kenjiArai | 0:308d4fafaafb | 171 | extern FATFileSystem fs; |
kenjiArai | 0:308d4fafaafb | 172 | #endif |
kenjiArai | 0:308d4fafaafb | 173 | |
kenjiArai | 0:308d4fafaafb | 174 | static void extended_mon( char *ptr ); |
kenjiArai | 0:308d4fafaafb | 175 | static void v_next( char *ptr ); |
kenjiArai | 0:308d4fafaafb | 176 | static void d_next( char *ptr ); |
kenjiArai | 0:308d4fafaafb | 177 | static void c_next( char *ptr ); |
kenjiArai | 0:308d4fafaafb | 178 | static void m_next( char *ptr ); |
kenjiArai | 0:308d4fafaafb | 179 | static void r_next( char *ptr ); |
kenjiArai | 0:308d4fafaafb | 180 | static void t_next( char *ptr ); |
kenjiArai | 0:308d4fafaafb | 181 | static void memory_inf(char *ptr); |
kenjiArai | 0:308d4fafaafb | 182 | static void disk_inf(char *ptr); |
kenjiArai | 0:308d4fafaafb | 183 | |
kenjiArai | 0:308d4fafaafb | 184 | static void crlf( void ); |
kenjiArai | 0:308d4fafaafb | 185 | static FRESULT scan_files( char* path ); |
kenjiArai | 0:308d4fafaafb | 186 | static void put_rc( FRESULT rc ); |
kenjiArai | 0:308d4fafaafb | 187 | static void file_inf( char *ptr ); |
kenjiArai | 0:308d4fafaafb | 188 | static void put_dump( void* buff, unsigned long addr, int len, int width ); |
kenjiArai | 0:308d4fafaafb | 189 | static void chk_and_set_time(char *ptr); |
kenjiArai | 0:308d4fafaafb | 190 | static int xatoi ( char **str, long *res ); |
kenjiArai | 0:308d4fafaafb | 191 | |
kenjiArai | 0:308d4fafaafb | 192 | void get_line (char *buff, int len); |
kenjiArai | 0:308d4fafaafb | 193 | |
kenjiArai | 0:308d4fafaafb | 194 | // Object --------------------------------------------------------------------- |
kenjiArai | 0:308d4fafaafb | 195 | extern Serial pc; |
kenjiArai | 0:308d4fafaafb | 196 | Timer t; |
kenjiArai | 0:308d4fafaafb | 197 | |
kenjiArai | 0:308d4fafaafb | 198 | //------------------------------------------------------------------------------ |
kenjiArai | 0:308d4fafaafb | 199 | // Control Program |
kenjiArai | 0:308d4fafaafb | 200 | //------------------------------------------------------------------------------ |
kenjiArai | 0:308d4fafaafb | 201 | // Monitor program for File control |
kenjiArai | 0:308d4fafaafb | 202 | void mon () |
kenjiArai | 0:308d4fafaafb | 203 | { |
kenjiArai | 0:308d4fafaafb | 204 | char *ptr; |
kenjiArai | 0:308d4fafaafb | 205 | |
kenjiArai | 0:308d4fafaafb | 206 | Dirx = new FATFS_DIR; |
kenjiArai | 0:308d4fafaafb | 207 | /* Open Uart to communicate with Host PC */ |
kenjiArai | 0:308d4fafaafb | 208 | PUTS(monmsg0); |
kenjiArai | 0:308d4fafaafb | 209 | PUTS(monmsg1); |
kenjiArai | 0:308d4fafaafb | 210 | crlf(); |
kenjiArai | 0:308d4fafaafb | 211 | for (;;) { |
kenjiArai | 0:308d4fafaafb | 212 | DEBUG_LINE |
kenjiArai | 0:308d4fafaafb | 213 | PUTC('>'); |
kenjiArai | 0:308d4fafaafb | 214 | ptr = Linebuf; |
kenjiArai | 0:308d4fafaafb | 215 | get_line( ptr, sizeof(Linebuf) ); |
kenjiArai | 0:308d4fafaafb | 216 | switch ( *ptr++ ) { |
kenjiArai | 0:308d4fafaafb | 217 | // vol |
kenjiArai | 0:308d4fafaafb | 218 | case 'v' : |
kenjiArai | 0:308d4fafaafb | 219 | v_next(ptr); |
kenjiArai | 0:308d4fafaafb | 220 | break; |
kenjiArai | 0:308d4fafaafb | 221 | // dir |
kenjiArai | 0:308d4fafaafb | 222 | case 'd' : |
kenjiArai | 0:308d4fafaafb | 223 | d_next(ptr); |
kenjiArai | 0:308d4fafaafb | 224 | break; |
kenjiArai | 0:308d4fafaafb | 225 | // cd, copy |
kenjiArai | 0:308d4fafaafb | 226 | case 'c' : |
kenjiArai | 0:308d4fafaafb | 227 | c_next(ptr); |
kenjiArai | 0:308d4fafaafb | 228 | break; |
kenjiArai | 0:308d4fafaafb | 229 | // mkdir |
kenjiArai | 0:308d4fafaafb | 230 | case 'm' : |
kenjiArai | 0:308d4fafaafb | 231 | m_next(ptr); |
kenjiArai | 0:308d4fafaafb | 232 | break; |
kenjiArai | 0:308d4fafaafb | 233 | // ren |
kenjiArai | 0:308d4fafaafb | 234 | case 'r' : |
kenjiArai | 0:308d4fafaafb | 235 | r_next(ptr); |
kenjiArai | 0:308d4fafaafb | 236 | break; |
kenjiArai | 0:308d4fafaafb | 237 | case 't' : |
kenjiArai | 0:308d4fafaafb | 238 | t_next(ptr); |
kenjiArai | 0:308d4fafaafb | 239 | break; |
kenjiArai | 0:308d4fafaafb | 240 | case 'x' : |
kenjiArai | 0:308d4fafaafb | 241 | extended_mon(ptr); |
kenjiArai | 0:308d4fafaafb | 242 | break; |
kenjiArai | 0:308d4fafaafb | 243 | // Help |
kenjiArai | 0:308d4fafaafb | 244 | case '?' : |
kenjiArai | 0:308d4fafaafb | 245 | PUTS(HelpMsg0); |
kenjiArai | 0:308d4fafaafb | 246 | break; |
kenjiArai | 0:308d4fafaafb | 247 | // Exit monitor (return to main()) |
kenjiArai | 0:308d4fafaafb | 248 | case 'q' : |
kenjiArai | 0:308d4fafaafb | 249 | PUTS("Return to main\r\n"); |
kenjiArai | 0:308d4fafaafb | 250 | return; |
kenjiArai | 0:308d4fafaafb | 251 | // Not a command |
kenjiArai | 0:308d4fafaafb | 252 | default: |
kenjiArai | 0:308d4fafaafb | 253 | PUTS("? [HELP]=?"); |
kenjiArai | 0:308d4fafaafb | 254 | crlf(); |
kenjiArai | 0:308d4fafaafb | 255 | break; |
kenjiArai | 0:308d4fafaafb | 256 | } |
kenjiArai | 0:308d4fafaafb | 257 | } |
kenjiArai | 0:308d4fafaafb | 258 | } |
kenjiArai | 0:308d4fafaafb | 259 | |
kenjiArai | 0:308d4fafaafb | 260 | uint32_t get_disk_freespace(void) |
kenjiArai | 0:308d4fafaafb | 261 | { |
kenjiArai | 0:308d4fafaafb | 262 | long p1; |
kenjiArai | 0:308d4fafaafb | 263 | UINT s1, s2; |
kenjiArai | 0:308d4fafaafb | 264 | FATFS *fs; |
kenjiArai | 0:308d4fafaafb | 265 | BYTE res; |
kenjiArai | 0:308d4fafaafb | 266 | |
kenjiArai | 0:308d4fafaafb | 267 | if (Dirx == NULL){ |
kenjiArai | 0:308d4fafaafb | 268 | Dirx = new FATFS_DIR; |
kenjiArai | 0:308d4fafaafb | 269 | } |
kenjiArai | 0:308d4fafaafb | 270 | char p = NULL; |
kenjiArai | 0:308d4fafaafb | 271 | res = f_opendir(Dirx, &p); |
kenjiArai | 0:308d4fafaafb | 272 | if (res) { |
kenjiArai | 0:308d4fafaafb | 273 | return 0; |
kenjiArai | 0:308d4fafaafb | 274 | } |
kenjiArai | 0:308d4fafaafb | 275 | p1 = s1 = s2 = 0; |
kenjiArai | 0:308d4fafaafb | 276 | for(;;) { |
kenjiArai | 0:308d4fafaafb | 277 | res = f_readdir(Dirx, &Finfo); |
kenjiArai | 0:308d4fafaafb | 278 | if ((res != FR_OK) || !Finfo.fname[0]) break; |
kenjiArai | 0:308d4fafaafb | 279 | if (Finfo.fattrib & AM_DIR) { |
kenjiArai | 0:308d4fafaafb | 280 | s2++; |
kenjiArai | 0:308d4fafaafb | 281 | } else { |
kenjiArai | 0:308d4fafaafb | 282 | s1++; |
kenjiArai | 0:308d4fafaafb | 283 | p1 += Finfo.fsize; |
kenjiArai | 0:308d4fafaafb | 284 | } |
kenjiArai | 0:308d4fafaafb | 285 | } |
kenjiArai | 0:308d4fafaafb | 286 | res = f_getfree(&p, (DWORD*)&p1, &fs); |
kenjiArai | 0:308d4fafaafb | 287 | uint32_t size = p1 * fs->csize * 512; |
kenjiArai | 0:308d4fafaafb | 288 | if (res == FR_OK) { |
kenjiArai | 0:308d4fafaafb | 289 | return size; |
kenjiArai | 0:308d4fafaafb | 290 | } else { |
kenjiArai | 0:308d4fafaafb | 291 | return 0; |
kenjiArai | 0:308d4fafaafb | 292 | } |
kenjiArai | 0:308d4fafaafb | 293 | } |
kenjiArai | 0:308d4fafaafb | 294 | |
kenjiArai | 1:58fc0cbd9a41 | 295 | uint32_t get_data_file_size(const char *const file_name) |
kenjiArai | 1:58fc0cbd9a41 | 296 | { |
kenjiArai | 1:58fc0cbd9a41 | 297 | BYTE res; |
kenjiArai | 1:58fc0cbd9a41 | 298 | //const char *file_name ="acc_data.txt"; |
kenjiArai | 1:58fc0cbd9a41 | 299 | |
kenjiArai | 1:58fc0cbd9a41 | 300 | if (Dirx == NULL){ |
kenjiArai | 1:58fc0cbd9a41 | 301 | Dirx = new FATFS_DIR; |
kenjiArai | 1:58fc0cbd9a41 | 302 | } |
kenjiArai | 1:58fc0cbd9a41 | 303 | char p = NULL; |
kenjiArai | 1:58fc0cbd9a41 | 304 | res = f_opendir(Dirx, &p); |
kenjiArai | 1:58fc0cbd9a41 | 305 | if (res) { |
kenjiArai | 1:58fc0cbd9a41 | 306 | put_rc((FRESULT)res); |
kenjiArai | 1:58fc0cbd9a41 | 307 | return 0; |
kenjiArai | 1:58fc0cbd9a41 | 308 | } |
kenjiArai | 1:58fc0cbd9a41 | 309 | for(;;) { |
kenjiArai | 1:58fc0cbd9a41 | 310 | res = f_readdir(Dirx, &Finfo); |
kenjiArai | 1:58fc0cbd9a41 | 311 | if ((res != FR_OK) || !Finfo.fname[0]) break; |
kenjiArai | 1:58fc0cbd9a41 | 312 | if (strcmp(Finfo.fname, file_name) == 0){ |
kenjiArai | 1:58fc0cbd9a41 | 313 | return Finfo.fsize; |
kenjiArai | 1:58fc0cbd9a41 | 314 | } |
kenjiArai | 1:58fc0cbd9a41 | 315 | } |
kenjiArai | 1:58fc0cbd9a41 | 316 | return 0; |
kenjiArai | 1:58fc0cbd9a41 | 317 | } |
kenjiArai | 1:58fc0cbd9a41 | 318 | |
kenjiArai | 0:308d4fafaafb | 319 | static void extended_mon( char *ptr ) |
kenjiArai | 0:308d4fafaafb | 320 | { |
kenjiArai | 0:308d4fafaafb | 321 | PUTS(HelpMsg1); |
kenjiArai | 0:308d4fafaafb | 322 | while(true) { |
kenjiArai | 0:308d4fafaafb | 323 | PUTS("e>"); |
kenjiArai | 0:308d4fafaafb | 324 | ptr = Linebuf; |
kenjiArai | 0:308d4fafaafb | 325 | get_line( ptr, sizeof(Linebuf) ); |
kenjiArai | 0:308d4fafaafb | 326 | switch ( *ptr++ ) { |
kenjiArai | 0:308d4fafaafb | 327 | case 'f' : |
kenjiArai | 0:308d4fafaafb | 328 | DEBUG_LINE; |
kenjiArai | 0:308d4fafaafb | 329 | file_inf(ptr); |
kenjiArai | 0:308d4fafaafb | 330 | break; |
kenjiArai | 0:308d4fafaafb | 331 | case 'd' : |
kenjiArai | 0:308d4fafaafb | 332 | DEBUG_LINE; |
kenjiArai | 0:308d4fafaafb | 333 | disk_inf(ptr); |
kenjiArai | 0:308d4fafaafb | 334 | break; |
kenjiArai | 0:308d4fafaafb | 335 | case 'm' : |
kenjiArai | 0:308d4fafaafb | 336 | DEBUG_LINE; |
kenjiArai | 0:308d4fafaafb | 337 | memory_inf(ptr); |
kenjiArai | 0:308d4fafaafb | 338 | break; |
kenjiArai | 0:308d4fafaafb | 339 | case '?' : |
kenjiArai | 0:308d4fafaafb | 340 | DEBUG_LINE; |
kenjiArai | 0:308d4fafaafb | 341 | PUTS(HelpMsg1); |
kenjiArai | 0:308d4fafaafb | 342 | break; |
kenjiArai | 0:308d4fafaafb | 343 | case 'q' : |
kenjiArai | 0:308d4fafaafb | 344 | DEBUG_LINE; |
kenjiArai | 0:308d4fafaafb | 345 | return; |
kenjiArai | 0:308d4fafaafb | 346 | default: |
kenjiArai | 0:308d4fafaafb | 347 | PUTS( "?\r\n" ); |
kenjiArai | 0:308d4fafaafb | 348 | } |
kenjiArai | 0:308d4fafaafb | 349 | } |
kenjiArai | 0:308d4fafaafb | 350 | } |
kenjiArai | 0:308d4fafaafb | 351 | |
kenjiArai | 0:308d4fafaafb | 352 | //------------------------------------------------------------------------------ |
kenjiArai | 0:308d4fafaafb | 353 | // General monitor functions |
kenjiArai | 0:308d4fafaafb | 354 | static void v_next( char *ptr ) |
kenjiArai | 0:308d4fafaafb | 355 | { |
kenjiArai | 0:308d4fafaafb | 356 | switch ( *ptr++ ) { |
kenjiArai | 0:308d4fafaafb | 357 | case 'o' : |
kenjiArai | 0:308d4fafaafb | 358 | if (*ptr == 'l') { |
kenjiArai | 0:308d4fafaafb | 359 | *ptr = 's'; |
kenjiArai | 0:308d4fafaafb | 360 | file_inf(ptr); // fs [<path>] - Show volume status |
kenjiArai | 0:308d4fafaafb | 361 | } |
kenjiArai | 0:308d4fafaafb | 362 | break; |
kenjiArai | 0:308d4fafaafb | 363 | default: |
kenjiArai | 0:308d4fafaafb | 364 | PUTS( "?\r\n" ); |
kenjiArai | 0:308d4fafaafb | 365 | } |
kenjiArai | 0:308d4fafaafb | 366 | } |
kenjiArai | 0:308d4fafaafb | 367 | |
kenjiArai | 0:308d4fafaafb | 368 | static void d_next(char *ptr) |
kenjiArai | 0:308d4fafaafb | 369 | { |
kenjiArai | 0:308d4fafaafb | 370 | switch ( *ptr++ ) { |
kenjiArai | 0:308d4fafaafb | 371 | case 'i' : |
kenjiArai | 0:308d4fafaafb | 372 | if (*ptr == 'r') { |
kenjiArai | 0:308d4fafaafb | 373 | *ptr = 'l'; |
kenjiArai | 0:308d4fafaafb | 374 | file_inf(ptr); // fl [<path>] - Directory listing |
kenjiArai | 0:308d4fafaafb | 375 | } |
kenjiArai | 0:308d4fafaafb | 376 | break; |
kenjiArai | 0:308d4fafaafb | 377 | default: |
kenjiArai | 0:308d4fafaafb | 378 | PUTS( "?\r\n" ); |
kenjiArai | 0:308d4fafaafb | 379 | } |
kenjiArai | 0:308d4fafaafb | 380 | } |
kenjiArai | 0:308d4fafaafb | 381 | |
kenjiArai | 0:308d4fafaafb | 382 | static void c_next(char *ptr) |
kenjiArai | 0:308d4fafaafb | 383 | { |
kenjiArai | 0:308d4fafaafb | 384 | switch ( *ptr++ ) { |
kenjiArai | 0:308d4fafaafb | 385 | case 'o' : |
kenjiArai | 0:308d4fafaafb | 386 | if ((*ptr == 'p') && (*(ptr + 1) == 'y')) { |
kenjiArai | 0:308d4fafaafb | 387 | ptr++; |
kenjiArai | 0:308d4fafaafb | 388 | *ptr = 'x'; |
kenjiArai | 0:308d4fafaafb | 389 | file_inf(ptr); // fx <src_name> <dst_name> - Copy file |
kenjiArai | 0:308d4fafaafb | 390 | } |
kenjiArai | 0:308d4fafaafb | 391 | break; |
kenjiArai | 0:308d4fafaafb | 392 | case 'd' : |
kenjiArai | 0:308d4fafaafb | 393 | *ptr = 'g'; |
kenjiArai | 0:308d4fafaafb | 394 | file_inf(ptr); // fx <src_name> <dst_name> - Copy file |
kenjiArai | 0:308d4fafaafb | 395 | break; |
kenjiArai | 0:308d4fafaafb | 396 | default: |
kenjiArai | 0:308d4fafaafb | 397 | PUTS( "?\r\n" ); |
kenjiArai | 0:308d4fafaafb | 398 | } |
kenjiArai | 0:308d4fafaafb | 399 | } |
kenjiArai | 0:308d4fafaafb | 400 | |
kenjiArai | 0:308d4fafaafb | 401 | static void m_next(char *ptr) |
kenjiArai | 0:308d4fafaafb | 402 | { |
kenjiArai | 0:308d4fafaafb | 403 | switch ( *ptr++ ) { |
kenjiArai | 0:308d4fafaafb | 404 | case 'k' : |
kenjiArai | 0:308d4fafaafb | 405 | if ((*ptr == 'd') && (*(ptr + 1) == 'i') && (*(ptr + 2) == 'r')) { |
kenjiArai | 0:308d4fafaafb | 406 | ptr += 2; |
kenjiArai | 0:308d4fafaafb | 407 | *ptr = 'k'; |
kenjiArai | 0:308d4fafaafb | 408 | file_inf(ptr); // fk <name> - Create a directory |
kenjiArai | 0:308d4fafaafb | 409 | } |
kenjiArai | 0:308d4fafaafb | 410 | break; |
kenjiArai | 0:308d4fafaafb | 411 | default: |
kenjiArai | 0:308d4fafaafb | 412 | PUTS("?\r\n"); |
kenjiArai | 0:308d4fafaafb | 413 | } |
kenjiArai | 0:308d4fafaafb | 414 | } |
kenjiArai | 0:308d4fafaafb | 415 | |
kenjiArai | 0:308d4fafaafb | 416 | static void r_next(char *ptr) |
kenjiArai | 0:308d4fafaafb | 417 | { |
kenjiArai | 0:308d4fafaafb | 418 | switch (*ptr++) { |
kenjiArai | 0:308d4fafaafb | 419 | case 'e' : |
kenjiArai | 0:308d4fafaafb | 420 | if (*ptr == 'n') { |
kenjiArai | 0:308d4fafaafb | 421 | // fn <old_name> <new_name> - Change file/dir name |
kenjiArai | 0:308d4fafaafb | 422 | file_inf(ptr); |
kenjiArai | 0:308d4fafaafb | 423 | } |
kenjiArai | 0:308d4fafaafb | 424 | break; |
kenjiArai | 0:308d4fafaafb | 425 | default: |
kenjiArai | 0:308d4fafaafb | 426 | PUTS("?\r\n"); |
kenjiArai | 0:308d4fafaafb | 427 | } |
kenjiArai | 0:308d4fafaafb | 428 | } |
kenjiArai | 0:308d4fafaafb | 429 | |
kenjiArai | 0:308d4fafaafb | 430 | static void t_next(char *ptr) |
kenjiArai | 0:308d4fafaafb | 431 | { |
kenjiArai | 0:308d4fafaafb | 432 | switch (*ptr++) { |
kenjiArai | 0:308d4fafaafb | 433 | case ' ' : |
kenjiArai | 0:308d4fafaafb | 434 | case 0x0d: |
kenjiArai | 0:308d4fafaafb | 435 | chk_and_set_time(ptr); |
kenjiArai | 0:308d4fafaafb | 436 | case 'y' : |
kenjiArai | 0:308d4fafaafb | 437 | if ((*ptr == 'p') && (*(ptr + 1) == 'e')) { |
kenjiArai | 0:308d4fafaafb | 438 | ptr++; |
kenjiArai | 0:308d4fafaafb | 439 | *ptr = '&'; |
kenjiArai | 0:308d4fafaafb | 440 | file_inf(ptr); |
kenjiArai | 0:308d4fafaafb | 441 | } |
kenjiArai | 0:308d4fafaafb | 442 | break; |
kenjiArai | 0:308d4fafaafb | 443 | default: |
kenjiArai | 0:308d4fafaafb | 444 | PUTS("?\r\n"); |
kenjiArai | 0:308d4fafaafb | 445 | } |
kenjiArai | 0:308d4fafaafb | 446 | } |
kenjiArai | 0:308d4fafaafb | 447 | |
kenjiArai | 0:308d4fafaafb | 448 | static FRESULT scan_files ( |
kenjiArai | 0:308d4fafaafb | 449 | char* path /* Pointer to the path name working buffer */ |
kenjiArai | 0:308d4fafaafb | 450 | ) |
kenjiArai | 0:308d4fafaafb | 451 | { |
kenjiArai | 0:308d4fafaafb | 452 | FATFS_DIR dirs; |
kenjiArai | 0:308d4fafaafb | 453 | FRESULT res; |
kenjiArai | 0:308d4fafaafb | 454 | BYTE i; |
kenjiArai | 0:308d4fafaafb | 455 | char *fn; |
kenjiArai | 0:308d4fafaafb | 456 | |
kenjiArai | 0:308d4fafaafb | 457 | if ((res = f_opendir(&dirs, path)) == FR_OK) { |
kenjiArai | 0:308d4fafaafb | 458 | i = strlen(path); |
kenjiArai | 0:308d4fafaafb | 459 | PRINTF("path: %s, n=%u\r\n", path, i); |
kenjiArai | 0:308d4fafaafb | 460 | while (((res = f_readdir(&dirs, &Finfo)) == FR_OK) && Finfo.fname[0]) { |
kenjiArai | 0:308d4fafaafb | 461 | if (FF_FS_RPATH && Finfo.fname[0] == '.') { |
kenjiArai | 0:308d4fafaafb | 462 | continue; |
kenjiArai | 0:308d4fafaafb | 463 | } |
kenjiArai | 0:308d4fafaafb | 464 | fn = Finfo.fname; |
kenjiArai | 0:308d4fafaafb | 465 | if (Finfo.fattrib & AM_DIR) { |
kenjiArai | 0:308d4fafaafb | 466 | AccDirs++; |
kenjiArai | 0:308d4fafaafb | 467 | *(path+i) = '/'; |
kenjiArai | 0:308d4fafaafb | 468 | strcpy(path+i+1, fn); |
kenjiArai | 0:308d4fafaafb | 469 | res = scan_files(path); |
kenjiArai | 0:308d4fafaafb | 470 | *(path+i) = '\0'; |
kenjiArai | 0:308d4fafaafb | 471 | if (res != FR_OK) break; |
kenjiArai | 0:308d4fafaafb | 472 | } else { |
kenjiArai | 0:308d4fafaafb | 473 | PRINTF("%s/%s\r\n", path, fn); |
kenjiArai | 0:308d4fafaafb | 474 | AccFiles++; |
kenjiArai | 0:308d4fafaafb | 475 | AccSize += Finfo.fsize; |
kenjiArai | 0:308d4fafaafb | 476 | } |
kenjiArai | 0:308d4fafaafb | 477 | } |
kenjiArai | 0:308d4fafaafb | 478 | } |
kenjiArai | 0:308d4fafaafb | 479 | return res; |
kenjiArai | 0:308d4fafaafb | 480 | } |
kenjiArai | 0:308d4fafaafb | 481 | |
kenjiArai | 0:308d4fafaafb | 482 | static void put_rc (FRESULT rc) |
kenjiArai | 0:308d4fafaafb | 483 | { |
kenjiArai | 0:308d4fafaafb | 484 | const char *str = |
kenjiArai | 0:308d4fafaafb | 485 | "OK\0" "DISK_ERR\0" "INT_ERR\0" "NOT_READY\0" "NO_FILE\0" "NO_PATH\0" |
kenjiArai | 0:308d4fafaafb | 486 | "INVALID_NAME\0" "DENIED\0" "EXIST\0" "INVALID_OBJECT\0" |
kenjiArai | 0:308d4fafaafb | 487 | "WRITE_PROTECTED\0" "INVALID_DRIVE\0" "NOT_ENABLED\0" |
kenjiArai | 0:308d4fafaafb | 488 | "NO_FILE_SYSTEM\0" "MKFS_ABORTED\0" "TIMEOUT\0" |
kenjiArai | 0:308d4fafaafb | 489 | "LOCKED\0" "NOT_ENOUGH_CORE\0" "TOO_MANY_OPEN_FILES\0"; |
kenjiArai | 0:308d4fafaafb | 490 | int i; |
kenjiArai | 0:308d4fafaafb | 491 | |
kenjiArai | 0:308d4fafaafb | 492 | for ( i = 0; i != rc && *str; i++ ) { |
kenjiArai | 0:308d4fafaafb | 493 | while ( *str++ ) { |
kenjiArai | 0:308d4fafaafb | 494 | ; |
kenjiArai | 0:308d4fafaafb | 495 | } |
kenjiArai | 0:308d4fafaafb | 496 | } |
kenjiArai | 0:308d4fafaafb | 497 | PRINTF( "rc=%u FR_%s\r\n", (UINT)rc, str ); |
kenjiArai | 0:308d4fafaafb | 498 | } |
kenjiArai | 0:308d4fafaafb | 499 | |
kenjiArai | 0:308d4fafaafb | 500 | static void file_inf(char *ptr) |
kenjiArai | 0:308d4fafaafb | 501 | { |
kenjiArai | 0:308d4fafaafb | 502 | long p1, p2, p3; |
kenjiArai | 0:308d4fafaafb | 503 | CHAR *ptr2; |
kenjiArai | 0:308d4fafaafb | 504 | BYTE f_res; |
kenjiArai | 0:308d4fafaafb | 505 | UINT s1, s2, cnt, blen = sizeof Buff; |
kenjiArai | 0:308d4fafaafb | 506 | FATFS *fs; |
kenjiArai | 0:308d4fafaafb | 507 | static const BYTE ft[] = {0, 12, 16, 32}; |
kenjiArai | 0:308d4fafaafb | 508 | BYTE res; |
kenjiArai | 0:308d4fafaafb | 509 | DWORD ofs = 0; |
kenjiArai | 0:308d4fafaafb | 510 | uint32_t tim; |
kenjiArai | 0:308d4fafaafb | 511 | |
kenjiArai | 0:308d4fafaafb | 512 | switch (*ptr++) { |
kenjiArai | 0:308d4fafaafb | 513 | case '&' : |
kenjiArai | 0:308d4fafaafb | 514 | DEBUG_LINE; |
kenjiArai | 0:308d4fafaafb | 515 | while (*ptr == ' ') ptr++; |
kenjiArai | 0:308d4fafaafb | 516 | /* Open a file */ |
kenjiArai | 0:308d4fafaafb | 517 | f_res = f_open(&File1, ptr, FA_READ); |
kenjiArai | 0:308d4fafaafb | 518 | if ( f_res ) { |
kenjiArai | 0:308d4fafaafb | 519 | put_rc((FRESULT)f_res); |
kenjiArai | 0:308d4fafaafb | 520 | break; |
kenjiArai | 0:308d4fafaafb | 521 | } |
kenjiArai | 0:308d4fafaafb | 522 | DEBUG_LINE; |
kenjiArai | 0:308d4fafaafb | 523 | /* Read all lines and display it */ |
kenjiArai | 0:308d4fafaafb | 524 | while(true) { |
kenjiArai | 0:308d4fafaafb | 525 | f_res = f_read(&File1, (TCHAR*)Buff, blen, &cnt); |
kenjiArai | 0:308d4fafaafb | 526 | if ( f_res ) { |
kenjiArai | 0:308d4fafaafb | 527 | put_rc((FRESULT)f_res); |
kenjiArai | 0:308d4fafaafb | 528 | break; |
kenjiArai | 0:308d4fafaafb | 529 | } |
kenjiArai | 0:308d4fafaafb | 530 | for (s1 = 0; s1 < cnt; s1++) { |
kenjiArai | 0:308d4fafaafb | 531 | PUTC(Buff[s1]); |
kenjiArai | 0:308d4fafaafb | 532 | } |
kenjiArai | 0:308d4fafaafb | 533 | if (cnt != blen) { |
kenjiArai | 0:308d4fafaafb | 534 | break; |
kenjiArai | 0:308d4fafaafb | 535 | } |
kenjiArai | 0:308d4fafaafb | 536 | } |
kenjiArai | 0:308d4fafaafb | 537 | DEBUG_LINE; |
kenjiArai | 0:308d4fafaafb | 538 | /* Close the file */ |
kenjiArai | 0:308d4fafaafb | 539 | f_close(&File1); |
kenjiArai | 0:308d4fafaafb | 540 | break; |
kenjiArai | 0:308d4fafaafb | 541 | |
kenjiArai | 0:308d4fafaafb | 542 | case 'i' : /* fi [<opt>]- Initialize logical drive */ |
kenjiArai | 0:308d4fafaafb | 543 | if ( !xatoi(&ptr, &p1) ) { |
kenjiArai | 0:308d4fafaafb | 544 | break; |
kenjiArai | 0:308d4fafaafb | 545 | } |
kenjiArai | 0:308d4fafaafb | 546 | if (!xatoi(&ptr, &p2)) p2 = 0; |
kenjiArai | 0:308d4fafaafb | 547 | put_rc(f_mount(&Fatfs[p1], (const TCHAR*)p1, 0)); |
kenjiArai | 0:308d4fafaafb | 548 | break; |
kenjiArai | 0:308d4fafaafb | 549 | |
kenjiArai | 0:308d4fafaafb | 550 | case 's' : /* fs [<path>] - Show volume status */ |
kenjiArai | 0:308d4fafaafb | 551 | f_res = f_getfree( ptr, (DWORD*)&p2, &fs ); |
kenjiArai | 0:308d4fafaafb | 552 | if ( f_res ) { |
kenjiArai | 0:308d4fafaafb | 553 | put_rc((FRESULT)f_res); |
kenjiArai | 0:308d4fafaafb | 554 | break; |
kenjiArai | 0:308d4fafaafb | 555 | } |
kenjiArai | 0:308d4fafaafb | 556 | PRINTF |
kenjiArai | 0:308d4fafaafb | 557 | ( |
kenjiArai | 0:308d4fafaafb | 558 | "\rFAT type = FAT%u\r\nBytes/Cluster" |
kenjiArai | 0:308d4fafaafb | 559 | " = %lu\r\nNumber of FATs = %u\r\n" |
kenjiArai | 0:308d4fafaafb | 560 | "Root DIR entries = %u\r\n" |
kenjiArai | 0:308d4fafaafb | 561 | "Sectors/FAT = %lu\r\n" |
kenjiArai | 0:308d4fafaafb | 562 | "Number of clusters = %lu\r\n" |
kenjiArai | 0:308d4fafaafb | 563 | "FAT start (lba) = %lu\r\n" |
kenjiArai | 0:308d4fafaafb | 564 | "DIR start (lba,clustor) = %lu\r\n" |
kenjiArai | 0:308d4fafaafb | 565 | "Data start (lba) = %lu\r\n", |
kenjiArai | 0:308d4fafaafb | 566 | ft[fs->fs_type & 3], (DWORD)fs->csize * 512, fs->n_fats, |
kenjiArai | 0:308d4fafaafb | 567 | fs->n_rootdir, fs->fsize, (DWORD)fs->n_fatent - 2, |
kenjiArai | 0:308d4fafaafb | 568 | fs->fatbase, fs->dirbase, fs->database |
kenjiArai | 0:308d4fafaafb | 569 | ); |
kenjiArai | 0:308d4fafaafb | 570 | AccSize = AccFiles = AccDirs = 0; |
kenjiArai | 0:308d4fafaafb | 571 | break; |
kenjiArai | 0:308d4fafaafb | 572 | case 'l' : /* fl [<path>] - Directory listing */ |
kenjiArai | 0:308d4fafaafb | 573 | while (*ptr == ' ') ptr++; |
kenjiArai | 0:308d4fafaafb | 574 | res = f_opendir(Dirx, ptr); |
kenjiArai | 0:308d4fafaafb | 575 | if (res) { |
kenjiArai | 0:308d4fafaafb | 576 | put_rc((FRESULT)res); |
kenjiArai | 0:308d4fafaafb | 577 | break; |
kenjiArai | 0:308d4fafaafb | 578 | } |
kenjiArai | 0:308d4fafaafb | 579 | p1 = s1 = s2 = 0; |
kenjiArai | 0:308d4fafaafb | 580 | for(;;) { |
kenjiArai | 0:308d4fafaafb | 581 | res = f_readdir(Dirx, &Finfo); |
kenjiArai | 0:308d4fafaafb | 582 | if ((res != FR_OK) || !Finfo.fname[0]) break; |
kenjiArai | 0:308d4fafaafb | 583 | if (Finfo.fattrib & AM_DIR) { |
kenjiArai | 0:308d4fafaafb | 584 | s2++; |
kenjiArai | 0:308d4fafaafb | 585 | } else { |
kenjiArai | 0:308d4fafaafb | 586 | s1++; |
kenjiArai | 0:308d4fafaafb | 587 | p1 += Finfo.fsize; |
kenjiArai | 0:308d4fafaafb | 588 | } |
kenjiArai | 0:308d4fafaafb | 589 | PRINTF("%c%c%c%c%c %u/%02u/%02u %02u:%02u %9lu %s\r\n", |
kenjiArai | 0:308d4fafaafb | 590 | (Finfo.fattrib & AM_DIR) ? 'D' : '-', |
kenjiArai | 0:308d4fafaafb | 591 | (Finfo.fattrib & AM_RDO) ? 'R' : '-', |
kenjiArai | 0:308d4fafaafb | 592 | (Finfo.fattrib & AM_HID) ? 'H' : '-', |
kenjiArai | 0:308d4fafaafb | 593 | (Finfo.fattrib & AM_SYS) ? 'S' : '-', |
kenjiArai | 0:308d4fafaafb | 594 | (Finfo.fattrib & AM_ARC) ? 'A' : '-', |
kenjiArai | 0:308d4fafaafb | 595 | (Finfo.fdate >> 9) + 1980, (Finfo.fdate >> 5) & 15, |
kenjiArai | 0:308d4fafaafb | 596 | Finfo.fdate & 31, |
kenjiArai | 0:308d4fafaafb | 597 | (Finfo.ftime >> 11), (Finfo.ftime >> 5) & 63, |
kenjiArai | 0:308d4fafaafb | 598 | Finfo.fsize, Finfo.fname); |
kenjiArai | 0:308d4fafaafb | 599 | } |
kenjiArai | 0:308d4fafaafb | 600 | #if 0 // f_getfree cannnot count under Dir, subdirectory area |
kenjiArai | 0:308d4fafaafb | 601 | PRINTF("%4u File(s),%10lu bytes total\r\n%4u Dir(s)", s1, p1, s2); |
kenjiArai | 0:308d4fafaafb | 602 | res = f_getfree(ptr, (DWORD*)&p1, &fs); |
kenjiArai | 0:308d4fafaafb | 603 | if (res == FR_OK) |
kenjiArai | 0:308d4fafaafb | 604 | PRINTF(", %10lu bytes free\r\n", p1 * fs->csize * 512); |
kenjiArai | 0:308d4fafaafb | 605 | else |
kenjiArai | 0:308d4fafaafb | 606 | put_rc((FRESULT)res); |
kenjiArai | 0:308d4fafaafb | 607 | #else |
kenjiArai | 0:308d4fafaafb | 608 | PRINTF("%4u File(s) = %10lu bytes total, %4u Dir(s)\r\n", |
kenjiArai | 0:308d4fafaafb | 609 | s1, p1, s2); |
kenjiArai | 0:308d4fafaafb | 610 | #endif |
kenjiArai | 0:308d4fafaafb | 611 | break; |
kenjiArai | 0:308d4fafaafb | 612 | |
kenjiArai | 0:308d4fafaafb | 613 | case 'o' : /* fo <mode> <file> - Open a file */ |
kenjiArai | 0:308d4fafaafb | 614 | if (!xatoi(&ptr, &p1)) break; |
kenjiArai | 0:308d4fafaafb | 615 | while (*ptr == ' ') ptr++; |
kenjiArai | 0:308d4fafaafb | 616 | put_rc(f_open(&File1, ptr, (BYTE)p1)); |
kenjiArai | 0:308d4fafaafb | 617 | #if 0 |
kenjiArai | 0:308d4fafaafb | 618 | put_rc(f_open(&File1, "savedata.txt", 1)); |
kenjiArai | 0:308d4fafaafb | 619 | PRINTF("Open savedata.txt as read mode\r\n"); |
kenjiArai | 0:308d4fafaafb | 620 | #endif |
kenjiArai | 0:308d4fafaafb | 621 | break; |
kenjiArai | 0:308d4fafaafb | 622 | |
kenjiArai | 0:308d4fafaafb | 623 | case 'c' : /* fc - Close a file */ |
kenjiArai | 0:308d4fafaafb | 624 | put_rc(f_close(&File1)); |
kenjiArai | 0:308d4fafaafb | 625 | break; |
kenjiArai | 0:308d4fafaafb | 626 | |
kenjiArai | 0:308d4fafaafb | 627 | case 'e' : /* fe - Seek file pointer */ |
kenjiArai | 0:308d4fafaafb | 628 | if (!xatoi(&ptr, &p1)) break; |
kenjiArai | 0:308d4fafaafb | 629 | res = f_lseek(&File1, p1); |
kenjiArai | 0:308d4fafaafb | 630 | put_rc((FRESULT)res); |
kenjiArai | 0:308d4fafaafb | 631 | if (res == FR_OK) |
kenjiArai | 0:308d4fafaafb | 632 | PRINTF("fptr=%lu(0x%lX)\r\n", File1.fptr, File1.fptr); |
kenjiArai | 0:308d4fafaafb | 633 | break; |
kenjiArai | 0:308d4fafaafb | 634 | |
kenjiArai | 0:308d4fafaafb | 635 | case 'd' : /* fd <len> - read and dump file from current fp */ |
kenjiArai | 0:308d4fafaafb | 636 | if (!xatoi(&ptr, &p1)) break; |
kenjiArai | 0:308d4fafaafb | 637 | ofs = File1.fptr; |
kenjiArai | 0:308d4fafaafb | 638 | while (p1) { |
kenjiArai | 0:308d4fafaafb | 639 | if ((UINT)p1 >= 16) { |
kenjiArai | 0:308d4fafaafb | 640 | cnt = 16; |
kenjiArai | 0:308d4fafaafb | 641 | p1 -= 16; |
kenjiArai | 0:308d4fafaafb | 642 | } else { |
kenjiArai | 0:308d4fafaafb | 643 | cnt = p1; |
kenjiArai | 0:308d4fafaafb | 644 | p1 = 0; |
kenjiArai | 0:308d4fafaafb | 645 | } |
kenjiArai | 0:308d4fafaafb | 646 | res = f_read(&File1, Buff, cnt, &cnt); |
kenjiArai | 0:308d4fafaafb | 647 | if (res != FR_OK) { |
kenjiArai | 0:308d4fafaafb | 648 | put_rc((FRESULT)res); |
kenjiArai | 0:308d4fafaafb | 649 | break; |
kenjiArai | 0:308d4fafaafb | 650 | } |
kenjiArai | 0:308d4fafaafb | 651 | if (!cnt) break; |
kenjiArai | 0:308d4fafaafb | 652 | put_dump(Buff, ofs, cnt, DW_CHAR); |
kenjiArai | 0:308d4fafaafb | 653 | ofs += 16; |
kenjiArai | 0:308d4fafaafb | 654 | } |
kenjiArai | 0:308d4fafaafb | 655 | break; |
kenjiArai | 0:308d4fafaafb | 656 | |
kenjiArai | 0:308d4fafaafb | 657 | case 'r' : /* fr <len> - read file */ |
kenjiArai | 0:308d4fafaafb | 658 | if (!xatoi(&ptr, &p1)) break; |
kenjiArai | 0:308d4fafaafb | 659 | p2 = 0; |
kenjiArai | 0:308d4fafaafb | 660 | t.reset(); |
kenjiArai | 0:308d4fafaafb | 661 | t.start(); |
kenjiArai | 0:308d4fafaafb | 662 | while (p1) { |
kenjiArai | 0:308d4fafaafb | 663 | if ((UINT)p1 >= blen) { |
kenjiArai | 0:308d4fafaafb | 664 | cnt = blen; |
kenjiArai | 0:308d4fafaafb | 665 | p1 -= blen; |
kenjiArai | 0:308d4fafaafb | 666 | } else { |
kenjiArai | 0:308d4fafaafb | 667 | cnt = p1; |
kenjiArai | 0:308d4fafaafb | 668 | p1 = 0; |
kenjiArai | 0:308d4fafaafb | 669 | } |
kenjiArai | 0:308d4fafaafb | 670 | res = f_read(&File1, Buff, cnt, &s2); |
kenjiArai | 0:308d4fafaafb | 671 | if (res != FR_OK) { |
kenjiArai | 0:308d4fafaafb | 672 | put_rc((FRESULT)res); |
kenjiArai | 0:308d4fafaafb | 673 | break; |
kenjiArai | 0:308d4fafaafb | 674 | } |
kenjiArai | 0:308d4fafaafb | 675 | p2 += s2; |
kenjiArai | 0:308d4fafaafb | 676 | if (cnt != s2) break; |
kenjiArai | 0:308d4fafaafb | 677 | } |
kenjiArai | 0:308d4fafaafb | 678 | tim = t.read_ms(); |
kenjiArai | 0:308d4fafaafb | 679 | PRINTF("%lu bytes read with %lu kB/sec.\r\n", |
kenjiArai | 0:308d4fafaafb | 680 | p2, tim ? (p2 / tim) : 0); |
kenjiArai | 0:308d4fafaafb | 681 | break; |
kenjiArai | 0:308d4fafaafb | 682 | |
kenjiArai | 0:308d4fafaafb | 683 | case 'w' : /* fw <len> <val> - write file */ |
kenjiArai | 0:308d4fafaafb | 684 | if (!xatoi(&ptr, &p1) || !xatoi(&ptr, &p2)) break; |
kenjiArai | 0:308d4fafaafb | 685 | memset(Buff, (BYTE)p2, blen); |
kenjiArai | 0:308d4fafaafb | 686 | p2 = 0; |
kenjiArai | 0:308d4fafaafb | 687 | t.reset(); |
kenjiArai | 0:308d4fafaafb | 688 | t.start(); |
kenjiArai | 0:308d4fafaafb | 689 | while (p1) { |
kenjiArai | 0:308d4fafaafb | 690 | if ((UINT)p1 >= blen) { |
kenjiArai | 0:308d4fafaafb | 691 | cnt = blen; |
kenjiArai | 0:308d4fafaafb | 692 | p1 -= blen; |
kenjiArai | 0:308d4fafaafb | 693 | } else { |
kenjiArai | 0:308d4fafaafb | 694 | cnt = p1; |
kenjiArai | 0:308d4fafaafb | 695 | p1 = 0; |
kenjiArai | 0:308d4fafaafb | 696 | } |
kenjiArai | 0:308d4fafaafb | 697 | res = f_write(&File1, Buff, cnt, &s2); |
kenjiArai | 0:308d4fafaafb | 698 | if (res != FR_OK) { |
kenjiArai | 0:308d4fafaafb | 699 | put_rc((FRESULT)res); |
kenjiArai | 0:308d4fafaafb | 700 | break; |
kenjiArai | 0:308d4fafaafb | 701 | } |
kenjiArai | 0:308d4fafaafb | 702 | p2 += s2; |
kenjiArai | 0:308d4fafaafb | 703 | if (cnt != s2) break; |
kenjiArai | 0:308d4fafaafb | 704 | } |
kenjiArai | 0:308d4fafaafb | 705 | tim = t.read_ms(); |
kenjiArai | 0:308d4fafaafb | 706 | PRINTF("%lu bytes written with %lu kB/sec.\r\n", |
kenjiArai | 0:308d4fafaafb | 707 | p2, tim ? (p2 / tim) : 0); |
kenjiArai | 0:308d4fafaafb | 708 | break; |
kenjiArai | 0:308d4fafaafb | 709 | |
kenjiArai | 0:308d4fafaafb | 710 | case 'n' : /* fn <org.name> <new.name> - Change name of an object */ |
kenjiArai | 0:308d4fafaafb | 711 | while (*ptr == ' ') ptr++; |
kenjiArai | 0:308d4fafaafb | 712 | ptr2 = strchr(ptr, ' '); |
kenjiArai | 0:308d4fafaafb | 713 | if (!ptr2) break; |
kenjiArai | 0:308d4fafaafb | 714 | *ptr2++ = 0; |
kenjiArai | 0:308d4fafaafb | 715 | while (*ptr2 == ' ') ptr2++; |
kenjiArai | 0:308d4fafaafb | 716 | put_rc(f_rename(ptr, ptr2)); |
kenjiArai | 0:308d4fafaafb | 717 | break; |
kenjiArai | 0:308d4fafaafb | 718 | |
kenjiArai | 0:308d4fafaafb | 719 | case 'u' : /* fu <name> - Unlink an object */ |
kenjiArai | 0:308d4fafaafb | 720 | while (*ptr == ' ') ptr++; |
kenjiArai | 0:308d4fafaafb | 721 | put_rc(f_unlink(ptr)); |
kenjiArai | 0:308d4fafaafb | 722 | break; |
kenjiArai | 0:308d4fafaafb | 723 | |
kenjiArai | 0:308d4fafaafb | 724 | case 'v' : /* fv - Truncate file */ |
kenjiArai | 0:308d4fafaafb | 725 | put_rc(f_truncate(&File1)); |
kenjiArai | 0:308d4fafaafb | 726 | break; |
kenjiArai | 0:308d4fafaafb | 727 | |
kenjiArai | 0:308d4fafaafb | 728 | case 'k' : /* fk <name> - Create a directory */ |
kenjiArai | 0:308d4fafaafb | 729 | while (*ptr == ' ') ptr++; |
kenjiArai | 0:308d4fafaafb | 730 | put_rc(f_mkdir(ptr)); |
kenjiArai | 0:308d4fafaafb | 731 | break; |
kenjiArai | 0:308d4fafaafb | 732 | #if 0 |
kenjiArai | 0:308d4fafaafb | 733 | case 'a' : /* fa <atrr> <mask> <name> - Change attribute of an object */ |
kenjiArai | 0:308d4fafaafb | 734 | if (!xatoi(&ptr, &p1) || !xatoi(&ptr, &p2)) break; |
kenjiArai | 0:308d4fafaafb | 735 | while (*ptr == ' ') ptr++; |
kenjiArai | 0:308d4fafaafb | 736 | put_rc(f_chmod(ptr, p1, p2)); |
kenjiArai | 0:308d4fafaafb | 737 | break; |
kenjiArai | 0:308d4fafaafb | 738 | #endif |
kenjiArai | 0:308d4fafaafb | 739 | #if 0 |
kenjiArai | 0:308d4fafaafb | 740 | /* ft <year> <month> <day> <hour> <min> <sec> <name> |
kenjiArai | 0:308d4fafaafb | 741 | - Change timestamp of an object */ |
kenjiArai | 0:308d4fafaafb | 742 | case 't' : |
kenjiArai | 0:308d4fafaafb | 743 | if (!xatoi(&ptr, &p1) || !xatoi(&ptr, &p2) || !xatoi(&ptr, &p3)) { |
kenjiArai | 0:308d4fafaafb | 744 | break; |
kenjiArai | 0:308d4fafaafb | 745 | } |
kenjiArai | 0:308d4fafaafb | 746 | Finfo.fdate = ((p1 - 1980) << 9) | ((p2 & 15) << 5) | (p3 & 31); |
kenjiArai | 0:308d4fafaafb | 747 | if (!xatoi(&ptr, &p1) || !xatoi(&ptr, &p2) || !xatoi(&ptr, &p3)) { |
kenjiArai | 0:308d4fafaafb | 748 | break; |
kenjiArai | 0:308d4fafaafb | 749 | } |
kenjiArai | 0:308d4fafaafb | 750 | Finfo.ftime = |
kenjiArai | 0:308d4fafaafb | 751 | ((p1 & 31) << 11) | ((p2 & 63) << 5) | ((p3 >> 1) & 31); |
kenjiArai | 0:308d4fafaafb | 752 | put_rc(f_utime(ptr, &Finfo)); |
kenjiArai | 0:308d4fafaafb | 753 | break; |
kenjiArai | 0:308d4fafaafb | 754 | #endif |
kenjiArai | 0:308d4fafaafb | 755 | #if FILCPY_NOTUSE == 0 |
kenjiArai | 0:308d4fafaafb | 756 | case 'x' : /* fx <src_name> <dst_name> - Copy file */ |
kenjiArai | 0:308d4fafaafb | 757 | while ( *ptr == ' ' ) { |
kenjiArai | 0:308d4fafaafb | 758 | ptr++; |
kenjiArai | 0:308d4fafaafb | 759 | } |
kenjiArai | 0:308d4fafaafb | 760 | ptr2 = strchr( ptr, ' ' ); |
kenjiArai | 0:308d4fafaafb | 761 | if ( !ptr2 ) { |
kenjiArai | 0:308d4fafaafb | 762 | break; |
kenjiArai | 0:308d4fafaafb | 763 | } |
kenjiArai | 0:308d4fafaafb | 764 | *ptr2++ = 0; |
kenjiArai | 0:308d4fafaafb | 765 | while ( *ptr2 == ' ' ) { |
kenjiArai | 0:308d4fafaafb | 766 | ptr2++; |
kenjiArai | 0:308d4fafaafb | 767 | } |
kenjiArai | 0:308d4fafaafb | 768 | f_res = f_open( &File1, ptr, FA_OPEN_EXISTING | FA_READ ); |
kenjiArai | 0:308d4fafaafb | 769 | PRINTF("Opening %s \r\n", ptr); |
kenjiArai | 0:308d4fafaafb | 770 | if ( f_res ) { |
kenjiArai | 0:308d4fafaafb | 771 | put_rc( (FRESULT)f_res ); |
kenjiArai | 0:308d4fafaafb | 772 | break; |
kenjiArai | 0:308d4fafaafb | 773 | } |
kenjiArai | 0:308d4fafaafb | 774 | f_res = f_open( &File2, ptr2, FA_CREATE_ALWAYS | FA_WRITE ); |
kenjiArai | 0:308d4fafaafb | 775 | PRINTF(" Creating %s \r\n", ptr2); |
kenjiArai | 0:308d4fafaafb | 776 | if ( f_res ) { |
kenjiArai | 0:308d4fafaafb | 777 | put_rc( (FRESULT)f_res ); |
kenjiArai | 0:308d4fafaafb | 778 | f_close( &File1 ); |
kenjiArai | 0:308d4fafaafb | 779 | break; |
kenjiArai | 0:308d4fafaafb | 780 | } |
kenjiArai | 0:308d4fafaafb | 781 | PRINTF("Copying file..."); |
kenjiArai | 0:308d4fafaafb | 782 | p1 = 0; |
kenjiArai | 0:308d4fafaafb | 783 | for ( ;; ) { |
kenjiArai | 0:308d4fafaafb | 784 | f_res = f_read( &File1, Buff, blen, &s1 ); |
kenjiArai | 0:308d4fafaafb | 785 | if ( f_res || s1 == 0 ) { |
kenjiArai | 0:308d4fafaafb | 786 | break; /* error or eof */ |
kenjiArai | 0:308d4fafaafb | 787 | } |
kenjiArai | 0:308d4fafaafb | 788 | f_res = f_write( &File2, Buff, s1, &s2 ); |
kenjiArai | 0:308d4fafaafb | 789 | p1 += s2; |
kenjiArai | 0:308d4fafaafb | 790 | if ( f_res || s2 < s1 ) { |
kenjiArai | 0:308d4fafaafb | 791 | break; /* error or disk full */ |
kenjiArai | 0:308d4fafaafb | 792 | } |
kenjiArai | 0:308d4fafaafb | 793 | } |
kenjiArai | 0:308d4fafaafb | 794 | f_close( &File1 ); |
kenjiArai | 0:308d4fafaafb | 795 | f_close( &File2 ); |
kenjiArai | 0:308d4fafaafb | 796 | crlf(); |
kenjiArai | 0:308d4fafaafb | 797 | break; |
kenjiArai | 0:308d4fafaafb | 798 | #endif |
kenjiArai | 0:308d4fafaafb | 799 | #if 0 |
kenjiArai | 0:308d4fafaafb | 800 | case 'x' : /* fx <src.name> <dst.name> - Copy a file */ |
kenjiArai | 0:308d4fafaafb | 801 | while (*ptr == ' ') ptr++; |
kenjiArai | 0:308d4fafaafb | 802 | ptr2 = strchr(ptr, ' '); |
kenjiArai | 0:308d4fafaafb | 803 | if (!ptr2) break; |
kenjiArai | 0:308d4fafaafb | 804 | *ptr2++ = 0; |
kenjiArai | 0:308d4fafaafb | 805 | while (*ptr2 == ' ') ptr2++; |
kenjiArai | 0:308d4fafaafb | 806 | PRINTF("Opening \"%s\"", ptr); |
kenjiArai | 0:308d4fafaafb | 807 | res = f_open(&File1, ptr, FA_OPEN_EXISTING | FA_READ); |
kenjiArai | 0:308d4fafaafb | 808 | PUTS("\r\n"); |
kenjiArai | 0:308d4fafaafb | 809 | if (res) { |
kenjiArai | 0:308d4fafaafb | 810 | put_rc((FRESULT)res); |
kenjiArai | 0:308d4fafaafb | 811 | break; |
kenjiArai | 0:308d4fafaafb | 812 | } |
kenjiArai | 0:308d4fafaafb | 813 | PRINTF("Creating \"%s\"", ptr2); |
kenjiArai | 0:308d4fafaafb | 814 | res = f_open(&File1, ptr2, FA_CREATE_ALWAYS | FA_WRITE); |
kenjiArai | 0:308d4fafaafb | 815 | PUTS("\r\n"); |
kenjiArai | 0:308d4fafaafb | 816 | if (res) { |
kenjiArai | 0:308d4fafaafb | 817 | put_rc((FRESULT)res); |
kenjiArai | 0:308d4fafaafb | 818 | f_close(&File1); |
kenjiArai | 0:308d4fafaafb | 819 | break; |
kenjiArai | 0:308d4fafaafb | 820 | } |
kenjiArai | 0:308d4fafaafb | 821 | PRINTF("Copying file..."); |
kenjiArai | 0:308d4fafaafb | 822 | t.reset(); |
kenjiArai | 0:308d4fafaafb | 823 | t.start(); |
kenjiArai | 0:308d4fafaafb | 824 | p1 = 0; |
kenjiArai | 0:308d4fafaafb | 825 | for (;;) { |
kenjiArai | 0:308d4fafaafb | 826 | res = f_read(&File1, Buff, blen, &s1); |
kenjiArai | 0:308d4fafaafb | 827 | if (res || s1 == 0) break; /* error or eof */ |
kenjiArai | 0:308d4fafaafb | 828 | res = f_write(&File2, Buff, s1, &s2); |
kenjiArai | 0:308d4fafaafb | 829 | p1 += s2; |
kenjiArai | 0:308d4fafaafb | 830 | if (res || s2 < s1) break; /* error or disk full */ |
kenjiArai | 0:308d4fafaafb | 831 | } |
kenjiArai | 0:308d4fafaafb | 832 | tim = t.read_ms(); |
kenjiArai | 0:308d4fafaafb | 833 | PRINTF("\r\n%lu bytes copied with %lu kB/sec.\r\n", |
kenjiArai | 0:308d4fafaafb | 834 | p1, tim ? (p1 / tim) : 0); |
kenjiArai | 0:308d4fafaafb | 835 | f_close(&File1); |
kenjiArai | 0:308d4fafaafb | 836 | f_close(&File2); |
kenjiArai | 0:308d4fafaafb | 837 | break; |
kenjiArai | 0:308d4fafaafb | 838 | #endif |
kenjiArai | 0:308d4fafaafb | 839 | #if FF_FS_RPATH |
kenjiArai | 0:308d4fafaafb | 840 | case 'g' : /* fg <path> - Change current directory */ |
kenjiArai | 0:308d4fafaafb | 841 | while (*ptr == ' ') ptr++; |
kenjiArai | 0:308d4fafaafb | 842 | put_rc(f_chdir(ptr)); |
kenjiArai | 0:308d4fafaafb | 843 | break; |
kenjiArai | 0:308d4fafaafb | 844 | #if FF_FS_RPATH >= 2 |
kenjiArai | 0:308d4fafaafb | 845 | case 'q' : /* fq - Show current dir path */ |
kenjiArai | 0:308d4fafaafb | 846 | res = f_getcwd(Linebuf, sizeof Linebuf); |
kenjiArai | 0:308d4fafaafb | 847 | if (res) |
kenjiArai | 0:308d4fafaafb | 848 | put_rc(res); |
kenjiArai | 0:308d4fafaafb | 849 | else |
kenjiArai | 0:308d4fafaafb | 850 | PRINTF("%s\r\n", Linebuf); |
kenjiArai | 0:308d4fafaafb | 851 | break; |
kenjiArai | 0:308d4fafaafb | 852 | #endif |
kenjiArai | 0:308d4fafaafb | 853 | #endif |
kenjiArai | 0:308d4fafaafb | 854 | #if FF_USE_LABEL |
kenjiArai | 0:308d4fafaafb | 855 | case 'b' : /* fb <name> - Set volume label */ |
kenjiArai | 0:308d4fafaafb | 856 | while (*ptr == ' ') ptr++; |
kenjiArai | 0:308d4fafaafb | 857 | put_rc(f_setlabel(ptr)); |
kenjiArai | 0:308d4fafaafb | 858 | break; |
kenjiArai | 0:308d4fafaafb | 859 | #endif /* FF_USE_LABEL */ |
kenjiArai | 0:308d4fafaafb | 860 | #if FF_USE_MKFS |
kenjiArai | 0:308d4fafaafb | 861 | case 'm' : /* fm <type> <csize> - Create file system */ |
kenjiArai | 0:308d4fafaafb | 862 | if (!xatoi(&ptr, &p2) || !xatoi(&ptr, &p3)) break; |
kenjiArai | 0:308d4fafaafb | 863 | PRINTF("The volume will be formatted. Are you sure? (Y/n)="); |
kenjiArai | 0:308d4fafaafb | 864 | get_line(Linebuf, sizeof Linebuf); |
kenjiArai | 0:308d4fafaafb | 865 | if (Linebuf[0] == 'Y') |
kenjiArai | 0:308d4fafaafb | 866 | put_rc(f_mkfs("", (BYTE)p2, (DWORD)p3, Buff, sizeof Buff)); |
kenjiArai | 0:308d4fafaafb | 867 | break; |
kenjiArai | 0:308d4fafaafb | 868 | #endif /* FF_USE_MKFS */ |
kenjiArai | 0:308d4fafaafb | 869 | /* fz [<size>] - Change/Show R/W length for fr/fw/fx command */ |
kenjiArai | 0:308d4fafaafb | 870 | case 'z' : |
kenjiArai | 0:308d4fafaafb | 871 | if (xatoi(&ptr, &p1) && p1 >= 1 && p1 <= (long)sizeof Buff) |
kenjiArai | 0:308d4fafaafb | 872 | blen = p1; |
kenjiArai | 0:308d4fafaafb | 873 | PRINTF("blen=%u\r\n", blen); |
kenjiArai | 0:308d4fafaafb | 874 | break; |
kenjiArai | 0:308d4fafaafb | 875 | } |
kenjiArai | 0:308d4fafaafb | 876 | } |
kenjiArai | 0:308d4fafaafb | 877 | |
kenjiArai | 0:308d4fafaafb | 878 | static void memory_inf(char *ptr) |
kenjiArai | 0:308d4fafaafb | 879 | { |
kenjiArai | 0:308d4fafaafb | 880 | long p1, p2, p3; |
kenjiArai | 0:308d4fafaafb | 881 | |
kenjiArai | 0:308d4fafaafb | 882 | switch (*ptr++) { |
kenjiArai | 0:308d4fafaafb | 883 | case 'd' : /* md[b|h|w] <address> [<count>] - Dump memory */ |
kenjiArai | 0:308d4fafaafb | 884 | switch (*ptr++) { |
kenjiArai | 0:308d4fafaafb | 885 | case 'w': |
kenjiArai | 0:308d4fafaafb | 886 | p3 = DW_LONG; |
kenjiArai | 0:308d4fafaafb | 887 | break; |
kenjiArai | 0:308d4fafaafb | 888 | case 'h': |
kenjiArai | 0:308d4fafaafb | 889 | p3 = DW_SHORT; |
kenjiArai | 0:308d4fafaafb | 890 | break; |
kenjiArai | 0:308d4fafaafb | 891 | default: |
kenjiArai | 0:308d4fafaafb | 892 | p3 = DW_CHAR; |
kenjiArai | 0:308d4fafaafb | 893 | } |
kenjiArai | 0:308d4fafaafb | 894 | if (!xatoi(&ptr, &p1)) break; |
kenjiArai | 0:308d4fafaafb | 895 | if (!xatoi(&ptr, &p2)) p2 = 128 / p3; |
kenjiArai | 0:308d4fafaafb | 896 | for (ptr = (char*)p1; p2 >= 16 / p3; ptr += 16, p2 -= 16 / p3) |
kenjiArai | 0:308d4fafaafb | 897 | put_dump(ptr, (DWORD)ptr, 16 / p3, p3); |
kenjiArai | 0:308d4fafaafb | 898 | if (p2) put_dump((BYTE*)ptr, (UINT)ptr, p2, p3); |
kenjiArai | 0:308d4fafaafb | 899 | break; |
kenjiArai | 0:308d4fafaafb | 900 | case 'f' : /* mf <address> <value> <count> - Fill memory */ |
kenjiArai | 0:308d4fafaafb | 901 | if (!xatoi(&ptr, &p1) || !xatoi(&ptr, &p2) || !xatoi(&ptr, &p3)) { |
kenjiArai | 0:308d4fafaafb | 902 | break; |
kenjiArai | 0:308d4fafaafb | 903 | } |
kenjiArai | 0:308d4fafaafb | 904 | while (p3--) { |
kenjiArai | 0:308d4fafaafb | 905 | *(BYTE*)p1 = (BYTE)p2; |
kenjiArai | 0:308d4fafaafb | 906 | p1++; |
kenjiArai | 0:308d4fafaafb | 907 | } |
kenjiArai | 0:308d4fafaafb | 908 | break; |
kenjiArai | 0:308d4fafaafb | 909 | case 'e' : /* me[b|h|w] <address> [<value> ...] - Edit memory */ |
kenjiArai | 0:308d4fafaafb | 910 | switch (*ptr++) { /* Get data width */ |
kenjiArai | 0:308d4fafaafb | 911 | case 'w': |
kenjiArai | 0:308d4fafaafb | 912 | p3 = DW_LONG; |
kenjiArai | 0:308d4fafaafb | 913 | break; |
kenjiArai | 0:308d4fafaafb | 914 | case 'h': |
kenjiArai | 0:308d4fafaafb | 915 | p3 = DW_SHORT; |
kenjiArai | 0:308d4fafaafb | 916 | break; |
kenjiArai | 0:308d4fafaafb | 917 | default: |
kenjiArai | 0:308d4fafaafb | 918 | p3 = DW_CHAR; |
kenjiArai | 0:308d4fafaafb | 919 | } |
kenjiArai | 0:308d4fafaafb | 920 | if (!xatoi(&ptr, &p1)) break; /* Get start address */ |
kenjiArai | 0:308d4fafaafb | 921 | if (xatoi(&ptr, &p2)) { /* 2nd parameter is given (direct mode) */ |
kenjiArai | 0:308d4fafaafb | 922 | do { |
kenjiArai | 0:308d4fafaafb | 923 | switch (p3) { |
kenjiArai | 0:308d4fafaafb | 924 | case DW_LONG: |
kenjiArai | 0:308d4fafaafb | 925 | *(DWORD*)p1 = (DWORD)p2; |
kenjiArai | 0:308d4fafaafb | 926 | break; |
kenjiArai | 0:308d4fafaafb | 927 | case DW_SHORT: |
kenjiArai | 0:308d4fafaafb | 928 | *(WORD*)p1 = (WORD)p2; |
kenjiArai | 0:308d4fafaafb | 929 | break; |
kenjiArai | 0:308d4fafaafb | 930 | default: |
kenjiArai | 0:308d4fafaafb | 931 | *(BYTE*)p1 = (BYTE)p2; |
kenjiArai | 0:308d4fafaafb | 932 | } |
kenjiArai | 0:308d4fafaafb | 933 | p1 += p3; |
kenjiArai | 0:308d4fafaafb | 934 | } while (xatoi(&ptr, &p2)); /* Get next value */ |
kenjiArai | 0:308d4fafaafb | 935 | break; |
kenjiArai | 0:308d4fafaafb | 936 | } |
kenjiArai | 0:308d4fafaafb | 937 | for (;;) { /* 2nd parameter is not given (interactive mode) */ |
kenjiArai | 0:308d4fafaafb | 938 | switch (p3) { |
kenjiArai | 0:308d4fafaafb | 939 | case DW_LONG: |
kenjiArai | 1:58fc0cbd9a41 | 940 | PRINTF("%08X 0x%08X-", (unsigned int)p1, *(unsigned int*)p1); |
kenjiArai | 0:308d4fafaafb | 941 | break; |
kenjiArai | 0:308d4fafaafb | 942 | case DW_SHORT: |
kenjiArai | 1:58fc0cbd9a41 | 943 | PRINTF("%08X 0x%04X-", (unsigned int)p1, *(WORD*)p1); |
kenjiArai | 0:308d4fafaafb | 944 | break; |
kenjiArai | 0:308d4fafaafb | 945 | default: |
kenjiArai | 1:58fc0cbd9a41 | 946 | PRINTF("%08X 0x%02X-", (unsigned int)p1, *(BYTE*)p1); |
kenjiArai | 0:308d4fafaafb | 947 | } |
kenjiArai | 0:308d4fafaafb | 948 | ptr = Linebuf; |
kenjiArai | 0:308d4fafaafb | 949 | get_line(ptr, sizeof Linebuf); |
kenjiArai | 0:308d4fafaafb | 950 | if (*ptr == '.') break; |
kenjiArai | 0:308d4fafaafb | 951 | if ((BYTE)*ptr >= ' ') { |
kenjiArai | 0:308d4fafaafb | 952 | if (!xatoi(&ptr, &p2)) continue; |
kenjiArai | 0:308d4fafaafb | 953 | switch (p3) { |
kenjiArai | 0:308d4fafaafb | 954 | case DW_LONG: |
kenjiArai | 0:308d4fafaafb | 955 | *(DWORD*)p1 = (DWORD)p2; |
kenjiArai | 0:308d4fafaafb | 956 | break; |
kenjiArai | 0:308d4fafaafb | 957 | case DW_SHORT: |
kenjiArai | 0:308d4fafaafb | 958 | *(WORD*)p1 = (WORD)p2; |
kenjiArai | 0:308d4fafaafb | 959 | break; |
kenjiArai | 0:308d4fafaafb | 960 | default: |
kenjiArai | 0:308d4fafaafb | 961 | *(BYTE*)p1 = (BYTE)p2; |
kenjiArai | 0:308d4fafaafb | 962 | } |
kenjiArai | 0:308d4fafaafb | 963 | } |
kenjiArai | 0:308d4fafaafb | 964 | p1 += p3; |
kenjiArai | 0:308d4fafaafb | 965 | } |
kenjiArai | 0:308d4fafaafb | 966 | } |
kenjiArai | 0:308d4fafaafb | 967 | } |
kenjiArai | 0:308d4fafaafb | 968 | |
kenjiArai | 0:308d4fafaafb | 969 | static void disk_inf(char *ptr) |
kenjiArai | 0:308d4fafaafb | 970 | { |
kenjiArai | 0:308d4fafaafb | 971 | long p1, p2; |
kenjiArai | 0:308d4fafaafb | 972 | UINT s1; |
kenjiArai | 0:308d4fafaafb | 973 | BYTE res, b, drv = 0; |
kenjiArai | 0:308d4fafaafb | 974 | DWORD ofs = 0, sect = 0, blk[2]; |
kenjiArai | 0:308d4fafaafb | 975 | |
kenjiArai | 0:308d4fafaafb | 976 | switch (*ptr++) { |
kenjiArai | 0:308d4fafaafb | 977 | case 'd' : /* dd [<pd#> <sect>] - Dump secrtor */ |
kenjiArai | 0:308d4fafaafb | 978 | if (!xatoi(&ptr, &p1)) { |
kenjiArai | 0:308d4fafaafb | 979 | p1 = drv; |
kenjiArai | 0:308d4fafaafb | 980 | p2 = sect; |
kenjiArai | 0:308d4fafaafb | 981 | } else { |
kenjiArai | 0:308d4fafaafb | 982 | if (!xatoi(&ptr, &p2)) break; |
kenjiArai | 0:308d4fafaafb | 983 | } |
kenjiArai | 0:308d4fafaafb | 984 | drv = (BYTE)p1; |
kenjiArai | 0:308d4fafaafb | 985 | sect = p2; |
kenjiArai | 0:308d4fafaafb | 986 | res = disk_read(drv, Buff, sect, 1); |
kenjiArai | 0:308d4fafaafb | 987 | if (res) { |
kenjiArai | 0:308d4fafaafb | 988 | PRINTF("rc=%d\r\n", (WORD)res); |
kenjiArai | 0:308d4fafaafb | 989 | break; |
kenjiArai | 0:308d4fafaafb | 990 | } |
kenjiArai | 0:308d4fafaafb | 991 | PRINTF("PD#:%u LBA:%lu\r\n", drv, sect++); |
kenjiArai | 0:308d4fafaafb | 992 | for (ptr=(char*)Buff, ofs = 0; ofs < 0x200; ptr += 16, ofs += 16) |
kenjiArai | 0:308d4fafaafb | 993 | put_dump((BYTE*)ptr, ofs, 16, DW_CHAR); |
kenjiArai | 0:308d4fafaafb | 994 | break; |
kenjiArai | 0:308d4fafaafb | 995 | |
kenjiArai | 0:308d4fafaafb | 996 | case 'i' : /* di <pd#> - Initialize disk */ |
kenjiArai | 0:308d4fafaafb | 997 | if (!xatoi(&ptr, &p1)) break; |
kenjiArai | 0:308d4fafaafb | 998 | PRINTF("rc=%d\r\n", (WORD)disk_initialize((BYTE)p1)); |
kenjiArai | 0:308d4fafaafb | 999 | break; |
kenjiArai | 0:308d4fafaafb | 1000 | |
kenjiArai | 0:308d4fafaafb | 1001 | case 's' : /* ds <pd#> - Show disk status */ |
kenjiArai | 0:308d4fafaafb | 1002 | if (!xatoi(&ptr, &p1)) break; |
kenjiArai | 0:308d4fafaafb | 1003 | if (disk_ioctl((BYTE)p1, GET_SECTOR_COUNT, &p2) == RES_OK) { |
kenjiArai | 0:308d4fafaafb | 1004 | PRINTF("Drive size: %lu sectors\r\n", p2); |
kenjiArai | 0:308d4fafaafb | 1005 | } |
kenjiArai | 0:308d4fafaafb | 1006 | if (disk_ioctl((BYTE)p1, GET_BLOCK_SIZE, &p2) == RES_OK) { |
kenjiArai | 0:308d4fafaafb | 1007 | PRINTF("Block size: %lu sectors\r\n", p2); |
kenjiArai | 0:308d4fafaafb | 1008 | } |
kenjiArai | 0:308d4fafaafb | 1009 | if (disk_ioctl((BYTE)p1, MMC_GET_TYPE, &b) == RES_OK) { |
kenjiArai | 0:308d4fafaafb | 1010 | PRINTF("Media type: %u\r\n", b); |
kenjiArai | 0:308d4fafaafb | 1011 | } |
kenjiArai | 0:308d4fafaafb | 1012 | if (disk_ioctl((BYTE)p1, MMC_GET_CSD, Buff) == RES_OK) { |
kenjiArai | 0:308d4fafaafb | 1013 | PUTS("CSD:\r\n"); |
kenjiArai | 0:308d4fafaafb | 1014 | put_dump(Buff, 0, 16, DW_CHAR); |
kenjiArai | 0:308d4fafaafb | 1015 | } |
kenjiArai | 0:308d4fafaafb | 1016 | if (disk_ioctl((BYTE)p1, MMC_GET_CID, Buff) == RES_OK) { |
kenjiArai | 0:308d4fafaafb | 1017 | PUTS("CID:\r\n"); |
kenjiArai | 0:308d4fafaafb | 1018 | put_dump(Buff, 0, 16, DW_CHAR); |
kenjiArai | 0:308d4fafaafb | 1019 | } |
kenjiArai | 0:308d4fafaafb | 1020 | if (disk_ioctl((BYTE)p1, MMC_GET_OCR, Buff) == RES_OK) { |
kenjiArai | 0:308d4fafaafb | 1021 | PUTS("OCR:\r\n"); |
kenjiArai | 0:308d4fafaafb | 1022 | put_dump(Buff, 0, 4, DW_CHAR); |
kenjiArai | 0:308d4fafaafb | 1023 | } |
kenjiArai | 0:308d4fafaafb | 1024 | if (disk_ioctl((BYTE)p1, MMC_GET_SDSTAT, Buff) == RES_OK) { |
kenjiArai | 0:308d4fafaafb | 1025 | PUTS("SD Status:\r\n"); |
kenjiArai | 0:308d4fafaafb | 1026 | for (s1 = 0; s1 < 64; s1 += 16) { |
kenjiArai | 0:308d4fafaafb | 1027 | put_dump(Buff+s1, s1, 16, DW_CHAR); |
kenjiArai | 0:308d4fafaafb | 1028 | } |
kenjiArai | 0:308d4fafaafb | 1029 | } |
kenjiArai | 0:308d4fafaafb | 1030 | break; |
kenjiArai | 0:308d4fafaafb | 1031 | |
kenjiArai | 0:308d4fafaafb | 1032 | case 'c' : /* Disk ioctl */ |
kenjiArai | 0:308d4fafaafb | 1033 | switch (*ptr++) { |
kenjiArai | 0:308d4fafaafb | 1034 | case 's' : /* dcs <pd#> - CTRL_SYNC */ |
kenjiArai | 0:308d4fafaafb | 1035 | if (!xatoi(&ptr, &p1)) break; |
kenjiArai | 0:308d4fafaafb | 1036 | PRINTF("rc=%d\r\n", disk_ioctl((BYTE)p1, CTRL_SYNC, 0)); |
kenjiArai | 0:308d4fafaafb | 1037 | break; |
kenjiArai | 0:308d4fafaafb | 1038 | case 'e' : /* dce <pd#> <s.lba> <e.lba> - CTRL_TRIM */ |
kenjiArai | 0:308d4fafaafb | 1039 | if (!xatoi(&ptr, &p1) || |
kenjiArai | 0:308d4fafaafb | 1040 | !xatoi(&ptr, (long*)&blk[0]) || |
kenjiArai | 0:308d4fafaafb | 1041 | !xatoi(&ptr, (long*)&blk[1])) { |
kenjiArai | 0:308d4fafaafb | 1042 | break; |
kenjiArai | 0:308d4fafaafb | 1043 | } |
kenjiArai | 0:308d4fafaafb | 1044 | PRINTF("rc=%d\r\n", disk_ioctl((BYTE)p1, CTRL_TRIM, blk)); |
kenjiArai | 0:308d4fafaafb | 1045 | break; |
kenjiArai | 0:308d4fafaafb | 1046 | } |
kenjiArai | 0:308d4fafaafb | 1047 | } |
kenjiArai | 0:308d4fafaafb | 1048 | } |
kenjiArai | 0:308d4fafaafb | 1049 | |
kenjiArai | 0:308d4fafaafb | 1050 | void put_dump ( |
kenjiArai | 0:308d4fafaafb | 1051 | void* buff, /* Pointer to the array to be dumped */ |
kenjiArai | 0:308d4fafaafb | 1052 | unsigned long addr, /* Heading address value */ |
kenjiArai | 0:308d4fafaafb | 1053 | int len, /* Number of items to be dumped */ |
kenjiArai | 0:308d4fafaafb | 1054 | int width /* Size of the items (DW_CHAR, DW_SHORT, DW_LONG) */ |
kenjiArai | 0:308d4fafaafb | 1055 | ) |
kenjiArai | 0:308d4fafaafb | 1056 | { |
kenjiArai | 0:308d4fafaafb | 1057 | int i; |
kenjiArai | 0:308d4fafaafb | 1058 | unsigned char *bp; |
kenjiArai | 0:308d4fafaafb | 1059 | unsigned short *sp; |
kenjiArai | 0:308d4fafaafb | 1060 | unsigned long *lp; |
kenjiArai | 0:308d4fafaafb | 1061 | |
kenjiArai | 0:308d4fafaafb | 1062 | PRINTF( "%08lx ", addr ); /* address */ |
kenjiArai | 0:308d4fafaafb | 1063 | switch ( width ) { |
kenjiArai | 0:308d4fafaafb | 1064 | case DW_CHAR: |
kenjiArai | 0:308d4fafaafb | 1065 | bp = (unsigned char *)buff; |
kenjiArai | 0:308d4fafaafb | 1066 | for ( i = 0; i < len; i++ ) { /* Hexdecimal dump */ |
kenjiArai | 0:308d4fafaafb | 1067 | PRINTF( " %02x", bp[i] ); |
kenjiArai | 0:308d4fafaafb | 1068 | } |
kenjiArai | 0:308d4fafaafb | 1069 | PUTC(' '); |
kenjiArai | 0:308d4fafaafb | 1070 | for ( i = 0; i < len; i++ ) { /* ASCII dump */ |
kenjiArai | 0:308d4fafaafb | 1071 | PUTC( (bp[i] >= ' ' && bp[i] <= '~') ? bp[i] : '.' ); |
kenjiArai | 0:308d4fafaafb | 1072 | } |
kenjiArai | 0:308d4fafaafb | 1073 | break; |
kenjiArai | 0:308d4fafaafb | 1074 | case DW_SHORT: |
kenjiArai | 0:308d4fafaafb | 1075 | sp = (unsigned short *)buff; |
kenjiArai | 0:308d4fafaafb | 1076 | do { /* Hexdecimal dump */ |
kenjiArai | 0:308d4fafaafb | 1077 | PRINTF( " %04x", *sp++ ); |
kenjiArai | 0:308d4fafaafb | 1078 | } while ( --len ); |
kenjiArai | 0:308d4fafaafb | 1079 | break; |
kenjiArai | 0:308d4fafaafb | 1080 | case DW_LONG: |
kenjiArai | 0:308d4fafaafb | 1081 | lp = (unsigned long *)buff; |
kenjiArai | 0:308d4fafaafb | 1082 | do { /* Hexdecimal dump */ |
kenjiArai | 0:308d4fafaafb | 1083 | PRINTF( " %08lx", *lp++ ); |
kenjiArai | 0:308d4fafaafb | 1084 | } while ( --len ); |
kenjiArai | 0:308d4fafaafb | 1085 | break; |
kenjiArai | 0:308d4fafaafb | 1086 | } |
kenjiArai | 0:308d4fafaafb | 1087 | PUTS( "\r\n" ); |
kenjiArai | 0:308d4fafaafb | 1088 | } |
kenjiArai | 0:308d4fafaafb | 1089 | |
kenjiArai | 0:308d4fafaafb | 1090 | // RTC related subroutines |
kenjiArai | 0:308d4fafaafb | 1091 | void chk_and_set_time(char *ptr) |
kenjiArai | 0:308d4fafaafb | 1092 | { |
kenjiArai | 0:308d4fafaafb | 1093 | char buf[64]; |
kenjiArai | 0:308d4fafaafb | 1094 | |
kenjiArai | 0:308d4fafaafb | 1095 | long p1; |
kenjiArai | 0:308d4fafaafb | 1096 | struct tm t; |
kenjiArai | 0:308d4fafaafb | 1097 | time_t seconds; |
kenjiArai | 0:308d4fafaafb | 1098 | |
kenjiArai | 0:308d4fafaafb | 1099 | if (xatoi(&ptr, &p1)) { |
kenjiArai | 0:308d4fafaafb | 1100 | t.tm_year = (uint8_t)p1 + 100; |
kenjiArai | 1:58fc0cbd9a41 | 1101 | pc.printf("Year:%ld ",p1); |
kenjiArai | 0:308d4fafaafb | 1102 | xatoi( &ptr, &p1 ); |
kenjiArai | 0:308d4fafaafb | 1103 | t.tm_mon = (uint8_t)p1 - 1; |
kenjiArai | 1:58fc0cbd9a41 | 1104 | pc.printf("Month:%ld ",p1); |
kenjiArai | 0:308d4fafaafb | 1105 | xatoi( &ptr, &p1 ); |
kenjiArai | 0:308d4fafaafb | 1106 | t.tm_mday = (uint8_t)p1; |
kenjiArai | 1:58fc0cbd9a41 | 1107 | pc.printf("Day:%ld ",p1); |
kenjiArai | 0:308d4fafaafb | 1108 | xatoi( &ptr, &p1 ); |
kenjiArai | 0:308d4fafaafb | 1109 | t.tm_hour = (uint8_t)p1; |
kenjiArai | 1:58fc0cbd9a41 | 1110 | pc.printf("Hour:%ld ",p1); |
kenjiArai | 0:308d4fafaafb | 1111 | xatoi( &ptr, &p1 ); |
kenjiArai | 0:308d4fafaafb | 1112 | t.tm_min = (uint8_t)p1; |
kenjiArai | 1:58fc0cbd9a41 | 1113 | pc.printf("Min:%ld ",p1); |
kenjiArai | 0:308d4fafaafb | 1114 | xatoi( &ptr, &p1 ); |
kenjiArai | 0:308d4fafaafb | 1115 | t.tm_sec = (uint8_t)p1; |
kenjiArai | 1:58fc0cbd9a41 | 1116 | pc.printf("Sec: %ld \r\n",p1); |
kenjiArai | 0:308d4fafaafb | 1117 | seconds = mktime(&t); |
kenjiArai | 0:308d4fafaafb | 1118 | set_time(seconds); |
kenjiArai | 0:308d4fafaafb | 1119 | } else { |
kenjiArai | 0:308d4fafaafb | 1120 | seconds = time(NULL); |
kenjiArai | 0:308d4fafaafb | 1121 | } |
kenjiArai | 0:308d4fafaafb | 1122 | strftime(buf, 50, " %B %d,'%y, %H:%M:%S\r\n", localtime(&seconds)); |
kenjiArai | 0:308d4fafaafb | 1123 | pc.printf("[Time] %s", buf); |
kenjiArai | 0:308d4fafaafb | 1124 | } |
kenjiArai | 0:308d4fafaafb | 1125 | |
kenjiArai | 0:308d4fafaafb | 1126 | // Get key input data |
kenjiArai | 0:308d4fafaafb | 1127 | void get_line (char *buff, int len) |
kenjiArai | 0:308d4fafaafb | 1128 | { |
kenjiArai | 0:308d4fafaafb | 1129 | char c; |
kenjiArai | 0:308d4fafaafb | 1130 | int idx = 0; |
kenjiArai | 0:308d4fafaafb | 1131 | |
kenjiArai | 0:308d4fafaafb | 1132 | for (;;) { |
kenjiArai | 0:308d4fafaafb | 1133 | c = GETC(); |
kenjiArai | 0:308d4fafaafb | 1134 | // Added by Kenji Arai / JH1PJL May 9th, 2010 |
kenjiArai | 0:308d4fafaafb | 1135 | if (c == '\r') { |
kenjiArai | 0:308d4fafaafb | 1136 | buff[idx++] = c; |
kenjiArai | 0:308d4fafaafb | 1137 | break; |
kenjiArai | 0:308d4fafaafb | 1138 | } |
kenjiArai | 0:308d4fafaafb | 1139 | if ((c == '\b') && idx) { |
kenjiArai | 0:308d4fafaafb | 1140 | idx--; |
kenjiArai | 0:308d4fafaafb | 1141 | PUTC(c); |
kenjiArai | 0:308d4fafaafb | 1142 | PUTC(' '); |
kenjiArai | 0:308d4fafaafb | 1143 | PUTC(c); |
kenjiArai | 0:308d4fafaafb | 1144 | } |
kenjiArai | 0:308d4fafaafb | 1145 | if (((uint8_t)c >= ' ') && (idx < len - 1)) { |
kenjiArai | 0:308d4fafaafb | 1146 | buff[idx++] = c; |
kenjiArai | 0:308d4fafaafb | 1147 | PUTC(c); |
kenjiArai | 0:308d4fafaafb | 1148 | } |
kenjiArai | 0:308d4fafaafb | 1149 | } |
kenjiArai | 0:308d4fafaafb | 1150 | buff[idx] = 0; |
kenjiArai | 0:308d4fafaafb | 1151 | PUTS("\r\n"); |
kenjiArai | 0:308d4fafaafb | 1152 | } |
kenjiArai | 0:308d4fafaafb | 1153 | |
kenjiArai | 0:308d4fafaafb | 1154 | /* Outpur LF & CR */ |
kenjiArai | 0:308d4fafaafb | 1155 | void crlf( void ) |
kenjiArai | 0:308d4fafaafb | 1156 | { |
kenjiArai | 0:308d4fafaafb | 1157 | PRINTF( "\r\n" ); |
kenjiArai | 0:308d4fafaafb | 1158 | } |
kenjiArai | 0:308d4fafaafb | 1159 | |
kenjiArai | 0:308d4fafaafb | 1160 | /* Check key input */ |
kenjiArai | 0:308d4fafaafb | 1161 | unsigned int check_hit_key (void) |
kenjiArai | 0:308d4fafaafb | 1162 | { |
kenjiArai | 0:308d4fafaafb | 1163 | return ( READABLE() ); |
kenjiArai | 0:308d4fafaafb | 1164 | } |
kenjiArai | 0:308d4fafaafb | 1165 | |
kenjiArai | 0:308d4fafaafb | 1166 | /*----------------------------------------------*/ |
kenjiArai | 0:308d4fafaafb | 1167 | /* Get a value of the string */ |
kenjiArai | 0:308d4fafaafb | 1168 | /*----------------------------------------------*/ |
kenjiArai | 0:308d4fafaafb | 1169 | /* "123 -5 0x3ff 0b1111 0377 w " |
kenjiArai | 0:308d4fafaafb | 1170 | ^ 1st call returns 123 and next ptr |
kenjiArai | 0:308d4fafaafb | 1171 | ^ 2nd call returns -5 and next ptr |
kenjiArai | 0:308d4fafaafb | 1172 | ^ 3rd call returns 1023 and next ptr |
kenjiArai | 0:308d4fafaafb | 1173 | ^ 4th call returns 15 and next ptr |
kenjiArai | 0:308d4fafaafb | 1174 | ^ 5th call returns 255 and next ptr |
kenjiArai | 0:308d4fafaafb | 1175 | ^ 6th call fails and returns 0 |
kenjiArai | 0:308d4fafaafb | 1176 | */ |
kenjiArai | 0:308d4fafaafb | 1177 | int xatoi ( /* 0:Failed, 1:Successful */ |
kenjiArai | 0:308d4fafaafb | 1178 | char **str, /* Pointer to pointer to the string */ |
kenjiArai | 0:308d4fafaafb | 1179 | long *res /* Pointer to the valiable to store the value */ |
kenjiArai | 0:308d4fafaafb | 1180 | ) |
kenjiArai | 0:308d4fafaafb | 1181 | { |
kenjiArai | 0:308d4fafaafb | 1182 | unsigned long val; |
kenjiArai | 0:308d4fafaafb | 1183 | unsigned char c, r, s = 0; |
kenjiArai | 0:308d4fafaafb | 1184 | |
kenjiArai | 0:308d4fafaafb | 1185 | *res = 0; |
kenjiArai | 0:308d4fafaafb | 1186 | while ( (c = **str) == ' ' ) { |
kenjiArai | 0:308d4fafaafb | 1187 | (*str)++; /* Skip leading spaces */ |
kenjiArai | 0:308d4fafaafb | 1188 | } |
kenjiArai | 0:308d4fafaafb | 1189 | if ( c == '-' ) { /* negative? */ |
kenjiArai | 0:308d4fafaafb | 1190 | s = 1; |
kenjiArai | 0:308d4fafaafb | 1191 | c = *(++(*str)); |
kenjiArai | 0:308d4fafaafb | 1192 | } |
kenjiArai | 0:308d4fafaafb | 1193 | if ( c == '0' ) { |
kenjiArai | 0:308d4fafaafb | 1194 | c = *(++(*str)); |
kenjiArai | 0:308d4fafaafb | 1195 | switch (c) { |
kenjiArai | 0:308d4fafaafb | 1196 | case 'x': /* hexdecimal */ |
kenjiArai | 0:308d4fafaafb | 1197 | r = 16; |
kenjiArai | 0:308d4fafaafb | 1198 | c = *(++(*str)); |
kenjiArai | 0:308d4fafaafb | 1199 | break; |
kenjiArai | 0:308d4fafaafb | 1200 | case 'b': /* binary */ |
kenjiArai | 0:308d4fafaafb | 1201 | r = 2; |
kenjiArai | 0:308d4fafaafb | 1202 | c = *(++(*str)); |
kenjiArai | 0:308d4fafaafb | 1203 | break; |
kenjiArai | 0:308d4fafaafb | 1204 | default: |
kenjiArai | 0:308d4fafaafb | 1205 | if ( c <= ' ' ) return 1; /* single zero */ |
kenjiArai | 0:308d4fafaafb | 1206 | if ( c < '0' || c > '9' ) return 0; /* invalid char */ |
kenjiArai | 0:308d4fafaafb | 1207 | r = 8; /* octal */ |
kenjiArai | 0:308d4fafaafb | 1208 | } |
kenjiArai | 0:308d4fafaafb | 1209 | } else { |
kenjiArai | 0:308d4fafaafb | 1210 | if ( c < '0' || c > '9' ) return 0; /* EOL or invalid char */ |
kenjiArai | 0:308d4fafaafb | 1211 | r = 10; /* decimal */ |
kenjiArai | 0:308d4fafaafb | 1212 | } |
kenjiArai | 0:308d4fafaafb | 1213 | val = 0; |
kenjiArai | 0:308d4fafaafb | 1214 | while ( c > ' ' ) { |
kenjiArai | 0:308d4fafaafb | 1215 | if ( c >= 'a' ) { |
kenjiArai | 0:308d4fafaafb | 1216 | c -= 0x20; |
kenjiArai | 0:308d4fafaafb | 1217 | } |
kenjiArai | 0:308d4fafaafb | 1218 | c -= '0'; |
kenjiArai | 0:308d4fafaafb | 1219 | if ( c >= 17 ) { |
kenjiArai | 0:308d4fafaafb | 1220 | c -= 7; |
kenjiArai | 0:308d4fafaafb | 1221 | if ( c <= 9 ) { |
kenjiArai | 0:308d4fafaafb | 1222 | return 0; /* invalid char */ |
kenjiArai | 0:308d4fafaafb | 1223 | } |
kenjiArai | 0:308d4fafaafb | 1224 | } |
kenjiArai | 0:308d4fafaafb | 1225 | if ( c >= r ) { |
kenjiArai | 0:308d4fafaafb | 1226 | return 0; /* invalid char for current radix */ |
kenjiArai | 0:308d4fafaafb | 1227 | } |
kenjiArai | 0:308d4fafaafb | 1228 | val = val * r + c; |
kenjiArai | 0:308d4fafaafb | 1229 | c = *(++(*str)); |
kenjiArai | 0:308d4fafaafb | 1230 | } |
kenjiArai | 0:308d4fafaafb | 1231 | if (s) val = 0 - val; /* apply sign if needed */ |
kenjiArai | 0:308d4fafaafb | 1232 | *res = val; |
kenjiArai | 0:308d4fafaafb | 1233 | return 1; |
kenjiArai | 0:308d4fafaafb | 1234 | } |