git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@468 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
e6757ceef9
commit
875c8f3686
|
@ -31,9 +31,9 @@ static msg_t Thread1(void *arg) {
|
||||||
|
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
P6OUT |= P6_O_LED;
|
P6OUT |= P6_O_LED;
|
||||||
chThdSleep(50);
|
chThdSleep(MS2ST(500));
|
||||||
P6OUT &= ~P6_O_LED;
|
P6OUT &= ~P6_O_LED;
|
||||||
chThdSleep(50);
|
chThdSleep(MS2ST(500));
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ int main(int argc, char **argv) {
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
if (!(P6IN & P6_I_BUTTON))
|
if (!(P6IN & P6_I_BUTTON))
|
||||||
TestThread(&COM1);
|
TestThread(&COM1);
|
||||||
chThdSleep(50);
|
chThdSleep(MS2ST(500));
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,23 @@
|
||||||
#ifndef _SLEEP_H_
|
#ifndef _SLEEP_H_
|
||||||
#define _SLEEP_H_
|
#define _SLEEP_H_
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Time conversion utility. Converts from seconds to system ticks number.
|
||||||
|
*/
|
||||||
|
#define S2ST(sec) ((sec) * CH_FREQUENCY)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Time conversion utility. Converts from milliseconds to system ticks number.
|
||||||
|
* @note The result is rounded upward to the next tick boundary.
|
||||||
|
*/
|
||||||
|
#define MS2ST(msec) (((((msec) - 1L) * CH_FREQUENCY) / 1000) + 1)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Time conversion utility. Converts from microseconds to system ticks number.
|
||||||
|
* @note The result is rounded upward to the next tick boundary.
|
||||||
|
*/
|
||||||
|
#define US2ST(usec) (((((usec) - 1L) * CH_FREQUENCY) / 1000000) + 1)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
10
test/test.c
10
test/test.c
|
@ -182,10 +182,11 @@ void test_wait_threads(void) {
|
||||||
chThdWait(threads[i]);
|
chThdWait(threads[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_cpu_pulse(systime_t ms) {
|
void test_cpu_pulse(unsigned ms) {
|
||||||
|
|
||||||
|
systime_t duration = MS2ST(ms);
|
||||||
systime_t start = chSysGetTime();
|
systime_t start = chSysGetTime();
|
||||||
while (chSysInTimeWindow(start, start + ms)) {
|
while (chSysInTimeWindow(start, start + duration)) {
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
ChkIntSources();
|
ChkIntSources();
|
||||||
#endif
|
#endif
|
||||||
|
@ -209,11 +210,12 @@ static void tmr(void *p) {
|
||||||
test_timer_done = TRUE;
|
test_timer_done = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_start_timer(systime_t time) {
|
void test_start_timer(unsigned ms) {
|
||||||
|
|
||||||
|
systime_t duration = MS2ST(ms);
|
||||||
test_timer_done = FALSE;
|
test_timer_done = FALSE;
|
||||||
chSysLock();
|
chSysLock();
|
||||||
chVTSetI(&vt, time, tmr, NULL);
|
chVTSetI(&vt, duration, tmr, NULL);
|
||||||
chSysUnlock();
|
chSysUnlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
#define MAX_THREADS 5
|
#define MAX_THREADS 5
|
||||||
#define MAX_TOKENS 16
|
#define MAX_TOKENS 16
|
||||||
#define DELAY_BETWEEN_TESTS 200
|
#define DELAY_BETWEEN_TESTS MS2ST(200)
|
||||||
|
|
||||||
#if defined(CH_ARCHITECTURE_AVR) || defined(CH_ARCHITECTURE_MSP430)
|
#if defined(CH_ARCHITECTURE_AVR) || defined(CH_ARCHITECTURE_MSP430)
|
||||||
#define THREADS_STACK_SIZE 64
|
#define THREADS_STACK_SIZE 64
|
||||||
|
@ -53,8 +53,8 @@ extern "C" {
|
||||||
void test_terminate_threads(void);
|
void test_terminate_threads(void);
|
||||||
void test_wait_threads(void);
|
void test_wait_threads(void);
|
||||||
systime_t test_wait_tick(void);
|
systime_t test_wait_tick(void);
|
||||||
void test_cpu_pulse(systime_t ms);
|
void test_cpu_pulse(unsigned ms);
|
||||||
void test_start_timer(systime_t time);
|
void test_start_timer(unsigned ms);
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
void ChkIntSources(void);
|
void ChkIntSources(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -85,7 +85,7 @@ static void mtx2_teardown(void) {
|
||||||
|
|
||||||
static msg_t thread2(void *p) {
|
static msg_t thread2(void *p) {
|
||||||
|
|
||||||
chThdSleep(5);
|
chThdSleep(MS2ST(10));
|
||||||
chMtxLock(&m1);
|
chMtxLock(&m1);
|
||||||
chMtxUnlock();
|
chMtxUnlock();
|
||||||
test_emit_token(*(char *)p);
|
test_emit_token(*(char *)p);
|
||||||
|
@ -95,7 +95,7 @@ static msg_t thread2(void *p) {
|
||||||
static msg_t thread3(void *p) {
|
static msg_t thread3(void *p) {
|
||||||
|
|
||||||
chMtxLock(&m1);
|
chMtxLock(&m1);
|
||||||
chThdSleep(20);
|
chThdSleep(MS2ST(40));
|
||||||
chMtxUnlock();
|
chMtxUnlock();
|
||||||
test_emit_token(*(char *)p);
|
test_emit_token(*(char *)p);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -103,7 +103,7 @@ static msg_t thread3(void *p) {
|
||||||
|
|
||||||
static msg_t thread4(void *p) {
|
static msg_t thread4(void *p) {
|
||||||
|
|
||||||
chThdSleep(10);
|
chThdSleep(MS2ST(20));
|
||||||
test_cpu_pulse(50);
|
test_cpu_pulse(50);
|
||||||
test_emit_token(*(char *)p);
|
test_emit_token(*(char *)p);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -156,7 +156,7 @@ static msg_t thread5(void *p) {
|
||||||
|
|
||||||
static msg_t thread6(void *p) {
|
static msg_t thread6(void *p) {
|
||||||
|
|
||||||
chThdSleep(10);
|
chThdSleep(MS2ST(10));
|
||||||
chMtxLock(&m2);
|
chMtxLock(&m2);
|
||||||
test_cpu_pulse(20);
|
test_cpu_pulse(20);
|
||||||
chMtxLock(&m1);
|
chMtxLock(&m1);
|
||||||
|
@ -170,7 +170,7 @@ static msg_t thread6(void *p) {
|
||||||
|
|
||||||
static msg_t thread7(void *p) {
|
static msg_t thread7(void *p) {
|
||||||
|
|
||||||
chThdSleep(20);
|
chThdSleep(MS2ST(20));
|
||||||
chMtxLock(&m2);
|
chMtxLock(&m2);
|
||||||
test_cpu_pulse(50);
|
test_cpu_pulse(50);
|
||||||
chMtxUnlock();
|
chMtxUnlock();
|
||||||
|
@ -180,7 +180,7 @@ static msg_t thread7(void *p) {
|
||||||
|
|
||||||
static msg_t thread8(void *p) {
|
static msg_t thread8(void *p) {
|
||||||
|
|
||||||
chThdSleep(40);
|
chThdSleep(MS2ST(40));
|
||||||
test_cpu_pulse(200);
|
test_cpu_pulse(200);
|
||||||
test_emit_token(*(char *)p);
|
test_emit_token(*(char *)p);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -188,7 +188,7 @@ static msg_t thread8(void *p) {
|
||||||
|
|
||||||
static msg_t thread9(void *p) {
|
static msg_t thread9(void *p) {
|
||||||
|
|
||||||
chThdSleep(50);
|
chThdSleep(MS2ST(50));
|
||||||
chMtxLock(&m2);
|
chMtxLock(&m2);
|
||||||
test_cpu_pulse(50);
|
test_cpu_pulse(50);
|
||||||
chMtxUnlock();
|
chMtxUnlock();
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
#define ALLOWED_DELAY 5
|
#define ALLOWED_DELAY MS2ST(5)
|
||||||
|
|
||||||
static Semaphore sem1;
|
static Semaphore sem1;
|
||||||
|
|
||||||
|
@ -85,10 +85,10 @@ static void sem2_execute(void) {
|
||||||
int i;
|
int i;
|
||||||
systime_t target_time;
|
systime_t target_time;
|
||||||
|
|
||||||
target_time = chSysGetTime() + 5 * 500;
|
target_time = chSysGetTime() + MS2ST(5 * 500);
|
||||||
for (i = 0; i < 5; i++) {
|
for (i = 0; i < 5; i++) {
|
||||||
test_emit_token('A' + i);
|
test_emit_token('A' + i);
|
||||||
chSemWaitTimeout(&sem1, 500);
|
chSemWaitTimeout(&sem1, MS2ST(500));
|
||||||
}
|
}
|
||||||
test_assert_sequence("ABCDE");
|
test_assert_sequence("ABCDE");
|
||||||
test_assert_time_window(target_time, target_time + ALLOWED_DELAY);
|
test_assert_time_window(target_time, target_time + ALLOWED_DELAY);
|
||||||
|
|
Loading…
Reference in New Issue