[En-Nut-Discussion] Testcase For Crashing Nut/OS
Harald Kipp
harald.kipp at egnite.de
Fri Jun 23 20:25:49 CEST 2006
Running the following code on Ethernut 2 (linked with Nut/OS 4.1.x)
will show the event handling problem.
#include <cfg/os.h>
#include <stdio.h>
#include <io.h>
#include <cfg/arch.h>
#include <dev/debug.h>
#include <dev/irqreg.h>
#include <dev/board.h>
#include <sys/thread.h>
#include <sys/timer.h>
#include <sys/event.h>
#include <sys/version.h>
/* Event queue. */
HANDLE tque;
/* Timer 1 interrupt. */
static void NutTraceTimer1IRQ(void *arg)
{
putchar('.');
NutEventPostFromIrq(&tque);
}
/* High priority background thread. */
THREAD(High, arg)
{
NutThreadSetPriority(32);
/* Loop for events. */
for(;;) {
if (NutEventWait(&tque, 0)) {
putchar('T');
}
else {
putchar('E');
}
NutSleep(50);
}
}
/* Low priority background thread. */
THREAD(Low, arg)
{
NutThreadSetPriority(96);
/* Loop for events. */
for(;;) {
putchar('w');
if (NutEventWait(&tque, 2)) {
putchar('t');
}
else {
putchar('e');
}
}
}
/* Main application routine. */
int main(void)
{
/* Initialize the debug port. */
u_long baud = 115200;
NutRegisterDevice(&DEV_DEBUG, 0, 0);
freopen(DEV_DEBUG_NAME, "w", stdout);
_ioctl(_fileno(stdout), UART_SETSPEED, &baud);
printf("\nNut/OS %s Event Test\n", NutVersionString());
NutSleep(1000);
/* Initialize timer/counter 1 interrupts. */
outp(1, TCCR1B);
NutRegisterIrqHandler(&sig_OVERFLOW1, NutTraceTimer1IRQ, 0);
sbi(TIMSK, TOIE1);
/* Create two additional threads. */
NutThreadCreate("high", High, 0, 1024);
NutThreadCreate("low", Low, 0, 1024);
/* Loop for events. */
for(;;) {
if (NutEventWait(&tque, 1)) {
putchar('1');
}
else {
putchar('2');
}
NutSleep(5);
}
}
The output is
Nut/OS 4.1.5.4 pre Event Test
w1twtwtwtw.E1twtwtw.ewtw1twtwtw.ewtw1twtw.ewtw1twtw.ewtwtw1tw.ewtwtw.2twtwtw1tw.ewtwtw.2twtwtw1.twewtwtwtw.2twtwtw.Etw1t
wtwtwtw.ew1twtwtw.ewtw1twtwtw.ewtw1twtw.ewtw1twtw.ewtwtw1tw.ewtwtw.2twtwtw1tw.ewtwtw.2twtwtw1.twewtwtwtw.Etw1twtwtw.ew1t
wtwtw.ewtw1twtw.ewtw1twtw.ewtw1tw.ewtwtw................................................................................
........................................................................................................................
........................................................................................................................
.................................
After a few events posted from interrupt all three threads stop working and
only the timer interrupt remains active.
Harald
More information about the En-Nut-Discussion
mailing list