]> git.sur5r.net Git - freertos/blob - FreeRTOS-Labs/Source/FreeRTOS-Plus-FAT/ff_memory.c
Add the Labs projects provided in the V10.2.1_191129 zip file.
[freertos] / FreeRTOS-Labs / Source / FreeRTOS-Plus-FAT / ff_memory.c
1 /*\r
2  * FreeRTOS+FAT build 191128 - Note:  FreeRTOS+FAT is still in the lab!\r
3  * Copyright (C) 2018 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  * Authors include James Walmsley, Hein Tibosch and Richard Barry\r
5  *\r
6  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
7  * this software and associated documentation files (the "Software"), to deal in\r
8  * the Software without restriction, including without limitation the rights to\r
9  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
10  * the Software, and to permit persons to whom the Software is furnished to do so,\r
11  * subject to the following conditions:\r
12  *\r
13  * The above copyright notice and this permission notice shall be included in all\r
14  * copies or substantial portions of the Software.\r
15  *\r
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22  *\r
23  * https://www.FreeRTOS.org\r
24  *\r
25  */\r
26 \r
27 /**\r
28  *      @file           ff_memory.c\r
29  *      @ingroup        MEMORY\r
30  *\r
31  *      @defgroup       MEMORY  FreeRTOS+FAT Memory Access Routines\r
32  *      @brief          Handles memory access in a portable way.\r
33  *\r
34  *      Provides simple, fast, and portable access to memory routines.\r
35  *      These are only used to read data from buffers. That are LITTLE ENDIAN\r
36  *      due to the FAT specification.\r
37  *\r
38  *      These routines may need to be modified to your platform.\r
39  *\r
40  **/\r
41 \r
42 #include "ff_headers.h"\r
43 \r
44 /*\r
45  * Here below 3 x 2 access functions that allow the code\r
46  * not to worry about the endianness of the MCU.\r
47  */\r
48 \r
49 \r
50 #if( ffconfigINLINE_MEMORY_ACCESS == 0 )\r
51 \r
52 uint8_t FF_getChar( const uint8_t *pBuffer, uint32_t aOffset )\r
53 {\r
54         return ( uint8_t ) ( pBuffer[ aOffset ] );\r
55 }\r
56 \r
57 uint16_t FF_getShort( const uint8_t *pBuffer, uint32_t aOffset )\r
58 {\r
59 FF_T_UN16 u16;\r
60 \r
61         pBuffer += aOffset;\r
62         u16.bytes.u8_1 = pBuffer[ 1 ];\r
63         u16.bytes.u8_0 = pBuffer[ 0 ];\r
64 \r
65         return u16.u16;\r
66 }\r
67 \r
68 uint32_t FF_getLong( const uint8_t *pBuffer, uint32_t aOffset )\r
69 {\r
70 FF_T_UN32 u32;\r
71 \r
72         pBuffer += aOffset;\r
73         u32.bytes.u8_3 = pBuffer[ 3 ];\r
74         u32.bytes.u8_2 = pBuffer[ 2 ];\r
75         u32.bytes.u8_1 = pBuffer[ 1 ];\r
76         u32.bytes.u8_0 = pBuffer[ 0 ];\r
77 \r
78         return u32.u32;\r
79 }\r
80 \r
81 void FF_putChar( uint8_t *pBuffer, uint32_t aOffset, uint32_t Value )\r
82 {\r
83         pBuffer[ aOffset ] = ( uint8_t ) Value;\r
84 }\r
85 \r
86 void FF_putShort( uint8_t *pBuffer, uint32_t aOffset, uint32_t Value )\r
87 {\r
88 FF_T_UN16 u16;\r
89 \r
90         u16.u16 = ( uint16_t ) Value;\r
91         pBuffer += aOffset;\r
92         pBuffer[ 0 ] = u16.bytes.u8_0;\r
93         pBuffer[ 1 ] = u16.bytes.u8_1;\r
94 }\r
95 \r
96 void FF_putLong( uint8_t *pBuffer, uint32_t aOffset, uint32_t Value )\r
97 {\r
98 FF_T_UN32 u32;\r
99 \r
100         u32.u32 = Value;\r
101         pBuffer += aOffset;\r
102         pBuffer[ 0 ] = u32.bytes.u8_0;\r
103         pBuffer[ 1 ] = u32.bytes.u8_1;\r
104         pBuffer[ 2 ] = u32.bytes.u8_2;\r
105         pBuffer[ 3 ] = u32.bytes.u8_3;\r
106 }\r
107 \r
108 #endif\r