PSDK QNX API Guide
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/csl/tistdtypes.h>
63 #include <ti/osal/TaskP.h>
64 #include <ti/osal/HwiP.h>
65 #include <ti/osal/MuxIntcP.h>
66 #include <ti/osal/SemaphoreP.h>
67 #include <ti/osal/CacheP.h>
68 #include <ti/osal/TimerP.h>
69 #include <ti/osal/RegisterIntr.h>
70 #include <ti/osal/QueueP.h>
71 #include <ti/osal/CycleprofilerP.h>
72 #include <ti/osal/MailboxP.h>
73 #include <ti/osal/MutexP.h>
74 #include <ti/osal/ClockP.h>
75 #include <ti/osal/DebugP.h>
76 #include <ti/osal/HeapP.h>
77 #include <ti/osal/MemoryP.h>
78 #include <ti/osal/EventP.h>
79 #include <ti/osal/StartuphooksP.h>
80 #ifdef _TMS320C6X
81 #include <ti/osal/EventCombinerP.h>
82 #endif
83 
89 /*********************************************************************
90  * @def osal_OK
91  * OSAL operation successful
92  *********************************************************************/
93 #define osal_OK ((int32_t)(0))
94 
95 /*********************************************************************
96  * @def osal_FAILURE
97  * OSAL operation failed
98  *********************************************************************/
99 #define osal_FAILURE (-(int32_t)(1))
100 
101 /*********************************************************************
102  * @def osal_UNSUPPORTED
103  * OSAL operation is not supported
104  *********************************************************************/
105 #define osal_UNSUPPORTED (-(int32_t)(2))
106 
107 /*********************************************************************
108  * @def osal_NOMEM
109  * OSAL operation is not successful due to internal osal static memory
110  * is full. Application would need to create additional memory blocks
111  * during startup by calling @ref Osal_setHwAttrs API to set the additional
112  * memory blocks for semaphoreP and hwiP
113  *********************************************************************/
114 #define osal_NOMEM (-(int32_t)(3))
115 /* @} */
116 
117 /*********************************************************************
118  * @def osal_WAIT_FOREVER
119  * OSAL timeout wait forever
120  *********************************************************************/
121 #define osal_WAIT_FOREVER (~((uint32_t)0U))
122 
123 /*********************************************************************
124  * @def osal_NO_WAIT
125  * OSAL timeout no wait
126  *********************************************************************/
127 #define osal_NO_WAIT ((uint32_t)0U)
128 
129 /*********************************************************************
130  * @def OSAL_NONOS_SEMAPHOREP_SIZE_BYTES
131  * Semaphorep handle size for non-os use case
132  * Application can use this size to provide a secondary extended
133  * memory block for semaphore creation when all the memory (internal to osal)
134  * are utilized
135  *
136  *********************************************************************/
137 #define OSAL_NONOS_SEMAPHOREP_SIZE_BYTES ((uint32_t) 48U)
138 
139 /*********************************************************************
140  * @def OSAL_NONOS_HWI_SIZE_BYTES
141  * HwiP handle size for non-os use case
142  * Application can use this size to provide a secondary extended
143  * memory block for hwip creation when all the memory (internal to osal)
144  * are utilized
145  *********************************************************************/
146 #define OSAL_NONOS_HWIP_SIZE_BYTES ((uint32_t) 48U)
147 
148 /*********************************************************************
149  * @def OSAL_FREERTOS_HWIP_C7X_SIZE_BYTES
150  * HwiP handle size for freertos-os c7x use case
151  * Application can use this size to provide a secondary extended
152  * memory block for hwip creation when all the memory (internal to osal)
153  * are utilized
154  *********************************************************************/
155 #define OSAL_FREERTOS_HWIP_C7X_SIZE_BYTES ((uint32_t) 56U)
156 
157 /*********************************************************************
158  * @def OSAL_SAFERTOS_HWIP_C7X_SIZE_BYTES
159  * HwiP handle size for safertos-os c7x use case
160  * Application can use this size to provide a secondary extended
161  * memory block for hwip creation when all the memory (internal to osal)
162  * are utilized
163  *********************************************************************/
164 #define OSAL_SAFERTOS_HWIP_C7X_SIZE_BYTES ((uint32_t) 56U)
165 
166 /*********************************************************************
167  * @def OSAL_FREERTOS_SEMAPHOREP_SIZE_BYTES
168  * Semaphorep handle size for non-os use case
169  * Application can use this size to provide a secondary extended
170  * memory block for semaphore creation when all the memory (internal to osal)
171  * are utilized
172  *
173  *********************************************************************/
174 #if defined (BUILD_C7X)
175 #define OSAL_FREERTOS_SEMAPHOREP_SIZE_BYTES ((uint32_t) 176U)
176 #else
177 #define OSAL_FREERTOS_SEMAPHOREP_SIZE_BYTES ((uint32_t) 96U)
178 #endif
179 
180 /*********************************************************************
181  * @def OSAL_FREERTOS_TASKP_SIZE_BYTES
182  * TaskP handle size for non-os use case
183  * Application can use this size to provide a secondary extended
184  * memory block for semaphore creation when all the memory (internal to osal)
185  * are utilized
186  *
187  *********************************************************************/
188 #define OSAL_FREERTOS_TASKP_SIZE_BYTES ((uint32_t) 128U)
189 
190 /*********************************************************************
191  * @def OSAL_SAFERTOS_SEMAPHOREP_SIZE_BYTES
192  * Semaphorep handle size for non-os use case
193  * Application can use this size to provide a secondary extended
194  * memory block for semaphore creation when all the memory (internal to osal)
195  * are utilized
196  *
197  *********************************************************************/
198 #if defined (BUILD_C7X)
199 #define OSAL_SAFERTOS_SEMAPHOREP_SIZE_BYTES ((uint32_t) 304U)
200 #else
201 #define OSAL_SAFERTOS_SEMAPHOREP_SIZE_BYTES ((uint32_t) 248U)
202 #endif
203 
204 /*********************************************************************
205  * @def OSAL_SAFERTOS_TASKP_SIZE_BYTES
206  * TaskP handle size for non-os use case
207  * Application can use this size to provide a secondary extended
208  * memory block for semaphore creation when all the memory (internal to osal)
209  * are utilized
210  *
211  *********************************************************************/
212 #if defined (BUILD_C7X)
213 #define OSAL_SAFERTOS_TASKP_SIZE_BYTES ((uint32_t) 320U)
214 #else
215 #define OSAL_SAFERTOS_TASKP_SIZE_BYTES ((uint32_t) 248U)
216 #endif
217 
222 typedef struct Osal_StaticMemoryStatus
223 {
224  uint32_t peakSemObjs;
225  uint32_t numMaxSemObjs;
226  uint32_t numFreeSemObjs;
228  uint32_t peakTimerObjs;
229  uint32_t numMaxTimerObjs;
230  uint32_t numFreeTimerObjs;
232  uint32_t peakHwiObjs;
233  uint32_t numMaxHwiObjs;
234  uint32_t numFreeHwiObjs;
236 
241 typedef enum Osal_ThreadType_e {
248 
249 /* Internal function for assert */
250 /* Rename file to filename in function prototype to fix MISRA.CT.UNIQUE.ID and MISRA.VAR.HIDDEN KW issues */
251 extern void Osal_DebugP_assert(int32_t expression, const char *filename, int32_t line);
261 /* in real code use TI's version of OSAL_Assert (which is also fatal for OSAL_Assert(1)*/
262 #define OSAL_Assert(expression) (Osal_DebugP_assert((int32_t)((expression)?1:0),\
263  __FILE__, __LINE__))
264 
272 
285 extern int32_t Osal_delay(uint32_t nTicks);
286 
291 typedef enum {
295 
300 typedef struct Osal_memRange_s {
301  uintptr_t base;
302  uint32_t size;
303  uint32_t padding;
304 } Osal_memRange;
305 
310 typedef struct Osal_HwAttrs_s
311 {
313  uint32_t cpuFreqKHz;
315  uint32_t extClkKHz;
316 #if defined(gnu_targets_arm_A15F)
318  uint32_t a15TargetProcMask;
319 #endif
320 #ifdef _TMS320C6X
322  uint32_t ECM_intNum[4];
323 #endif
327  uint32_t padding;
340 } Osal_HwAttrs;
341 
350 #define OSAL_HWATTR_SET_EXT_CLK (0x00000001U)
351 
355 #define OSAL_HWATTR_SET_ECM_INT (0x00000002U)
356 
360 #define OSAL_HWATTR_SET_HWACCESS_TYPE (0x00000004U)
361 
365 #define OSAL_HWATTR_SET_OSALDELAY_TIMER_BASE (0x00000008U)
366 
370 #define OSAL_HWATTR_SET_SEMP_EXT_BASE (0x00000010U)
371 
375 #define OSAL_HWATTR_SET_HWIP_EXT_BASE (0x00000020U)
376 
380 #define OSAL_HWATTR_SET_CPU_FREQ (0x00000040U)
381 
385 #define OSAL_HWATTR_SET_TARG_PROC_LIST (0x00000080U)
386 /* @} */
387 
388 
406 extern int32_t Osal_setHwAttrs(uint32_t ctrlBitMap, const Osal_HwAttrs *hwAttrs);
407 
415 extern int32_t Osal_getHwAttrs(Osal_HwAttrs *hwAttrs);
416 
425 
431 extern uint32_t Osal_getCoreId(void);
432 
439 
444 
475 #define OSAL_COMPILE_TIME_SIZE_CHECK(x,y) \
476  do { \
477  struct { \
478  uint8_t NegativeSizeIfPostulateFalse[(y) + 1U - (x)]; \
479  } PostulateCheck; \
480  } \
481  while (BFALSE)
482 
487 extern void OS_init(void);
488 
493 extern void OS_start(void);
494 
499 extern void OS_stop(void);
500 
501 #ifdef __cplusplus
502 }
503 #endif
504 
505 #endif /* ti_OSAL__include */
506 /* @} */
Cache Handling routines for the RTOS Porting Interface.
Clock module for the RTOS Porting Interface. This implements the software timer support....
Hardware Interrupt module for the RTOS Porting Interface.
Mailbox module for the RTOS Porting Interface.
Queue Handling routines for RTOS.
Interrupt register routines.
Semaphore module for the RTOS Porting Interface.
Task module for the RTOS Porting Interface.
Osal_ThreadType
This enum defines the multiple thread types used under OSAL library.
Definition: osal.h:241
uint32_t padding
Definition: osal.h:303
uintptr_t base
Definition: osal.h:301
uint32_t numMaxHwiObjs
Definition: osal.h:233
uint32_t peakSemObjs
Definition: osal.h:224
uint32_t numFreeSemObjs
Definition: osal.h:226
uint32_t numFreeHwiObjs
Definition: osal.h:234
int32_t Osal_setHwAttrs(uint32_t ctrlBitMap, const Osal_HwAttrs *hwAttrs)
Function to set the Hw Attributes.
uint32_t cpuFreqKHz
Definition: osal.h:313
Osal_HwAccessType
Osal hw access type.
Definition: osal.h:291
void Osal_DebugP_assert(int32_t expression, const char *filename, int32_t line)
Osal_ThreadType Osal_getThreadType(void)
Function to get the current thread type.
void OS_stop(void)
Function to stop OS / scheduler.
int32_t Osal_getStaticMemStatus(Osal_StaticMemStatus *pMemStat)
Function to get the static memory usage of OSAL library.
uint32_t Osal_getCoreId(void)
Function to get the core ID of the running Core.
Osal_memRange extHwiPBlock
Definition: osal.h:339
int32_t Osal_delay(uint32_t nTicks)
Function to delay/sleep the specified number of ticks.
int32_t Osal_isInPrivilegeMode(void)
Function to check if the calling task is in privileged mode.
uint32_t padding
Definition: osal.h:327
uint32_t size
Definition: osal.h:302
uintptr_t osalDelayTimerBaseAddr
Definition: osal.h:335
uint32_t peakHwiObjs
Definition: osal.h:232
int32_t Osal_getHwAttrs(Osal_HwAttrs *hwAttrs)
Function to get the Hw Attributes.
void OS_init(void)
Function for initializing the OS / scheduler.
Osal_HwAttrs gOsal_HwAttrs
external references for Osal Hw Attribute structure
uint32_t numMaxSemObjs
Definition: osal.h:225
void OS_start(void)
Function to strat OS / scheduler.
uint32_t numMaxTimerObjs
Definition: osal.h:229
uint32_t numFreeTimerObjs
Definition: osal.h:230
Osal_HwAccessType hwAccessType
Definition: osal.h:325
uint32_t peakTimerObjs
Definition: osal.h:228
Osal_memRange extSemaphorePBlock
Definition: osal.h:337
uint32_t extClkKHz
Definition: osal.h:315
@ Osal_ThreadType_Swi
Definition: osal.h:243
@ Osal_ThreadType_Main
Definition: osal.h:245
@ Osal_ThreadType_Hwi
Definition: osal.h:242
@ Osal_ThreadType_Task
Definition: osal.h:244
@ Osal_ThreadType_Abort
Definition: osal.h:246
@ OSAL_HWACCESS_UNRESTRICTED
Definition: osal.h:292
@ OSAL_HWACCESS_RESTRICTED
Definition: osal.h:293
Osal hw attributes structure.
Definition: osal.h:311
This structure holds static memory status parameters of OSAL library.
Definition: osal.h:223
Osal memory address range.
Definition: osal.h:300