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
This commit is contained in:
parent
2706d240bb
commit
dd6e2f3911
|
@ -102,6 +102,36 @@ typedef GenericQueue InputQueue;
|
||||||
*/
|
*/
|
||||||
#define chIQGet(iqp) chIQGetTimeout(iqp, TIME_INFINITE)
|
#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.
|
* @brief Output queue structure.
|
||||||
* @details This structure represents a generic asymmetrical output queue.
|
* @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)
|
#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
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
11
test/test.c
11
test/test.c
|
@ -56,11 +56,12 @@ static bool_t local_fail, global_fail;
|
||||||
static unsigned failpoint;
|
static unsigned failpoint;
|
||||||
static char tokens_buffer[MAX_TOKENS];
|
static char tokens_buffer[MAX_TOKENS];
|
||||||
static char *tokp;
|
static char *tokp;
|
||||||
static WORKING_AREA(waT0, THREADS_STACK_SIZE);
|
|
||||||
static WORKING_AREA(waT1, THREADS_STACK_SIZE);
|
WORKING_AREA(waT0, THREADS_STACK_SIZE);
|
||||||
static WORKING_AREA(waT2, THREADS_STACK_SIZE);
|
WORKING_AREA(waT1, THREADS_STACK_SIZE);
|
||||||
static WORKING_AREA(waT3, THREADS_STACK_SIZE);
|
WORKING_AREA(waT2, THREADS_STACK_SIZE);
|
||||||
static WORKING_AREA(waT4, THREADS_STACK_SIZE);
|
WORKING_AREA(waT3, THREADS_STACK_SIZE);
|
||||||
|
WORKING_AREA(waT4, THREADS_STACK_SIZE);
|
||||||
|
|
||||||
void *wa[MAX_THREADS] = {waT0, waT1, waT2, waT3, waT4};
|
void *wa[MAX_THREADS] = {waT0, waT1, waT2, waT3, waT4};
|
||||||
Thread *threads[MAX_THREADS];
|
Thread *threads[MAX_THREADS];
|
||||||
|
|
|
@ -95,6 +95,11 @@ extern "C" {
|
||||||
|
|
||||||
extern Thread *threads[MAX_THREADS];
|
extern Thread *threads[MAX_THREADS];
|
||||||
extern void *wa[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;
|
extern bool_t test_timer_done;
|
||||||
|
|
||||||
#endif /* _TEST_H_ */
|
#endif /* _TEST_H_ */
|
||||||
|
|
|
@ -57,6 +57,16 @@
|
||||||
|
|
||||||
#define TEST_QUEUES_SIZE 4
|
#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
|
* @page test_queues_001 Input Queues functionality and APIs
|
||||||
*
|
*
|
||||||
|
@ -65,18 +75,19 @@
|
||||||
* @p InputQueue object including timeouts. The queue state must remain
|
* @p InputQueue object including timeouts. The queue state must remain
|
||||||
* consistent through the whole test.
|
* consistent through the whole test.
|
||||||
*/
|
*/
|
||||||
static void notify(void) {}
|
|
||||||
|
|
||||||
static char *queues1_gettest(void) {
|
static char *queues1_gettest(void) {
|
||||||
|
|
||||||
return "Queues, input queues";
|
return "Queues, input queues";
|
||||||
}
|
}
|
||||||
|
|
||||||
static void queues1_execute(void) {
|
static void queues1_setup(void) {
|
||||||
InputQueue iq;
|
|
||||||
unsigned i;
|
|
||||||
|
|
||||||
chIQInit(&iq, wa[0], TEST_QUEUES_SIZE, notify);
|
chIQInit(&iq, wa[0], TEST_QUEUES_SIZE, notify);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void queues1_execute(void) {
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
/* Initial empty state */
|
/* Initial empty state */
|
||||||
test_assert(1, chIQIsEmpty(&iq), "not empty");
|
test_assert(1, chIQIsEmpty(&iq), "not empty");
|
||||||
|
@ -114,7 +125,7 @@ static void queues1_execute(void) {
|
||||||
|
|
||||||
const struct testcase testqueues1 = {
|
const struct testcase testqueues1 = {
|
||||||
queues1_gettest,
|
queues1_gettest,
|
||||||
NULL,
|
queues1_setup,
|
||||||
NULL,
|
NULL,
|
||||||
queues1_execute
|
queues1_execute
|
||||||
};
|
};
|
||||||
|
@ -132,11 +143,13 @@ static char *queues2_gettest(void) {
|
||||||
return "Queues, output queues";
|
return "Queues, output queues";
|
||||||
}
|
}
|
||||||
|
|
||||||
static void queues2_execute(void) {
|
static void queues2_setup(void) {
|
||||||
OutputQueue oq;
|
|
||||||
unsigned i;
|
|
||||||
|
|
||||||
chOQInit(&oq, wa[0], TEST_QUEUES_SIZE, notify);
|
chOQInit(&oq, wa[0], TEST_QUEUES_SIZE, notify);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void queues2_execute(void) {
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
/* Initial empty state */
|
/* Initial empty state */
|
||||||
test_assert(1, chOQIsEmpty(&oq), "not empty");
|
test_assert(1, chOQIsEmpty(&oq), "not empty");
|
||||||
|
@ -172,7 +185,7 @@ static void queues2_execute(void) {
|
||||||
|
|
||||||
const struct testcase testqueues2 = {
|
const struct testcase testqueues2 = {
|
||||||
queues2_gettest,
|
queues2_gettest,
|
||||||
NULL,
|
queues2_setup,
|
||||||
NULL,
|
NULL,
|
||||||
queues2_execute
|
queues2_execute
|
||||||
};
|
};
|
||||||
|
|
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
|
? Move the serial drivers implementations in library. Better keep the core
|
||||||
as compact as possible.
|
as compact as possible.
|
||||||
* Add tests documentation to the general documentation via doxygen.
|
* Add tests documentation to the general documentation via doxygen.
|
||||||
X Static object initializers.
|
* Static object initializers.
|
||||||
- Remove any instance of unnamed structures/unions.
|
- Remove any instance of unnamed structures/unions.
|
||||||
- Objects registry in the kernel.
|
- Objects registry in the kernel.
|
||||||
- OSEK-style simple tasks within the idle thread.
|
- OSEK-style simple tasks within the idle thread.
|
||||||
|
|
Loading…
Reference in New Issue