/* example5.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 a state machine * with three states. Two thread objects, THREAD1 and * THREAD2, are used. SALARM3 peridocially schedules * THREAD1 to run. In entry_point1(), THREAD1 schedules * THREAD2 to run via TS_ORThreadGateBits(). In * entry_point2(), THREAD2 determines the state machine's * state via its Thread Gate value. * * State transitions are implemented via TS_DefThreadArg(). * In this example, the Thread Arguments are passed as scalar * values. This is in contrast to example3.c, which passes * Thread Arguments as a pointer to a data structure. * */ #include "rtxcapi.h" #include "rtxcuart.h" #include "sysinit.h" #include "kalarm.h" #include "kthread.h" #include "example.h" #include "util.h" #define GK_STATE1 ((GATEKEY)1) #define GK_STATE2 ((GATEKEY)2) #define GK_STATE3 ((GATEKEY)4) #define GK_PRESET ((GATEKEY)0) /***** Example Initialization *****/ void example_init(void) { TS_DefThreadArg(THREAD1, (void *)GK_STATE1); TS_SetThreadGate(THREAD2, GK_PRESET); TS_DefAlarmActionArm(SALARM3, SCHEDULETHREAD, THREAD1); } /***** Example Application *****/ void entry_point1(void *p1, void *p2) { int threadargs = (int)p1; TS_ORThreadGateBits(THREAD2, (GATEKEY)threadargs); } void entry_point2(void *p1, void *p2) { GATEKEY gate_value = TS_GetThreadGateLoadPreset(); print_thread_id_message(); /* Thread: 2 */ switch(gate_value) { case GK_STATE1: print_state_message(1); /* State: 1 */ TS_DefThreadArg(THREAD1, (void *)GK_STATE2); break; case GK_STATE2: print_state_message(2); /* State: 2 */ TS_DefThreadArg(THREAD1, (void *)GK_STATE3); break; case GK_STATE3: print_state_message(3); /* State: 3 */ TS_DefThreadArg(THREAD1, (void *)GK_STATE1); break; default: print_state_message(gate_value); TS_DefThreadArg(THREAD1, (void *)GK_STATE1); break; } } /***** Unused Entry Points *****/ 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 - example5.c */