2 * FreeRTOS+FAT SL V1.0.1 (C) 2014 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 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
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
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
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
36 * http://www.FreeRTOS.org
\r
37 * http://www.FreeRTOS.org/FreeRTOS-Plus
\r
41 #include "../../api/fat_sl.h"
\r
42 #include "../../psp/include/psp_rtc.h"
\r
47 #include "../../version/ver_fat_sl.h"
\r
48 #if VER_FAT_SL_MAJOR != 5 || VER_FAT_SL_MINOR != 2
\r
49 #error Incompatible FAT_SL version number!
\r
53 /****************************************************************************
\r
57 * get a word 16bit number from a memory (it uses LITTLE ENDIAN mode always)
\r
61 * ptr - pointer where data is
\r
67 ***************************************************************************/
\r
68 unsigned short _f_getword ( void * ptr )
\r
70 unsigned char * sptr = (unsigned char *)ptr;
\r
73 ret = (unsigned short)( sptr[1] & 0xff );
\r
75 ret |= ( sptr[0] & 0xff );
\r
80 /****************************************************************************
\r
84 * set a word 16bit number into a memory (it uses LITTLE ENDIAN mode always)
\r
88 * ptr - where to store data
\r
89 * num - 16 bit number to store
\r
91 ***************************************************************************/
\r
92 void _f_setword ( void * ptr, unsigned short num )
\r
94 unsigned char * sptr = (unsigned char *)ptr;
\r
96 sptr[1] = (unsigned char)( num >> 8 );
\r
97 sptr[0] = (unsigned char)( num );
\r
101 /****************************************************************************
\r
105 * get a long 32bit number from a memory (it uses LITTLE ENDIAN mode always)
\r
109 * ptr - pointer where data is
\r
115 ***************************************************************************/
\r
116 unsigned long _f_getlong ( void * ptr )
\r
118 unsigned char * sptr = (unsigned char *)ptr;
\r
121 ret = (unsigned long)( sptr[3] & 0xff );
\r
123 ret |= ( sptr[2] & 0xff );
\r
125 ret |= ( sptr[1] & 0xff );
\r
127 ret |= ( sptr[0] & 0xff );
\r
132 /****************************************************************************
\r
136 * set a long 32bit number into a memory (it uses LITTLE ENDIAN mode always)
\r
140 * ptr - where to store data
\r
141 * num - 32 bit number to store
\r
143 ***************************************************************************/
\r
144 void _f_setlong ( void * ptr, unsigned long num )
\r
146 unsigned char * sptr = (unsigned char *)ptr;
\r
148 sptr[3] = (unsigned char)( num >> 24 );
\r
149 sptr[2] = (unsigned char)( num >> 16 );
\r
150 sptr[1] = (unsigned char)( num >> 8 );
\r
151 sptr[0] = (unsigned char)( num );
\r
155 /****************************************************************************
\r
159 * fills with zero charater to memory
\r
163 * num - number of characters
\r
164 * ptr - where to store data
\r
168 * last write position
\r
170 ***************************************************************************/
\r
171 unsigned char * _setcharzero ( int num, unsigned char * ptr )
\r
182 /****************************************************************************
\r
186 * copy a charater string to memory
\r
190 * array - original code what to copy
\r
191 * num - number of characters
\r
192 * ptr - where to store data
\r
196 * last write position
\r
198 ***************************************************************************/
\r
199 unsigned char * _setchar ( const unsigned char * array, int num, unsigned char * ptr )
\r
203 return _setcharzero( num, ptr );
\r
215 /****************************************************************************
\r
219 * store a 16bit word into memory
\r
223 * num - 16bit number to store
\r
224 * ptr - where to store data
\r
228 * last write position
\r
230 ***************************************************************************/
\r
231 unsigned char * _setword ( unsigned short num, unsigned char * ptr )
\r
233 _f_setword( ptr, num );
\r
238 /****************************************************************************
\r
242 * store a 32bit long number into memory
\r
246 * num - 32bit number to store
\r
247 * ptr - where to store data
\r
251 * last write position
\r
253 ***************************************************************************/
\r
254 unsigned char * _setlong ( unsigned long num, unsigned char * ptr )
\r
256 _f_setlong( ptr, num );
\r
261 /****************************************************************************
\r
265 * convert a string into lower case
\r
269 * s - input string to convert
\r
271 ***************************************************************************/
\r
272 char _f_toupper ( char ch )
\r
274 if ( ( ch >= 'a' ) && ( ch <= 'z' ) )
\r
276 return (char)( ch - 'a' + 'A' );
\r
283 /****************************************************************************
\r
288 * time - pointer to time variable
\r
289 * date - pointer to date variable
\r
291 * time - current time
\r
292 * date - current date
\r
297 ***************************************************************************/
\r
298 void f_igettimedate ( unsigned short * time, unsigned short * date )
\r
300 t_psp_timedate s_timedate;
\r
302 psp_getcurrenttimedate( &s_timedate );
\r
304 *time = ( ( (uint16_t)s_timedate.hour << F_CTIME_HOUR_SHIFT ) & F_CTIME_HOUR_MASK )
\r
305 | ( ( (uint16_t)s_timedate.min << F_CTIME_MIN_SHIFT ) & F_CTIME_MIN_MASK )
\r
306 | ( ( ( (uint16_t)s_timedate.sec >> 1 ) << F_CTIME_SEC_SHIFT ) & F_CTIME_SEC_MASK );
\r
308 *date = ( ( ( s_timedate.year - 1980 ) << F_CDATE_YEAR_SHIFT ) & F_CDATE_YEAR_MASK )
\r
309 | ( ( (uint16_t)s_timedate.month << F_CDATE_MONTH_SHIFT ) & F_CDATE_MONTH_MASK )
\r
310 | ( ( (uint16_t)s_timedate.day << F_CDATE_DAY_SHIFT ) & F_CDATE_DAY_MASK );
\r