ChibiOS/RT
2.5.1
chregistry.h
Go to the documentation of this file.
00001 /*
00002     ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
00003                  2011,2012 Giovanni Di Sirio.
00004 
00005     This file is part of ChibiOS/RT.
00006 
00007     ChibiOS/RT is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 3 of the License, or
00010     (at your option) any later version.
00011 
00012     ChibiOS/RT is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 /**
00022  * @file    chregistry.h
00023  * @brief   Threads registry macros and structures.
00024  *
00025  * @addtogroup registry
00026  * @{
00027  */
00028 
00029 #ifndef _CHREGISTRY_H_
00030 #define _CHREGISTRY_H_
00031 
00032 #if CH_USE_REGISTRY || defined(__DOXYGEN__)
00033 
00034 /**
00035  * @brief   ChibiOS/RT memory signature record.
00036  */
00037 typedef struct {
00038   char      ch_identifier[4];       /**< @brief Always set to "main".       */
00039   uint8_t   ch_zero;                /**< @brief Must be zero.               */
00040   uint8_t   ch_size;                /**< @brief Size of this structure.     */
00041   uint16_t  ch_version;             /**< @brief Encoded ChibiOS/RT version. */
00042   uint8_t   ch_ptrsize;             /**< @brief Size of a pointer.          */
00043   uint8_t   ch_timesize;            /**< @brief Size of a @p systime_t.     */
00044   uint8_t   ch_threadsize;          /**< @brief Size of a @p Thread struct. */
00045   uint8_t   cf_off_prio;            /**< @brief Offset of @p p_prio field.  */
00046   uint8_t   cf_off_ctx;             /**< @brief Offset of @p p_ctx field.   */
00047   uint8_t   cf_off_newer;           /**< @brief Offset of @p p_newer field. */
00048   uint8_t   cf_off_older;           /**< @brief Offset of @p p_older field. */
00049   uint8_t   cf_off_name;            /**< @brief Offset of @p p_name field.  */
00050   uint8_t   cf_off_stklimit;        /**< @brief Offset of @p p_stklimit
00051                                                 field.                      */
00052   uint8_t   cf_off_state;           /**< @brief Offset of @p p_state field. */
00053   uint8_t   cf_off_flags;           /**< @brief Offset of @p p_flags field. */
00054   uint8_t   cf_off_refs;            /**< @brief Offset of @p p_refs field.  */
00055   uint8_t   cf_off_preempt;         /**< @brief Offset of @p p_preempt
00056                                                 field.                      */
00057   uint8_t   cf_off_time;            /**< @brief Offset of @p p_time field.  */
00058 } chdebug_t;
00059 
00060 /**
00061  * @name    Macro Functions
00062  * @{
00063  */
00064 /**
00065  * @brief   Sets the current thread name.
00066  * @pre     This function only stores the pointer to the name if the option
00067  *          @p CH_USE_REGISTRY is enabled else no action is performed.
00068  *
00069  * @param[in] p         thread name as a zero terminated string
00070  *
00071  * @api
00072  */
00073 #define chRegSetThreadName(p) (currp->p_name = (p))
00074 
00075 /**
00076  * @brief   Returns the name of the specified thread.
00077  * @pre     This function only returns the pointer to the name if the option
00078  *          @p CH_USE_REGISTRY is enabled else @p NULL is returned.
00079  *
00080  * @param[in] tp        pointer to the thread
00081  *
00082  * @return              Thread name as a zero terminated string.
00083  * @retval NULL         if the thread name has not been set.
00084  */
00085 #define chRegGetThreadName(tp) ((tp)->p_name)
00086 /** @} */
00087 #else /* !CH_USE_REGISTRY */
00088 #define chRegSetThreadName(p)
00089 #define chRegGetThreadName(tp) NULL
00090 #endif /* !CH_USE_REGISTRY */
00091 
00092 #if CH_USE_REGISTRY || defined(__DOXYGEN__)
00093 /**
00094  * @brief   Removes a thread from the registry list.
00095  * @note    This macro is not meant for use in application code.
00096  *
00097  * @param[in] tp        thread to remove from the registry
00098  */
00099 #define REG_REMOVE(tp) {                                                    \
00100   (tp)->p_older->p_newer = (tp)->p_newer;                                   \
00101   (tp)->p_newer->p_older = (tp)->p_older;                                   \
00102 }
00103 
00104 /**
00105  * @brief   Adds a thread to the registry list.
00106  * @note    This macro is not meant for use in application code.
00107  *
00108  * @param[in] tp        thread to add to the registry
00109  */
00110 #define REG_INSERT(tp) {                                                    \
00111   (tp)->p_newer = (Thread *)&rlist;                                         \
00112   (tp)->p_older = rlist.r_older;                                            \
00113   (tp)->p_older->p_newer = rlist.r_older = (tp);                            \
00114 }
00115 
00116 #ifdef __cplusplus
00117 extern "C" {
00118 #endif
00119   extern ROMCONST chdebug_t ch_debug;
00120   Thread *chRegFirstThread(void);
00121   Thread *chRegNextThread(Thread *tp);
00122 #ifdef __cplusplus
00123 }
00124 #endif
00125 
00126 #endif /* CH_USE_REGISTRY */
00127 
00128 #endif /* _CHREGISTRY_H_ */
00129 
00130 /** @} */