网站公告列表

  没有公告

加入收藏
设为首页
联系站长
您现在的位置: 61IC中国电子在线 >> DSP >> 代码示例 >> TI DSP代码示例 >> C6000 >> 文章正文
  在目标应用程序中使用RTDX发送数据         ★★★ 【字体:
在目标应用程序中使用RTDX发送数据
作者:A007    文章来源:本站    点击数:    更新时间:2007-3-15    
1、在目标应用程序中使用RTDX发送数据
RTDX提供了实时、连续了解目标系统程序运行情况的手段,它允许用户在不干扰目标系统程序运行的情况下,在主机和目标系统之间传输数据。可以这么认为,RTDX提供了一个目标应用程序与主机客户程序之间的双向数据管道。
目标系统与主机之间的RTDX实际上仍然是通过JTAG接口完成的。目标系统中的RTDX目标库和位于CCS中的RTDX主机库之间实时交换数据。RTDX目标库向目标应用程序提供用户接口,目标应用程序可以通过此接口发送和接受程序。RTDX主机库提供COM接口,主机客户成熟通过COM接口发送和接收数据。RTDX主机库孩可以将数据保存在日志文件中,供非实时数据分析使用。
目标应用程序通过调用RTDX目标库中的函数发送数据。这些数据实际撒航只是放在RTDX目标库的缓冲去中,然后函数立即返回。RTDX目标库在处理器空闲时将本地缓冲区中的数据发送出去,这样不干扰应用程序的正常运行。根据设定的主机记录模式,主机将数据放到缓冲区或者记录到日志文件中。RTDX主机库对外提供COM接口,可以认为是COM服务器,主机客户程序通过COM接口获取数据,并根据需要分析和显示数据。
在CCS中打开工程文件ti\tutorial\sim64xx\sect_1\less_1\s1l1.pjt,然后在一个源程序对话框中打开S1L1.c源文件。为了使用RTDX,需要对此源文件进行一定的修改。
可以看到,目标应用程序发送数据的步骤主要包括:声明发送通道、初始化RTDX目标库、使能发送通道、发送数据、关闭通道。修改完成后,编译连接程序,得到s1l1.out文件,加载程序到目标系统。选择“Tool”|“RTDX”|“Configuration Control”命令,打开“RtdxConfig”对话框。然后按快捷键F5运行程序,可以在ccs标准输出对话框见到程序最后调用puts()函数的输出信息“Program Complete!”。此时数据应该发送到Rtdx主机库中。现在需要一个COM客户程序通过COM接口读出这个数据,CCS提供了一个工具,位于ti\tutorial\sim64xx\sect_1\less_1目录下。打开一个命令提示符对话框,改变目录到ti\tutorial\sim64xx\sect_1\less_1,运行程序s1l1.exe,程序输出。

2、在目标应用程序中使用RTDX接收数据
在CCS中打开工程文件ti\tutorial\sim64xx\sect_1\less_3\s1l3.pjt,同时在一个源程序对话框打开s1l3.c文件。此源文件需要一定的修改,才能完成接受一个整数的工作。
可以看到,接收数据的过程与发送数据的过程基本类似,只不过使用输入通道,用目标库提供的RTDX_read()函数读取数据。编译连接运行程序,然后打开一个命令行对话框,并在其中运行程序ti\tutorial\sim64xx\sect_1\less_3\s1l3.exe。在CCS的标准输出对话框中可以看到目标应用程序的输出“Value 5 was received from the host”,表示已经从主机客户接收到数据。
3、建立DSP/BIOS的配置文件
当DSP/BIOS的基本设置完成后,可以将修改后的配置以volume.cdb名字保存。配置文件编辑工具还将自动生成volumecfg.h,volumecfg.cmd,volumecfg等DSP/BIOS应用程序所需要的系统文件。
4、用DSP/BIOS工具创建应用程序
使用DSP/BIOS工具开发DSP应用程序与不使用DSP/BIOS工具基本一致。首先在“Project”菜单中选择“New”或“Open”,新建或打开一个工作文件。然后将需要的.h、.asm、.c、.obj、.lib(这时不需要添加C语言标准库如rts.lib)添加到该工程文件中。还需要将DSP/BIOS的配置文件.cdb添加到工程到工程文件中。注意:LNK使用的.cmd文件有DSP/BIOS配置文件自动产生,所以应该添加DSP/BIOS配置工具自动生成的.cmd文件。

