Added static initializers to input and output queues.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@976 35acf78f-673a-0410-8e92-d51de3d6d3f4
master
gdisirio 2009-05-16 11:53:48 +00:00
parent 2706d240bb
commit dd6e2f3911
5 changed files with 94 additions and 15 deletions

View File

@ -102,6 +102,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.
@ -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

View File

@ -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];

View File

@ -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_ */

View File

@ -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
};

View File

@ -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.