chregistry.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio.
  3. This file is part of ChibiOS.
  4. ChibiOS is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. ChibiOS is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. /**
  16. * @file chregistry.h
  17. * @brief Threads registry macros and structures.
  18. *
  19. * @addtogroup registry
  20. * @{
  21. */
  22. #ifndef CHREGISTRY_H
  23. #define CHREGISTRY_H
  24. #if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__)
  25. /*===========================================================================*/
  26. /* Module constants. */
  27. /*===========================================================================*/
  28. /*===========================================================================*/
  29. /* Module pre-compile time settings. */
  30. /*===========================================================================*/
  31. /*===========================================================================*/
  32. /* Derived constants and error checks. */
  33. /*===========================================================================*/
  34. /*===========================================================================*/
  35. /* Module data structures and types. */
  36. /*===========================================================================*/
  37. /**
  38. * @brief ChibiOS/RT memory signature record.
  39. */
  40. typedef struct {
  41. char identifier[4]; /**< @brief Always set to "main". */
  42. uint8_t zero; /**< @brief Must be zero. */
  43. uint8_t size; /**< @brief Size of this structure. */
  44. uint16_t version; /**< @brief Encoded ChibiOS/RT version. */
  45. uint8_t ptrsize; /**< @brief Size of a pointer. */
  46. uint8_t timesize; /**< @brief Size of a @p systime_t. */
  47. uint8_t threadsize; /**< @brief Size of a @p thread_t. */
  48. uint8_t off_prio; /**< @brief Offset of @p prio field. */
  49. uint8_t off_ctx; /**< @brief Offset of @p ctx field. */
  50. uint8_t off_newer; /**< @brief Offset of @p newer field. */
  51. uint8_t off_older; /**< @brief Offset of @p older field. */
  52. uint8_t off_name; /**< @brief Offset of @p name field. */
  53. uint8_t off_stklimit; /**< @brief Offset of @p stklimit field.*/
  54. uint8_t off_state; /**< @brief Offset of @p state field. */
  55. uint8_t off_flags; /**< @brief Offset of @p flags field. */
  56. uint8_t off_refs; /**< @brief Offset of @p refs field. */
  57. uint8_t off_preempt; /**< @brief Offset of @p preempt field. */
  58. uint8_t off_time; /**< @brief Offset of @p time field. */
  59. } chdebug_t;
  60. /*===========================================================================*/
  61. /* Module macros. */
  62. /*===========================================================================*/
  63. /**
  64. * @brief Removes a thread from the registry list.
  65. * @note This macro is not meant for use in application code.
  66. *
  67. * @param[in] tp thread to remove from the registry
  68. */
  69. #define REG_REMOVE(tp) { \
  70. (tp)->older->newer = (tp)->newer; \
  71. (tp)->newer->older = (tp)->older; \
  72. }
  73. /**
  74. * @brief Adds a thread to the registry list.
  75. * @note This macro is not meant for use in application code.
  76. *
  77. * @param[in] tp thread to add to the registry
  78. */
  79. #define REG_INSERT(tp) { \
  80. (tp)->newer = (thread_t *)&ch.rlist; \
  81. (tp)->older = ch.rlist.older; \
  82. (tp)->older->newer = (tp); \
  83. ch.rlist.older = (tp); \
  84. }
  85. /*===========================================================================*/
  86. /* External declarations. */
  87. /*===========================================================================*/
  88. #ifdef __cplusplus
  89. extern "C" {
  90. #endif
  91. extern ROMCONST chdebug_t ch_debug;
  92. thread_t *chRegFirstThread(void);
  93. thread_t *chRegNextThread(thread_t *tp);
  94. thread_t *chRegFindThreadByName(const char *name);
  95. thread_t *chRegFindThreadByPointer(thread_t *tp);
  96. thread_t *chRegFindThreadByWorkingArea(stkalign_t *wa);
  97. #ifdef __cplusplus
  98. }
  99. #endif
  100. #endif /* CH_CFG_USE_REGISTRY == TRUE */
  101. /*===========================================================================*/
  102. /* Module inline functions. */
  103. /*===========================================================================*/
  104. /**
  105. * @brief Sets the current thread name.
  106. * @pre This function only stores the pointer to the name if the option
  107. * @p CH_CFG_USE_REGISTRY is enabled else no action is performed.
  108. *
  109. * @param[in] name thread name as a zero terminated string
  110. *
  111. * @api
  112. */
  113. static inline void chRegSetThreadName(const char *name) {
  114. #if CH_CFG_USE_REGISTRY == TRUE
  115. ch.rlist.current->name = name;
  116. #else
  117. (void)name;
  118. #endif
  119. }
  120. /**
  121. * @brief Returns the name of the specified thread.
  122. * @pre This function only returns the pointer to the name if the option
  123. * @p CH_CFG_USE_REGISTRY is enabled else @p NULL is returned.
  124. *
  125. * @param[in] tp pointer to the thread
  126. *
  127. * @return Thread name as a zero terminated string.
  128. * @retval NULL if the thread name has not been set.
  129. *
  130. */
  131. static inline const char *chRegGetThreadNameX(thread_t *tp) {
  132. #if CH_CFG_USE_REGISTRY == TRUE
  133. return tp->name;
  134. #else
  135. (void)tp;
  136. return NULL;
  137. #endif
  138. }
  139. /**
  140. * @brief Changes the name of the specified thread.
  141. * @pre This function only stores the pointer to the name if the option
  142. * @p CH_CFG_USE_REGISTRY is enabled else no action is performed.
  143. *
  144. * @param[in] tp pointer to the thread
  145. * @param[in] name thread name as a zero terminated string
  146. *
  147. * @xclass
  148. */
  149. static inline void chRegSetThreadNameX(thread_t *tp, const char *name) {
  150. #if CH_CFG_USE_REGISTRY == TRUE
  151. tp->name = name;
  152. #else
  153. (void)tp;
  154. (void)name;
  155. #endif
  156. }
  157. #endif /* CHREGISTRY_H */
  158. /** @} */