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
This commit is contained in:
parent
b20088a8cb
commit
53f1b74772
|
@ -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.
|
||||
|
|
|
@ -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_ */
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 \
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
2
todo.txt
2
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.
|
||||
|
|
Loading…
Reference in New Issue