From d5853de4bd4603ba507999d45075031779b13912 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 5 Oct 2010 14:05:25 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2235 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/include/ch.h | 1 + os/kernel/include/chbsem.h | 22 +++++++++--------- os/ports/GCC/ARMCMx/port.dox | 14 ++++++++++++ readme.txt | 8 +++++-- test/testmtx.c | 5 ++++ test/testsem.c | 54 +++++++++++++++++++++++++++++++++++++++++++- test/testthd.c | 6 ++++- 7 files changed, 95 insertions(+), 15 deletions(-) diff --git a/os/kernel/include/ch.h b/os/kernel/include/ch.h index 3641c826f..d048b99b7 100644 --- a/os/kernel/include/ch.h +++ b/os/kernel/include/ch.h @@ -74,6 +74,7 @@ #include "chvt.h" #include "chschd.h" #include "chsem.h" +#include "chbsem.h" #include "chmtx.h" #include "chcond.h" #include "chevents.h" diff --git a/os/kernel/include/chbsem.h b/os/kernel/include/chbsem.h index 238ee2607..5726cd350 100644 --- a/os/kernel/include/chbsem.h +++ b/os/kernel/include/chbsem.h @@ -94,7 +94,7 @@ typedef struct { * * @init */ -#define chBSemInit(bsp, taken) chSemInit(&bsp->bs_sem, taken ? 0 : 1) +#define chBSemInit(bsp, taken) chSemInit(&(bsp)->bs_sem, (taken) ? 0 : 1) /** * @brief Wait operation on the binary semaphore. @@ -108,7 +108,7 @@ typedef struct { * * @api */ -#define chBSemWait(bsp) chSemWait(&bsp->bs_sem) +#define chBSemWait(bsp) chSemWait(&(bsp)->bs_sem) /** * @brief Wait operation on the binary semaphore. @@ -122,7 +122,7 @@ typedef struct { * * @sclass */ -#define chBSemWaitS(bsp) chSemWaitS(&bsp->bs_sem) +#define chBSemWaitS(bsp) chSemWaitS(&(bsp)->bs_sem) /** * @brief Wait operation on the binary semaphore. @@ -143,7 +143,7 @@ typedef struct { * * @api */ -#define chBSemWaitTimeout(bsp, time) chSemWaitTimeout(&bsp->bs_sem, time) +#define chBSemWaitTimeout(bsp, time) chSemWaitTimeout(&(bsp)->bs_sem, (time)) /** * @brief Wait operation on the binary semaphore. @@ -164,7 +164,7 @@ typedef struct { * * @sclass */ -#define chBSemWaitTimeoutS(bsp, time) chSemWaitTimeoutS(&bsp->bs_sem, time) +#define chBSemWaitTimeoutS(bsp, time) chSemWaitTimeoutS(&(bsp)->bs_sem, (time)) /** * @brief Reset operation on the binary semaphore. @@ -180,7 +180,7 @@ typedef struct { * * @api */ -#define chBSemReset(bsp, taken) chSemReset(&bsp->bs_sem, taken ? 0 : 1) +#define chBSemReset(bsp, taken) chSemReset(&(bsp)->bs_sem, (taken) ? 0 : 1) /** * @brief Reset operation on the binary semaphore. @@ -197,7 +197,7 @@ typedef struct { * * @iclass */ -#define chBSemResetI(bsp, taken) chSemResetI(&bsp->bs_sem, taken ? 0 : 1) +#define chBSemResetI(bsp, taken) chSemResetI(&(bsp)->bs_sem, (taken) ? 0 : 1) /** * @brief Performs a signal operation on a binary semaphore. @@ -208,7 +208,7 @@ typedef struct { */ #define chBSemSignal(bsp) { \ chSysLock(); \ - chBSemSignalI(bsp); \ + chBSemSignalI((bsp)); \ chSchRescheduleS(); \ chSysUnlock(); \ } @@ -222,8 +222,8 @@ typedef struct { * @iclass */ #define chBSemSignalI(bsp) { \ - if (bsp->bs_sem.s_cnt < 1) \ - chSemSignalI(&bsp->bs_sem); \ + if ((bsp)->bs_sem.s_cnt < 1) \ + chSemSignalI(&(bsp)->bs_sem); \ } /** @@ -236,7 +236,7 @@ typedef struct { * * @iclass */ -#define chBSemGetStateI(bsp) ((bsp)->bs_sem.s_cnt > 0 ? 0 : 1) +#define chBSemGetStateI(bsp) ((bsp)->bs_sem.s_cnt > 0 ? FALSE : TRUE) #endif /* CH_USE_SEMAPHORES */ diff --git a/os/ports/GCC/ARMCMx/port.dox b/os/ports/GCC/ARMCMx/port.dox index 3556d3196..2f91f27f3 100644 --- a/os/ports/GCC/ARMCMx/port.dox +++ b/os/ports/GCC/ARMCMx/port.dox @@ -106,6 +106,20 @@ * stack where all the interrupts and exceptions are processed. * - The threads are started in thread-privileged mode. * - Interrupt nesting and the other advanced core/NVIC features are supported. + * - When using an STM32 one of the following macros must be defined on the + * compiler command line or in a file named board.h: + * - @p STM32F10X_LD + * - @p STM32F10X_MD + * - @p STM32F10X_HD + * - @p STM32F10X_CL + * . + * This is required in order to include a vectors table with the correct + * length for the STM32 model, see the file + * ./os/ports/GCC/ARMCMx/STM32F10x/vectors.s. + * - The Cortex-Mx port is perfectly generic, support for more devices can be + * easily added by adding a subdirectory under ./os/ports/GCC/ARMCMx + * and giving it the name of the new device, then copy the files from another + * device into the new directory and customize them for the new device. * . * @ingroup gcc */ diff --git a/readme.txt b/readme.txt index ec4c18527..1250904a4 100644 --- a/readme.txt +++ b/readme.txt @@ -63,7 +63,7 @@ ***************************************************************************** *** 2.1.2 *** -- FIX: Fixed wrong macro check in STM32 serial support (but 3078891)(backported +- FIX: Fixed wrong macro check in STM32 serial support (bug 3078891)(backported to 2.0.6). - FIX: Fixed non functioning option CH_USE_NESTED_LOCKS (bug 3075544) (backported to 2.0.6). @@ -117,11 +117,15 @@ change). - NEW: Added to the documentation more notes about interrupt handlers in the ARM7 port. +- NEW: Modified some tests in order to bring back code coverage to 100% + in all modules except chdebug.c. Added a test case covering binary + semaphores. - OPT: The fix to the bug 3075544 considerably improved the threads creation benchmarks score. - OPT: Speed optimizations of the STM32 SPI driver, improved latency. - OPT: Speed optimizations of the STM32 ADC driver. -- CHANGE: The API chThdInit() has been renamed to chThdCreateI(). +- CHANGE: The API chThdInit() has been renamed to chThdCreateI() in order to + make clear it is useable from interrupt handlers. - CHANGE: The mailboxes macros chMBSize(), chMBGetEmpty(), chMBGetFull(), chMBPeek() have been renamed to chMBSizeI(), chMBGetEmptyI(), chMBGetFullI(), chMBPeekI(). diff --git a/test/testmtx.c b/test/testmtx.c index 339403127..9ca9edc85 100644 --- a/test/testmtx.c +++ b/test/testmtx.c @@ -452,6 +452,11 @@ static void mtx5_execute(void) { test_assert(3, isempty(&m1.m_queue), "queue not empty"); test_assert(4, m1.m_owner == NULL, "still owned"); test_assert(5, chThdGetPriority() == prio, "wrong priority level"); + + chMtxLock(&m1); + chMtxUnlockAll(); + test_assert(6, isempty(&m1.m_queue), "queue not empty"); + test_assert(7, m1.m_owner == NULL, "still owned"); } ROMCONST struct testcase testmtx5 = { diff --git a/test/testsem.c b/test/testsem.c index 798e3a65d..85535ed0a 100644 --- a/test/testsem.c +++ b/test/testsem.c @@ -189,7 +189,7 @@ ROMCONST struct testcase testsem2 = { * @page test_sem_003 Atomic signal-wait test * *

