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/fat_sl.h"
\r
40 #include "../../psp/include/psp_string.h"
\r
46 #include "../../version/ver_fat_sl.h"
\r
47 #if VER_FAT_SL_MAJOR != 3 || VER_FAT_SL_MINOR != 2
\r
48 #error Incompatible FAT_SL version number!
\r
51 F_DRIVER * mdrv = NULL; /* driver structure */
\r
54 /****************************************************************************
\r
58 * checking a volume driver status, if media is removed or has been changed
\r
62 * error code or zero if successful
\r
64 ***************************************************************************/
\r
65 unsigned char _f_checkstatus ( void )
\r
67 if ( mdrv->getstatus != NULL )
\r
69 if ( mdrv->getstatus( mdrv ) & ( F_ST_MISSING | F_ST_CHANGED ) )
\r
71 gl_volume.state = F_STATE_NEEDMOUNT; /*card has been removed;*/
\r
72 return F_ERR_CARDREMOVED;
\r
80 /****************************************************************************
\r
84 * write sector data on a volume, it calls low level driver function, it
\r
85 * writes a complete sector
\r
88 * sector - which physical sector
\r
91 * error code or zero if successful
\r
93 ***************************************************************************/
\r
94 unsigned char _f_writeglsector ( unsigned long sector )
\r
96 unsigned char retry;
\r
98 if ( mdrv->writesector == NULL )
\r
100 gl_volume.state = F_STATE_NEEDMOUNT; /*no write function*/
\r
101 return F_ERR_ACCESSDENIED;
\r
104 if ( sector == (unsigned long)-1 )
\r
106 if ( gl_file.modified )
\r
108 sector = gl_file.pos.sector;
\r
112 sector = gl_volume.actsector;
\r
116 if ( sector != (unsigned long)-1 )
\r
118 if ( mdrv->getstatus != NULL )
\r
120 unsigned int status;
\r
122 status = mdrv->getstatus( mdrv );
\r
124 if ( status & ( F_ST_MISSING | F_ST_CHANGED ) )
\r
126 gl_volume.state = F_STATE_NEEDMOUNT; /*card has been removed;*/
\r
127 return F_ERR_CARDREMOVED;
\r
130 if ( status & ( F_ST_WRPROTECT ) )
\r
132 gl_volume.state = F_STATE_NEEDMOUNT; /*card has been removed;*/
\r
133 return F_ERR_WRITEPROTECT;
\r
137 gl_volume.modified = 0;
\r
138 gl_file.modified = 0;
\r
139 gl_volume.actsector = sector;
\r
140 for ( retry = 3 ; retry ; retry-- )
\r
143 mdrv_ret = mdrv->writesector( mdrv, (unsigned char *)gl_sector, sector );
\r
149 if ( mdrv_ret == -1 )
\r
151 gl_volume.state = F_STATE_NEEDMOUNT; /*card has been removed;*/
\r
152 return F_ERR_CARDREMOVED;
\r
158 return F_ERR_ONDRIVE;
\r
159 } /* _f_writeglsector */
\r
162 /****************************************************************************
\r
166 * read sector data from a volume, it calls low level driver function, it
\r
167 * reads a complete sector
\r
170 * sector - which physical sector is read
\r
173 * error code or zero if successful
\r
175 ***************************************************************************/
\r
176 unsigned char _f_readglsector ( unsigned long sector )
\r
178 unsigned char retry;
\r
181 if ( sector == gl_volume.actsector )
\r
186 if ( gl_volume.modified || gl_file.modified )
\r
188 ret = _f_writeglsector( (unsigned long)-1 );
\r
196 for ( retry = 3 ; retry ; retry-- )
\r
199 mdrv_ret = mdrv->readsector( mdrv, (unsigned char *)gl_sector, sector );
\r
202 gl_volume.actsector = sector;
\r
206 if ( mdrv_ret == -1 )
\r
208 gl_volume.state = F_STATE_NEEDMOUNT; /*card has been removed;*/
\r
209 return F_ERR_CARDREMOVED;
\r
213 gl_volume.actsector = (unsigned long)-1;
\r
214 return F_ERR_ONDRIVE;
\r
215 } /* _f_readglsector */
\r