brdbootldr/ubootldr/inc/ymodem.h
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Thu, 07 Jan 2010 13:38:45 +0200
changeset 10 36bfc973b146
parent 9 96e5fb8b040d
permissions -rw-r--r--
Revision: 201001 Kit: 201001

// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
// All rights reserved.
// This component and the accompanying materials are made available
// under the terms of the License "Eclipse Public License v1.0"
// which accompanies this distribution, and is available
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
//
// Initial Contributors:
// Nokia Corporation - initial contribution.
//
// Contributors:
//
// Description:
// bootldr\inc\ymodem.h
// 
//

#ifndef __YMODEM_H__
#define __YMODEM_H__

#ifndef __KERNEL_MODE__
#include <e32base.h>
typedef CBase BASE;
//#else
//#include <kernel/kernel.h>
//typedef DBase BASE;
#endif

const TUint8 SOH=0x01;
const TUint8 STX=0x02;
const TUint8 EOT=0x04;
const TUint8 ACK=0x06;
const TUint8 NAK=0x15;
const TUint8 CAN=0x18;
const TUint8 SUB=0x1A;
const TUint8 BIGC=0x43;
const TUint8 BIGG=0x47;

const TInt KErrZeroLengthPacket=-200;
const TInt KErrPacketTooShort=-201;
const TInt KErrBadPacketType=-202;
const TInt KErrCorruptSequenceNumber=-203;
const TInt KErrWrongSequenceNumber=-204;
const TInt KErrBadCrc=-205;
const TInt KErrBadTerminationPacket=-206;

const TInt KHeaderBufferSize=1024; 

class YModem : public BASE
	{
public:
	TInt StartDownload(TBool aG, TInt& aLength, TDes& aName);
	TInt ReadPackets(TUint8*& aDest, TInt aLength);
	
	// Support to deflated ROM Image
	TInt GetInnerCompression(TBool &aImageDeflated, TBool &aRomLoaderHeaderExists);
	TInt GetHeaderBufferContent(TUint8*& aDest, TInt& aLength);
	TBool IsHeaderStored(void);
protected:
	YModem(TBool aG);
	void UpdateCrc(const TUint8* aPtr, TInt aLength);
	TInt CheckPacket(TUint8* aDest);
	TInt ReadPacket(TDes8& aDest);
	virtual TInt ReadBlock(TDes8& aDest)=0;
	virtual void WriteC(TUint aChar)=0;
protected:
	TInt iTimeout;
	TInt iState;
	TInt iPacketSize;
	TInt iBlockSize;
	TUint8 iInitChar;
	TUint8 iSeqNum;
	TUint16 iCrc;
	TInt iFileSize;
	TBuf8<1040> iPacketBuf;
	TBuf<256> iFileName;
    
    // Support to deflated ROM Image
	TBuf8<KHeaderBufferSize> iHeaderBuf;
    TBool iHeaderStored;
    TInt iDataSizeInPuffer;
    TBool iImageDeflated;
	};

#endif