LoRaMacConfirmQueue.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*!
  2. * \file LoRaMacConfirmQueue.h
  3. *
  4. * \brief LoRa MAC confirm queue implementation
  5. *
  6. * \copyright Revised BSD License, see section \ref LICENSE.
  7. *
  8. * \code
  9. * ______ _
  10. * / _____) _ | |
  11. * ( (____ _____ ____ _| |_ _____ ____| |__
  12. * \____ \| ___ | (_ _) ___ |/ ___) _ \
  13. * _____) ) ____| | | || |_| ____( (___| | | |
  14. * (______/|_____)_|_|_| \__)_____)\____)_| |_|
  15. * (C)2013 Semtech
  16. *
  17. * ___ _____ _ ___ _ _____ ___ ___ ___ ___
  18. * / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __|
  19. * \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _|
  20. * |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___|
  21. * embedded.connectivity.solutions===============
  22. *
  23. * \endcode
  24. *
  25. * \author Miguel Luis ( Semtech )
  26. *
  27. * \author Gregory Cristian ( Semtech )
  28. *
  29. * \author Daniel Jaeckle ( STACKFORCE )
  30. *
  31. * \defgroup LORAMACCONFIRMQUEUE LoRa MAC confirm queue implementation
  32. * This module specifies the API implementation of the LoRaMAC confirm queue.
  33. * The confirm queue is implemented with as a ring buffer. The number of
  34. * elements can be defined with \ref LORA_MAC_MLME_CONFIRM_QUEUE_LEN. The
  35. * current implementation does not support multiple elements of the same
  36. * Mlme_t type.
  37. * \{
  38. */
  39. #ifndef __LORAMAC_CONFIRMQUEUE_H__
  40. #define __LORAMAC_CONFIRMQUEUE_H__
  41. #ifdef __cplusplus
  42. extern "C"
  43. {
  44. #endif
  45. #include <stdbool.h>
  46. #include <stdint.h>
  47. #include "LoRaMac.h"
  48. /*!
  49. * LoRaMac MLME-Confirm queue length
  50. */
  51. #define LORA_MAC_MLME_CONFIRM_QUEUE_LEN 5
  52. /*!
  53. * Structure to hold multiple MLME request confirm data
  54. */
  55. typedef struct sMlmeConfirmQueue
  56. {
  57. /*!
  58. * Holds the previously performed MLME-Request
  59. */
  60. Mlme_t Request;
  61. /*!
  62. * Status of the operation
  63. */
  64. LoRaMacEventInfoStatus_t Status;
  65. /*!
  66. * Set to true, if the request is ready to be handled
  67. */
  68. bool ReadyToHandle;
  69. /*!
  70. * Set to true, if it is not permitted to set the ReadyToHandle variable
  71. * with a function call to LoRaMacConfirmQueueSetStatusCmn.
  72. */
  73. bool RestrictCommonReadyToHandle;
  74. }MlmeConfirmQueue_t;
  75. /*!
  76. * Signature of callback function to be called by this module when the
  77. * non-volatile needs to be saved.
  78. */
  79. typedef void ( *LoRaMacConfirmQueueNvmEvent )( void );
  80. /*!
  81. * \brief Initializes the confirm queue
  82. *
  83. * \param [IN] primitives - Pointer to the LoRaMac primitives.
  84. *
  85. * \param [IN] confirmQueueNvmCtxChanged - Callback function which will be called when the
  86. * non-volatile context needs to be saved.
  87. */
  88. void LoRaMacConfirmQueueInit( LoRaMacPrimitives_t* primitives, LoRaMacConfirmQueueNvmEvent confirmQueueNvmCtxChanged );
  89. /*!
  90. * Restores the internal non-volatile context from passed pointer.
  91. *
  92. * \param [IN] confirmQueueNvmCtx - Pointer to non-volatile class B module context to be restored.
  93. *
  94. * \retval [true - operation was successful, false - operation failed]
  95. */
  96. bool LoRaMacConfirmQueueRestoreNvmCtx( void* confirmQueueNvmCtx );
  97. /*!
  98. * Returns a pointer to the internal non-volatile context.
  99. *
  100. * \param [IN] confirmQueueNvmCtxSize - Size of the module non-volatile context
  101. *
  102. * \retval - Points to a structure where the module store its non-volatile context
  103. */
  104. void* LoRaMacConfirmQueueGetNvmCtx( size_t* confirmQueueNvmCtxSize );
  105. /*!
  106. * \brief Adds an element to the confirm queue.
  107. *
  108. * \param [IN] mlmeConfirm - Pointer to the element to add.
  109. *
  110. * \retval [true - operation was successful, false - operation failed]
  111. */
  112. bool LoRaMacConfirmQueueAdd( MlmeConfirmQueue_t* mlmeConfirm );
  113. /*!
  114. * \brief Removes the last element which was added into the queue.
  115. *
  116. * \retval [true - operation was successful, false - operation failed]
  117. */
  118. bool LoRaMacConfirmQueueRemoveLast( void );
  119. /*!
  120. * \brief Removes the first element which was added to the confirm queue.
  121. *
  122. * \retval [true - operation was successful, false - operation failed]
  123. */
  124. bool LoRaMacConfirmQueueRemoveFirst( void );
  125. /*!
  126. * \brief Sets the status of an element.
  127. *
  128. * \param [IN] status - The status to set.
  129. *
  130. * \param [IN] request - The related request to set the status.
  131. */
  132. void LoRaMacConfirmQueueSetStatus( LoRaMacEventInfoStatus_t status, Mlme_t request );
  133. /*!
  134. * \brief Gets the status of an element.
  135. *
  136. * \param [IN] request - The request to query the status.
  137. *
  138. * \retval The status of the related MlmeRequest.
  139. */
  140. LoRaMacEventInfoStatus_t LoRaMacConfirmQueueGetStatus( Mlme_t request );
  141. /*!
  142. * \brief Sets a common status for all elements in the queue.
  143. *
  144. * \param [IN] status - The status to set.
  145. */
  146. void LoRaMacConfirmQueueSetStatusCmn( LoRaMacEventInfoStatus_t status );
  147. /*!
  148. * \brief Gets the common status of all elements.
  149. *
  150. * \retval The common status of all elements.
  151. */
  152. LoRaMacEventInfoStatus_t LoRaMacConfirmQueueGetStatusCmn( void );
  153. /*!
  154. * \brief Verifies if a request is in the queue and active.
  155. *
  156. * \param [IN] request - The request to verify.
  157. *
  158. * \retval [true - element is in the queue, false - element is not in the queue].
  159. */
  160. bool LoRaMacConfirmQueueIsCmdActive( Mlme_t request );
  161. /*!
  162. * \brief Handles all callbacks of active requests
  163. *
  164. * \param [IN] mlmeConfirm - Pointer to the generic mlmeConfirm structure.
  165. */
  166. void LoRaMacConfirmQueueHandleCb( MlmeConfirm_t* mlmeConfirm );
  167. /*!
  168. * \brief Query number of elements in the queue.
  169. *
  170. * \retval Number of elements.
  171. */
  172. uint8_t LoRaMacConfirmQueueGetCnt( void );
  173. /*!
  174. * \brief Verify if the confirm queue is full.
  175. *
  176. * \retval [true - queue is full, false - queue is not full].
  177. */
  178. bool LoRaMacConfirmQueueIsFull( void );
  179. #ifdef __cplusplus
  180. }
  181. #endif
  182. #endif // __LORAMAC_CONFIRMQUEUE_H__