📄 siotest.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)" */
/*
* ======== siotest.c ========
*
* This example demonstrates the use of LIO drivers with SIOs by
* using the the LIO SIO driver. This is a loopback application. Audio
* is read from an input SIO, then sent back out on an output SIO.
*
* The following objects need to be created in the DSP/BIOS
* configuration for this application:
*
* * A UDEV object, which links in a user SIO device driver. In this
* case the UDEV is an LIO SIO driver.
* * A TSK object, with the function to run set to the function echo
* defined in this file.
* * A LOG named trace for debug and status output.
*/
#include <std.h>
#include <log.h>
#include <sys.h>
#include <mem.h>
#include <sio.h>
#include <dlio.h>
#include <lio.h>
#define BUFLEN 128 /* number of samples in a frame */
#define BUFSIZE (BUFLEN * sizeof(unsigned short))
#define BUFALIGN 128 /* alignment of buffer to allow use of L2 cache */
extern far LOG_Obj trace;
/* Set CONTROLLER_FXN_TABLE in the linker command file. */
extern LIO_Fxns CONTROLLER_FXN_TABLE;
DLIO_Params dlioParams = {
&CONTROLLER_FXN_TABLE,
NULL
};
/*
* inStream and outStream are SIO objects created in main
*/
SIO_Obj *inStream, *outStream;
/*
* ======== main ========
*/
main()
{
Ptr buf0, buf1, buf2, buf3;
SIO_Attrs attrs;
/* align the buffer to allow it to be used with L2 cache */
attrs = SIO_ATTRS;
attrs.align = BUFALIGN;
attrs.model = SIO_ISSUERECLAIM;
/*
* 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);
/* open the streams */
inStream = SIO_create("/codec", SIO_INPUT, BUFSIZE, &attrs);
if (inStream == NULL) {
SYS_abort("Open of codec for input FAILED.");
}
outStream = SIO_create("/codec", SIO_OUTPUT, BUFSIZE, &attrs);
if (outStream == NULL) {
SYS_abort("Open of codec for output FAILED.");
}
/* Allocate buffers for the SIO buffer exchanges */
buf0 = (Ptr)MEM_calloc(0, BUFSIZE, BUFALIGN);
buf1 = (Ptr)MEM_calloc(0, BUFSIZE, BUFALIGN);
buf2 = (Ptr)MEM_calloc(0, BUFSIZE, BUFALIGN);
buf3 = (Ptr)MEM_calloc(0, BUFSIZE, BUFALIGN);
if (buf0 == NULL || buf1 == NULL || buf2 == NULL || buf3 == NULL) {
SYS_abort("MEM_calloc failed.");
}
/* Issue the first & second empty buffers to the input stream */
if (SIO_issue(inStream, buf0, SIO_bufsize(inStream), NULL) < 0) {
SYS_abort("Error issuing buffer");
}
if (SIO_issue(inStream, buf1, SIO_bufsize(inStream), NULL) < 0) {
SYS_abort("Error issuing buffer");
}
/* Issue the first & second empty buffers to the output stream */
if (SIO_issue(outStream, buf2, SIO_bufsize(outStream), NULL) < 0) {
SYS_abort("Error issuing buffer");
}
if (SIO_issue(outStream, buf3, SIO_bufsize(outStream), NULL) < 0) {
SYS_abort("Error issuing buffer");
}
LOG_printf(&trace, "SIOTEST STARTED!");
}
/*
* ======== echo ========
* Run within a TSK configured in the DSP/BIOS configuration for the
* application. Performs the loopback operation.
*/
void echo(void)
{
Int i, nbytes;
unsigned short *inbuf, *outbuf;
/* Loop forever looping back buffers */
for (;;) {
/* Reclaim full buffer from the input stream */
if ((nbytes = SIO_reclaim(inStream, (Ptr *)&inbuf, NULL)) < 0) {
SYS_abort("Error reclaiming buffer");
}
/* Reclaim empty buffer from the output stream to be reused */
if (SIO_reclaim(outStream, (Ptr *)&outbuf, NULL) < 0) {
SYS_abort("Error reclaiming buffer");
}
/*
* 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 < (nbytes / sizeof(short)); i++) {
outbuf[i] = inbuf[i] & 0xfffe;
}
/* Issue full buffer to the output stream */
if (SIO_issue(outStream, outbuf, nbytes, NULL) < 0) {
SYS_abort("Error issuing buffer");
}
/* Issue an empty buffer to the input stream */
if (SIO_issue(inStream, inbuf, SIO_bufsize(inStream), NULL) < 0) {
SYS_abort("Error issuing buffer");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -