diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-05-16 14:49:41 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-05-16 14:49:41 +0000 |
commit | 53f1b747726d85020beca994f6fe67a5e9af7b8e (patch) | |
tree | 72bbc0235de15168314bc3b5c803464f2c16f667 | |
parent | b20088a8cb72e3f3e694e309671cd7f96fb552dc (diff) | |
download | ChibiOS-53f1b747726d85020beca994f6fe67a5e9af7b8e.tar.gz ChibiOS-53f1b747726d85020beca994f6fe67a5e9af7b8e.tar.bz2 ChibiOS-53f1b747726d85020beca994f6fe67a5e9af7b8e.zip |
Added static initializers for mailboxes and memory pools.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@978 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r-- | readme.txt | 4 | ||||
-rw-r--r-- | src/include/mailboxes.h | 28 | ||||
-rw-r--r-- | src/include/mempools.h | 19 | ||||
-rw-r--r-- | src/include/queues.h | 16 | ||||
-rw-r--r-- | test/testmbox.c | 10 | ||||
-rw-r--r-- | test/testpools.c | 2 | ||||
-rw-r--r-- | test/testqueues.c | 4 | ||||
-rw-r--r-- | todo.txt | 2 |
8 files changed, 70 insertions, 15 deletions
diff --git a/readme.txt b/readme.txt index 596122629..acbd5fff0 100644 --- a/readme.txt +++ b/readme.txt @@ -90,6 +90,10 @@ Win32-MinGW - ChibiOS/RT simulator and demo into a WIN32 process, 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: Static initializers macros introduced for most kernel objects. The
+ static initializers allow to not have to chXXXInit() any object and save some
+ code space. The initialization functions are retained in order to allow
+ initialization of dynamic objects and re-initializations.
- 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.
diff --git a/src/include/mailboxes.h b/src/include/mailboxes.h index 734a71bac..075806da8 100644 --- a/src/include/mailboxes.h +++ b/src/include/mailboxes.h @@ -91,6 +91,34 @@ extern "C" { */
#define chMBPeek(mbp) (*(mbp)->mb_rdptr)
+/**
+ * @brief Data part of a static mailbox initializer.
+ * @details This macro should be used when statically initializing a
+ * mailbox that is part of a bigger structure.
+ * @param name the name of the mailbox variable
+ * @param buffer pointer to the mailbox buffer area
+ * @param size size of the mailbox buffer area
+ */
+#define _MAILBOX_DATA(name, buffer, size) { \
+ (msg_t *)(buffer), \
+ (msg_t *)(buffer) + size, \
+ (msg_t *)(buffer), \
+ (msg_t *)(buffer), \
+ _SEMAPHORE_DATA(name.mb_fullsem, 0), \
+ _SEMAPHORE_DATA(name.mb_emptysem, size), \
+}
+
+/**
+ * @brief Static mailbox initializer.
+ * @details Statically initialized mailboxes require no explicit
+ * initialization using @p chMBInit().
+ * @param name the name of the mailbox variable
+ * @param buffer pointer to the mailbox buffer area
+ * @param size size of the mailbox buffer area
+ */
+#define MAILBOX_DECL(name, buffer, size) \
+ Mailbox name = _MAILBOX_DATA(name, buffer, size)
+
#endif /* CH_USE_MAILBOXES */
#endif /* _MAILBOXES_H_ */
diff --git a/src/include/mempools.h b/src/include/mempools.h index 537ca3425..38e54b3d8 100644 --- a/src/include/mempools.h +++ b/src/include/mempools.h @@ -44,6 +44,25 @@ typedef struct { size_t mp_object_size; /**< Memory pool objects size.*/
} MemoryPool;
+/**
+ * @brief Data part of a static memory pool initializer.
+ * @details This macro should be used when statically initializing a
+ * memory pool that is part of a bigger structure.
+ * @param name the name of the memory pool variable
+ * @param size size of the memory pool contained objects
+ */
+#define _MEMORYPOOL_DATA(name, size) {NULL, size}
+
+/**
+ * @brief Static memory pool initializer.
+ * @details Statically initialized memory pools require no explicit
+ * initialization using @p chPoolInit().
+ * @param name the name of the memory pool variable
+ * @param size size of the memory pool contained objects
+ */
+#define MEMORYPOOL_DECL(name, size) \
+ MemoryPool name = _MEMORYPOOL_DATA(name, size)
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/src/include/queues.h b/src/include/queues.h index d6c7d46fc..6bd98b4f1 100644 --- a/src/include/queues.h +++ b/src/include/queues.h @@ -112,10 +112,10 @@ typedef GenericQueue InputQueue; * @param inotify input notification callback pointer */ #define _INPUTQUEUE_DATA(name, buffer, size, inotify) { \ - buffer, \ - buffer + size, \ - buffer, \ - buffer, \ + (uint8_t *)(buffer), \ + (uint8_t *)(buffer) + size, \ + (uint8_t *)(buffer), \ + (uint8_t *)(buffer), \ _SEMAPHORE_DATA(name.q_sem, 0), \ inotify \ } @@ -174,10 +174,10 @@ typedef GenericQueue OutputQueue; * @param onotify output notification callback pointer */ #define _OUTPUTQUEUE_DATA(name, buffer, size, onotify) { \ - buffer, \ - buffer + size, \ - buffer, \ - buffer, \ + (uint8_t *)(buffer), \ + (uint8_t *)(buffer) + size, \ + (uint8_t *)(buffer), \ + (uint8_t *)(buffer), \ _SEMAPHORE_DATA(name.q_sem, size), \ onotify \ } diff --git a/test/testmbox.c b/test/testmbox.c index 2403afce6..a485c3a4e 100644 --- a/test/testmbox.c +++ b/test/testmbox.c @@ -55,8 +55,12 @@ #define ALLOWED_DELAY MS2ST(5)
#define MB_SIZE 5
-static msg_t mb1_buf[MB_SIZE];
-static Mailbox mb1;
+/*
+ * 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 MAILBOX_DECL(mb1, waT0, MB_SIZE);
/**
* @page test_mbox_001 Queuing and timeouts
@@ -74,7 +78,7 @@ static char *mbox1_gettest(void) { static void mbox1_setup(void) {
- chMBInit(&mb1, mb1_buf, MB_SIZE);
+ chMBInit(&mb1, (msg_t *)waT0, MB_SIZE);
}
static void mbox1_execute(void) {
diff --git a/test/testpools.c b/test/testpools.c index 78f19a91c..ce6716444 100644 --- a/test/testpools.c +++ b/test/testpools.c @@ -49,7 +49,7 @@ #if CH_USE_MEMPOOLS
-static MemoryPool mp1;
+static MEMORYPOOL_DECL(mp1, THD_WA_SIZE(THREADS_STACK_SIZE));
/**
* @page test_pools_001 Allocation and enqueuing test
diff --git a/test/testqueues.c b/test/testqueues.c index 36c90402b..fe79712eb 100644 --- a/test/testqueues.c +++ b/test/testqueues.c @@ -64,8 +64,8 @@ static void notify(void) {} * 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);
+static INPUTQUEUE_DECL(iq, waT0, TEST_QUEUES_SIZE, notify);
+static OUTPUTQUEUE_DECL(oq, waT0, TEST_QUEUES_SIZE, notify);
/**
* @page test_queues_001 Input Queues functionality and APIs
@@ -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.
|