timer3.c 2.16 KB
#include <os.h>
#include <R4300.h>
#include <rcp.h>
#include "rmon.h"
#include "osprof.h"

#define INTERVAL OS_USEC_TO_CYCLES(100)
/*
 * Timer
 *
 * Tests for:
 *	osGetTime
 *	osSetTime
 *	osSetTimer
 *	osStopTimer
 *
 * Assumed working:
 *	osCreateMesgQueue
 *	osRecvMesg
 *
 * Description:
 *	
 *	Setup interval timer and check that the message is 
 * 		delivered when timer expire
 *	Call osGetTime to check that we do get message in specified 
 *		interval time
 */

static OSTimer		mytimer;
static OSMesgQueue	timerMesgQueue;
static OSMesg		timerMesgBuf;

int
timer3(void)
{
    int i=0;
    int j;
    OSTime t1, t2;
    int numFailures = 0;
    OSMesg actualMesg;
    int retValue;
    OSTime t;

    osCreateMesgQueue(&timerMesgQueue, &timerMesgBuf, 2);
    osSetTimer(&mytimer, 0, INTERVAL, &timerMesgQueue, &timerMesgBuf);

    while (i++ < 15) {
	    t1 = osGetTime();
	    (void)osRecvMesg(&timerMesgQueue, &actualMesg, OS_MESG_BLOCK);
	    t2 = osGetTime();
	    if ((t2 - t1) > (OS_CYCLES_TO_NSEC(INTERVAL)+500)) {
		rmonPrintf("timer3: miss interval timer. t2 0x%x t1 0x%x\n", 
		t2, t1);
		numFailures++;
	    }
	    if (&timerMesgBuf != actualMesg) {
		rmonPrintf("timer3: expected message 0x%x, actual 0x%x\n",
			&timerMesgBuf, actualMesg);
		numFailures++;
	    }
    }
    retValue =  osStopTimer(&mytimer);
    if (retValue) {
	rmonPrintf("timer3: osStopTimer failed\n");
	numFailures++;
    }

    for(t = 0xffffff00, j = 0; j < 20; j++, t = t + 0xfffff) {
	    osSetTime(t);
	    osSetTimer(&mytimer, 0, INTERVAL, &timerMesgQueue, &timerMesgBuf);

	    while (i++ < 15) {
		    t1 = osGetTime();
		    (void)osRecvMesg(&timerMesgQueue, &actualMesg, OS_MESG_BLOCK);
		    t2 = osGetTime();
		    if ((t2 - t1) > (OS_CYCLES_TO_NSEC(INTERVAL)+500)) {
			rmonPrintf("timer3: miss interval timer. t2 0x%x t1 0x%x\n", 
			t2, t1);
			numFailures++;
		    }
		    if (&timerMesgBuf != actualMesg) {
			rmonPrintf("timer3: expected message 0x%x, actual 0x%x\n",
				&timerMesgBuf, actualMesg);
			numFailures++;
		    }
	    }
	    retValue =  osStopTimer(&mytimer);
	    if (retValue) {
		rmonPrintf("timer3: osStopTimer failed\n");
		numFailures++;
	    }
    }
    return(numFailures);
}