Changeset 590:4531b8ede6e4
- Timestamp:
- 06/08/08 00:44:14 (7 months ago)
- Author:
- Maxime Petazzoni <maxime.petazzoni@…>
- Parents:
- 589:6fed7fee381f (diff), 588:9a2f360ec1e6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
- Branch:
- default
- Message:
-
Merge changes from devel.
- Location:
- nxos
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r588
|
r590
|
|
| 24 | 24 | #define FS_FILE_METADATA_SIZE 10 |
| 25 | 25 | |
| 26 | | /* File metadata size, in bytes. */ |
| | 26 | /** Filename offset (in U32s) in the metadata. */ |
| | 27 | #define FS_FILENAME_OFFSET 2 |
| | 28 | |
| | 29 | /** File metadata size, in bytes. */ |
| 27 | 30 | #define FS_FILE_METADATA_BYTES (FS_FILE_METADATA_SIZE * sizeof(U32)) |
| 28 | 31 | |
| | 32 | /** Mask to use on the first metadata U32 to get the file origin marker value. */ |
| 29 | 33 | #define FS_FILE_ORIGIN_MASK 0xFF000000 |
| | 34 | |
| | 35 | /** Mask to use on the first metadata U32 to get the file permissions. */ |
| 30 | 36 | #define FS_FILE_PERMS_MASK 0x00F00000 |
| | 37 | |
| | 38 | /** Mask to use on the first metadata U32 to get the file size. */ |
| 31 | 39 | #define FS_FILE_SIZE_MASK 0x000FFFFF |
| 32 | 40 | |
| … |
… |
|
| 34 | 42 | #define FS_FILE_PERM_MASK_EXECUTABLE (1 << 1) |
| 35 | 43 | |
| 36 | | #define FS_FILENAME_OFFSET 2 |
| 37 | | |
| 38 | | /* U32 <-> char conversion union for filenames. */ |
| | 44 | /** U32 <-> char conversion union for filenames. */ |
| 39 | 45 | union U32tochar { |
| 40 | 46 | char chars[FS_FILENAME_LENGTH]; |
| … |
… |
|
| 304 | 310 | static fs_err_t nx_fs_init_fd(U32 origin, fs_fd_t fd) { |
| 305 | 311 | volatile U32 *metadata = &(FLASH_BASE_PTR[origin*EFC_PAGE_WORDS]); |
| | 312 | union U32tochar nameconv; |
| 306 | 313 | fs_file_t *file; |
| 307 | 314 | |
| … |
… |
|
| 309 | 316 | NX_ASSERT(file != NULL); |
| 310 | 317 | |
| | 318 | memcpy(nameconv.integers, |
| | 319 | (void *)(metadata + FS_FILENAME_OFFSET), |
| | 320 | FS_FILENAME_LENGTH); |
| | 321 | |
| 311 | 322 | file->origin = origin; |
| | 323 | memcpy(file->name, nameconv.chars, MIN(strlen(nameconv.chars), 31)); |
| 312 | 324 | file->size = nx_fs_get_file_size_from_metadata(metadata); |
| 313 | 325 | file->perms = nx_fs_get_file_perms_from_metadata(metadata); |
| … |
… |
|
| 679 | 691 | } |
| 680 | 692 | |
| 681 | | void nx_fs_get_occupation(U16 *files, U32 *used, U32 *free_pages, |
| | 693 | void nx_fs_get_occupation(U32 *files, U32 *used, U32 *free_pages, |
| 682 | 694 | U32 *wasted) { |
| | 695 | U32 _files = 0, _used = 0, _free_pages = 0, _wasted = 0; |
| | 696 | U32 i; |
| | 697 | |
| | 698 | for (i=FS_PAGE_START; i<FS_PAGE_END; i++) { |
| | 699 | if (nx_fs_page_has_magic(i)) { |
| | 700 | volatile U32 *metadata = &(FLASH_BASE_PTR[i*EFC_PAGE_WORDS]); |
| | 701 | size_t size; |
| | 702 | U32 pages; |
| | 703 | |
| | 704 | size = nx_fs_get_file_size_from_metadata(metadata); |
| | 705 | pages = nx_fs_get_file_page_count(size); |
| | 706 | |
| | 707 | _files++; |
| | 708 | _used += size; |
| | 709 | _wasted += pages * EFC_PAGE_BYTES - size - FS_FILE_METADATA_BYTES; |
| | 710 | |
| | 711 | i += pages - 1; |
| | 712 | } else { |
| | 713 | _free_pages++; |
| | 714 | } |
| | 715 | } |
| | 716 | |
| 683 | 717 | if (files) { |
| | 718 | *files = _files; |
| 684 | 719 | } |
| 685 | 720 | |
| 686 | 721 | if (used) { |
| | 722 | *used = _used; |
| 687 | 723 | } |
| 688 | 724 | |
| 689 | 725 | if (free_pages) { |
| | 726 | *free_pages = _free_pages; |
| 690 | 727 | } |
| 691 | 728 | |
| 692 | 729 | if (wasted) { |
| | 730 | *wasted = _wasted; |
| 693 | 731 | } |
| 694 | 732 | } |
-
|
r588
|
r590
|
|
| 22 | 22 | /*@{*/ |
| 23 | 23 | |
| 24 | | /** @defgroup fs Flash file system */ |
| | 24 | /** @defgroup fs Flash file system |
| | 25 | * |
| | 26 | * A flash-friendly file system for the NXT on-board flash memory. This is a very simple |
| | 27 | * file system implementation, allowing most of the basic features expected from a file |
| | 28 | * system: open(), read(), write(), seek(), flush() and close(). Note that reading and |
| | 29 | * writing use two different pointers. A seek() will move both of them. |
| | 30 | * |
| | 31 | * The file system also tries to minimize stress on the flash by progressively moving files |
| | 32 | * needing more space towards the end of the flash medium. This relocation process happens |
| | 33 | * automatically and may make one write operation rather costly (in terms of time). |
| | 34 | * |
| | 35 | * For more information, refer to the file system design document. |
| | 36 | */ |
| 25 | 37 | /*@{*/ |
| 26 | 38 | |
| … |
… |
|
| 187 | 199 | * @param wasted The bytes lost by files page aligment. |
| 188 | 200 | */ |
| 189 | | void nx_fs_get_occupation(U16 *files, U32 *used, U32 *free_pages, |
| | 201 | void nx_fs_get_occupation(U32 *files, U32 *used, U32 *free_pages, |
| 190 | 202 | U32 *wasted); |
| 191 | 203 | |
-
|
r588
|
r590
|
|
| 36 | 36 | }; |
| 37 | 37 | |
| 38 | | rcmd_err_t nx__rcmd_find_command(const char *line, rcmd_command_def *command) { |
| | 38 | rcmd_err_t nx__rcmd_find_command(char *line, rcmd_command_def *command) { |
| 39 | 39 | U32 i = 0; |
| | 40 | char *sep; |
| | 41 | |
| | 42 | sep = strchr(line, RCMD_TOKEN_SEPARATOR); |
| | 43 | if (sep) { |
| | 44 | *sep = '\0'; |
| | 45 | } |
| 40 | 46 | |
| 41 | 47 | while (rcmd_commands[i].name) { |
| 42 | 48 | if (streq(line, rcmd_commands[i].name)) { |
| 43 | 49 | *command = rcmd_commands[i]; |
| | 50 | *sep = RCMD_TOKEN_SEPARATOR; |
| 44 | 51 | return RCMD_ERR_NO_ERROR; |
| 45 | 52 | } |
| … |
… |
|
| 48 | 55 | } |
| 49 | 56 | |
| | 57 | *sep = RCMD_TOKEN_SEPARATOR; |
| 50 | 58 | return RCMD_ERR_COMMAND_NOT_FOUND; |
| 51 | 59 | } |
-
|
r583
|
r590
|
|
| 1 | | /* Copyright (c) 2007-2008 the NxOS developers |
| | 1 | /* Copyright (c) 2007,2008 the NxOS developers |
| 2 | 2 | * |
| 3 | 3 | * See AUTHORS for a full list of the developers. |
| … |
… |
|
| 10 | 10 | #include "base/util.h" |
| 11 | 11 | #include "base/display.h" |
| 12 | | #include "base/fs.h" |
| 13 | 12 | #include "base/nxt.h" |
| 14 | 13 | #include "base/drivers/motors.h" |
| 15 | 14 | #include "base/drivers/sound.h" |
| 16 | 15 | #include "base/drivers/systick.h" |
| | 16 | #include "base/lib/fs/fs.h" |
| 17 | 17 | #include "base/lib/rcmd/_rcmd.h" |
| 18 | 18 | |
-
|
r588
|
r590
|
|
| 40 | 40 | * @return An appropriate @a rcmd_err_t error code. |
| 41 | 41 | */ |
| 42 | | rcmd_err_t nx__rcmd_find_command(const char *line, rcmd_command_def *command); |
| | 42 | rcmd_err_t nx__rcmd_find_command(char *line, rcmd_command_def *command); |
| 43 | 43 | |
| 44 | 44 | rcmd_err_t nx__rcmd_move(char *line); |
-
|
r583
|
r590
|
|
| 3 | 3 | */ |
| 4 | 4 | |
| 5 | | /* Copyright (c) 2007-2008 the NxOS developers |
| | 5 | /* Copyright (c) 2007,2008 the NxOS developers |
| 6 | 6 | * |
| 7 | 7 | * See AUTHORS for a full list of the developers. |
| … |
… |
|
| 15 | 15 | |
| 16 | 16 | #include "base/types.h" |
| 17 | | #include "base/fs.h" |
| | 17 | #include "base/lib/fs/fs.h" |
| 18 | 18 | #include "base/lib/rcmd/rcmd.h" |
| 19 | 19 | |
-
|
r588
|
r590
|
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | | err = nx__rcmd_find_command(line, &command); |
| | 25 | /* Call the command actuator on a copy of the command line so |
| | 26 | * it can mess around with it if it wants to. |
| | 27 | */ |
| | 28 | memcpy(cmdline, line, strlen(line)); |
| | 29 | |
| | 30 | err = nx__rcmd_find_command(cmdline, &command); |
| 26 | 31 | if (err != RCMD_ERR_NO_ERROR) { |
| 27 | 32 | return err; |
| 28 | 33 | } |
| 29 | 34 | |
| 30 | | /* Call the command actuator on a copy of the command line so |
| 31 | | * it can mess around with it if it wants to. |
| 32 | | */ |
| 33 | | memcpy(cmdline, line, strlen(line)); |
| 34 | 35 | return command.actuator(cmdline); |
| 35 | 36 | } |
| … |
… |
|
| 37 | 38 | void nx_rcmd_parse(char *file) { |
| 38 | 39 | rcmd_err_t err, result; |
| | 40 | fs_err_t fserr; |
| 39 | 41 | fs_fd_t fd; |
| 40 | 42 | int n = 0; |
| 41 | 43 | |
| 42 | | if (nx_fs_open(file, FS_FILE_MODE_OPEN, &fd) != FS_ERR_NO_ERROR) { |
| | 44 | fserr = nx_fs_open(file, FS_FILE_MODE_OPEN, &fd); |
| | 45 | if (fserr != FS_ERR_NO_ERROR) { |
| | 46 | nx_display_uint(fserr); |
| | 47 | nx_display_end_line(); |
| 43 | 48 | nx__rcmd_error(RCMD_ERR_READ_ERROR, file, 0); |
| 44 | 49 | return; |
-
|
r583
|
r590
|
|
| 1 | | /* Copyright (c) 2007-2008 the NxOS developers |
| | 1 | /* Copyright (c) 2007,2008 the NxOS developers |
| 2 | 2 | * |
| 3 | 3 | * See AUTHORS for a full list of the developers. |
| … |
… |
|
| 10 | 10 | #include "base/util.h" |
| 11 | 11 | #include "base/assert.h" |
| 12 | | #include "base/fs.h" |
| 13 | | #include "base/display.h" |
| | 12 | #include "base/lib/fs/fs.h" |
| 14 | 13 | #include "base/lib/rcmd/rcmd.h" |
| 15 | 14 | #include "base/lib/rcmd/_rcmd.h" |
-
|
r588
|
r590
|
|
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | | /** Tag-route follower. |
| 10 | | * |
| 11 | | * Replays a recorded tag route. |
| 12 | | */ |
| | 9 | /** Tag-route follower. Replays a recorded tag route. */ |
| 13 | 10 | |
| 14 | 11 | #include "base/types.h" |
| … |
… |
|
| 25 | 22 | #define ROUTE_FILE "tag.data" |
| 26 | 23 | |
| 27 | | #define TEST_DATA "print hello world\nmove A,B -90 500\nwait 2000\nplay 1500 1000 sync\nprint done" |
| | 24 | #define TEST_DATA "print hello world\nmove A,B 100 1500\nwait 2000\nplay 1500 1000 sync\nprint done" |
| 28 | 25 | #define DATA_SIZE strlen(TEST_DATA) |
| 29 | 26 | |
| 30 | 27 | void record(char *filename); |
| 31 | 28 | void replay(char *filename); |
| | 29 | void defrag(void); |
| 32 | 30 | |
| 33 | 31 | void record(char *filename) { |
| … |
… |
|
| 85 | 83 | } |
| 86 | 84 | |
| | 85 | void defrag(void) { |
| | 86 | nx_display_clear(); |
| | 87 | nx_display_string("- Defrag -\n\n"); |
| | 88 | nx_fs_defrag_best_overall(); |
| | 89 | nx_display_string("Done.\n"); |
| | 90 | } |
| | 91 | |
| | 92 | void stats(void) { |
| | 93 | U32 files = 0, used = 0, free_pages = 0, wasted = 0; |
| | 94 | |
| | 95 | nx_display_clear(); |
| | 96 | nx_display_string("- FS stats -\n\n"); |
| | 97 | |
| | 98 | nx_fs_get_occupation(&files, &used, &free_pages, &wasted); |
| | 99 | |
| | 100 | nx_display_uint(files); |
| | 101 | nx_display_string(" file(s).\n"); |
| | 102 | |
| | 103 | nx_display_uint(used); |
| | 104 | nx_display_string("B used.\n"); |
| | 105 | |
| | 106 | nx_display_uint(free_pages); |
| | 107 | nx_display_string(" free page(s).\n"); |
| | 108 | |
| | 109 | nx_display_uint(wasted); |
| | 110 | nx_display_string("B wasted.\n"); |
| | 111 | } |
| | 112 | |
| 87 | 113 | void main(void) { |
| 88 | | char *entries[] = {"Replay", "Record", "--", "Halt", NULL}; |
| | 114 | char *entries[] = {"Replay", "Record", "Stats", "Defrag", "Halt", NULL}; |
| 89 | 115 | gui_text_menu_t menu; |
| 90 | 116 | U8 res; |
| … |
… |
|
| 108 | 134 | record(ROUTE_FILE); |
| 109 | 135 | break; |
| | 136 | case 2: |
| | 137 | stats(); |
| | 138 | break; |
| | 139 | case 3: |
| | 140 | defrag(); |
| | 141 | break; |
| 110 | 142 | default: |
| 111 | 143 | continue; |
-
|
r589
|
r590
|
|
| 1 | | /* Copyright (c) 2007-2008 the NxOS developers |
| | 1 | /* Copyright (c) 2008 the NxOS developers |
| 2 | 2 | * |
| 3 | 3 | * See AUTHORS for a full list of the developers. |
| … |
… |
|
| 12 | 12 | #include "base/core.h" |
| 13 | 13 | #include "base/display.h" |
| 14 | | #include "base/fs.h" |
| 15 | 14 | #include "base/util.h" |
| 16 | 15 | #include "base/drivers/avr.h" |
| 17 | 16 | #include "base/drivers/systick.h" |
| 18 | 17 | #include "base/drivers/motors.h" |
| | 18 | #include "base/lib/fs/fs.h" |
| 19 | 19 | #include "base/lib/gui/gui.h" |
| 20 | 20 | #include "base/lib/rcmd/rcmd.h" |