/* example4.c */ /* * RTXC Quadros Version 1.0 * Copyright (c) 1999-2003 * Quadros Systems, Inc. * ALL RIGHTS RESERVED * * THE INFORMATION HEREIN IS CONFIDENTIAL AND PROPRIETARY. * UNAUTHORIZED DISCLOSURE OR DISTRIBUTION IS PROHIBITED. * * * This example application demonstrates three independent * state machines, each with three states. The state * machines are started by the expiration of Alarm objects * SALARM1, SALARM2, and SALARM3. The three state machines * are implemented via the thread objects THREAD1, THREAD2, * and THREAD3. The three thread objects share one entry * point, entry_point1(). State transitions are implemented * by using Environment Arguments. The Environment Arguments * are initialized in example_init(). * * The example also illustrates how multiple thread objects * can share a single resource: the UART. THREAD1, THREAD2, * and THREAD3 have all been configured to run at LEVEL1 via * RTXCgen. Since threads within one level can not preempt * each other, the string of characters that one thread sends * to the UART is not randomly mixed with characters output * by another thread. * */ #include "rtxcapi.h" #include "rtxcuart.h" #include "sysinit.h" #include "kalarm.h" #include "kthread.h" #include "example.h" #include "util.h" typedef struct { unsigned int state; unsigned int data; } EX_ENVARGS; EX_ENVARGS thread1_envargs; EX_ENVARGS thread2_envargs; EX_ENVARGS thread3_envargs; /***** Example Initialization *****/ void example_init(void) { /* Adjust SALARM1's recycle count to something more reasonable for this example. */ ALARMPROP aprop; TS_GetAlarmProp(SALARM1, &aprop); aprop.recycle = 250; TS_DefAlarmProp(SALARM1, &aprop); /* Initialize thread environment arguments and entry points */ thread1_envargs.state = 1; TS_DefThreadEnvArg(THREAD1, (void *)&thread1_envargs); TS_DefThreadEntry(THREAD1, entry_point1); TS_DefAlarmActionArm(SALARM1, SCHEDULETHREAD, THREAD1); thread2_envargs.state = 1; TS_DefThreadEnvArg(THREAD2, (void *)&thread2_envargs); TS_DefThreadEntry(THREAD2, entry_point1); TS_DefAlarmActionArm(SALARM2, SCHEDULETHREAD, THREAD2); thread3_envargs.state = 1; TS_DefThreadEnvArg(THREAD3, (void *)&thread3_envargs); TS_DefThreadEntry(THREAD3, entry_point1); TS_DefAlarmActionArm(SALARM3, SCHEDULETHREAD, THREAD3); } /***** Example Application *****/ void entry_point1(void *p1, void *p2) { EX_ENVARGS *envargs = p2; print_thread_id_message(); /* Thread: 1, Thread: 2, Thread 3 */ switch(envargs->state) { case 1: print_state_message(1); /* State: 1 */ envargs->state = 2; break; case 2: print_state_message(2); /* State: 2 */ envargs->state = 3; break; case 3: print_state_message(3); /* State: 3 */ envargs->state = 1; break; default: print_state_message(envargs->state); break; } } /***** Unused Entry Points *****/ void entry_point2(void *p1, void *p2) {} void entry_point3(void *p1, void *p2) {} void entry_point4(void *p1, void *p2) {} void entry_point5(void *p1, void *p2) {} void entry_point6(void *p1, void *p2) {} void uexcptn1(void) {} void uexcptn2(void) {} void example_null_run(void) {} /* end of file - example4.c */