📄 hostdlg.cpp
字号:
// HostDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Host.h"
#include "HostDlg.h"
#include "C62x.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BOOL bKillThread;
HANDLE m_hEventKillThread;
UINT GetDspMessage(LPVOID pParam)
{
CThreadInfo *pInfo = (CThreadInfo *)pParam;
EVM6XDLL_MESSAGE hMessage;
int iRet;
while (TRUE)
{
if (bKillThread)
{
SetEvent(m_hEventKillThread);
break;
}
iRet = evm6x_retrieve_message(pInfo->hBd, &hMessage);
if (iRet == TRUE)
::SendMessage(pInfo->hWnd, DSP_MESSAGE, NULL, NULL);
}
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CHostDlg dialog
CHostDlg::CHostDlg(CWnd* pParent /*=NULL*/)
: CDialog(CHostDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CHostDlg)
m_EditBox = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CHostDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CHostDlg)
DDX_Text(pDX, IDC_EDIT1, m_EditBox);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CHostDlg, CDialog)
//{{AFX_MSG_MAP(CHostDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(ID_SENDDATA, OnSenddata)
ON_MESSAGE(DSP_MESSAGE, OnGetDspMessage)
ON_BN_CLICKED(ID_RECDATA, OnRecdata)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHostDlg message handlers
BOOL CHostDlg::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
// Init DSP
InitDSP(m_hBd, m_hHpi);
// Thread Operations
m_ThreadInfo.hBd = m_hBd;
m_ThreadInfo.hWnd = m_hWnd;
m_pWinThread = AfxBeginThread(GetDspMessage, &m_ThreadInfo);
bKillThread = FALSE;
m_hEventKillThread = CreateEvent(NULL, FALSE, FALSE, NULL); // auto reset, initially reset
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 CHostDlg::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 CHostDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CHostDlg::OnOK()
{
bKillThread = TRUE;
WaitForSingleObject(m_hEventKillThread, INFINITE);
CloseHandle(m_hEventKillThread);
CloseDSP(m_hBd, m_hHpi);
CDialog::OnOK();
}
void CHostDlg::OnSenddata()
{
ULONG ulLength = DATA_LEN * 4, i;
EVM6XDLL_MESSAGE hMessage = 0x0000FFFF;
char szData[10];
for (i = 0; i < DATA_LEN; i++)
{
m_ulData[i] = i;
}
// Using Hpi to transfer data to dsp
if (!evm6x_hpi_write(m_hHpi, (ULONG *)m_ulData, &ulLength, SDRAM_ADDR))
exit(0);
if (ulLength != (DATA_LEN * 4))
exit(0);
// Indicate data transfer complete
evm6x_send_message(m_hBd, &hMessage);
// Text out
m_EditBox = "Begin Transfer Data...";
for (i = 0; i < DATA_LEN; i++)
{
sprintf(szData, "%d ", m_ulData[i]);
m_EditBox += szData;
}
m_EditBox += " Waiting for DSP to process...";
UpdateData(FALSE);
}
void CHostDlg::OnGetDspMessage()
{
m_EditBox += " DSP process complete.";
UpdateData(FALSE);
}
void CHostDlg::OnRecdata()
{
ULONG ulLength = DATA_LEN * 4, i;
EVM6XDLL_MESSAGE hMessage = 0x0000FFFF;
char szData[10];
m_EditBox = "Begin Receive Data...";
// Using Hpi to Receive data from dsp
if (!evm6x_hpi_read(m_hHpi, (ULONG *)m_ulData, &ulLength, SDRAM_ADDR))
exit(0);
if (ulLength != (DATA_LEN * 4))
exit(0);
for (i = 0; i < DATA_LEN; i++)
{
sprintf(szData, "%d ", m_ulData[i]);
m_EditBox += szData;
}
UpdateData(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -