1 /* 2 * Copyright (c) 2015, Freescale Semiconductor, Inc. 3 * Copyright 2016-2020, 2024 NXP 4 * 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #ifndef _FSL_OS_ABSTRACTION_H_ 10 #define _FSL_OS_ABSTRACTION_H_ 11 12 #ifndef SDK_COMPONENT_DEPENDENCY_FSL_COMMON 13 #define SDK_COMPONENT_DEPENDENCY_FSL_COMMON (1U) 14 #endif 15 #if (defined(SDK_COMPONENT_DEPENDENCY_FSL_COMMON) && (SDK_COMPONENT_DEPENDENCY_FSL_COMMON > 0U)) 16 #include "fsl_common.h" 17 #else 18 #endif 19 20 #include "fsl_os_abstraction_config.h" 21 22 #ifndef __ZEPHYR__ 23 #include "fsl_component_generic_list.h" 24 #endif 25 26 /*! 27 * @addtogroup osa_adapter 28 * @{ 29 */ 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 /******************************************************************************* 36 * Definitions 37 ******************************************************************************/ 38 39 /*! @brief Type for the Task Priority*/ 40 typedef uint16_t osa_task_priority_t; 41 /*! @brief Type for a task handler */ 42 typedef void *osa_task_handle_t; 43 /*! @brief Type for the parameter to be passed to the task at its creation */ 44 typedef void *osa_task_param_t; 45 /*! @brief Type for task pointer. Task prototype declaration */ 46 typedef void (*osa_task_ptr_t)(osa_task_param_t task_param); 47 /*! @brief Type for the semaphore handler */ 48 typedef void *osa_semaphore_handle_t; 49 /*! @brief Type for the mutex handler */ 50 typedef void *osa_mutex_handle_t; 51 /*! @brief Type for the event handler */ 52 typedef void *osa_event_handle_t; 53 /*! @brief Type for an event flags group, bit 32 is reserved. */ 54 typedef uint32_t osa_event_flags_t; 55 /*! @brief Message definition. */ 56 typedef void *osa_msg_handle_t; 57 /*! @brief Type for the message queue handler */ 58 typedef void *osa_msgq_handle_t; 59 /*! @brief Type for the Timer handler */ 60 typedef void *osa_timer_handle_t; 61 /*! @brief Type for the Timer callback function pointer. */ 62 typedef void (*osa_timer_fct_ptr_t)(void const *argument); 63 /*! @brief Type for the semaphore counter. */ 64 typedef uint32_t osa_semaphore_count_t; 65 /*! @brief Type for the notification wait time. */ 66 typedef uint32_t osa_notify_time_ms_t; 67 /*! @brief Thread Definition structure contains startup information of a thread.*/ 68 typedef struct osa_task_def_tag 69 { 70 osa_task_ptr_t pthread; /*!< start address of thread function*/ 71 uint32_t tpriority; /*!< initial thread priority*/ 72 uint32_t instances; /*!< maximum number of instances of that thread function*/ 73 uint32_t stacksize; /*!< stack size requirements in bytes; 0 is default stack size*/ 74 uint8_t *tstack; /*!< stack pointer, which can be used on freertos static allocation*/ 75 void *tlink; /*!< link pointer*/ 76 uint8_t *tname; /*!< name pointer*/ 77 uint8_t useFloat; /*!< is use float*/ 78 } osa_task_def_t; 79 /*! @brief Thread Link Definition structure .*/ 80 typedef struct osa_thread_link_tag 81 { 82 uint8_t link[12]; /*!< link*/ 83 osa_task_handle_t osThreadId; /*!< thread id*/ 84 osa_task_def_t *osThreadDefHandle; /*!< pointer of thread define handle*/ 85 uint32_t *osThreadStackHandle; /*!< pointer of thread stack handle*/ 86 } osa_thread_link_t, *osa_thread_link_handle_t; 87 88 /*! @brief Definition structure contains timer parameters.*/ 89 typedef struct osa_time_def_tag 90 { 91 osa_timer_fct_ptr_t pfCallback; /* < start address of a timer function */ 92 void *argument; /* < argument of a timer function */ 93 } osa_time_def_t; 94 95 /*! @brief Type for the timer definition*/ 96 typedef enum _osa_timer 97 { 98 KOSA_TimerOnce = 0, /*!< one-shot timer*/ 99 KOSA_TimerPeriodic = 1 /*!< repeating timer*/ 100 } osa_timer_t; 101 102 /*! @brief Defines the return status of OSA's functions */ 103 #if (defined(SDK_COMPONENT_DEPENDENCY_FSL_COMMON) && (SDK_COMPONENT_DEPENDENCY_FSL_COMMON > 0U)) 104 typedef enum _osa_status 105 { 106 KOSA_StatusSuccess = kStatus_Success, /*!< Success */ 107 KOSA_StatusError = MAKE_STATUS(kStatusGroup_OSA, 1), /*!< Failed */ 108 KOSA_StatusTimeout = MAKE_STATUS(kStatusGroup_OSA, 2), /*!< Timeout occurs while waiting */ 109 KOSA_StatusIdle = MAKE_STATUS(kStatusGroup_OSA, 3), /*!< Used for bare metal only, the wait object is not ready 110 and timeout still not occur */ 111 } osa_status_t; 112 #else 113 typedef enum _osa_status 114 { 115 KOSA_StatusSuccess = 0, /*!< Success */ 116 KOSA_StatusError = 1, /*!< Failed */ 117 KOSA_StatusTimeout = 2, /*!< Timeout occurs while waiting */ 118 KOSA_StatusIdle = 3, /*!< Used for bare metal only, the wait object is not ready 119 and timeout still not occur */ 120 } osa_status_t; 121 122 #endif 123 124 #ifdef USE_RTOS 125 #undef USE_RTOS 126 #endif 127 128 #if defined(SDK_OS_FREE_RTOS) 129 #include "fsl_os_abstraction_free_rtos.h" 130 #elif defined(FSL_RTOS_THREADX) 131 #include "fsl_os_abstraction_threadx.h" 132 #elif defined(__ZEPHYR__) 133 #include "fsl_os_abstraction_zephyr.h" 134 #else 135 #include "fsl_os_abstraction_bm.h" 136 #endif 137 138 extern const uint8_t gUseRtos_c; 139 140 #if defined(SDK_OS_MQX) 141 #define USE_RTOS (1) 142 #elif defined(SDK_OS_FREE_RTOS) 143 #define USE_RTOS (1) 144 #if (defined(GENERIC_LIST_LIGHT) && (GENERIC_LIST_LIGHT > 0U)) 145 #if (defined(configSUPPORT_STATIC_ALLOCATION) && (configSUPPORT_STATIC_ALLOCATION > 0U)) && \ 146 !((defined(configSUPPORT_DYNAMIC_ALLOCATION) && (configSUPPORT_DYNAMIC_ALLOCATION > 0U))) 147 #define OSA_TASK_HANDLE_SIZE (150U) 148 #else 149 #define OSA_TASK_HANDLE_SIZE (12U) 150 #endif 151 #else 152 #define OSA_TASK_HANDLE_SIZE (16U) 153 #endif 154 #if (defined(configSUPPORT_STATIC_ALLOCATION) && (configSUPPORT_STATIC_ALLOCATION > 0U)) && \ 155 !((defined(configSUPPORT_DYNAMIC_ALLOCATION) && (configSUPPORT_DYNAMIC_ALLOCATION > 0U))) 156 #define OSA_EVENT_HANDLE_SIZE (40U) 157 #else 158 #define OSA_EVENT_HANDLE_SIZE (8U) 159 #endif 160 #if (defined(configSUPPORT_STATIC_ALLOCATION) && (configSUPPORT_STATIC_ALLOCATION > 0U)) && \ 161 !((defined(configSUPPORT_DYNAMIC_ALLOCATION) && (configSUPPORT_DYNAMIC_ALLOCATION > 0U))) 162 #define OSA_SEM_HANDLE_SIZE (84U) 163 #else 164 #define OSA_SEM_HANDLE_SIZE (4U) 165 #endif 166 #if (defined(configSUPPORT_STATIC_ALLOCATION) && (configSUPPORT_STATIC_ALLOCATION > 0U)) && \ 167 !((defined(configSUPPORT_DYNAMIC_ALLOCATION) && (configSUPPORT_DYNAMIC_ALLOCATION > 0U))) 168 #define OSA_MUTEX_HANDLE_SIZE (84U) 169 #else 170 #define OSA_MUTEX_HANDLE_SIZE (4U) 171 #endif 172 #if (defined(configSUPPORT_STATIC_ALLOCATION) && (configSUPPORT_STATIC_ALLOCATION > 0U)) && \ 173 !((defined(configSUPPORT_DYNAMIC_ALLOCATION) && (configSUPPORT_DYNAMIC_ALLOCATION > 0U))) 174 #define OSA_MSGQ_HANDLE_SIZE (84U) 175 #else 176 #define OSA_MSGQ_HANDLE_SIZE (4U) 177 #endif 178 #define OSA_MSG_HANDLE_SIZE (0U) 179 #if (defined(configSUPPORT_STATIC_ALLOCATION) && (configSUPPORT_STATIC_ALLOCATION > 0U)) && \ 180 !((defined(configSUPPORT_DYNAMIC_ALLOCATION) && (configSUPPORT_DYNAMIC_ALLOCATION > 0U))) 181 #define OSA_TIMER_HANDLE_SIZE (48U) 182 #else 183 #define OSA_TIMER_HANDLE_SIZE (4U) 184 #endif 185 #elif defined(SDK_OS_UCOSII) 186 #define USE_RTOS (1) 187 #elif defined(SDK_OS_UCOSIII) 188 #define USE_RTOS (1) 189 #elif defined(FSL_RTOS_THREADX) 190 #define USE_RTOS (1) 191 #elif defined(__ZEPHYR__) 192 #define USE_RTOS (1) 193 #else 194 #define USE_RTOS (0) 195 #if (defined(GENERIC_LIST_LIGHT) && (GENERIC_LIST_LIGHT > 0U)) 196 #define OSA_TASK_HANDLE_SIZE (24U) 197 #else 198 #define OSA_TASK_HANDLE_SIZE (28U) 199 #endif 200 #if (defined(FSL_OSA_TASK_ENABLE) && (FSL_OSA_TASK_ENABLE > 0U)) 201 #define OSA_EVENT_HANDLE_SIZE (20U) 202 #else 203 #define OSA_EVENT_HANDLE_SIZE (16U) 204 #endif /* FSL_OSA_TASK_ENABLE */ 205 #if (defined(FSL_OSA_BM_TIMEOUT_ENABLE) && (FSL_OSA_BM_TIMEOUT_ENABLE > 0U)) 206 #define OSA_SEM_HANDLE_SIZE (16U) 207 #define OSA_MUTEX_HANDLE_SIZE (12U) 208 #else 209 #define OSA_SEM_HANDLE_SIZE (8U) 210 #define OSA_MUTEX_HANDLE_SIZE (4U) 211 #endif 212 #if (defined(FSL_OSA_TASK_ENABLE) && (FSL_OSA_TASK_ENABLE > 0U)) 213 #define OSA_MSGQ_HANDLE_SIZE (32U) 214 #else 215 #define OSA_MSGQ_HANDLE_SIZE (28U) 216 #endif /* FSL_OSA_TASK_ENABLE */ 217 #define OSA_MSG_HANDLE_SIZE (4U) 218 #endif 219 220 /*! @brief Priority setting for OSA. */ 221 #ifndef OSA_PRIORITY_IDLE 222 #define OSA_PRIORITY_IDLE (6U) 223 #endif 224 225 #ifndef OSA_PRIORITY_LOW 226 #define OSA_PRIORITY_LOW (5U) 227 #endif 228 229 #ifndef OSA_PRIORITY_BELOW_NORMAL 230 #define OSA_PRIORITY_BELOW_NORMAL (4U) 231 #endif 232 233 #ifndef OSA_PRIORITY_NORMAL 234 #define OSA_PRIORITY_NORMAL (3U) 235 #endif 236 237 #ifndef OSA_PRIORITY_ABOVE_NORMAL 238 #define OSA_PRIORITY_ABOVE_NORMAL (2U) 239 #endif 240 241 #ifndef OSA_PRIORITY_HIGH 242 #define OSA_PRIORITY_HIGH (1U) 243 #endif 244 245 #ifndef OSA_PRIORITY_REAL_TIME 246 #define OSA_PRIORITY_REAL_TIME (0U) 247 #endif 248 249 #ifndef OSA_TASK_PRIORITY_MAX 250 #define OSA_TASK_PRIORITY_MAX (0U) 251 #endif 252 253 #ifndef OSA_TASK_PRIORITY_MIN 254 #define OSA_TASK_PRIORITY_MIN (15U) 255 #endif 256 257 /* 258 * Converse the percent of the priority to the priority of the OSA. 259 * The the range of the parameter x is 0-100. 260 */ 261 #define OSA_TASK_PRIORITY_PERCENT(x) \ 262 ((((OSA_TASK_PRIORITY_MIN - OSA_TASK_PRIORITY_MAX) * (100 - (x))) / 100) + OSA_TASK_PRIORITY_MAX) 263 264 #define SIZE_IN_UINT32_UNITS(size) (((size) + sizeof(uint32_t) - 1) / sizeof(uint32_t)) 265 266 /*! @brief Constant to pass as timeout value in order to wait indefinitely. */ 267 #define osaWaitNone_c ((uint32_t)(0)) 268 #define osaWaitForever_c ((uint32_t)(-1)) 269 #define osaEventFlagsAll_c ((osa_event_flags_t)(0x00FFFFFF)) 270 #define osThreadStackArray(name) osThread_##name##_stack 271 #define osThreadStackDef(name, stacksize, instances) \ 272 const uint32_t osThreadStackArray(name)[SIZE_IN_UINT32_UNITS(stacksize) * (instances)]; 273 274 /* ==== Thread Management ==== */ 275 276 /* Create a Thread Definition with function, priority, and stack requirements. 277 * \param name name of the thread function. 278 * \param priority initial priority of the thread function. 279 * \param instances number of possible thread instances. 280 * \param stackSz stack size (in bytes) requirements for the thread function. 281 * \param useFloat 282 */ 283 #if defined(SDK_OS_MQX) 284 #define OSA_TASK_DEFINE(name, priority, instances, stackSz, useFloat) \ 285 osa_thread_link_t osThreadLink_##name[instances] = {0}; \ 286 osThreadStackDef(name, stackSz, instances) osa_task_def_t os_thread_def_##name = { \ 287 (name), (priority), (instances), (stackSz), (uint8_t *) osThreadStackArray(name), osThreadLink_##name, \ 288 (uint8_t *)#name, (useFloat)} 289 #elif defined(SDK_OS_UCOSII) 290 #if gTaskMultipleInstancesManagement_c 291 #define OSA_TASK_DEFINE(name, priority, instances, stackSz, useFloat) \ 292 osa_thread_link_t osThreadLink_##name[instances] = {0}; \ 293 osThreadStackDef(name, stackSz, instances) osa_task_def_t os_thread_def_##name = { \ 294 (name), (priority), (instances), (stackSz), (uint8_t *) osThreadStackArray(name), osThreadLink_##name, \ 295 (uint8_t *)#name, (useFloat)} 296 #else 297 #define OSA_TASK_DEFINE(name, priority, instances, stackSz, useFloat) \ 298 osThreadStackDef(name, stackSz, instances) osa_task_def_t os_thread_def_##name = { \ 299 (name), (priority), (instances), (stackSz), (uint8_t *) osThreadStackArray(name), NULL, (uint8_t *)#name, (useFloat)} 300 #endif 301 #elif defined(FSL_RTOS_THREADX) 302 #define OSA_TASK_DEFINE(name, priority, instances, stackSz, useFloat) \ 303 uint32_t s_stackBuffer##name[(stackSz + sizeof(uint32_t) - 1U) / sizeof(uint32_t)]; \ 304 static const osa_task_def_t os_thread_def_##name = { \ 305 (name), (priority), (instances), (stackSz), (uint8_t *) s_stackBuffer##name, NULL, (uint8_t *)#name, (useFloat)} 306 #elif defined(__ZEPHYR__) 307 #define OSA_TASK_DEFINE(name, priority, instances, stackSz, useFloat) \ 308 K_THREAD_STACK_DEFINE(name##_stack, (stackSz)); \ 309 const osa_task_def_t os_thread_def_##name = {(name), (priority), (instances), (stackSz), \ 310 (uint8_t *) name##_stack, NULL, (uint8_t *)#name, (useFloat)} 311 #else 312 #if (defined(configSUPPORT_STATIC_ALLOCATION) && (configSUPPORT_STATIC_ALLOCATION > 0U)) && \ 313 !((defined(configSUPPORT_DYNAMIC_ALLOCATION) && (configSUPPORT_DYNAMIC_ALLOCATION > 0U))) 314 #define OSA_TASK_DEFINE(name, priority, instances, stackSz, useFloat) \ 315 uint32_t s_stackBuffer##name[(stackSz + sizeof(uint32_t) - 1U) / sizeof(uint32_t)]; \ 316 static const osa_task_def_t os_thread_def_##name = { \ 317 (name), (priority), (instances), (stackSz), (uint8_t *) s_stackBuffer##name, NULL, (uint8_t *)#name, (useFloat)} 318 #else 319 #define OSA_TASK_DEFINE(name, priority, instances, stackSz, useFloat) \ 320 const osa_task_def_t os_thread_def_##name = {(name), (priority), (instances), (stackSz), \ 321 NULL, NULL, (uint8_t *)#name, (useFloat)} 322 #endif 323 #endif 324 /* Access a Thread defintion. 325 * \param name name of the thread definition object. 326 */ 327 #define OSA_TASK(name) (const osa_task_def_t *)&os_thread_def_##name 328 329 #define OSA_TASK_PROTO(name) extern osa_task_def_t os_thread_def_##name 330 /* ==== Timer Management ==== 331 * Define a Timer object. 332 * \param name name of the timer object. 333 * \param function name of the timer call back function. 334 */ 335 336 #define OSA_TIMER_DEF(name, function) osa_time_def_t os_timer_def_##name = {(function), NULL} 337 338 /* Access a Timer definition. 339 * \param name name of the timer object. 340 */ 341 #define OSA_TIMER(name) &os_timer_def_##name 342 343 /* ==== Buffer Definition ==== */ 344 345 /*! 346 * @brief Defines the semaphore handle 347 * 348 * This macro is used to define a 4 byte aligned semaphore handle. 349 * Then use "(osa_semaphore_handle_t)name" to get the semaphore handle. 350 * 351 * The macro should be global and could be optional. You could also define semaphore handle by yourself. 352 * 353 * This is an example, 354 * @code 355 * OSA_SEMAPHORE_HANDLE_DEFINE(semaphoreHandle); 356 * @endcode 357 * 358 * @param name The name string of the semaphore handle. 359 */ 360 #define OSA_SEMAPHORE_HANDLE_DEFINE(name) \ 361 uint32_t name[(OSA_SEM_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)] 362 363 /*! 364 * @brief Defines the mutex handle 365 * 366 * This macro is used to define a 4 byte aligned mutex handle. 367 * Then use "(osa_mutex_handle_t)name" to get the mutex handle. 368 * 369 * The macro should be global and could be optional. You could also define mutex handle by yourself. 370 * 371 * This is an example, 372 * @code 373 * OSA_MUTEX_HANDLE_DEFINE(mutexHandle); 374 * @endcode 375 * 376 * @param name The name string of the mutex handle. 377 */ 378 #define OSA_MUTEX_HANDLE_DEFINE(name) uint32_t name[(OSA_MUTEX_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)] 379 380 /*! 381 * @brief Defines the event handle 382 * 383 * This macro is used to define a 4 byte aligned event handle. 384 * Then use "(osa_event_handle_t)name" to get the event handle. 385 * 386 * The macro should be global and could be optional. You could also define event handle by yourself. 387 * 388 * This is an example, 389 * @code 390 * OSA_EVENT_HANDLE_DEFINE(eventHandle); 391 * @endcode 392 * 393 * @param name The name string of the event handle. 394 */ 395 #define OSA_EVENT_HANDLE_DEFINE(name) uint32_t name[(OSA_EVENT_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)] 396 397 /*! 398 * @brief Defines the message queue handle 399 * 400 * This macro is used to define a 4 byte aligned message queue handle. 401 * Then use "(osa_msgq_handle_t)name" to get the message queue handle. 402 * 403 * The macro should be global and could be optional. You could also define message queue handle by yourself. 404 * 405 * This is an example, 406 * @code 407 * OSA_MSGQ_HANDLE_DEFINE(msgqHandle, 3, sizeof(msgStruct)); 408 * @endcode 409 * 410 * @param name The name string of the message queue handle. 411 * @param numberOfMsgs Number of messages. 412 * @param msgSize Message size. 413 * 414 */ 415 #if defined(SDK_OS_FREE_RTOS) && (defined(configSUPPORT_DYNAMIC_ALLOCATION) && (configSUPPORT_DYNAMIC_ALLOCATION > 0)) 416 /*< Macro For FREE_RTOS dynamic allocation*/ 417 #define OSA_MSGQ_HANDLE_DEFINE(name, numberOfMsgs, msgSize) \ 418 uint32_t name[(OSA_MSGQ_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)] 419 #elif defined(__ZEPHYR__) 420 #define OSA_MSGQ_HANDLE_DEFINE(name, numberOfMsgs, msgSize) \ 421 uint32_t name[(OSA_MSGQ_HANDLE_SIZE + (numberOfMsgs * msgSize) + sizeof(uint32_t) - 1U) / sizeof(uint32_t)] 422 #else 423 /*< Macro For BARE_MATEL and FREE_RTOS static allocation*/ 424 #define OSA_MSGQ_HANDLE_DEFINE(name, numberOfMsgs, msgSize) \ 425 uint32_t name[((OSA_MSGQ_HANDLE_SIZE + numberOfMsgs * msgSize) + sizeof(uint32_t) - 1U) / sizeof(uint32_t)] 426 #endif 427 428 /*! 429 * @brief Defines the timer handle 430 * 431 * This macro is used to define a 4 byte aligned timer handle. 432 * Then use "(osa_timer_handle_t)name" to get the timer handle. 433 * 434 * The macro should be global and could be optional. You could also define timer handle by yourself. 435 * 436 * This is an example, 437 * @code 438 * OSA_TIMER_HANDLE_DEFINE(timerHandle); 439 * @endcode 440 * 441 * @param name The name string of the timer handle. 442 */ 443 #define OSA_TIMER_HANDLE_DEFINE(name) uint32_t name[(OSA_TIMER_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)] 444 445 /*! 446 * @brief Defines the TASK handle 447 * 448 * This macro is used to define a 4 byte aligned TASK handle. 449 * Then use "(osa_task_handle_t)name" to get the TASK handle. 450 * 451 * The macro should be global and could be optional. You could also define TASK handle by yourself. 452 * 453 * This is an example, 454 * @code 455 * OSA_TASK_HANDLE_DEFINE(taskHandle); 456 * @endcode 457 * 458 * @param name The name string of the TASK handle. 459 */ 460 #define OSA_TASK_HANDLE_DEFINE(name) uint32_t name[(OSA_TASK_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)] 461 462 #ifndef __DSB 463 #define __DSB() 464 #endif 465 /* 466 * alloc the temporary memory to store the status 467 */ 468 #define OSA_SR_ALLOC() uint32_t osaCurrentSr = 0U; 469 /* 470 * Enter critical mode 471 */ 472 #define OSA_ENTER_CRITICAL() OSA_EnterCritical(&osaCurrentSr) 473 /* 474 * Exit critical mode and retore the previous mode 475 */ 476 #define OSA_EXIT_CRITICAL() \ 477 __DSB(); \ 478 OSA_ExitCritical(osaCurrentSr); 479 480 /******************************************************************************* 481 * API 482 ******************************************************************************/ 483 484 /*! 485 * @brief Reserves the requested amount of memory in bytes. 486 * 487 * The function is used to reserve the requested amount of memory in bytes and initializes it to 0. 488 * 489 * @param memLength Amount of bytes to reserve. 490 * 491 * @return Pointer to the reserved memory. NULL if memory can't be allocated. 492 */ 493 void *OSA_MemoryAllocate(uint32_t memLength); 494 495 /*! 496 * @brief Frees the memory previously reserved. 497 * 498 * The function is used to free the memory block previously reserved. 499 * 500 * @param p Pointer to the start of the memory block previously reserved. 501 * 502 */ 503 void OSA_MemoryFree(void *p); 504 505 /*! 506 * @brief Reserves the requested amount of memory in bytes. 507 * 508 * The function is used to reserve the requested amount of memory in bytes and initializes it to 0. 509 * The function allocates some extra memory to ensure that the return address is aligned on a alignbytes boundary 510 * and that the memory size is a multiple of alignbytes. 511 * 512 * @param memLength Amount of bytes to reserve. 513 * @param alignbytes Bytes boundary. 514 * 515 * @return Pointer to the reserved memory. NULL if memory can't be allocated. 516 */ 517 void *OSA_MemoryAllocateAlign(uint32_t memLength, uint32_t alignbytes); 518 519 /*! 520 * @brief Frees the memory previously reserved. 521 * 522 * The function is used to free the memory block previously reserved. 523 * 524 * @param p Pointer to the start of the memory block previously reserved. 525 * 526 */ 527 void OSA_MemoryFreeAlign(void *p); 528 529 /*! 530 * @brief Enter critical with nesting mode. 531 * 532 * @param sr Store current status and return to caller. 533 */ 534 void OSA_EnterCritical(uint32_t *sr); 535 536 /*! 537 * @brief Exit critical with nesting mode. 538 * 539 * @param sr Previous status to restore. 540 */ 541 void OSA_ExitCritical(uint32_t sr); 542 543 /*! 544 * @name Task management 545 * @{ 546 */ 547 548 /*! 549 * @brief Initialize OSA. 550 * 551 * This function is used to setup the basic services. 552 * 553 * Example below shows how to use this API to create the task handle. 554 * @code 555 * OSA_Init(); 556 * @endcode 557 */ 558 #if (defined(FSL_OSA_TASK_ENABLE) && (FSL_OSA_TASK_ENABLE > 0U)) 559 void OSA_Init(void); 560 #endif 561 562 /*! 563 * @brief Start OSA schedule. 564 * 565 * This function is used to start OSA scheduler. 566 * 567 * Example below shows how to use this API to start osa schedule. 568 * @code 569 * OSA_Start(); 570 * @endcode 571 */ 572 #if (defined(FSL_OSA_TASK_ENABLE) && (FSL_OSA_TASK_ENABLE > 0U)) 573 void OSA_Start(void); 574 #endif 575 576 #if ((defined(FSL_OSA_TASK_ENABLE)) && (FSL_OSA_TASK_ENABLE > 0U)) 577 /*! 578 * @brief Creates a task. 579 * 580 * This function is used to create task based on the resources defined 581 * by the macro OSA_TASK_DEFINE. 582 * 583 * Example below shows how to use this API to create the task handle. 584 * @code 585 * OSA_TASK_HANDLE_DEFINE(taskHandle); 586 * OSA_TASK_DEFINE( Job1, OSA_PRIORITY_HIGH, 1, 800, 0); 587 * OSA_TaskCreate((osa_task_handle_t)taskHandle, OSA_TASK(Job1), (osa_task_param_t)NULL); 588 * @endcode 589 * 590 * @param taskHandle Pointer to a memory space of size OSA_TASK_HANDLE_SIZE allocated by the caller, task handle. 591 * The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices. 592 * You can define the handle in the following two ways: 593 * #OSA_TASK_HANDLE_DEFINE(taskHandle); 594 * or 595 * uint32_t taskHandle[((OSA_TASK_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]; 596 * @param thread_def pointer to theosa_task_def_t structure which defines the task. 597 * @param task_param Pointer to be passed to the task when it is created. 598 * @retval KOSA_StatusSuccess The task is successfully created. 599 * @retval KOSA_StatusError The task can not be created. 600 */ 601 osa_status_t OSA_TaskCreate(osa_task_handle_t taskHandle, 602 const osa_task_def_t *thread_def, 603 osa_task_param_t task_param); 604 #endif /* FSL_OSA_TASK_ENABLE */ 605 606 #if ((defined(FSL_OSA_TASK_ENABLE)) && (FSL_OSA_TASK_ENABLE > 0U)) 607 /*! 608 * @brief Gets the handler of active task. 609 * 610 * @return Handler to current active task. 611 */ 612 osa_task_handle_t OSA_TaskGetCurrentHandle(void); 613 #endif /* FSL_OSA_TASK_ENABLE */ 614 615 #if ((defined(FSL_OSA_TASK_ENABLE)) && (FSL_OSA_TASK_ENABLE > 0U)) 616 /*! 617 * @brief Puts the active task to the end of scheduler's queue. 618 * 619 * When a task calls this function, it gives up the CPU and puts itself to the 620 * end of a task ready list. 621 * 622 * @retval NULL 623 */ 624 void OSA_TaskYield(void); 625 #endif /* FSL_OSA_TASK_ENABLE */ 626 627 #if ((defined(FSL_OSA_TASK_ENABLE)) && (FSL_OSA_TASK_ENABLE > 0U)) 628 /*! 629 * @brief Gets the priority of a task. 630 * 631 * @param taskHandle The handler of the task whose priority is received. 632 * 633 * @return Task's priority. 634 */ 635 osa_task_priority_t OSA_TaskGetPriority(osa_task_handle_t taskHandle); 636 #endif /* FSL_OSA_TASK_ENABLE */ 637 638 #if ((defined(FSL_OSA_TASK_ENABLE)) && (FSL_OSA_TASK_ENABLE > 0U)) 639 /*! 640 * @brief Sets the priority of a task. 641 * 642 * @param taskHandle The handler of the task whose priority is set. 643 * @param taskPriority The priority to set. 644 * 645 * @retval KOSA_StatusSuccess Task's priority is set successfully. 646 * @retval KOSA_StatusError Task's priority can not be set. 647 */ 648 osa_status_t OSA_TaskSetPriority(osa_task_handle_t taskHandle, osa_task_priority_t taskPriority); 649 #endif /* FSL_OSA_TASK_ENABLE */ 650 651 #if ((defined(FSL_OSA_TASK_ENABLE)) && (FSL_OSA_TASK_ENABLE > 0U)) 652 /*! 653 * @brief Destroys a previously created task. 654 * 655 * @param taskHandle The handler of the task to destroy. 656 * 657 * @retval KOSA_StatusSuccess The task was successfully destroyed. 658 * @retval KOSA_StatusError Task destruction failed or invalid parameter. 659 */ 660 osa_status_t OSA_TaskDestroy(osa_task_handle_t taskHandle); 661 #endif /* FSL_OSA_TASK_ENABLE */ 662 663 #if (defined(FSL_OSA_TASK_ENABLE) && (FSL_OSA_TASK_ENABLE > 0U)) 664 /** 665 * @brief Waits for task notification. 666 * 667 * This function waits for task notification from other task or interrupt 668 * context. 669 * 670 * @param[in] waitTime_ms Timeout specified in milliseconds. 671 * 672 * @return KOSA_StatusSuccess When notification is successful 673 * @return KOSA_StatusTimeout When timeout occurs 674 * @return KOSA_StatusError On failure 675 */ 676 osa_status_t OSA_TaskNotifyGet(osa_notify_time_ms_t waitTime_ms); 677 678 /** 679 * @brief Sends task notification 680 * 681 * This function gives task notification so that waiting task can be 682 * unblocked. 683 * 684 * @param[in] task Task handle to be notified 685 * 686 * @return KOSA_StatusSuccess When notification is successful 687 * @return KOSA_StatusError On failure 688 */ 689 osa_status_t OSA_TaskNotifyPost(osa_task_handle_t taskHandle); 690 #endif /* (defined(FSL_OSA_TASK_ENABLE) && (FSL_OSA_TASK_ENABLE > 0U)) */ 691 692 /*! 693 * @brief Pre-creates a semaphore. 694 * 695 * This function pre-creates a semaphore with the task handler. 696 * 697 * Example below shows how to use this API to create the semaphore handle. 698 * @code 699 * OSA_SEMAPHORE_HANDLE_DEFINE(semaphoreHandle); 700 * OSA_SemaphoreCreate((osa_semaphore_handle_t)semaphoreHandle, (osa_task_ptr_t)taskHandler); 701 * @endcode 702 * 703 * @param semaphoreHandle Pointer to a memory space of size OSA_SEM_HANDLE_SIZE allocated by the caller. 704 * The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices. 705 * You can define the handle in the following two ways: 706 * #OSA_SEMAPHORE_HANDLE_DEFINE(semaphoreHandle); 707 * or 708 * uint32_t semaphoreHandle[((OSA_SEM_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]; 709 * @param taskHandler The task handler this semaphore is used by. 710 * 711 * @retval KOSA_StatusSuccess the new semaphore if the semaphore is created successfully. 712 */ 713 osa_status_t OSA_SemaphorePrecreate(osa_semaphore_handle_t semaphoreHandle, osa_task_ptr_t taskHandler); 714 715 /*! 716 * @brief Creates a semaphore with a given value. 717 * 718 * This function creates a semaphore and sets the value to the parameter 719 * initValue. 720 * 721 * Example below shows how to use this API to create the semaphore handle. 722 * @code 723 * OSA_SEMAPHORE_HANDLE_DEFINE(semaphoreHandle); 724 * OSA_SemaphoreCreate((osa_semaphore_handle_t)semaphoreHandle, 0xff); 725 * @endcode 726 * 727 * @param semaphoreHandle Pointer to a memory space of size OSA_SEM_HANDLE_SIZE allocated by the caller. 728 * The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices. 729 * You can define the handle in the following two ways: 730 * #OSA_SEMAPHORE_HANDLE_DEFINE(semaphoreHandle); 731 * or 732 * uint32_t semaphoreHandle[((OSA_SEM_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]; 733 * @param initValue Initial value the semaphore will be set to. 734 * 735 * @retval KOSA_StatusSuccess the new semaphore if the semaphore is created successfully. 736 * @retval KOSA_StatusError if the semaphore can not be created. 737 */ 738 osa_status_t OSA_SemaphoreCreate(osa_semaphore_handle_t semaphoreHandle, uint32_t initValue); 739 740 /*! 741 * @brief Creates a binary semaphore. 742 * 743 * This function creates a binary semaphore 744 * 745 * Example below shows how to use this API to create the semaphore handle. 746 * @code 747 * OSA_SEMAPHORE_HANDLE_DEFINE(semaphoreHandle); 748 * OSA_SemaphoreCreateBinary((osa_semaphore_handle_t)semaphoreHandle); 749 * @endcode 750 * 751 * @param semaphoreHandle Pointer to a memory space of size OSA_SEM_HANDLE_SIZE allocated by the caller. 752 * The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices. 753 * You can define the handle in the following two ways: 754 * #OSA_SEMAPHORE_HANDLE_DEFINE(semaphoreHandle); 755 * or 756 * uint32_t semaphoreHandle[((OSA_SEM_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]; 757 * 758 * @retval KOSA_StatusSuccess the new binary semaphore if the binary semaphore is created successfully. 759 * @retval KOSA_StatusError if the binary semaphore can not be created. 760 */ 761 osa_status_t OSA_SemaphoreCreateBinary(osa_semaphore_handle_t semaphoreHandle); 762 763 /*! 764 * @brief Destroys a previously created semaphore. 765 * 766 * @param semaphoreHandle The semaphore handle. 767 * The macro SEMAPHORE_HANDLE_BUFFER_GET is used to get the semaphore buffer pointer, 768 * and should not be used before the macro SEMAPHORE_HANDLE_BUFFER_DEFINE is used. 769 * 770 * @retval KOSA_StatusSuccess The semaphore is successfully destroyed. 771 * @retval KOSA_StatusError The semaphore can not be destroyed. 772 */ 773 osa_status_t OSA_SemaphoreDestroy(osa_semaphore_handle_t semaphoreHandle); 774 775 /*! 776 * @brief Pending a semaphore with timeout. 777 * 778 * This function checks the semaphore's counting value. If it is positive, 779 * decreases it and returns KOSA_StatusSuccess. Otherwise, a timeout is used 780 * to wait. 781 * 782 * @param semaphoreHandle The semaphore handle. 783 * @param millisec The maximum number of milliseconds to wait if semaphore is not 784 * positive. Pass osaWaitForever_c to wait indefinitely, pass 0 785 * will return KOSA_StatusTimeout immediately. 786 * 787 * @retval KOSA_StatusSuccess The semaphore is received. 788 * @retval KOSA_StatusTimeout The semaphore is not received within the specified 'timeout'. 789 * @retval KOSA_StatusError An incorrect parameter was passed. 790 */ 791 osa_status_t OSA_SemaphoreWait(osa_semaphore_handle_t semaphoreHandle, uint32_t millisec); 792 793 /*! 794 * @brief Signals for someone waiting on the semaphore to wake up. 795 * 796 * Wakes up one task that is waiting on the semaphore. If no task is waiting, increases 797 * the semaphore's counting value. 798 * 799 * @param semaphoreHandle The semaphore handle to signal. 800 * 801 * @retval KOSA_StatusSuccess The semaphore is successfully signaled. 802 * @retval KOSA_StatusError The object can not be signaled or invalid parameter. 803 * 804 */ 805 osa_status_t OSA_SemaphorePost(osa_semaphore_handle_t semaphoreHandle); 806 807 /*! 808 * @brief Gets the semaphore counter. 809 * 810 * @param semaphoreHandle The semaphore handle counter should be obtained from. 811 * 812 * @retval count The semaphore count. 813 * 814 */ 815 osa_semaphore_count_t OSA_SemaphoreGetCount(osa_semaphore_handle_t semaphoreHandle); 816 817 /*! 818 * @brief Create an unlocked mutex. 819 * 820 * This function creates a non-recursive mutex and sets it to unlocked status. 821 * 822 * Example below shows how to use this API to create the mutex handle. 823 * @code 824 * OSA_MUTEX_HANDLE_DEFINE(mutexHandle); 825 * OSA_MutexCreate((osa_mutex_handle_t)mutexHandle); 826 * @endcode 827 * 828 * @param mutexHandle Pointer to a memory space of size OSA_MUTEX_HANDLE_SIZE allocated by the caller. 829 * The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices. 830 * You can define the handle in the following two ways: 831 * #OSA_MUTEX_HANDLE_DEFINE(mutexHandle); 832 * or 833 * uint32_t mutexHandle[((OSA_MUTEX_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]; 834 * @retval KOSA_StatusSuccess the new mutex if the mutex is created successfully. 835 * @retval KOSA_StatusError if the mutex can not be created. 836 */ 837 osa_status_t OSA_MutexCreate(osa_mutex_handle_t mutexHandle); 838 839 /*! 840 * @brief Waits for a mutex and locks it. 841 * 842 * This function checks the mutex's status. If it is unlocked, locks it and returns the 843 * KOSA_StatusSuccess. Otherwise, waits for a timeout in milliseconds to lock. 844 * 845 * @param mutexHandle The mutex handle. 846 * @param millisec The maximum number of milliseconds to wait for the mutex. 847 * If the mutex is locked, Pass the value osaWaitForever_c will 848 * wait indefinitely, pass 0 will return KOSA_StatusTimeout 849 * immediately. 850 * 851 * @retval KOSA_StatusSuccess The mutex is locked successfully. 852 * @retval KOSA_StatusTimeout Timeout occurred. 853 * @retval KOSA_StatusError Incorrect parameter was passed. 854 * 855 * @note This is non-recursive mutex, a task can not try to lock the mutex it has locked. 856 */ 857 osa_status_t OSA_MutexLock(osa_mutex_handle_t mutexHandle, uint32_t millisec); 858 859 /*! 860 * @brief Unlocks a previously locked mutex. 861 * 862 * @param mutexHandle The mutex handle. 863 * 864 * @retval KOSA_StatusSuccess The mutex is successfully unlocked. 865 * @retval KOSA_StatusError The mutex can not be unlocked or invalid parameter. 866 */ 867 osa_status_t OSA_MutexUnlock(osa_mutex_handle_t mutexHandle); 868 869 /*! 870 * @brief Destroys a previously created mutex. 871 * 872 * @param mutexHandle The mutex handle. 873 * 874 * @retval KOSA_StatusSuccess The mutex is successfully destroyed. 875 * @retval KOSA_StatusError The mutex can not be destroyed. 876 * 877 */ 878 osa_status_t OSA_MutexDestroy(osa_mutex_handle_t mutexHandle); 879 880 /*! 881 * @brief Pre-initializes an event object. 882 * 883 * This function pre-creates an event object and indicates which task this event is used by. 884 * 885 * Example below shows how to use this API to create the event handle. 886 * @code 887 * OSA_EVENT_HANDLE_DEFINE(eventHandle); 888 * OSA_EventPrecreate((osa_event_handle_t)eventHandle, (osa_task_ptr_t)taskHandler); 889 * @endcode 890 * 891 * @param eventHandle Pointer to a memory space of size OSA_EVENT_HANDLE_SIZE allocated by the caller. 892 * The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices. 893 * You can define the handle in the following two ways: 894 * #OSA_EVENT_HANDLE_DEFINE(eventHandle); 895 * or 896 * uint32 eventHandle[((OSA_EVENT_HANDLE_SIZE + sizeof(uint32) - 1U) / sizeof(uint32))]; 897 * @param taskHandler The task handler this event is used by. 898 * @retval KOSA_StatusSuccess the new event if the event is pre-created successfully. 899 */ 900 osa_status_t OSA_EventPrecreate(osa_event_handle_t eventHandle, osa_task_ptr_t taskHandler); 901 902 /*! 903 * @brief Initializes an event object with all flags cleared. 904 * 905 * This function creates an event object and set its clear mode. If autoClear 906 * is 1, when a task gets the event flags, these flags will be 907 * cleared automatically. Otherwise these flags must 908 * be cleared manually. 909 * 910 * Example below shows how to use this API to create the event handle. 911 * @code 912 * OSA_EVENT_HANDLE_DEFINE(eventHandle); 913 * OSA_EventCreate((osa_event_handle_t)eventHandle, 0); 914 * @endcode 915 * 916 * @param eventHandle Pointer to a memory space of size OSA_EVENT_HANDLE_SIZE allocated by the caller. 917 * The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices. 918 * You can define the handle in the following two ways: 919 * #OSA_EVENT_HANDLE_DEFINE(eventHandle); 920 * or 921 * uint32_t eventHandle[((OSA_EVENT_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]; 922 * @param autoClear 1 The event is auto-clear. 923 * 0 The event manual-clear 924 * @retval KOSA_StatusSuccess the new event if the event is created successfully. 925 * @retval KOSA_StatusError if the event can not be created. 926 */ 927 osa_status_t OSA_EventCreate(osa_event_handle_t eventHandle, uint8_t autoClear); 928 929 /*! 930 * @brief Sets one or more event flags. 931 * 932 * Sets specified flags of an event object. 933 * 934 * @param eventHandle The event handle. 935 * @param flagsToSet Flags to be set. 936 * 937 * @retval KOSA_StatusSuccess The flags were successfully set. 938 * @retval KOSA_StatusError An incorrect parameter was passed. 939 */ 940 osa_status_t OSA_EventSet(osa_event_handle_t eventHandle, osa_event_flags_t flagsToSet); 941 942 /*! 943 * @brief Clears one or more flags. 944 * 945 * Clears specified flags of an event object. 946 * 947 * @param eventHandle The event handle. 948 * @param flagsToClear Flags to be clear. 949 * 950 * @retval KOSA_StatusSuccess The flags were successfully cleared. 951 * @retval KOSA_StatusError An incorrect parameter was passed. 952 */ 953 osa_status_t OSA_EventClear(osa_event_handle_t eventHandle, osa_event_flags_t flagsToClear); 954 955 /*! 956 * @brief Get event's flags. 957 * 958 * Get specified flags of an event object. 959 * 960 * @param eventHandle The event handle. 961 * The macro EVENT_HANDLE_BUFFER_GET is used to get the event buffer pointer, 962 * and should not be used before the macro EVENT_HANDLE_BUFFER_DEFINE is used. 963 * @param flagsMask The flags user want to get are specified by this parameter. 964 * @param pFlagsOfEvent The event flags are obtained by this parameter. 965 * 966 * @retval KOSA_StatusSuccess The event flags were successfully got. 967 * @retval KOSA_StatusError An incorrect parameter was passed. 968 */ 969 osa_status_t OSA_EventGet(osa_event_handle_t eventHandle, 970 osa_event_flags_t flagsMask, 971 osa_event_flags_t *pFlagsOfEvent); 972 973 /*! 974 * @brief Waits for specified event flags to be set. 975 * 976 * This function waits for a combination of flags to be set in an event object. 977 * Applications can wait for any/all bits to be set. Also this function could 978 * obtain the flags who wakeup the waiting task. 979 * 980 * @param eventHandle The event handle. 981 * @param flagsToWait Flags that to wait. 982 * @param waitAll Wait all flags or any flag to be set. 983 * @param millisec The maximum number of milliseconds to wait for the event. 984 * If the wait condition is not met, pass osaWaitForever_c will 985 * wait indefinitely, pass 0 will return KOSA_StatusTimeout 986 * immediately. 987 * @param pSetFlags Flags that wakeup the waiting task are obtained by this parameter. 988 * 989 * @retval KOSA_StatusSuccess The wait condition met and function returns successfully. 990 * @retval KOSA_StatusTimeout Has not met wait condition within timeout. 991 * @retval KOSA_StatusError An incorrect parameter was passed. 992 993 * 994 * @note Please pay attention to the flags bit width, FreeRTOS uses the most 995 * significant 8 bis as control bits, so do not wait these bits while using 996 * FreeRTOS. 997 * 998 */ 999 osa_status_t OSA_EventWait(osa_event_handle_t eventHandle, 1000 osa_event_flags_t flagsToWait, 1001 uint8_t waitAll, 1002 uint32_t millisec, 1003 osa_event_flags_t *pSetFlags); 1004 1005 /*! 1006 * @brief Destroys a previously created event object. 1007 * 1008 * @param eventHandle The event handle. 1009 * 1010 * @retval KOSA_StatusSuccess The event is successfully destroyed. 1011 * @retval KOSA_StatusError Event destruction failed. 1012 */ 1013 osa_status_t OSA_EventDestroy(osa_event_handle_t eventHandle); 1014 1015 /*! 1016 * @brief Initializes a message queue. 1017 * 1018 * This function allocates memory for and initializes a message queue. Message queue elements are hardcoded as void*. 1019 * 1020 * Example below shows how to use this API to create the massage queue handle. 1021 * @code 1022 * OSA_MSGQ_HANDLE_DEFINE(msgqHandle); 1023 * OSA_MsgQCreate((osa_msgq_handle_t)msgqHandle, 5U, sizeof(msg)); 1024 * @endcode 1025 * 1026 * @param msgqHandle Pointer to a memory space of size #(OSA_MSGQ_HANDLE_SIZE + msgNo*msgSize) on bare-matel, 1027 * FreeRTOS static allocation allocated by the caller and #(OSA_MSGQ_HANDLE_SIZE) on FreeRTOS dynamic allocation, 1028 * message queue handle. The handle should be 4 byte aligned, because unaligned access doesn't be supported on some 1029 * devices. You can define the handle in the following two ways: #OSA_MSGQ_HANDLE_DEFINE(msgqHandle); or For bm and 1030 * freertos static: uint32_t msgqHandle[((OSA_MSGQ_HANDLE_SIZE + msgNo*msgSize + sizeof(uint32_t) - 1U) / 1031 * sizeof(uint32_t))]; For freertos dynamic: uint32_t msgqHandle[((OSA_MSGQ_HANDLE_SIZE + sizeof(uint32_t) - 1U) / 1032 * sizeof(uint32_t))]; 1033 * @param msgNo :number of messages the message queue should accommodate. 1034 * @param msgSize :size of a single message structure. 1035 * 1036 * @retval KOSA_StatusSuccess Message queue successfully Create. 1037 * @retval KOSA_StatusError Message queue create failure. 1038 */ 1039 osa_status_t OSA_MsgQCreate(osa_msgq_handle_t msgqHandle, uint32_t msgNo, uint32_t msgSize); 1040 1041 /*! 1042 * @brief Puts a message at the end of the queue. 1043 * 1044 * This function puts a message to the end of the message queue. If the queue 1045 * is full, this function returns the KOSA_StatusError; 1046 * 1047 * @param msgqHandle Message Queue handler. 1048 * @param pMessage Pointer to the message to be put into the queue. 1049 * 1050 * @retval KOSA_StatusSuccess Message successfully put into the queue. 1051 * @retval KOSA_StatusError The queue was full or an invalid parameter was passed. 1052 */ 1053 osa_status_t OSA_MsgQPut(osa_msgq_handle_t msgqHandle, osa_msg_handle_t pMessage); 1054 1055 /*! 1056 * @brief Reads and remove a message at the head of the queue. 1057 * 1058 * This function gets a message from the head of the message queue. If the 1059 * queue is empty, timeout is used to wait. 1060 * 1061 * @param msgqHandle Message Queue handler. 1062 * @param pMessage Pointer to a memory to save the message. 1063 * @param millisec The number of milliseconds to wait for a message. If the 1064 * queue is empty, pass osaWaitForever_c will wait indefinitely, 1065 * pass 0 will return KOSA_StatusTimeout immediately. 1066 * 1067 * @retval KOSA_StatusSuccess Message successfully obtained from the queue. 1068 * @retval KOSA_StatusTimeout The queue remains empty after timeout. 1069 * @retval KOSA_StatusError Invalid parameter. 1070 */ 1071 osa_status_t OSA_MsgQGet(osa_msgq_handle_t msgqHandle, osa_msg_handle_t pMessage, uint32_t millisec); 1072 1073 /*! 1074 * @brief Get the available message 1075 * 1076 * This function is used to get the available message. 1077 * 1078 * @param msgqHandle Message Queue handler. 1079 * 1080 * @return Available message count 1081 */ 1082 int OSA_MsgQAvailableMsgs(osa_msgq_handle_t msgqHandle); 1083 1084 /*! 1085 * @brief Destroys a previously created queue. 1086 * 1087 * @param msgqHandle Message Queue handler. 1088 * 1089 * @retval KOSA_StatusSuccess The queue was successfully destroyed. 1090 * @retval KOSA_StatusError Message queue destruction failed. 1091 */ 1092 osa_status_t OSA_MsgQDestroy(osa_msgq_handle_t msgqHandle); 1093 1094 /*! 1095 * @brief Enable all interrupts. 1096 */ 1097 void OSA_InterruptEnable(void); 1098 1099 /*! 1100 * @brief Disable all interrupts. 1101 */ 1102 void OSA_InterruptDisable(void); 1103 1104 /*! 1105 * @brief Enable all interrupts using PRIMASK. 1106 */ 1107 void OSA_EnableIRQGlobal(void); 1108 1109 /*! 1110 * @brief Disable all interrupts using PRIMASK. 1111 */ 1112 void OSA_DisableIRQGlobal(void); 1113 1114 /*! 1115 * @brief Disable the scheduling of any task. 1116 */ 1117 void OSA_DisableScheduler(void); 1118 1119 /*! 1120 * @brief Enable the scheduling of any task. 1121 */ 1122 void OSA_EnableScheduler(void); 1123 1124 /*! 1125 * @brief Delays execution for a number of milliseconds. 1126 * 1127 * @param millisec The time in milliseconds to wait. 1128 */ 1129 void OSA_TimeDelay(uint32_t millisec); 1130 1131 /*! 1132 * @brief This function gets current time in milliseconds. 1133 * 1134 * @retval current time in milliseconds 1135 */ 1136 uint32_t OSA_TimeGetMsec(void); 1137 1138 /*! 1139 * @brief Installs the interrupt handler. 1140 * 1141 * @param IRQNumber IRQ number of the interrupt. 1142 * @param handler The interrupt handler to install. 1143 */ 1144 void OSA_InstallIntHandler(uint32_t IRQNumber, void (*handler)(void)); 1145 1146 /*! @}*/ 1147 #ifdef __cplusplus 1148 } 1149 #endif 1150 /*! @}*/ 1151 #endif // _FSL_OS_ABSTRACTION_H_ 1152