DSP/BIOS應用

在這個DSP/BIOS應用的例子中,我們使用DSP/BIOS配置工具創建了一個名爲dataIO_CLK的時鐘對象、名爲PRD0的週期性函數對象、processing_SWI軟件中斷、TSK0任務線程對象以及名爲control_channel的RTDX輸入通道。

    現在我們做如下假設:系統每隔1ms進行一次數據讀入,即調用dataIO()函數一次;而模擬出來函數processing()需要每調用10次dataIO()函數後才運行。這裏我們首先利用定時器模塊,使得程序運行時,在定時器中斷的作用下實現1ms調用一次dataIO()函數。然後在將處理函數processing()放到一個軟件中斷processing_SWI中,並利用DSP/BIOS提供的郵箱(mailbox)功能對dataIO()函數調用次數進行計數,以確定在什麼時候將processing()放到執行隊列。


    我們通過在dataIO()函數中調用內核中的SWI模塊的API函數SWI_dec(),該函數將對軟件中斷模塊的郵箱(mailbox)減1,當mailbox參數減到0時,便將該軟件中斷對象中指定的函數processing()放入執行隊列等待執行。我們只需要在設置軟件中斷模塊時將郵箱預置爲10,DSP/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。


程序的源代碼如下:


1.volume.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 */2.volume.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);
}3.volumecfg.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;
exte
rn 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" */4.volumecfg_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()
{
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章