From 3d2f2081cebee2936d8073ab6a55177b6549013e Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 17 Feb 2009 19:58:46 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@778 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- src/chmboxes.c | 152 +++++++++++++++++++++++++++++++++ src/chqueues.c | 4 +- src/chsys.c | 3 + src/chthreads.c | 3 + src/include/ch.h | 1 + src/include/mailboxes.h | 85 +++++++++++++++++++ src/include/semaphores.h | 4 +- src/include/sys.h | 4 - src/include/threads.h | 4 + src/kernel.mk | 16 ++-- src/templates/chconf.h | 212 ++++++++++++++++++++++++++++------------------- src/templates/chcore.c | 4 + 12 files changed, 393 insertions(+), 99 deletions(-) create mode 100644 src/chmboxes.c create mode 100644 src/include/mailboxes.h (limited to 'src') diff --git a/src/chmboxes.c b/src/chmboxes.c new file mode 100644 index 000000000..63ab01364 --- /dev/null +++ b/src/chmboxes.c @@ -0,0 +1,152 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT 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/RT 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.c + * @brief Mailboxes code. + * @addtogroup Mailboxes + * @{ + */ + +#include + +#if CH_USE_MAILBOXES + +/** + * @brief Initializes a Mailbox object. + * + * @param[out] mbp the pointer to the Mailbox structure to be initialized + * @param[in] buf the circular messages buffer + * @param[in] n the buffer size as number of @p msg_t + */ +void chMBInit(Mailbox *mbp, msg_t *buf, cnt_t n) { + + mbp->mb_buffer = mbp->mb_wrptr = mbp->mb_rdptr = buf; + mbp->mb_top = &buf[n]; + chSemInit(&mbp->mb_emptysem, n); + chSemInit(&mbp->mb_fullsem, 0); +} + +/** + * @brief Resets a Mailbox object. + * @details All the waiting threads are resumed with status @p RDY_RESET and + * the queued messages are lost. + * + * @param[in] mbp the pointer to an initialized Mailbox object + */ +void chMBReset(Mailbox *mbp) { + + chSysLock(); + mbp->mb_wrptr = mbp->mb_rdptr = mbp->mb_buffer; + chSemResetI(&mbp->mb_emptysem, mbp->mb_top - mbp->mb_buffer); + chSemResetI(&mbp->mb_fullsem, 0); + chSchRescheduleS(); + chSysUnlock(); +} + +/** + * @brief Posts a message into a mailbox. + * @details The invoking thread waits until a empty slot in the mailbox becomes + * available or the specified time runs out. + * + * @param[in] mbp the pointer to an initialized Mailbox object + * @param[in] msg the message to be posted on the mailbox + * @param[in] timeout the number of ticks before the operation fails + * @return The operation status. + * @retval RDY_OK if the message was correctly posted. + * @retval RDY_RESET if the mailbox was reset while waiting. + * @retval RDY_TIMEOUT if the operation timed out. + */ +msg_t chMBPost(Mailbox *mbp, msg_t msg, systime_t timeout) { + msg_t rdymsg; + + chSysLock(); + rdymsg = chSemWaitTimeoutS(&mbp->mb_emptysem, timeout); + if (rdymsg == RDY_OK) { + *mbp->mb_wrptr++ = msg; + if (mbp->mb_wrptr >= mbp->mb_top) + mbp->mb_wrptr = mbp->mb_buffer; + chSemSignalI(&mbp->mb_fullsem); + chSchRescheduleS(); + } + chSysUnlock(); + return rdymsg; +} + +/** + * @brief Posts an high priority message into a mailbox. + * @details The invoking thread waits until a empty slot in the mailbox becomes + * available or the specified time runs out. + * + * @param[in] mbp the pointer to an initialized Mailbox object + * @param[in] msg the message to be posted on the mailbox + * @param[in] timeout the number of ticks before the operation timeouts + * @return The operation status. + * @retval RDY_OK if the message was correctly posted. + * @retval RDY_RESET if the mailbox was reset while waiting. + * @retval RDY_TIMEOUT if the operation timed out. + */ +msg_t chMBPostAhead(Mailbox *mbp, msg_t msg, systime_t timeout) { + msg_t rdymsg; + + chSysLock(); + rdymsg = chSemWaitTimeoutS(&mbp->mb_emptysem, timeout); + if (rdymsg == RDY_OK) { + if (--mbp->mb_rdptr < mbp->mb_buffer) + mbp->mb_rdptr = mbp->mb_top - 1; + *mbp->mb_rdptr = msg; + chSemSignalI(&mbp->mb_fullsem); + chSchRescheduleS(); + } + chSysUnlock(); + return rdymsg; +} + +/** + * @brief Retrieves a message from a mailbox. + * @details The invoking thread waits until a message is posted in the mailbox + * or the specified time runs out. + * + * @param[in] mbp the pointer to an initialized Mailbox object + * @param[out] msgp pointer to a message variable for the received message + * @param[in] timeout the number of ticks before the operation timeouts + * @return The operation status. + * @retval RDY_OK if a message was correctly fetched. + * @retval RDY_RESET if the mailbox was reset while waiting. + * @retval RDY_TIMEOUT if the operation timed out. + */ +msg_t chMBFetch(Mailbox *mbp, msg_t *msgp, systime_t timeout) { + msg_t rdymsg; + + chSysLock(); + rdymsg = chSemWaitTimeoutS(&mbp->mb_fullsem, timeout); + if (rdymsg == RDY_OK) { + *msgp = *mbp->mb_rdptr++; + if (mbp->mb_rdptr >= mbp->mb_top) + mbp->mb_rdptr = mbp->mb_buffer; + chSemSignalI(&mbp->mb_emptysem); + chSchRescheduleS(); + } + chSysUnlock(); + return rdymsg; +} + +#endif /* CH_USE_MAILBOXES */ + +/** @} */ diff --git a/src/chqueues.c b/src/chqueues.c index 968ab273e..2615d36b7 100644 --- a/src/chqueues.c +++ b/src/chqueues.c @@ -177,7 +177,7 @@ size_t chIQRead(Queue *qp, uint8_t *buffer, size_t n) { chSysUnlock(); break; } - chSemFastWaitS(&qp->q_sem); + chSemFastWaitI(&qp->q_sem); *buffer++ = *qp->q_rdptr++; if (qp->q_rdptr >= qp->q_top) qp->q_rdptr = qp->q_buffer; @@ -302,7 +302,7 @@ size_t chOQWrite(Queue *qp, uint8_t *buffer, size_t n) { chSysUnlock(); break; } - chSemFastWaitS(&qp->q_sem); + chSemFastWaitI(&qp->q_sem); *qp->q_wrptr++ = *buffer++; if (qp->q_wrptr >= qp->q_top) qp->q_wrptr = qp->q_buffer; diff --git a/src/chsys.c b/src/chsys.c index db1e7f955..20c1e17fb 100644 --- a/src/chsys.c +++ b/src/chsys.c @@ -100,6 +100,9 @@ void chSysTimerHandlerI(void) { if (rlist.r_preempt > 0) /* decrement remaining quantum */ rlist.r_preempt--; +#endif +#if CH_DBG_THREADS_PROFILING + currp->p_time++; #endif chVTDoTickI(); } diff --git a/src/chthreads.c b/src/chthreads.c index e91c4c18f..c9d4b1d2c 100644 --- a/src/chthreads.c +++ b/src/chthreads.c @@ -37,6 +37,9 @@ Thread *init_thread(Thread *tp, tprio_t prio) { #if CH_USE_NESTED_LOCKS tp->p_locks = 0; #endif +#if CH_DBG_THREADS_PROFILING + tp->p_time = 0; +#endif #if CH_USE_MUTEXES /* realprio is the thread's own, non-inherited, priority */ tp->p_realprio = prio; diff --git a/src/include/ch.h b/src/include/ch.h index ec53b4197..b760e3d30 100644 --- a/src/include/ch.h +++ b/src/include/ch.h @@ -74,6 +74,7 @@ #include "condvars.h" #include "events.h" #include "messages.h" +#include "mailboxes.h" #include "heap.h" #include "mempools.h" #include "threads.h" diff --git a/src/include/mailboxes.h b/src/include/mailboxes.h new file mode 100644 index 000000000..03623e7bc --- /dev/null +++ b/src/include/mailboxes.h @@ -0,0 +1,85 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT 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/RT 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 mailboxes.h + * @brief Mailboxes macros and structures. + * @addtogroup Mailboxes + * @{ + */ + +#ifndef _MAILBOXES_H_ +#define _MAILBOXES_H_ + +#if CH_USE_MAILBOXES + +typedef struct { + msg_t *mb_buffer; /**< Pointer to the mailbox buffer.*/ + msg_t *mb_top; /**< Pointer to the first location + after the buffer.*/ + msg_t *mb_wrptr; /**< Write pointer.*/ + msg_t *mb_rdptr; /**< Read pointer.*/ + Semaphore mb_fullsem; /**< Full counter @p Semaphore.*/ + Semaphore mb_emptysem; /**< Empty counter @p Semaphore.*/ +} Mailbox; + +#ifdef __cplusplus +extern "C" { +#endif + void chMBInit(Mailbox *mbp, msg_t *buf, cnt_t n); + void chMBReset(Mailbox *mbp); + msg_t chMBPost(Mailbox *mbp, msg_t msg, systime_t timeout); + msg_t chMBPostAhead(Mailbox *mbp, msg_t msg, systime_t timeout); + msg_t chMBFetch(Mailbox *mbp, msg_t *msgp, systime_t timeout); +#ifdef __cplusplus +} +#endif + +/** + * Verifies if the mailbox has space for an immediate message. + * @param[in] mbp the pointer to an initialized Mailbox object + * @return The number of empty message slots. + * @note Can be invoked in any system state but if invoked out of a locked + * state then the returned value may change after reading. + */ +#define chMBHasSpace(mbp) chSemGetCounterI(&(mbp)->mb_emptysem) + +/** + * Verifies if the mailbox has incoming messages. + * @param[in] mbp the pointer to an initialized Mailbox object + * @return The number of queued messages. + * @note Can be invoked in any system state but if invoked out of a locked + * state then the returned value may change after reading. + */ +#define chMBContainsMessages(mbp) chSemGetCounterI(&(mbp)->mb_fullsem) + +/** + * Returns the next message in the queue without removing it. + * @note 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 chMBContainsMessages() and then use this macro, all within + * a lock state. + */ +#define chMBPeek(mbp) (*(mbp)->mb_rdptr) + +#endif /* CH_USE_MAILBOXES */ + +#endif /* _MAILBOXES_H_ */ + +/** @} */ diff --git a/src/include/semaphores.h b/src/include/semaphores.h index 25f11b06b..acb48f150 100644 --- a/src/include/semaphores.h +++ b/src/include/semaphores.h @@ -63,7 +63,7 @@ extern "C" { * Decreases the semaphore counter, this macro can be used when it is ensured * that the counter would not become negative. */ -#define chSemFastWaitS(sp) ((sp)->s_cnt--) +#define chSemFastWaitI(sp) ((sp)->s_cnt--) /** * Increases the semaphore counter, this macro can be used when the counter is @@ -74,7 +74,7 @@ extern "C" { /** * Returns the semaphore counter current value. */ -#define chSemGetCounter(sp) ((sp)->s_cnt) +#define chSemGetCounterI(sp) ((sp)->s_cnt) #endif /* CH_USE_SEMAPHORES */ diff --git a/src/include/sys.h b/src/include/sys.h index ccc71ae7f..e36d98b76 100644 --- a/src/include/sys.h +++ b/src/include/sys.h @@ -43,13 +43,9 @@ /** * @brief Performs a context switch. - * @details This is the most critical code in any port, this function - * is responsible for the context switch between 2 threads. * * @param otp the thread to be switched out * @param ntp the thread to be switched in - * @note The implementation of this code affects directly the context - * switch performance so optimize here as much as you can. */ #define chSysSwitchI(otp, ntp) port_switch(otp, ntp) diff --git a/src/include/threads.h b/src/include/threads.h index be48fcbb3..961ef5b0b 100644 --- a/src/include/threads.h +++ b/src/include/threads.h @@ -49,6 +49,10 @@ struct Thread { struct context p_ctx; /**< Processor context.*/ #if CH_USE_NESTED_LOCKS cnt_t p_locks; /**< Number of nested locks.*/ +#endif +#if CH_DBG_THREADS_PROFILING + systime_t p_time; /**< Consumed time. + @note This field can overflow.*/ #endif /* * The following fields are merged in unions because they are all diff --git a/src/kernel.mk b/src/kernel.mk index 9f18bcec6..dae6749eb 100644 --- a/src/kernel.mk +++ b/src/kernel.mk @@ -1,13 +1,13 @@ # List of all the ChibiOS/RT kernel files, there is no need to remove the files # from this list, you can disable parts of the kernel by editing chconf.h. -KERNSRC = ../../src/chsys.c ../../src/chdebug.c \ - ../../src/chlists.c ../../src/chvt.c \ - ../../src/chschd.c ../../src/chthreads.c \ - ../../src/chsem.c ../../src/chmtx.c \ - ../../src/chcond.c ../../src/chevents.c \ - ../../src/chmsg.c ../../src/chqueues.c \ - ../../src/chheap.c ../../src/chmempools.c \ - ../../src/chserial.c +KERNSRC = ../../src/chsys.c ../../src/chdebug.c \ + ../../src/chlists.c ../../src/chvt.c \ + ../../src/chschd.c ../../src/chthreads.c \ + ../../src/chsem.c ../../src/chmtx.c \ + ../../src/chcond.c ../../src/chevents.c \ + ../../src/chmsg.c ../../src/chmboxes.c \ + ../../src/chqueues.c ../../src/chheap.c \ + ../../src/chmempools.c ../../src/chserial.c # Required include directories KERNINC = ../../src/include diff --git a/src/templates/chconf.h b/src/templates/chconf.h index 3338d5b3f..d91a2f743 100644 --- a/src/templates/chconf.h +++ b/src/templates/chconf.h @@ -27,14 +27,25 @@ #ifndef _CHCONF_H_ #define _CHCONF_H_ +/*===========================================================================*/ +/* Kernel parameters. */ +/*===========================================================================*/ + /** - * If specified then time efficient rather than space efficient code is used - * when two possible implementations exist. - * @note This is not related to the compiler optimization options. - * @note The default is @p TRUE. + * Frequency of the system timer that drives the system ticks. This also + * defines the system tick time unit. */ -#ifndef CH_OPTIMIZE_SPEED -#define CH_OPTIMIZE_SPEED TRUE +#if !defined(CH_FREQUENCY) || defined(__DOXYGEN__) +#define CH_FREQUENCY 1000 +#endif + +/** + * This constant is the number of system ticks allowed for the threads before + * preemption occurs. This option is only meaningful if the option + * @p CH_USE_ROUNDROBIN is also active. + */ +#if !defined(CH_TIME_QUANTUM) || defined(__DOXYGEN__) +#define CH_TIME_QUANTUM 20 #endif /** @@ -43,10 +54,10 @@ * For performance and code size reasons the recommended setting is to leave * this option disabled.
* You can use this option if you need to merge ChibiOS/RT with external - * libraries that require nested lock/unlock operations. + * libraries that require nested lock/unlock operations. * @note The default is @p FALSE. */ -#ifndef CH_USE_NESTED_LOCKS +#if !defined(CH_USE_NESTED_LOCKS) || defined(__DOXYGEN__) #define CH_USE_NESTED_LOCKS FALSE #endif @@ -55,15 +66,62 @@ * on threads of equal priority. * @note The default is @p TRUE. */ -#ifndef CH_USE_ROUNDROBIN +#if !defined(CH_USE_ROUNDROBIN) || defined(__DOXYGEN__) #define CH_USE_ROUNDROBIN TRUE #endif +/** + * Number of RAM bytes to use as system heap. If set to zero then the whole + * available RAM is used as system heap. + * @note In order to use the whole RAM as system heap the linker script must + * provide the @p __heap_base__ and @p __heap_end__ symbols. + * @note Requires @p CH_USE_HEAP. + */ +#if !defined(CH_HEAP_SIZE) || defined(__DOXYGEN__) +#define CH_HEAP_SIZE 0 +#endif + +/*===========================================================================*/ +/* Performance options. */ +/*===========================================================================*/ + +/** + * If specified then time efficient rather than space efficient code is used + * when two possible implementations exist. + * @note This is not related to the compiler optimization options. + * @note The default is @p TRUE. + */ +#if !defined(CH_OPTIMIZE_SPEED) || defined(__DOXYGEN__) +#define CH_OPTIMIZE_SPEED TRUE +#endif + +/** + * If enabled defines a CPU register to be used as storage for the global + * @p currp variable. Caching this variable in a register can greatly + * improve both space and time efficiency of the generated code. Another side + * effect is that one less register has to be saved during the context switch + * resulting in lower RAM usage and faster code. + * @note This option is only usable with the GCC compiler and is only useful + * on processors with many registers like ARM cores. + * @note If this option is enabled then ALL the libraries linked to the + * ChibiOS/RT code must be recompiled with the GCC option @p + * -ffixed-@. + * @note This option must be enabled in the Makefile, it is listed here for + * documentation. + */ +#if defined(__DOXYGEN__) +#define CH_CURRP_REGISTER_CACHE "reg" +#endif + +/*===========================================================================*/ +/* Subsystem options. */ +/*===========================================================================*/ + /** * If specified then the @p chThdWait() function is included in the kernel. * @note The default is @p TRUE. */ -#ifndef CH_USE_WAITEXIT +#if !defined(CH_USE_WAITEXIT) || defined(__DOXYGEN__) #define CH_USE_WAITEXIT TRUE #endif @@ -71,7 +129,7 @@ * If specified then the Semaphores APIs are included in the kernel. * @note The default is @p TRUE. */ -#ifndef CH_USE_SEMAPHORES +#if !defined(CH_USE_SEMAPHORES) || defined(__DOXYGEN__) #define CH_USE_SEMAPHORES TRUE #endif @@ -81,7 +139,7 @@ * @note The default is @p FALSE. Enable this if you have special requirements. * @note Requires @p CH_USE_SEMAPHORES. */ -#ifndef CH_USE_SEMAPHORES_PRIORITY +#if !defined(CH_USE_SEMAPHORES_PRIORITY) || defined(__DOXYGEN__) #define CH_USE_SEMAPHORES_PRIORITY FALSE #endif @@ -91,7 +149,7 @@ * @note The default is @p TRUE. * @note Requires @p CH_USE_SEMAPHORES. */ -#ifndef CH_USE_SEMSW +#if !defined(CH_USE_SEMSW) || defined(__DOXYGEN__) #define CH_USE_SEMSW TRUE #endif @@ -101,7 +159,7 @@ * @note The default is @p TRUE. * @note Requires @p CH_USE_SEMAPHORES. */ -#ifndef CH_USE_SEMAPHORES_TIMEOUT +#if !defined(CH_USE_SEMAPHORES_TIMEOUT) || defined(__DOXYGEN__) #define CH_USE_SEMAPHORES_TIMEOUT TRUE #endif @@ -109,7 +167,7 @@ * If specified then the Mutexes APIs are included in the kernel. * @note The default is @p TRUE. */ -#ifndef CH_USE_MUTEXES +#if !defined(CH_USE_MUTEXES) || defined(__DOXYGEN__) #define CH_USE_MUTEXES TRUE #endif @@ -118,7 +176,7 @@ * @note The default is @p TRUE. * @note Requires @p CH_USE_MUTEXES. */ -#ifndef CH_USE_CONDVARS +#if !defined(CH_USE_CONDVARS) || defined(__DOXYGEN__) #define CH_USE_CONDVARS TRUE #endif @@ -127,7 +185,7 @@ * @note The default is @p TRUE. * @note Requires @p CH_USE_CONDVARS. */ -#ifndef CH_USE_CONDVARS_TIMEOUT +#if !defined(CH_USE_CONDVARS_TIMEOUT) || defined(__DOXYGEN__) #define CH_USE_CONDVARS_TIMEOUT TRUE #endif @@ -135,7 +193,7 @@ * If specified then the Event flags APIs are included in the kernel. * @note The default is @p TRUE. */ -#ifndef CH_USE_EVENTS +#if !defined(CH_USE_EVENTS) || defined(__DOXYGEN__) #define CH_USE_EVENTS TRUE #endif @@ -145,7 +203,7 @@ * @note The default is @p TRUE. * @note Requires @p CH_USE_EVENTS. */ -#ifndef CH_USE_EVENTS_TIMEOUT +#if !defined(CH_USE_EVENTS_TIMEOUT) || defined(__DOXYGEN__) #define CH_USE_EVENTS_TIMEOUT TRUE #endif @@ -153,7 +211,7 @@ * If specified then the Synchronous Messages APIs are included in the kernel. * @note The default is @p TRUE. */ -#ifndef CH_USE_MESSAGES +#if !defined(CH_USE_MESSAGES) || defined(__DOXYGEN__) #define CH_USE_MESSAGES TRUE #endif @@ -163,7 +221,7 @@ * @note The default is @p TRUE. * @note Requires @p CH_USE_MESSAGES and @p CH_USE_EVENTS. */ -#ifndef CH_USE_MESSAGES_EVENT +#if !defined(CH_USE_MESSAGES_EVENT) || defined(__DOXYGEN__) #define CH_USE_MESSAGES_EVENT TRUE #endif @@ -172,16 +230,25 @@ * @note The default is @p FALSE. Enable this if you have special requirements. * @note Requires @p CH_USE_MESSAGES. */ -#ifndef CH_USE_MESSAGES_PRIORITY +#if !defined(CH_USE_MESSAGES_PRIORITY) || defined(__DOXYGEN__) #define CH_USE_MESSAGES_PRIORITY FALSE #endif +/** + * If specified then the Asynchronous Messages (Mailboxes) APIs are included + * in the kernel. + * @note The default is @p TRUE. + */ +#if !defined(CH_USE_MAILBOXES) || defined(__DOXYGEN__) +#define CH_USE_MAILBOXES TRUE +#endif + /** * If specified then the I/O queues APIs are included in the kernel. * @note The default is @p TRUE. * @note Requires @p CH_USE_SEMAPHORES. */ -#ifndef CH_USE_QUEUES +#if !defined(CH_USE_QUEUES) || defined(__DOXYGEN__) #define CH_USE_QUEUES TRUE #endif @@ -190,7 +257,7 @@ * @note The default is @p TRUE. * @note Requires @p CH_USE_SEMAPHORES. */ -#ifndef CH_USE_QUEUES_HALFDUPLEX +#if !defined(CH_USE_QUEUES_HALFDUPLEX) || defined(__DOXYGEN__) #define CH_USE_QUEUES_HALFDUPLEX TRUE #endif @@ -200,7 +267,7 @@ * @note The default is @p TRUE. * @note Requires @p CH_USE_QUEUES and @p CH_USE_SEMAPHORES_TIMEOUT. */ -#ifndef CH_USE_QUEUES_TIMEOUT +#if !defined(CH_USE_QUEUES_TIMEOUT) || defined(__DOXYGEN__) #define CH_USE_QUEUES_TIMEOUT TRUE #endif @@ -210,7 +277,7 @@ * @note The default is @p TRUE. * @note Requires @p CH_USE_QUEUES. */ -#ifndef CH_USE_SERIAL_FULLDUPLEX +#if !defined(CH_USE_SERIAL_FULLDUPLEX) || defined(__DOXYGEN__) #define CH_USE_SERIAL_FULLDUPLEX TRUE #endif @@ -220,7 +287,7 @@ * @note The default is @p TRUE. * @note Requires @p CH_USE_QUEUES_HALFDUPLEX. */ -#ifndef CH_USE_SERIAL_HALFDUPLEX +#if !defined(CH_USE_SERIAL_HALFDUPLEX) || defined(__DOXYGEN__) #define CH_USE_SERIAL_HALFDUPLEX TRUE #endif @@ -230,28 +297,17 @@ * @note Requires @p CH_USE_MUTEXES or @p CH_USE_SEMAPHORES. * @note Mutexes are recommended. */ -#ifndef CH_USE_HEAP +#if !defined(CH_USE_HEAP) || defined(__DOXYGEN__) #define CH_USE_HEAP TRUE #endif -/** - * Number of RAM bytes to use as system heap. If set to zero then the whole - * available RAM is used as system heap. - * @note In order to use the whole RAM as system heap the linker script must - * provide the @p __heap_base__ and @p __heap_end__ symbols. - * @note Requires @p CH_USE_HEAP. - */ -#ifndef CH_HEAP_SIZE -#define CH_HEAP_SIZE 0 -#endif - /** * If enabled enforces the use of the C-runtime @p malloc() and @p free() * functions as backend for the system heap allocator. * @note The default is @p FALSE. * @note Requires @p CH_USE_HEAP. */ -#ifndef CH_USE_MALLOC_HEAP +#if !defined(CH_USE_MALLOC_HEAP) || defined(__DOXYGEN__) #define CH_USE_MALLOC_HEAP FALSE #endif @@ -260,7 +316,7 @@ * kernel. * @note The default is @p TRUE. */ -#ifndef CH_USE_MEMPOOLS +#if !defined(CH_USE_MEMPOOLS) || defined(__DOXYGEN__) #define CH_USE_MEMPOOLS TRUE #endif @@ -270,44 +326,13 @@ * @note The default is @p TRUE. * @note Requires @p CH_USE_WAITEXIT. */ -#ifndef CH_USE_DYNAMIC +#if !defined(CH_USE_DYNAMIC) || defined(__DOXYGEN__) #define CH_USE_DYNAMIC TRUE #endif -/** - * Frequency of the system timer that drives the system ticks. This also - * defines the system tick time unit. - */ -#ifndef CH_FREQUENCY -#define CH_FREQUENCY 1000 -#endif - -/** - * This constant is the number of system ticks allowed for the threads before - * preemption occurs. This option is only meaningful if the option - * @p CH_USE_ROUNDROBIN is also active. - */ -#ifndef CH_TIME_QUANTUM -#define CH_TIME_QUANTUM 20 -#endif - -/** - * If enabled defines a CPU register to be used as storage for the global - * @p currp variable. Caching this variable in a register can greatly - * improve both space and time efficiency of the generated code. Another side - * effect is that one less register has to be saved during the context switch - * resulting in lower RAM usage and faster code. - * @note This option is only usable with the GCC compiler and is only useful - * on processors with many registers like ARM cores. - * @note If this option is enabled then ALL the libraries linked to the - * ChibiOS/RT code must be recompiled with the GCC option @p - * -ffixed-@. - * @note This option must be enabled in the Makefile, it is listed here for - * documentation. - */ -#if defined(__DOXYGEN__) -#define CH_CURRP_REGISTER_CACHE "reg" -#endif +/*===========================================================================*/ +/* Debug options. */ +/*===========================================================================*/ /** * Debug option, if enabled all the assertions in the kernel code are @@ -315,7 +340,7 @@ * checks inside the kernel. * @note The default is @p FALSE. */ -#ifndef CH_DBG_ENABLE_ASSERTS +#if !defined(CH_DBG_ENABLE_ASSERTS) || defined(__DOXYGEN__) #define CH_DBG_ENABLE_ASSERTS FALSE #endif @@ -324,22 +349,43 @@ * activated. * @note The default is @p FALSE. */ -#ifndef CH_DBG_ENABLE_TRACE +#if !defined(CH_DBG_ENABLE_TRACE) || defined(__DOXYGEN__) #define CH_DBG_ENABLE_TRACE FALSE #endif +/** + * Debug option, if enabled a runtime stack check is performed. + * @note The stack check is performed in a architecture/port dependent way. It + * may not be implemented at all. + */ +#if !defined(CH_DBG_ENABLE_STACK_CHECK) || defined(__DOXYGEN__) +#define CH_DBG_ENABLE_STACK_CHECK FALSE +#endif + /** * Debug option, if enabled the threads working area is filled with a byte * pattern when a thread is created. */ -#ifndef CH_DBG_FILL_THREADS +#if !defined(CH_DBG_FILL_THREADS) || defined(__DOXYGEN__) #define CH_DBG_FILL_THREADS FALSE #endif +/** + * Debug option, if enabled a field is added to the @p Thread structure that + * counts the system ticks occurred while executing the thread. + */ +#if !defined(CH_DBG_THREADS_PROFILING) || defined(__DOXYGEN__) +#define CH_DBG_THREADS_PROFILING FALSE +#endif + +/*===========================================================================*/ +/* Kernel hooks. */ +/*===========================================================================*/ + /** * User fields added to the end of the @p Thread structure. */ -#ifndef THREAD_EXT_FIELDS +#if !defined(THREAD_EXT_FIELDS) || defined(__DOXYGEN__) #define THREAD_EXT_FIELDS \ struct { \ /* Add thread custom fields here.*/ \ @@ -350,7 +396,7 @@ struct { \ * User initialization code added to the @p chThdInit() API. * @note It is invoked from within @p chThdInit(). */ -#ifndef THREAD_EXT_INIT +#if !defined(THREAD_EXT_INIT) || defined(__DOXYGEN__) #define THREAD_EXT_INIT(tp) { \ /* Add thread initialization code here.*/ \ } @@ -360,7 +406,7 @@ struct { \ * User finalization code added to the @p chThdExit() API. * @note It is inserted into lock zone. */ -#ifndef THREAD_EXT_EXIT +#if !defined(THREAD_EXT_EXIT) || defined(__DOXYGEN__) #define THREAD_EXT_EXIT(tp) { \ /* Add thread finalization code here.*/ \ } @@ -370,7 +416,7 @@ struct { \ * Code inserted inside the idle thread loop immediately after an interrupt * resumed execution. */ -#ifndef IDLE_LOOP_HOOK +#if !defined(IDLE_LOOP_HOOK) || defined(__DOXYGEN__) #define IDLE_LOOP_HOOK() { \ /* Idle loop code here.*/ \ } diff --git a/src/templates/chcore.c b/src/templates/chcore.c index 7f64ee35b..9d09784ef 100644 --- a/src/templates/chcore.c +++ b/src/templates/chcore.c @@ -119,9 +119,13 @@ void port_halt(void) { /** * @brief Performs a context switch between two threads. + * @details This is the most critical code in any port, this function + * is responsible for the context switch between 2 threads. * * @param otp the thread to be switched out * @param ntp the thread to be switched in + * @note The implementation of this code affects directly the context + * switch performance so optimize here as much as you can. */ void port_switch(Thread *otp, Thread *ntp) { } -- cgit v1.2.3