#include "vxWorks.h" #include "semLib.h" #include "msgQLib.h" #include "wdLib.h" #include "config.h" #define DEMO_TICK extern SEM_ID semaBin; extern SEM_ID semaMut; extern SEM_ID semaCnt; MSG_Q_ID msgQueue; MSG_Q_ID msgQueue2; WDOG_ID watchdog; void usrWatchdog (int in); int function (int); /******************************************************************************** * usrDemo/usrDemo2 - example application * * This routines are spawned as tasks in usrAppInit(). * The semaphores mentioned above are also created in usrAppInit(). * This example is for showing the task specific debug possibilities of * TRACE32 together with vxWorks. * * The following code fragment is the setup of tasks and semaphores in * usrAppInit(): * * #if defined(INCLUDE_DEMO) * taskSpawn ("demo", 20, 0, 2000, (FUNCPTR) usrDemo, 0,0,0,0,0,0,0,0,0,0); * taskSpawn ("demo2", 21, 0, 2000, (FUNCPTR) usrDemo2, 0,0,0,0,0,0,0,0,0,0); * * semaBin = semBCreate (SEM_Q_PRIORITY, SEM_EMPTY); * semaMut = semMCreate (SEM_Q_FIFO); * semaCnt = semCCreate (SEM_Q_FIFO, 5); * #endif * */ void usrDemo (void) { char buffer[20]; int i = 5;; /* taskSuspend (taskNameToId ("tBoot")); */ watchdog = wdCreate (); wdStart (watchdog, 1000, (FUNCPTR) usrWatchdog, 50); msgQueue = msgQCreate (10, 20, MSG_Q_PRIORITY); msgQueue2 = msgQCreate (10, 20, MSG_Q_FIFO); FOREVER { msgQSend (msgQueue, "Hello TRACE32", 13, WAIT_FOREVER, MSG_PRI_NORMAL); i = function (i); #ifdef DEMO_TICK tickAnnounce(); #endif msgQReceive (msgQueue2, buffer, 20, WAIT_FOREVER); } } void usrDemo2 (void) { char buffer[20]; int i = 4; FOREVER { msgQReceive (msgQueue, buffer, 20, WAIT_FOREVER); i = function (i); #ifdef DEMO_TICK tickAnnounce(); #endif msgQSend (msgQueue2, "Hello back", 10, WAIT_FOREVER, MSG_PRI_URGENT); } } void usrWatchdog (int in) { in = ((--in)+(++in)+1)/2; } int function (int i) { int j; j = 5 * i * i; i = j / 27; return (i); }