]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/uncached_memory.c
commit 9f316c246baafa15c542a5aea81a94f26e3d6507
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-TCP / portable / NetworkInterface / Zynq / uncached_memory.c
index b43e50ec20f4bc5f410b39d1653cc6d0767b3982..bfbdc341b50f06557d04e7c301da965f719edda1 100644 (file)
@@ -1,10 +1,35 @@
+/*\r
+ * FreeRTOS V202002.00\r
+ * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\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
+ * http://aws.amazon.com/freertos\r
+ * http://www.FreeRTOS.org\r
+ */\r
+\r
 /*\r
  * uncached_memory.c\r
  *\r
  * This module will declare 1 MB of memory and switch off the caching for it.\r
  *\r
  * pucGetUncachedMemory( ulSize ) returns a trunc of this memory with a length\r
- * rounded up to a multiple of 4 KB\r
+ * rounded up to a multiple of 4 KB.\r
  *\r
  * ucIsCachedMemory( pucBuffer ) returns non-zero if a given pointer is NOT\r
  * within the range of the 1 MB non-cached memory.\r
 \r
 #include "uncached_memory.h"\r
 \r
-#define UNCACHED_MEMORY_SIZE   0x100000ul\r
+/* Reserve 1 MB of memory. */\r
+#define uncMEMORY_SIZE                         0x100000uL\r
+\r
+/* Make sure that each pointer has an alignment of 4 KB. */\r
+#define uncALIGNMENT_SIZE                      0x1000uL\r
 \r
 #define DDR_MEMORY_END (XPAR_PS7_DDR_0_S_AXI_HIGHADDR+1)\r
 \r
+#define uncMEMORY_ATTRIBUTE                    0x1C02\r
+\r
 static void vInitialiseUncachedMemory( void );\r
 \r
 static uint8_t *pucHeadOfMemory;\r
 static uint32_t ulMemorySize;\r
 static uint8_t *pucStartOfMemory = NULL;\r
 \r
+/* The linker file defines some pseudo variables. '_end' is one of them.\r
+It is located at the first free byte in RAM. */\r
+extern u8 _end;\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
 uint8_t ucIsCachedMemory( const uint8_t *pucBuffer )\r
 {\r
 uint8_t ucReturn;\r
 \r
        if( ( pucStartOfMemory != NULL ) &&\r
                ( pucBuffer >= pucStartOfMemory ) &&\r
-               ( pucBuffer < ( pucStartOfMemory + UNCACHED_MEMORY_SIZE ) ) )\r
+               ( pucBuffer < ( pucStartOfMemory + uncMEMORY_SIZE ) ) )\r
        {\r
                ucReturn = pdFALSE;\r
        }\r
@@ -70,10 +107,12 @@ uint8_t ucReturn;
 \r
        return ucReturn;\r
 }\r
+/*-----------------------------------------------------------*/\r
 \r
 uint8_t *pucGetUncachedMemory( uint32_t ulSize )\r
 {\r
 uint8_t *pucReturn;\r
+uint32_t ulSkipSize;\r
 \r
        if( pucStartOfMemory == NULL )\r
        {\r
@@ -85,48 +124,40 @@ uint8_t *pucReturn;
        }\r
        else\r
        {\r
-       uint32_t ulSkipSize;\r
-\r
                pucReturn = pucHeadOfMemory;\r
-               ulSkipSize = ( ulSize + 0x1000ul ) & ~0xffful;\r
+               /* Make sure that the next pointer return will have a good alignment. */\r
+               ulSkipSize = ( ulSize + uncALIGNMENT_SIZE ) & ~( uncALIGNMENT_SIZE - 1uL );\r
                pucHeadOfMemory += ulSkipSize;\r
                ulMemorySize -= ulSkipSize;\r
        }\r
 \r
        return pucReturn;\r
 }\r
-\r
-extern u8 _end;\r
+/*-----------------------------------------------------------*/\r
 \r
 static void vInitialiseUncachedMemory( )\r
 {\r
        /* At the end of program's space... */\r
-       pucStartOfMemory = (uint8_t *) &_end;\r
-       /*\r
-        * Align the start address to 1 MB boundary.\r
-        */\r
-       pucStartOfMemory = (uint8_t *)( ( ( uint32_t )pucStartOfMemory + UNCACHED_MEMORY_SIZE ) & ( ~( UNCACHED_MEMORY_SIZE - 1 ) ) );\r
+       pucStartOfMemory = ( uint8_t * ) &( _end );\r
 \r
-       if( ( ( u32 )pucStartOfMemory ) + UNCACHED_MEMORY_SIZE > DDR_MEMORY_END )\r
+       /* Align the start address to 1 MB boundary. */\r
+       pucStartOfMemory = ( uint8_t * )( ( ( uint32_t )pucStartOfMemory + uncMEMORY_SIZE ) & ( ~( uncMEMORY_SIZE - 1 ) ) );\r
+\r
+       if( ( ( u32 )pucStartOfMemory ) + uncMEMORY_SIZE > DDR_MEMORY_END )\r
        {\r
-//             vLoggingPrintf("vInitialiseUncachedMemory: Can not allocate uncached memory\n" );\r
+               FreeRTOS_printf( ( "vInitialiseUncachedMemory: Can not allocate uncached memory\n" ) );\r
        }\r
        else\r
        {\r
-               /*\r
-                * Some objects want to be stored in uncached memory. Hence the 1 MB\r
-                * address range that starts after "_end" is made uncached\r
-                * by setting appropriate attributes in the translation table.\r
-                */\r
-               /* FIXME claudio rossi. Modified to prevent data abort exception (misaligned access)\r
-                * when application is compiled with -O1 or more optimization flag.\r
-                */\r
-/*             Xil_SetTlbAttributes( ( uint32_t )pucStartOfMemory, 0xc02 ); // addr, attr */\r
-               Xil_SetTlbAttributes( ( uint32_t )pucStartOfMemory, 0x1c02 ); // addr, attr\r
-\r
-               /* For experiments in the SDIO driver, make the remaining uncached memory public */\r
+               /* Some objects want to be stored in uncached memory. Hence the 1 MB\r
+               address range that starts after "_end" is made uncached by setting\r
+               appropriate attributes in the translation table. */\r
+               Xil_SetTlbAttributes( ( uint32_t ) pucStartOfMemory, uncMEMORY_ATTRIBUTE );\r
+\r
+               /* For experiments in the SDIO driver, make the remaining uncached memory\r
+               public */\r
                pucHeadOfMemory = pucStartOfMemory;\r
-               ulMemorySize = UNCACHED_MEMORY_SIZE;\r
-               memset( pucStartOfMemory, '\0', UNCACHED_MEMORY_SIZE );\r
+               ulMemorySize = uncMEMORY_SIZE;\r
+               memset( pucStartOfMemory, '\0', uncMEMORY_SIZE );\r
        }\r
 }\r