]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/Zynq/uncached_memory.c
Add missing +TCP code.
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-TCP / portable / NetworkInterface / Zynq / uncached_memory.c
1 #warning Temoporary file and a dependent on the Zynq network interface.\r
2 \r
3 /*\r
4  * uncached_memory.c\r
5  *\r
6  * This module will declare 1 MB of memory and switch off the caching for it.\r
7  *\r
8  * pucGetUncachedMemory( ulSize ) returns a trunc of this memory with a length\r
9  * rounded up to a multiple of 4 KB\r
10  *\r
11  * ucIsCachedMemory( pucBuffer ) returns non-zero if a given pointer is NOT\r
12  * within the range of the 1 MB non-cached memory.\r
13  *\r
14  */\r
15 \r
16 /*\r
17  * After "_end", 1 MB of uncached memory will be allocated for DMA transfers.\r
18  * Both the DMA descriptors as well as all EMAC TX-buffers will be allocated in\r
19  * uncached memory.\r
20  */\r
21 \r
22 #include "Zynq/x_emacpsif.h"\r
23 #include "Zynq/x_topology.h"\r
24 #include "xstatus.h"\r
25 \r
26 #include "xparameters.h"\r
27 #include "xparameters_ps.h"\r
28 #include "xil_exception.h"\r
29 #include "xil_mmu.h"\r
30 \r
31 #include "FreeRTOS.h"\r
32 \r
33 #include "uncached_memory.h"\r
34 \r
35 #include "Demo_Logging.h"\r
36 \r
37 #define UNCACHED_MEMORY_SIZE    0x100000ul\r
38 \r
39 #define DDR_MEMORY_END  (XPAR_PS7_DDR_0_S_AXI_HIGHADDR+1)\r
40 \r
41 static void vInitialiseUncachedMemory( void );\r
42 \r
43 static uint8_t *pucHeadOfMemory;\r
44 static uint32_t ulMemorySize;\r
45 static uint8_t *pucStartOfMemory = NULL;\r
46 \r
47 uint8_t ucIsCachedMemory( const uint8_t *pucBuffer )\r
48 {\r
49 uint8_t ucReturn;\r
50 \r
51         if( ( pucStartOfMemory != NULL ) &&\r
52                 ( pucBuffer >= pucStartOfMemory ) &&\r
53                 ( pucBuffer < ( pucStartOfMemory + UNCACHED_MEMORY_SIZE ) ) )\r
54         {\r
55                 ucReturn = pdFALSE;\r
56         }\r
57         else\r
58         {\r
59                 ucReturn = pdTRUE;\r
60         }\r
61 \r
62         return ucReturn;\r
63 }\r
64 \r
65 uint8_t *pucGetUncachedMemory( uint32_t ulSize )\r
66 {\r
67 uint8_t *pucReturn;\r
68 \r
69         if( pucStartOfMemory == NULL )\r
70         {\r
71                 vInitialiseUncachedMemory( );\r
72         }\r
73         if( ( pucStartOfMemory == NULL ) || ( ulSize > ulMemorySize ) )\r
74         {\r
75                 pucReturn = NULL;\r
76         }\r
77         else\r
78         {\r
79         uint32_t ulSkipSize;\r
80 \r
81                 pucReturn = pucHeadOfMemory;\r
82                 ulSkipSize = ( ulSize + 0x1000ul ) & ~0xffful;\r
83                 pucHeadOfMemory += ulSkipSize;\r
84                 ulMemorySize -= ulSkipSize;\r
85         }\r
86 \r
87         return pucReturn;\r
88 }\r
89 \r
90 extern u8 _end;\r
91 \r
92 static void vInitialiseUncachedMemory( )\r
93 {\r
94         /* At the end of program's space... */\r
95         pucStartOfMemory = (uint8_t *) &_end;\r
96         /*\r
97          * Align the start address to 1 MB boundary.\r
98          */\r
99         pucStartOfMemory = (uint8_t *)( ( ( uint32_t )pucStartOfMemory + UNCACHED_MEMORY_SIZE ) & ( ~( UNCACHED_MEMORY_SIZE - 1 ) ) );\r
100 \r
101         if( ( ( u32 )pucStartOfMemory ) + UNCACHED_MEMORY_SIZE > DDR_MEMORY_END )\r
102         {\r
103                 vLoggingPrintf("vInitialiseUncachedMemory: Can not allocate uncached memory\n" );\r
104         }\r
105         else\r
106         {\r
107                 /*\r
108                  * Some objects want to be stored in uncached memory. Hence the 1 MB\r
109                  * address range that starts after "_end" is made uncached\r
110                  * by setting appropriate attributes in the translation table.\r
111                  */\r
112                 Xil_SetTlbAttributes( ( uint32_t )pucStartOfMemory, 0xc02 ); // addr, attr\r
113 \r
114                 /* For experiments in the SDIO driver, make the remaining uncached memory public */\r
115                 pucHeadOfMemory = pucStartOfMemory;\r
116                 ulMemorySize = UNCACHED_MEMORY_SIZE;\r
117                 memset( pucStartOfMemory, '\0', UNCACHED_MEMORY_SIZE );\r
118         }\r
119 }\r