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

📄 usbwriter.cpp

📁 PW芯片方案Flash ROM烧写程序
💻 CPP
字号:
//---------------------------------------------------------------------------
// Pixelworks Inc. Company Confidential Strictly Private
//
// $Archive: $
// $Revision: 1.1.1.1 $
// $Author: KevinM $
// $Date: 2003/09/29 18:19:04 $
//
// --------------------------------------------------------------------------
// >>>>>>>>>>>>>>>>>>>>>>>>> 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.
// --------------------------------------------------------------------------
//
// UsbWriter.cpp: implementation of the CUsbWriter class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "UsbWriter.h"

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

static void GetStringFromHex( CString& strHex, LPBYTE pByte, 
								 int nCount)
{
	LPBYTE		p 		= pByte;
	int			n  		= nCount;
	LPBYTE		t 		= p;

	CString		strLine;
	CString		strChar;

	for( int i = 0; i < n; i++ ) {
		strChar.Format("%02x ", *t++ );
		strLine	+= strChar;
	}

	strHex	= strLine + "\n";
}

static int nTotal = 0;
static nPacket = 0;
static void DisplayHexPacket(LPBYTE pByte, int nCount)
{
	int nData = 0;

	nTotal += nCount;

	CString strPacket;
	strPacket.Format("TX: P%04d  B:%05d  T:%05d \n", nPacket++, nCount, nTotal);
	OutputDebugString(strPacket);

	while (nData < nCount)
	{
		CString strTmp;
		CString strLine;
		
		int nLen = 16;
		if (nData + nLen > nCount)
			nLen = (nCount - nData);

		strLine.Format("    0x%04x Data: ", nData);
		GetStringFromHex(strTmp, &pByte[nData], nLen);
		OutputDebugString(strLine + strTmp);

		nData += nLen;
	}
	OutputDebugString("\n");
}

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CUsbWriter::CUsbWriter()
{
	AllocateBuffers(256, 5);
	CircBuf.SetSize(4096);
	m_nMaxPacketSize = 0;
	m_bShutdown = FALSE;
}

CUsbWriter::~CUsbWriter()
{
	FreeBuffers();
}


void CUsbWriter::ProcessBuffer(CUsbIoBuf *Buf)
{
	// Only return when we have bytes to submit to the target

	Buf->NumberOfBytesToTransfer=0;

	int nBytesToSend = 0;

	if (!m_bShutdown)
	{
		nBytesToSend = CircBuf.WaitForBytes();
	}

	// Data is available to send...
	// nBytesToSend = CircBuf.GetAvailBytes();

#if 1
	//m_nMaxPacketSize = 64;
	if (nBytesToSend > m_nMaxPacketSize)
		nBytesToSend = m_nMaxPacketSize;
#endif

	if (!m_bShutdown)
	{
		CircBuf.ReadBytes((BYTE*)Buf->Buffer(), nBytesToSend, INFINITE);
	}

#if 1
	DisplayHexPacket((BYTE*)Buf->Buffer(), nBytesToSend);
#endif

	Buf->NumberOfBytesToTransfer=nBytesToSend;
	Buf->BytesTransferred=0;
	Buf->OperationFinished = false;
}

void CUsbWriter::WriteData(BYTE* pBytes, int nCount)
{
#if 1
	while (CircBuf.GetAvailBytes() > 0)
	{
		Sleep(10);
	}
#endif

	CircBuf.AddBytes(pBytes, nCount);
}

⌨️ 快捷键说明

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