uji.c 8.45 KB
#include <ultra64.h>
#include "gng.h"

extern void playSubway(void);

static u8 controllerdata[] = {
    0x00, 
    0x55, 
    0xaa, 
    0xff, 
    0x01, 
    0x02, 
    0x04, 
    0x08, 
    0x10, 
    0x20, 
    0x40, 
    0x80, 
};

/* Check the power, ground, and other signal bits.
 * These are scattered around in the zaru address space */
int VoltageTest() {
    int retvalue = GNG_TEST_SUCCESS;	    /* assume success */
    u8 data;

#ifndef _FINALROM    
    if (!zaruexists)	    /* Assume everything is OK if no Zaru */
		return GNG_TEST_SUCCESS;
#endif
    
    /* First check the Power line register (0x1800) */
    data = ZaruGetPowerCheck();

    /* check that only the bits that should be on are on
     * and that only those bits are on.  */
    if (data ^ (ZARU_V2 | ZARU_V3 | ZARU_V4 | ZARU_GND1CHK | ZARU_GND2CHK))
			retvalue = GNG_TEST_FAILURE;
	
    data = ZaruGetMisc();
    if ( (data & ZARU_MISC_5VCHKCON) == 0)
			retvalue = GNG_TEST_FAILURE;

    ZaruSetExpCommand(ZARU_EXP_CMD_GND);
    
    data = ZaruGetExpHigh();
    /* check that only the bits that should be on are on
     * and that only those bits are on.
     * XXXX - also checking SEC1, SEC2,  CCLK & CSYNC */
    if (data ^ (ZARU_SEC1 | ZARU_SEC2 | ZARU_CCLK | ZARU_CSYNC))
			retvalue = GNG_TEST_FAILURE;
    
    data = ZaruGetExpLow();
    /* check that only the bits that should be on are on
     * and that only those bits are on.*/
    if (data)
			retvalue = GNG_TEST_FAILURE;
	
    ZaruSetExpCommand(ZARU_EXP_CMD_VOLT);
    data = ZaruGetExpLow();
    data &= (ZARU_12V1 | ZARU_3V0 | ZARU_3V1 | ZARU_3V2); /* some bits unused */
    /* check that only the bits that should be on are on
     * and that only those bits are on. */
    if (data ^ (ZARU_12V1 | ZARU_3V0 | ZARU_3V1 | ZARU_3V2))
			retvalue = GNG_TEST_FAILURE;
    
    return retvalue;
}

/* Check that the reset time is in acceptable range */
int ResetTimeTest() {
    int resettime;
    
#ifndef _FINALROM    
    if (!zaruexists)	    /* Assume everything is OK if no Zaru */
		return GNG_TEST_SUCCESS;
#endif
    
    resettime = ZaruGetResetTime();
    
    if (resettime >= ZARU_RESET_LOW && resettime <= ZARU_RRESET_HIGH)
			return GNG_TEST_SUCCESS;
    else 
			return GNG_TEST_FAILURE;
}

/* Test Joy ports 2, 3, and 4
 * There is only one switch register.  You cannot write different
 * data values to 2, 3, and 4 and then expect those values to be
 * read back.  Only the data from the last write is available.  */
