testDriver.c.sjs 12.6 KB
/***************************************************************************
  NUS検査プログラム順序検査プログラムとそのた小物検査プログラム
  *************************************************************************/

/***************************************************************************
  改訂履歴 和田
  
  96/10 コントローラ検査関数ContTestから不要なV−Sync待ちを省く
  ************************************************************************/





#include <ultra64.h>
#include "testDriver.h"
#include "gng.h"

extern void ssn(void);

extern int controllerSlot;

Test_t testList[] = {
    /* debug */
    { 0,&(intr1test)      ,"Cartridge Interrupt"	                 ,GNG_PASS_FAIL_BIT, 									                      PASS_MESSAGE_RETRACE_COUNT,IndexINT   },

    { 0,&(ContTest)       ,"Controller test"                      ,GNG_PASS_FAIL_BIT,                                        PASS_MESSAGE_RETRACE_COUNT,IndexCONT  },
    { 0,&(rdramTest)      ,"RDRAM memory"                         ,GNG_PASS_FAIL_BIT                      ,                  PASS_MESSAGE_RETRACE_COUNT,IndexRDRAM },
    { 0,&(clocktest)      ,"62.5MHz Clock"                        ,GNG_PASS_FAIL_BIT,					                              PASS_MESSAGE_RETRACE_COUNT,IndexCLOCK },
#if 0
    { 0,&(intr1test)      ,"Cartridge Interrupt"	                 ,GNG_PASS_FAIL_BIT, 									                      PASS_MESSAGE_RETRACE_COUNT,IndexINT   },
#endif
    { 0,&(pifCheck)       ,"PIF controller"				               ,GNG_PASS_FAIL_BIT,								                        PASS_MESSAGE_RETRACE_COUNT,IndexPIF   },
    { 0,&(chk50PExtjoy)   ,"EXTJOY controller check"              ,GNG_PASS_FAIL_BIT,										                    PASS_MESSAGE_RETRACE_COUNT,IndexEXTJOY},
    { 0,&(chk50PReadWrite),"AD16 BUS RW cycle count"              ,GNG_PASS_FAIL_BIT,										                    PASS_MESSAGE_RETRACE_COUNT,IndexRW    },
    { 0,&(AD16_LatchTest1),"AD16 BUS address latch1"              ,GNG_PASS_FAIL_BIT,										                    PASS_MESSAGE_RETRACE_COUNT,IndexLATCH1},
    { 0,&(AD16_LatchTest2),"AD16 BUS address latch2"              ,GNG_PASS_FAIL_BIT,										                    PASS_MESSAGE_RETRACE_COUNT,IndexLATCH2},
    { 0,&(piAllTest)      ,"PI RW DMA/PIO,INT"		                 ,GNG_PASS_FAIL_BIT,  							                        PASS_MESSAGE_RETRACE_COUNT,IndexPIO   },
    { 0,&(rsp)            ,"RSP Diagnostic Tests"		             ,GNG_PASS_FAIL_BIT,										                    PASS_MESSAGE_RETRACE_COUNT,IndexRSP   },
    { 0,&(dlDriver)       ,"RDP Display List Checksum"            ,GNG_PASS_FAIL_BIT,										                    PASS_MESSAGE_RETRACE_COUNT,IndexRDP   },
    { 0,&(nmitest_phase1) ,"Reset Switch"      ,GNG_PASS_FAIL_BIT | GNG_NMI_TEST_BIT,                                        PASS_MESSAGE_RETRACE_COUNT,IndexRESET },
    { 0,&(WaveOutput)     ,"Wave Output"                          ,GNG_PASS_FAIL_BIT,                                        PASS_MESSAGE_RETRACE_COUNT,IndexWAVE  },
    { 1,&(music44100)     ,"Music with 44100Hz"                   ,GNG_PASS_FAIL_BIT,                                        PASS_MESSAGE_RETRACE_COUNT,Index441   },
    { 1,&(music32000)     ,"Music with 32000Hz"                   ,GNG_PASS_FAIL_BIT,                                        PASS_MESSAGE_RETRACE_COUNT,Index320   },
    { 1,&(music22050)     ,"Music with 22050Hz"                   ,GNG_PASS_FAIL_BIT,                                        PASS_MESSAGE_RETRACE_COUNT,Index220   },
    { 1,&(RunViTests)     ,"Video Patterns"					             ,GNG_PASS_FAIL_BIT,                                        PASS_MESSAGE_RETRACE_COUNT,IndexVIDEO },
    { 0,&(CpuTest)        ,"R4300 CPU Test"					             ,GNG_PASS_FAIL_BIT,									                      PASS_MESSAGE_RETRACE_COUNT,IndexCPU   },
    { 0,&(Jumptime)       ,"Dummy jump"					                 ,GNG_PASS_FAIL_BIT,									                      PASS_MESSAGE_RETRACE_COUNT,IndexJUMP  },
    { 0,NULL						   ,"end of tests"	  ,GNG_PASS_FAIL_BIT | GNG_FINAL_TEST_BIT,                                                PASS_MESSAGE_RETRACE_COUNT,255},
};

