aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--demos/ARM7-AT91SAM7X-GCC/chconf.h4
-rw-r--r--demos/ARM7-AT91SAM7X-WEB-GCC/chconf.h4
-rw-r--r--demos/ARM7-LPC214x-G++/chconf.h4
-rw-r--r--demos/ARM7-LPC214x-GCC-minimal/chconf.h4
-rw-r--r--demos/ARM7-LPC214x-GCC/chconf.h4
-rw-r--r--demos/ARMCM3-STM32F103-GCC/chconf.h4
-rw-r--r--demos/AVR-AT90CANx-GCC/chconf.h216
-rw-r--r--demos/AVR-ATmega128-GCC/chconf.h216
-rw-r--r--demos/MSP430-MSP430x1611-GCC/chconf.h216
-rw-r--r--demos/Win32-MinGW/chconf.h4
-rw-r--r--docs/Doxyfile8
-rw-r--r--docs/ch.txt36
-rw-r--r--src/chmboxes.c152
-rw-r--r--src/chqueues.c4
-rw-r--r--src/chsys.c3
-rw-r--r--src/chthreads.c3
-rw-r--r--src/include/ch.h1
-rw-r--r--src/include/mailboxes.h85
-rw-r--r--src/include/semaphores.h4
-rw-r--r--src/include/sys.h4
-rw-r--r--src/include/threads.h4
-rw-r--r--src/kernel.mk16
-rw-r--r--src/templates/chconf.h212
-rw-r--r--src/templates/chcore.c4
24 files changed, 836 insertions, 376 deletions
diff --git a/demos/ARM7-AT91SAM7X-GCC/chconf.h b/demos/ARM7-AT91SAM7X-GCC/chconf.h
index 7c3520830..e8cc24807 100644
--- a/demos/ARM7-AT91SAM7X-GCC/chconf.h
+++ b/demos/ARM7-AT91SAM7X-GCC/chconf.h
@@ -239,8 +239,8 @@
* in the kernel.
* @note The default is @p TRUE.
*/
-#if !defined(CH_USE_MAILBOXESS) || defined(__DOXYGEN__)
-#define CH_USE_MAILBOXESS TRUE
+#if !defined(CH_USE_MAILBOXES) || defined(__DOXYGEN__)
+#define CH_USE_MAILBOXES TRUE
#endif
/**
diff --git a/demos/ARM7-AT91SAM7X-WEB-GCC/chconf.h b/demos/ARM7-AT91SAM7X-WEB-GCC/chconf.h
index 7c3520830..d91a2f743 100644
--- a/demos/ARM7-AT91SAM7X-WEB-GCC/chconf.h
+++ b/demos/ARM7-AT91SAM7X-WEB-GCC/chconf.h
@@ -239,8 +239,8 @@
* in the kernel.
* @note The default is @p TRUE.
*/
-#if !defined(CH_USE_MAILBOXESS) || defined(__DOXYGEN__)
-#define CH_USE_MAILBOXESS TRUE
+#if !defined(CH_USE_MAILBOXES) || defined(__DOXYGEN__)
+#define CH_USE_MAILBOXES TRUE
#endif
/**
diff --git a/demos/ARM7-LPC214x-G++/chconf.h b/demos/ARM7-LPC214x-G++/chconf.h
index 7c3520830..d91a2f743 100644
--- a/demos/ARM7-LPC214x-G++/chconf.h
+++ b/demos/ARM7-LPC214x-G++/chconf.h
@@ -239,8 +239,8 @@
* in the kernel.
* @note The default is @p TRUE.
*/
-#if !defined(CH_USE_MAILBOXESS) || defined(__DOXYGEN__)
-#define CH_USE_MAILBOXESS TRUE
+#if !defined(CH_USE_MAILBOXES) || defined(__DOXYGEN__)
+#define CH_USE_MAILBOXES TRUE
#endif
/**
diff --git a/demos/ARM7-LPC214x-GCC-minimal/chconf.h b/demos/ARM7-LPC214x-GCC-minimal/chconf.h
index 7c3520830..d91a2f743 100644
--- a/demos/ARM7-LPC214x-GCC-minimal/chconf.h
+++ b/demos/ARM7-LPC214x-GCC-minimal/chconf.h
@@ -239,8 +239,8 @@
* in the kernel.
* @note The default is @p TRUE.
*/
-#if !defined(CH_USE_MAILBOXESS) || defined(__DOXYGEN__)
-#define CH_USE_MAILBOXESS TRUE
+#if !defined(CH_USE_MAILBOXES) || defined(__DOXYGEN__)
+#define CH_USE_MAILBOXES TRUE
#endif
/**
diff --git a/demos/ARM7-LPC214x-GCC/chconf.h b/demos/ARM7-LPC214x-GCC/chconf.h
index 7c3520830..d91a2f743 100644
--- a/demos/ARM7-LPC214x-GCC/chconf.h
+++ b/demos/ARM7-LPC214x-GCC/chconf.h
@@ -239,8 +239,8 @@
* in the kernel.
* @note The default is @p TRUE.
*/
-#if !defined(CH_USE_MAILBOXESS) || defined(__DOXYGEN__)
-#define CH_USE_MAILBOXESS TRUE
+#if !defined(CH_USE_MAILBOXES) || defined(__DOXYGEN__)
+#define CH_USE_MAILBOXES TRUE
#endif
/**
diff --git a/demos/ARMCM3-STM32F103-GCC/chconf.h b/demos/ARMCM3-STM32F103-GCC/chconf.h
index 7c3520830..d91a2f743 100644
--- a/demos/ARMCM3-STM32F103-GCC/chconf.h
+++ b/demos/ARMCM3-STM32F103-GCC/chconf.h
@@ -239,8 +239,8 @@
* in the kernel.
* @note The default is @p TRUE.
*/
-#if !defined(CH_USE_MAILBOXESS) || defined(__DOXYGEN__)
-#define CH_USE_MAILBOXESS TRUE
+#if !defined(CH_USE_MAILBOXES) || defined(__DOXYGEN__)
+#define CH_USE_MAILBOXES TRUE
#endif
/**
diff --git a/demos/AVR-AT90CANx-GCC/chconf.h b/demos/AVR-AT90CANx-GCC/chconf.h
index da4744a16..15ce1a80d 100644
--- a/demos/AVR-AT90CANx-GCC/chconf.h
+++ b/demos/AVR-AT90CANx-GCC/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.<br>
* 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 512
+#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 <b>must</b> be recompiled with the GCC option @p
+ * -ffixed-@<reg@>.
+ * @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 512
-#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,52 +326,21 @@
* @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 <b>must</b> be recompiled with the GCC option @p
- * -ffixed-@<reg@>.
- * @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
* activated. This includes function parameters checks and consistency
- * checks inside the kernel.
+ * 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.
+ * 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/demos/AVR-ATmega128-GCC/chconf.h b/demos/AVR-ATmega128-GCC/chconf.h
index da4744a16..15ce1a80d 100644
--- a/demos/AVR-ATmega128-GCC/chconf.h
+++ b/demos/AVR-ATmega128-GCC/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.<br>
* 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 512
+#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 <b>must</b> be recompiled with the GCC option @p
+ * -ffixed-@<reg@>.
+ * @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 512
-#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,52 +326,21 @@
* @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 <b>must</b> be recompiled with the GCC option @p
- * -ffixed-@<reg@>.
- * @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
* activated. This includes function parameters checks and consistency
- * checks inside the kernel.
+ * 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.
+ * 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/demos/MSP430-MSP430x1611-GCC/chconf.h b/demos/MSP430-MSP430x1611-GCC/chconf.h
index e270a6ccf..109135795 100644
--- a/demos/MSP430-MSP430x1611-GCC/chconf.h
+++ b/demos/MSP430-MSP430x1611-GCC/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 100
+#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 10
#endif
/**
@@ -43,10 +54,10 @@
* For performance and code size reasons the recommended setting is to leave
* this option disabled.<br>
* 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 512
+#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 <b>must</b> be recompiled with the GCC option @p
+ * -ffixed-@<reg@>.
+ * @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 512
-#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,52 +326,21 @@
* @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 100
-#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 10
-#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 <b>must</b> be recompiled with the GCC option @p
- * -ffixed-@<reg@>.
- * @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
* activated. This includes function parameters checks and consistency
- * checks inside the kernel.
+ * 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.
+ * 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/demos/Win32-MinGW/chconf.h b/demos/Win32-MinGW/chconf.h
index e41f4410e..761819bba 100644
--- a/demos/Win32-MinGW/chconf.h
+++ b/demos/Win32-MinGW/chconf.h
@@ -239,8 +239,8 @@
* in the kernel.
* @note The default is @p TRUE.
*/
-#if !defined(CH_USE_MAILBOXESS) || defined(__DOXYGEN__)
-#define CH_USE_MAILBOXESS TRUE
+#if !defined(CH_USE_MAILBOXES) || defined(__DOXYGEN__)
+#define CH_USE_MAILBOXES TRUE
#endif
/**
diff --git a/docs/Doxyfile b/docs/Doxyfile
index a7d3a256d..71904c177 100644
--- a/docs/Doxyfile
+++ b/docs/Doxyfile
@@ -1308,10 +1308,14 @@ PREDEFINED = __DOXYGEN__ \
CH_USE_HEAP=1 \
CH_USE_MEMPOOLS=1 \
CH_USE_MESSAGES=1 \
+ CH_USE_MAILBOXES=1 \
CH_USE_MESSAGES_EVENT=1 \
- CH_USE_DEBUG=1 \
- CH_USE_TRACE=1 \
CH_USE_DYNAMIC=1 \
+ CH_DBG_ENABLE_ASSERTS=1 \
+ CH_DBG_ENABLE_TRACE=1 \
+ CH_DBG_ENABLE_STACK_CHECK=1 \
+ CH_DBG_FILL_THREADS=1 \
+ CH_DBG_THREADS_PROFILING=1 \
CH_USE_ROUNDROBIN=1
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
diff --git a/docs/ch.txt b/docs/ch.txt
index b62fa38ca..58a96870d 100644
--- a/docs/ch.txt
+++ b/docs/ch.txt
@@ -281,15 +281,15 @@
/** @} */
/**
- * @defgroup Messages Messages
+ * @defgroup Messages Synchronous Messages
* @{
* Synchronous inter-thread messages.
* <h2>Operation Mode</h2>
- * Messages are an easy to use and fast IPC mechanism, threads can both serve
- * messages and send messages to other threads, the mechanism allows data to
- * be carried in both directions. Data is not copied between the client and
- * server threads but just a pointer passed so the exchange is very time
- * efficient.<br>
+ * Synchronoud messages are an easy to use and fast IPC mechanism, threads
+ * can both serve messages and send messages to other threads, the mechanism
+ * allows data to be carried in both directions. Data is not copied between
+ * the client and server threads but just a pointer passed so the exchange
+ * is very time efficient.<br>
* Messages are usually processed in FIFO order but it is possible to process
* them in priority order by specifying CH_USE_MESSAGES_PRIORITY
* in @p chconf.h.<br>
@@ -302,6 +302,30 @@
/** @} */
/**
+ * @defgroup Mailboxes Mailboxes
+ * @{
+ * Asynchronous messages.
+ * <h2>Operation mode</h2>
+ * A mailbox is an asynchronous communication mechanism.<br>
+ * The following operations are possible on a mailbox:
+ * - <b>Post</b>: Posts a message on the mailbox in FIFO order.
+ * - <b>Post Ahead</b>: Posts a message on the mailbox with high priority.
+ * - <b>Fetch</b>: A message is fetched from the mailbox and removed from
+ * the queue.
+ * - <b>Reset</b>: The mailbox is emptied and all the stored messages lost.
+ * .
+ * A message is a variable of type msg_t that is guaranteed to have the
+ * same size of and be compatible with pointers (an explicit cast is needed).
+ * If larger messages need to be exchanged then a pointer to a structure can
+ * be posted in the mailbox but the posting side has no predefined way to
+ * know when the message has been processed. A possible approach is to
+ * allocate memory (from a memory pool as example) from the posting side and
+ * free it on the fetching side. Another approach is to set a "done" flag into
+ * the structure pointed by the message.
+ */
+/** @} */
+
+/**
* @defgroup IOQueues I/O Queues
* @{
* ChibiOS/RT supports several kinds of queues. The queues are mostly used
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 <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * @file chmboxes.c
+ * @brief Mailboxes code.
+ * @addtogroup Mailboxes
+ * @{
+ */
+
+#include <ch.h>
+
+#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
@@ -101,6 +101,9 @@ void chSysTimerHandlerI(void) {
/* 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 <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * @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 <b>directly</b> 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
@@ -50,6 +50,10 @@ struct Thread {
#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
* state-specific fields. This trick saves some extra space for each
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.<br>
* 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 <b>must</b> be recompiled with the GCC option @p
+ * -ffixed-@<reg@>.
+ * @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 <b>must</b> be recompiled with the GCC option @p
- * -ffixed-@<reg@>.
- * @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 <b>directly</b> the context
+ * switch performance so optimize here as much as you can.
*/
void port_switch(Thread *otp, Thread *ntp) {
}