int ControllerTest() {
	  u16 buttons;
	  u8 select;
	  int i, j;
	  char message[256];

#ifndef _FINALROM    
	  if (!zaruexists)	    /* Assume everything is OK if no Zaru */
		return GNG_TEST_SUCCESS;
#endif
	  gng_report( "Controller test:\nPlease wiggle (shake)\ncontroller inputs\nduring test.\n\nPress yellow button\nto continue...", 
	  0, GNG_INHIBIT_PRINT, 0);

		/* Play an alert noise to indicate to the user that they need 
		 to press the button. */
	  playSubway();
    
	  while (ZaruGetNextTestButton() == 0) {
		/* test joy ports 2, 3, and 4. */
			for (i = 2; i < 5; i++) {
	      switch (i) {
			    case 2:
						select = ZARU_JOY_SELECT_2;
						break;
		
			    case 3:
						select = ZARU_JOY_SELECT_3;
						break;
		
			    case 4:
						select = ZARU_JOY_SELECT_4;
						break;

			    default:
						sprintf(message, "Controller test:\nillegal controller index %d", i);
						gng_report(message, 0, GNG_INHIBIT_PRINT, 120);
						break;
		    }
	    
		    ZaruSetJoySelect(select);

		    for (j = 0; j < sizeof(controllerdata)/sizeof(u8); j++) {
					ZaruSetJoyButtons(controllerdata[j]);
					if (ZaruButtonCheck(controllerdata[j], ZaruReadControllerButton(i-1))
					== GNG_TEST_FAILURE) {
			
				    sprintf(message, "Controller test:\ncontroller %d no good", i);
				    gng_report(message, 1, GNG_PASS_FAIL_BIT, 0);

				    /* Not reached. */
				    return GNG_TEST_FAILURE;
					}
		    }
			}
		}
	  return GNG_TEST_SUCCESS;
}

/* New functions from uji "checker" program  */
/* Import globals from ../testDriver/main.c: */
extern OSMesgQueue	dmaMessageQ, rspMessageQ, rdpMessageQ, retraceMessageQ;
extern OSMesg		dmaMessageBuf, rspMessageBuf, rdpMessageBuf, retraceMessageBuf;
extern OSMesg		dummyMessage;
extern OSIoMesg		dmaIOMessageBuf;
extern char		*staticSegment;

#define AD16BUSTEST 0x12345678

/* Symbols generated by "makerom" to tell us where the static segment is in ROM*/
extern char _staticSegmentRomStart[], _staticSegmentRomEnd[];

char ssnRWchk(void){
    volatile u32* ptr0;
    int itmp0,itmp1;
    volatile unsigned long ltmp0;

    ZaruSetADBusCheck(ZARU_ON, 1);

    osPiStartDma(&dmaIOMessageBuf,OS_MESG_PRI_NORMAL,OS_WRITE,
    (u32)_staticSegmentRomStart,staticSegment,0x10,&dmaMessageQ);
    (void)osRecvMesg(&dmaMessageQ,&dummyMessage,OS_MESG_BLOCK);

    /* Perform 4 reads to AD16 address space
     (these will be counted by the Zaru)*/
    ptr0=(u32*)(PHYS_TO_K1(AD16BUSTEST));
    osInvalDCache((void *)ptr0, 4);
    ltmp0=*(ptr0++);
    osInvalDCache((void *)ptr0, 4);
    ptr0=(u32*)(PHYS_TO_K1(AD16BUSTEST));
    ltmp0=*(ptr0++);

/*    ZaruSetExpCommand(ZARU_EXP_CMD_RW_COUNTS);*/
/*    ZaruSetADBusCheck(ZARU_OFF, 0);*/
/*    ZaruSetADBusCheck(ZARU_ON, 1);*/

    /* Perform 8 writes to AD16 using DMA (to avoid dcache problems)
     * (these will be counted by the Zaru) */
    ZaruSetExpCommand(ZARU_EXP_CMD_RW_COUNTS);
    ZaruSetADBusCheck(ZARU_OFF, 0);
    itmp0 = ZaruReadReg(REG_3000);

    return(0x84^itmp0);

#if 0
    volatile u32* ptr0;
    int itmp0,itmp1;
    volatile unsigned long ltmp0;

    ZaruSetADBusCheck(ZARU_ON, 1);
    
    /* Perform 4 reads to AD16 address space
		 (these will be counted by the Zaru)*/
    ptr0=(u32*)(PHYS_TO_K1(AD16BUSTEST));
    osInvalDCache((void *)ptr0, 4);
    ltmp0=*(ptr0++);
    osInvalDCache((void *)ptr0, 4);
    ptr0=(u32*)(PHYS_TO_K1(AD16BUSTEST));
    ltmp0=*(ptr0++);

    ZaruSetExpCommand(ZARU_EXP_CMD_RW_COUNTS);
    ZaruSetADBusCheck(ZARU_OFF, 0); 
    ZaruSetADBusCheck(ZARU_ON, 1); 

    /* Perform 8 writes to AD16 using DMA (to avoid dcache problems)
     * (these will be counted by the Zaru) */
    osPiStartDma(&dmaIOMessageBuf,OS_MESG_PRI_NORMAL,OS_WRITE,
	  (u32)_staticSegmentRomStart,staticSegment,0x10,&dmaMessageQ);
    (void)osRecvMesg(&dmaMessageQ,&dummyMessage,OS_MESG_BLOCK);

    ZaruSetExpCommand(ZARU_EXP_CMD_RW_COUNTS);
    ZaruSetADBusCheck(ZARU_OFF, 0);
    itmp0 = ZaruReadReg(REG_3000);

    return(0x84^itmp0);
#endif
}

