Contiki-Inga 3.x
fat_coop.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Institute of Operating Systems and Computer Networks (TU Brunswick).
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * Author: Christoph Peltz <peltz@ibr.cs.tu-bs.de>
30  */
31 
32  /**
33  * \addtogroup cfs
34  * @{
35  *
36  * \defgroup fat_coop_driver FAT Driver - Cooperative Additions
37  *
38  * <p></p>
39  * @{
40  *
41  */
42 
43 /**
44  * \file
45  * FAT driver Coop Additions definitions
46  * \author
47  * Christoph Peltz <peltz@ibr.cs.tu-bs.de>
48  */
49 
50 #ifndef FAT_COOP_H
51 #define FAT_COOP_H
52 
53 #include <stdint.h>
54 #include "cfs-fat.h"
55 
56 #define FAT_COOP_BUFFER_SIZE 128
57 #define FAT_COOP_QUEUE_SIZE 15
58 #define FAT_COOP_SLOT_SIZE_MS 50L
59 
60 #define FAT_COOP_TIME_READ_BLOCK_MS 8
61 #define FAT_COOP_TIME_WRITE_BLOCK_MS 12
62 
63 #define FAT_COOP_STACK_SIZE 192
64 
65 
66 enum {
67  STATUS_QUEUED = 1,
68  STATUS_INPROGRESS,
69  STATUS_DONE
70 };
71 
72 typedef struct q_entry_generic_file_op {
73  int fd;
74  uint8_t *buffer;
75  uint16_t length;
76 } GenericFileOp;
77 
78 typedef struct q_entry_open_file_op {
79  const char *name;
80  int flags;
81 } OpenFileOp;
82 
83 typedef struct q_entry_seek_file_op {
84  int fd;
85  cfs_offset_t offset;
86  int whence;
87 } SeekFileOp;
88 
89 typedef struct q_entry_dir_op {
90  struct cfs_dir *dirp;
91  union {
92  struct cfs_dirent *dirent;
93  const char *name;
94  } u;
95 } DirOp;
96 
97 typedef enum {
98  COOP_CFS_OPEN,
99  COOP_CFS_CLOSE,
100  COOP_CFS_WRITE,
101  COOP_CFS_READ,
102  COOP_CFS_SEEK,
103  COOP_CFS_REMOVE,
104  COOP_CFS_OPENDIR,
105  COOP_CFS_READDIR,
106  COOP_CFS_CLOSEDIR
107 } Operation;
108 
109 typedef struct q_entry {
110  uint8_t token;
111  Operation op;
112  struct process *source_process;
113  union {
114  GenericFileOp generic;
115  OpenFileOp open;
116  SeekFileOp seek;
117  DirOp dir;
118  } parameters;
119  uint8_t state;
120  int16_t ret_value;
121 } QueueEntry;
122 
123 typedef struct event_op_finished {
124  uint8_t token;
125  int16_t ret_value;
126 } Event_OperationFinished;
127 
128 int8_t ccfs_open( const char *name, int flags, uint8_t *token );
129 int8_t ccfs_close( int fd, uint8_t *token);
130 int8_t ccfs_write( int fd, uint8_t *buf, uint16_t length, uint8_t *token );
131 int8_t ccfs_read( int fd, uint8_t *buf, uint16_t length, uint8_t *token );
132 int8_t ccfs_seek( int fd, cfs_offset_t offset, int whence, uint8_t *token);
133 int8_t ccfs_remove( const char *name, uint8_t *token );
134 int8_t ccfs_opendir( struct cfs_dir *dirp, const char *name, uint8_t *token );
135 int8_t ccfs_readdir( struct cfs_dir *dirp, struct cfs_dirent *dirent, uint8_t *token);
136 int8_t ccfs_closedir(struct cfs_dir *dirp, uint8_t *token);
137 uint8_t fat_op_status( uint8_t token );
138 uint16_t fat_estimate_by_token( uint8_t token );
139 uint16_t fat_estimate_by_parameter( Operation type, uint16_t length );
140 uint8_t fat_buffer_available( uint16_t length );
141 void printQueueEntry( QueueEntry *entry );
142 process_event_t get_coop_event_id();
143 uint8_t get_item_from_buffer( uint8_t *start, uint16_t index);
144 
145 void operation(void *data);
146 
147 PROCESS_NAME(fsp);
148 #endif