291608c4a47f1b119339432a1929447eb5438bac
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: Creates a task blocking object
99 ***********************************************************************
100 * DESCRIPTION: The function is used to create a task blocking object
101 * capable of blocking the task a RM instance is running
102 * within
103 */
104 void *Osal_rmTaskBlockCreate(void)
105 {
106 Semaphore_Params semParams;
108 Semaphore_Params_init(&semParams);
109 return((void *)Semaphore_create(0, &semParams, NULL));
110 }
112 /* FUNCTION PURPOSE: Blocks a RM instance
113 ***********************************************************************
114 * DESCRIPTION: The function is used to block a task whose context a
115 * RM instance is running within.
116 */
117 void Osal_rmTaskBlock(void *handle)
118 {
119 Semaphore_pend((Semaphore_Handle)handle, BIOS_WAIT_FOREVER);
120 }
122 /* FUNCTION PURPOSE: unBlocks a RM instance
123 ***********************************************************************
124 * DESCRIPTION: The function is used to unblock a task whose context a
125 * RM instance is running within.
126 */
127 void Osal_rmTaskUnblock(void *handle)
128 {
129 Semaphore_post((Semaphore_Handle)handle);
130 }
132 /* FUNCTION PURPOSE: Deletes a task blocking object
133 ***********************************************************************
134 * DESCRIPTION: The function is used to delete a task blocking object
135 * provided to a RM instance
136 */
137 void Osal_rmTaskBlockDelete(void *handle)
138 {
139 Semaphore_delete((Semaphore_Handle *)&handle);
140 }
142 /* FUNCTION PURPOSE: Prints a variable list
143 ***********************************************************************
144 * DESCRIPTION: The function is used to print a string to the console
145 */
146 void Osal_rmLog (char *fmt, ... )
147 {
148 VaList ap;
150 va_start(ap, fmt);
151 System_vprintf(fmt, ap);
152 va_end(ap);
153 }