1 /* 2 * Copyright 2018 NXP 3 * All rights reserved. 4 * 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #ifndef __COMMON_TASK_H__ 10 #define __COMMON_TASK_H__ 11 12 #include "fsl_common.h" 13 /*! 14 * @addtogroup CommonTask 15 * @{ 16 */ 17 18 #ifndef COMMON_TASK_ENABLE 19 #define COMMON_TASK_ENABLE (0) 20 #endif 21 #if !defined(OSA_USED) 22 #undef COMMON_TASK_ENABLE 23 #define COMMON_TASK_ENABLE (0) 24 #endif 25 /******************************************************************************* 26 * Definitions 27 ******************************************************************************/ 28 29 #if defined(OSA_USED) 30 31 /*! @brief Definition of common task max msg queue count. */ 32 #ifndef COMMON_TASK_MAX_MSGQ_COUNT 33 #define COMMON_TASK_MAX_MSGQ_COUNT (8U) 34 #endif 35 36 /*! @brief Definition of common task priority. */ 37 #ifndef COMMON_TASK_PRIORITY 38 #define COMMON_TASK_PRIORITY (9U) 39 #endif 40 41 /*! @brief Definition of common task stack size. */ 42 #ifndef COMMON_TASK_STACK_SIZE 43 #define COMMON_TASK_STACK_SIZE (2000U) 44 #endif 45 46 /*! @brief The status type of common task */ 47 typedef enum _common_task_status 48 { 49 kStatus_COMMON_TASK_Success = kStatus_Success, /*!< Success */ 50 kStatus_COMMON_TASK_Error = MAKE_STATUS(kStatusGroup_COMMON_TASK, 1), /*!< Failed */ 51 kStatus_COMMON_TASK_Busy = MAKE_STATUS(kStatusGroup_COMMON_TASK, 2), /*!< Busy */ 52 } common_task_status_t; 53 54 /*! @brief The callback function of common task */ 55 typedef void (*common_task_message_callback_t)(void *callbackParam); 56 57 /*! @brief The callback message struct of common task */ 58 typedef struct _common_task_message 59 { 60 common_task_message_callback_t callback; 61 void *callbackParam; 62 } common_task_message_t; 63 64 /******************************************************************************* 65 * API 66 ******************************************************************************/ 67 68 #if defined(__cplusplus) 69 extern "C" { 70 #endif /* _cplusplus */ 71 72 /*! 73 * @name Common task functional operation 74 * @{ 75 */ 76 77 /*! 78 * @brief Initializes the common task module 79 * 80 * This function is used to initialize the common task module. The module is a delegation for other modules 81 * without the self task. The common task will be created when the function is calling. 82 * The task stack size is set by #COMMON_TASK_STACK_SIZE. And the task priority is defined by #COMMON_TASK_PRIORITY. 83 * And a message queue is created with the length #COMMON_TASK_MAX_MSGQ_COUN by the function. 84 * 85 * This is an example. 86 * @code 87 * COMMON_TASK_init(); 88 * @endcode 89 * @retval kStatus_COMMON_TASK_Success The common task initialization succeed. 90 * @retval kStatus_COMMON_TASK_Error An error occurred when the common task is initialized. 91 */ 92 common_task_status_t COMMON_TASK_init(void); 93 94 /*! 95 * @brief De-initializes the common task module 96 * 97 * This function is used to de-initialize the common task module. 98 * 99 * @retval kStatus_COMMON_TASK_Success The common task de-initialization succeed. 100 * @retval kStatus_COMMON_TASK_Error An error occurred when the common task is de-initialized. 101 */ 102 common_task_status_t COMMON_TASK_deinit(void); 103 104 /*! 105 * @brief Posts a new message to common task 106 * 107 * This function is used to post a new message to common task. The message space cannot be released until 108 * the message is executed. 109 * 110 * @param msg Pointer to point to a memory space of #common_task_message_t allocated by the caller. 111 * @retval kStatus_COMMON_TASK_Success The common task de-initialization succeed. 112 * @retval kStatus_COMMON_TASK_Error An error occurred when post a message to the common task. 113 */ 114 common_task_status_t COMMON_TASK_post_message(common_task_message_t *msg); 115 116 /*! 117 * @brief Get the common task instance 118 * 119 * This function is used to get the common task instance. 120 * 121 * @retval The instance of the common task. 122 */ 123 void *COMMON_TASK_get_instance(void); 124 125 /*! 126 * @brief Get the pending message count of common task 127 * 128 * This function is used to get the pending message count of common task. 129 * 130 * @retval Pending message count. 131 */ 132 int COMMON_TASK_get_pending_message_count(void); 133 134 /*! @} */ 135 136 #if defined(__cplusplus) 137 } 138 #endif 139 140 #endif 141 142 /*! @}*/ 143 144 #endif 145