Description

- * This test case explicitly address the @p chSemWaitSignal() function. A + * This test case explicitly addresses the @p chSemWaitSignal() function. A * thread is created that performs a wait and a signal operations. * The tester thread is awakened from an atomic wait/signal operation.
* The test expects that the semaphore wait function returns the correct value @@ -229,6 +229,57 @@ ROMCONST struct testcase testsem3 = { sem3_execute }; #endif /* CH_USE_SEMSW */ + +/** + * @page test_sem_004 Binary Wait and Signal + * + *

Description

+ * This test case tests the binary semaphores functionality. The test both + * checks the binary semaphore status and the expected status of the underlying + * counting semaphore. + */ +static msg_t thread4(void *p) { + + chBSemSignal((BinarySemaphore *)p); + return 0; +} + +static void sem4_execute(void) { + BinarySemaphore bsem; + + /* Creates a taken binary semaphore.*/ + chBSemInit(&bsem, TRUE); + chBSemReset(&bsem, TRUE); + test_assert(1, chBSemGetStateI(&bsem) == TRUE, "not taken"); + + /* Starts a signaler thread at a lower priority.*/ + threads[0] = chThdCreateStatic(wa[0], WA_SIZE, + chThdGetPriority()-1, thread4, &bsem); + + /* Waits to be signaled.*/ + chBSemWait(&bsem); + + /* The binary semaphore is expected to be taken.*/ + test_assert(2, chBSemGetStateI(&bsem) == TRUE, "not taken"); + + /* Releasing it, check both the binary semaphore state and the underlying + counter semaphore state..*/ + chBSemSignal(&bsem); + test_assert(3, chBSemGetStateI(&bsem) == FALSE, "still taken"); + test_assert(4, chSemGetCounterI(&bsem.bs_sem) == 1, "unexpected counter"); + + /* Checking signaling overflow, the counter must not go beyond 1.*/ + chBSemSignal(&bsem); + test_assert(3, chBSemGetStateI(&bsem) == FALSE, "taken"); + test_assert(5, chSemGetCounterI(&bsem.bs_sem) == 1, "unexpected counter"); +} + +ROMCONST struct testcase testsem4 = { + "Binary Semaphores, functionality", + NULL, + NULL, + sem4_execute +}; #endif /* CH_USE_SEMAPHORES */ /** @@ -241,6 +292,7 @@ ROMCONST struct testcase * ROMCONST patternsem[] = { #if CH_USE_SEMSW &testsem3, #endif + &testsem4, #endif NULL }; diff --git a/test/testthd.c b/test/testthd.c index b12378320..8b0440248 100644 --- a/test/testthd.c +++ b/test/testthd.c @@ -100,7 +100,11 @@ static void thd2_execute(void) { threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()-5, thread, "E"); threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriority()-1, thread, "A"); threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriority()-2, thread, "B"); - threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriority()-3, thread, "C"); + /* Done this way for coverage of chThdCreateI() and chThdResume().*/ + chSysLock(); + threads[2] = chThdCreateI(wa[2], WA_SIZE, chThdGetPriority()-3, thread, "C"); + chSysUnlock(); + chThdResume(threads[2]); test_wait_threads(); test_assert_sequence(1, "ABCDE"); } -- cgit v1.2.3