ai_pintests.c 3.62 KB
#include <sys/types.h>
#ifdef __sgi__
#include <sys/sbd.h>
#endif
#include <sys/stat.h>
#include <sys/mman.h>
#ifdef __sgi__
#include <sys/sema.h>
#endif
#include <netinet/in.h>

#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>



#include <rcp.h>

#include "diag.h"
#include <dbg_comm.h>

int
ai_pintests (TEST_REF *test_ref)
{


    int NumFailures = 0;
    int DmaInProcess;
    int i;
    int reg_value ;
    unsigned int bit_rate_clear;
    unsigned int bit_rate_set;

    int *pwbuf;
    int *prbuf;
    unsigned int numbytes;
    unsigned int rdbuf;

#define NumSamples 4
    unsigned char wbuf[NumSamples*4];
    unsigned char rbuf[NumSamples*4];

    pwbuf = (int *)wbuf;
    prbuf = (int *)rbuf;

    /* Initialize Rdram */
    errlog(DEBUG,"Initializing Rdram");


    /* send 4 samples out to the DAC
     * each sample is  2 16 bit l/r channel pairs
     */
/* rdram image for audio buffer
 * 63   48:47   32:31   16:15   00
 *   L0       R0     L1      R1
 *   Sample 0     :   Sample 1
 */

    *pwbuf      = 0x8ef08000;
    *(pwbuf+1)  = 0x8ef18001;

    *(pwbuf+2) = 0x8ef28002;
    *(pwbuf+3) = 0x8ef38003;

    numbytes =  NumSamples * 4;



        for (i = 0; i < NumSamples ; i ++) {
        if (dgWriteWord ((dgRdramFree+(i*4)),*(pwbuf+i)))  return (1);

        if (dgReadWord ((dgRdramFree+(i*4)),&rdbuf)) return (1);
        errlog (DEBUG,"rdram data is %08x",rdbuf);
        if (rdbuf != *(pwbuf+i)) {
        errlog ( ERR_SEVERE,
        "Rdram buffer load failed - actual = %08x, expected = %08x",
                rdbuf, *(pwbuf+i));
        }
    }

/*
    if (dgWriteMem (dgRdramFree, numbytes, ((char *)pwbuf)) ) return (1);
    if (dgReadMem  (dgRdramFree, numbytes, ((char *)prbuf)) ) return (1);

    for (i = 0; i < NumSamples; i++){
  errlog(DEBUG,"MemDatat is %08x",*(pwbuf+i));
      if (*(pwbuf+i) != *(prbuf+i) ) {
      errlog(ERR_SEVERE,
          "Rdram buffer load failed - actual = %08x, expected = %08x",
          *(prbuf+i), *(pwbuf+i));
      }
    }
*/

        /* Init VI to get video clock signal into AI */
        if (dgWriteWord(VI_STATUS_REG, 0) ) return (1);
    /* need read status word and compare */

        /* To get ~44.1 KHz for audio (based on Rambus clock of 243.37 MHz
         * and video clock of 48.67 MHz), AI dac rate = 1103 (0x44f) and
         * AI bit rate = 15 (0xf)
         */
        if ( dgWriteWord(AI_DACRATE_REG, 0x44f) ) return (1);
        if ( dgWriteWord(AI_BITRATE_REG, 0xf) ) return (1);


    /* ensure ai status word indicates dma not full */
    if (dgReadWord(AI_STATUS_REG, &rdbuf) ) return (1);

    if (rdbuf & AI_STATUS_FIFO_FULL)
    errlog (ERR_SEVERE,"AI Status is full, should be 0 on reset");

    if (dgWriteWord(AI_DRAM_ADDR_REG,dgRdramFree) ) return(1);
    if (dgWriteWord(AI_LEN_REG,(NumSamples*2)) ) return (1);
    /* try the double buffer */
/* not sure double bufferd is needed.
    if (dgWriteWord(AI_DRAM_ADDR_REG,dgRdramFree) ) return(1);
    if (dgWriteWord(AI_LEN_REG,(NumSamples*2)) ) return (1);
*/


    /* turn on dma */
    errlog(DEBUG,"Starting Audio DMA Now");
        if ( dgWriteWord(AI_CONTROL_REG, AI_CONTROL_DMA_ON) ) return (1);


    /* monitor audio length till its 0 */
    DmaInProcess = 1;
    while (DmaInProcess){
    if (dgReadWord(AI_LEN_REG,&rdbuf)) return (1);

    if (rdbuf != 0) {
        errlog(DEBUG,"Length is now %08x",rdbuf);
    DmaInProcess = 1;
    }
    else {
    errlog(INFO,"Audio DMA Complete");
    DmaInProcess = 0;
    }
    }

/* kill some time */
for (i = 0; i < 512; i++){
if (dgReadWord(AI_STATUS_REG, &rdbuf) ) return (1);
errlog(DEBUG,"AI DAC Counter is %08x",((rdbuf & 0xff) >> 1));
}

    return(NumFailures);

}