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

📄 sdloaderdlg.cpp

📁 TMS320F2808的完整驱动测试程序源码
💻 CPP
字号:
/*
 *  Copyright 2003 by Spectrum Digital Incorporated.
 *  All rights reserved. Property of Spectrum Digital Incorporated.
 */

// SDLoaderDlg.cpp : implementation file
//

#include "stdafx.h"
#include "SDLoader.h"
#include "SDLoaderDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSDLoaderDlg dialog

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

void CSDLoaderDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSDLoaderDlg)
	DDX_Control(pDX, IDC_I2C_LOOPBACK, c_I2CLoopBack);
	DDX_Control(pDX, IDC_CAN_LOOPBACK, c_CanLoopBack);
	DDX_Control(pDX, IDC_SCI_LOOPBACK, c_SciLoopBack);
	DDX_Control(pDX, IDC_LOAD, c_LoadButton);
	DDX_Control(pDX, IDC_OUTPUT_EDIT, c_OutputEdit);
	DDX_Control(pDX, IDC_VERBOSE_ERRORS, c_ErrorVerbose );
	DDX_Control(pDX, IDC_VERBOSE_MESSAGE, c_MessageVerbose );
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSDLoaderDlg, CDialog)
	//{{AFX_MSG_MAP(CSDLoaderDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_LOAD, OnLoad)
	ON_BN_CLICKED(IDC_VERBOSE_ERRORS, OnErrorVerbose)
	ON_BN_CLICKED(IDC_VERBOSE_MESSAGE, OnMessageVerbose)
    ON_MESSAGE(UWM_ONTHREADMESSAGE, OnThreadMessage)
    ON_MESSAGE(UWM_ONTHREADSTOP, OnThreadStop)
	ON_BN_CLICKED(IDC_SCI_LOOPBACK, OnSciLoopback)
	ON_BN_CLICKED(IDC_CAN_LOOPBACK, OnCanLoopback)
	ON_BN_CLICKED(IDC_I2C_LOOPBACK, OnI2cLoopback)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSDLoaderDlg message handlers

BOOL CSDLoaderDlg::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

    // Set default entry point
    m_useAltEntry  = FALSE;
    m_ErrorVerbose = TRUE;
	m_MessageVerbose = TRUE;
	m_CanLoopBack = FALSE;
	m_SciLoopBack = FALSE;
	m_I2CLoopBack = FALSE;

	c_ErrorVerbose.SetCheck( 1 );
	c_MessageVerbose.SetCheck( 1 );
	c_CanLoopBack.SetCheck(0);
	c_SciLoopBack.SetCheck(0);
	c_I2CLoopBack.SetCheck(0);

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


void CSDLoaderDlg::OnLoad() 
{
    CString dskType;
    char    CurrentDirectory[MAX_PATH+1];

    ZeroMemory(CurrentDirectory, sizeof(CurrentDirectory));

    ::GetCurrentDirectory(MAX_PATH,CurrentDirectory);

	// Directory structure is:
	// <CCS_INSTALL>
	//    |
	//    |-drivers
	//    |-boards\2808eZdspUSB\2808eZdspUSBDiags\Bin
	// 

	// Points to <CCS_INSTALL>\boards\2808eZdspUSB\2808eZdspUSBDiags\Bin
	m_workingDirectory = CurrentDirectory;
	m_workingDirectory.MakeUpper();
    m_targetPath = m_workingDirectory;

	int BaseOffset = m_targetPath.Find("\\BOARDS",0);
	if( BaseOffset == -1 )
	{
		// message
		return;
	}

	CString CCS_Root = m_targetPath.Left(BaseOffset);

	m_driverPath = CCS_Root + "\\drivers";
    m_driverName = "sdgo28xxeZdspusb.dvr";

	
	m_boardName     = "2808eZdspusb.dat";
    m_procFamily    = "TMS320C27XX";
    m_procName      = "cpu_0";
	m_procAddr      = "0x540";
	int Len = m_targetPath.GetLength();
	if( m_targetPath[Len-1] != '\\' )
		m_coffFileName = m_targetPath  + "\\2808eZdspUSBTest.out";
	else
		m_coffFileName = m_targetPath  + "2808eZdspUSBTest.out";

    /* Disable load button */ 
    c_LoadButton.EnableWindow( FALSE );

    /* Clear the edit window */ 
    c_OutputEdit.Clear();

    m_TestCount++;
    CString Result;
    Result.Format("@BEGIN-%d",m_TestCount );
    PrintResults(Result);

    m_mainWindow = AfxGetMainWnd();

    /* Start thread */ 
    AfxBeginThread(ThreadStart, this);
}


/*  ThreadStart( LPVOID pArg )
 *      This is the entry point for starting the coff load thread.
 *      The purpose of this function is to allow the user control over the GUI 
 *      (Graphical User Intf. ) while the load is processing.
 */
UINT CSDLoaderDlg::ThreadStart( LPVOID pArg )
{
    /* Create CoffLoader object */ 
    CoffLoader coffLoader;

    coffLoader.LoadGeneric( pArg );
    return 0;
}

/*  OnThreadStop( )
 *      When coff loading is complete, reenable the Load Button to accept
 *      a new load command.
 */
void CSDLoaderDlg::OnThreadStop( WPARAM, LPARAM lParam )
{
    c_LoadButton.EnableWindow( TRUE );
    CString Result;
    Result.Format("@END-%d\r\n",m_TestCount );
    PrintResults(Result);
}

/*  OnThreadMessage( WPARAM, LPARAM lParam )
 *      When a message is received, via the PostMessage(), print the message
 *      to the edit box, and free the message string. 
 */
void CSDLoaderDlg::OnThreadMessage( WPARAM, LPARAM lParam )
{
    /* Type cast the input parameter to a CString* */ 
    CString* message = ( CString* )lParam;

    /* Print the message */ 
    PrintResults( *message );

    /* Free the message resources */ 
    delete message;
}

void CSDLoaderDlg::PrintResults( CString outstr )
{
    /* Select end of text */
    c_OutputEdit.SetSel(-1,-1);

    /* Append output string */
    c_OutputEdit.ReplaceSel(outstr);
    c_OutputEdit.ReplaceSel("\r\n");

    /* Scroll text window */
    c_OutputEdit.LineScroll(1);
}
void CSDLoaderDlg::OnErrorVerbose() 
{
	m_ErrorVerbose = ( c_ErrorVerbose.GetCheck() == 1 ) ? TRUE:FALSE;
}

void CSDLoaderDlg::OnMessageVerbose() 
{
	m_MessageVerbose = ( c_MessageVerbose.GetCheck() == 1 ) ? TRUE:FALSE;
}

void CSDLoaderDlg::OnSciLoopback() 
{
	// TODO: Add your control notification handler code here
	m_SciLoopBack = ( c_SciLoopBack.GetCheck() == 1 ) ? TRUE : FALSE ;
	
}

void CSDLoaderDlg::OnCanLoopback() 
{
	// TODO: Add your control notification handler code here
	m_CanLoopBack = ( c_CanLoopBack.GetCheck() == 1 ) ? TRUE : FALSE ;
}

void CSDLoaderDlg::OnI2cLoopback() 
{
	// TODO: Add your control notification handler code here
	m_I2CLoopBack = ( c_I2CLoopBack.GetCheck() == 1 ) ? TRUE : FALSE ;

}

⌨️ 快捷键说明

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