Contiki 3.x
cfs-fill.c
Go to the documentation of this file.
1 /*
2  * FILL THE 2MB flash just to see
3  */
4 
5 /**
6  * \file
7  * Basic test for CFS/Coffee.
8  * \author
9  * Kirk Martinez, University of Southampton
10  */
11 
12 #include "contiki.h"
13 #include "cfs/cfs.h"
14 #include "cfs/cfs-coffee.h"
15 #include "lib/crc16.h"
16 #include "lib/random.h"
17 
18 #include <stdio.h>
19 #include <string.h>
20 
21 PROCESS(listcoffee_process, "CFS/Coffee process");
22 AUTOSTART_PROCESSES(&listcoffee_process);
23 
24 int coffee_fill()
25 {
26 struct cfs_dir dir;
27 struct cfs_dirent dirent;
28 static int bufsize;
29 char buf[500]; // data to write
30 char filename[80];
31 bufsize=500;
32 int dirp;
33 int count = 0;
34 int used = 0;
35 int fd;
36 int bytes;
37 int full;
38 full =0;
39 
41 printf("formatted flash\n");
42 while( !full){
43  sprintf(filename,"f%d",count);
44  fd = cfs_open(filename, CFS_WRITE);
45 
46  if (fd < 0) {
47  printf("Failed to open file %s for writing\n", filename);
48  full = 1;
49  }
50 
51  bytes = cfs_write(fd, buf, bufsize);
52 
53  if (bytes != bufsize) {
54  printf("Failed to write file to %s, wrote %d bytes\n", filename, bytes);
55  full = 1;
56  }
57 
58  cfs_close(fd);
59  printf("%d\n",count++);
60  }
61 return(0);
62 }
63 
64 /*---------------------------------------------------------------------------*/
65 PROCESS_THREAD(listcoffee_process, ev, data)
66 {
67 int c;
68 int used;
69 int count;
70  PROCESS_BEGIN();
71 
72  c = coffee_fill();
73  PROCESS_END();
74 }
75 /*---------------------------------------------------------------------------*/
int cfs_open(const char *name, int flags)
Open a file.
Definition: cfs-coffee.c:1011
#define CFS_WRITE
Specify that cfs_open() should open a file for writing.
Definition: cfs.h:104
void cfs_close(int fd)
Close an open file.
Definition: cfs-coffee.c:1047
#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
static volatile clock_time_t count
These routines define the AVR-specific calls declared in /core/sys/clock.h CLOCK_SECOND is the number...
Definition: clock.c:80
Header for the Coffee file system.
CFS header file.
Header file for the CRC16 calculcation
#define PROCESS_BEGIN()
Define the beginning of a process.
Definition: process.h:120