osAiTest.c 4.08 KB
/*====================================================================
 * osAiTest.c
 * 
 *  Test for the hardware bug in osAiSetNextBuffer, where buffer ends
 *     that end in a set bit followed by 13 zeroes cause the next Ai
 *     DMA to fail.
 *
 *
 * Copyright 1993, Silicon Graphics, Inc.
 * All Rights Reserved.
 *
 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics,
 * Inc.; the contents of this file may not be disclosed to third
 * parties, copied or duplicated in any form, in whole or in part,
 * without the prior written permission of Silicon Graphics, Inc.
 *
 * RESTRICTED RIGHTS LEGEND:
 * Use, duplication or disclosure by the Government is subject to
 * restrictions as set forth in subdivision (c)(1)(ii) of the Rights
 * in Technical Data and Computer Software clause at DFARS
 * 252.227-7013, and/or in similar or successor clauses in the FAR,
 * DOD or NASA FAR Supplement. Unpublished - rights reserved under the
 * Copyright Laws of the United States.
 *====================================================================*/

#include <libaudio.h>
#include "audio.h"
#include "audiotest.h"


static void startOsAiTest();
static void stopOsAiTest();
static void doOsAiRetrace();
static void osAiButtProc(u16 oldButton,u16 newButton);

test_cntrl OsAiTest = {
    &startOsAiTest,
    &stopOsAiTest,
    &osAiButtProc,      /* button proc */
    &doOsAiRetrace,
    NULL,            /* void *retraceData */
    1                /* u32  numSubTests */
};

extern u32      gTestDone;
extern ALHeap   gHeapRec;
extern u8       gHeapBuf[AUDIO_HEAP_SIZE];


static OSThread     audThread;
static u64          audThreadStack[STACKSIZE/8];


static void audProc(void *arg);

/***********************************************************************
 * Test interface routines
 ***********************************************************************/
static void startOsAiTest() 
{
    PRINTF("Audio Hardware bug test. If sound is smooth square wave,\n");
    PRINTF("all is OK. If sound is jittery, bug is occurring.\n");
    PRINTF("Press any button to continue to next test.\n");
    osCreateThread(&audThread, 9, audProc, 0, audThreadStack+STACKSIZE/8, AUDIO_PRIORITY);
    osStartThread(&audThread); 

}

static void audProc(void *arg)
{

    OSMesg          *msg = 0;
    s32             res;
    OSMesgQueue     audioTestMsgQ;
    OSMesg          audioTestMsgBuf[MAX_MESGS];
    u32             i, d;
    s16             *data;
    s32             lastFrame;
    s32             thisFrame;
    s16             *outData[3];
    u32             waveCt = 0;
    u32             audioFrameCt = 1;
    u32             frmSize = 0x400; 
    u32             endAddr;

    osAiSetFrequency(44100);

    endAddr = (u32)&gHeapBuf[0x10000];

    endAddr &= 0xFFFFC000;  /* clear lower fourteen bits */
    endAddr |= 0x00001000;  /* set bit 12, */
                            /* when added with 400 * 4 bytes per sample */
                            /* will equal clear lower thirteen bits with */
                            /* next bit set */

    outData[0] = (s16*) endAddr;
    outData[2] = (s16*)(endAddr + 0x8000 );
    outData[1] = (s16*)(endAddr + 0x10010);

    osCreateMesgQueue(&audioTestMsgQ, audioTestMsgBuf, MAX_MESGS);
    osSetEventMesg(OS_EVENT_AI,&audioTestMsgQ,&msg);
    osSendMesg(&audioTestMsgQ,(OSMesg)&msg,OS_MESG_BLOCK);

    while(!gTestDone)
    {
        (void) osRecvMesg(&audioTestMsgQ, (OSMesg *)&msg, OS_MESG_BLOCK);

	lastFrame = (audioFrameCt-1)%3;
	thisFrame = audioFrameCt%3;

	res =osAiSetNextBuffer(outData[lastFrame], (u32)frmSize<<2); 
	if(res < 0)
	    PRINTF("osAiSetNextBuffer %d\n",res); 

	data = outData[thisFrame];

	for(d = 0; d < (2*frmSize) ; d++)
	{
	    if(waveCt < 0x7E)
	    {
		data[d] = (s16)0x2000;
		waveCt++;
	    }
	    else
	    {
		data[d] = (s16)0xe000;
		waveCt++;
		if(waveCt >= 0xFc)
		    waveCt = 0;
	    }	    
	}

	osWritebackDCacheAll();

	audioFrameCt++;
    }
}

static void stopOsAiTest() 
{

}

static void doOsAiRetrace() 
{

}

static void osAiButtProc(u16 oldButton,u16 newButton)
{
    if(newButton)
    {
	osDestroyThread(&audThread);
	gTestDone = 1;
    }
}