/* Return values from ssnRWchk */
#define MASK_READ  0x000f
#define MASK_WRITE 0x00f0
 
int chk50PReadWrite( ) {

    char state = 0;
    char message[256];

#ifndef _FINALROM    
    if (!zaruexists)	    /* Assume everything is OK if no Zaru */
		return GNG_TEST_SUCCESS;
#endif

    sprintf(message,"When push yellow button\nAD16BUS RW ACCESS");
    gng_report(message, 1, GNG_INHIBIT_PRINT, 0);

    ZaruWriteReg2(REG_RW50P,ZARU_RW50PSTART); /* sasano added */
		ZaruWaitForNextTestButton();
/*    while(ZaruGetNextTestButton()==0){}*/

    state  = ssnRWchk();
    ZaruWriteReg2(REG_RW50P,ZARU_RW50PEND); /* sasano added */

		return GNG_TEST_SUCCESS; /* sasano added */
#if 0
    if (state) {
			sprintf(message, "AD16 BUS RW ERROR:\nexpected 0x0\nread 0x%x\n", state);
			gng_report(message, 1, GNG_PASS_FAIL_BIT, 0);
      return GNG_TEST_FAILURE;
    } else {
			return GNG_TEST_SUCCESS;
    }
#endif
}

/* Check that we are properly generating AD16 addresses on the bottom connector*/
int AD16_LatchTest(u32 testadd) {
  volatile u32* ptr;
  short i0,i1,i2,i3;
  char message[256];
  int i;

    sprintf(message,"Address latched test\n(%x)\nPress yello button\n to continue",testadd);
    gng_report(message, 1, GNG_INHIBIT_PRINT, 0);

    ZaruWriteReg2(REG_LATCH,ZARU_LATCHSTART); /* sasano added */
		ZaruWaitForNextTestButton();

    ptr=(u32*)(PHYS_TO_K1(testadd));
    i0=*(ptr);

    ZaruWriteReg2(REG_LATCH,ZARU_LATCHEND); /* sasano added */

    sprintf(message,"Address latched test finished.\n(%x)\nPress yello button\n to continue",testadd);
    gng_report(message, 1, GNG_INHIBIT_PRINT, 1);

		return GNG_TEST_SUCCESS;
}
int AD16_LatchTest1(){
    
    return(AD16_LatchTest((ZaruReadReg2(REG_LATCHADD3)<<24)
                         +(ZaruReadReg2(REG_LATCHADD2)<<16)
                         +(ZaruReadReg2(REG_LATCHADD1)<< 8)
                         +(ZaruReadReg2(REG_LATCHADD0))));
}
int AD16_LatchTest2(){

    return(AD16_LatchTest((ZaruReadReg2(REG_LATCHADD7)<<24)
                         +(ZaruReadReg2(REG_LATCHADD6)<<16)
                         +(ZaruReadReg2(REG_LATCHADD5)<< 8)
                         +(ZaruReadReg2(REG_LATCHADD4))));
}