⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 evm67x.txt

📁 TI公司的EVM67x开发板板与PC机通信的程序.看一下吧
💻 TXT
📖 第 1 页 / 共 2 页
字号:
/**********************************************************************************
// ECE581 DSP Projects Lab 5A -- Example of Two-Way, handshaked communication
// between the PC and the C67 EVM DSP Card using the Host Peripheral Interface (HPI)
// This demo sends two 32-bit unsigned (ULONG) integers to the DSP.
// The DSP multiplies them together and sends result back to PC, and PC prints result.
// The demo is then repeated for two 32-bit floating point numbers.
//
// This is the PC-Side Program (Written as an MSVC 6.0 Win32 Console Application)
//**********************************************************************************
#include "stdafx.h"
#include <windows.h>
#include <evm6xdll.h>

#define DSP_SND_FLG_ADR 0x80000000
#define PC_SND_FLG_ADR 0x80000004
#define DATA1_ADR 0x80000008
#define DATA2_ADR 0x8000000C
#define DATA3_ADR 0x80000010
#define DATA4_ADR 0x80000014

HANDLE h_board;
LPVOID h_hpi;
ULONG  ul_temp;


void DSP_SNDFLG_SET(ULONG ul_val)
{  
  if(!evm6x_hpi_write_single(h_hpi,ul_val,4, DSP_SND_FLG_ADR))
    printf("evm6x_hpi_write_single failed. \n");
}

void PC_SNDFLG_SET(ULONG ul_val)
{
  if( !evm6x_hpi_write_single(h_hpi,ul_val,4,PC_SND_FLG_ADR))
       printf("evm6x_hpi_write_single failed. \n");
}
ULONG DSP_SNDFLG_RD(void)
{   ULONG ul_val;
	if( !evm6x_hpi_read_single( h_hpi, &ul_val, 4, DSP_SND_FLG_ADR))
		  {printf("evm6x_hpi_read_single failed. \n");}
	return(ul_val);

}
ULONG PC_SNDFLG_RD(void)
{   ULONG ul_val;
	if( !evm6x_hpi_read_single( h_hpi, &ul_val, 4, PC_SND_FLG_ADR))
		  {printf("evm6x_hpi_read_single failed. \n");}
	return(ul_val);
}

void DATA1_SND(ULONG data_val)
{ 
   if( !evm6x_hpi_write_single(h_hpi,data_val,4,DATA1_ADR))
   {printf("evm6x_hpi_write_single failed. \n");}
}
ULONG DATA1_RD(void)
{   ULONG ul_val;
	if( !evm6x_hpi_read_single( h_hpi, &ul_val, 4, DATA1_ADR))
	{  printf("evm6x_hpi_read_single failed. \n");}
	return(ul_val);
}
void DATA2_SND(ULONG data_val)
{ 
   if( !evm6x_hpi_write_single(h_hpi,data_val,4,DATA2_ADR))
   {printf("evm6x_hpi_write_single failed. \n");}
}
ULONG DATA2_RD(void)
{   ULONG ul_val;
	if( !evm6x_hpi_read_single( h_hpi, &ul_val, 4, DATA2_ADR))
	{  printf("evm6x_hpi_read_single failed. \n");}
	return(ul_val);
}
// The following function converts a 32-bit floating point number
// into an unsigned long integer (ULONG) type WITHOUT changing the bit pattern.
// This function allows floating point values to be sent to DSP as ULONG
// integers, as required by the evm6x_hpi_write_single( ) API function.
ULONG FLT_TO_ULONG(float x)
{
	ULONG *point_to_ulong;
	point_to_ulong = (ULONG *) &x;
	return(*point_to_ulong);
}
// The following function converts a 32-bit unsigned integer (ULONG) number
// into a floating point type, WITHOUT changing the bit pattern.
// This function allows floating point values to be read from the DSP as ULONG
// integers, as required by the evm6x_hpi_read_single( ) API function.
float ULONG_TO_FLT(ULONG x)
{
	float *point_to_float;
	point_to_float = (float *) &x;
	return(*point_to_float);
}

int main(int argc, char* argv[])
{	printf("ECE581 DSP-PC Communication Demo via HPI Port\n\n");
	printf("Here is a demo of floating point/ULONG type conversion routines:\n");
	printf("The hex encoding of 2.5 is 0x%x\n",FLT_TO_ULONG(2.5));
	printf("The floating pt value of 0x40200000 is %f\n\n",ULONG_TO_FLT(0x40200000));
	h_board = evm6x_open(0,FALSE);
	if( h_board == INVALID_HANDLE_VALUE)
		{
			printf("Unable to open EVM6X board\n");	
		}
	h_hpi = evm6x_hpi_open(h_board);
	if(h_hpi == NULL)
		{
		  printf("evm6x hpi_open( ) failed.\n");
		  evm6x_close( h_board);
		}
	//Start by lowering both DSP_SND and PC_SND FLAGS 
	DSP_SNDFLG_SET(0);
	PC_SNDFLG_SET(0);
    // Place two unsigned long (ULONG) integers (5 and 7) into the DSP Card memory.
	DATA1_SND(7);
	DATA2_SND(5);
	// Tell DSP CARD that the two input numbers are available in DSP memory
	// by raising the PC_SNDFLG (changing it from 0 to 1)
	PC_SNDFLG_SET(1);
	// Wait until PC_SNDFLG has been lowered by DSP card,
	// indicating that the DSP program has read this data..
	while(PC_SNDFLG_RD()==1);
	// Wait until DSP calculates the result and places it at the 
	// proper place in DSP memory, by waiting for DSP_SNDFLG to
	// be raised (raised from 0 to 1) by the DSP program.
	while(DSP_SNDFLG_RD()==0);
	printf("The product of the 2 numbers sent to DSP card is = %d\n",DATA1_RD());
	// Remember to lower flag (from 1 to 0) once the DSP card raises it, to let DSP
	// card know that the DSP's result has been read by PC.
	DSP_SNDFLG_SET(0);
	// Now let we send two FLOATING POINT numbers to DSP and get product back.
	DATA1_SND(FLT_TO_ULONG(1.5));
	DATA2_SND(FLT_TO_ULONG(2.5));
	PC_SNDFLG_SET(1); //Raise PC_SNDFLG to let DSP know that data is ready to read.
	// Wait until PC_SNDFLG has been lowered by DSP card,
	// indicating that the DSP program has read this data..
	while(PC_SNDFLG_RD()==1);
	// Wait until DSP calculates the result and places it at the 
	// proper place in DSP memory, by waiting for DSP_SNDFLG to
	// be raised (raised from 0 to 1) by the DSP program.
	while(DSP_SNDFLG_RD()==0);
	printf("The product of the 2 FLOATING POINT numbers sent to DSP card is = %f\n",
		    ULONG_TO_FLT(DATA1_RD()));
	// Remember to lower flag (from 1 to 0) once the DSP card raises it, to let DSP
	// card know that the DSP's result has been read by PC.
	DSP_SNDFLG_SET(0);
	if (!evm6x_hpi_close( h_hpi ))
		  printf("evm_close( ) failed.\n");
	return 0;
}

 
Appendix C.  Example showing how to call the evm6x_coff_load( ) function from a PC-side MSVC++ V6.0 program in order to automatically load a COFF executable program onto the DSP board,  and then begin executing the DSP-side program.

Example In the following example, the evm6x_coff_load() function is used to load a COFF executable to a DSP. The COFF executable is the file example.out, and
the verbose flag is set, which causes COFF section information to be displayed
to stdout during the load operation.



#include <windows.h>
#include <evm6xdll.h>
. . .
. . .
. . .
HANDLE h_board;
h_board = evm6x_open( 0, FALSE );
if ( h_board == INVALID_HANDLE_VALUE )
{
printf(“unable to open board\n”);
exit(–1);
}
/*––––––––––––––––––––––––––––––––––*
reset DSP into HPI boot mode
configure emif registers
load COFF executable
unreset DSP
*––––––––––––––––––––––––––––––––––*/
evm6x_reset_dsp( h_board, HPI_BOOT );
evm6x_init_emif( h_board, NULL );
if ( !evm6x_coff_load( h_board, NULL, ”example.out”,
TRUE, FALSE, FALSE ) )
{
/* COFF load failed */
}
evm6x_unreset_dsp( h_board );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -