]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/FreeRTOS-Plus-FAT-SL/media-drv/ram/ramdrv_f.c
Add missing +TCP code.
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-FAT-SL / media-drv / ram / ramdrv_f.c
1 /*\r
2  * FreeRTOS+FAT SL V1.0.1 (C) 2014 HCC Embedded\r
3  *\r
4  * The FreeRTOS+FAT SL license terms are different to the FreeRTOS license\r
5  * terms.\r
6  *\r
7  * FreeRTOS+FAT SL uses a dual license model that allows the software to be used\r
8  * under a standard GPL open source license, or a commercial license.  The\r
9  * standard GPL license (unlike the modified GPL license under which FreeRTOS\r
10  * itself is distributed) requires that all software statically linked with\r
11  * FreeRTOS+FAT SL is also distributed under the same GPL V2 license terms.\r
12  * Details of both license options follow:\r
13  *\r
14  * - Open source licensing -\r
15  * FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and\r
16  * distributed without charge provided the user adheres to version two of the\r
17  * GNU General Public License (GPL) and does not remove the copyright notice or\r
18  * this text.  The GPL V2 text is available on the gnu.org web site, and on the\r
19  * following URL: http://www.FreeRTOS.org/gpl-2.0.txt.\r
20  *\r
21  * - Commercial licensing -\r
22  * Businesses and individuals who for commercial or other reasons cannot comply\r
23  * with the terms of the GPL V2 license must obtain a commercial license before\r
24  * incorporating FreeRTOS+FAT SL into proprietary software for distribution in\r
25  * any form.  Commercial licenses can be purchased from\r
26  * http://shop.freertos.org/fat_sl and do not require any source files to be\r
27  * changed.\r
28  *\r
29  * FreeRTOS+FAT SL is distributed in the hope that it will be useful.  You\r
30  * cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as\r
31  * is'.  FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the\r
32  * implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A\r
33  * PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all\r
34  * conditions and terms, be they implied, expressed, or statutory.\r
35  *\r
36  * http://www.FreeRTOS.org\r
37  * http://www.FreeRTOS.org/FreeRTOS-Plus\r
38  *\r
39  */\r
40 \r
41 #include "../../api/api_mdriver_ram.h"\r
42 #include "config_mdriver_ram.h"\r
43 #include "../../psp/include/psp_string.h"\r
44 \r
45 #include "../../version/ver_mdriver_ram.h"\r
46 #if VER_MDRIVER_RAM_MAJOR != 1 || VER_MDRIVER_RAM_MINOR != 2\r
47  #error Incompatible MDRIVER_RAM version number!\r
48 #endif\r
49 \r
50 /* The array used as the RAM disk storage. */\r
51 static char  ramdrv[ MDRIVER_RAM_VOLUME0_SIZE ];\r
52 \r
53 /* The F_DRIVER structure that is filled with the RAM disk versions of the read\r
54 sector, write sector, etc. functions. */\r
55 static F_DRIVER  t_driver;\r
56 \r
57 static const unsigned long maxsector = MDRIVER_RAM_VOLUME0_SIZE / MDRIVER_RAM_SECTOR_SIZE;\r
58 \r
59 /* Disk not initialized yet. */\r
60 static char in_use = 0;\r
61 \r
62 \r
63 /****************************************************************************\r
64  * Read one sector\r
65  ***************************************************************************/\r
66 static int ram_readsector ( F_DRIVER * driver, void * data, unsigned long sector )\r
67 {\r
68   long       len;\r
69   char     * d = (char *)data;\r
70   char     * s;\r
71 \r
72   /* Not used. */\r
73   ( void ) driver;\r
74 \r
75   /* Check for valid sector. */\r
76   if ( sector >= maxsector )\r
77   {\r
78     return MDRIVER_RAM_ERR_SECTOR;\r
79   }\r
80 \r
81   if( in_use == 0 )\r
82   {\r
83     return MDRIVER_RAM_ERR_NOTAVAILABLE;\r
84   }\r
85 \r
86   /* Locate offset into RAM disk for sector. */\r
87   s = ramdrv;\r
88   s += sector * MDRIVER_RAM_SECTOR_SIZE;\r
89   len = MDRIVER_RAM_SECTOR_SIZE;\r
90 \r
91 #if MDRIVER_MEM_LONG_ACCESS\r
92   if ( ( !( len & 3 ) ) && ( !( ( (long)d ) & 3 ) ) && ( !( ( (long)s ) & 3 ) ) )\r
93   {\r
94     long * dd = (long *)d;\r
95     long * ss = (long *)s;\r
96     len >>= 2;\r
97         /* Read words. */\r
98     while ( len-- )\r
99     {\r
100       *dd++ = *ss++;\r
101     }\r
102 \r
103     return MDRIVER_RAM_NO_ERROR;\r
104   }\r
105 \r
106 #endif /* if MDRIVER_MEM_LONG_ACCESS */\r
107 \r
108   /* Read bytes. */\r
109   while ( len-- )\r
110   {\r
111     *d++ = *s++;\r
112   }\r
113 \r
114   return MDRIVER_RAM_NO_ERROR;\r
115 }\r
116 \r
117 /****************************************************************************\r
118  * Write one sector\r
119  ***************************************************************************/\r
120 static int ram_writesector ( F_DRIVER * driver, void * data, unsigned long sector )\r
121 {\r
122   long       len;\r
123   char     * s = (char *)data;\r
124   char     * d;\r
125 \r
126   /* Not used. */\r
127   ( void ) driver;\r
128 \r
129   /* Check for valid sector. */\r
130   if ( sector >= maxsector )\r
131   {\r
132     return MDRIVER_RAM_ERR_SECTOR;\r
133   }\r
134 \r
135   if( in_use == 0 )\r
136   {\r
137           return MDRIVER_RAM_ERR_NOTAVAILABLE;\r
138   }\r
139 \r
140   /* Locate offset into RAM disk for sector. */\r
141   d = ramdrv;\r
142   d += sector * MDRIVER_RAM_SECTOR_SIZE;\r
143   len = MDRIVER_RAM_SECTOR_SIZE;\r
144 \r
145 #if MDRIVER_MEM_LONG_ACCESS\r
146   if ( ( !( len & 3 ) ) && ( !( ( (long)d ) & 3 ) ) && ( !( ( (long)s ) & 3 ) ) )\r
147   {\r
148     long * dd = (long *)d;\r
149     long * ss = (long *)s;\r
150     len >>= 2;\r
151 \r
152         /* Write words. */\r
153     while ( len-- )\r
154     {\r
155       *dd++ = *ss++;\r
156     }\r
157 \r
158     return MDRIVER_RAM_NO_ERROR;\r
159   }\r
160 #endif /* if MDRIVER_MEM_LONG_ACCESS */\r
161 \r
162   /* Write bytes. */\r
163   while ( len-- )\r
164   {\r
165     *d++ = *s++;\r
166   }\r
167 \r
168   return MDRIVER_RAM_NO_ERROR;\r
169 }\r
170 \r
171 \r
172 /****************************************************************************\r
173  *\r
174  * ram_getphy\r
175  *\r
176  * determinate ramdrive physicals\r
177  *\r
178  * INPUTS\r
179  *\r
180  * driver - driver structure\r
181  * phy - this structure has to be filled with physical information\r
182  *\r
183  * RETURNS\r
184  *\r
185  * error code or zero if successful\r
186  *\r
187  ***************************************************************************/\r
188 static int ram_getphy ( F_DRIVER * driver, F_PHY * phy )\r
189 {\r
190   /* Not used. */\r
191   ( void ) driver;\r
192 \r
193   phy->number_of_sectors = maxsector;\r
194   phy->bytes_per_sector = MDRIVER_RAM_SECTOR_SIZE;\r
195 \r
196   return MDRIVER_RAM_NO_ERROR;\r
197 }\r
198 \r
199 \r
200 /****************************************************************************\r
201  *\r
202  * ram_release\r
203  *\r
204  * Releases a drive\r
205  *\r
206  * INPUTS\r
207  *\r
208  * driver_param - driver parameter\r
209  *\r
210  ***************************************************************************/\r
211 static void ram_release ( F_DRIVER * driver )\r
212 {\r
213   /* Not used. */\r
214   ( void ) driver;\r
215 \r
216   /* Disk no longer in use. */\r
217   in_use = 0;\r
218 }\r
219 \r
220 \r
221 /****************************************************************************\r
222  *\r
223  * ram_initfunc\r
224  *\r
225  * this init function has to be passed for highlevel to initiate the\r
226  * driver functions\r
227  *\r
228  * INPUTS\r
229  *\r
230  * driver_param - driver parameter\r
231  *\r
232  * RETURNS\r
233  *\r
234  * driver structure pointer\r
235  *\r
236  ***************************************************************************/\r
237 F_DRIVER * ram_initfunc ( unsigned long driver_param )\r
238 {\r
239   ( void ) driver_param;\r
240 \r
241   if( in_use )\r
242     return NULL;\r
243 \r
244   (void)psp_memset( &t_driver, 0, sizeof( F_DRIVER ) );\r
245 \r
246   t_driver.readsector = ram_readsector;\r
247   t_driver.writesector = ram_writesector;\r
248   t_driver.getphy = ram_getphy;\r
249   t_driver.release = ram_release;\r
250 \r
251   in_use = 1;\r
252 \r
253   return &t_driver;\r
254 } /* ram_initfunc */\r
255 \r