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

This commit is contained in:
gdisirio 2011-03-05 12:21:45 +00:00
parent b122874af2
commit 2de7c9ddf9
1 changed files with 71 additions and 17 deletions

View File

@ -17,15 +17,34 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stdlib.h>
#include "ch.h" #include "ch.h"
#include "hal.h" #include "hal.h"
/*===========================================================================*/ /*===========================================================================*/
/* Test related code. */ /* Configurable settings. */
/*===========================================================================*/ /*===========================================================================*/
#ifndef RANDOMIZE
#define RANDOMIZE FALSE
#endif
#ifndef ITERATIONS
#define ITERATIONS 100
#endif
#ifndef NUM_THREADS
#define NUM_THREADS 4 #define NUM_THREADS 4
#endif
#ifndef MAILBOX_SIZE
#define MAILBOX_SIZE 2 #define MAILBOX_SIZE 2
#endif
/*===========================================================================*/
/* Test related code. */
/*===========================================================================*/
#define MSG_SEND_LEFT 0 #define MSG_SEND_LEFT 0
#define MSG_SEND_RIGHT 1 #define MSG_SEND_RIGHT 1
@ -43,11 +62,11 @@ static msg_t b[NUM_THREADS][MAILBOX_SIZE];
*/ */
static WORKING_AREA(waWorkerThread[NUM_THREADS], 128); static WORKING_AREA(waWorkerThread[NUM_THREADS], 128);
static msg_t WorkerThread(void *arg) { static msg_t WorkerThread(void *arg) {
static volatile uint32_t x = 0; static volatile unsigned x = 0;
static uint32_t cnt = 0; static unsigned cnt = 0;
uint32_t me = (uint32_t)arg; unsigned me = (unsigned)arg;
uint32_t target; unsigned target;
uint32_t i; unsigned r;
msg_t msg; msg_t msg;
/* Work loop.*/ /* Work loop.*/
@ -55,9 +74,23 @@ static msg_t WorkerThread(void *arg) {
/* Waiting for a message.*/ /* Waiting for a message.*/
chMBFetch(&mb[me], &msg, TIME_INFINITE); chMBFetch(&mb[me], &msg, TIME_INFINITE);
/* Pseudo-random delay.*/ #if RANDOMIZE
for (i = 0; i < (me >> 4); i++) /* Pseudo-random delay.*/
x++; {
chSysLock();
r = rand() & 15;
chSysUnlock();
while (r--)
x++;
}
#else
/* Fixed delay.*/
{
r = me >> 4;
while (r--)
x++;
}
#endif
/* Deciding in which direction to re-send the message.*/ /* Deciding in which direction to re-send the message.*/
if (msg == MSG_SEND_LEFT) if (msg == MSG_SEND_LEFT)
@ -165,8 +198,7 @@ static void printn(uint32_t n) {
*/ */
int main(void) { int main(void) {
unsigned i; unsigned i;
gptcnt_t interval; gptcnt_t interval, threshold, worst;
gptcnt_t threshold;
/* /*
* System initializations. * System initializations.
@ -201,7 +233,7 @@ int main(void) {
println("*** ChibiOS/RT IRQ-STORM long duration test"); println("*** ChibiOS/RT IRQ-STORM long duration test");
println("***"); println("***");
print("*** Kernel: "); print("*** Kernel: ");
println(CH_KERNEL_VERSION); println(CH_KERNEL_VERSION);
#ifdef __GNUC__ #ifdef __GNUC__
print("*** GCC Version: "); print("*** GCC Version: ");
println(__VERSION__); println(__VERSION__);
@ -220,12 +252,26 @@ int main(void) {
print("*** Test Board: "); print("*** Test Board: ");
println(BOARD_NAME); println(BOARD_NAME);
#endif #endif
print("*** SYSCLK: "); println("***");
print("*** System Clock: ");
printn(STM32_SYSCLK); printn(STM32_SYSCLK);
println(""); println("");
print("*** Iterations: ");
printn(ITERATIONS);
println("");
print("*** Randomize: ");
printn(RANDOMIZE);
println("");
print("*** Threads: ");
printn(NUM_THREADS);
println("");
print("*** Mailbox size: ");
printn(MAILBOX_SIZE);
println("");
println(""); println("");
for (i = 1; i <= 100; i++){ worst = 0;
for (i = 1; i <= ITERATIONS; i++){
print("Iteration "); print("Iteration ");
printn(i); printn(i);
println(""); println("");
@ -248,14 +294,22 @@ int main(void) {
/* Gives the worker threads a chance to empty the mailboxes before next /* Gives the worker threads a chance to empty the mailboxes before next
cycle.*/ cycle.*/
chThdSleepMilliseconds(20); chThdSleepMilliseconds(20);
print("\r\nSaturated at "); println("");
print("Saturated at ");
printn(threshold); printn(threshold);
print(" uS\r\n\n"); println(" uS");
println("");
if (threshold > worst)
worst = threshold;
} }
gptStopTimer(&GPTD1); gptStopTimer(&GPTD1);
gptStopTimer(&GPTD2); gptStopTimer(&GPTD2);
println("\r\nTest Complete"); print("Worst case at ");
printn(worst);
println(" uS");
println("");
println("Test Complete");
/* /*
* Normal main() thread activity, nothing in this test. * Normal main() thread activity, nothing in this test.