git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2235 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
gdisirio 2010-10-05 14:05:25 +00:00
parent 2891f7d645
commit d5853de4bd
7 changed files with 95 additions and 15 deletions

View File

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

View File

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

View File

@ -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 <tt>board.h</tt>:
* - @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
* <tt>./os/ports/GCC/ARMCMx/STM32F10x/vectors.s</tt>.
* - The Cortex-Mx port is perfectly generic, support for more devices can be
* easily added by adding a subdirectory under <tt>./os/ports/GCC/ARMCMx</tt>
* 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
*/

View File

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

View File

@ -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 = {

View File

@ -189,7 +189,7 @@ ROMCONST struct testcase testsem2 = {
* @page test_sem_003 Atomic signal-wait test
*
* <h2>Description</h2>
* 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.<br>
* 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
*
* <h2>Description</h2>
* 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
};

View File

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