]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS-Labs/Source/FreeRTOS-Plus-FAT/include/ff_memory.h
Add the Labs projects provided in the V10.2.1_191129 zip file.
[freertos] / FreeRTOS-Labs / Source / FreeRTOS-Plus-FAT / include / ff_memory.h
diff --git a/FreeRTOS-Labs/Source/FreeRTOS-Plus-FAT/include/ff_memory.h b/FreeRTOS-Labs/Source/FreeRTOS-Plus-FAT/include/ff_memory.h
new file mode 100644 (file)
index 0000000..f3bae06
--- /dev/null
@@ -0,0 +1,168 @@
+/*\r
+ * FreeRTOS+FAT build 191128 - Note:  FreeRTOS+FAT is still in the lab!\r
+ * Copyright (C) 2018 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
+ * Authors include James Walmsley, Hein Tibosch and Richard Barry\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+ * this software and associated documentation files (the "Software"), to deal in\r
+ * the Software without restriction, including without limitation the rights to\r
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
+ * the Software, and to permit persons to whom the Software is furnished to do so,\r
+ * subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included in all\r
+ * copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ *\r
+ * https://www.FreeRTOS.org\r
+ *\r
+ */\r
+\r
+/**\r
+ *     @file           ff_memory.h\r
+ *     @ingroup        MEMORY\r
+ **/\r
+\r
+#ifndef _FF_MEMORY_H_\r
+#define _FF_MEMORY_H_\r
+\r
+/*\r
+ * When sector data is written or analysed, some values might be stored unaligned.\r
+ * The routines below treat all values as little arrays of either 2 or 4 bytes.\r
+ * Also on big endian platforms, the order of bytes will be swapped.\r
+ */\r
+/*---------- PROTOTYPES */\r
+\r
+#if( ffconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN )\r
+       /*\r
+        * FAT is little endian.\r
+        * On a little endian CPU, bytes will be copied to the structures below 1-to-1 :\r
+        */\r
+       typedef struct\r
+       {\r
+               uint8_t u8_0;   /* the first byte */\r
+               uint8_t u8_1;   /* the second byte */\r
+       } FF_TShort_t;\r
+\r
+       typedef struct\r
+       {\r
+               uint8_t u8_0;\r
+               uint8_t u8_1;\r
+               uint8_t u8_2;\r
+               uint8_t u8_3;\r
+       } FF_TLong_t;\r
+#elif( ffconfigBYTE_ORDER == pdFREERTOS_BIG_ENDIAN )\r
+       /*\r
+        * On a big endian CPU, all bytes will be swapped, either 2 or 4 bytes:\r
+        */\r
+       typedef struct\r
+       {\r
+               uint8_t u8_1;   /* the second byte */\r
+               uint8_t u8_0;   /* the first byte */\r
+       } FF_TShort_t;\r
+\r
+       typedef struct\r
+       {\r
+               uint8_t u8_3;\r
+               uint8_t u8_2;\r
+               uint8_t u8_1;\r
+               uint8_t u8_0;\r
+       } FF_TLong_t;\r
+#else\r
+       #error Little or Big Endian? - Please set ffconfigBYTE_ORDER to either pdFREERTOS_LITTLE_ENDIAN or pdFREERTOS_BIG_ENDIAN 1 in FreeRTOSFATConfig.h\r
+#endif\r
+\r
+/*! 16-bit union. */\r
+typedef union\r
+{\r
+   uint16_t u16;\r
+   FF_TShort_t bytes;\r
+} FF_T_UN16;\r
+\r
+/*! 32-bit union. */\r
+typedef union\r
+{\r
+  uint32_t u32;\r
+  FF_TLong_t bytes;\r
+} FF_T_UN32;\r
+\r
+/*     HT inlined these functions:\r
+ */\r
+\r
+#if( ffconfigINLINE_MEMORY_ACCESS != 0 )\r
+\r
+       static portINLINE uint8_t FF_getChar( const uint8_t *pBuffer, uint32_t aOffset )\r
+       {\r
+               return ( uint8_t ) ( pBuffer[ aOffset ] );\r
+       }\r
+\r
+       static portINLINE uint16_t FF_getShort( const uint8_t *pBuffer, uint32_t aOffset )\r
+       {\r
+       FF_T_UN16 u16;\r
+\r
+               pBuffer += aOffset;\r
+               u16.bytes.u8_1 = pBuffer[ 1 ];\r
+               u16.bytes.u8_0 = pBuffer[ 0 ];\r
+\r
+               return u16.u16;\r
+       }\r
+\r
+       static portINLINE uint32_t FF_getLong( const uint8_t *pBuffer, uint32_t aOffset )\r
+       {\r
+       FF_T_UN32 u32;\r
+\r
+               pBuffer += aOffset;\r
+               u32.bytes.u8_3 = pBuffer[ 3 ];\r
+               u32.bytes.u8_2 = pBuffer[ 2 ];\r
+               u32.bytes.u8_1 = pBuffer[ 1 ];\r
+               u32.bytes.u8_0 = pBuffer[ 0 ];\r
+\r
+               return u32.u32;\r
+       }\r
+\r
+       static portINLINE void FF_putChar( uint8_t *pBuffer, uint32_t aOffset, uint32_t Value )\r
+       {\r
+               pBuffer[ aOffset ] = ( uint8_t ) Value;\r
+       }\r
+\r
+       static portINLINE void FF_putShort( uint8_t *pBuffer, uint32_t aOffset, uint32_t Value )\r
+       {\r
+       FF_T_UN16 u16;\r
+\r
+               u16.u16 = ( uint16_t ) Value;\r
+               pBuffer += aOffset;\r
+               pBuffer[ 0 ] = u16.bytes.u8_0;\r
+               pBuffer[ 1 ] = u16.bytes.u8_1;\r
+       }\r
+\r
+       static portINLINE void FF_putLong( uint8_t *pBuffer, uint32_t aOffset, uint32_t Value )\r
+       {\r
+       FF_T_UN32 u32;\r
+\r
+               u32.u32 = Value;\r
+               pBuffer += aOffset;\r
+               pBuffer[ 0 ] = u32.bytes.u8_0;\r
+               pBuffer[ 1 ] = u32.bytes.u8_1;\r
+               pBuffer[ 2 ] = u32.bytes.u8_2;\r
+               pBuffer[ 3 ] = u32.bytes.u8_3;\r
+       }\r
+\r
+#else  /* ffconfigINLINE_MEMORY_ACCESS */\r
+\r
+       uint8_t FF_getChar( const uint8_t *pBuffer, uint32_t aOffset );\r
+       uint16_t FF_getShort( const uint8_t *pBuffer, uint32_t aOffset );\r
+       uint32_t FF_getLong( const uint8_t *pBuffer, uint32_t aOffset );\r
+       void FF_putChar( uint8_t *pBuffer, uint32_t aOffset, uint32_t Value );\r
+       void FF_putShort( uint8_t *pBuffer, uint32_t aOffset, uint32_t Value );\r
+       void FF_putLong( uint8_t *pBuffer, uint32_t aOffset, uint32_t Value );\r
+\r
+#endif /* ffconfigINLINE_MEMORY_ACCESS */\r
+\r
+#endif /* _FF_MEMORY_H_ */\r
+\r