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

📄 dspload1_0dlg.cpp

📁 Anlog 公司的DSP,ADSP-BF531并口模拟spi引导程序,是采用BF531从引导模式。
💻 CPP
字号:
// DSPLOAD1_0Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "DSPLOAD1_0.h"
#include "DSPLOAD1_0Dlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDSPLOAD1_0Dlg dialog

CDSPLOAD1_0Dlg::CDSPLOAD1_0Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDSPLOAD1_0Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDSPLOAD1_0Dlg)
	m_file_path = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

	dlg_status = 0;
}

void CDSPLOAD1_0Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDSPLOAD1_0Dlg)
	DDX_Control(pDX, IDC_DOWNLOAD, m_download_button);
	DDX_Control(pDX, IDC_PROGRESS, m_progress);
	DDX_Text(pDX, IDC_FILE_PATH, m_file_path);
	DDV_MaxChars(pDX, m_file_path, 100);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDSPLOAD1_0Dlg, CDialog)
	//{{AFX_MSG_MAP(CDSPLOAD1_0Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_OPEN_FILE, OnOpenFile)
	ON_BN_CLICKED(IDC_RESET, OnReset)
	ON_BN_CLICKED(IDC_DOWNLOAD, OnDownload)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDSPLOAD1_0Dlg message handlers

BOOL CDSPLOAD1_0Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 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
}

void CDSPLOAD1_0Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// 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 CDSPLOAD1_0Dlg::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 CDSPLOAD1_0Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CDSPLOAD1_0Dlg::OnEditchangeDownloadStype() 
{
	// TODO: Add your control notification handler code here
	
}

void CDSPLOAD1_0Dlg::OnOpenFile() 
{
	// TODO: Add your control notification handler code here
	//if (dlg_status)		//In Download Status
		//return;

	CFileDialog filedlg(TRUE, NULL, NULL, OFN_HIDEREADONLY, "*.ldr|*.ldr||");
	filedlg.m_ofn.lpstrInitialDir = "E:\\VisualDSP Projects";
	if (filedlg.DoModal() == IDOK) {
		m_file_path = filedlg.GetPathName();
	}
	SetDlgItemText(IDC_FILE_PATH, m_file_path);
}

CWinThread *pThreadReset;
CWinThread *pThreadDownload;
UINT ThreadReset(LPVOID lparam);
UINT ThreadDownload(LPVOID lparam);

void CDSPLOAD1_0Dlg::OnReset() 
{
	// TODO: Add your control notification handler code here
	if (dlg_status) {		//In Download Status
		MessageBox("Stop first and then Reset!");
		return;
	}
	MessageBeep(MB_ICONEXCLAMATION);
	pThreadReset =::AfxBeginThread(ThreadReset, this);
}

void CDSPLOAD1_0Dlg::OnDownload() 
{
	// TODO: Add your control notification handler code here
	if (!dlg_status) {		//In Download Status
		dlg_status = 1;

		UpdateData(TRUE);
		if (!ldr_file.Open(m_file_path, CFile::modeRead | CFile::shareDenyNone)) {
			dlg_status = 0;
			MessageBox("Can not Open file!");
			return;
		}

		m_download_button.SetWindowText("&Stop");   
		filelen = ldr_file.GetLength();
		fptr = new unsigned char[filelen];
		ldr_file.SeekToBegin();
		UINT nBytesRead = ldr_file.Read(fptr, filelen);

		pThreadDownload =::AfxBeginThread(ThreadDownload, this);
	} else {
		dlg_status = 0;
	}
}

UINT ThreadReset(LPVOID lparam)
{
	SPIPseudo spiLoad;
	CDSPLOAD1_0Dlg *pDlg = (CDSPLOAD1_0Dlg *)lparam;
	pDlg->m_progress.SetRange32(0, 100);
	pDlg->m_progress.SetPos(50);
	spiLoad.SPI_Reset();
	pDlg->m_progress.SetPos(0);
	return 0;
}

UINT ThreadDownload(LPVOID lparam)
{
	SPIPseudo spiLoad;
	CDSPLOAD1_0Dlg *pDlg = (CDSPLOAD1_0Dlg *)lparam;

	//pDlg->filelen = 1024 * 256;//////////////////////////
	pDlg->m_progress.SetRange32(0, pDlg->filelen);
	DWORD progress_step = pDlg->filelen / 64;

	spiLoad.SPI_BMode(0);
	spiLoad.SPI_Reset();
	spiLoad.SPI_ChipCS(0);
	for (DWORD i = 0; i < pDlg->filelen; i++) {
		if (spiLoad.SPI_ByteWrite(pDlg->fptr[i]) == -1) {
			AfxMessageBox("Error!");
			break;
		}
		if (pDlg->dlg_status == 0) {//manual stop download
			break;
		}
		if ((i % progress_step) == 0)
			pDlg->m_progress.SetPos(i + progress_step);
	}
	pDlg->m_progress.SetPos(0);
	pDlg->dlg_status = 0;
	MessageBeep(MB_ICONASTERISK);
	pDlg->m_download_button.SetWindowText("&DownLoad"); 
	delete(pDlg->fptr);
	return 0;
}

⌨️ 快捷键说明

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