int Jumptime(){
    return GNG_TEST_SUCCESS;
}


int WaveOutput(){
    char message[256];
    int length;
    volatile u32 *ptr;
    short s0;
    
    length=ZaruReadReg2(REG_SNDLENGTH);
    if(length==0) length=ZARU_SNDLENGTHDEFAULT;
    
    ZaruWriteReg2(REG_AUDIO,ZARU_SINWAVE); /* sasano added */
    sprintf(message,"When press yellow button,\nOutput sin wave\n");
    gng_report(message, 1, GNG_INHIBIT_PRINT, 1);
    audioTest(ZARU_SINWAVE,length);
    
    ptr=(u32*)(PHYS_TO_K1(0x1f000000));
    s0=*(ptr);
    ZaruWriteReg2(REG_THRU ,s0>>8);
    ZaruWriteReg2(REG_THRU2,s0%0x100);
    
    ZaruWriteReg2(REG_AUDIO,ZARU_SAWWAVE); /* sasano added */
    sprintf(message,"When press yellow button,\nOutput saw wave\n");
    gng_report(message, 1, GNG_INHIBIT_PRINT, 1);
    audioTest(ZARU_SAWWAVE,length);
    
    ZaruWriteReg2(REG_AUDIO,ZARU_TRIWAVE); /* sasano added */
    sprintf(message,"When press yellow button,\nOutput triangle wave\n");
    gng_report(message, 1, GNG_INHIBIT_PRINT, 1);
    audioTest(ZARU_TRIWAVE,length);
    
    ZaruWriteReg2(REG_AUDIO,ZARU_RCTWAVE); /* sasano added */
    sprintf(message,"When press yellow button,\nOutput rectangle wave\n");
    gng_report(message, 1, GNG_INHIBIT_PRINT, 1);
    audioTest(ZARU_RCTWAVE,length);
    
    ZaruWriteReg2(REG_AUDIO,ZARU_ONLYL); /* sasano added */
    sprintf(message,"When press yellow button,\nOutput sin wave\nonly Left channel");
    gng_report(message, 1, GNG_INHIBIT_PRINT, 1);
    audioTest(ZARU_ONLYL,length);

    ZaruWriteReg2(REG_AUDIO,ZARU_ONLYR); /* sasano added */
    sprintf(message,"When press yellow button,\nOutput sin wave\nonly Right channel");
    gng_report(message, 1, GNG_INHIBIT_PRINT, 1);
    audioTest(ZARU_ONLYR,length);
    
    return GNG_TEST_SUCCESS;
}

void presstonext(){
    char message[80];
    sprintf(message,"When press yellow button,\nGo next test.");
    gng_report(message, 1, GNG_INHIBIT_PRINT, 1);
    ZaruWaitForNextTestButton();
}

/**************************************************************************
  現在接続されているジョイチャンネルを取得 
  ************************************************************************/
int ZaruGetCurrentChannel( void ){
    int i;
    u8  data[16];
    ZaruReadAllControllerButton( data );
    /* 現在接続されているジョイチャンネルを検索 */
    for( i=0 ; i<4; i+=1 ){
	if( ( data[i*4]&0x80 )== 0 ) return i;
    }
    return 0xffff; /* 接続なし */
}



