wm_wl_task.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /**
  2. * @file wm_wl_task.h
  3. *
  4. * @brief task APIs
  5. *
  6. * @author dave
  7. *
  8. * Copyright (c) 2015 Winner Microelectronics Co., Ltd.
  9. */
  10. #ifndef __TLS_WL_TASK_H__
  11. #define __TLS_WL_TASK_H__
  12. #include "wm_type_def.h"
  13. #include "wm_wl_mbox.h"
  14. #include "wm_wl_timers.h"
  15. //#include "ithread.h"
  16. #define TLS_TASK_START_PRIO 0
  17. #define TASK_WL_PRIO 9
  18. #define TASK_WL_PRIO_MAX 12
  19. #define TLS_SUPPLICANT_TASK_PRIO (TASK_WL_PRIO_MAX + 1)
  20. #define TLS_SUPPLICANT_TIMER_TASK_PRIO (TASK_WL_PRIO_MAX + 2)
  21. #define TLS_LWIP_TASK_PRIO (TASK_WL_PRIO_MAX + 3)
  22. #define TLS_SYS_TASK_PRIO (TASK_WL_PRIO_MAX + 5)
  23. #define TLS_HOSTIF_TASK_PRIO (TASK_WL_PRIO_MAX + 6)
  24. #define TLS_SPI_SCHEDULER_TASK_PRIO (TASK_WL_PRIO_MAX + 7)
  25. #define TLS_FWUP_TASK_PRIO (TASK_WL_PRIO_MAX + 8)
  26. #define TLS_HTTP_CLIENT_TASK_PRIO (TASK_WL_PRIO_MAX + 9)
  27. #define AP_SOCKET_S_TASK_PRIO (TASK_WL_PRIO_MAX + 10)
  28. #define TLS_UPNP_TASK_PRIO (TASK_WL_PRIO_MAX + 11)
  29. #define TLS_ONESHOT_TASK_PRIO (TASK_WL_PRIO_MAX + 15)
  30. #define TLS_ONESHOT_SPEC_TASK_PRIO (TASK_WL_PRIO_MAX + 16)
  31. #define TLS_MBOX_ALL_COUNT 8
  32. #define TLS_MBOX_ID_WL_TASK 0
  33. #define TLS_MBOX_ID_HOSTIF_TASK 1
  34. #define TLS_MBOX_ID_JDCLOUD_SERVER 2
  35. #define TLS_MBOX_ID_JDCLOUD_DATA 3
  36. #define TLS_MBOX_ID_UPNP_HD 4
  37. #define TLS_MBOX_ID_UPNP_COMMON 5
  38. #define TLS_MBOX_ID_UPNP_GENA 6
  39. #define TLS_MBOX_ID_UPNP_MINISERVER 7
  40. #define TLS_TIMEO_ALL_COUONT 9
  41. #define TLS_TIMEO_ID_NULL 0
  42. #define TLS_TIMEO_ID_WL_TASK 1
  43. #define TLS_TIMEO_ID_HOSTIF_TASK 2
  44. #define TLS_TIMEO_ID_JDCLOUD_SERVER 3
  45. #define TLS_TIMEO_ID_JDCLOUD_DATA 4
  46. #define TLS_TIMEO_ID_UPNP_HD 5
  47. #define TLS_TIMEO_ID_UPNP_COMMON 6
  48. #define TLS_TIMEO_ID_UPNP_GENA 7
  49. #define TLS_TIMEO_ID_UPNP_MINISERVER 8
  50. #define TLS_MSG_ALL_COUONT 9
  51. #define TLS_MSG_ID_TX_MGMT_CMPLT 0
  52. #define TLS_MSG_ID_MLME_TASK 1
  53. #define TLS_MSG_ID_UART_SENT_FREE 2
  54. #define TLS_MSG_ID_UART0_RX 3
  55. #define TLS_MSG_ID_HSPI_RX_CMD 4
  56. #define TLS_MSG_ID_HSPI_RX_DATA 5
  57. #define TLS_MSG_ID_HSPI_TX_DATA 6
  58. #define TLS_MSG_ID_TX_DATA_CMPLT 7
  59. #define TLS_MSG_ID_UART1_RX 8
  60. /** pointer to the semaphore */
  61. typedef tls_os_sem_t * tls_sem_t;
  62. /** Thread start routine */
  63. typedef void *(*start_routine)(void *arg);
  64. /** message type of task */
  65. enum task_msg_type {
  66. TASK_MSG_TIMEOUT,
  67. TASK_MSG_UNTIMEOUT,
  68. TASK_MSG_CALLBACK_WITH_BLOCK,
  69. TASK_MSG_CALLBACK,
  70. TASK_MSG_CALLBACK_STATIC,
  71. TASK_MSG_NULL
  72. };
  73. /** message of task */
  74. struct task_msg {
  75. enum task_msg_type type;
  76. tls_sem_t *sem;
  77. union {
  78. struct {
  79. start_routine function;
  80. void *ctx;
  81. } cb;
  82. struct {
  83. start_routine function;
  84. void *ctx;
  85. u8 cnt;
  86. } cbs;
  87. struct {
  88. u32 msecs;
  89. tls_timeout_handler h;
  90. void *arg;
  91. } tmo;
  92. } msg;
  93. };
  94. /** task parameters */
  95. struct task_parameter{
  96. u8 task_id; /**< task ID */
  97. const char * name; /**< task name */
  98. u8 *stk_start; /**< start address of task stack */
  99. u32 stk_size; /**< size of task stack */
  100. u8 mbox_size; /**< size of mailbox */
  101. u8 mbox_id; /**< mailbox ID */
  102. u8 timeo_id; /**< timer ID */
  103. };
  104. /**
  105. * @brief Task initialized
  106. *
  107. * @param None
  108. *
  109. * @retval 0 success
  110. * @retval other failed
  111. *
  112. * @note None
  113. */
  114. s8 tls_wl_task_init(void);
  115. /**
  116. * @brief Running the task
  117. *
  118. * @param[in] *task_param pointer to the task parameters
  119. *
  120. * @retval 0 success
  121. * @retval other failed
  122. *
  123. * @note None
  124. */
  125. s8 tls_wl_task_run(struct task_parameter *task_param);
  126. /**
  127. * @brief Running the callback function
  128. *
  129. * @param[in] *task_param pointer to the task parameters
  130. * @param[in] function the callback function
  131. * @param[in] *ctx parameter of the callback function
  132. * @param[in] block
  133. * @param[in] msg_id
  134. *
  135. * @retval TLS_OS_SUCCESS success
  136. * @retval TLS_OS_ERROR failed
  137. *
  138. * @note None
  139. */
  140. s8 tls_wl_task_callback_static(struct task_parameter *task_param,
  141. start_routine function, void *ctx, u8 block, u8 msg_id);
  142. /**
  143. * @brief Running the callback function
  144. *
  145. * @param[in] *task_param pointer to the task parameters
  146. * @param[in] function the callback function
  147. * @param[in] *ctx parameter of the callback function
  148. * @param[in] block
  149. *
  150. * @retval TLS_OS_SUCCESS success
  151. * @retval TLS_OS_ERROR failed
  152. *
  153. * @note None
  154. */
  155. s8 tls_wl_task_callback(struct task_parameter *task_param,
  156. start_routine function, void *ctx, u8 block);
  157. /**
  158. * @brief Add a timer to the task
  159. *
  160. * @param[in] *task_param pointer to the task parameters
  161. * @param[in] msecs timer value
  162. * @param[in] h the callback function
  163. * @param[in] *arg parameter of the callback function
  164. *
  165. * @retval TLS_OS_SUCCESS success
  166. * @retval TLS_OS_ERROR failed
  167. *
  168. * @note None
  169. */
  170. s8 tls_wl_task_add_timeout(struct task_parameter *task_param, u32 msecs,
  171. tls_timeout_handler h, void *arg);
  172. /**
  173. * @brief Stop or delay the timer to expire.
  174. *
  175. * @param[in] *task_param pointer to the task parameters
  176. * @param[in] h the callback function
  177. * @param[in] *arg parameter of the callback function
  178. *
  179. * @retval TLS_OS_SUCCESS success
  180. * @retval TLS_OS_ERROR failed
  181. *
  182. * @note None
  183. */
  184. s8 tls_wl_task_untimeout(struct task_parameter *task_param,
  185. tls_timeout_handler h, void *arg);
  186. #endif