s1l1.c代码
/*********************************************************************
* S1L1.c - (Section 1, Lesson 1) SENDING AN INTEGER TO THE HOST
* This is the RTDX Target Code for Section 1, Lesson 1
*
* This example sends integer value 5 to the host
********************************************************************/

/*********************************************************************
* Insert code from Step #2 here - to include the rtdx header file,
* which defines the RTDX target API
********************************************************************/
#include<rtdx.h> /*必须包含的头文件,其中包含目标库函数的原型*/

#include "target.h" /* defines TARGET_INITIALIZE() */
#include <stdio.h> /* C_I/O */

/* This is the value we are going to send to the host */
#define VALUE_TO_SEND 6

/*********************************************************************
* Insert code from Step #3 here - to declare a global output channel
*RTDX_CreateOutputChannel()用于声明通道的宏
********************************************************************/
RTDX_CreateOutputChannel(ochan);


void main()
{
int data = VALUE_TO_SEND;
int status;

TARGET_INITIALIZE();

/*************************************************************
* Insert code from Step #5 here - to enable the output
* channel
************************************************************/

RTDX_enableOutput(&ochan);

/*************************************************************
* Insert code from Step #6 here - to send the data to
* the host
************************************************************/

status=RTDX_write(&ochan,&data,sizeof(data));
/*返回值为0表示操作失败*/

if ( status == 0 ) {
puts( "ERROR: RTDX_write failed!\n" );
exit( -1 );
}

while ( RTDX_writing != NULL ) {
#if RTDX_POLLING_IMPLEMENTATION
RTDX_Poll();
#endif
}

/*************************************************************
* Insert code from Step #7 here - to disable the output
* channel
************************************************************/

RTDX_disableOutput(&ochan);
puts( "Program Complete!\n" );
}

s1l1.cpp代码
//####################################################################
// S1L1.cpp - (Section 1, Lesson 1) SENDING AN INTEGER TO THE HOST
// This is the RTDX Host Client for Section 1, Lesson1
//####################################################################

#import "..\..\..\..\cc\bin\rtdxint.dll"
#include <iostream.h>

using namespace RTDXINTLib;

int main()
{
IRtdxExpPtr rtdx; // Holds pointer to IRtdxExp interface
long data; // Holds data read from target application
long status; // Holds status of RTDX COM API calls
HRESULT hr; // Holds status of generic COM API calls

// initialize COM
::CoInitialize( NULL );

// Instantiate the RTDX COM object
// IRtdxExp interface
hr = rtdx.CreateInstance( __uuidof(RTDXINTLib::RtdxExp) );

cout.setf( ios::showbase );

if ( FAILED(hr) ) {
cerr << hex << hr << " - Error: Instantiation failed! \n";
return -1;
}

// open a channel (ochan) for reading
status = rtdx->Open( "ochan", "R" );

if ( status != Success ) {
cerr << hex << status \
<< " - Error: Opening of a channel failed! \n";
exit(-1);
}

// loop until we have read all of our messages
do {
// read a message
status = rtdx->ReadI4( &data );

// test status returned from ReadI4
switch ( status ) {
case Success:
// display data
cout << data << "\n";
break;
case Failure:
cerr << hex << status \
<< " - Error: ReadI4 returned failure! \n";
return -1;
case ENoDataAvailable:
cout << "\n\nNo Data is currently available!\n";
cout << "\n\nWould you like to continue reading [y or n]?\n";
char option;
cin >> option;
if ( (option == 'y') || (option == 'Y') )
break;
else
return -1;
case EEndOfLogFile:
cout << "\n\nData Processing Complete!\n";
break;
default:
cerr << hex << status \
<< " - Error: Unknown return code! \n";
return -1;
}
} while ( status != EEndOfLogFile );

// close the channel
status = rtdx->Close();

// release the IRtdxExp interface
rtdx.Release();

// uninitialize COM
::CoUninitialize();

return 0;
}

Config1cfg.h代码
/* Do *not* directly modify this file. It was */
/* generated by the Configuration Tool; any */
/* changes risk being overwritten. */

