int4.c 4.24 KB

/*---------------------------------------------------------------------*
        Copyright (C) 1998 Nintendo. (Originated by SGI)
        
        $RCSfile: int4.c,v $
        $Revision: 1.1.1.1 $
        $Date: 2002/05/02 03:27:20 $
 *---------------------------------------------------------------------*/
#include <os.h>
#include <os_internal.h>
#include <rmon.h>
#include <rcp.h>
#include "corefunc.h"

/*
 * int4
 *
 * Tests for:
 *	osSetEventMesg
 *	osSetIntMask
 *	__osSpSetStatus
 *	rcp interrupts
 *
 * Assumed working:
 *	osCreateMesgQueue
 *	osRecvMesg
 *
 * Description:
 *	Check the multiple pending interrupts send correct messages that are
 *		ordered properly.
 */

#define	NUM_MESSAGE	4

static OSMesgQueue	intMesgQueue;
static OSMesg		intMesgBuf[NUM_MESSAGE];

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

    /*
     * Create a single message queue and associate four
     * interrupt events with it.
     */
    osCreateMesgQueue(&intMesgQueue, intMesgBuf, NUM_MESSAGE);
    osSetEventMesg(OS_EVENT_SP, &intMesgQueue, (OSMesg)0x11111111);
    osSetEventMesg(OS_EVENT_AI, &intMesgQueue, (OSMesg)0x22222222);
    osSetEventMesg(OS_EVENT_SI, &intMesgQueue, (OSMesg)0x33333333);
    osSetEventMesg(OS_EVENT_PI, &intMesgQueue, (OSMesg)0x44444444);

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

    __osSpSetStatus(SP_SET_SIG2);
    __osSpSetStatus(SP_SET_INTR);
    osAiSetFrequency(3000);
    osAiSetNextBuffer(buffer, 0x60);
    __osPiRawStartDma(OS_READ, 0, buffer, 0x10);
    __osSiRawStartDma(OS_READ, buffer);

    /*
     * Loop here a bit, since AI interrupt takes some time to fire.
     */
     for (loop = 0; loop < 1000000; loop++);

    /*
     * Enable the interrupts.
     */
    currentMask = osSetIntMask(OS_IM_SP|OS_IM_AI|OS_IM_SI|OS_IM_PI);
    if (currentMask != OS_IM_NONE) {
	osSyncPrintf("int4: expected interrupt mask 0x%x, actual 0x%x\n",
		    OS_IM_NONE, currentMask);
	numFailures++;
    }

    /*
     * Should get OS_EVENT_SP message first ...
     */
    expectedMesg = (OSMesg)0x11111111;
    retValue = osRecvMesg(&intMesgQueue, &actualMesg, OS_MESG_NOBLOCK);

    if (retValue != 0) {
	osSyncPrintf("int4: expected osRecvMesg return value %d, actual %d\n",
		   0, retValue);
	numFailures++;
    }

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

    /*
     * Then OS_EVENT_AI message ...
     */
    expectedMesg = (OSMesg)0x22222222;
    retValue = osRecvMesg(&intMesgQueue, &actualMesg, OS_MESG_BLOCK);

    if (retValue != 0) {
	osSyncPrintf("int4: expected osRecvMesg return value %d, actual %d\n",
		   0, retValue);
	numFailures++;
    }

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

    /*
     * Then OS_EVENT_SI message.
     */
    expectedMesg = (OSMesg)0x33333333;
    retValue = osRecvMesg(&intMesgQueue, &actualMesg, OS_MESG_BLOCK);

    if (retValue != 0) {
	osSyncPrintf("int4: expected osRecvMesg return value %d, actual %d\n",
		   0, retValue);
	numFailures++;
    }

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

    /*
     * finally OS_EVENT_PI message ...
     */
    expectedMesg = (OSMesg)0x44444444;
    retValue = osRecvMesg(&intMesgQueue, &actualMesg, OS_MESG_BLOCK);

    if (retValue != 0) {
	osSyncPrintf("int4: expected osRecvMesg return value %d, actual %d\n",
		   0, retValue);
	numFailures++;
    }

    if (expectedMesg != actualMesg) {
	osSyncPrintf("int4: 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_SP|OS_IM_AI|OS_IM_SI|OS_IM_PI)) {
	osSyncPrintf("int4: expected interrupt mask 0x%x, actual 0x%x\n",
		    OS_IM_SP|OS_IM_AI|OS_IM_SI|OS_IM_PI, currentMask);
	numFailures++;
    }
    return(numFailures);
}