aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/include/queues.h60
-rw-r--r--test/test.c11
-rw-r--r--test/test.h5
-rw-r--r--test/testqueues.c31
-rw-r--r--todo.txt2
5 files changed, 94 insertions, 15 deletions
diff --git a/src/include/queues.h b/src/include/queues.h
index 886707e7d..d6c7d46fc 100644
--- a/src/include/queues.h
+++ b/src/include/queues.h
@@ -103,6 +103,36 @@ typedef GenericQueue InputQueue;
#define chIQGet(iqp) chIQGetTimeout(iqp, TIME_INFINITE)
/**
+ * @brief Data part of a static input queue initializer.
+ * @details This macro should be used when statically initializing an
+ * input queue that is part of a bigger structure.
+ * @param name the name of the input queue variable
+ * @param buffer pointer to the queue buffer area
+ * @param size size of the queue buffer area
+ * @param inotify input notification callback pointer
+ */
+#define _INPUTQUEUE_DATA(name, buffer, size, inotify) { \
+ buffer, \
+ buffer + size, \
+ buffer, \
+ buffer, \
+ _SEMAPHORE_DATA(name.q_sem, 0), \
+ inotify \
+}
+
+/**
+ * @brief Static input queue initializer.
+ * @details Statically initialized input queues require no explicit
+ * initialization using @p chIQInit().
+ * @param name the name of the input queue variable
+ * @param buffer pointer to the queue buffer area
+ * @param size size of the queue buffer area
+ * @param inotify input notification callback pointer
+ */
+#define INPUTQUEUE_DECL(name, buffer, size, inotify) \
+ InputQueue name = _INPUTQUEUE_DATA(name, buffer, size, inotify)
+
+/**
* @brief Output queue structure.
* @details This structure represents a generic asymmetrical output queue.
* Reading from the queue is non-blocking and can be performed from
@@ -134,6 +164,36 @@ typedef GenericQueue OutputQueue;
*/
#define chOQPut(oqp, b) chOQPutTimeout(oqp, b, TIME_INFINITE)
+/**
+ * @brief Data part of a static output queue initializer.
+ * @details This macro should be used when statically initializing an
+ * output queue that is part of a bigger structure.
+ * @param name the name of the output queue variable.
+ * @param buffer pointer to the queue buffer area
+ * @param size size of the queue buffer area
+ * @param onotify output notification callback pointer
+ */
+#define _OUTPUTQUEUE_DATA(name, buffer, size, onotify) { \
+ buffer, \
+ buffer + size, \
+ buffer, \
+ buffer, \
+ _SEMAPHORE_DATA(name.q_sem, size), \
+ onotify \
+}
+
+/**
+ * @brief Static output queue initializer.
+ * @details Statically initialized output queues require no explicit
+ * initialization using @p chOQInit().
+ * @param name the name of the output queue variable
+ * @param buffer pointer to the queue buffer area
+ * @param size size of the queue buffer area
+ * @param onotify output notification callback pointer
+ */
+#define OUTPUTQUEUE_DECL(name, buffer, size, onotify) \
+ InputQueue name = _OUTPUTQUEUE_DATA(name, buffer, size, onotify)
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/test/test.c b/test/test.c
index 7d4e3f2b0..abbc1f0eb 100644
--- a/test/test.c
+++ b/test/test.c
@@ -56,11 +56,12 @@ static bool_t local_fail, global_fail;
static unsigned failpoint;
static char tokens_buffer[MAX_TOKENS];
static char *tokp;
-static WORKING_AREA(waT0, THREADS_STACK_SIZE);
-static WORKING_AREA(waT1, THREADS_STACK_SIZE);
-static WORKING_AREA(waT2, THREADS_STACK_SIZE);
-static WORKING_AREA(waT3, THREADS_STACK_SIZE);
-static WORKING_AREA(waT4, THREADS_STACK_SIZE);
+
+WORKING_AREA(waT0, THREADS_STACK_SIZE);
+WORKING_AREA(waT1, THREADS_STACK_SIZE);
+WORKING_AREA(waT2, THREADS_STACK_SIZE);
+WORKING_AREA(waT3, THREADS_STACK_SIZE);
+WORKING_AREA(waT4, THREADS_STACK_SIZE);
void *wa[MAX_THREADS] = {waT0, waT1, waT2, waT3, waT4};
Thread *threads[MAX_THREADS];
diff --git a/test/test.h b/test/test.h
index 761ee08b9..17972b5c6 100644
--- a/test/test.h
+++ b/test/test.h
@@ -95,6 +95,11 @@ extern "C" {
extern Thread *threads[MAX_THREADS];
extern void *wa[MAX_THREADS];
+extern WORKING_AREA(waT0, THREADS_STACK_SIZE);
+extern WORKING_AREA(waT1, THREADS_STACK_SIZE);
+extern WORKING_AREA(waT2, THREADS_STACK_SIZE);
+extern WORKING_AREA(waT3, THREADS_STACK_SIZE);
+extern WORKING_AREA(waT4, THREADS_STACK_SIZE);
extern bool_t test_timer_done;
#endif /* _TEST_H_ */
diff --git a/test/testqueues.c b/test/testqueues.c
index 6c460becf..36c90402b 100644
--- a/test/testqueues.c
+++ b/test/testqueues.c
@@ -57,6 +57,16 @@
#define TEST_QUEUES_SIZE 4
+static void notify(void) {}
+
+/*
+ * 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 INPUTQUEUE_DECL(iq, (uint8_t *)waT0, TEST_QUEUES_SIZE, notify);
+static OUTPUTQUEUE_DECL(oq, (uint8_t *)waT0, TEST_QUEUES_SIZE, notify);
+
/**
* @page test_queues_001 Input Queues functionality and APIs
*
@@ -65,18 +75,19 @@
* @p InputQueue object including timeouts. The queue state must remain
* consistent through the whole test.
*/
-static void notify(void) {}
static char *queues1_gettest(void) {
return "Queues, input queues";
}
-static void queues1_execute(void) {
- InputQueue iq;
- unsigned i;
+static void queues1_setup(void) {
chIQInit(&iq, wa[0], TEST_QUEUES_SIZE, notify);
+}
+
+static void queues1_execute(void) {
+ unsigned i;
/* Initial empty state */
test_assert(1, chIQIsEmpty(&iq), "not empty");
@@ -114,7 +125,7 @@ static void queues1_execute(void) {
const struct testcase testqueues1 = {
queues1_gettest,
- NULL,
+ queues1_setup,
NULL,
queues1_execute
};
@@ -132,11 +143,13 @@ static char *queues2_gettest(void) {
return "Queues, output queues";
}
-static void queues2_execute(void) {
- OutputQueue oq;
- unsigned i;
+static void queues2_setup(void) {
chOQInit(&oq, wa[0], TEST_QUEUES_SIZE, notify);
+}
+
+static void queues2_execute(void) {
+ unsigned i;
/* Initial empty state */
test_assert(1, chOQIsEmpty(&oq), "not empty");
@@ -172,7 +185,7 @@ static void queues2_execute(void) {
const struct testcase testqueues2 = {
queues2_gettest,
- NULL,
+ queues2_setup,
NULL,
queues2_execute
};
diff --git a/todo.txt b/todo.txt
index 1d674618a..e9628ec12 100644
--- a/todo.txt
+++ b/todo.txt
@@ -9,7 +9,7 @@ After 1.2.0:
? Move the serial drivers implementations in library. Better keep the core
as compact as possible.
* Add tests documentation to the general documentation via doxygen.
-X Static object initializers.
+* Static object initializers.
- Remove any instance of unnamed structures/unions.
- Objects registry in the kernel.
- OSEK-style simple tasks within the idle thread.