PDK API Guide for J721E
osal.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 - 2023, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the 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 "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
38 /* @} */
39 
55 #ifndef ti_OSAL__include
56 #define ti_OSAL__include
57 
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61 
62 #include <ti/osal/TaskP.h>
63 #include <ti/osal/HwiP.h>
64 #include <ti/osal/MuxIntcP.h>
65 #include <ti/osal/SemaphoreP.h>
66 #include <ti/osal/CacheP.h>
67 #include <ti/osal/TimerP.h>
68 #include <ti/osal/RegisterIntr.h>
69 #include <ti/osal/QueueP.h>
70 #include <ti/osal/CycleprofilerP.h>
71 #include <ti/osal/MailboxP.h>
72 #include <ti/osal/MutexP.h>
73 #include <ti/osal/ClockP.h>
74 #include <ti/osal/DebugP.h>
75 #include <ti/osal/HeapP.h>
76 #include <ti/osal/MemoryP.h>
77 #include <ti/osal/EventP.h>
78 #ifdef _TMS320C6X
79 #include <ti/osal/EventCombinerP.h>
80 #endif
81 
87 /*********************************************************************
88  * @def osal_OK
89  * OSAL operation successful
90  *********************************************************************/
91 #define osal_OK (0)
92 
93 /*********************************************************************
94  * @def osal_FAILURE
95  * OSAL operation failed
96  *********************************************************************/
97 #define osal_FAILURE (-(int32_t)(1))
98 
99 /*********************************************************************
100  * @def osal_UNSUPPORTED
101  * OSAL operation is not supported
102  *********************************************************************/
103 #define osal_UNSUPPORTED (-(int32_t)(2))
104 
105 /*********************************************************************
106  * @def osal_NOMEM
107  * OSAL operation is not successful due to internal osal static memory
108  * is full. Application would need to create additional memory blocks
109  * during startup by calling @ref Osal_setHwAttrs API to set the additional
110  * memory blocks for semaphoreP and hwiP
111  *********************************************************************/
112 #define osal_NOMEM (-(int32_t)(3))
113 /* @} */
114 
115 /*********************************************************************
116  * @def osal_WAIT_FOREVER
117  * OSAL timeout wait forever
118  *********************************************************************/
119 #define osal_WAIT_FOREVER (~((uint32_t)0U))
120 
121 /*********************************************************************
122  * @def osal_NO_WAIT
123  * OSAL timeout no wait
124  *********************************************************************/
125 #define osal_NO_WAIT ((uint32_t)0U)
126 
127 /*********************************************************************
128  * @def OSAL_NONOS_SEMAPHOREP_SIZE_BYTES
129  * Semaphorep handle size for non-os use case
130  * Application can use this size to provide a secondary extended
131  * memory block for semaphore creation when all the memory (internal to osal)
132  * are utilized
133  *
134  *********************************************************************/
135 #define OSAL_NONOS_SEMAPHOREP_SIZE_BYTES ((uint32_t) 48U)
136 
137 /*********************************************************************
138  * @def OSAL_NONOS_HWI_SIZE_BYTES
139  * HwiP handle size for non-os use case
140  * Application can use this size to provide a secondary extended
141  * memory block for hwip creation when all the memory (internal to osal)
142  * are utilized
143  *********************************************************************/
144 #define OSAL_NONOS_HWIP_SIZE_BYTES ((uint32_t) 48U)
145 
146 /*********************************************************************
147  * @def OSAL_FREERTOS_HWIP_C7X_SIZE_BYTES
148  * HwiP handle size for freertos-os c7x use case
149  * Application can use this size to provide a secondary extended
150  * memory block for hwip creation when all the memory (internal to osal)
151  * are utilized
152  *********************************************************************/
153 #define OSAL_FREERTOS_HWIP_C7X_SIZE_BYTES ((uint32_t) 56U)
154 
155 /*********************************************************************
156  * @def OSAL_SAFERTOS_HWIP_C7X_SIZE_BYTES
157  * HwiP handle size for safertos-os c7x use case
158  * Application can use this size to provide a secondary extended
159  * memory block for hwip creation when all the memory (internal to osal)
160  * are utilized
161  *********************************************************************/
162 #define OSAL_SAFERTOS_HWIP_C7X_SIZE_BYTES ((uint32_t) 56U)
163 
164 /*********************************************************************
165  * @def OSAL_FREERTOS_SEMAPHOREP_SIZE_BYTES
166  * Semaphorep handle size for non-os use case
167  * Application can use this size to provide a secondary extended
168  * memory block for semaphore creation when all the memory (internal to osal)
169  * are utilized
170  *
171  *********************************************************************/
172 #if defined (BUILD_C7X)
173 #define OSAL_FREERTOS_SEMAPHOREP_SIZE_BYTES ((uint32_t) 176U)
174 #else
175 #define OSAL_FREERTOS_SEMAPHOREP_SIZE_BYTES ((uint32_t) 96U)
176 #endif
177 
178 /*********************************************************************
179  * @def OSAL_FREERTOS_TASKP_SIZE_BYTES
180  * TaskP handle size for non-os use case
181  * Application can use this size to provide a secondary extended
182  * memory block for semaphore creation when all the memory (internal to osal)
183  * are utilized
184  *
185  *********************************************************************/
186 #define OSAL_FREERTOS_TASKP_SIZE_BYTES ((uint32_t) 128U)
187 
188 /*********************************************************************
189  * @def OSAL_SAFERTOS_SEMAPHOREP_SIZE_BYTES
190  * Semaphorep handle size for non-os use case
191  * Application can use this size to provide a secondary extended
192  * memory block for semaphore creation when all the memory (internal to osal)
193  * are utilized
194  *
195  *********************************************************************/
196 #if defined (BUILD_C7X)
197 #define OSAL_SAFERTOS_SEMAPHOREP_SIZE_BYTES ((uint32_t) 304U)
198 #else
199 #define OSAL_SAFERTOS_SEMAPHOREP_SIZE_BYTES ((uint32_t) 248U)
200 #endif
201 
202 /*********************************************************************
203  * @def OSAL_SAFERTOS_TASKP_SIZE_BYTES
204  * TaskP handle size for non-os use case
205  * Application can use this size to provide a secondary extended
206  * memory block for semaphore creation when all the memory (internal to osal)
207  * are utilized
208  *
209  *********************************************************************/
210 #if defined (BUILD_C7X)
211 #define OSAL_SAFERTOS_TASKP_SIZE_BYTES ((uint32_t) 320U)
212 #else
213 #define OSAL_SAFERTOS_TASKP_SIZE_BYTES ((uint32_t) 248U)
214 #endif
215 
220 typedef struct Osal_StaticMemoryStatus
221 {
222  uint32_t peakSemObjs;
223  uint32_t numMaxSemObjs;
224  uint32_t numFreeSemObjs;
226  uint32_t peakTimerObjs;
227  uint32_t numMaxTimerObjs;
228  uint32_t numFreeTimerObjs;
230  uint32_t peakHwiObjs;
231  uint32_t numMaxHwiObjs;
232  uint32_t numFreeHwiObjs;
234 
239 typedef enum Osal_ThreadType_e {
246 
247 /* Internal function for assert */
248 extern void Osal_DebugP_assert(int32_t expression, const char *file, int32_t line);
258 /* in real code use TI's version of OSAL_Assert (which is also fatal for OSAL_Assert(1)*/
259 #define OSAL_Assert(expression) (Osal_DebugP_assert((int32_t)((expression)?1:0),\
260  __FILE__, __LINE__))
261 
269 
282 extern int32_t Osal_delay(uint32_t nTicks);
283 
288 typedef enum {
292 
297 typedef struct Osal_memRange_s {
298  uintptr_t base;
299  uint32_t size;
300 } Osal_memRange;
301 
306 typedef struct Osal_HwAttrs_s
307 {
309  uint32_t cpuFreqKHz;
311  uint32_t extClkKHz;
312 #if defined(gnu_targets_arm_A15F)
313 
314  uint32_t a15TargetProcMask;
315 #endif
316 #ifdef _TMS320C6X
317 
318  uint32_t ECM_intNum[4];
319 #endif
320 
334 } Osal_HwAttrs;
335 
344 #define OSAL_HWATTR_SET_EXT_CLK (0x00000001U)
345 
349 #define OSAL_HWATTR_SET_ECM_INT (0x00000002U)
350 
354 #define OSAL_HWATTR_SET_HWACCESS_TYPE (0x00000004U)
355 
359 #define OSAL_HWATTR_SET_OSALDELAY_TIMER_BASE (0x00000008U)
360 
364 #define OSAL_HWATTR_SET_SEMP_EXT_BASE (0x00000010U)
365 
369 #define OSAL_HWATTR_SET_HWIP_EXT_BASE (0x00000020U)
370 
374 #define OSAL_HWATTR_SET_CPU_FREQ (0x00000040U)
375 
379 #define OSAL_HWATTR_SET_TARG_PROC_LIST (0x00000080)
380 /* @} */
381 
382 
400 extern int32_t Osal_setHwAttrs(uint32_t ctrlBitMap, const Osal_HwAttrs *hwAttrs);
401 
409 extern int32_t Osal_getHwAttrs(Osal_HwAttrs *hwAttrs);
410 
418 extern int32_t Osal_getStaticMemStatus(Osal_StaticMemStatus *pMemStat);
419 
425 extern uint32_t Osal_getCoreId(void);
426 
432 int32_t Osal_isInPrivilegeMode(void);
433 
438 
469 #define OSAL_COMPILE_TIME_SIZE_CHECK(x,y) \
470  do { \
471  struct { \
472  uint8_t NegativeSizeIfPostulateFalse[(y) + 1U - (x)]; \
473  } PostulateCheck; \
474  } \
475  while ((bool)false)
476 
481 extern void OS_init(void);
482 
487 extern void OS_start(void);
488 
493 extern void OS_stop(void);
494 
495 #ifdef __cplusplus
496 }
497 #endif
498 
499 #endif /* ti_OSAL__include */
500 /* @} */
Cycle profiler module to measure CPU cycles for the RTOS Porting Interface.
Osal_HwAccessType
Osal hw access type.
Definition: osal.h:288
Event Combiner routines for the RTOS Porting Interface.
Interrupt register routines.
Heap management module for the RTOS Porting Interface.
Osal_memRange extHwiPBlock
Definition: osal.h:333
uint32_t peakTimerObjs
Definition: osal.h:226
Osal hw attributes structure.
Definition: osal.h:306
int32_t Osal_isInPrivilegeMode(void)
Function to check if the calling task is in privileged mode.
Osal_ThreadType Osal_getThreadType(void)
Function to get the current thread type.
Osal_HwAccessType hwAccessType
Definition: osal.h:321
Cache Handling routines for the RTOS Porting Interface.
Definition: osal.h:240
Definition: osal.h:241
void OS_stop(void)
Function to stop OS / scheduler.
Definition: osal.h:290
uint32_t cpuFreqKHz
Definition: osal.h:309
Definition: osal.h:242
uintptr_t base
Definition: osal.h:298
uint32_t numMaxSemObjs
Definition: osal.h:223
Mailbox module for the RTOS Porting Interface.
Queue Handling routines for RTOS.
uint32_t Osal_getCoreId(void)
Function to get the core ID of the running Core.
Event module for the RTOS Porting Interface.
Definition: osal.h:243
Definition: osal.h:244
Mailbox module for the RTOS Porting Interface.
Osal_memRange extSemaphorePBlock
Definition: osal.h:331
uint32_t numMaxTimerObjs
Definition: osal.h:227
Interrupt Controller Mux module for the RTOS Porting Interface.
Memory module for the RTOS Porting Interface.
uintptr_t osalDelayTimerBaseAddr
Definition: osal.h:329
uint32_t numFreeSemObjs
Definition: osal.h:224
uint32_t peakHwiObjs
Definition: osal.h:230
Semaphore module for the RTOS Porting Interface.
This structure holds static memory status parameters of OSAL library.
Definition: osal.h:220
Task module for the RTOS Porting Interface.
void Osal_DebugP_assert(int32_t expression, const char *file, int32_t line)
void OS_init(void)
Function for initializing the OS / scheduler.
int32_t Osal_delay(uint32_t nTicks)
Function to delay/sleep the specified number of ticks.
uint32_t numFreeHwiObjs
Definition: osal.h:232
Osal_ThreadType
This enum defines the multiple thread types used under OSAL library.
Definition: osal.h:239
Definition: osal.h:289
uint32_t numFreeTimerObjs
Definition: osal.h:228
uint32_t numMaxHwiObjs
Definition: osal.h:231
Osal_HwAttrs gOsal_HwAttrs
external references for Osal Hw Attribute structure
Clock module for the RTOS Porting Interface. This implements the software timer support....
uint32_t extClkKHz
Definition: osal.h:311
Osal memory address range.
Definition: osal.h:297
uint32_t size
Definition: osal.h:299
int32_t Osal_getStaticMemStatus(Osal_StaticMemStatus *pMemStat)
Function to get the static memory usage of OSAL library.
int32_t Osal_setHwAttrs(uint32_t ctrlBitMap, const Osal_HwAttrs *hwAttrs)
Function to set the Hw Attributes.
uint32_t peakSemObjs
Definition: osal.h:222
void OS_start(void)
Function to strat OS / scheduler.
int32_t Osal_getHwAttrs(Osal_HwAttrs *hwAttrs)
Function to get the Hw Attributes.
Hardware Interrupt module for the RTOS Porting Interface.
Timer interface for the RTOS Porting Interface.