1 /* 2 * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @file wm_wl_task.h 18 * 19 * @brief task APIs 20 * 21 * @author dave 22 * 23 * Copyright (c) 2015 Winner Microelectronics Co., Ltd. 24 */ 25 #ifndef __TLS_WL_TASK_H__ 26 #define __TLS_WL_TASK_H__ 27 28 #include "wm_type_def.h" 29 #include "wm_wl_mbox.h" 30 #include "wm_wl_timers.h" 31 32 #define TLS_TASK_START_PRIO 0 33 #define TASK_WL_PRIO 9 34 #define TASK_WL_PRIO_MAX 12 35 #define TLS_SUPPLICANT_TASK_PRIO (TASK_WL_PRIO_MAX + 1) 36 #define TLS_SUPPLICANT_TIMER_TASK_PRIO (TASK_WL_PRIO_MAX + 2) 37 #define TLS_LWIP_TASK_PRIO (TASK_WL_PRIO_MAX + 3) 38 #define TLS_SYS_TASK_PRIO (TASK_WL_PRIO_MAX + 5) 39 #define TLS_HOSTIF_TASK_PRIO (TASK_WL_PRIO_MAX + 6) 40 #define TLS_SPI_SCHEDULER_TASK_PRIO (TASK_WL_PRIO_MAX + 7) 41 #define TLS_FWUP_TASK_PRIO (TASK_WL_PRIO_MAX + 8) 42 #define TLS_HTTP_CLIENT_TASK_PRIO (TASK_WL_PRIO_MAX + 9) 43 #define AP_SOCKET_S_TASK_PRIO (TASK_WL_PRIO_MAX + 10) 44 #define TLS_UPNP_TASK_PRIO (TASK_WL_PRIO_MAX + 11) 45 #define TLS_ONESHOT_TASK_PRIO (TASK_WL_PRIO_MAX + 15) 46 #define TLS_ONESHOT_SPEC_TASK_PRIO (TASK_WL_PRIO_MAX + 16) 47 48 #define TLS_MBOX_ALL_COUNT 8 49 #define TLS_MBOX_ID_WL_TASK 0 50 #define TLS_MBOX_ID_HOSTIF_TASK 1 51 #define TLS_MBOX_ID_JDCLOUD_SERVER 2 52 #define TLS_MBOX_ID_JDCLOUD_DATA 3 53 #define TLS_MBOX_ID_UPNP_HD 4 54 #define TLS_MBOX_ID_UPNP_COMMON 5 55 #define TLS_MBOX_ID_UPNP_GENA 6 56 #define TLS_MBOX_ID_UPNP_MINISERVER 7 57 58 #define TLS_TIMEO_ALL_COUONT 9 59 #define TLS_TIMEO_ID_NULL 0 60 #define TLS_TIMEO_ID_WL_TASK 1 61 #define TLS_TIMEO_ID_HOSTIF_TASK 2 62 #define TLS_TIMEO_ID_JDCLOUD_SERVER 3 63 #define TLS_TIMEO_ID_JDCLOUD_DATA 4 64 #define TLS_TIMEO_ID_UPNP_HD 5 65 #define TLS_TIMEO_ID_UPNP_COMMON 6 66 #define TLS_TIMEO_ID_UPNP_GENA 7 67 #define TLS_TIMEO_ID_UPNP_MINISERVER 8 68 69 #define TLS_MSG_ALL_COUONT 9 70 #define TLS_MSG_ID_TX_MGMT_CMPLT 0 71 #define TLS_MSG_ID_MLME_TASK 1 72 #define TLS_MSG_ID_UART_SENT_FREE 2 73 #define TLS_MSG_ID_UART0_RX 3 74 #define TLS_MSG_ID_HSPI_RX_CMD 4 75 #define TLS_MSG_ID_HSPI_RX_DATA 5 76 #define TLS_MSG_ID_HSPI_TX_DATA 6 77 #define TLS_MSG_ID_TX_DATA_CMPLT 7 78 #define TLS_MSG_ID_UART1_RX 8 79 80 /** pointer to the semaphore */ 81 typedef tls_os_sem_t *tls_sem_t; 82 83 /** Thread start routine */ 84 typedef void *(*start_routine)(void *arg); 85 86 /** message type of task */ 87 enum task_msg_type { 88 TASK_MSG_TIMEOUT, 89 TASK_MSG_UNTIMEOUT, 90 TASK_MSG_CALLBACK_WITH_BLOCK, 91 TASK_MSG_CALLBACK, 92 TASK_MSG_CALLBACK_STATIC, 93 TASK_MSG_NULL 94 }; 95 96 /** message of task */ 97 struct task_msg { 98 enum task_msg_type type; 99 tls_sem_t *sem; 100 union { 101 struct { 102 start_routine function; 103 void *ctx; 104 } cb; 105 struct { 106 start_routine function; 107 void *ctx; 108 u8 cnt; 109 } cbs; 110 struct { 111 u32 msecs; 112 tls_timeout_handler h; 113 void *arg; 114 } tmo; 115 } msg; 116 }; 117 118 /** task parameters */ 119 struct task_parameter { 120 u8 task_id; /**< task ID */ 121 const char *name; /**< task name */ 122 u8 *stk_start; /**< start address of task stack */ 123 u32 stk_size; /**< size of task stack */ 124 u8 mbox_size; /**< size of mailbox */ 125 u8 mbox_id; /**< mailbox ID */ 126 u8 timeo_id; /**< timer ID */ 127 }; 128 129 /** 130 * @brief Task initialized 131 * 132 * @param None 133 * 134 * @retval 0 success 135 * @retval other failed 136 * 137 * @note None 138 */ 139 s8 tls_wl_task_init(void); 140 141 /** 142 * @brief Running the task 143 * 144 * @param[in] *task_param pointer to the task parameters 145 * 146 * @retval 0 success 147 * @retval other failed 148 * 149 * @note None 150 */ 151 s8 tls_wl_task_run(struct task_parameter *task_param); 152 153 /** 154 * @brief Running the callback function 155 * 156 * @param[in] *task_param pointer to the task parameters 157 * @param[in] function the callback function 158 * @param[in] *ctx parameter of the callback function 159 * @param[in] block 160 * @param[in] msg_id 161 * 162 * @retval TLS_OS_SUCCESS success 163 * @retval TLS_OS_ERROR failed 164 * 165 * @note None 166 */ 167 s8 tls_wl_task_callback_static(struct task_parameter *task_param, 168 start_routine function, void *ctx, u8 block, u8 msg_id); 169 170 /** 171 * @brief Running the callback function 172 * 173 * @param[in] *task_param pointer to the task parameters 174 * @param[in] function the callback function 175 * @param[in] *ctx parameter of the callback function 176 * @param[in] block 177 * 178 * @retval TLS_OS_SUCCESS success 179 * @retval TLS_OS_ERROR failed 180 * 181 * @note None 182 */ 183 s8 tls_wl_task_callback(struct task_parameter *task_param, 184 start_routine function, void *ctx, u8 block); 185 186 /** 187 * @brief Add a timer to the task 188 * 189 * @param[in] *task_param pointer to the task parameters 190 * @param[in] msecs timer value 191 * @param[in] h the callback function 192 * @param[in] *arg parameter of the callback function 193 * 194 * @retval TLS_OS_SUCCESS success 195 * @retval TLS_OS_ERROR failed 196 * 197 * @note None 198 */ 199 s8 tls_wl_task_add_timeout(struct task_parameter *task_param, u32 msecs, 200 tls_timeout_handler h, void *arg); 201 202 /** 203 * @brief Stop or delay the timer to expire. 204 * 205 * @param[in] *task_param pointer to the task parameters 206 * @param[in] h the callback function 207 * @param[in] *arg parameter of the callback function 208 * 209 * @retval TLS_OS_SUCCESS success 210 * @retval TLS_OS_ERROR failed 211 * 212 * @note None 213 */ 214 s8 tls_wl_task_untimeout(struct task_parameter *task_param, 215 tls_timeout_handler h, void *arg); 216 217 #endif 218 219