![]() |
|
||||||||||||||
| . 网站首页 . 新闻 . 新品 . 方案 . 专访 . 活动 . DSP . EDA . 评测室 . 技术文库 . 会员区 . 商城 . 服务导航 . 邮购 . 资源 . | ||
|
||
|
|||||
| 使用PIPE进行数据传递 | |||||
作者:C003 文章来源:本站 点击数: 更新时间:2007-4-5 ![]() |
|||||
|
在该例程中,我们将使用DSP/BIOS内核提供的PIPE管道操作来完成数据传递。在DSP/BIOS配置工具中创建两个PIP对象连接接收中断与处理函数线程的pipRx管道,以及连接发送中断与处理函数线程的pipTx管道。 下面给出了pipe_audio.c完整的程序清单。当在评估板上运行该例程时,输入的语音信号会立即送到耳机中 * Copyright 2003 by * All rights reserved. Property of * Restricted rights to use, duplicate or disclose this code are * granted through contract. * */ /* "@(#) DDK /* * ======== pip_audio.c ======== * * This example demonstrates the use of IOM drivers with PIPs using * the PIO adapter with a user defined device mini-driver called * "udevCodec". The application performs a loopback. That is, audio data is * read from one PIP connected to an input IOM channel, and the data is * written back out on a PIP connected to an output IOM channel. * * The following objects need to be created in the DSP/BIOS * configuration for this application: * * * A UDEV object, which links in a user device driver. In this case * the UDEV is a codec based IOM device driver. * * * 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 <iom.h> #include <pio.h> #ifdef _6x_ extern far LOG_Obj trace; extern far PIP_Obj pipRx; extern far PIP_Obj pipTx; extern far SWI_Obj swiEcho; #else extern LOG_Obj trace; extern PIP_Obj pipRx; extern PIP_Obj pipTx; extern SWI_Obj swiEcho; #endif /* * pioRx and pioTx objects will be initialized by PIO_new(). */ PIO_Obj pioRx, pioTx; /* * ======== main ======== * * Application startup funtion called by DSP/BIOS. Initialize the * PIO adapter then return back into DSP/BIOS. */ main() { /* * Initialize PIO module */ PIO_init(); /* Bind the PIPs to the channels using the PIO class drivers */ PIO_new(&pioRx, &pipRx, "/udevCodec", IOM_INPUT, NULL); PIO_new(&pioTx, &pipTx, "/udevCodec", IOM_OUTPUT, 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. */ PIO_txStart(&pioTx, PIP_getWriterNumFrames(&pipTx), 0); /* Prime the receive side with empty buffers to be filled. */ PIO_rxStart(&pioRx, PIP_getWriterNumFrames(&pipRx)); LOG_printf(&trace, "pip_audio started"); } /* * ======== echo ======== * * This function is called by the swiEcho DSP/BIOS SWI thread created * statically with the DSP/BIOS configuration tool. The PIO 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 a signal processing algorithm. */ 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. */ for (i = 0; i < size; i++) { *dst++ = *src++; } /* 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); } 程序源代码如下: 1.pip_audiocfg.h代码 /* Do *not* directly modify this file. It was */ /* generated by the Configuration Tool; any */ /* changes risk being overwritten. */ /* INPUT pip_audio.cdb */ #define CHIP_DM642 1 /* Include Header Files */ #include <std.h> #include <hst.h> #include <swi.h> #include <log.h> #include <pip.h> #include <sts.h> #ifdef __cplusplus extern "C" { #endif extern far HST_Obj RTA_fromHost; extern far HST_Obj RTA_toHost; extern far SWI_Obj swiEcho; extern far LOG_Obj LOG_system; extern far LOG_Obj trace; extern far PIP_Obj pipRx; extern far PIP_Obj pipTx; extern far STS_Obj IDL_busyObj; extern far void CSL_cfgInit(); #ifdef __cplusplus } #endif /* extern "C" */ 2.pip_audiocfg_c.c代码 /* Do *not* directly modify this file. It was */ /* generated by the Configuration Tool; any */ /* changes risk being overwritten. */ /* INPUT pip_audio.cdb */ /* Include Header File */ #include "pip_audiocfg.h" #ifdef __cplusplus #pragma CODE_SECTION(".text:CSL_cfgInit") #else #pragma CODE_SECTION(CSL_cfgInit,".text:CSL_cfgInit") #endif #ifdef __cplusplus #pragma FUNC_EXT_CALLED() #else #pragma FUNC_EXT_CALLED(CSL_cfgInit) #endif /* Config Structures */ /* Handles */ /* * ======== CSL_cfgInit() ======== */ void CSL_cfgInit() { } 3.evmdm642_codec_devParams.c代码 /* * Copyright 2003 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. * */ /* "@(#) DDK /* * ======== evmdm642_devParams.c ======== * EVMDM642_EDMA_AIC23 default driver parameters */ #include <std.h> #include <evmdm642_edma_aic23.h> /* * ======== EVMDM642_DEVPARAMS ======== * This static initialization defines the default parameters used for * EVMDM642_EDMA_AIC23 IOM driver */ EVMDM642_EDMA_AIC23_DevParams EVMDM642_CODEC_DEVPARAMS = EVMDM642_EDMA_AIC23_DEFAULT_DEVPARAMS; 4.pip_audio.c代码 /* * Copyright 2003 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. * */ /* "@(#) DDK 1.10.00.23 07-02-03 (ddk-b12)" */ /* * ======== pip_audio.c ======== * * This example demonstrates the use of IOM drivers with PIPs using * the PIO adapter with a user defined device mini-driver called * "udevCodec". The application performs a loopback. That is, audio data is * read from one PIP connected to an input IOM channel, and the data is * written back out on a PIP connected to an output IOM channel. * * The following objects need to be created in the DSP/BIOS * configuration for this application: * * * A UDEV object, which links in a user device driver. In this case * the UDEV is a codec based IOM device driver. * * * 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 <iom.h> #include <pio.h> #ifdef _6x_ extern far LOG_Obj trace; extern far PIP_Obj pipRx; extern far PIP_Obj pipTx; extern far SWI_Obj swiEcho; #else extern LOG_Obj trace; extern PIP_Obj pipRx; extern PIP_Obj pipTx; extern SWI_Obj swiEcho; #endif /* * pioRx and pioTx objects will be initialized by PIO_new(). */ PIO_Obj pioRx, pioTx; /* * ======== main ======== * * Application startup funtion called by DSP/BIOS. Initialize the * PIO adapter then return back into DSP/BIOS. */ main() { /* * Initialize PIO module */ PIO_init(); /* Bind the PIPs to the channels using the PIO class drivers */ PIO_new(&pioRx, &pipRx, "/udevCodec", IOM_INPUT, NULL); PIO_new(&pioTx, &pipTx, "/udevCodec", IOM_OUTPUT, 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. */ PIO_txStart(&pioTx, PIP_getWriterNumFrames(&pipTx), 0); /* Prime the receive side with empty buffers to be filled. */ PIO_rxStart(&pioRx, PIP_getWriterNumFrames(&pipRx)); LOG_printf(&trace, "pip_audio started"); } /* * ======== echo ======== * * This function is called by the swiEcho DSP/BIOS SWI thread created * statically with the DSP/BIOS configuration tool. The PIO 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 a signal processing algorithm. */ 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. */ for (i = 0; i < size; i++) { *dst++ = *src++; } /* 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); } |
|||||
| 欢迎点击进入:TI德州中文网 (国内唯一针对TI应用的中文技术网站) 文章录入:admin 责任编辑:admin | |||||
| 【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 | |||||
| 最新热点 | 最新推荐 | 相关文章 | ||
| 没有相关文章 |
| 网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!) |
| | 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 | 网站公告 | 管理登录 | | |||
|
|