2 * FreeRTOS+FAT FS V1.0.0 (C) 2013 HCC Embedded
\r
4 * The FreeRTOS+FAT SL license terms are different to the FreeRTOS license
\r
7 * FreeRTOS+FAT SL uses a dual license model that allows the software to be used
\r
8 * under a pure GPL open source license (as opposed to the modified GPL licence
\r
9 * under which FreeRTOS is distributed) or a commercial license. Details of
\r
10 * both license options follow:
\r
12 * - Open source licensing -
\r
13 * FreeRTOS+FAT SL is a free download and may be used, modified, evaluated and
\r
14 * distributed without charge provided the user adheres to version two of the
\r
15 * GNU General Public License (GPL) and does not remove the copyright notice or
\r
16 * this text. The GPL V2 text is available on the gnu.org web site, and on the
\r
17 * following URL: http://www.FreeRTOS.org/gpl-2.0.txt.
\r
19 * - Commercial licensing -
\r
20 * Businesses and individuals who for commercial or other reasons cannot comply
\r
21 * with the terms of the GPL V2 license must obtain a commercial license before
\r
22 * incorporating FreeRTOS+FAT SL into proprietary software for distribution in
\r
23 * any form. Commercial licenses can be purchased from
\r
24 * http://shop.freertos.org/fat_sl and do not require any source files to be
\r
27 * FreeRTOS+FAT SL is distributed in the hope that it will be useful. You
\r
28 * cannot use FreeRTOS+FAT SL unless you agree that you use the software 'as
\r
29 * is'. FreeRTOS+FAT SL is provided WITHOUT ANY WARRANTY; without even the
\r
30 * implied warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
\r
31 * PARTICULAR PURPOSE. Real Time Engineers Ltd. and HCC Embedded disclaims all
\r
32 * conditions and terms, be they implied, expressed, or statutory.
\r
34 * http://www.FreeRTOS.org
\r
35 * http://www.FreeRTOS.org/FreeRTOS-Plus
\r
39 #include "../../api/api_mdriver_ram.h"
\r
40 #include "config_mdriver_ram.h"
\r
41 #include "../../psp/include/psp_string.h"
\r
43 #include "../../version/ver_mdriver_ram.h"
\r
44 #if VER_MDRIVER_RAM_MAJOR != 1 || VER_MDRIVER_RAM_MINOR != 2
\r
45 #error Incompatible MDRIVER_RAM version number!
\r
49 char ramdrv0[MDRIVER_RAM_VOLUME0_SIZE];
\r
54 unsigned long maxsector;
\r
59 static F_DRIVER t_drivers[1];
\r
61 static t_RamDrv RamDrv[1] =
\r
63 { ramdrv0, ( MDRIVER_RAM_VOLUME0_SIZE / MDRIVER_RAM_SECTOR_SIZE ), 0, &t_drivers[0] }
\r
67 /****************************************************************************
\r
69 ***************************************************************************/
\r
70 static int ram_readsector ( F_DRIVER * driver, void * data, unsigned long sector )
\r
73 char * d = (char *)data;
\r
75 t_RamDrv * p = (t_RamDrv *)( driver->user_ptr );
\r
77 if ( sector >= p->maxsector )
\r
79 return MDRIVER_RAM_ERR_SECTOR;
\r
83 s += sector * MDRIVER_RAM_SECTOR_SIZE;
\r
84 len = MDRIVER_RAM_SECTOR_SIZE;
\r
86 #if MDRIVER_MEM_LONG_ACCESS
\r
87 if ( ( !( len & 3 ) ) && ( !( ( (long)d ) & 3 ) ) && ( !( ( (long)s ) & 3 ) ) )
\r
89 long * dd = (long *)d;
\r
90 long * ss = (long *)s;
\r
97 return MDRIVER_RAM_NO_ERROR;
\r
100 #endif /* if MDRIVER_MEM_LONG_ACCESS */
\r
107 return MDRIVER_RAM_NO_ERROR;
\r
110 /****************************************************************************
\r
112 ***************************************************************************/
\r
113 static int ram_writesector ( F_DRIVER * driver, void * data, unsigned long sector )
\r
116 char * s = (char *)data;
\r
118 t_RamDrv * p = (t_RamDrv *)( driver->user_ptr );
\r
120 if ( sector >= p->maxsector )
\r
122 return MDRIVER_RAM_ERR_SECTOR;
\r
126 d += sector * MDRIVER_RAM_SECTOR_SIZE;
\r
127 len = MDRIVER_RAM_SECTOR_SIZE;
\r
129 #if MDRIVER_MEM_LONG_ACCESS
\r
130 if ( ( !( len & 3 ) ) && ( !( ( (long)d ) & 3 ) ) && ( !( ( (long)s ) & 3 ) ) )
\r
132 long * dd = (long *)d;
\r
133 long * ss = (long *)s;
\r
140 return MDRIVER_RAM_NO_ERROR;
\r
143 #endif /* if MDRIVER_MEM_LONG_ACCESS */
\r
150 return MDRIVER_RAM_NO_ERROR;
\r
154 /****************************************************************************
\r
158 * determinate ramdrive physicals
\r
162 * driver - driver structure
\r
163 * phy - this structure has to be filled with physical information
\r
167 * error code or zero if successful
\r
169 ***************************************************************************/
\r
170 static int ram_getphy ( F_DRIVER * driver, F_PHY * phy )
\r
172 t_RamDrv * p = (t_RamDrv *)( driver->user_ptr );
\r
174 phy->number_of_sectors = p->maxsector;
\r
175 phy->bytes_per_sector = MDRIVER_RAM_SECTOR_SIZE;
\r
177 return MDRIVER_RAM_NO_ERROR;
\r
181 /****************************************************************************
\r
189 * driver_param - driver parameter
\r
191 ***************************************************************************/
\r
192 static void ram_release ( F_DRIVER * driver )
\r
194 t_RamDrv * p = (t_RamDrv *)( driver->user_ptr );
\r
203 /****************************************************************************
\r
207 * this init function has to be passed for highlevel to initiate the
\r
212 * driver_param - driver parameter
\r
216 * driver structure pointer
\r
218 ***************************************************************************/
\r
219 F_DRIVER * ram_initfunc ( unsigned long driver_param )
\r
223 p = RamDrv + driver_param;
\r
235 (void)psp_memset( p->driver, 0, sizeof( F_DRIVER ) );
\r
237 p->driver->readsector = ram_readsector;
\r
238 p->driver->writesector = ram_writesector;
\r
239 p->driver->getphy = ram_getphy;
\r
240 p->driver->release = ram_release;
\r
241 p->driver->user_ptr = p;
\r
246 } /* ram_initfunc */
\r