📄 hostdownloaddlg.cpp
字号:
// hostdownloadDlg.cpp : implementation file
//
#include "stdafx.h"
#include "hostdownload.h"
#include "hostdownloadDlg.h"
#include "atetypes_1.h"
#include "IekC64Sdk.h"
#include "stdio.h"
#include "conio.h"
#include "memory.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#ifdef _DEBUG
#define DSP_CODE_FILE "..\\..\\..\\SoftDsp\\Debug\\dspdemo.out"
#else
#define DSP_CODE_FILE "..\\..\\..\\SoftDsp\\Release\\dspdemo.out"
#endif
// thread define
UINT myTreadProc(LPVOID pParam);
Bool exit_this_demo=FALSE;
/////////////////////////////////////////////////////////////////////////////
// CHostdownloadDlg dialog
CHostdownloadDlg::CHostdownloadDlg(CWnd* pParent /*=NULL*/)
: CDialog(CHostdownloadDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CHostdownloadDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CHostdownloadDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CHostdownloadDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CHostdownloadDlg, CDialog)
//{{AFX_MSG_MAP(CHostdownloadDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_Exit, OnBUTTONExit)
ON_BN_CLICKED(IDC_BUTTON_Start, OnBUTTONStart)
ON_BN_CLICKED(IDC_BUTTON_Download, OnBUTTONDownload)
ON_BN_CLICKED(IDC_BUTTON_Init, OnBUTTONInit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHostdownloadDlg message handlers
BOOL CHostdownloadDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CHostdownloadDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CHostdownloadDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
// first step
void CHostdownloadDlg::OnBUTTONInit()
{
// TODO: Add your control notification handler code here
IEKC64_STATUS status = IEKC64_OK;
Uint32 uBoardId = 0;
Uint32 DspDataAddr = 0;
/***********************
--- board initialize ---
***********************/
hEventMsg = NULL ;
// This handle points to the IEK board object
IekHandle = 0 ;
SetDlgItemText(IDC_MessageDisplay, "Initializing board driver ...");
Sleep(1000);
// disable all buttons
GetDlgItem(IDC_BUTTON_Start)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_Download)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_Exit)->EnableWindow(FALSE);
status = IEKC64_initialize( uBoardId, &IekHandle );
if( !status )
{
SetDlgItemText(IDC_MessageDisplay, "Board initialized!");
Sleep(1000);
status = IEKC64_resetDsp( IekHandle );
if( IEKC64_SUCCESS( status ) )
{
/*****************************************
--- create event for message reception ---
*****************************************/
SetDlgItemText(IDC_MessageDisplay, "Creating message event ...");
hEventMsg = CreateEvent( NULL, TRUE, FALSE, NULL );
if( !(hEventMsg == NULL) )
{
/*****************************************
--- enable message event for reception ---
*****************************************/
SetDlgItemText(IDC_MessageDisplay, "Connecting Message Event ...");
Sleep(1000);
status = IEKC64_enableMsgEvent( IekHandle, hEventMsg );
if( !status )
{
SetDlgItemText(IDC_MessageDisplay, "DSP Board Ready! You can download programs now!");
GetDlgItem(IDC_BUTTON_Download)->EnableWindow(TRUE);
GetDlgItem(IDC_BUTTON_Init)->EnableWindow(FALSE);
}
else
SetDlgItemText(IDC_MessageDisplay, "Error : connecting event to message failed !");
}
else
SetDlgItemText(IDC_MessageDisplay, "Error : can't create event!");
}
else
SetDlgItemText(IDC_MessageDisplay, "Error : Resetting DSP Error !");
}
else
SetDlgItemText(IDC_MessageDisplay, "Error : board initialization failed !");
}
// second step
void CHostdownloadDlg::OnBUTTONDownload()
{
IEKC64_STATUS status = IEKC64_OK;
char * FileNameString="dspdemo.out";
char * FilterString="*.out||";
// TODO: Add your control notification handler code here
/***************************
--- download DSP program ---
***************************/
CFileDialog myOpenFileDialog(TRUE,NULL,(LPSTR)FileNameString,NULL,(LPSTR)FilterString);
if(myOpenFileDialog.DoModal()!=IDOK)
{
SetDlgItemText(IDC_MessageDisplay,"Please select the DSP OUT File!");
return;
}
SetDlgItemText(IDC_MessageDisplay,"Downloading DSP code now ...");
GetDlgItem(IDC_BUTTON_Init)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_Download)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_Start)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_Exit)->EnableWindow(FALSE);
Sleep(100);
lstrcpy(FileNameString, (LPCTSTR)myOpenFileDialog.GetPathName());
status = IEKC64_loadProgram( IekHandle, (BYTE*)FileNameString);
// status = IEKC64_loadProgram( IekHandle, (BYTE*)DSP_CODE_FILE );
if( !status )
{
SetDlgItemText(IDC_MessageDisplay,"DSP software downloaded!");
/**********************************************
--- wait for message from DSP "end of init" ---
**********************************************/
// We have to wait a little before trying to get the 1st message
// because if we try to read messages before the DSP has done
// it's PCI_init() call, we will get error IEKC64_ERR_MSG (0xA1080000)
Sleep( 1000 );
SetDlgItemText(IDC_MessageDisplay,"Waiting to receive Initialization message ...");
Sleep( 1000 );
status = waitMessage();
if ( !IEKC64_SUCCESS(status) )
{
SetDlgItemText(IDC_MessageDisplay,"Error when waiting for DSP initialization message!");
return;
}
// if the received message is 0x11111111
if ( MessageBuffer[0] == 0x11111111 )
SetDlgItemText(IDC_MessageDisplay,"Received DSP initialization message !");
else
{
SetDlgItemText(IDC_MessageDisplay,"Error : Received unknown message !");
return;
}
}
else
{
SetDlgItemText(IDC_MessageDisplay,"Error : doanloding DSP code failed !");
return;
}
SetDlgItemText(IDC_MessageDisplay,"DSP is waiting for START command. Please press Start button!");
Sleep(100);
GetDlgItem(IDC_BUTTON_Start)->EnableWindow(TRUE);
}
// third step
void CHostdownloadDlg::OnBUTTONStart()
{
IEKC64_STATUS status = IEKC64_OK;
// TODO: Add your control notification handler code here
GetDlgItem(IDC_BUTTON_Start)->EnableWindow(FALSE);
/*************************
--- send START message ---
*************************/
SetDlgItemText(IDC_MessageDisplay,"Sending Start message to DSP ...");
printf( "Sending Start message to DSP\n" );
Sleep(1000);
MessageBuffer[0] = 0x22222222;
status = IEKC64_sendDspMsg( IekHandle, 0, sizeof(Uint32), MessageBuffer );
if( !IEKC64_SUCCESS(status) )
{
SetDlgItemText(IDC_MessageDisplay,"Sending Start message to DSP Failed!");
printf("Error : Sending failed : 0x%08X : %s\n", status, IEKC64_getErrorString(status) );
Sleep(1000);
exit( 1 );
}
// We have to wait a little before trying to get the message
SetDlgItemText(IDC_MessageDisplay,"Waiting for DSP to respond to START message ...");
Sleep( 1000 );
status = waitMessage();
if ( !IEKC64_SUCCESS(status) )
{
SetDlgItemText(IDC_MessageDisplay,"Error when waiting for DSP START message!");
return;
}
// if the received message is 0x33333333
if ( MessageBuffer[0] == 0x33333333 )
SetDlgItemText(IDC_MessageDisplay,"Received DSP START message !");
else
{
SetDlgItemText(IDC_MessageDisplay,"Error : Received unknown message !");
return;
}
Sleep( 1000 );
SetDlgItemText(IDC_MessageDisplay,"DSP Program Running now ...");
GetDlgItem(IDC_BUTTON_Exit)->EnableWindow(TRUE);
// begin the message thread
exit_this_demo=FALSE;
AfxBeginThread(myTreadProc, this);
}
// last step
void CHostdownloadDlg::OnBUTTONExit()
{
IEKC64_STATUS status = IEKC64_OK;
// TODO: Add your control notification handler code here
GetDlgItem(IDC_BUTTON_Exit)->EnableWindow(FALSE);
// end the message thread
exit_this_demo=TRUE;
MessageBuffer[0] = 0x99999999;
status = IEKC64_sendDspMsg( IekHandle, 0, sizeof(Uint32), MessageBuffer );
if( !IEKC64_SUCCESS(status) )
{
SetDlgItemText(IDC_MessageDisplay,"Sending Exit message to DSP Failed!");
printf("Error : Sending failed : 0x%08X : %s\n", status, IEKC64_getErrorString(status) );
Sleep(1000);
exit( 1 );
}
SetDlgItemText(IDC_MessageDisplay,"Stop DSP Program and Exit now!");
Sleep(2000);
/*************************
--- Uninitialize board ---
*************************/
IEKC64_unInitialize(IekHandle);
printf("Board uninitialized ...\n");
}
void CHostdownloadDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
IEKC64_STATUS CHostdownloadDlg::waitMessage( )
{
IEKC64_STATUS status;
Uint32 uMsgFlag = 0;
Uint32 uBytesRead;
// Clear the event
ResetEvent( hEventMsg );
// check to see if a message is already there
status = IEKC64_getDspMsg( IekHandle, &uMsgFlag, &uBytesRead, sizeof(MessageBuffer), MessageBuffer );
if ( status == IEKC64_ERR_NO_MSG )
{
// No message, wait for the event to be triggered
printf( "Wait for message Event\n" );
DWORD uRes = WaitForSingleObject( hEventMsg, INFINITE );
ResetEvent( hEventMsg );
if ( uRes != WAIT_OBJECT_0 )
{
printf( "Error in WFSO(hEventMsg) !!!\n" );
exit( 1 );
}
printf( "Event pulsed\n" );
// get the message
status = IEKC64_getDspMsg( IekHandle, &uMsgFlag, &uBytesRead, sizeof(MessageBuffer), MessageBuffer );
}
else
{
printf( "Message was already there\n" );
}
if ( IEKC64_SUCCESS(status) )
{
printf( "Message received\n");
}
else
{
printf( "Error in getting message : 0x%08X : %s !!!!\n", status, IEKC64_getErrorString( status ) );
}
return status;
}
// thread to retrieve message when DSP video I/O is running
UINT myTreadProc(LPVOID pParam )
{
IEKC64_STATUS status = IEKC64_OK;
CString s;
CHostdownloadDlg* pDlg;
pDlg = (CHostdownloadDlg*)pParam;
while(1)
{
if (exit_this_demo)
AfxEndThread(0);
status = pDlg->waitMessage();
if ( !IEKC64_SUCCESS(status) )
{
pDlg->SetDlgItemText(IDC_MessageDisplay,"Error when waiting for DSP running message!");
AfxEndThread(1);
}
// if the received message is 0x44444444
if ( pDlg->MessageBuffer[0] == 0x44444444 )
{
s.Format("DSP Video I/O Frame index: %d...", pDlg->MessageBuffer[1]);
pDlg->SetDlgItemText(IDC_MessageDisplay,s);
}
else
{
pDlg->SetDlgItemText(IDC_MessageDisplay,"Error : Received unknown message !");
AfxEndThread(1);
}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -