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

📄 piptest.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)" */
/*
 *  ======== piptest.c ========
 *
 *  This example demonstrates the use of LIO drivers with PIPs and
 *  the lio_pip adapter code. The application performs a loopback, that
 *  is audio data is read from one PIP connected to an input LIO
 *  channel, the the data is written back out on a PIP connected to an
 *  output LIO channel.
 *
 *  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.
 *
 *  * 2 PIP objects, one named pipTx, the other pipRx. The length of the
 *    buffers should be the same and can be any size. See the comments
 *    by the declarations below of pipTx and pipRx for the writer and
 *    reader notify function settings.
 *
 *  * 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 <pip.h>
#include <swi.h>
#include <sys.h>

#include <lio.h>
#include <plio.h>

/* Set CONTROLLER_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 PIP_Obj pipRx; /* writerNotify -> PLIO_rxPrime(plioRx)
                           * readerNotify -> SWI_andn(swiEcho,1) */
extern far PIP_Obj pipTx; /* writerNotify -> SWI_andn(swiEcho,2)
                           * readerNotify -> PLIO_txPrime(plioTx) */
extern far SWI_Obj swiEcho; /* SWI object which runs when buffers are ready. */

/*
 *  'plioRx' and 'plioTx' objects will be initialized by PLIO_new(). 
 */
PLIO_Obj plioRx, plioTx;

/*
 *  ======== main ========
 *
 *  Application startup funtion called by DSP/BIOS. Initialize the
 *  PLIO adapter then return back into DSP/BIOS.
 */
main()
{
    /*
     * CONTROLLER_init() initializes the device controller.
     * Set CONTROLLER_init() in the linker command file.
     */ 
    CONTROLLER_init();

    /*
     * CONTROLLER_setup() configures device with parameter.
     * If NULL is specified then the default settings will be used.
     * Set CONTROLLER_setup() in the linker command file.
     */
    CONTROLLER_setup(NULL);

    /*
     * Initialize PLIO module
     */
    PLIO_init();

    /* Bind the PIPs to LIO channels */
    PLIO_new(&plioRx, &pipRx, LIO_INPUT, controller, NULL);
    PLIO_new(&plioTx, &pipTx, LIO_OUTPUT, controller, NULL);

    /*
     * Prime the transmit side with buffers of silence.
     * The transmitter should be started before the receiver.
     * This results in input-to-output latency being one full
     * buffer period if the pipes is configured for 2 frames.
     */
    PLIO_txStart(&plioTx, PIP_getWriterNumFrames(&pipTx), 0);

    /* Prime the receive side with empty buffers to be filled. */
    PLIO_rxStart(&plioRx, PIP_getWriterNumFrames(&pipRx));

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


/*
 *  ======== echo ========
 *
 *  This function is by the swiEcho DSP/BIOS SWI thread created
 *  statically with the DSP/BIOS configuration tool. The PLIO adapter
 *  posts the swi when an the input PIP has a buffer of data and the
 *  output PIP has an empty buffer to put new data into. This function
 *  copies from the input PIP to the output PIP. You could easily
 *  replace the copy function with signal processing code.
 */
Void echo(Void)
{
    Int i, size;
    unsigned short *src, *dst;

    /*
     * Check that the precondions are met, that is pipRx has a buffer of
     * data and pipTx has a free buffer.
     */
    if (PIP_getReaderNumFrames(&pipRx) <= 0) {
        LOG_error("echo: No reader frame!", 0);
        return;
    }
    if (PIP_getWriterNumFrames(&pipTx) <= 0) {
        LOG_error("echo: No writer frame!", 0);
        return;
    }

    /* get the full buffer from the receive PIP */
    PIP_get(&pipRx);
    src = PIP_getReaderAddr(&pipRx);
    size = PIP_getReaderSize(&pipRx) * sizeof(short);

    /* get the empty buffer from the transmit PIP */
    PIP_alloc(&pipTx);
    dst = PIP_getWriterAddr(&pipTx);

    /* 
     * Do the data move. Mask off the low bit for compatibility with
     * those codecs that interpret a low bit of '1' as a command flag. 
     */
    for (i = 0; i < size; i++) {
        *dst++ = *src++ & 0xfffe;
    }     

    /* Record the amount of actual data being sent */
    PIP_setWriterSize(&pipTx, PIP_getReaderSize(&pipRx));

    /* Free the receive buffer, put the transmit buffer */
    PIP_put(&pipTx);
    PIP_free(&pipRx);
}

⌨️ 快捷键说明

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