1 /**
2 * @file rm_linux_osal.c
3 *
4 * @brief
5 * This is the OS abstraction layer used by the Resource Manager in Linux.
6 *
7 * \par
8 * ============================================================================
9 * @n (C) Copyright 2012-2014, 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 <stdint.h>
44 #include <stdarg.h>
45 #include <stdlib.h>
46 #include <pthread.h>
48 /**********************************************************************
49 ****************************** Defines *******************************
50 **********************************************************************/
52 /**********************************************************************
53 ************************** Global Variables **************************
54 **********************************************************************/
55 uint32_t rmMallocCounter = 0;
56 uint32_t rmFreeCounter = 0;
58 int32_t rmByteAlloc = 0;
59 int32_t rmByteFree = 0;
61 /**********************************************************************
62 *************************** OSAL Functions **************************
63 **********************************************************************/
65 /* FUNCTION PURPOSE: Allocates memory
66 ***********************************************************************
67 * DESCRIPTION: The function is used to allocate a memory block of the
68 * specified size.
69 */
70 void *Osal_rmMalloc (uint32_t num_bytes)
71 {
72 /* Increment the allocation counter. */
73 rmMallocCounter++;
74 rmByteAlloc += num_bytes;
76 /* Allocate memory. */
77 return calloc(1, num_bytes);
78 }
80 /* FUNCTION PURPOSE: Frees memory
81 ***********************************************************************
82 * DESCRIPTION: The function is used to free a memory block of the
83 * specified size.
84 */
85 void Osal_rmFree (void *ptr, uint32_t size)
86 {
87 /* Increment the free counter. */
88 rmFreeCounter++;
89 rmByteFree += size;
90 free(ptr);
91 }
93 /* FUNCTION PURPOSE: Critical section enter
94 ***********************************************************************
95 * DESCRIPTION: The function is used to enter a critical section.
96 * Function protects against
97 *
98 * access from multiple cores
99 * and
100 * access from multiple threads on single core
101 */
102 void *Osal_rmCsEnter(void)
103 {
104 return NULL;
105 }
107 /* FUNCTION PURPOSE: Critical section exit
108 ***********************************************************************
109 * DESCRIPTION: The function is used to exit a critical section
110 * protected using Osal_cppiCsEnter() API.
111 */
112 void Osal_rmCsExit(void *CsHandle)
113 {
115 }
117 /* FUNCTION PURPOSE: Multi-threaded critical section enter
118 ***********************************************************************
119 * DESCRIPTION: The function is used to enter a multi-threaded critical
120 * section. Function protects against
121 *
122 * access from multiple threads on single core
123 */
124 void *Osal_rmMtCsEnter(void *mtSemObj)
125 {
126 pthread_mutex_t *mutex = (pthread_mutex_t *)mtSemObj;
128 pthread_mutex_lock(mutex);
129 return NULL;
130 }
132 /* FUNCTION PURPOSE: Multi-threaded critical section exit
133 ***********************************************************************
134 * DESCRIPTION: The function is used to exit a multi-threaded critical
135 * section protected using Osal_rmMtCsEnter() API.
136 */
137 void Osal_rmMtCsExit(void *mtSemObj, void *CsHandle)
138 {
139 pthread_mutex_t *mutex = (pthread_mutex_t *)mtSemObj;
141 pthread_mutex_unlock(mutex);
142 }
144 /* FUNCTION PURPOSE: Cache invalidate
145 ***********************************************************************
146 * DESCRIPTION: The function is used to indicate that a block of memory is
147 * about to be accessed. If the memory block is cached then this
148 * indicates that the application would need to ensure that the
149 * cache is updated with the data from the actual memory.
150 */
151 void Osal_rmBeginMemAccess(void *ptr, uint32_t size)
152 {
153 return;
154 }
156 /* FUNCTION PURPOSE: Cache writeback
157 ***********************************************************************
158 * DESCRIPTION: The function is used to indicate that the block of memory has
159 * finished being accessed. If the memory block is cached then the
160 * application would need to ensure that the contents of the cache
161 * are updated immediately to the actual memory.
162 */
163 void Osal_rmEndMemAccess(void *ptr, uint32_t size)
164 {
165 return;
166 }
168 /* FUNCTION PURPOSE: Creates a task blocking object
169 ***********************************************************************
170 * DESCRIPTION: The function is used to create a task blocking object
171 * capable of blocking the task a RM instance is running
172 * within
173 */
174 void *Osal_rmTaskBlockCreate(void)
175 {
176 return(NULL);
177 }
179 /* FUNCTION PURPOSE: Blocks a RM instance
180 ***********************************************************************
181 * DESCRIPTION: The function is used to block a task whose context a
182 * RM instance is running within.
183 */
184 void Osal_rmTaskBlock(void *handle)
185 {
187 }
189 /* FUNCTION PURPOSE: unBlocks a RM instance
190 ***********************************************************************
191 * DESCRIPTION: The function is used to unblock a task whose context a
192 * RM instance is running within.
193 */
194 void Osal_rmTaskUnblock(void *handle)
195 {
197 }
199 /* FUNCTION PURPOSE: Deletes a task blocking object
200 ***********************************************************************
201 * DESCRIPTION: The function is used to delete a task blocking object
202 * provided to a RM instance
203 */
204 void Osal_rmTaskBlockDelete(void *handle)
205 {
207 }
209 /* FUNCTION PURPOSE: Prints a variable list
210 ***********************************************************************
211 * DESCRIPTION: The function is used to print a string to the console
212 */
213 void Osal_rmLog (char *fmt, ... )
214 {
215 va_list ap;
217 va_start(ap, fmt);
218 vprintf(fmt, ap);
219 va_end(ap);
220 }