]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/rm-lld.git/blob - test/rm_osal.c
c8bfc3a64fc1b5de797a18e5a12dc9255e5637db
[keystone-rtos/rm-lld.git] / test / rm_osal.c
1 /**
2  *   @file  rm_osal.c
3  *
4  *   @brief
5  *      This is the OS abstraction layer used by the Resource Manager.
6  *
7  *  \par
8  *  ============================================================================
9  *  @n   (C) Copyright 2012-2013, Texas Instruments, Inc.
10  *
11  *  Redistribution and use in source and binary forms, with or without
12  *  modification, are permitted provided that the following conditions
13  *  are met:
14  *
15  *    Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  *
18  *    Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the
21  *    distribution.
22  *
23  *    Neither the name of Texas Instruments Incorporated nor the names of
24  *    its contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38  *
39  *  \par
40 */
42 /* Standard Includes */
43 #include <stdarg.h>
45 /* XDC Includes */
46 #include <xdc/std.h>
47 #include <xdc/runtime/Memory.h>
48 #include <xdc/runtime/Error.h>
49 #include <xdc/runtime/System.h>
51 /* BIOS Includes */
52 #include <ti/sysbios/BIOS.h>
53 #include <ti/sysbios/hal/Hwi.h>
54 #include <ti/sysbios/knl/Semaphore.h>
56 /* CSL includes */
57 #include <ti/csl/csl_cacheAux.h>
58 #include <ti/csl/csl_xmcAux.h>
60 /**********************************************************************
61  ****************************** Defines *******************************
62  **********************************************************************/
64 /**********************************************************************
65  ************************** Global Variables **************************
66  **********************************************************************/
67 uint32_t rmMallocCounter = 0;
68 uint32_t rmFreeCounter   = 0;
70 /**********************************************************************
71  *************************** OSAL Functions **************************
72  **********************************************************************/
74 /* FUNCTION PURPOSE: Allocates memory
75  ***********************************************************************
76  * DESCRIPTION: The function is used to allocate a memory block of the
77  *              specified size.
78  */
79 void *Osal_rmMalloc (uint32_t num_bytes)
80 {
81         Error_Block     errorBlock;
83     /* Increment the allocation counter. */
84     rmMallocCounter++;
86         /* Allocate memory. */
87         return Memory_alloc(NULL, num_bytes, 0, &errorBlock);
88 }
90 /* FUNCTION PURPOSE: Frees memory
91  ***********************************************************************
92  * DESCRIPTION: The function is used to free a memory block of the
93  *              specified size.
94  */ 
95 void Osal_rmFree (void *ptr, uint32_t size)
96 {
97     /* Increment the free counter. */
98     rmFreeCounter++;
99         Memory_free(NULL, ptr, size);
102 /* FUNCTION PURPOSE: Critical section enter
103  ***********************************************************************
104  * DESCRIPTION: The function is used to enter a critical section.
105  *              Function protects against 
106  *      
107  *              access from multiple cores 
108  *              and 
109  *              access from multiple threads on single core
110  */  
111 void *Osal_rmCsEnter(void)
114     return NULL;
117 /* FUNCTION PURPOSE: Critical section exit
118  ***********************************************************************
119  * DESCRIPTION: The function is used to exit a critical section 
120  *              protected using Osal_cppiCsEnter() API.
121  */  
122 void Osal_rmCsExit(void *CsHandle)
127 /* FUNCTION PURPOSE: Cache invalidate
128  ***********************************************************************
129  * DESCRIPTION: The function is used to indicate that a block of memory is 
130  *              about to be accessed. If the memory block is cached then this 
131  *              indicates that the application would need to ensure that the 
132  *              cache is updated with the data from the actual memory.
133  */  
134 void Osal_rmBeginMemAccess(void *ptr, uint32_t size)
136     uint32_t    key;
138     /* Disable Interrupts */
139     key = Hwi_disable();
141     /* Cleanup the prefetch buffer also. */
142     CSL_XMC_invalidatePrefetchBuffer();
144 #ifdef L2_CACHE
145     /* Invalidate L2 cache. This should invalidate L1D as well. 
146      * Wait until operation is complete. */    
147     CACHE_invL2 (ptr, size, CACHE_FENCE_WAIT);
148 #else       
149     /* Invalidate L1D cache and wait until operation is complete. 
150      * Use this approach if L2 cache is not enabled */    
151     CACHE_invL1d (ptr, size, CACHE_FENCE_WAIT);
152 #endif
154     /* Reenable Interrupts. */
155     Hwi_restore(key);
157     return;
160 /* FUNCTION PURPOSE: Cache writeback
161  ***********************************************************************
162  * DESCRIPTION: The function is used to indicate that the block of memory has 
163  *              finished being accessed. If the memory block is cached then the 
164  *              application would need to ensure that the contents of the cache 
165  *              are updated immediately to the actual memory. 
166  */  
167 void Osal_rmEndMemAccess(void *ptr, uint32_t size)
169     uint32_t    key;
171     /* Disable Interrupts */
172     key = Hwi_disable();
174 #ifdef L2_CACHE
175     /* Writeback L2 cache. This should Writeback L1D as well. 
176      * Wait until operation is complete. */ 
177     CACHE_wbL2 (ptr, size, CACHE_FENCE_WAIT);
179 #else    
180     /* Writeback L1D cache and wait until operation is complete. 
181      * Use this approach if L2 cache is not enabled */    
182     CACHE_wbL1d (ptr, size, CACHE_FENCE_WAIT);
183 #endif
185     /* Reenable Interrupts. */
186     Hwi_restore(key);
188     return;
191 /* FUNCTION PURPOSE: Creates a task blocking object
192  ***********************************************************************
193  * DESCRIPTION: The function is used to create a task blocking object
194  *              capable of blocking the task a RM instance is running
195  *              within
196  */
197 void *Osal_rmTaskBlockCreate(void)
199     Semaphore_Params semParams;    
201     Semaphore_Params_init(&semParams);
202     return((void *)Semaphore_create(0, &semParams, NULL));
205 /* FUNCTION PURPOSE: Blocks a RM instance
206  ***********************************************************************
207  * DESCRIPTION: The function is used to block a task whose context a
208  *              RM instance is running within.
209  */
210 void Osal_rmTaskBlock(void *handle)
212     Semaphore_pend((Semaphore_Handle)handle, BIOS_WAIT_FOREVER);
215 /* FUNCTION PURPOSE: unBlocks a RM instance
216  ***********************************************************************
217  * DESCRIPTION: The function is used to unblock a task whose context a
218  *              RM instance is running within.
219  */
220 void Osal_rmTaskUnblock(void *handle)
222     Semaphore_post((Semaphore_Handle)handle);
225 /* FUNCTION PURPOSE: Deletes a task blocking object
226  ***********************************************************************
227  * DESCRIPTION: The function is used to delete a task blocking object
228  *              provided to a RM instance
229  */
230 void Osal_rmTaskBlockDelete(void *handle)
232     Semaphore_delete((Semaphore_Handle *)&handle);
235 /* FUNCTION PURPOSE: Prints a variable list
236  ***********************************************************************
237  * DESCRIPTION: The function is used to print a string to the console
238  */
239 void Osal_rmLog (char *fmt, ... )
241     VaList ap;
242     
243     va_start(ap, fmt);
244     System_vprintf(fmt, ap);
245     va_end(ap);