Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

175 lines
4.7 KiB

  1. /**
  2. * \file
  3. *
  4. * \brief List declaration.
  5. *
  6. * Copyright (C) 2014 Atmel Corporation. All rights reserved.
  7. *
  8. * \asf_license_start
  9. *
  10. * \page License
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. *
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. *
  18. * 2. Redistributions in binary form must reproduce the above copyright notice,
  19. * this list of conditions and the following disclaimer in the documentation
  20. * and/or other materials provided with the distribution.
  21. *
  22. * 3. The name of Atmel may not be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * 4. This software may only be redistributed and used in connection with an
  26. * Atmel microcontroller product.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  29. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  30. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  31. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  32. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  33. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  34. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  36. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  37. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38. * POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. * \asf_license_stop
  41. *
  42. */
  43. #ifndef _UTILS_LIST_H_INCLUDED
  44. #define _UTILS_LIST_H_INCLUDED
  45. #ifdef __cplusplus
  46. extern "C" {
  47. #endif
  48. /**
  49. * \addtogroup doc_driver_hal_utils_list
  50. *
  51. * @{
  52. */
  53. #include <compiler.h>
  54. /**
  55. * \brief List element type
  56. */
  57. struct list_element {
  58. struct list_element *next;
  59. };
  60. /**
  61. * \brief List head type
  62. */
  63. struct list_descriptor {
  64. struct list_element *head;
  65. };
  66. /**
  67. * \brief Reset list
  68. *
  69. * \param[in] list The pointer to a list descriptor
  70. */
  71. static inline void list_reset(struct list_descriptor *const list)
  72. {
  73. list->head = NULL;
  74. }
  75. /**
  76. * \brief Retrieve list head
  77. *
  78. * \param[in] list The pointer to a list descriptor
  79. *
  80. * \return A pointer to the head of the given list or NULL if the list is
  81. * empty
  82. */
  83. static inline void *list_get_head(const struct list_descriptor *const list)
  84. {
  85. return (void *)list->head;
  86. }
  87. /**
  88. * \brief Retrieve next list head
  89. *
  90. * \param[in] list The pointer to a list element
  91. *
  92. * \return A pointer to the next list element or NULL if there is not next
  93. * element
  94. */
  95. static inline void *list_get_next_element(const void *const element)
  96. {
  97. return element ? ((struct list_element *)element)->next : NULL;
  98. }
  99. /**
  100. * \brief Insert an element as list head
  101. *
  102. * \param[in] list The pointer to a list element
  103. * \param[in] element An element to insert to the given list
  104. */
  105. void list_insert_as_head(struct list_descriptor *const list, void *const element);
  106. /**
  107. * \brief Insert an element after the given list element
  108. *
  109. * \param[in] after An element to insert after
  110. * \param[in] element Element to insert to the given list
  111. */
  112. void list_insert_after(void *const after, void *const element);
  113. /**
  114. * \brief Insert an element at list end
  115. *
  116. * \param[in] after An element to insert after
  117. * \param[in] element Element to insert to the given list
  118. */
  119. void list_insert_at_end(struct list_descriptor *const list, void *const element);
  120. /**
  121. * \brief Check whether an element belongs to a list
  122. *
  123. * \param[in] list The pointer to a list
  124. * \param[in] element An element to check
  125. *
  126. * \return The result of checking
  127. * \retval true If the given element is an element of the given list
  128. * \retval false Otherwise
  129. */
  130. bool is_list_element(const struct list_descriptor *const list, const void *const element);
  131. /**
  132. * \brief Removes list head
  133. *
  134. * This function removes the list head and sets the next element after the list
  135. * head as a new list head.
  136. *
  137. * \param[in] list The pointer to a list
  138. *
  139. * \return The pointer to the new list head of NULL if the list head is NULL
  140. */
  141. void *list_remove_head(struct list_descriptor *const list);
  142. /**
  143. * \brief Removes the list element
  144. *
  145. * \param[in] list The pointer to a list
  146. * \param[in] element An element to remove
  147. *
  148. * \return The result of element removing
  149. * \retval true The given element is removed from the given list
  150. * \retval false The given element is not an element of the given list
  151. */
  152. bool list_delete_element(struct list_descriptor *const list, const void *const element);
  153. /**@}*/
  154. #ifdef __cplusplus
  155. }
  156. #endif
  157. #endif /* _UTILS_LIST_H_INCLUDED */