From cf204e72ea5fd6e4be8b3295cb148fde5fdd47d2 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Tue, 16 Feb 2016 10:07:00 +0000 Subject: Tree reorganization. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8900 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/rt/include/ch.h | 17 ++- os/rt/include/chalign.h | 114 +++++++++++++++++ os/rt/include/chbsem.h | 311 --------------------------------------------- os/rt/include/chcond.h | 4 +- os/rt/include/chdebug.h | 191 +++++++++++++++++++++++----- os/rt/include/chdynamic.h | 96 -------------- os/rt/include/chevents.h | 16 +-- os/rt/include/chheap.h | 118 ----------------- os/rt/include/chlicense.h | 7 +- os/rt/include/chmboxes.h | 207 ------------------------------ os/rt/include/chmemcore.h | 111 ---------------- os/rt/include/chmempools.h | 168 ------------------------ os/rt/include/chmsg.h | 6 +- os/rt/include/chmtx.h | 16 +-- os/rt/include/chqueues.h | 26 ++-- os/rt/include/chregistry.h | 56 ++++---- os/rt/include/chschd.h | 230 ++++++++++++++++----------------- os/rt/include/chsem.h | 12 +- os/rt/include/chsys.h | 34 ++++- os/rt/include/chthreads.h | 83 +++++++++--- os/rt/include/chvt.h | 60 ++++----- 21 files changed, 585 insertions(+), 1298 deletions(-) create mode 100644 os/rt/include/chalign.h delete mode 100644 os/rt/include/chbsem.h delete mode 100644 os/rt/include/chdynamic.h delete mode 100644 os/rt/include/chheap.h delete mode 100644 os/rt/include/chmboxes.h delete mode 100644 os/rt/include/chmemcore.h delete mode 100644 os/rt/include/chmempools.h (limited to 'os/rt/include') diff --git a/os/rt/include/ch.h b/os/rt/include/ch.h index eb35eb944..73faa8481 100644 --- a/os/rt/include/ch.h +++ b/os/rt/include/ch.h @@ -48,17 +48,17 @@ /** * @brief Kernel version string. */ -#define CH_KERNEL_VERSION "3.2.0" +#define CH_KERNEL_VERSION "4.0.0" /** * @brief Kernel version major number. */ -#define CH_KERNEL_MAJOR 3 +#define CH_KERNEL_MAJOR 4 /** * @brief Kernel version minor number. */ -#define CH_KERNEL_MINOR 2 +#define CH_KERNEL_MINOR 0 /** * @brief Kernel version patch number. @@ -69,8 +69,14 @@ /* Core headers.*/ #include "chtypes.h" #include "chconf.h" + +#if !defined(_CHIBIOS_RT_CONF_) +#error "invalid configuration file" +#endif + #include "chlicense.h" #include "chsystypes.h" +#include "chalign.h" #include "chcore.h" #include "chdebug.h" #include "chtm.h" @@ -92,10 +98,13 @@ #include "chmemcore.h" #include "chheap.h" #include "chmempools.h" -#include "chdynamic.h" #include "chqueues.h" #include "chstreams.h" +#if !defined(_CHIBIOS_RT_CONF_) +#error "missing or wrong configuration file" +#endif + #endif /* _CH_H_ */ /** @} */ diff --git a/os/rt/include/chalign.h b/os/rt/include/chalign.h new file mode 100644 index 000000000..198e50da3 --- /dev/null +++ b/os/rt/include/chalign.h @@ -0,0 +1,114 @@ +/* + ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio. + + This file is part of ChibiOS. + + ChibiOS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file chmem.h + * @brief Memory alignment macros and structures. + * + * @addtogroup mem + * @{ + */ + +#ifndef _CHALIGN_H_ +#define _CHALIGN_H_ + +/*===========================================================================*/ +/* Module constants. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module pre-compile time settings. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module data structures and types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module macros. */ +/*===========================================================================*/ + +/** + * @name Memory alignment support macros + */ +/** + * @brief Alignment mask constant. + * + * @param[in] a alignment, must be a power of two + */ +#define MEM_ALIGN_MASK(a) ((size_t)(a) - 1U) + +/** + * @brief Aligns to the previous aligned memory address. + * + * @param[in] p variable to be aligned + * @param[in] a alignment, must be a power of two + */ +#define MEM_ALIGN_PREV(p, a) ((size_t)(p) & ~MEM_ALIGN_MASK(a)) + +/** + * @brief Aligns to the new aligned memory address. + * + * @param[in] p variable to be aligned + * @param[in] a alignment, must be a power of two + */ +#define MEM_ALIGN_NEXT(p, a) MEM_ALIGN_PREV((size_t)(p) + \ + MEM_ALIGN_MASK(a), (a)) + +/** + * @brief Returns whatever a pointer or memory size is aligned. + * + * @param[in] p variable to be aligned + * @param[in] a alignment, must be a power of two + */ +#define MEM_IS_ALIGNED(p, a) (((size_t)(p) & MEM_ALIGN_MASK(a)) == 0U) + +/** + * @brief Returns whatever a constant is a valid alignment. + * @details Valid alignments are powers of two. + * + * @param[in] a alignment to be checked, must be a constant + */ +#define MEM_IS_VALID_ALIGNMENT(a) \ + (((size_t)(a) != 0U) && (((size_t)(a) & ((size_t)(a) - 1U)) == 0U)) +/** @} */ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +/*===========================================================================*/ +/* Module inline functions. */ +/*===========================================================================*/ + +#endif /* _CHALIGN_H_ */ + +/** @} */ diff --git a/os/rt/include/chbsem.h b/os/rt/include/chbsem.h deleted file mode 100644 index b25983118..000000000 --- a/os/rt/include/chbsem.h +++ /dev/null @@ -1,311 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio. - - This file is part of ChibiOS. - - ChibiOS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file chbsem.h - * @brief Binary semaphores structures and macros. - * - * @addtogroup binary_semaphores - * @details Binary semaphores related APIs and services. - *

Operation mode

