Nut/OS  4.10.3
API Reference
threads.c
Go to the documentation of this file.
00001 
00048 #include <stdio.h>
00049 #include <io.h>
00050 
00051 #include <cfg/arch.h>
00052 #include <dev/board.h>
00053 
00054 #include <sys/thread.h>
00055 #include <sys/timer.h>
00056 
00057 /*
00058  * High priority thread.
00059  */
00060 THREAD(Thread1, arg)
00061 {
00062     /*
00063      * Endless loop in high priority thread.
00064      */
00065     NutThreadSetPriority(16);
00066     for (;;) {
00067         putchar('H');
00068         NutSleep(125);
00069     }
00070 }
00071 
00072 /*
00073  * Low priority thread.
00074  */
00075 THREAD(Thread2, arg)
00076 {
00077     /*
00078      * Endless loop in low priority thread.
00079      */
00080     NutThreadSetPriority(128);
00081     for (;;) {
00082         putchar('L');
00083         NutSleep(125);
00084     }
00085 }
00086 
00087 /*
00088  * Main application thread. 
00089  */
00090 int main(void)
00091 {
00092     uint32_t baud = 115200;
00093 
00094     /*
00095      * Register the UART device, open it, assign stdout to it and set 
00096      * the baudrate.
00097      */
00098     NutRegisterDevice(&DEV_CONSOLE, 0, 0);
00099     freopen(DEV_CONSOLE_NAME, "w", stdout);
00100     _ioctl(_fileno(stdout), UART_SETSPEED, &baud);
00101 
00102     puts("\nThread Test");
00103 
00104     /*
00105      * Start two additional threads. All threads are started with 
00106      * priority 64.
00107      */
00108     NutThreadCreate("t1", Thread1, 0, 512);
00109     NutThreadCreate("t2", Thread2, 0, 512);
00110 
00111     /*
00112      * Endless loop in main thread.
00113      */
00114     for (;;) {
00115         putchar('M');
00116         NutSleep(125);
00117     }
00118     return 0;
00119 }