[processor-sdk/pdk.git] / packages / ti / drv / emac / test / EmacLoopbackTest / am574x / test_osal.c
1 /*
2 * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the
14 * distribution.
15 *
16 * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
34 /**
35 * @file test_osal.c
36 *
37 * @brief
38 * This is the OS abstraction layer and is used by the EMAC
39 * driver for the EMAC Unit Test Application.
40 */
42 /* Standard C-native includes */
43 #include <stdlib.h>
44 #include <string.h>
47 #include <xdc/std.h>
48 #include <xdc/runtime/System.h>
49 #include <xdc/runtime/Memory.h>
50 #include <xdc/runtime/Error.h>
51 #include <ti/sysbios/BIOS.h>
52 #include <ti/sysbios/knl/Task.h>
53 #include <ti/sysbios/hal/Hwi.h>
54 #include <xdc/cfg/global.h>
56 /* CSL CHIP, SEM Functional layer includes */
57 #include <ti/csl/csl_chip.h>
58 //#include <ti/csl/csl_semAux.h>
61 /* CSL Cache module includes */
63 //#include <ti/csl/csl_cache.h>
64 //#include <ti/csl/csl_cacheAux.h>
68 #include <ti/drv/emac/emac_hwcfg.h>
69 #include <ti/drv/emac/emac_drv.h>
70 #include "ti/drv/emac/test/EmacLoopbackTest/test_utils.h"
73 /**
74 * @b Description
75 * @n
76 * General Memory Barrier guarantees that all LOAD and STORE operations that were issued before the
77 * barrier occur before the LOAD and STORE operations issued after the barrier
78 *
79 */
80 #ifdef __ARM_ARCH_7A__
81 static inline void memBarrier(void) {__sync_synchronize();}
82 #endif
83 #define MAX_NUM_CORES 1
84 /**********************************************************************
85 ************************** Global Variables **************************
86 **********************************************************************/
88 UInt32 coreKey [MAX_NUM_CORES];
90 /**
91 * @b Description
92 * @n
93 * The function is used to indicate that a block of memory is
94 * about to be accessed. If the memory block is cached then this
95 * indicates that the application would need to ensure that the
96 * cache is updated with the data from the actual memory.
97 *
98 * @param[in] addr
99 * Address of memory block
100 * @param[in] size
101 * Size of memory block in bytes
102 *
103 * @retval
104 * None
105 */
106 void Osal_beginMemAccess
107 (
108 void* addr,
109 Uint32 size
110 )
111 {
112 return;
113 }
115 /**
116 * @b Description
117 * @n
118 * The function is used to indicate that the block of memory has
119 * finished being accessed. If the memory block is cached then the
120 * application would need to ensure that the contents of the cache
121 * are updated immediately to the actual memory.
122 *
123 * @param[in] addr
124 * Address of memory block
125 * @param[in] size
126 * Size of memory block in bytes
127 *
128 * @retval
129 * None
130 */
131 void
132 Osal_endMemAccess
133 (
134 void* addr,
135 Uint32 size
136 )
137 {
138 return;
139 }
141 /**
142 * @b Description
143 * @n
144 * The function is used to provide critical section to prevent access of shared
145 * resources from single core and multiple threads.
146 *
147 * @param[in] port_num
148 * EMAC port number which needs critical section to protect its resources.
149 *
150 * @retval
151 * None
152 */
153 void
154 Osal_enterSingleCoreCriticalSection
155 (
156 Uint32 port_num
157 )
158 {
159 uint32_t coreNum = 0;
160 coreKey [coreNum] = Hwi_disable();
162 return;
166 }
168 /**
169 * @b Description
170 * @n
171 * The function is called to end the critical section access of shared resources
172 * from single cores.
173 *
174 * @param[in] port_num
175 * EMAC port number which needs critical section to protect its resources.
176 *
177 * @retval
178 * None
179 */
180 void
181 Osal_exitSingleCoreCriticalSection
182 (
183 Uint32 port_num
184 )
185 {
186 uint32_t coreNum = 0;
187 /* Enable all interrupts and enables the OS scheduler back on.
188 *
189 * Release multi-threaded / multi-process lock on this core.
190 */
191 Hwi_restore(coreKey [coreNum]);
193 /* Release the hardware semaphore
194 *
195 * Release multi-core lock.
196 */
197 //CSL_semReleaseSemaphore (EMAC_HW_SEM);
199 return;
200 }
202 /**
203 * @b Description
204 * @n
205 * The function is used to provide critical section to prevent access of shared
206 * resources from multiple cores
207 *
208 * @retval
209 * None
210 */
211 void
212 Osal_enterMultipleCoreCriticalSection
213 (
214 Uint32 port_num
215 )
216 {
217 (void)port_num;
218 return;
219 }
221 /**
222 * @b Description
223 * @n
224 * The function is called to end the critical section access of shared resources
225 * from multiple cores.
226 *
227 * @param[in]
228 *
229 * @retval
230 * None
231 */
232 void
233 Osal_exitMultipleCoreCriticalSection
234 (
235 Uint32 port_num
236 )
237 {
238 (void)port_num;
239 return;
240 }
242 /**
243 * @b Description
244 * @n
245 * The function is used to allocate a memory block of the specified size.
246 *
247 * @param[in] num_bytes
248 * Number of bytes to be allocated.
249 *
250 * @retval
251 * Allocated block address
252 */
253 void* Osal_malloc
254 (
255 Uint32 num_bytes
256 )
257 {
258 Error_Block errorBlock;
259 Void* ptr;
261 /* Allocate memory */
262 ptr = Memory_alloc(NULL, num_bytes, 4, &errorBlock);
263 if (ptr == NULL)
264 {
265 return NULL;
266 }
268 /* Return the allocated memory block. */
269 return ptr;
270 }
272 /**
273 * @b Description
274 * @n
275 * The function is used to clean up a specific memory block
276 *
277 * @param[in] ptr
278 * Pointer to the memory block to be cleaned up.
279 * @param[in] num_bytes
280 * Size of the memory block being cleaned up.
281 *
282 * @retval
283 * Not Applicable
284 */
285 void
286 Osal_free
287 (
288 void* ptr,
289 Uint32 num_bytes
290 )
291 {
292 Memory_free(NULL, ptr, num_bytes);
293 }