int ContTest(){
    int i,j=0;
    u16 ikey1[MAXCONTROLLERS],ikey2[MAXCONTROLLERS];
    char message[256];
    u8   command;           /* 検査器側からの命令             */
    u8 data[16];            /* コントローラの状態保存用配列   */
    u16 *Data16b;           /* データ切出用にデータ形式の変換 */
    int ch;                 /* 検査で使用するチャンネル       */

    /* 検査画面表示 */
    gng_report( "Controller test:\nPlease wiggle (shake)\ncontroller inputs\nduring test.\n\nPress yellow button\nto continue...",
		0, GNG_INHIBIT_PRINT, 0);

    /* 検査ループ */
    while(1){
	j++;
	/* コントローラ読取許可待ち */
	while( 1 ){
	    /* ジョイチャンネル接続状況読取(接続なし=0xffff) */
	    ch = ZaruGetCurrentChannel();
	    /* 接続先からコントローラ読取リクエストを受け取る */
	    if ( ch != 0xffff ){
		/* コントローラが接続されているとき */
		command=ZaruReadReg4( REG_CONTLOOP, ch );
		if ( (command &0x80)== 0 )break;
	    }
	}    

	/* 検査終了判定 */
	if( command == ZARU_CONTLOOPEXIT ) break;

	/* 全チャンネルのコントローラデータ読み出し */
	ZaruReadAllControllerButton( data );
	
	/* データを検査器側に転送 */
	switch( ch ){
	  case 0:  ZaruWriteReg4(REG_CONTRESULT0,16,data,0); break;
	  case 1:  ZaruWriteReg4(REG_CONTRESULT1,16,data,1); break;
	  case 2:  ZaruWriteReg4(REG_CONTRESULT2,16,data,2); break;
	  case 3:  ZaruWriteReg4(REG_CONTRESULT3,16,data,3); break;
	  default: break;
	}

	/* 画面表示用にデータ形式の変換をおこなう */
	Data16b = (u16 *)data; /* データ切出用にデータ形式の変換 */
	for( i=0 ; i<4 ; i++ ){
	    ikey1[i]=*Data16b;  Data16b++;
	    ikey2[i]=*Data16b;  Data16b++;
	}
	
	/* 画面表示 */
	sprintf(message,"Controller Status %d\n\n 1P:%04x %04x\n 2P:%04x %04x\n 3P:%04x %04x\n 4P:%04x %04x",j,ikey1[0],ikey2[0],ikey1[1],ikey2[1],ikey1[2],ikey2[2],ikey1[3],ikey2[3]);
	gng_report(message,1,GNG_INHIBIT_PRINT,1);
	
	/* コントローラ読取ポートのシンク */
	while ( ZaruReadReg4( REG_CONTLOOP, ch )&ZARU_CONTNOWRITE == 0 );
    }
    return GNG_TEST_SUCCESS;
}

int DummyTest(){
    char message[80];
    gngstatus *pstatus;
    int rdramDiagStatus,rdramDiagErrors;
    u32 rdramDiagSasano,rdramDiagExpect,rdramDiagReaddt;
    
    pstatus = (gngstatus *)osAppNMIBuffer;
    rdramDiagStatus = pstatus->rdram_diag_status;
    rdramDiagErrors = pstatus->rdram_diag_errors;
    rdramDiagSasano = pstatus->rdram_diag_sasano;
    rdramDiagExpect = pstatus->rdram_diag_expect;
    rdramDiagReaddt = pstatus->rdram_diag_readdt;

    sprintf(message,"Dummy\nStatus=%x\nErrors=%x\nSasano=%x\nExpect=%x\nReaddt=%x",rdramDiagStatus,rdramDiagErrors,rdramDiagSasano,rdramDiagExpect,rdramDiagReaddt);
    while(ZaruReadReg2(REG_PAUSE)==ZARU_PAUSE){
	gng_report(message, 1, GNG_INHIBIT_PRINT, 1);
    }
    
    (void)osRecvMesg(&retraceMessageQ, NULL, OS_MESG_BLOCK);
    return GNG_TEST_SUCCESS;
}