/* INPUT Config1.cdb */

#define CHIP_DM642 1

/* Include Header Files */
#include <std.h>
#include <hst.h>
#include <swi.h>
#include <tsk.h>
#include <log.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 KNL_swi;
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" */

Config1cfg_c.c代码
/* Do *not* directly modify this file. It was */
/* generated by the Configuration Tool; any */
/* changes risk being overwritten. */

/* INPUT Config1.cdb */

/* Include Header File */
#include "Config1cfg.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()
{
}

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 <hst.h>
#include <swi.h>
#include <tsk.h>
#include <log.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 KNL_swi;
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" */

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)
#endif

/* Config Structures */
/* Handles */

/*
* ======== CSL_cfgInit() ========
*/
void CSL_cfgInit()
{
}

s1l3.c代码
/*********************************************************************
* S1L3.c - (Section 1, Lesson 3) RECEIVING AN INTEGER FROM THE HOST
* This is the RTDX Target Code for Section 1, Lesson 3
*
* This example receives integer value 5 from the host
********************************************************************/

#include <rtdx.h> /* defines RTDX target API calls */
#include "target.h" /* defines TARGET_INITIALIZE() */
#include <stdio.h> /* C_I/O */

/*********************************************************************
* Insert code from Step #2 here - to create a global input channel
********************************************************************/
//创建名为ichan的输入通道
RTDX_CreateInputChannel(ichan);

void main()
{
int data;
int status;

TARGET_INITIALIZE();

/*************************************************************
* Insert code from Step #3 here - to enable the input
* channel
************************************************************/

RTDX_enableInput(&ichan);
/*************************************************************
* Insert code from Step #4 here - to request an integer
************************************************************/
status=RTDX_read(&ichan,&data,sizeof(data));

if ( status != sizeof(data) ) {
printf( "ERROR: RTDX_read failed!\n" );
exit( -1 );
} else
printf( "Value %d was received from the host\n", data );

/*************************************************************
* Insert code from Step #5 here - to disable the input
* channel
************************************************************/
RTDX_disableInput(&ichan);

printf( "Program Complete!\n" );
}

s1l3.cpp代码
//####################################################################
// S1L3.cpp - (Section 1, Lesson 3) RECEIVING AN INTEGER FROM THE HOST
// This is the RTDX Host Client for Section 1, Lesson 3
//####################################################################

#import "..\..\..\..\cc\bin\rtdxint.dll"
#include <iostream.h>


#define VALUE_TO_SEND 5

using namespace RTDXINTLib;

int main()
{
IRtdxExpPtr rtdx; // Holds pointer to IRtdxExp interface
long status; // Holds status of RTDX COM API calls
HRESULT hr; // Holds status of generic COM API calls
long data=VALUE_TO_SEND; // Holds data to be sent to target
long bufferstate; // Holds the state of the host's write buffer

// initialize COM
::CoInitialize( NULL );

// Instantiate the RTDX COM object
hr = rtdx.CreateInstance( __uuidof(RTDXINTLib::RtdxExp) );

cout.setf( ios::showbase );

if ( FAILED(hr) ) {
cerr << hex << hr << " - Error: Instantiation failed! \n";
return -1;
}

// open a channel (ichan) for writing
status = rtdx->Open( "ichan", "W" );

if ( status != Success ) {
cerr << hex << status \
<< " - Error: Opening of channel \"ichan\" failed! \n";
return -1;
}

// loop until the status of the write buffer is greater or equal to 0.
// This means that the target is satisfied and the Host client does not
// need to write any more data.
do {
rtdx->WriteI4( data, &bufferstate );

if ( status != Success ) {
cerr << hex << status << " - Error: WriteI4 failed!\n";
return -1;
}

cout << "Value " << data << " was sent to the target!\n";

// give the target enough time to catch up
Sleep( 2000 );

// write an integer
status = rtdx->StatusOfWrite( &bufferstate );

if ( status != Success ) {
cerr << hex << status \
<< " - Error: Getting status of host's write buffer! \n";
return -1;
}
} while ( bufferstate < 0 );


// close the channel
status = rtdx->Close();

// release the IRtdxExp interface
rtdx.Release();

// uninitialize COM
::CoUninitialize();

return 0;
}

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

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