BUG: NutSleep() fails when called concurrently.
This sample demonstrates Nut/OS multithreading.
#include <dev/uartavr.h> #include <sys/thread.h> #include <sys/print.h> #include <sys/timer.h> static NUTDEVICE *uart; /* * High priority thread. */ THREAD(Thread1, arg) { /* * Endless loop in high priority thread. */ NutThreadSetPriority(16); for(;;) { NutPrintString(uart, "H"); NutPrintFlush(uart); NutSleep(2000); } } /* * Low priority thread. */ THREAD(Thread2, arg) { /* * Endless loop in low priority thread. */ NutThreadSetPriority(128); for(;;) { NutPrintString(uart, "L"); NutPrintFlush(uart); NutSleep(50); } } /* * Main application thread. */ THREAD(NutMain, arg) { u_long baud = 115200; /* * Register the UART device, open it and * set the baudrate. */ NutRegisterDevice(&devUart0, 0, 0); uart = NutDeviceOpen("uart0"); NutDeviceIOCtl(uart, UART_SETSPEED, &baud); /* * Start two additional threads. All threads * are started with priority 64. */ NutThreadCreate("t1", Thread1, 0, 128); NutThreadCreate("t2", Thread2, 0, 128); /* * Endless loop in main thread. */ for(;;) { NutPrintString(uart, "M"); NutPrintFlush(uart); NutSleep(1000); } }