- * Binary semaphores are implemented as a set of inline functions - * that use the existing counting semaphores primitives. The - * difference between counting and binary semaphores is that the - * counter of binary semaphores is not allowed to grow above the - * value 1. Repeated signal operation are ignored. A binary - * semaphore can thus have only two defined states: - * - Taken, when its counter has a value of zero or lower - * than zero. A negative number represent the number of threads - * queued on the binary semaphore. - * - Not taken, when its counter has a value of one. - * . - * Binary semaphores are different from mutexes because there is no - * concept of ownership, a binary semaphore can be taken by a - * thread and signaled by another thread or an interrupt handler, - * mutexes can only be taken and released by the same thread. Another - * difference is that binary semaphores, unlike mutexes, do not - * implement the priority inheritance protocol.
- * In order to use the binary semaphores APIs the - * @p CH_CFG_USE_SEMAPHORES option must be enabled in @p chconf.h. - * @{ - */ - -#ifndef _CHBSEM_H_ -#define _CHBSEM_H_ - -#if (CH_CFG_USE_SEMAPHORES == TRUE) || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Module constants. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module pre-compile time settings. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Derived constants and error checks. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module data structures and types. */ -/*===========================================================================*/ - -/** - * @extends semaphore_t - * - * @brief Binary semaphore type. - */ -typedef struct { - semaphore_t bs_sem; -} binary_semaphore_t; - -/*===========================================================================*/ -/* Module macros. */ -/*===========================================================================*/ - -/** - * @brief Data part of a static semaphore initializer. - * @details This macro should be used when statically initializing a semaphore - * that is part of a bigger structure. - * - * @param[in] name the name of the semaphore variable - * @param[in] taken the semaphore initial state - */ -#define _BSEMAPHORE_DATA(name, taken) \ - {_SEMAPHORE_DATA(name.bs_sem, ((taken) ? 0 : 1))} - -/** - * @brief Static semaphore initializer. - * @details Statically initialized semaphores require no explicit - * initialization using @p chBSemInit(). - * - * @param[in] name the name of the semaphore variable - * @param[in] taken the semaphore initial state - */ -#define BSEMAPHORE_DECL(name, taken) \ - binary_semaphore_t name = _BSEMAPHORE_DATA(name, taken) - -/*===========================================================================*/ -/* External declarations. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module inline functions. */ -/*===========================================================================*/ - -/** - * @brief Initializes a binary semaphore. - * - * @param[out] bsp pointer to a @p binary_semaphore_t structure - * @param[in] taken initial state of the binary semaphore: - * - @a false, the initial state is not taken. - * - @a true, the initial state is taken. - * . - * - * @init - */ -static inline void chBSemObjectInit(binary_semaphore_t *bsp, bool taken) { - - chSemObjectInit(&bsp->bs_sem, taken ? (cnt_t)0 : (cnt_t)1); -} - -/** - * @brief Wait operation on the binary semaphore. - * - * @param[in] bsp pointer to a @p binary_semaphore_t structure - * @return A message specifying how the invoking thread has been - * released from the semaphore. - * @retval MSG_OK if the binary semaphore has been successfully taken. - * @retval MSG_RESET if the binary semaphore has been reset using - * @p bsemReset(). - * - * @api - */ -static inline msg_t chBSemWait(binary_semaphore_t *bsp) { - - return chSemWait(&bsp->bs_sem); -} - -/** - * @brief Wait operation on the binary semaphore. - * - * @param[in] bsp pointer to a @p binary_semaphore_t structure - * @return A message specifying how the invoking thread has been - * released from the semaphore. - * @retval MSG_OK if the binary semaphore has been successfully taken. - * @retval MSG_RESET if the binary semaphore has been reset using - * @p bsemReset(). - * - * @sclass - */ -static inline msg_t chBSemWaitS(binary_semaphore_t *bsp) { - - chDbgCheckClassS(); - - return chSemWaitS(&bsp->bs_sem); -} - -/** - * @brief Wait operation on the binary semaphore. - * - * @param[in] bsp pointer to a @p binary_semaphore_t structure - * @param[in] time the number of ticks before the operation timeouts, - * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. - * - @a TIME_INFINITE no timeout. - * . - * @return A message specifying how the invoking thread has been - * released from the semaphore. - * @retval MSG_OK if the binary semaphore has been successfully taken. - * @retval MSG_RESET if the binary semaphore has been reset using - * @p bsemReset(). - * @retval MSG_TIMEOUT if the binary semaphore has not been signaled or reset - * within the specified timeout. - * - * @sclass - */ -static inline msg_t chBSemWaitTimeoutS(binary_semaphore_t *bsp, - systime_t time) { - - chDbgCheckClassS(); - - return chSemWaitTimeoutS(&bsp->bs_sem, time); -} - -/** - * @brief Wait operation on the binary semaphore. - * - * @param[in] bsp pointer to a @p binary_semaphore_t structure - * @param[in] time the number of ticks before the operation timeouts, - * the following special values are allowed: - * - @a TIME_IMMEDIATE immediate timeout. - * - @a TIME_INFINITE no timeout. - * . - * @return A message specifying how the invoking thread has been - * released from the semaphore. - * @retval MSG_OK if the binary semaphore has been successfully taken. - * @retval MSG_RESET if the binary semaphore has been reset using - * @p bsemReset(). - * @retval MSG_TIMEOUT if the binary semaphore has not been signaled or reset - * within the specified timeout. - * - * @api - */ -static inline msg_t chBSemWaitTimeout(binary_semaphore_t *bsp, - systime_t time) { - - return chSemWaitTimeout(&bsp->bs_sem, time); -} - -/** - * @brief Reset operation on the binary semaphore. - * @note The released threads can recognize they were waked up by a reset - * rather than a signal because the @p bsemWait() will return - * @p MSG_RESET instead of @p MSG_OK. - * @note This function does not reschedule. - * - * @param[in] bsp pointer to a @p binary_semaphore_t structure - * @param[in] taken new state of the binary semaphore - * - @a false, the new state is not taken. - * - @a true, the new state is taken. - * . - * - * @iclass - */ -static inline void chBSemResetI(binary_semaphore_t *bsp, bool taken) { - - chDbgCheckClassI(); - - chSemResetI(&bsp->bs_sem, taken ? (cnt_t)0 : (cnt_t)1); -} - -/** - * @brief Reset operation on the binary semaphore. - * @note The released threads can recognize they were waked up by a reset - * rather than a signal because the @p bsemWait() will return - * @p MSG_RESET instead of @p MSG_OK. - * - * @param[in] bsp pointer to a @p binary_semaphore_t structure - * @param[in] taken new state of the binary semaphore - * - @a false, the new state is not taken. - * - @a true, the new state is taken. - * . - * - * @api - */ -static inline void chBSemReset(binary_semaphore_t *bsp, bool taken) { - - chSemReset(&bsp->bs_sem, taken ? (cnt_t)0 : (cnt_t)1); -} - -/** - * @brief Performs a signal operation on a binary semaphore. - * @note This function does not reschedule. - * - * @param[in] bsp pointer to a @p binary_semaphore_t structure - * - * @iclass - */ -static inline void chBSemSignalI(binary_semaphore_t *bsp) { - - chDbgCheckClassI(); - - if (bsp->bs_sem.s_cnt < (cnt_t)1) { - chSemSignalI(&bsp->bs_sem); - } -} - -/** - * @brief Performs a signal operation on a binary semaphore. - * - * @param[in] bsp pointer to a @p binary_semaphore_t structure - * - * @api - */ -static inline void chBSemSignal(binary_semaphore_t *bsp) { - - chSysLock(); - chBSemSignalI(bsp); - chSchRescheduleS(); - chSysUnlock(); -} - -/** - * @brief Returns the binary semaphore current state. - * - * @param[in] bsp pointer to a @p binary_semaphore_t structure - * @return The binary semaphore current state. - * @retval false if the binary semaphore is not taken. - * @retval true if the binary semaphore is taken. - * - * @iclass - */ -static inline bool chBSemGetStateI(binary_semaphore_t *bsp) { - - chDbgCheckClassI(); - - return (bsp->bs_sem.s_cnt > (cnt_t)0) ? false : true; -} - -#endif /* CH_CFG_USE_SEMAPHORES == TRUE */ - -#endif /* _CHBSEM_H_ */ - -/** @} */ diff --git a/os/rt/include/chcond.h b/os/rt/include/chcond.h index e8620e9c5..57b1f73f0 100644 --- a/os/rt/include/chcond.h +++ b/os/rt/include/chcond.h @@ -57,7 +57,7 @@ * @brief condition_variable_t structure. */ typedef struct condition_variable { - threads_queue_t c_queue; /**< @brief Condition variable + threads_queue_t queue; /**< @brief Condition variable threads queue. */ } condition_variable_t; @@ -72,7 +72,7 @@ typedef struct condition_variable { * * @param[in] name the name of the condition variable */ -#define _CONDVAR_DATA(name) {_THREADS_QUEUE_DATA(name.c_queue)} +#define _CONDVAR_DATA(name) {_THREADS_QUEUE_DATA(name.queue)} /** * @brief Static condition variable initializer. diff --git a/os/rt/include/chdebug.h b/os/rt/include/chdebug.h index 593a25c88..9436ce30c 100644 --- a/os/rt/include/chdebug.h +++ b/os/rt/include/chdebug.h @@ -32,6 +32,51 @@ /* Module constants. */ /*===========================================================================*/ +/** + * @name Trace record types + * @{ + */ +#define CH_TRACE_TYPE_UNUSED 0U +#define CH_TRACE_TYPE_SWITCH 1U +#define CH_TRACE_TYPE_ISR_ENTER 2U +#define CH_TRACE_TYPE_ISR_LEAVE 3U +#define CH_TRACE_TYPE_HALT 4U +#define CH_TRACE_TYPE_USER 5U +/** @} */ + +/** + * @name Trace suspend masks + * @{ + */ +#define CH_TRACE_SUSPEND_NONE 0U +#define CH_TRACE_SUSPEND_SWITCH (1U << CH_TRACE_TYPE_SWITCH) +#define CH_TRACE_SUSPEND_ISR_ENTER (1U << CH_TRACE_TYPE_ISR_ENTER) +#define CH_TRACE_SUSPEND_ISR_LEAVE (1U << CH_TRACE_TYPE_ISR_LEAVE) +#define CH_TRACE_SUSPEND_HALT (1U << CH_TRACE_TYPE_HALT) +#define CH_TRACE_SUSPEND_USER (1U << CH_TRACE_TYPE_USER) +#define CH_TRACE_SUSPEND_ALL (CH_TRACE_SUSPEND_SWITCH | \ + CH_TRACE_SUSPEND_ISR_ENTER | \ + CH_TRACE_SUSPEND_ISR_LEAVE | \ + CH_TRACE_SUSPEND_HALT | \ + CH_TRACE_SUSPEND_USER) + +/** @} */ + +/** + * @name Events to trace + * @{ + */ +#define CH_DBG_TRACE_MASK_NONE 0U +#define CH_DBG_TRACE_MASK_SWITCH 1U +#define CH_DBG_TRACE_MASK_ISR 2U +#define CH_DBG_TRACE_MASK_HALT 4U +#define CH_DBG_TRACE_MASK_USER 8U +#define CH_DBG_TRACE_MASK_ALL (CH_DBG_TRACE_MASK_SWITCH | \ + CH_DBG_TRACE_MASK_ISR | \ + CH_DBG_TRACE_MASK_HALT | \ + CH_DBG_TRACE_MASK_USER) +/** @} */ + /*===========================================================================*/ /* Module pre-compile time settings. */ /*===========================================================================*/ @@ -43,26 +88,24 @@ /** * @brief Trace buffer entries. */ -#if !defined(CH_DBG_TRACE_BUFFER_SIZE) || defined(__DOXYGEN__) -#define CH_DBG_TRACE_BUFFER_SIZE 64 +#if !defined(CH_DBG_TRACE_MASK) || defined(__DOXYGEN__) +#define CH_DBG_TRACE_MASK CH_DBG_TRACE_MASK_ALL #endif /** - * @brief Fill value for thread stack area in debug mode. + * @brief Trace buffer entries. + * @note The trace buffer is only allocated if @p CH_DBG_TRACE_MASK is + * different from @p CH_DBG_TRACE_MASK_NONE. */ -#if !defined(CH_DBG_STACK_FILL_VALUE) || defined(__DOXYGEN__) -#define CH_DBG_STACK_FILL_VALUE 0x55 +#if !defined(CH_DBG_TRACE_BUFFER_SIZE) || defined(__DOXYGEN__) +#define CH_DBG_TRACE_BUFFER_SIZE 128 #endif /** - * @brief Fill value for thread area in debug mode. - * @note The chosen default value is 0xFF in order to make evident which - * thread fields were not initialized when inspecting the memory with - * a debugger. A uninitialized field is not an error in itself but it - * better to know it. + * @brief Fill value for thread stack area in debug mode. */ -#if !defined(CH_DBG_THREAD_FILL_VALUE) || defined(__DOXYGEN__) -#define CH_DBG_THREAD_FILL_VALUE 0xFF +#if !defined(CH_DBG_STACK_FILL_VALUE) || defined(__DOXYGEN__) +#define CH_DBG_STACK_FILL_VALUE 0x55 #endif /** @} */ @@ -70,51 +113,107 @@ /* Derived constants and error checks. */ /*===========================================================================*/ +#if !defined(CH_CFG_TRACE_HOOK) +#error "CH_CFG_TRACE_HOOK not defined in chconf.h" +#endif + /*===========================================================================*/ /* Module data structures and types. */ /*===========================================================================*/ -#if (CH_DBG_ENABLE_TRACE == TRUE) || defined(__DOXYGEN__) +#if (CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_NONE) || defined(__DOXYGEN__) /** * @brief Trace buffer record. */ typedef struct { /** - * @brief Time of the switch event. + * @brief Record type. */ - systime_t se_time; + uint32_t type:3; /** - * @brief Switched in thread. + * @brief Switched out thread state. */ - thread_t *se_tp; + uint32_t state:5; /** - * @brief Object where going to sleep. + * @brief Accurate time stamp. + * @note This field only available if the post supports + * @p PORT_SUPPORTS_RT else it is set to zero. */ - void *se_wtobjp; + uint32_t rtstamp:24; /** - * @brief Switched out thread state. + * @brief System time stamp of the switch event. */ - uint8_t se_state; -} ch_swc_event_t; + systime_t time; + union { + /** + * @brief Structure representing a context switch. + */ + struct { + /** + * @brief Switched in thread. + */ + thread_t *ntp; + /** + * @brief Object where going to sleep. + */ + void *wtobjp; + } sw; + /** + * @brief Structure representing an ISR enter. + */ + struct { + /** + * @brief ISR function name taken using @p __func__. + */ + const char *name; + } isr; + /** + * @brief Structure representing an halt. + */ + struct { + /** + * @brief Halt error string. + */ + const char *reason; + } halt; + /** + * @brief User trace structure. + */ + struct { + /** + * @brief Trace user parameter 1. + */ + void *up1; + /** + * @brief Trace user parameter 2. + */ + void *up2; + } user; + } u; +} ch_trace_event_t; /** * @brief Trace buffer header. */ typedef struct { + /** + * @brief Suspended trace sources mask. + */ + uint16_t suspended; /** * @brief Trace buffer size (entries). */ - unsigned tb_size; + uint16_t size; /** * @brief Pointer to the buffer front. */ - ch_swc_event_t *tb_ptr; + ch_trace_event_t *ptr; /** * @brief Ring buffer. */ - ch_swc_event_t tb_buffer[CH_DBG_TRACE_BUFFER_SIZE]; + ch_trace_event_t buffer[CH_DBG_TRACE_BUFFER_SIZE]; } ch_trace_buffer_t; -#endif /* CH_DBG_ENABLE_TRACE */ +#endif /* CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_NONE */ /*===========================================================================*/ /* Module macros. */ @@ -143,10 +242,21 @@ typedef struct { #define chDbgCheckClassS() #endif -/* When the trace feature is disabled this function is replaced by an empty - macro.*/ -#if CH_DBG_ENABLE_TRACE == FALSE -#define _dbg_trace(otp) +/* When a trace feature is disabled the associated functions are replaced by + an empty macro.*/ +#if (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_SWITCH) == 0 +#define _dbg_trace_switch(otp) +#endif +#if (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_ISR) == 0 +#define _dbg_trace_isr_enter(isr) +#define _dbg_trace_isr_leave(isr) +#endif +#if (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_HALT) == 0 +#define _dbg_trace_halt(reason) +#endif +#if (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_USER) == 0 +#define chDbgWriteTraceI(up1, up2) +#define chDbgWriteTrace(up1, up2) #endif /** @@ -222,10 +332,27 @@ extern "C" { void chDbgCheckClassI(void); void chDbgCheckClassS(void); #endif -#if (CH_DBG_ENABLE_TRACE == TRUE) || defined(__DOXYGEN__) +#if (CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_NONE) || defined(__DOXYGEN__) void _dbg_trace_init(void); - void _dbg_trace(thread_t *otp); +#if (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_SWITCH) != 0 + void _dbg_trace_switch(thread_t *otp); +#endif +#if (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_ISR) != 0 + void _dbg_trace_isr_enter(const char *isr); + void _dbg_trace_isr_leave(const char *isr); +#endif +#if (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_HALT) != 0 + void _dbg_trace_halt(const char *reason); +#endif +#if (CH_DBG_TRACE_MASK & CH_DBG_TRACE_MASK_USER) != 0 + void chDbgWriteTraceI(void *up1, void *up2); + void chDbgWriteTrace(void *up1, void *up2); + void chDbgSuspendTraceI(uint16_t mask); + void chDbgSuspendTrace(uint16_t mask); + void chDbgResumeTraceI(uint16_t mask); + void chDbgResumeTrace(uint16_t mask); #endif +#endif /* CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_NONE */ #ifdef __cplusplus } #endif diff --git a/os/rt/include/chdynamic.h b/os/rt/include/chdynamic.h deleted file mode 100644 index 66f3232c0..000000000 --- a/os/rt/include/chdynamic.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio. - - This file is part of ChibiOS. - - ChibiOS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file chdynamic.h - * @brief Dynamic threads macros and structures. - * - * @addtogroup dynamic_threads - * @{ - */ - -#ifndef _CHDYNAMIC_H_ -#define _CHDYNAMIC_H_ - -#if (CH_CFG_USE_DYNAMIC == TRUE) || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Module constants. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module pre-compile time settings. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Derived constants and error checks. */ -/*===========================================================================*/ - -/* - * Module dependencies check. - */ -#if CH_CFG_USE_WAITEXIT == FALSE -#error "CH_CFG_USE_DYNAMIC requires CH_CFG_USE_WAITEXIT" -#endif - -#if (CH_CFG_USE_HEAP == FALSE) && (CH_CFG_USE_MEMPOOLS == FALSE) -#error "CH_CFG_USE_DYNAMIC requires CH_CFG_USE_HEAP and/or CH_CFG_USE_MEMPOOLS" -#endif - -/*===========================================================================*/ -/* Module data structures and types. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module macros. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* External declarations. */ -/*===========================================================================*/ - -/* - * Dynamic threads APIs. - */ -#ifdef __cplusplus -extern "C" { -#endif - thread_t *chThdAddRef(thread_t *tp); - void chThdRelease(thread_t *tp); -#if CH_CFG_USE_HEAP == TRUE - thread_t *chThdCreateFromHeap(memory_heap_t *heapp, size_t size, - tprio_t prio, tfunc_t pf, void *arg); -#endif -#if CH_CFG_USE_MEMPOOLS == TRUE - thread_t *chThdCreateFromMemoryPool(memory_pool_t *mp, tprio_t prio, - tfunc_t pf, void *arg); -#endif -#ifdef __cplusplus -} -#endif - -/*===========================================================================*/ -/* Module inline functions. */ -/*===========================================================================*/ - -#endif /* CH_CFG_USE_DYNAMIC == TRUE */ - -#endif /* _CHDYNAMIC_H_ */ - -/** @} */ diff --git a/os/rt/include/chevents.h b/os/rt/include/chevents.h index 8ac91d256..1ff0871c7 100644 --- a/os/rt/include/chevents.h +++ b/os/rt/include/chevents.h @@ -55,16 +55,16 @@ typedef struct event_listener event_listener_t; * @brief Event Listener structure. */ struct event_listener { - event_listener_t *el_next; /**< @brief Next Event Listener + event_listener_t *next; /**< @brief Next Event Listener registered on the event source. */ - thread_t *el_listener; /**< @brief Thread interested in the + thread_t *listener; /**< @brief Thread interested in the event source. */ - eventmask_t el_events; /**< @brief Events to be set in + eventmask_t events; /**< @brief Events to be set in the listening thread. */ - eventflags_t el_flags; /**< @brief Flags added to the listener + eventflags_t flags; /**< @brief Flags added to the listener by the event source. */ - eventflags_t el_wflags; /**< @brief Flags that this listener + eventflags_t wflags; /**< @brief Flags that this listener interested in. */ }; @@ -72,7 +72,7 @@ struct event_listener { * @brief Event Source structure. */ typedef struct event_source { - event_listener_t *es_next; /**< @brief First Event Listener + event_listener_t *next; /**< @brief First Event Listener registered on the Event Source. */ } event_source_t; @@ -169,7 +169,7 @@ extern "C" { */ static inline void chEvtObjectInit(event_source_t *esp) { - esp->es_next = (event_listener_t *)esp; + esp->next = (event_listener_t *)esp; } /** @@ -223,7 +223,7 @@ static inline void chEvtRegister(event_source_t *esp, */ static inline bool chEvtIsListeningI(event_source_t *esp) { - return (bool)(esp != (event_source_t *)esp->es_next); + return (bool)(esp != (event_source_t *)esp->next); } /** diff --git a/os/rt/include/chheap.h b/os/rt/include/chheap.h deleted file mode 100644 index b041646b5..000000000 --- a/os/rt/include/chheap.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio. - - This file is part of ChibiOS. - - ChibiOS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file chheap.h - * @brief Heaps macros and structures. - * - * @addtogroup heaps - * @{ - */ - -#ifndef _CHHEAP_H_ -#define _CHHEAP_H_ - -#if (CH_CFG_USE_HEAP == TRUE) || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Module constants. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module pre-compile time settings. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Derived constants and error checks. */ -/*===========================================================================*/ - -#if CH_CFG_USE_MEMCORE == FALSE -#error "CH_CFG_USE_HEAP requires CH_CFG_USE_MEMCORE" -#endif - -#if (CH_CFG_USE_MUTEXES == FALSE) && (CH_CFG_USE_SEMAPHORES == FALSE) -#error "CH_CFG_USE_HEAP requires CH_CFG_USE_MUTEXES and/or CH_CFG_USE_SEMAPHORES" -#endif - -/*===========================================================================*/ -/* Module data structures and types. */ -/*===========================================================================*/ - -/** - * @brief Type of a memory heap. - */ -typedef struct memory_heap memory_heap_t; - -/** - * @brief Memory heap block header. - */ -union heap_header { - stkalign_t align; - struct { - union { - union heap_header *next; /**< @brief Next block in free list. */ - memory_heap_t *heap; /**< @brief Block owner heap. */ - } u; /**< @brief Overlapped fields. */ - size_t size; /**< @brief Size of the memory block. */ - } h; -}; - -/** - * @brief Structure describing a memory heap. - */ -struct memory_heap { - memgetfunc_t h_provider; /**< @brief Memory blocks provider for - this heap. */ - union heap_header h_free; /**< @brief Free blocks list header. */ -#if CH_CFG_USE_MUTEXES == TRUE - mutex_t h_mtx; /**< @brief Heap access mutex. */ -#else - semaphore_t h_sem; /**< @brief Heap access semaphore. */ -#endif -}; - -/*===========================================================================*/ -/* Module macros. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* External declarations. */ -/*===========================================================================*/ - -#ifdef __cplusplus -extern "C" { -#endif - void _heap_init(void); - void chHeapObjectInit(memory_heap_t *heapp, void *buf, size_t size); - void *chHeapAlloc(memory_heap_t *heapp, size_t size); - void chHeapFree(void *p); - size_t chHeapStatus(memory_heap_t *heapp, size_t *sizep); -#ifdef __cplusplus -} -#endif - -/*===========================================================================*/ -/* Module inline functions. */ -/*===========================================================================*/ - -#endif /* CH_CFG_USE_HEAP == TRUE */ - -#endif /* _CHHEAP_H_ */ - -/** @} */ diff --git a/os/rt/include/chlicense.h b/os/rt/include/chlicense.h index 254e6e930..064ec2412 100644 --- a/os/rt/include/chlicense.h +++ b/os/rt/include/chlicense.h @@ -207,17 +207,14 @@ #error "CH_CFG_USE_TM == TRUE, Time Measurement functionality restricted" #endif - #if CH_CFG_USE_MUTEXES_RECURSIVE == TRUE - #error "CH_CFG_USE_MUTEXES_RECURSIVE == TRUE, Recursive Mutexes functionality restricted" + #if CH_CFG_USE_MUTEXES == TRUE + #error "CH_CFG_USE_MUTEXES == TRUE, Recursive Mutexes functionality restricted" #endif #if CH_CFG_USE_CONDVARS == TRUE #error "CH_CFG_USE_CONDVARS == TRUE, Condition Variables functionality restricted" #endif - #if CH_CFG_USE_DYNAMIC == TRUE - #error "CH_CFG_USE_DYNAMIC == TRUE, Dynamic Threads functionality restricted" - #endif #endif /* CH_LICENSE_FEATURES == CH_FEATURES_BASIC */ #else diff --git a/os/rt/include/chmboxes.h b/os/rt/include/chmboxes.h deleted file mode 100644 index f4a52ae90..000000000 --- a/os/rt/include/chmboxes.h +++ /dev/null @@ -1,207 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio. - - This file is part of ChibiOS. - - ChibiOS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file chmboxes.h - * @brief Mailboxes macros and structures. - * - * @addtogroup mailboxes - * @{ - */ - -#ifndef _CHMBOXES_H_ -#define _CHMBOXES_H_ - -#if (CH_CFG_USE_MAILBOXES == TRUE) || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Module constants. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module pre-compile time settings. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Derived constants and error checks. */ -/*===========================================================================*/ - -#if CH_CFG_USE_SEMAPHORES == FALSE -#error "CH_CFG_USE_MAILBOXES requires CH_CFG_USE_SEMAPHORES" -#endif - -/*===========================================================================*/ -/* Module data structures and types. */ -/*===========================================================================*/ - -/** - * @brief Structure representing a mailbox object. - */ -typedef struct { - msg_t *mb_buffer; /**< @brief Pointer to the mailbox - buffer. */ - msg_t *mb_top; /**< @brief Pointer to the location - after the buffer. */ - msg_t *mb_wrptr; /**< @brief Write pointer. */ - msg_t *mb_rdptr; /**< @brief Read pointer. */ - semaphore_t mb_fullsem; /**< @brief Full counter - @p semaphore_t. */ - semaphore_t mb_emptysem; /**< @brief Empty counter - @p semaphore_t. */ -} mailbox_t; - -/*===========================================================================*/ -/* Module macros. */ -/*===========================================================================*/ - -/** - * @brief Data part of a static mailbox initializer. - * @details This macro should be used when statically initializing a - * mailbox that is part of a bigger structure. - * - * @param[in] name the name of the mailbox variable - * @param[in] buffer pointer to the mailbox buffer area - * @param[in] size size of the mailbox buffer area - */ -#define _MAILBOX_DATA(name, buffer, size) { \ - (msg_t *)(buffer), \ - (msg_t *)(buffer) + size, \ - (msg_t *)(buffer), \ - (msg_t *)(buffer), \ - _SEMAPHORE_DATA(name.mb_fullsem, 0), \ - _SEMAPHORE_DATA(name.mb_emptysem, size), \ -} - -/** - * @brief Static mailbox initializer. - * @details Statically initialized mailboxes require no explicit - * initialization using @p chMBInit(). - * - * @param[in] name the name of the mailbox variable - * @param[in] buffer pointer to the mailbox buffer area - * @param[in] size size of the mailbox buffer area - */ -#define MAILBOX_DECL(name, buffer, size) \ - mailbox_t name = _MAILBOX_DATA(name, buffer, size) - -/*===========================================================================*/ -/* External declarations. */ -/*===========================================================================*/ - -#ifdef __cplusplus -extern "C" { -#endif - void chMBObjectInit(mailbox_t *mbp, msg_t *buf, cnt_t n); - void chMBReset(mailbox_t *mbp); - void chMBResetI(mailbox_t *mbp); - msg_t chMBPost(mailbox_t *mbp, msg_t msg, systime_t timeout); - msg_t chMBPostS(mailbox_t *mbp, msg_t msg, systime_t timeout); - msg_t chMBPostI(mailbox_t *mbp, msg_t msg); - msg_t chMBPostAhead(mailbox_t *mbp, msg_t msg, systime_t timeout); - msg_t chMBPostAheadS(mailbox_t *mbp, msg_t msg, systime_t timeout); - msg_t chMBPostAheadI(mailbox_t *mbp, msg_t msg); - msg_t chMBFetch(mailbox_t *mbp, msg_t *msgp, systime_t timeout); - msg_t chMBFetchS(mailbox_t *mbp, msg_t *msgp, systime_t timeout); - msg_t chMBFetchI(mailbox_t *mbp, msg_t *msgp); -#ifdef __cplusplus -} -#endif - -/*===========================================================================*/ -/* Module inline functions. */ -/*===========================================================================*/ - -/** - * @brief Returns the mailbox buffer size. - * - * @param[in] mbp the pointer to an initialized mailbox_t object - * @return The size of the mailbox. - * - * @iclass - */ -static inline size_t chMBGetSizeI(mailbox_t *mbp) { - - /*lint -save -e9033 [10.8] Perfectly safe pointers - arithmetic.*/ - return (size_t)(mbp->mb_top - mbp->mb_buffer); - /*lint -restore*/ -} - -/** - * @brief Returns the number of free message slots into a mailbox. - * @note Can be invoked in any system state but if invoked out of a locked - * state then the returned value may change after reading. - * @note The returned value can be less than zero when there are waiting - * threads on the internal semaphore. - * - * @param[in] mbp the pointer to an initialized mailbox_t object - * @return The number of empty message slots. - * - * @iclass - */ -static inline cnt_t chMBGetFreeCountI(mailbox_t *mbp) { - - chDbgCheckClassI(); - - return chSemGetCounterI(&mbp->mb_emptysem); -} - -/** - * @brief Returns the number of used message slots into a mailbox. - * @note Can be invoked in any system state but if invoked out of a locked - * state then the returned value may change after reading. - * @note The returned value can be less than zero when there are waiting - * threads on the internal semaphore. - * - * @param[in] mbp the pointer to an initialized mailbox_t object - * @return The number of queued messages. - * - * @iclass - */ -static inline cnt_t chMBGetUsedCountI(mailbox_t *mbp) { - - chDbgCheckClassI(); - - return chSemGetCounterI(&mbp->mb_fullsem); -} - -/** - * @brief Returns the next message in the queue without removing it. - * @pre A message must be waiting in the queue for this function to work - * or it would return garbage. The correct way to use this macro is - * to use @p chMBGetFullCountI() and then use this macro, all within - * a lock state. - * - * @param[in] mbp the pointer to an initialized mailbox_t object - * @return The next message in queue. - * - * @iclass - */ -static inline msg_t chMBPeekI(mailbox_t *mbp) { - - chDbgCheckClassI(); - - return *mbp->mb_rdptr; -} - -#endif /* CH_CFG_USE_MAILBOXES == TRUE */ - -#endif /* _CHMBOXES_H_ */ - -/** @} */ diff --git a/os/rt/include/chmemcore.h b/os/rt/include/chmemcore.h deleted file mode 100644 index d590d8982..000000000 --- a/os/rt/include/chmemcore.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio. - - This file is part of ChibiOS. - - ChibiOS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file chmemcore.h - * @brief Core memory manager macros and structures. - * - * @addtogroup memcore - * @{ - */ - -#ifndef _CHMEMCORE_H_ -#define _CHMEMCORE_H_ - -#if (CH_CFG_USE_MEMCORE == TRUE) || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Module constants. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module pre-compile time settings. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Derived constants and error checks. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module data structures and types. */ -/*===========================================================================*/ - -/** - * @brief Memory get function. - */ -typedef void *(*memgetfunc_t)(size_t size); - -/*===========================================================================*/ -/* Module macros. */ -/*===========================================================================*/ - -/** - * @name Alignment support macros - */ -/** - * @brief Alignment size constant. - */ -#define MEM_ALIGN_SIZE sizeof(stkalign_t) - -/** - * @brief Alignment mask constant. - */ -#define MEM_ALIGN_MASK (MEM_ALIGN_SIZE - 1U) - -/** - * @brief Alignment helper macro. - */ -#define MEM_ALIGN_PREV(p) ((size_t)(p) & ~MEM_ALIGN_MASK) - -/** - * @brief Alignment helper macro. - */ -#define MEM_ALIGN_NEXT(p) MEM_ALIGN_PREV((size_t)(p) + MEM_ALIGN_MASK) - -/** - * @brief Returns whatever a pointer or memory size is aligned to - * the type @p stkalign_t. - */ -#define MEM_IS_ALIGNED(p) (((size_t)(p) & MEM_ALIGN_MASK) == 0U) -/** @} */ - -/*===========================================================================*/ -/* External declarations. */ -/*===========================================================================*/ - -#ifdef __cplusplus -extern "C" { -#endif - void _core_init(void); - void *chCoreAlloc(size_t size); - void *chCoreAllocI(size_t size); - size_t chCoreGetStatusX(void); -#ifdef __cplusplus -} -#endif - -/*===========================================================================*/ -/* Module inline functions. */ -/*===========================================================================*/ - -#endif /* CH_CFG_USE_MEMCORE == TRUE */ - -#endif /* _CHMEMCORE_H_ */ - -/** @} */ diff --git a/os/rt/include/chmempools.h b/os/rt/include/chmempools.h deleted file mode 100644 index 3e363f86d..000000000 --- a/os/rt/include/chmempools.h +++ /dev/null @@ -1,168 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio. - - This file is part of ChibiOS. - - ChibiOS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file chmempools.h - * @brief Memory Pools macros and structures. - * - * @addtogroup pools - * @{ - */ - -#ifndef _CHMEMPOOLS_H_ -#define _CHMEMPOOLS_H_ - -#if (CH_CFG_USE_MEMPOOLS == TRUE) || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Module constants. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module pre-compile time settings. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Derived constants and error checks. */ -/*===========================================================================*/ - -#if CH_CFG_USE_MEMCORE == FALSE -#error "CH_CFG_USE_MEMPOOLS requires CH_CFG_USE_MEMCORE" -#endif - -/*===========================================================================*/ -/* Module data structures and types. */ -/*===========================================================================*/ - -/** - * @brief Memory pool free object header. - */ -struct pool_header { - struct pool_header *ph_next; /**< @brief Pointer to the next pool - header in the list. */ -}; - -/** - * @brief Memory pool descriptor. - */ -typedef struct { - struct pool_header *mp_next; /**< @brief Pointer to the header. */ - size_t mp_object_size; /**< @brief Memory pool objects - size. */ - memgetfunc_t mp_provider; /**< @brief Memory blocks provider - for this pool. */ -} memory_pool_t; - -/*===========================================================================*/ -/* Module macros. */ -/*===========================================================================*/ - -/** - * @brief Data part of a static memory pool initializer. - * @details This macro should be used when statically initializing a - * memory pool that is part of a bigger structure. - * - * @param[in] name the name of the memory pool variable - * @param[in] size size of the memory pool contained objects - * @param[in] provider memory provider function for the memory pool - */ -#define _MEMORYPOOL_DATA(name, size, provider) \ - {NULL, size, provider} - -/** - * @brief Static memory pool initializer in hungry mode. - * @details Statically initialized memory pools require no explicit - * initialization using @p chPoolInit(). - * - * @param[in] name the name of the memory pool variable - * @param[in] size size of the memory pool contained objects - * @param[in] provider memory provider function for the memory pool or @p NULL - * if the pool is not allowed to grow automatically - */ -#define MEMORYPOOL_DECL(name, size, provider) \ - memory_pool_t name = _MEMORYPOOL_DATA(name, size, provider) - -/*===========================================================================*/ -/* External declarations. */ -/*===========================================================================*/ - -#ifdef __cplusplus -extern "C" { -#endif - void chPoolObjectInit(memory_pool_t *mp, size_t size, memgetfunc_t provider); - void chPoolLoadArray(memory_pool_t *mp, void *p, size_t n); - void *chPoolAllocI(memory_pool_t *mp); - void *chPoolAlloc(memory_pool_t *mp); - void chPoolFreeI(memory_pool_t *mp, void *objp); - void chPoolFree(memory_pool_t *mp, void *objp); -#ifdef __cplusplus -} -#endif - -/*===========================================================================*/ -/* Module inline functions. */ -/*===========================================================================*/ - -/** - * @brief Adds an object to a memory pool. - * @pre The memory pool must be already been initialized. - * @pre The added object must be of the right size for the specified - * memory pool. - * @pre The added object must be memory aligned to the size of - * @p stkalign_t type. - * @note This function is just an alias for @p chPoolFree() and has been - * added for clarity. - * - * @param[in] mp pointer to a @p memory_pool_t structure - * @param[in] objp the pointer to the object to be added - * - * @api - */ -static inline void chPoolAdd(memory_pool_t *mp, void *objp) { - - chPoolFree(mp, objp); -} - -/** - * @brief Adds an object to a memory pool. - * @pre The memory pool must be already been initialized. - * @pre The added object must be of the right size for the specified - * memory pool. - * @pre The added object must be memory aligned to the size of - * @p stkalign_t type. - * @note This function is just an alias for @p chPoolFree() and has been - * added for clarity. - * - * @param[in] mp pointer to a @p memory_pool_t structure - * @param[in] objp the pointer to the object to be added - * - * @iclass - */ -static inline void chPoolAddI(memory_pool_t *mp, void *objp) { - - chDbgCheckClassI(); - - chPoolFreeI(mp, objp); -} - -#endif /* CH_CFG_USE_MEMPOOLS == TRUE */ - -#endif /* _CHMEMPOOLS_H_ */ - -/** @} */ diff --git a/os/rt/include/chmsg.h b/os/rt/include/chmsg.h index cd4f99897..a907eba93 100644 --- a/os/rt/include/chmsg.h +++ b/os/rt/include/chmsg.h @@ -80,7 +80,7 @@ static inline bool chMsgIsPendingI(thread_t *tp) { chDbgCheckClassI(); - return (bool)(tp->p_msgqueue.p_next != (thread_t *)&tp->p_msgqueue); + return (bool)(tp->msgqueue.next != (thread_t *)&tp->msgqueue); } /** @@ -95,9 +95,9 @@ static inline bool chMsgIsPendingI(thread_t *tp) { */ static inline msg_t chMsgGet(thread_t *tp) { - chDbgAssert(tp->p_state == CH_STATE_SNDMSG, "invalid state"); + chDbgAssert(tp->state == CH_STATE_SNDMSG, "invalid state"); - return tp->p_u.sentmsg; + return tp->u.sentmsg; } /** diff --git a/os/rt/include/chmtx.h b/os/rt/include/chmtx.h index caa0c8266..f1cc65a2f 100644 --- a/os/rt/include/chmtx.h +++ b/os/rt/include/chmtx.h @@ -55,14 +55,14 @@ typedef struct ch_mutex mutex_t; * @brief Mutex structure. */ struct ch_mutex { - threads_queue_t m_queue; /**< @brief Queue of the threads sleeping + threads_queue_t queue; /**< @brief Queue of the threads sleeping on this mutex. */ - thread_t *m_owner; /**< @brief Owner @p thread_t pointer or + thread_t *owner; /**< @brief Owner @p thread_t pointer or @p NULL. */ - mutex_t *m_next; /**< @brief Next @p mutex_t into an + mutex_t *next; /**< @brief Next @p mutex_t into an owner-list or @p NULL. */ #if (CH_CFG_USE_MUTEXES_RECURSIVE == TRUE) || defined(__DOXYGEN__) - cnt_t m_cnt; /**< @brief Mutex recursion counter. */ + cnt_t cnt; /**< @brief Mutex recursion counter. */ #endif }; @@ -78,9 +78,9 @@ struct ch_mutex { * @param[in] name the name of the mutex variable */ #if (CH_CFG_USE_MUTEXES_RECURSIVE == TRUE) || defined(__DOXYGEN__) -#define _MUTEX_DATA(name) {_THREADS_QUEUE_DATA(name.m_queue), NULL, NULL, 0} +#define _MUTEX_DATA(name) {_THREADS_QUEUE_DATA(name.queue), NULL, NULL, 0} #else -#define _MUTEX_DATA(name) {_THREADS_QUEUE_DATA(name.m_queue), NULL, NULL} +#define _MUTEX_DATA(name) {_THREADS_QUEUE_DATA(name.queue), NULL, NULL} #endif /** @@ -130,7 +130,7 @@ static inline bool chMtxQueueNotEmptyS(mutex_t *mp) { chDbgCheckClassS(); - return queue_notempty(&mp->m_queue); + return queue_notempty(&mp->queue); } /** @@ -143,7 +143,7 @@ static inline bool chMtxQueueNotEmptyS(mutex_t *mp) { */ static inline mutex_t *chMtxGetNextMutexS(void) { - return chThdGetSelfX()->p_mtxlist; + return chThdGetSelfX()->mtxlist; } #endif /* CH_CFG_USE_MUTEXES == TRUE */ diff --git a/os/rt/include/chqueues.h b/os/rt/include/chqueues.h index 56a1c51ea..3ab7087ca 100644 --- a/os/rt/include/chqueues.h +++ b/os/rt/include/chqueues.h @@ -75,15 +75,15 @@ typedef void (*qnotify_t)(io_queue_t *qp); * @ref system_states) and is non-blocking. */ struct io_queue { - threads_queue_t q_waiting; /**< @brief Queue of waiting threads. */ - volatile size_t q_counter; /**< @brief Resources counter. */ - uint8_t *q_buffer; /**< @brief Pointer to the queue buffer.*/ - uint8_t *q_top; /**< @brief Pointer to the first location + threads_queue_t waiting; /**< @brief Queue of waiting threads. */ + volatile size_t counter; /**< @brief Resources counter. */ + uint8_t *buffer; /**< @brief Pointer to the queue buffer.*/ + uint8_t *top; /**< @brief Pointer to the first location after the buffer. */ - uint8_t *q_wrptr; /**< @brief Write pointer. */ - uint8_t *q_rdptr; /**< @brief Read pointer. */ - qnotify_t q_notify; /**< @brief Data notification callback. */ - void *q_link; /**< @brief Application defined field. */ + uint8_t *wrptr; /**< @brief Write pointer. */ + uint8_t *rdptr; /**< @brief Read pointer. */ + qnotify_t notify; /**< @brief Data notification callback. */ + void *link; /**< @brief Application defined field. */ }; /** @@ -202,7 +202,7 @@ typedef io_queue_t output_queue_t; */ #define chQSizeX(qp) \ /*lint -save -e9033 [10.8] The cast is safe.*/ \ - ((size_t)((qp)->q_top - (qp)->q_buffer)) \ + ((size_t)((qp)->top - (qp)->buffer)) \ /*lint -restore*/ /** @@ -215,7 +215,7 @@ typedef io_queue_t output_queue_t; * * @iclass */ -#define chQSpaceI(qp) ((qp)->q_counter) +#define chQSpaceI(qp) ((qp)->counter) /** * @brief Returns the queue application-defined link. @@ -225,7 +225,7 @@ typedef io_queue_t output_queue_t; * * @xclass */ -#define chQGetLinkX(qp) ((qp)->q_link) +#define chQGetLinkX(qp) ((qp)->link) /** @} */ /*===========================================================================*/ @@ -322,7 +322,7 @@ static inline bool chIQIsFullI(input_queue_t *iqp) { chDbgCheckClassI(); /*lint -save -e9007 [13.5] No side effects.*/ - return (bool)((iqp->q_wrptr == iqp->q_rdptr) && (iqp->q_counter != 0U)); + return (bool)((iqp->wrptr == iqp->rdptr) && (iqp->counter != 0U)); /*lint -restore*/ } @@ -390,7 +390,7 @@ static inline bool chOQIsEmptyI(output_queue_t *oqp) { chDbgCheckClassI(); /*lint -save -e9007 [13.5] No side effects.*/ - return (bool)((oqp->q_wrptr == oqp->q_rdptr) && (oqp->q_counter != 0U)); + return (bool)((oqp->wrptr == oqp->rdptr) && (oqp->counter != 0U)); /*lint -restore*/ } diff --git a/os/rt/include/chregistry.h b/os/rt/include/chregistry.h index a5d13b798..39029b195 100644 --- a/os/rt/include/chregistry.h +++ b/os/rt/include/chregistry.h @@ -50,26 +50,24 @@ * @brief ChibiOS/RT memory signature record. */ typedef struct { - char ch_identifier[4]; /**< @brief Always set to "main". */ - uint8_t ch_zero; /**< @brief Must be zero. */ - uint8_t ch_size; /**< @brief Size of this structure. */ - uint16_t ch_version; /**< @brief Encoded ChibiOS/RT version. */ - uint8_t ch_ptrsize; /**< @brief Size of a pointer. */ - uint8_t ch_timesize; /**< @brief Size of a @p systime_t. */ - uint8_t ch_threadsize; /**< @brief Size of a @p thread_t. */ - uint8_t cf_off_prio; /**< @brief Offset of @p p_prio field. */ - uint8_t cf_off_ctx; /**< @brief Offset of @p p_ctx field. */ - uint8_t cf_off_newer; /**< @brief Offset of @p p_newer field. */ - uint8_t cf_off_older; /**< @brief Offset of @p p_older field. */ - uint8_t cf_off_name; /**< @brief Offset of @p p_name field. */ - uint8_t cf_off_stklimit; /**< @brief Offset of @p p_stklimit - field. */ - uint8_t cf_off_state; /**< @brief Offset of @p p_state field. */ - uint8_t cf_off_flags; /**< @brief Offset of @p p_flags field. */ - uint8_t cf_off_refs; /**< @brief Offset of @p p_refs field. */ - uint8_t cf_off_preempt; /**< @brief Offset of @p p_preempt - field. */ - uint8_t cf_off_time; /**< @brief Offset of @p p_time field. */ + char identifier[4]; /**< @brief Always set to "main". */ + uint8_t zero; /**< @brief Must be zero. */ + uint8_t size; /**< @brief Size of this structure. */ + uint16_t version; /**< @brief Encoded ChibiOS/RT version. */ + uint8_t ptrsize; /**< @brief Size of a pointer. */ + uint8_t timesize; /**< @brief Size of a @p systime_t. */ + uint8_t threadsize; /**< @brief Size of a @p thread_t. */ + uint8_t off_prio; /**< @brief Offset of @p prio field. */ + uint8_t off_ctx; /**< @brief Offset of @p ctx field. */ + uint8_t off_newer; /**< @brief Offset of @p newer field. */ + uint8_t off_older; /**< @brief Offset of @p older field. */ + uint8_t off_name; /**< @brief Offset of @p name field. */ + uint8_t off_stklimit; /**< @brief Offset of @p stklimit field.*/ + uint8_t off_state; /**< @brief Offset of @p state field. */ + uint8_t off_flags; /**< @brief Offset of @p flags field. */ + uint8_t off_refs; /**< @brief Offset of @p refs field. */ + uint8_t off_preempt; /**< @brief Offset of @p preempt field. */ + uint8_t off_time; /**< @brief Offset of @p time field. */ } chdebug_t; /*===========================================================================*/ @@ -83,8 +81,8 @@ typedef struct { * @param[in] tp thread to remove from the registry */ #define REG_REMOVE(tp) { \ - (tp)->p_older->p_newer = (tp)->p_newer; \ - (tp)->p_newer->p_older = (tp)->p_older; \ + (tp)->older->newer = (tp)->newer; \ + (tp)->newer->older = (tp)->older; \ } /** @@ -94,10 +92,10 @@ typedef struct { * @param[in] tp thread to add to the registry */ #define REG_INSERT(tp) { \ - (tp)->p_newer = (thread_t *)&ch.rlist; \ - (tp)->p_older = ch.rlist.r_older; \ - (tp)->p_older->p_newer = (tp); \ - ch.rlist.r_older = (tp); \ + (tp)->newer = (thread_t *)&ch.rlist; \ + (tp)->older = ch.rlist.older; \ + (tp)->older->newer = (tp); \ + ch.rlist.older = (tp); \ } /*===========================================================================*/ @@ -132,7 +130,7 @@ extern "C" { static inline void chRegSetThreadName(const char *name) { #if CH_CFG_USE_REGISTRY == TRUE - ch.rlist.r_current->p_name = name; + ch.rlist.current->name = name; #else (void)name; #endif @@ -152,7 +150,7 @@ static inline void chRegSetThreadName(const char *name) { static inline const char *chRegGetThreadNameX(thread_t *tp) { #if CH_CFG_USE_REGISTRY == TRUE - return tp->p_name; + return tp->name; #else (void)tp; return NULL; @@ -172,7 +170,7 @@ static inline const char *chRegGetThreadNameX(thread_t *tp) { static inline void chRegSetThreadNameX(thread_t *tp, const char *name) { #if CH_CFG_USE_REGISTRY == TRUE - tp->p_name = name; + tp->name = name; #else (void)tp; (void)name; diff --git a/os/rt/include/chschd.h b/os/rt/include/chschd.h index 18412ccc1..a3db7a3db 100644 --- a/os/rt/include/chschd.h +++ b/os/rt/include/chschd.h @@ -108,20 +108,8 @@ /** @} */ /** - * @name Working Areas and Alignment + * @name Working Areas */ -/** - * @brief Enforces a correct alignment for a stack area size value. - * - * @param[in] n the stack size to be aligned to the next stack - * alignment boundary - * @return The aligned stack size. - * - * @api - */ -#define THD_ALIGN_STACK_SIZE(n) \ - (((((size_t)(n)) - 1U) | (sizeof(stkalign_t) - 1U)) + 1U) - /** * @brief Calculates the total Working Area size. * @@ -131,7 +119,7 @@ * @api */ #define THD_WORKING_AREA_SIZE(n) \ - THD_ALIGN_STACK_SIZE(sizeof(thread_t) + PORT_WA_SIZE(n)) + MEM_ALIGN_NEXT(sizeof(thread_t) + PORT_WA_SIZE(n), PORT_STACK_ALIGN) /** * @brief Static working area allocation. @@ -143,8 +131,22 @@ * * @api */ -#define THD_WORKING_AREA(s, n) \ - stkalign_t s[THD_WORKING_AREA_SIZE(n) / sizeof(stkalign_t)] +#define THD_WORKING_AREA(s, n) PORT_WORKING_AREA(s, n) + +/** + * @brief Base of a working area casted to the correct type. + * + * @param[in] s name of the working area + */ +#define THD_WORKING_AREA_BASE(s) ((stkalign_t *)(s)) + +/** + * @brief End of a working area casted to the correct type. + * + * @param[in] s name of the working area + */ +#define THD_WORKING_AREA_END(s) (THD_WORKING_AREA_BASE(s) + \ + (sizeof (s) / sizeof (stkalign_t))) /** @} */ /** @@ -166,6 +168,18 @@ /* Derived constants and error checks. */ /*===========================================================================*/ +#if !defined(CH_CFG_IDLE_ENTER_HOOK) +#error "CH_CFG_IDLE_ENTER_HOOK not defined in chconf.h" +#endif + +#if !defined(CH_CFG_IDLE_LEAVE_HOOK) +#error "CH_CFG_IDLE_LEAVE_HOOK not defined in chconf.h" +#endif + +#if !defined(CH_CFG_IDLE_LOOP_HOOK) +#error "CH_CFG_IDLE_LOOP_HOOK not defined in chconf.h" +#endif + /*===========================================================================*/ /* Module data structures and types. */ /*===========================================================================*/ @@ -174,15 +188,15 @@ * @brief Generic threads single link list, it works like a stack. */ struct ch_threads_list { - thread_t *p_next; /**< @brief Next in the list/queue. */ + thread_t *next; /**< @brief Next in the list/queue. */ }; /** * @brief Generic threads bidirectional linked list header and element. */ struct ch_threads_queue { - thread_t *p_next; /**< @brief Next in the list/queue. */ - thread_t *p_prev; /**< @brief Previous in the queue. */ + thread_t *next; /**< @brief Next in the list/queue. */ + thread_t *prev; /**< @brief Previous in the queue. */ }; /** @@ -192,55 +206,44 @@ struct ch_threads_queue { * by shrinking this structure. */ struct ch_thread { - thread_t *p_next; /**< @brief Next in the list/queue. */ + thread_t *next; /**< @brief Next in the list/queue. */ /* End of the fields shared with the threads_list_t structure.*/ - thread_t *p_prev; /**< @brief Previous in the queue. */ + thread_t *prev; /**< @brief Previous in the queue. */ /* End of the fields shared with the threads_queue_t structure.*/ - tprio_t p_prio; /**< @brief Thread priority. */ - struct context p_ctx; /**< @brief Processor context. */ + tprio_t prio; /**< @brief Thread priority. */ + struct port_context ctx; /**< @brief Processor context. */ #if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__) - thread_t *p_newer; /**< @brief Newer registry element. */ - thread_t *p_older; /**< @brief Older registry element. */ + thread_t *newer; /**< @brief Newer registry element. */ + thread_t *older; /**< @brief Older registry element. */ #endif /* End of the fields shared with the ReadyList structure. */ #if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__) /** * @brief Thread name or @p NULL. */ - const char *p_name; + const char *name; #endif -#if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || defined(__DOXYGEN__) /** * @brief Thread stack boundary. + * @note This pointer matches with the working area base address. */ - stkalign_t *p_stklimit; -#endif + stkalign_t *stklimit; /** * @brief Current thread state. */ - tstate_t p_state; - /** - * @brief Various thread flags. - */ - tmode_t p_flags; -#if (CH_CFG_USE_DYNAMIC == TRUE) || defined(__DOXYGEN__) - /** - * @brief References to this thread. - */ - trefs_t p_refs; -#endif + tstate_t state; /** * @brief Number of ticks remaining to this thread. */ #if (CH_CFG_TIME_QUANTUM > 0) || defined(__DOXYGEN__) - tslices_t p_preempt; + tslices_t preempt; #endif #if (CH_DBG_THREADS_PROFILING == TRUE) || defined(__DOXYGEN__) /** * @brief Thread consumed time in ticks. * @note This field can overflow. */ - volatile systime_t p_time; + volatile systime_t time; #endif /** * @brief State-specific fields. @@ -308,48 +311,41 @@ struct ch_thread { */ eventmask_t ewmask; #endif - } p_u; + } u; #if (CH_CFG_USE_WAITEXIT == TRUE) || defined(__DOXYGEN__) /** * @brief Termination waiting list. */ - threads_list_t p_waiting; + threads_list_t waiting; #endif #if (CH_CFG_USE_MESSAGES == TRUE) || defined(__DOXYGEN__) /** * @brief Messages queue. */ - threads_queue_t p_msgqueue; + threads_queue_t msgqueue; #endif #if (CH_CFG_USE_EVENTS == TRUE) || defined(__DOXYGEN__) /** * @brief Pending events mask. */ - eventmask_t p_epending; + eventmask_t epending; #endif #if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__) /** * @brief List of the mutexes owned by this thread. * @note The list is terminated by a @p NULL in this field. */ - struct ch_mutex *p_mtxlist; + struct ch_mutex *mtxlist; /** * @brief Thread's own, non-inherited, priority. */ - tprio_t p_realprio; -#endif -#if ((CH_CFG_USE_DYNAMIC == TRUE) && (CH_CFG_USE_MEMPOOLS == TRUE)) || \ - defined(__DOXYGEN__) - /** - * @brief Memory Pool where the thread workspace is returned. - */ - void *p_mpool; + tprio_t realprio; #endif #if (CH_DBG_STATISTICS == TRUE) || defined(__DOXYGEN__) /** * @brief Thread statistics. */ - time_measurement_t p_stats; + time_measurement_t stats; #endif #if defined(CH_CFG_THREAD_EXTRA_FIELDS) /* Extra fields defined in chconf.h.*/ @@ -363,12 +359,12 @@ struct ch_thread { * @brief Virtual Timer descriptor structure. */ struct ch_virtual_timer { - virtual_timer_t *vt_next; /**< @brief Next timer in the list. */ - virtual_timer_t *vt_prev; /**< @brief Previous timer in the list. */ - systime_t vt_delta; /**< @brief Time delta before timeout. */ - vtfunc_t vt_func; /**< @brief Timer callback function + virtual_timer_t *next; /**< @brief Next timer in the list. */ + virtual_timer_t *prev; /**< @brief Previous timer in the list. */ + systime_t delta; /**< @brief Time delta before timeout. */ + vtfunc_t func; /**< @brief Timer callback function pointer. */ - void *vt_par; /**< @brief Timer callback function + void *par; /**< @brief Timer callback function parameter. */ }; @@ -379,19 +375,19 @@ struct ch_virtual_timer { * timer is often used in the code. */ struct ch_virtual_timers_list { - virtual_timer_t *vt_next; /**< @brief Next timer in the delta + virtual_timer_t *next; /**< @brief Next timer in the delta list. */ - virtual_timer_t *vt_prev; /**< @brief Last timer in the delta + virtual_timer_t *prev; /**< @brief Last timer in the delta list. */ - systime_t vt_delta; /**< @brief Must be initialized to -1. */ + systime_t delta; /**< @brief Must be initialized to -1. */ #if (CH_CFG_ST_TIMEDELTA == 0) || defined(__DOXYGEN__) - volatile systime_t vt_systime; /**< @brief System Time counter. */ + volatile systime_t systime; /**< @brief System Time counter. */ #endif #if (CH_CFG_ST_TIMEDELTA > 0) || defined(__DOXYGEN__) /** * @brief System time of the last tick event. */ - systime_t vt_lasttime;/**< @brief System time of the last + systime_t lasttime; /**< @brief System time of the last tick event. */ #endif }; @@ -400,17 +396,17 @@ struct ch_virtual_timers_list { * @extends threads_queue_t */ struct ch_ready_list { - threads_queue_t r_queue; /**< @brief Threads queue. */ - tprio_t r_prio; /**< @brief This field must be + threads_queue_t queue; /**< @brief Threads queue. */ + tprio_t prio; /**< @brief This field must be initialized to zero. */ - struct context r_ctx; /**< @brief Not used, present because + struct port_context ctx; /**< @brief Not used, present because offsets. */ #if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__) - thread_t *r_newer; /**< @brief Newer registry element. */ - thread_t *r_older; /**< @brief Older registry element. */ + thread_t *newer; /**< @brief Newer registry element. */ + thread_t *older; /**< @brief Older registry element. */ #endif /* End of the fields shared with the thread_t structure.*/ - thread_t *r_current; /**< @brief The currently running + thread_t *current; /**< @brief The currently running thread. */ }; @@ -436,7 +432,7 @@ struct ch_system_debug { */ cnt_t lock_cnt; #endif -#if (CH_DBG_ENABLE_TRACE == TRUE) || defined(__DOXYGEN__) +#if (CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_NONE) || defined(__DOXYGEN__) /** * @brief Public trace buffer. */ @@ -478,7 +474,7 @@ struct ch_system { */ kernel_stats_t kernel_stats; #endif -#if (CH_CFG_NO_IDLE_THREAD == FALSE) || defined(__DOXYGEN__) +#if CH_CFG_NO_IDLE_THREAD == FALSE /** * @brief Idle thread working area. */ @@ -495,25 +491,14 @@ struct ch_system { * * @notapi */ -#define firstprio(rlp) ((rlp)->p_next->p_prio) +#define firstprio(rlp) ((rlp)->next->prio) /** * @brief Current thread pointer access macro. * @note This macro is not meant to be used in the application code but - * only from within the kernel, use the @p chThdSelf() API instead. - * @note It is forbidden to use this macro in order to change the pointer - * (currp = something), use @p setcurrp() instead. - */ -#define currp ch.rlist.r_current - -/** - * @brief Current thread pointer change macro. - * @note This macro is not meant to be used in the application code but - * only from within the kernel. - * - * @notapi + * only from within the kernel, use @p chThdGetSelfX() instead. */ -#define setcurrp(tp) (currp = (tp)) +#define currp ch.rlist.current /*===========================================================================*/ /* External declarations. */ @@ -531,6 +516,7 @@ extern "C" { #endif void _scheduler_init(void); thread_t *chSchReadyI(thread_t *tp); + thread_t *chSchReadyAheadI(thread_t *tp); void chSchGoSleepS(tstate_t newstate); msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time); void chSchWakeupS(thread_t *ntp, msg_t msg); @@ -565,7 +551,7 @@ extern "C" { */ static inline void list_init(threads_list_t *tlp) { - tlp->p_next = (thread_t *)tlp; + tlp->next = (thread_t *)tlp; } /** @@ -578,7 +564,7 @@ static inline void list_init(threads_list_t *tlp) { */ static inline bool list_isempty(threads_list_t *tlp) { - return (bool)(tlp->p_next == (thread_t *)tlp); + return (bool)(tlp->next == (thread_t *)tlp); } /** @@ -591,7 +577,7 @@ static inline bool list_isempty(threads_list_t *tlp) { */ static inline bool list_notempty(threads_list_t *tlp) { - return (bool)(tlp->p_next != (thread_t *)tlp); + return (bool)(tlp->next != (thread_t *)tlp); } /** @@ -603,8 +589,8 @@ static inline bool list_notempty(threads_list_t *tlp) { */ static inline void queue_init(threads_queue_t *tqp) { - tqp->p_next = (thread_t *)tqp; - tqp->p_prev = (thread_t *)tqp; + tqp->next = (thread_t *)tqp; + tqp->prev = (thread_t *)tqp; } /** @@ -617,7 +603,7 @@ static inline void queue_init(threads_queue_t *tqp) { */ static inline bool queue_isempty(const threads_queue_t *tqp) { - return (bool)(tqp->p_next == (const thread_t *)tqp); + return (bool)(tqp->next == (const thread_t *)tqp); } /** @@ -630,7 +616,7 @@ static inline bool queue_isempty(const threads_queue_t *tqp) { */ static inline bool queue_notempty(const threads_queue_t *tqp) { - return (bool)(tqp->p_next != (const thread_t *)tqp); + return (bool)(tqp->next != (const thread_t *)tqp); } /* If the performance code path has been chosen then all the following @@ -638,14 +624,14 @@ static inline bool queue_notempty(const threads_queue_t *tqp) { #if CH_CFG_OPTIMIZE_SPEED == TRUE static inline void list_insert(thread_t *tp, threads_list_t *tlp) { - tp->p_next = tlp->p_next; - tlp->p_next = tp; + tp->next = tlp->next; + tlp->next = tp; } static inline thread_t *list_remove(threads_list_t *tlp) { - thread_t *tp = tlp->p_next; - tlp->p_next = tp->p_next; + thread_t *tp = tlp->next; + tlp->next = tp->next; return tp; } @@ -654,44 +640,44 @@ static inline void queue_prio_insert(thread_t *tp, threads_queue_t *tqp) { thread_t *cp = (thread_t *)tqp; do { - cp = cp->p_next; - } while ((cp != (thread_t *)tqp) && (cp->p_prio >= tp->p_prio)); - tp->p_next = cp; - tp->p_prev = cp->p_prev; - tp->p_prev->p_next = tp; - cp->p_prev = tp; + cp = cp->next; + } while ((cp != (thread_t *)tqp) && (cp->prio >= tp->prio)); + tp->next = cp; + tp->prev = cp->prev; + tp->prev->next = tp; + cp->prev = tp; } static inline void queue_insert(thread_t *tp, threads_queue_t *tqp) { - tp->p_next = (thread_t *)tqp; - tp->p_prev = tqp->p_prev; - tp->p_prev->p_next = tp; - tqp->p_prev = tp; + tp->next = (thread_t *)tqp; + tp->prev = tqp->prev; + tp->prev->next = tp; + tqp->prev = tp; } static inline thread_t *queue_fifo_remove(threads_queue_t *tqp) { - thread_t *tp = tqp->p_next; + thread_t *tp = tqp->next; - tqp->p_next = tp->p_next; - tqp->p_next->p_prev = (thread_t *)tqp; + tqp->next = tp->next; + tqp->next->prev = (thread_t *)tqp; return tp; } static inline thread_t *queue_lifo_remove(threads_queue_t *tqp) { - thread_t *tp = tqp->p_prev; + thread_t *tp = tqp->prev; - tqp->p_prev = tp->p_prev; - tqp->p_prev->p_next = (thread_t *)tqp; + tqp->prev = tp->prev; + tqp->prev->next = (thread_t *)tqp; return tp; } static inline thread_t *queue_dequeue(thread_t *tp) { - tp->p_prev->p_next = tp->p_next; - tp->p_next->p_prev = tp->p_prev; + tp->prev->next = tp->next; + tp->next->prev = tp->prev; return tp; } @@ -712,7 +698,7 @@ static inline bool chSchIsRescRequiredI(void) { chDbgCheckClassI(); - return firstprio(&ch.rlist.r_queue) > currp->p_prio; + return firstprio(&ch.rlist.queue) > currp->prio; } /** @@ -730,7 +716,7 @@ static inline bool chSchCanYieldS(void) { chDbgCheckClassS(); - return firstprio(&ch.rlist.r_queue) >= currp->p_prio; + return firstprio(&ch.rlist.queue) >= currp->prio; } /** @@ -757,11 +743,11 @@ static inline void chSchDoYieldS(void) { * @special */ static inline void chSchPreemption(void) { - tprio_t p1 = firstprio(&ch.rlist.r_queue); - tprio_t p2 = currp->p_prio; + tprio_t p1 = firstprio(&ch.rlist.queue); + tprio_t p2 = currp->prio; #if CH_CFG_TIME_QUANTUM > 0 - if (currp->p_preempt > (tslices_t)0) { + if (currp->preempt > (tslices_t)0) { if (p1 > p2) { chSchDoRescheduleAhead(); } diff --git a/os/rt/include/chsem.h b/os/rt/include/chsem.h index efc1cea0b..c555c550e 100644 --- a/os/rt/include/chsem.h +++ b/os/rt/include/chsem.h @@ -50,9 +50,9 @@ * @brief Semaphore structure. */ typedef struct ch_semaphore { - threads_queue_t s_queue; /**< @brief Queue of the threads sleeping + threads_queue_t queue; /**< @brief Queue of the threads sleeping on this semaphore. */ - cnt_t s_cnt; /**< @brief The semaphore counter. */ + cnt_t cnt; /**< @brief The semaphore counter. */ } semaphore_t; /*===========================================================================*/ @@ -68,7 +68,7 @@ typedef struct ch_semaphore { * @param[in] n the counter initial value, this value must be * non-negative */ -#define _SEMAPHORE_DATA(name, n) {_THREADS_QUEUE_DATA(name.s_queue), n} +#define _SEMAPHORE_DATA(name, n) {_THREADS_QUEUE_DATA(name.queue), n} /** * @brief Static semaphore initializer. @@ -119,7 +119,7 @@ static inline void chSemFastWaitI(semaphore_t *sp) { chDbgCheckClassI(); - sp->s_cnt--; + sp->cnt--; } /** @@ -135,7 +135,7 @@ static inline void chSemFastSignalI(semaphore_t *sp) { chDbgCheckClassI(); - sp->s_cnt++; + sp->cnt++; } /** @@ -150,7 +150,7 @@ static inline cnt_t chSemGetCounterI(semaphore_t *sp) { chDbgCheckClassI(); - return sp->s_cnt; + return sp->cnt; } #endif /* CH_CFG_USE_SEMAPHORES == TRUE */ diff --git a/os/rt/include/chsys.h b/os/rt/include/chsys.h index 6742259e3..6bc3b507f 100644 --- a/os/rt/include/chsys.h +++ b/os/rt/include/chsys.h @@ -52,6 +52,26 @@ /* Derived constants and error checks. */ /*===========================================================================*/ +#if !defined(CH_CFG_IRQ_PROLOGUE_HOOK) +#error "CH_CFG_IRQ_PROLOGUE_HOOK not defined in chconf.h" +#endif + +#if !defined(CH_CFG_IRQ_EPILOGUE_HOOK) +#error "CH_CFG_IRQ_EPILOGUE_HOOK not defined in chconf.h" +#endif + +#if !defined(CH_CFG_CONTEXT_SWITCH_HOOK) +#error "CH_CFG_CONTEXT_SWITCH_HOOK not defined in chconf.h" +#endif + +#if !defined(CH_CFG_SYSTEM_TICK_HOOK) +#error "CH_CFG_SYSTEM_TICK_HOOK not defined in chconf.h" +#endif + +#if !defined(CH_CFG_SYSTEM_HALT_HOOK) +#error "CH_CFG_SYSTEM_HALT_HOOK not defined in chconf.h" +#endif + /*===========================================================================*/ /* Module data structures and types. */ /*===========================================================================*/ @@ -108,7 +128,9 @@ */ #define CH_IRQ_PROLOGUE() \ PORT_IRQ_PROLOGUE(); \ + CH_CFG_IRQ_PROLOGUE_HOOK(); \ _stats_increase_irq(); \ + _dbg_trace_isr_enter(__func__); \ _dbg_check_enter_isr() /** @@ -121,6 +143,8 @@ */ #define CH_IRQ_EPILOGUE() \ _dbg_check_leave_isr(); \ + _dbg_trace_isr_leave(__func__); \ + CH_CFG_IRQ_EPILOGUE_HOOK(); \ PORT_IRQ_EPILOGUE() /** @@ -261,7 +285,7 @@ */ #define chSysSwitch(ntp, otp) { \ \ - _dbg_trace(otp); \ + _dbg_trace_switch(otp); \ _stats_ctxswc(ntp, otp); \ CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp); \ port_switch(ntp, otp); \ @@ -280,7 +304,7 @@ extern "C" { void chSysTimerHandlerI(void); syssts_t chSysGetStatusAndLockX(void); void chSysRestoreStatusX(syssts_t sts); -#if PORT_SUPPORTS_RT +#if PORT_SUPPORTS_RT == TRUE bool chSysIsCounterWithinX(rtcnt_t cnt, rtcnt_t start, rtcnt_t end); void chSysPolledDelayX(rtcnt_t cycles); #endif @@ -364,8 +388,8 @@ static inline void chSysUnlock(void) { in a critical section not followed by a chSchResceduleS(), this means that the current thread has a lower priority than the next thread in the ready list.*/ - chDbgAssert((ch.rlist.r_queue.p_next == (thread_t *)&ch.rlist.r_queue) || - (ch.rlist.r_current->p_prio >= ch.rlist.r_queue.p_next->p_prio), + chDbgAssert((ch.rlist.queue.next == (thread_t *)&ch.rlist.queue) || + (ch.rlist.current->prio >= ch.rlist.queue.next->prio), "priority order violation"); port_unlock(); @@ -453,7 +477,7 @@ static inline void chSysUnconditionalUnlock(void) { */ static inline thread_t *chSysGetIdleThreadX(void) { - return ch.rlist.r_queue.p_prev; + return ch.rlist.queue.prev; } #endif /* CH_CFG_NO_IDLE_THREAD == FALSE */ diff --git a/os/rt/include/chthreads.h b/os/rt/include/chthreads.h index 690c45f7f..8d632d59e 100644 --- a/os/rt/include/chthreads.h +++ b/os/rt/include/chthreads.h @@ -38,6 +38,18 @@ /* Module pre-compile time settings. */ /*===========================================================================*/ +#if !defined(CH_CFG_THREAD_EXTRA_FIELDS) +#error "CH_CFG_THREAD_EXTRA_FIELDS not defined in chconf.h" +#endif + +#if !defined(CH_CFG_THREAD_INIT_HOOK) +#error "CH_CFG_THREAD_INIT_HOOK not defined in chconf.h" +#endif + +#if !defined(CH_CFG_THREAD_EXIT_HOOK) +#error "CH_CFG_THREAD_EXIT_HOOK not defined in chconf.h" +#endif + /*===========================================================================*/ /* Derived constants and error checks. */ /*===========================================================================*/ @@ -51,6 +63,36 @@ */ typedef void (*tfunc_t)(void *p); +/** + * @brief Type of a thread descriptor. + */ +typedef struct { + /** + * @brief Thread name. + */ + const char *name; + /** + * @brief Pointer to the working area base. + */ + stkalign_t *wbase; + /** + * @brief End of the working area. + */ + stkalign_t *wend; + /** + * @brief Thread priority. + */ + tprio_t prio; + /** + * @brief Thread function pointer. + */ + tfunc_t funcp; + /** + * @brief Thread argument. + */ + void *arg; +} thread_descriptor_t; + /*===========================================================================*/ /* Module macros. */ /*===========================================================================*/ @@ -128,12 +170,14 @@ typedef void (*tfunc_t)(void *p); #ifdef __cplusplus extern "C" { #endif - thread_t *_thread_init(thread_t *tp, tprio_t prio); + thread_t *_thread_init(thread_t *tp, const char *name, tprio_t prio); #if CH_DBG_FILL_THREADS == TRUE void _thread_memfill(uint8_t *startp, uint8_t *endp, uint8_t v); #endif - thread_t *chThdCreateI(void *wsp, size_t size, - tprio_t prio, tfunc_t pf, void *arg); + thread_t *chThdCreateSuspendedI(const thread_descriptor_t *tdp); + thread_t *chThdCreateSuspended(const thread_descriptor_t *tdp); + thread_t *chThdCreateI(const thread_descriptor_t *tdp); + thread_t *chThdCreate(const thread_descriptor_t *tdp); thread_t *chThdCreateStatic(void *wsp, size_t size, tprio_t prio, tfunc_t pf, void *arg); thread_t *chThdStart(thread_t *tp); @@ -146,7 +190,6 @@ extern "C" { msg_t chThdEnqueueTimeoutS(threads_queue_t *tqp, systime_t timeout); void chThdDequeueNextI(threads_queue_t *tqp, msg_t msg); void chThdDequeueAllI(threads_queue_t *tqp, msg_t msg); - void chThdTerminate(thread_t *tp); void chThdSleep(systime_t time); void chThdSleepUntil(systime_t time); systime_t chThdSleepUntilWindowed(systime_t prev, systime_t next); @@ -173,7 +216,7 @@ extern "C" { */ static inline thread_t *chThdGetSelfX(void) { - return ch.rlist.r_current; + return ch.rlist.current; } /** @@ -186,7 +229,7 @@ static inline thread_t *chThdGetSelfX(void) { */ static inline tprio_t chThdGetPriorityX(void) { - return chThdGetSelfX()->p_prio; + return chThdGetSelfX()->prio; } /** @@ -202,35 +245,35 @@ static inline tprio_t chThdGetPriorityX(void) { #if (CH_DBG_THREADS_PROFILING == TRUE) || defined(__DOXYGEN__) static inline systime_t chThdGetTicksX(thread_t *tp) { - return tp->p_time; + return tp->time; } #endif /** - * @brief Verifies if the specified thread is in the @p CH_STATE_FINAL state. + * @brief Returns the stack limit of the specified thread. * * @param[in] tp pointer to the thread - * @retval true thread terminated. - * @retval false thread not terminated. + * @return The stack limit pointer. * * @xclass */ -static inline bool chThdTerminatedX(thread_t *tp) { +static inline stkalign_t *chthdGetStackLimitX(thread_t *tp) { - return (bool)(tp->p_state == CH_STATE_FINAL); + return tp->stklimit; } /** - * @brief Verifies if the current thread has a termination request pending. + * @brief Verifies if the specified thread is in the @p CH_STATE_FINAL state. * - * @retval true termination request pending. - * @retval false termination request not pending. + * @param[in] tp pointer to the thread + * @retval true thread terminated. + * @retval false thread not terminated. * * @xclass */ -static inline bool chThdShouldTerminateX(void) { +static inline bool chThdTerminatedX(thread_t *tp) { - return (bool)((chThdGetSelfX()->p_flags & CH_FLAG_TERMINATE) != (tmode_t)0); + return (bool)(tp->state == CH_STATE_FINAL); } /** @@ -244,7 +287,7 @@ static inline bool chThdShouldTerminateX(void) { */ static inline thread_t *chThdStartI(thread_t *tp) { - chDbgAssert(tp->p_state == CH_STATE_WTSTART, "wrong state"); + chDbgAssert(tp->state == CH_STATE_WTSTART, "wrong state"); return chSchReadyI(tp); } @@ -316,9 +359,9 @@ static inline void chThdDoDequeueNextI(threads_queue_t *tqp, msg_t msg) { tp = queue_fifo_remove(tqp); - chDbgAssert(tp->p_state == CH_STATE_QUEUED, "invalid state"); + chDbgAssert(tp->state == CH_STATE_QUEUED, "invalid state"); - tp->p_u.rdymsg = msg; + tp->u.rdymsg = msg; (void) chSchReadyI(tp); } diff --git a/os/rt/include/chvt.h b/os/rt/include/chvt.h index bcf1dbcac..1608cbc2b 100644 --- a/os/rt/include/chvt.h +++ b/os/rt/include/chvt.h @@ -209,7 +209,7 @@ extern "C" { */ static inline void chVTObjectInit(virtual_timer_t *vtp) { - vtp->vt_func = NULL; + vtp->func = NULL; } /** @@ -228,7 +228,7 @@ static inline void chVTObjectInit(virtual_timer_t *vtp) { static inline systime_t chVTGetSystemTimeX(void) { #if CH_CFG_ST_TIMEDELTA == 0 - return ch.vtlist.vt_systime; + return ch.vtlist.systime; #else /* CH_CFG_ST_TIMEDELTA > 0 */ return port_timer_get_time(); #endif /* CH_CFG_ST_TIMEDELTA > 0 */ @@ -344,15 +344,15 @@ static inline bool chVTGetTimersStateI(systime_t *timep) { chDbgCheckClassI(); - if (&ch.vtlist == (virtual_timers_list_t *)ch.vtlist.vt_next) { + if (&ch.vtlist == (virtual_timers_list_t *)ch.vtlist.next) { return false; } if (timep != NULL) { #if CH_CFG_ST_TIMEDELTA == 0 - *timep = ch.vtlist.vt_next->vt_delta; + *timep = ch.vtlist.next->delta; #else - *timep = ch.vtlist.vt_lasttime + ch.vtlist.vt_next->vt_delta + + *timep = ch.vtlist.lasttime + ch.vtlist.next->delta + CH_CFG_ST_TIMEDELTA - chVTGetSystemTimeX(); #endif } @@ -374,7 +374,7 @@ static inline bool chVTIsArmedI(virtual_timer_t *vtp) { chDbgCheckClassI(); - return (bool)(vtp->vt_func != NULL); + return (bool)(vtp->func != NULL); } /** @@ -504,21 +504,21 @@ static inline void chVTDoTickI(void) { chDbgCheckClassI(); #if CH_CFG_ST_TIMEDELTA == 0 - ch.vtlist.vt_systime++; - if (&ch.vtlist != (virtual_timers_list_t *)ch.vtlist.vt_next) { + ch.vtlist.systime++; + if (&ch.vtlist != (virtual_timers_list_t *)ch.vtlist.next) { /* The list is not empty, processing elements on top.*/ - --ch.vtlist.vt_next->vt_delta; - while (ch.vtlist.vt_next->vt_delta == (systime_t)0) { + --ch.vtlist.next->delta; + while (ch.vtlist.next->delta == (systime_t)0) { virtual_timer_t *vtp; vtfunc_t fn; - vtp = ch.vtlist.vt_next; - fn = vtp->vt_func; - vtp->vt_func = NULL; - vtp->vt_next->vt_prev = (virtual_timer_t *)&ch.vtlist; - ch.vtlist.vt_next = vtp->vt_next; + vtp = ch.vtlist.next; + fn = vtp->func; + vtp->func = NULL; + vtp->next->prev = (virtual_timer_t *)&ch.vtlist; + ch.vtlist.next = vtp->next; chSysUnlockFromISR(); - fn(vtp->vt_par); + fn(vtp->par); chSysLockFromISR(); } } @@ -527,26 +527,26 @@ static inline void chVTDoTickI(void) { systime_t now, delta; /* First timer to be processed.*/ - vtp = ch.vtlist.vt_next; + vtp = ch.vtlist.next; now = chVTGetSystemTimeX(); /* All timers within the time window are triggered and removed, note that the loop is stopped by the timers header having "ch.vtlist.vt_delta == (systime_t)-1" which is greater than all deltas.*/ - while (vtp->vt_delta <= (systime_t)(now - ch.vtlist.vt_lasttime)) { + while (vtp->delta <= (systime_t)(now - ch.vtlist.lasttime)) { vtfunc_t fn; /* The "last time" becomes this timer's expiration time.*/ - ch.vtlist.vt_lasttime += vtp->vt_delta; + ch.vtlist.lasttime += vtp->delta; - vtp->vt_next->vt_prev = (virtual_timer_t *)&ch.vtlist; - ch.vtlist.vt_next = vtp->vt_next; - fn = vtp->vt_func; - vtp->vt_func = NULL; + vtp->next->prev = (virtual_timer_t *)&ch.vtlist; + ch.vtlist.next = vtp->next; + fn = vtp->func; + vtp->func = NULL; /* if the list becomes empty then the timer is stopped.*/ - if (ch.vtlist.vt_next == (virtual_timer_t *)&ch.vtlist) { + if (ch.vtlist.next == (virtual_timer_t *)&ch.vtlist) { port_timer_stop_alarm(); } @@ -556,7 +556,7 @@ static inline void chVTDoTickI(void) { chSysUnlockFromISR(); /* The callback is invoked outside the kernel critical zone.*/ - fn(vtp->vt_par); + fn(vtp->par); /* Re-entering the critical zone in order to continue the exploration of the list.*/ @@ -564,24 +564,24 @@ static inline void chVTDoTickI(void) { /* Next element in the list, the current time could have advanced so recalculating the time window.*/ - vtp = ch.vtlist.vt_next; + vtp = ch.vtlist.next; now = chVTGetSystemTimeX(); } /* if the list is empty, nothing else to do.*/ - if (ch.vtlist.vt_next == (virtual_timer_t *)&ch.vtlist) { + if (ch.vtlist.next == (virtual_timer_t *)&ch.vtlist) { return; } /* Recalculating the next alarm time.*/ - delta = ch.vtlist.vt_lasttime + vtp->vt_delta - now; + delta = ch.vtlist.lasttime + vtp->delta - now; if (delta < (systime_t)CH_CFG_ST_TIMEDELTA) { delta = (systime_t)CH_CFG_ST_TIMEDELTA; } port_timer_set_alarm(now + delta); - chDbgAssert((chVTGetSystemTimeX() - ch.vtlist.vt_lasttime) <= - (now + delta - ch.vtlist.vt_lasttime), + chDbgAssert((chVTGetSystemTimeX() - ch.vtlist.lasttime) <= + (now + delta - ch.vtlist.lasttime), "exceeding delta"); #endif /* CH_CFG_ST_TIMEDELTA > 0 */ } -- cgit v1.2.3