Contiki 3.x
node-setup.c
1 #include <stdio.h>
2 
3 #include "contiki.h"
4 #include "cfs/cfs.h"
5 #include "cfs/cfs-coffee.h"
6 #include "ms-io.h"
7 
8 PROCESS(example_coffee_process, "Node Reset");
9 AUTOSTART_PROCESSES(&example_coffee_process);
10 
11 /* Formatting is needed if the storage device is in an unknown state;
12  e.g., when using Coffee on the storage device for the first time. */
13 #ifndef NEED_FORMATTING
14 #define NEED_FORMATTING 1
15 #endif
16 
17 static int
18 dir_test(void)
19 {
20  struct cfs_dir dir;
21  struct cfs_dirent dirent;
22 
23  /* Coffee provides a root directory only. */
24  if(cfs_opendir(&dir, "/") != 0) {
25  printf("failed to open the root directory\n");
26  return 0;
27  }
28 
29  /* List all files and their file sizes. */
30  printf("Available files:\n");
31  while(cfs_readdir(&dir, &dirent) == 0) {
32  printf(" %s (%lu bytes)\n", dirent.name, (unsigned long)dirent.size);
33  }
34 
35  cfs_closedir(&dir);
36 
37  return 1;
38 }
39 
40 PROCESS_THREAD(example_coffee_process, ev, data)
41 {
42  PROCESS_BEGIN();
43 
44  printf("\n\nNode Setup\n");
45 
46 #if NEED_FORMATTING
47  printf("Formatting flash... ");
49  printf("Done\n");
50 #endif
51 
52  PROCESS_PAUSE();
53 
54  if(dir_test() == 0) {
55  printf("dir test failed\n");
56  }
57 
58  // Reset the reboot counter
59  printf("Reseting reboot counter... ");
60  ms_reset_reboot();
61  printf("Done\n");
62 
63  printf("\nNode setup complete\n");
64 
65  PROCESS_END();
66 }
int cfs_opendir(struct cfs_dir *dir, const char *name)
Open a directory for reading directory entries.
Definition: cfs-coffee.c:1283
#define PROCESS_END()
Define the end of a process.
Definition: process.h:131
#define PROCESS(name, strname)
Declare a process.
Definition: process.h:307
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
Definition: process.h:273
int cfs_coffee_format(void)
Format the storage area assigned to Coffee.
Definition: cfs-coffee.c:1378
int cfs_readdir(struct cfs_dir *dir, struct cfs_dirent *record)
Read a directory entry.
Definition: cfs-coffee.c:1294
Header for the Coffee file system.
void cfs_closedir(struct cfs_dir *dir)
Close a directory opened with cfs_opendir().
Definition: cfs-coffee.c:1320
CFS header file.
#define PROCESS_PAUSE()
Yield the process for a short while.
Definition: process.h:221
#define PROCESS_BEGIN()
Define the beginning of a process.
Definition: process.h:120