7302871081d0dfb1a004ee624edb0735e86592f8
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/knl/Task.h>
54 #include <ti/sysbios/knl/Semaphore.h>
56 /**********************************************************************
57 ****************************** Defines *******************************
58 **********************************************************************/
60 /**********************************************************************
61 ************************** Global Variables **************************
62 **********************************************************************/
63 uint32_t rmMallocCounter = 0;
64 uint32_t rmFreeCounter = 0;
66 /**********************************************************************
67 *************************** OSAL Functions **************************
68 **********************************************************************/
70 /* FUNCTION PURPOSE: Allocates memory
71 ***********************************************************************
72 * DESCRIPTION: The function is used to allocate a memory block of the
73 * specified size.
74 */
75 void *Osal_rmMalloc (uint32_t num_bytes)
76 {
77 Error_Block errorBlock;
79 /* Increment the allocation counter. */
80 rmMallocCounter++;
82 /* Allocate memory. */
83 return Memory_alloc(NULL, num_bytes, 0, &errorBlock);
84 }
86 /* FUNCTION PURPOSE: Frees memory
87 ***********************************************************************
88 * DESCRIPTION: The function is used to free a memory block of the
89 * specified size.
90 */
91 void Osal_rmFree (void *ptr, uint32_t size)
92 {
93 /* Increment the free counter. */
94 rmFreeCounter++;
95 Memory_free(NULL, ptr, size);
96 }
98 /* FUNCTION PURPOSE: Critical section enter
99 ***********************************************************************
100 * DESCRIPTION: The function is used to enter a critical section.
101 * Function protects against
102 *
103 * access from multiple cores
104 * and
105 * access from multiple threads on single core
106 */
107 void *Osal_rmCsEnter(void)
108 {
110 return NULL;
111 }
113 /* FUNCTION PURPOSE: Critical section exit
114 ***********************************************************************
115 * DESCRIPTION: The function is used to exit a critical section
116 * protected using Osal_cppiCsEnter() API.
117 */
118 void Osal_rmCsExit(void *CsHandle)
119 {
121 }
123 /* FUNCTION PURPOSE: Critical section exit
124 ***********************************************************************
125 * DESCRIPTION: The function is used to indicate that a block of memory is
126 * about to be accessed. If the memory block is cached then this
127 * indicates that the application would need to ensure that the
128 * cache is updated with the data from the actual memory.
129 */
130 void Osal_rmBeginMemAccess(void *ptr, uint32_t size)
131 {
133 }
135 /* FUNCTION PURPOSE: Critical section exit
136 ***********************************************************************
137 * DESCRIPTION: The function is used to indicate that the block of memory has
138 * finished being accessed. If the memory block is cached then the
139 * application would need to ensure that the contents of the cache
140 * are updated immediately to the actual memory.
141 */
142 void Osal_rmEndMemAccess(void *ptr, uint32_t size)
143 {
145 }
147 /* FUNCTION PURPOSE: Creates a task blocking object
148 ***********************************************************************
149 * DESCRIPTION: The function is used to create a task blocking object
150 * capable of blocking the task a RM instance is running
151 * within
152 */
153 void *Osal_rmTaskBlockCreate(void)
154 {
155 Semaphore_Params semParams;
157 Semaphore_Params_init(&semParams);
158 return((void *)Semaphore_create(0, &semParams, NULL));
159 }
161 /* FUNCTION PURPOSE: Blocks a RM instance
162 ***********************************************************************
163 * DESCRIPTION: The function is used to block a task whose context a
164 * RM instance is running within.
165 */
166 void Osal_rmTaskBlock(void *handle)
167 {
168 Semaphore_pend((Semaphore_Handle)handle, BIOS_WAIT_FOREVER);
169 }
171 /* FUNCTION PURPOSE: unBlocks a RM instance
172 ***********************************************************************
173 * DESCRIPTION: The function is used to unblock a task whose context a
174 * RM instance is running within.
175 */
176 void Osal_rmTaskUnblock(void *handle)
177 {
178 Semaphore_post((Semaphore_Handle)handle);
179 }
181 /* FUNCTION PURPOSE: Deletes a task blocking object
182 ***********************************************************************
183 * DESCRIPTION: The function is used to delete a task blocking object
184 * provided to a RM instance
185 */
186 void Osal_rmTaskBlockDelete(void *handle)
187 {
188 Semaphore_delete((Semaphore_Handle *)&handle);
189 }
191 /* FUNCTION PURPOSE: Prints a variable list
192 ***********************************************************************
193 * DESCRIPTION: The function is used to print a string to the console
194 */
195 void Osal_rmLog (char *fmt, ... )
196 {
197 VaList ap;
199 va_start(ap, fmt);
200 System_vprintf(fmt, ap);
201 va_end(ap);
202 }