Changeset 590:4531b8ede6e4

Show
Ignore:
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:
2 removed
10 modified

Legend:

Unmodified
Added
Removed
  • nxos/base/lib/fs/fs.c

    r588 r590  
    2424#define FS_FILE_METADATA_SIZE 10 
    2525 
    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. */ 
    2730#define FS_FILE_METADATA_BYTES (FS_FILE_METADATA_SIZE * sizeof(U32)) 
    2831 
     32/** Mask to use on the first metadata U32 to get the file origin marker value. */ 
    2933#define FS_FILE_ORIGIN_MASK 0xFF000000 
     34 
     35/** Mask to use on the first metadata U32 to get the file permissions. */ 
    3036#define FS_FILE_PERMS_MASK 0x00F00000 
     37 
     38/** Mask to use on the first metadata U32 to get the file size. */ 
    3139#define FS_FILE_SIZE_MASK 0x000FFFFF 
    3240 
     
    3442#define FS_FILE_PERM_MASK_EXECUTABLE (1 << 1) 
    3543 
    36 #define FS_FILENAME_OFFSET 2 
    37  
    38 /* U32 <-> char conversion union for filenames. */ 
     44/** U32 <-> char conversion union for filenames. */ 
    3945union U32tochar { 
    4046  char chars[FS_FILENAME_LENGTH]; 
     
    304310static fs_err_t nx_fs_init_fd(U32 origin, fs_fd_t fd) { 
    305311  volatile U32 *metadata = &(FLASH_BASE_PTR[origin*EFC_PAGE_WORDS]); 
     312  union U32tochar nameconv; 
    306313  fs_file_t *file; 
    307314 
     
    309316  NX_ASSERT(file != NULL); 
    310317 
     318  memcpy(nameconv.integers, 
     319         (void *)(metadata + FS_FILENAME_OFFSET), 
     320         FS_FILENAME_LENGTH); 
     321 
    311322  file->origin = origin; 
     323  memcpy(file->name, nameconv.chars, MIN(strlen(nameconv.chars), 31)); 
    312324  file->size = nx_fs_get_file_size_from_metadata(metadata); 
    313325  file->perms = nx_fs_get_file_perms_from_metadata(metadata); 
     
    679691} 
    680692 
    681 void nx_fs_get_occupation(U16 *files, U32 *used, U32 *free_pages, 
     693void nx_fs_get_occupation(U32 *files, U32 *used, U32 *free_pages, 
    682694                          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 
    683717  if (files) { 
     718    *files = _files; 
    684719  } 
    685720 
    686721  if (used) { 
     722    *used = _used; 
    687723  } 
    688724 
    689725  if (free_pages) { 
     726    *free_pages = _free_pages; 
    690727  } 
    691728 
    692729  if (wasted) { 
     730    *wasted = _wasted; 
    693731  } 
    694732} 
  • nxos/base/lib/fs/fs.h

    r588 r590  
    2222/*@{*/ 
    2323 
    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 */ 
    2537/*@{*/ 
    2638 
     
    187199 * @param wasted The bytes lost by files page aligment. 
    188200 */ 
    189 void nx_fs_get_occupation(U16 *files, U32 *used, U32 *free_pages, 
     201void nx_fs_get_occupation(U32 *files, U32 *used, U32 *free_pages, 
    190202                          U32 *wasted); 
    191203 
  • nxos/base/lib/rcmd/_rcmd.c

    r588 r590  
    3636}; 
    3737 
    38 rcmd_err_t nx__rcmd_find_command(const char *line, rcmd_command_def *command) { 
     38rcmd_err_t nx__rcmd_find_command(char *line, rcmd_command_def *command) { 
    3939  U32 i = 0; 
     40  char *sep; 
     41 
     42  sep = strchr(line, RCMD_TOKEN_SEPARATOR); 
     43  if (sep) { 
     44    *sep = '\0'; 
     45  } 
    4046 
    4147  while (rcmd_commands[i].name) { 
    4248    if (streq(line, rcmd_commands[i].name)) { 
    4349      *command = rcmd_commands[i]; 
     50      *sep = RCMD_TOKEN_SEPARATOR; 
    4451      return RCMD_ERR_NO_ERROR; 
    4552    } 
     
    4855  } 
    4956 
     57  *sep = RCMD_TOKEN_SEPARATOR; 
    5058  return RCMD_ERR_COMMAND_NOT_FOUND; 
    5159} 
  • nxos/base/lib/rcmd/_rcmd.c

    r583 r590  
    1 /* Copyright (c) 2007-2008 the NxOS developers 
     1/* Copyright (c) 2007,2008 the NxOS developers 
    22 * 
    33 * See AUTHORS for a full list of the developers. 
     
    1010#include "base/util.h" 
    1111#include "base/display.h" 
    12 #include "base/fs.h" 
    1312#include "base/nxt.h" 
    1413#include "base/drivers/motors.h" 
    1514#include "base/drivers/sound.h" 
    1615#include "base/drivers/systick.h" 
     16#include "base/lib/fs/fs.h" 
    1717#include "base/lib/rcmd/_rcmd.h" 
    1818 
  • nxos/base/lib/rcmd/_rcmd.h

    r588 r590  
    4040 * @return An appropriate @a rcmd_err_t error code. 
    4141 */ 
    42 rcmd_err_t nx__rcmd_find_command(const char *line, rcmd_command_def *command); 
     42rcmd_err_t nx__rcmd_find_command(char *line, rcmd_command_def *command); 
    4343 
    4444rcmd_err_t nx__rcmd_move(char *line); 
  • nxos/base/lib/rcmd/_rcmd.h

    r583 r590  
    33 */ 
    44 
    5 /* Copyright (c) 2007-2008 the NxOS developers 
     5/* Copyright (c) 2007,2008 the NxOS developers 
    66 * 
    77 * See AUTHORS for a full list of the developers. 
     
    1515 
    1616#include "base/types.h" 
    17 #include "base/fs.h" 
     17#include "base/lib/fs/fs.h" 
    1818#include "base/lib/rcmd/rcmd.h" 
    1919 
  • nxos/base/lib/rcmd/rcmd.c

    r588 r590  
    2323  } 
    2424 
    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); 
    2631  if (err != RCMD_ERR_NO_ERROR) { 
    2732    return err; 
    2833  } 
    2934 
    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)); 
    3435  return command.actuator(cmdline); 
    3536} 
     
    3738void nx_rcmd_parse(char *file) { 
    3839  rcmd_err_t err, result; 
     40  fs_err_t fserr; 
    3941  fs_fd_t fd; 
    4042  int n = 0; 
    4143 
    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(); 
    4348    nx__rcmd_error(RCMD_ERR_READ_ERROR, file, 0); 
    4449    return; 
  • nxos/base/lib/rcmd/rcmd.c

    r583 r590  
    1 /* Copyright (c) 2007-2008 the NxOS developers 
     1/* Copyright (c) 2007,2008 the NxOS developers 
    22 * 
    33 * See AUTHORS for a full list of the developers. 
     
    1010#include "base/util.h" 
    1111#include "base/assert.h" 
    12 #include "base/fs.h" 
    13 #include "base/display.h" 
     12#include "base/lib/fs/fs.h" 
    1413#include "base/lib/rcmd/rcmd.h" 
    1514#include "base/lib/rcmd/_rcmd.h" 
  • nxos/systems/tag-route/main.c

    r588 r590  
    77 */ 
    88 
    9 /** Tag-route follower. 
    10  * 
    11  * Replays a recorded tag route. 
    12  */ 
     9/** Tag-route follower. Replays a recorded tag route. */ 
    1310 
    1411#include "base/types.h" 
     
    2522#define ROUTE_FILE "tag.data" 
    2623 
    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" 
    2825#define DATA_SIZE strlen(TEST_DATA) 
    2926 
    3027void record(char *filename); 
    3128void replay(char *filename); 
     29void defrag(void); 
    3230 
    3331void record(char *filename) { 
     
    8583} 
    8684 
     85void 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 
     92void 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 
    87113void main(void) { 
    88   char *entries[] = {"Replay", "Record", "--", "Halt", NULL}; 
     114  char *entries[] = {"Replay", "Record", "Stats", "Defrag", "Halt", NULL}; 
    89115  gui_text_menu_t menu; 
    90116  U8 res; 
     
    108134        record(ROUTE_FILE); 
    109135        break; 
     136      case 2: 
     137        stats(); 
     138        break; 
     139      case 3: 
     140        defrag(); 
     141        break; 
    110142      default: 
    111143        continue; 
  • nxos/systems/tag-route/main.c

    r589 r590  
    1 /* Copyright (c) 2007-2008 the NxOS developers 
     1/* Copyright (c) 2008 the NxOS developers 
    22 * 
    33 * See AUTHORS for a full list of the developers. 
     
    1212#include "base/core.h" 
    1313#include "base/display.h" 
    14 #include "base/fs.h" 
    1514#include "base/util.h" 
    1615#include "base/drivers/avr.h" 
    1716#include "base/drivers/systick.h" 
    1817#include "base/drivers/motors.h" 
     18#include "base/lib/fs/fs.h" 
    1919#include "base/lib/gui/gui.h" 
    2020#include "base/lib/rcmd/rcmd.h"