aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--readme.txt6
-rw-r--r--src/include/condvars.h15
-rw-r--r--src/include/events.h16
-rw-r--r--src/include/lists.h50
-rw-r--r--src/include/mutexes.h16
-rw-r--r--src/include/semaphores.h20
-rw-r--r--test/testevt.c8
-rw-r--r--test/testmtx.c10
-rw-r--r--test/testsem.c7
-rw-r--r--todo.txt4
10 files changed, 120 insertions, 32 deletions
diff --git a/readme.txt b/readme.txt
index 9baa121b5..596122629 100644
--- a/readme.txt
+++ b/readme.txt
@@ -84,16 +84,16 @@ Win32-MinGW - ChibiOS/RT simulator and demo into a WIN32 process,
- NEW: Abstract I/O Channels mechanism introduced. This mechanism allows to
access I/O resources through a standard interface and hides implementation
details. The existing serial drivers were modified to offer a standard
- channel interface to the applications.
+ channel interface to the applications (the old APIs are retained as macros).
- NEW: The I/O queues code was improved, now there are 2 separate structures:
InputQueue and OutputQueue. There are some changes in the queue APIs
in order to make them more symmetrical and functional. Improved the queues
documentation. Some of the changes were needed in order to support the new
channels mechanism as a backend for queued serial drivers.
-- NEW: Added test cases for the improved queues.
-- NEW: Added a code coverage analysis application under ./tests/coverage.
- NEW: Added more test cases in order to improve the test suite code coverage
(it was 74% in version 1.2.0, it is now close to 100%).
+- NEW: Added test cases for the improved queues and serial drivers.
+- NEW: Added a code coverage analysis application under ./tests/coverage.
- NEW: Added the test suite documentation to the general documentation.
- NEW: Added a new "naked" context switch benchmark that better defines the
real context switch time, previous benchmarks introduced too much overhead
diff --git a/src/include/condvars.h b/src/include/condvars.h
index 90c78eccf..d68637f21 100644
--- a/src/include/condvars.h
+++ b/src/include/condvars.h
@@ -58,6 +58,21 @@ extern "C" {
}
#endif
+/**
+ * @brief Data part of a static condition variable initializer.
+ * @details This macro should be used when statically initializing a condition
+ * variable that is part of a bigger structure.
+ */
+#define _CONDVAR_DATA(name) {_THREADSQUEUE_DATA(name.c_queue)}
+
+/**
+ * @brief Static condition variable initializer.
+ * @details Statically initialized condition variables require no explicit
+ * initialization using @p chCondInit().
+ * @param name the name of the condition variable
+ */
+#define CONDVAR_DECL(name) CondVar name = _CONDVAR_DATA(name)
+
#endif /* CH_USE_CONDVARS && CH_USE_MUTEXES */
#endif /* _CONDVARS_H_ */
diff --git a/src/include/events.h b/src/include/events.h
index ada7812d1..6b79553ed 100644
--- a/src/include/events.h
+++ b/src/include/events.h
@@ -104,6 +104,22 @@ extern "C" {
#endif
/**
+ * @brief Data part of a static event source initializer.
+ * @details This macro should be used when statically initializing an event
+ * source that is part of a bigger structure.
+ * @param name the name of the event source variable
+ */
+#define _EVENTSOURCE_DATA(name) {(EventListener *)&name}
+
+/**
+ * @brief Static event source initializer.
+ * @details Statically initialized event sources require no explicit
+ * initialization using @p chEvtInit().
+ * @param name the name of the event source variable
+ */
+#define EVENTSOURCE_DECL(name) EventSource name = _EVENTSOURCE_DATA(name)
+
+/**
* Registers an Event Listener on an Event Source.
* @param esp pointer to the @p EventSource structure
* @param elp pointer to the @p EventListener structure
diff --git a/src/include/lists.h b/src/include/lists.h
index 89fdb84a7..3783f8749 100644
--- a/src/include/lists.h
+++ b/src/include/lists.h
@@ -29,39 +29,47 @@
typedef struct Thread Thread;
-/* Macros good with both ThreadsQueue and ThreadsList.*/
+/**
+ * Threads queue initialization.
+ */
+#define queue_init(tqp) ((tqp)->p_next = (tqp)->p_prev = (Thread *)(tqp));
+
+/**
+ * Macro evaluating to @p TRUE if the specified threads queue is empty.
+ */
#define isempty(p) ((p)->p_next == (Thread *)(p))
-#define notempty(p) ((p)->p_next != (Thread *)(p))
/**
- * @brief Generic threads bidirectional linked list header and element.
- * @extends ThreadsList
+ * Macro evaluating to @p TRUE if the specified threads queue is not empty.
*/
-typedef struct {
- Thread *p_next; /**< First @p Thread in the queue, or
- @p ThreadQueue when empty.*/
- Thread *p_prev; /**< Last @p Thread in the queue, or
- @p ThreadQueue when empty.*/
-} ThreadsQueue;
+#define notempty(p) ((p)->p_next != (Thread *)(p))
/**
- * @brief Generic threads single linked list.
- * @details This list behaves like a stack.
+ * @brief Data part of a static threads queue initializer.
+ * @details This macro should be used when statically initializing a threads
+ * queue that is part of a bigger structure.
+ * @param name the name of the threads queue variable
*/
-typedef struct {
- Thread *p_next; /**< Last pushed @p Thread on the stack,
- or @p ThreadList when empty.*/
-} ThreadsList;
+#define _THREADSQUEUE_DATA(name) {(Thread *)&name, (Thread *)&name}
/**
- * Queue initialization.
+ * @brief Static threads queue initializer.
+ * @details Statically initialized threads queues require no explicit
+ * initialization using @p queue_init().
+ * @param name the name of the threads queue variable
*/
-#define queue_init(tqp) ((tqp)->p_next = (tqp)->p_prev = (Thread *)(tqp));
+#define THREADSQUEUE_DECL(name) ThreadsQueue name = _THREADSQUEUE_DATA(name)
/**
- * List initialization.
+ * @brief Generic threads bidirectional linked list header and element.
+ * @extends ThreadsList
*/
-#define list_init(tlp) ((tlp)->p_next = (Thread *)(tlp))
+typedef struct {
+ Thread *p_next; /**< First @p Thread in the queue, or
+ @p ThreadQueue when empty.*/
+ Thread *p_prev; /**< Last @p Thread in the queue, or
+ @p ThreadQueue when empty.*/
+} ThreadsQueue;
#if !CH_OPTIMIZE_SPEED
@@ -73,8 +81,6 @@ extern "C" {
Thread *fifo_remove(ThreadsQueue *tqp);
Thread *lifo_remove(ThreadsQueue *tqp);
Thread *dequeue(Thread *tp);
- void list_insert(Thread *tp, ThreadsList *tlp);
- Thread *list_remove(ThreadsList *tlp);
#ifdef __cplusplus
}
#endif
diff --git a/src/include/mutexes.h b/src/include/mutexes.h
index 16b59f695..6ef6e48f4 100644
--- a/src/include/mutexes.h
+++ b/src/include/mutexes.h
@@ -57,6 +57,22 @@ extern "C" {
#endif
/**
+ * @brief Data part of a static mutex initializer.
+ * @details This macro should be used when statically initializing a mutex
+ * that is part of a bigger structure.
+ * @param name the name of the mutex variable
+ */
+#define _MUTEX_DATA(name) {_THREADSQUEUE_DATA(name.m_queue), NULL, NULL}
+
+/**
+ * @brief Static mutex initializer.
+ * @details Statically initialized mutexes require no explicit initialization
+ * using @p chMtxInit().
+ * @param name the name of the mutex variable
+ */
+#define MUTEX_DECL(name) Mutex name = _MUTEX_DATA(name)
+
+/**
* Returns @p TRUE if the mutex queue contains at least a waiting thread.
*/
#define chMtxQueueNotEmptyS(mp) notempty(&(mp)->m_queue)
diff --git a/src/include/semaphores.h b/src/include/semaphores.h
index 10f784ffc..833fc5cd2 100644
--- a/src/include/semaphores.h
+++ b/src/include/semaphores.h
@@ -58,6 +58,24 @@ extern "C" {
#endif
/**
+ * @brief Data part of a static semaphore initializer.
+ * @details This macro should be used when statically initializing a semaphore
+ * that is part of a bigger structure.
+ * @param name the name of the semaphore variable
+ * @param n the counter initial value, this value must be non-negative
+ */
+#define _SEMAPHORE_DATA(name, n) {_THREADSQUEUE_DATA(name.s_queue), n}
+
+/**
+ * @brief Static semaphore initializer.
+ * @details Statically initialized semaphores require no explicit initialization
+ * using @p chSemInit().
+ * @param name the name of the semaphore variable
+ * @param n the counter initial value, this value must be non-negative
+ */
+#define SEMAPHORE_DECL(name, n) Semaphore name = _SEMAPHORE_DATA(name, n)
+
+/**
* Decreases the semaphore counter, this macro can be used when it is ensured
* that the counter would not become negative.
*/
@@ -72,7 +90,7 @@ extern "C" {
/**
* Returns the semaphore counter current value.
*/
-#define chSemGetCounterI(sp) ((sp)->s_cnt)
+#define chSemGetCounterI(sp) ((sp)->s_cnt)
#endif /* CH_USE_SEMAPHORES */
diff --git a/test/testevt.c b/test/testevt.c
index 31f8870b0..e053737a5 100644
--- a/test/testevt.c
+++ b/test/testevt.c
@@ -54,7 +54,13 @@
#define ALLOWED_DELAY MS2ST(5)
-static EventSource es1, es2;
+/*
+ * Note, the static initializers are not really required because the
+ * variables are explicitly initialized in each test case. It is done in order
+ * to test the macros.
+ */
+static EVENTSOURCE_DECL(es1);
+static EVENTSOURCE_DECL(es2);
/**
* @page test_events_001 Events registration and dispatch
diff --git a/test/testmtx.c b/test/testmtx.c
index 030b8ab87..6027aca7e 100644
--- a/test/testmtx.c
+++ b/test/testmtx.c
@@ -63,8 +63,14 @@
#define ALLOWED_DELAY 5
-static Mutex m1, m2;
-static CondVar c1;
+/*
+ * Note, the static initializers are not really required because the
+ * variables are explicitly initialized in each test case. It is done in order
+ * to test the macros.
+ */
+static MUTEX_DECL(m1);
+static MUTEX_DECL(m2);
+static CONDVAR_DECL(c1);
/**
* @page test_mtx_001 Priority enqueuing test
diff --git a/test/testsem.c b/test/testsem.c
index 7cb103789..46c6a7941 100644
--- a/test/testsem.c
+++ b/test/testsem.c
@@ -53,7 +53,12 @@
#define ALLOWED_DELAY MS2ST(5)
-static Semaphore sem1;
+/*
+ * Note, the static initializers are not really required because the
+ * variables are explicitly initialized in each test case. It is done in order
+ * to test the macros.
+ */
+static SEMAPHORE_DECL(sem1, 0);
/**
* @page test_sem_001 Enqueuing test
diff --git a/todo.txt b/todo.txt
index 801ec4302..1d674618a 100644
--- a/todo.txt
+++ b/todo.txt
@@ -8,8 +8,8 @@ After 1.2.0:
* Abstract I/O channels rather than just serial ports.
? Move the serial drivers implementations in library. Better keep the core
as compact as possible.
-X Add tests documentation to the general documentation via doxygen.
-- Static object initializers.
+* Add tests documentation to the general documentation via doxygen.
+X Static object initializers.
- Remove any instance of unnamed structures/unions.
- Objects registry in the kernel.
- OSEK-style simple tasks within the idle thread.