网站公告列表

  没有公告

加入收藏
设为首页
联系站长
您现在的位置: 61IC中国电子在线 >> DSP >> 代码示例 >> TI DSP代码示例 >> C6000 >> 文章正文
  DSP/BIOS应用         ★★★ 【字体:
DSP/BIOS应用
作者:C003    文章来源:本站    点击数:    更新时间:2007-4-5    

在这个DSP/BIOS应用的例子中,我们使用DSP/BIOS配置工具创建了一个名为dataIO_CLK的时钟对象、名为PRD0的周期性函数对象、processing_SWI软件中断、TSK0任务线程对象以及名为control_channelRTDX输入通道。

 

现在我们做如下假设:系统每隔1ms进行一次数据读入,即调用dataIO()函数一次;而模拟出来函数processing()需要每调用10dataIO()函数后才运行。这里我们首先利用定时器模块,使得程序运行时,在定时器中断的作用下实现1ms调用一次dataIO()函数。然后在将处理函数processing()放到一个软件中断processing_SWI中,并利用DSP/BIOS提供的邮箱(mailbox)功能对dataIO()函数调用次数进行计数,以确定在什么时候将processing()放到执行队列。

 

 

我们通过在dataIO()函数中调用内核中的SWI模块的API函数SWI_dec(),该函数将对软件中断模块的邮箱(mailbox)减1,当mailbox参数减到0时,便将该软件中断对象中指定的函数processing()放入执行队列等待执行。我们只需要在设置软件中断模块时将邮箱预置为10DSP/BIOS会每次自动重新装入并实现计数功能。

 

 

周期性对象PRD0被设置为每2ms调用一次,其指定的函数为mytest(),每次运行该函数时都从RTDX通道control_channel中读取一个数据,若读取函数返回值大于0,表示已成功从RTDX通道获得数据。这时,周期函数mytest()将从RTDX通道获得的数据送到变量processingLoad时,以改变 load()函数的运行时间。

 

 

TI公司提供一个使用VB编写的应用程序loadctrl.exe。该软件可以实时地将数据参数通过OLE发送到CCS,并通过RTDX技术传送到DSP目标板。

 

 

任务线程TSK0对象指定的任务函数为fun_loop(),该函数实际上一个无限循环。每次循环时都对全局变量temp进行累加,然后调用任务休眠函数TSK_sleep(),该函数将强制TSK0线程从运行状态转变为暂停状态。正是这个休眠函数的调用,后台的IDL线程才有可能得到运行。

 

 

DSP/BIOS内核提供了具有优先级的多线程处理。按优先级从低到高有四种主要线程;后台线程(IDL线程)、任务线程(TSK模块)、软件中断(SWI)和硬件中断(HWI)。

 

 

完成这个例子的工程名称为volume.pjt

 

 

程序的源代码如下:

 

 

1volume.h代码

/*

* Copyright 2001 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.

* U.S. Patent Nos. 5,283,900 5,392,448

*/

/* "@(#) DSP/BIOS 4.51.0 05-23-01 (barracuda-i10)" */

/*

* ======== volume.h ========

*

*/#ifndef __VOLUME_H

#define __VOLUME_H#ifndef TRUE

#define TRUE 1

#endif#define BUFSIZE 0x64#define FRAMESPERBUFFER 10#define MINGAIN 1

#define MAXGAIN 10#define MINCONTROL 0

#define MAXCONTROL 19#define BASELOAD 1struct PARMS {

int Beta;

int EchoPower;

int ErrorPower;

int Ratio;

struct PARMS *Link;

};#endif /* __VOLUME_H */2volume.c代码#include <std.h>#include <log.h>

#include <swi.h>

#include <clk.h>

#include <sts.h>

#include <trc.h>

#include <rtdx.h>#include "volumecfg.h"#include "volume.h"/*Global declarations*/

Int inp_buffer[BUFSIZE];

Int out_buffer[BUFSIZE]; /*processing data buffer*/Int gain=MINGAIN; /*volume control variable*/

Uns processingLoad=BASELOAD; /*processing routine load value*/

int temp;

/*Functions*/

extern Void load(Uns loadValue); /*written in ASM in Load.asm*/

Int processing(Int *input,Int *output);

Void dataIO(Void);void fun_loop() /*TSK0 function*/

{int i,j;

do

{

for(i=0;i<10000;i++)

for(j=0;j<100;j++)

temp++;

TSK_sleep(10);

}while(1); /*infinite loop*/

}void mytest() /*PRD0 function*/

{

static int control=1;

 

if(RTDX_readNB(&control_channel,&control,sizeof(control))>0)

{

processingLoad=BASELOAD<<control;

LOG_printf(&trace,"Load new value=%d\n",control);

}

}void main()

{

LOG_printf(&trace,"new volume example started\n");

RTDX_enableInput(&control_channel);

 

/*fall into DSP/BIOS idle loop*/

 

return;

}Int processing(Int *input,Int *output) /*processing_SWI function*/

{

Int size=BUFSIZE;

while(size--)

{*output++==*input++*gain;}

 

/*additional processing load*/

 

if(TRC_query(TRC_USER0)==0)

STS_set(&mytestSTS,CLK_gethtime());

 

load(processingLoad);

 

 

if(TRC_query(TRC_USER0)==0)

STS_delta(&mytestSTS,CLK_gethtime());

 

return(TRUE);

 

}void dataIO()

{

SWI_dec(&processing_SWI);

}3volumecfg.h代码

/* Do *not* directly modify this file. It was */

/* generated by the Configuration Tool; any */

/* changes risk being overwritten. *//* INPUT volume.cdb */#define CHIP_DM642 1/* Include Header Files */

#include <std.h>

#include <prd.h>

#include <rtdx.h>

#include <hst.h>

#include <swi.h>

#include <tsk.h>

#include <log.h>

#include <sts.h>#ifdef __cplusplus

extern "C" {

#endifextern far PRD_Obj PRD0;

extern far RTDX_inputChannel control_channel;

extern far HST_Obj RTA_fromHost;

extern far HST_Obj RTA_toHost;

extern far SWI_Obj PRD_swi;

extern far SWI_Obj KNL_swi;

extern far SWI_Obj processing_SWI;

extern far TSK_Obj TSK_idle;

extern far TSK_Obj TSK0;

extern far LOG_Obj LOG_system;

extern far LOG_Obj trace;

extern far STS_Obj IDL_busyObj;

extern far STS_Obj mytestSTS;

extern far void CSL_cfgInit();#ifdef __cplusplus

}

#endif /* extern "C" */4volumecfg_c.c代码

/* Do *not* directly modify this file. It was */

/* generated by the Configuration Tool; any */

/* changes risk being overwritten. *//* INPUT volume.cdb *//* Include Header File */

#include "volumecfg.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)

#endifRTDX_CreateInputChannel(control_channel);

/* Config Structures */

/* Handles *//*

* ======== CSL_cfgInit() ========

*/

void CSL_cfgInit()

{

}

               欢迎点击进入:TI德州中文网   (国内唯一针对TI应用的中文技术网站)    文章录入:admin    责任编辑:admin 
  • 上一篇文章:

  • 下一篇文章:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关文章
    没有相关文章
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    站长:61IC 湘ICP备05002478号