mac_task_scheduler.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /**
  2. * Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
  3. *
  4. * All Rights Reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. *
  10. * 1. Redistributions of source code must retain the above copyright notice, this
  11. * list of conditions and the following disclaimer.
  12. *
  13. * 2. Redistributions in binary form, except as embedded into a Nordic
  14. * Semiconductor ASA integrated circuit in a product or a software update for
  15. * such product, must reproduce the above copyright notice, this list of
  16. * conditions and the following disclaimer in the documentation and/or other
  17. * materials provided with the distribution.
  18. *
  19. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * 4. This software, with or without modification, must only be used with a
  24. * Nordic Semiconductor ASA integrated circuit.
  25. *
  26. * 5. Any software provided in binary form under this license must not be reverse
  27. * engineered, decompiled, modified and/or disassembled.
  28. *
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  31. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  33. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  34. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  35. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  36. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  38. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  39. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. *
  41. */
  42. #ifndef MAC_TASK_SCHEDULER_H_INCLUDED
  43. #define MAC_TASK_SCHEDULER_H_INCLUDED
  44. #include <stdint.h>
  45. #include "sys_queue.h"
  46. #include "sys_time.h"
  47. /** @file
  48. *
  49. * @defgroup mac_task_scheduler MAC task scheduler
  50. * @ingroup mac_15_4
  51. * @{
  52. * @brief Module for MAC task scheduling.
  53. */
  54. /**@brief Identifiers for external requests.
  55. */
  56. typedef enum
  57. {
  58. #if (CONFIG_PURGE_ENABLED == 1)
  59. MAC_PURGE_REQ_ID,
  60. #endif
  61. #if (CONFIG_ASSOCIATE_REQ_ENABLED == 1)
  62. MAC_ASSOCIATE_REQ_ID,
  63. #endif
  64. #if (CONFIG_DISASSOCIATE_ENABLED == 1)
  65. MAC_DISASSOCIATE_REQ_ID,
  66. #endif
  67. MAC_GET_REQ_ID,
  68. #if (CONFIG_GTS_ENABLED == 1)
  69. MAC_GTS_REQ_ID,
  70. #endif
  71. MAC_RESET_REQ_ID,
  72. #if (CONFIG_RXE_ENABLED == 1)
  73. MAC_RX_ENABLE_REQ_ID,
  74. #endif
  75. MAC_SCAN_REQ_ID,
  76. MAC_SET_REQ_ID,
  77. #if (CONFIG_SYNC_REQ_ENABLED == 1)
  78. MAC_SYNC_REQ_ID,
  79. #endif
  80. MAC_POLL_REQ_ID,
  81. #if (CONFIG_START_ENABLED == 1)
  82. MAC_START_REQ_ID,
  83. #endif
  84. MAC_DATA_REQ_ID,
  85. #if (CONFIG_ORPHAN_ENABLED == 1)
  86. MAC_ORPHAN_RESP_ID,
  87. #endif
  88. MAC_REQS_AMOUNT
  89. } mac_req_id_t;
  90. /**@brief Identifiers for internal handlers.
  91. *
  92. * These handlers are used for private MAC task scheduling.
  93. */
  94. typedef enum
  95. {
  96. #if (CONFIG_FFD_DEVICE == 1) && (CONFIG_BEACON_ENABLED == 1)
  97. MAC_SUPERFRAME_OUT_TASK_ID,
  98. #endif
  99. MAC_CSMA_CA_TASK_ID,
  100. #if (CONFIG_START_ENABLED == 1)
  101. MAC_START_TASK_ID,
  102. #endif
  103. MAC_FP_TX_TASK_ID,
  104. MAC_DATA_DIR_CONF_ID,
  105. #if (CONFIG_INDIRECT_ENGINE_ENABLED == 1)
  106. MAC_INDIR_ENGINE_REQ_ID,
  107. #endif
  108. MAC_FP_RX_TASK_ID,
  109. #if (CONFIG_ORPHAN_ENABLED == 1)
  110. MAC_ORPHAN_IND_ID,
  111. #endif
  112. #if (CONFIG_DISASSOCIATE_ENABLED == 1)
  113. MAC_DISASSOC_IND_ID,
  114. #endif
  115. #if (CONFIG_SYNC_ENABLED == 1)
  116. MAC_SYNC_LOSS_IND_ID,
  117. #endif
  118. MAC_GET_CONF_ID,
  119. MAC_SET_CONF_ID,
  120. MAC_REQ_QUEUE_TASK_ID,
  121. MAC_POLL_TASK_ID,
  122. MAC_SCAN_CONF_ID,
  123. MAC_MEM_ALLOCATOR_TASK_ID,
  124. MAC_TASKS_AMOUNT
  125. } mac_task_id_t;
  126. /**@brief MAC request descriptor.
  127. */
  128. typedef struct
  129. {
  130. sys_queue_item_t item;
  131. mac_req_id_t id;
  132. void * p_conf_cb; //pointer to confirmation primitive
  133. } mac_abstract_req_t;
  134. /**@brief scheduler memory.
  135. */
  136. typedef struct
  137. {
  138. sys_queue_t outer_req_queue;
  139. volatile uint32_t pending_tasks;
  140. bool mac_scheduler_busy;
  141. } mac_scheduler_mem_t;
  142. /**@brief MAC task handler prototype.
  143. *
  144. * @details Handler which will be called by the MAC scheduler.
  145. */
  146. typedef void (* mac_task_handler_t)(void);
  147. /**@brief MAC external requests queue task handler prototype.
  148. *
  149. * @details Handler which will be called by the MAC scheduler inside
  150. * corresponding task handler.
  151. */
  152. typedef void (* mac_req_handler_t)(mac_abstract_req_t *);
  153. /**@brief Initialize MAC scheduler.
  154. *
  155. * @details Clean up MAC request's queue.
  156. */
  157. void mac_init(void);
  158. /**@brief MAC task handler.
  159. *
  160. * @details Handler invokes a MAC primitives routine for a request according to
  161. * the requests identification.
  162. */
  163. void mac_task_handler(void);
  164. /**@brief Scheduler request from some MAC primitive.
  165. *
  166. * @details Place request to MAC scheduler queue for a further handling.
  167. *
  168. * @param[in] p_req Pointer to a request structure.
  169. */
  170. void mac_request_schedule(mac_abstract_req_t * p_req);
  171. /**@brief Internal function of MAC API.
  172. *
  173. * This function is used to post tasks between MAC primitives.
  174. *
  175. * @param[in] id MAC task ID.
  176. *
  177. */
  178. void mac_internal_task_post(mac_task_id_t id);
  179. /**@brief Internal function of MAC API.
  180. *
  181. * Notifies mac scheduler that incoming request has been completely
  182. * served and may be safely removed from MAC task queue.
  183. *
  184. * @param[in] p_req Pointer to a request structure.
  185. */
  186. void mac_close_request(mac_abstract_req_t * p_req);
  187. /** @} */
  188. #endif // MAC_TASK_SCHEDULER_H_INCLUDED