virage.c 4.71 KB
#include "ultra64.h"
#include "os_bb.h"
#include "bcp.h"

#include "virage.h"
#include "nvram_test.h"
#include "nvram_util.h"
#include "nu64sys.h"
#include "graph.h"

#define PRINTF osSyncPrintf

/*
 * Thread and stack structures
 */
char   bootStack[STACKSIZE] __attribute__ ((aligned (8)));

static OSThread idleThread;
static char     idleThreadStack[STACKSIZE] __attribute__ ((aligned (8)));

static OSThread mainThread;
static char     mainThreadStack[STACKSIZE] __attribute__ ((aligned (8)));


static void		idleproc(char *);
static void		mainproc(char *);
static void             run();


void
boot(void)
{
  __osBbVideoPllInit(OS_TV_NTSC);
    osInitialize();
    osCreateThread(&idleThread, 1, (void(*)(void *))idleproc, (void *)0,
                   idleThreadStack+STACKSIZE, 8);
    osStartThread(&idleThread);
}

static void
idleproc(char *argv)		/* priority 8 */
{
    osCreateViManager(OS_PRIORITY_VIMGR);
#if	SCREEN_LOW
    osViSetMode(&osViModeTable[OS_VI_NTSC_LPN1]);
#else
    osViSetMode(&osViModeTable[OS_VI_NTSC_HPF1]);
#endif

    /*
     * The main thread's priority must be the same or lower than the original
     * idle's thread priority. This allows the idle thread to change its
     * priority to 0 before the main thread starts execution.
     */
    osCreateThread(&mainThread, 3, (void(*)(void *))mainproc, argv,
           mainThreadStack+STACKSIZE/8, (OSPri)7);
    osStartThread(&mainThread);

    osSetThreadPri(0, OS_PRIORITY_IDLE);
    for(;;);                                    /* idle thread */
}

static OSMesgQueue	retraceMessageQ;
static OSMesg		dummyMessage, retraceMessageBuf;

static u16 cfb[SCREEN_WD*SCREEN_HT] __attribute__((aligned(64)));
static void clear(u16 bg) {
    int i;
    for (i = 0; i < SCREEN_WD*SCREEN_HT; ++i) {
            cfb[i] = bg;
    }
}

static void 
mainproc(char *argv)		{
    osCreateMesgQueue(&retraceMessageQ, &retraceMessageBuf, 1);
    osViSetEvent(&retraceMessageQ, dummyMessage, 1);
    osViBlack(1);
    osViSwapBuffer(cfb);
    clear(0);
    osViBlack(0);
    osWritebackDCacheAll();
    osViSwapBuffer(cfb);

    run();
    for(;;) ;
}


static void run(void) 
{
        
   
    int loops = 0;
    int sysclk_scale = 1;
    int fail = 0;
    u32 starttime;
    u32 endtime;
    
    
    starttime= osGetCount();

    for(loops = 0; loops < 100; loops++) {        
        if (nms_store_test(sysclk_scale, VIRAGE0_CTRL_REG, 16, 0) != PASS) {
            sprintf(buf, "VIRAGE0 def store %d FAIL", loops);
            printstr(white, 3, 2, buf);
            osWritebackDCacheAll();
            fail  = 1;
        } else {
            sprintf(buf, "VIRAGE0 def store %d PASS", loops);
            printstr(white, 3, 2, buf);
            osWritebackDCacheAll();
        }
    }
   
    endtime = osGetCount();
    bzero(buf, sizeof(buf));
    sprintf(buf, "Time taken = %llu", OS_CYCLES_TO_USEC(endtime - starttime));
    printstr(white, 3, 4, buf);
    osWritebackDCacheAll();

    if(fail == 1){
         sprintf(buf, "****FAILED**********");
         printstr(white, 3, 12, buf);
         osWritebackDCacheAll();
    }

    starttime= osGetCount();

    fail = 0;
    
    for(loops = 0; loops < 100; loops++){
        if (nms_store_test(sysclk_scale, VIRAGE1_CTRL_REG, 16, 0) != PASS) {
            sprintf(buf, "VIRAGE1 def store %d FAIL", loops);
            printstr(white, 3, 6, buf);
            osWritebackDCacheAll();
            fail = 1;
        } else {
            sprintf(buf, "VIRAGE1 def store %d PASS", loops);
            printstr(white, 3, 6, buf);
            osWritebackDCacheAll();
        }
    }

    endtime = osGetCount();
    bzero(buf, sizeof(buf));
    sprintf(buf, "Time taken = %llu", OS_CYCLES_TO_USEC(endtime - starttime));
    printstr(white, 3, 8, buf);
    osWritebackDCacheAll();
    
    if(fail == 1){
         sprintf(buf, "****FAILED**********");
         printstr(white, 3, 12, buf);
         osWritebackDCacheAll();
    }

    fail = 0;
    
    starttime= osGetCount();

    for(loops = 0; loops < 100; loops++){
        if (nms_store_test(sysclk_scale, VIRAGE2_CTRL_REG, 64, 0) != PASS) {
            sprintf(buf, "VIRAGE2 def store %d FAIL", loops);
            printstr(white, 3, 10, buf);
            osWritebackDCacheAll();
            fail = 1;
        } else {
            sprintf(buf, "VIRAGE2 def store %d PASS", loops);
            printstr(white, 3, 10, buf);
            osWritebackDCacheAll();
        }
     
    }
    endtime = osGetTime();
    bzero(buf, sizeof(buf));
    sprintf(buf, "Time taken = %llu", OS_CYCLES_TO_USEC(endtime - starttime));
    printstr(white, 3, 12, buf);
    osWritebackDCacheAll();
    
    if(fail == 1){
         sprintf(buf, "****FAILED**********");
         printstr(white, 3, 12, buf);
         osWritebackDCacheAll();
    }

    for(;;);
    
}