📄 flashhelper.h
字号:
//---------------------------------------------------------------------------
// Pixelworks Inc. Company Confidential Strictly Private
//
// $Archive: $
// $Revision: 1.2 $
// $Author: ckerchner $
// $Date: 2004/11/23 00:31:35 $
//
// --------------------------------------------------------------------------
// >>>>>>>>>>>>>>>>>>>>>>>>> COPYRIGHT NOTICE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// --------------------------------------------------------------------------
// Copyright 1997-2003 (c) Pixelworks Inc.
//
// Pixelworks owns the sole copyright to this software. Under international
// copyright laws you (1) may not make a copy of this software except for
// the purposes of maintaining a single archive copy, (2) may not derive
// works herefrom, (3) may not distribute this work to others. These rights
// are provided for information clarification, other restrictions of rights
// may apply as well.
//
// This is an unpublished work.
// --------------------------------------------------------------------------
// >>>>>>>>>>>>>>>>>>>>>>>>>>>> WARRANTEE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// --------------------------------------------------------------------------
// Pixelworks Inc. MAKES NO WARRANTY OF ANY KIND WITH REGARD TO THE USE OF
// THIS SOFTWARE, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
// PURPOSE.
// --------------------------------------------------------------------------
//
#ifndef __FLASHHELPER_H__
#define __FLASHHELPER_H__
#include "FlashUpgrader.h"
#include "MakeSafe.h"
#include "ComPortCmd.h"
//----------------------------------------------------------------------------
// Enumeration of error conditions.
//----------------------------------------------------------------------------
typedef enum
{
feOK,
// Errors that occur before downloading a file to the target.
feAPP_ERROR,
feFLASHFILE_NOTFOUND,
feFLASHFILE_READ_ERROR,
feFLASHFILE_FORMAT_ERROR,
feFLASHFILE_EXPECTED_INTEL80_ERROR,
// Errors that occur while attempting to download a file to the target.
feTARGET_ERROR_MESSAGE,
feFLASH_CANCELED
} eFLASHERROR;
//----------------------------------------------------------------------------
// Enumeration of status events passed in callback procedure.
//----------------------------------------------------------------------------
typedef enum
{
fsNONE, // dwParam not used
fsERROR, // dwParam not used
fsDOWNLOADED_BLOCK, // dwParam= number of bytes downloaded
fsCOMPLETED // dwParam not used
} eFLASHSTATUS;
//----------------------------------------------------------------------------
// Type declaration for callback procedure.
//----------------------------------------------------------------------------
typedef void (*PFLASHCALLBACK)(eFLASHSTATUS eStatus, DWORD dwParam = 0);
//----------------------------------------------------------------------------
// Intel Extended Hex file record types.
//----------------------------------------------------------------------------
typedef enum
{
rtDATA = 0,
rtEOF = 1,
rtEXTENDED_ADDRESS = 2,
rtSTART_ADDRESS = 3,
rtLINEAR_ADDRESS = 4,
} eRECORDTYPE;
//****************************************************************************
// Start of class declaration
//****************************************************************************
class CFlashHelper
{
public:
// Constructor/destructor
CFlashHelper();
~CFlashHelper();
//------------------------------------------------------------------------
// Begin downloading a file to the target system.
//
// Note: The serial port must have already been opened before using this
// API.
//------------------------------------------------------------------------
eFLASHERROR BeginFlashDownload(const PFLASHCALLBACK pCallback,
CComPortCmd *pComPortCmd,
const PFILE_ITEM pFileItem,
int *pnTotalSize,
bool bFirstFile);
//------------------------------------------------------------------------
// Cancel pending download operation.
//------------------------------------------------------------------------
BOOL CancelOperation();
//------------------------------------------------------------------------
// Get last message that was sent from target as a string.
//------------------------------------------------------------------------
LPCSTR GetLastReturnedTargetMessage() const;
//------------------------------------------------------------------------
// Get last error message as a string.
//------------------------------------------------------------------------
LPCSTR GetLastError() const;
private:
int m_nPartialBlockSize;
int m_nBlockSize;
PFLASHCALLBACK m_pCallback; // pointer to event callback procedure
CComPortCmd *m_pComPortCmd; // pointer to COM port command object
HANDLE m_hCancelEvent; // event used to cancel pending COM command operation
BOOL m_bCanceled; // TRUE= operation was canceled
int m_nBlockCounter; // Counts block downloaded.
BYTE *m_pFlashData; // pointer to binary data to download
int m_nFlashDataSize; // size of binary data
HANDLE m_hThread; // Downloader thread handle
HANDLE m_hKillEvent; // Event used to signal thread to die
CSafe m_Safe; // Thread-safe object (uses semaphore)
CString m_strReturnedMsg; // Status message returned from target
eFLASHERROR m_eLastError; // enumerated last error value
CString m_strLastErrorMsg; // Last error message
static DWORD WINAPI ThreadProc(LPVOID pParam);
void DeleteHeapObjects();
void SetLastError(eFLASHERROR eStatus);
eFLASHERROR TextToBinaryChunks(const PFILE_ITEM pFileItem, const BYTE *pData,
int nDataSize, BYTE **ppBinary, int *pnSize);
eFLASHERROR BinaryToBinaryChunks(const PFILE_ITEM pFileItem, const BYTE *pData,
int nDataSize, BYTE **ppBinary, int *pnSize);
eFLASHERROR ConvertToBinaryChunks(const PFILE_ITEM pFileItem, const BYTE *pData,
int nDataSize, BYTE **ppBinary, int *pnSize);
BOOL ParseIntelExtendedHexLine(char **ppSourceText, int *pnTextSize,
WORD *pwOffset, eRECORDTYPE *peCode,
BYTE *pDataArray, BYTE *pcDataSize);
BOOL DownloadFlashCode();
eSENDCMDRETVAL DownloadDataXModem(const BYTE *pData, int nSize, CString& rstrResult);
eSENDCMDRETVAL DownloadXModemBlock(BYTE cBlock, const BYTE *pData, int nSize);
eSENDCMDRETVAL GetResponseString(CString& rstrResult);
WORD CalculateCRC16(const BYTE *pcData, int nCount);
BOOL AsciiHexToByte(char *pText, BYTE *pcRet);
BOOL AsciiHexToWord(char *pText, WORD *pwRet);
int HexDigit(char chr);
int GetByte(const BYTE * & pInput, const BYTE * pEnd);
public:
eFLASHERROR GetFlashData(const PFILE_ITEM pFileItem, BYTE **ppData, int *pSize);
CString GetError(eFLASHERROR eErr) { SetLastError( eErr ); return m_strLastErrorMsg; }; // Last error message
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -