Examining the VxWorks AE 1.1 RTOS
by Bart Van Beneden 

Listing One
/*************************************************************************/
/***** In this test, the main thread creates 10 other threads that   *****/
/***** yield the processor as soon as they become active.            *****/
/***** Every thread writes a trace to the bus analyzer so the time   *****/
/***** needed to switch from one thread to the other can be measured.*****/
/*************************************************************************/

#include "vxWorks.h"
#include "taskLib.h"
#include "stdio.h"
#include "trace.h"

#define NUM_OF_THREADS      10
#define HIGHEST_PRIO         0
#define LOWEST_PRIO        255

void Thread(int iArg1,int iArg2,int iArg3,int iArg4,int iArg5,
                     int iArg6,int iArg7, int iArg8,int iArg9,int iArg10);
unsigned long   *pulp_trace = (unsigned long*) 0xE1000000;

void start()
{
    int i, iStatus;

    /* Set priority of current thread to highest */
    taskPrioritySet(taskIdSelf(), HIGHEST_PRIO);    

    /* Creating threads with the same priority */
    for (i=0; i<NUM_OF_THREADS; i++)
    {
        iStatus = taskSpawn("Thread", HIGHEST_PRIO+1, 0, 1024, 
                             (FUNCPTR) Thread, i,0,0,0,0,0,0,0,0,0);
        if (iStatus == ERROR)  {*pulp_trace=0xAAAAAAAA; return;} 
    }
    /* Lower priority of this thread so test threads are unblocked */
    taskPrioritySet(taskIdSelf(), HIGHEST_PRIO+2);  
    return;
}
void Thread(int iArg1,int iArg2,int iArg3,int iArg4,int iArg5,
                      int iArg6,int iArg7, int iArg8,int iArg9,int iArg10)
{
    int i;
    for (i=0; i<33000/NUM_OF_THREADS; i++)
    {
        /* Write trace before processor is released */
        *pulp_trace = TRC(0, iArg1, TRC_TSW, 0, 0, 0);
        /* Let another thread run */
                taskDelay(0);
    }
    return;
}





1


