int2.c 2.75 KB
#include <os.h>
#include <os_internal.h>
#include <rmon.h>
#include <R4300.h>
#include "corefunc.h"

/*
 * int2
 *
 * Tests for:
 *	osSetEventMesg
 *	osSetIntMask
 *	__osSetCause
 *	__osSetCompare
 *	__osSetCount
 *
 * Assumed working:
 *	osCreateMesgQueue
 *	osRecvMesg
 *
 * Description:
 *	Check the multiple pending interrupts send correct messages that are
 *		ordered properly.
 */

#define	NUM_MESSAGE	3

static OSMesgQueue	intMesgQueue;
static OSMesg		intMesgBuf[NUM_MESSAGE];

int
int2(void)
{
    OSIntMask savedMask, currentMask;
    OSMesg actualMesg, expectedMesg;
    int i;
    int retValue;
    int numFailures = 0;
    
    savedMask = osSetIntMask(OS_IM_NONE);

    /*
     * Create a single message queue and associate three
     * interrupt events with it.
     */
    osCreateMesgQueue(&intMesgQueue, intMesgBuf, NUM_MESSAGE);
    osSetEventMesg(OS_EVENT_SW1,     &intMesgQueue, (OSMesg)0x11111111);
    osSetEventMesg(OS_EVENT_SW2,     &intMesgQueue, (OSMesg)0x22222222);
    osSetEventMesg(OS_EVENT_COUNTER, &intMesgQueue, (OSMesg)0x33333333);

    /*
     * While the interrupts are still disabled, trigger all three interrupts.
     */

    __osSetCause(CAUSE_SW1 | CAUSE_SW2);
    __osSetCompare(0);
    __osSetCount(0);

    /*
     * Enable the interrupts.
     */
    currentMask = osSetIntMask(OS_IM_SW1|OS_IM_SW2|OS_IM_COUNTER);
    if (currentMask != OS_IM_NONE) {
	osSyncPrintf("int2: expected interrupt mask 0x%x, actual 0x%x\n",
		OS_IM_NONE, currentMask);
	numFailures++;
    }

    /*
     * Should get OS_EVENT_COUNTER message first ...
     */
    expectedMesg = (OSMesg)0x33333333;
    (void)osRecvMesg(&intMesgQueue, &actualMesg, OS_MESG_NOBLOCK);

    if (expectedMesg != actualMesg) {
	osSyncPrintf("int2: expected message 0x%x, actual 0x%x\n",
		expectedMesg, actualMesg);
	numFailures++;
    }

    /*
     * Then OS_EVENT_SW2 message ...
     */
    expectedMesg = (OSMesg)0x22222222;
    (void)osRecvMesg(&intMesgQueue, &actualMesg, OS_MESG_NOBLOCK);

    if (expectedMesg != actualMesg) {
	osSyncPrintf("int2: expected message 0x%x, actual 0x%x\n",
		expectedMesg, actualMesg);
	numFailures++;
    }

    /*
     * And finally OS_EVENT_SW1 message.
     */
    expectedMesg = (OSMesg)0x11111111;
    (void)osRecvMesg(&intMesgQueue, &actualMesg, OS_MESG_NOBLOCK);

    if (expectedMesg != actualMesg) {
	osSyncPrintf("int2: expected message 0x%x, actual 0x%x\n",
		expectedMesg, actualMesg);
	numFailures++;
    }

    /*
     * Restore original interrupt mask and check it once more.
     */
    currentMask = osSetIntMask(savedMask);
    if (currentMask != (OS_IM_SW1|OS_IM_SW2|OS_IM_COUNTER)) {
	osSyncPrintf("int2: expected interrupt mask 0x%x, actual 0x%x\n",
		OS_IM_SW1|OS_IM_SW2|OS_IM_COUNTER, currentMask);
	numFailures++;
    }
    return(numFailures);
}