Kinetis SDK v.1.2 Demo Applications User's Guide  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
fs.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25  * OF SUCH DAMAGE.
26  *
27  * This file is part of the lwIP TCP/IP stack.
28  *
29  * Author: Adam Dunkels <adam@sics.se>
30  *
31  */
32 
33 #ifndef __FS_H__
34 #define __FS_H__
35 
37 // Includes
39 
40 #include "lwip/opt.h"
41 #include "lwip/err.h"
42 
44 // Definitions
46 
47 // Set this to 1 and provide the functions:
48 // - "int fs_open_custom(struct fs_file *file, const char *name)"
49 // Called first for every opened file to allow opening files
50 // that are not included in fsdata(_custom).c
51 // - "void fs_close_custom(struct fs_file *file)"
52 // Called to free resources allocated by fs_open_custom().
53 #ifndef LWIP_HTTPD_CUSTOM_FILES
54 #define LWIP_HTTPD_CUSTOM_FILES 0
55 #endif
56 
57 // Set this to 1 to support fs_read() to dynamically read file data.
58 // Without this (default=off), only one-block files are supported,
59 // and the contents must be ready after fs_open().
60 #ifndef LWIP_HTTPD_DYNAMIC_FILE_READ
61 #define LWIP_HTTPD_DYNAMIC_FILE_READ 0
62 #endif
63 
64 // Set this to 1 to include an application state argument per file
65 // that is opened. This allows to keep a state per connection/file.
66 #ifndef LWIP_HTTPD_FILE_STATE
67 #define LWIP_HTTPD_FILE_STATE 0
68 #endif
69 
70 // HTTPD_PRECALCULATED_CHECKSUM==1: include precompiled checksums for
71 // predefined (MSS-sized) chunks of the files to prevent having to calculate
72 // the checksums at runtime. */
73 #ifndef HTTPD_PRECALCULATED_CHECKSUM
74 #define HTTPD_PRECALCULATED_CHECKSUM 0
75 #endif
76 
77 // LWIP_HTTPD_FS_ASYNC_READ==1: support asynchronous read operations
78 // (fs_read_async returns FS_READ_DELAYED and calls a callback when finished).
79 #ifndef LWIP_HTTPD_FS_ASYNC_READ
80 #define LWIP_HTTPD_FS_ASYNC_READ 0
81 #endif
82 
83 #define FS_READ_EOF -1
84 #define FS_READ_DELAYED -2
85 
86 #if HTTPD_PRECALCULATED_CHECKSUM
87 struct fsdata_chksum {
88  u32_t offset;
89  u16_t chksum;
90  u16_t len;
91 };
92 #endif // HTTPD_PRECALCULATED_CHECKSUM
93 
94 struct fs_file {
95  const char *data;
96  int len;
97  int index;
98  void *pextension;
99 #if HTTPD_PRECALCULATED_CHECKSUM
100  const struct fsdata_chksum *chksum;
101  u16_t chksum_count;
102 #endif // HTTPD_PRECALCULATED_CHECKSUM
104 #if LWIP_HTTPD_CUSTOM_FILES
105  u8_t is_custom_file;
106 #endif // LWIP_HTTPD_CUSTOM_FILES
107 #if LWIP_HTTPD_FILE_STATE
108  void *state;
109 #endif // LWIP_HTTPD_FILE_STATE
110 };
111 
112 #if LWIP_HTTPD_FS_ASYNC_READ
113 typedef void (*fs_wait_cb)(void *arg);
114 #endif // LWIP_HTTPD_FS_ASYNC_READ
115 
116 err_t fs_open(struct fs_file *file, const char *name);
117 void fs_close(struct fs_file *file);
118 #if LWIP_HTTPD_DYNAMIC_FILE_READ
119 #if LWIP_HTTPD_FS_ASYNC_READ
120 int fs_read_async(struct fs_file *file, char *buffer, int count, fs_wait_cb callback_fn, void *callback_arg);
121 #else // LWIP_HTTPD_FS_ASYNC_READ
122 int fs_read(struct fs_file *file, char *buffer, int count);
123 #endif // LWIP_HTTPD_FS_ASYNC_READ
124 #endif // LWIP_HTTPD_DYNAMIC_FILE_READ
125 #if LWIP_HTTPD_FS_ASYNC_READ
126 int fs_is_file_ready(struct fs_file *file, fs_wait_cb callback_fn, void *callback_arg);
127 #endif // LWIP_HTTPD_FS_ASYNC_READ
128 int fs_bytes_left(struct fs_file *file);
129 
130 #if LWIP_HTTPD_FILE_STATE
131 // This user-defined function is called when a file is opened.
132 void *fs_state_init(struct fs_file *file, const char *name);
133 // This user-defined function is called when a file is closed.
134 void fs_state_free(struct fs_file *file, void *state);
135 #endif // #if LWIP_HTTPD_FILE_STATE
136 
137 #endif // __FS_H__
int index
Definition: fs.h:97
int fs_bytes_left(struct fs_file *file)
Definition: fs.c:196
u8_t http_header_included
Definition: fs.h:103
int len
Definition: fs.h:96
UINT8 buffer[BUFFER_SIZE_BYTE]
Definition: flash_demo_ram.c:53
void * pextension
Definition: fs.h:98
err_t fs_open(struct fs_file *file, const char *name)
Definition: fs.c:76
Definition: fs.h:94
void fs_close(struct fs_file *file)
Definition: fs.c:117
const char * data
Definition: fs.h:95