⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rawtest.c

📁 dsp程序
💻 C
字号:
/*
 *  Copyright 2002 by Texas Instruments Incorporated.
 *  All rights reserved. Property of Texas Instruments Incorporated.
 *  Restricted rights to use, duplicate or disclose this code are
 *  granted through contract.
 *  
 */
/* "@(#) LIO 1.00.01 02-20-02 (swat-b08)" */
/* 
 *  ======== rawtest.c ========
 * 
 *  This example demonstrates the use of LIO drivers and is called "raw" 
 *  because the LIO driver interface is being called directly, or "raw",
 *  instead of called via PIP or SIO adapter. The application performs a 
 *  loopback, that is audio data is read from a buffer from an input 
 *  channel, then writes the buffer back out to an output channel.  There 
 *  are two buffers per input/output channel.  The buffers are created 
 *  statically as arrays, signaling is done via a DSP/BIOS software interrupt 
 *  (SWI) object.
 *
 *  The following objects need to be created in the DSP/BIOS
 *  configuration for this application:
 *
 *  * A SWI object named swiEcho. Configure the function as _echo,
 *    and the mailbox value as 3.
 *
 *  * A LOG object named trace, used for status and debug output. Can be
 *    any size and can be circular or fixed.
 */

#include <std.h>
#include <log.h> 
#include <sem.h>
#include <lio.h> 

#include <string.h>

#define BUFSIZE 128

/* Set DRIVER_FXN_TABLE in the linker command file. */
extern LIO_Fxns CONTROLLER_FXN_TABLE;
static LIO_Fxns *controller = &CONTROLLER_FXN_TABLE;

extern far LOG_Obj trace; /* application printf() log, any size */
extern far SWI_Obj swiEcho; /* SWI object which runs when buffers are ready */

/*
 * Ping-pong buffers to be used for transfers.
 * Variables rxDone, rxBusy, txDone, txBusy manipulated by XOR operation
 * are used to keep the status of those pinp-pong buffers.  Align on a 
 * 128 byte boundary for L2 cache. 
 */
#pragma DATA_ALIGN (rxBuf , 128);
unsigned short rxBuf[2][BUFSIZE];
#pragma DATA_ALIGN (txBuf , 128);
unsigned short txBuf[2][BUFSIZE];

/* forward decl of callback function */
static Void rxCallback(Arg arg, Uns nmaus);  /* receive callback */ 
static Void txCallback(Arg arg, Uns nmaus);  /* transmit callbaack */

/*
 * 'rx' and 'tx' will be initialized with the return value from
 * the driver open function.
 */
Ptr rx;
Ptr tx;

/*
 * variables that are used to keep track of the usage of the buffers 
 * for both receive and transmit channels
 */
Int rxBusy = 0;
Int txBusy = 0;
Int rxDone = 0;
Int txDone = 0;

/*
 *  ======== main ========
 *
 *  Application startup funtion called by DSP/BIOS. Open the LIO
 *  channels, puts two buffers into the to-device queue on the receive
 *  channel, starts the channels, then returns back into DSP/BIOS.
 */
Void main()
{

    /*
     * CONTROLLER_init() initializes the device controller.
     * Set CONTROLLER_init() in the linker command file.
     */

    CONTROLLER_init();
    CONTROLLER_setup(NULL);
    
    /* Open the LIO channels */
    rx = controller->open(NULL, LIO_INPUT, NULL, rxCallback, NULL); 
    tx = controller->open(NULL, LIO_OUTPUT, NULL, txCallback, NULL); 
    
    /* Initialize two buffers of silence for the output queue. */        
    memset(txBuf[0], 0, BUFSIZE*sizeof(short));
    memset(txBuf[1], 0, BUFSIZE*sizeof(short));
    
    /* 
     * Submit rxBuf[0] to the LIO_INPUT channel and 
     * submit txBuf[0] to the LIO_OUTPUT channel;
     * This is the initialization for buffer transfers 
     */
    controller->submit(tx, txBuf[0], BUFSIZE*sizeof(short)); /* Start output */
    controller->submit(tx, txBuf[1], BUFSIZE*sizeof(short)); /* Start output */
    controller->submit(rx, rxBuf[0], BUFSIZE*sizeof(short)); /* Start input */
    controller->submit(rx, rxBuf[1], BUFSIZE*sizeof(short)); /* Start input */

    LOG_printf(&trace, "RAWTEST STARTED!");
}

/*
 *  ======== echo ========
 *
 *  This function is run as a DSP/BIOS SWI thread created statically with
 *  the DSP/BIOS configuration tool.
 */
Void echo()
{
    Int i;  
    
    for (i = 0; i < BUFSIZE; i++) {
        /*
         * For certain codecs, the least significant bit (when bit0 = 1)
         * is interpreted as command bit
         */
        txBuf[txDone][i] = rxBuf[rxDone][i] & 0xFFFE;
    }     
    rxDone = rxDone ^ 1;                /* XOR for rxDone */            
    txDone = txDone ^ 1;                /* XOR for txDone */
}
 

/*
 *  ======== rxCallback ========
 *
 *  Callback function for the LIO_INPUT channel 
 */
static Void rxCallback(Arg arg, Uns nmaus)
{
    rxBusy = rxBusy ^ 1;                /* XOR for rxBusy */
    controller->submit(rx, rxBuf[rxBusy], BUFSIZE*sizeof(short));
    SWI_andn(&swiEcho, 0x0001);
}

/*
 *  ======== txCallback ========
 *
 *  Callback function for the LIO_OUTPUT channel
 */ 
static Void txCallback(Arg arg, Uns nmaus)
{
    txBusy = txBusy ^ 1;                /* XOR for txBusy */
    controller->submit(tx, txBuf[txBusy], BUFSIZE*sizeof(short));
    SWI_andn(&swiEcho, 0x0002);
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -