|
在该例程中,我们从主机发送一个数据文件到DSP目标系统上,文件中包含的数据经DSP处理后再返回给PC主机。PC主机与DSP目标系统通过TDS510仿真器连接,PC主机运行的CCS提供主机通道控制工具,每次从数据文件中读取64个字,通过HST主机通道传递给DSP目标板。DSP收到数据后,将这64个字的数据反序后送回PC主机,并由CCS的主机通道控制工具保存。为了更真实地模拟实际情况,我们在DSP的程序中加入一个周期性函数,每0.1ms运行一次,每次启动一个软件中断SWI0,在该软件中断中调用processing()处理函数。处理函数从HST主机通道中读取64个数据,并将其反序后,再存回主机通道。
1) 将评估板,仿真器同PC机连接起来,接通电源; 2) 打开CCS,新建一个工程; 3) 新建一个cdb文件,在模板中选择DM642.cdb; 4) 在配置工具中,依次对SWI、HST的配置做出修改(如图1、2、3),保存退出; 5) 将上述生成的配置文件添加到该工程中来; 6) 新建一个文本,将完整的源程序输入并保存下来; 7) 将上述源程序添加到工程中来; 8) 将cmd文件添加进来 9) 编译文件; 10) 成功后下载out文件; 11)将输入通道HST1与原始数据文件read_hst.bin绑定起来; 12)将输出通道HST0与数据文件hst_output.dat绑定起来; 13)启动主机通道后,开始运行程序。
源程序如下: Config4cfg.h代码
/* Do *not* directly modify this file. It was */ /* generated by the Configuration Tool; any */ /* changes risk being overwritten. */
/* INPUT Config4.cdb */
#define CHIP_DM642 1
/* Include Header Files */ #include <std.h> #include <prd.h> #include <hst.h> #include <swi.h> #include <tsk.h> #include <log.h> #include <sts.h>
#ifdef __cplusplus extern "C" { #endif
extern far PRD_Obj PRD0; extern far HST_Obj RTA_fromHost; extern far HST_Obj RTA_toHost; extern far HST_Obj HST0; extern far HST_Obj HST1; extern far SWI_Obj PRD_swi; extern far SWI_Obj KNL_swi; extern far SWI_Obj SWI0; extern far TSK_Obj TSK_idle; extern far LOG_Obj LOG_system; extern far STS_Obj IDL_busyObj; extern far void CSL_cfgInit();
#ifdef __cplusplus } #endif /* extern "C" */
Config4cfg_c.c代码
/* Do *not* directly modify this file. It was */ /* generated by the Configuration Tool; any */ /* changes risk being overwritten. */
/* INPUT Config4.cdb */
/* Include Header File */ #include "Config4cfg.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() { }
#include "Config4cfg.h" int read_from_host(int *in);
int input_buf[64]; /* use to save A/D data */ int process_buf[64]; /* use to processing function saving data */ int wave_buf[64]; /* use to save D/A data */
main() {
}
void save_to_host(int *in) { PIP_Handle pipe; Uns size; int *addr; int I;
pipe = HST_getpipe(&HST0); /* 获得数据管道的句柄 */ // if(PIP_getWriterNumFrames(pipe) <= 0) // return; PIP_alloc(pipe); /* 从主机通道指定的数据管道中取得一个数据帧 */ size = PIP_getWriterSize(pipe); addr = PIP_getWriterAddr(pipe); for(I=0;I<size;I++) *addr++ = *in++; PIP_put(pipe); /* 释放这个数据帧 */ }
int read_from_host(int *in) { PIP_Handle pipe; Uns size; int *addr; int I;
pipe = HST_getpipe(&HST1); /* 获得数据管道的句柄 */ if(PIP_getReaderNumFrames(pipe) <= 0) return(-1); PIP_get(pipe); /* 从主机通道指定的数据管道中取得一个数据帧 */ size = PIP_getReaderSize(pipe); addr = PIP_getReaderAddr(pipe); for(I=0;I<size;I++) *in++ = *addr++; PIP_free(pipe); /* 释放这个数据帧 */ return(0); }
void processing(int *in,int *out) { int I;
if(read_from_host(in)<0) // 利用HST通道回放采样数据 ! return; in+=63; // 每帧数据反序输出 ! for(I=0;I<64;I++) *out++ = *in-- ; // processing input data !
out-=64; save_to_host(out); // 利用HST通道记录采样数据 !
}
void receive() { SWI_post(&SWI0); }
|