void testLoop(int index) {
    char message[256];
    Test_t *pTest;
    int errCount;
    u8 directtest;
    int i,j;
    
    /*	RunViTests();*/
    
    pTest = &(testList[index]);
    while (pTest->pTestFunction != NULL) {
	
	do {
	    if (ZaruReadReg2(REG_DIRECTENBL)!=ZARU_DIRECTDSBL) {
		i=ZaruReadReg2(REG_DIRECTTEST);
		j=0;
		
		while(1){
		    pTest = &(testList[j]);
		    if ((pTest->testNumber) == i) {
			index=j;
			break;
		    }
		    j++;
		    if ((pTest->testNumber)==0xff) {
			while(1) {gng_report("Error index number.\nHalted.",1,GNG_INHIBIT_PRINT,1);}
		    }
		}
		pTest = &(testList[index]);
		ZaruWriteReg2(REG_DIRECTENBL,ZARU_DIRECTDSBL);
	    }
	    
	    /* write pTest->testNumber to the LED panel on the ZARU test jig */
	    ZaruSetMemA(pTest->testNumber);
	    
	    /* Always print the test message before the test starts.  We'll re-print the message with PASS/FAIL reporting afterwards, if the test requested it.  */
	    
	    gng_report(pTest->gngMessageText, 1, GNG_INHIBIT_PRINT, 1);
	    if (pTest->presswait == 1) ZaruWaitForNextTestButton();
	    sprintf(message,"%s\nworking...",pTest->gngMessageText);
	    gng_report(message, 1, GNG_INHIBIT_PRINT, 1);
	    
	} while (ZaruReadReg2(REG_DIRECTENBL) != ZARU_DIRECTDSBL);
	
	/*  Run the test.  */
	errCount = (*pTest->pTestFunction)();
	
	/*  If test does need PASS/FAIL reporting, do so now.  */
	if (pTest->testFlags & GNG_PASS_FAIL_BIT) gng_report(pTest->gngMessageText, errCount, pTest->testFlags, pTest->retraceCount);
	
	pTest = &(testList[++index]);
	

	
        if (ZaruReadReg2(REG_DIRECTENBL)!=ZARU_DIRECTDSBL) {
	    i=ZaruReadReg2(REG_DIRECTTEST);
	    j=0;
	    
	    while(1){
		pTest = &(testList[j]);
		if ((pTest->testNumber) == i) {
		    index=j;
		    break;
		}
		j++;
		if ((pTest->testNumber)==0xff) {
		    while(1) {gng_report("Error index number.\nHalted.",1,GNG_INHIBIT_PRINT,1);}
		}
	    }
	    pTest = &(testList[index]);
	    ZaruWriteReg2(REG_DIRECTENBL,ZARU_DIRECTDSBL);
	}
	
	
	
	
	
    }
    sprintf(message,"Go/No-go testing complete.\n%s\n",NOWTIME);
    gng_report(message, 0, GNG_PASS_FAIL_BIT | GNG_FINAL_TEST_BIT, 0);
    ZaruWriteReg2(REG_ALLEND,0x80);
}

void testDriver(int nmiEntryFlag) {
    Test_t *pTest;
    int i;
    gngstatus *pstatus;
    int rdramDiagStatus,rdramDiagErrors;
    char message[80];
    char data[6];
    
    if (nmiEntryFlag == FALSE) {

	/* Iterate through the tests; optionally do a gng_report with their status upon completion.  */
	
	pstatus = (gngstatus *)osAppNMIBuffer;
	pstatus->rdram_diag_status=0;
	
	/* SetVersionNumber */
	sprintf(message,NOWTIME);
	data[0]=((message[0]-'0')<<4)+(message[1]-'0');
	data[1]=((message[3]-'0')<<4)+(message[4]-'0');
	data[2]=((message[6]-'0')<<4)+(message[7]-'0');
	data[3]=((message[9]-'0')<<4)+(message[10]-'0');
	data[4]=((message[12]-'0')<<4)+(message[13]-'0');
	data[5]=((message[15]-'0')<<4)+(message[16]-'0');
	ZaruWriteReg3(REG_VERSION,6,data);
	
	testLoop(0);
    } else {
	/* Find the NMI test by examining the testFlags field, then print a gng_report() as per the testFlags, retraceCount fields.  Then, iterate through the rest of the test sequence.  */
	ZaruWriteReg2(REG_RESET,ZARU_AFTERRESET); /* sasano added */
	i = 0;
	pTest = &(testList[i]);
	
	while ( (pTest->pTestFunction != NULL) && (pTest->testFlags & GNG_NMI_TEST_BIT) == 0 )  pTest = &(testList[++i]); 
	/* We should be pointing at the NMI test now.  Skip past it & continue. */
	testLoop(++i);
    }
}