Update contrib.
1 // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // bootldr\src\ymodemb.cpp
18 #define FILE_ID 0x594D4442
24 _LIT(KSerialLddName, "ECOMM");
25 _LIT(KSerialPddName, "EUART");
28 GLREF_C void RequestSignal(TInt aCount);
29 GLREF_C void HandleClose(TInt aHandle);
30 GLREF_C TInt OpenCommPort(TInt aPort, TInt& aHandle);
31 GLREF_C void WriteToCommPort(TInt aHandle, TRequestStatus& aStatus, const TDesC8& aDes);
32 GLREF_C void CommReadOneOrMore(TInt aHandle, TRequestStatus& aStatus, TDes8& aDes);
33 GLREF_C void CommRead(TInt aHandle, TRequestStatus& aStatus, TDes8& aDes);
34 GLREF_C void CommReadCancel(TInt aHandle);
40 YModemU::YModemU(TBool aG)
51 TInt YModemU::Create(TInt aPort)
53 TInt r=iComm.Open(aPort);
57 TCommConfigV01& c=cfg();
62 c.iParity=EParityNone;
63 // c.iHandshake=KConfigFreeRTS|KConfigFreeDTR;
67 r=iComm.SetConfig(cfg);
70 r=iComm.SetReceiveBufferLength(8192);
73 return iTimer.CreateLocal();
76 YModemU* YModemU::NewL(TInt aPort, TBool aG)
78 YModemU* p=new YModemU(aG);
79 TInt r=p->Create(aPort);
88 void YModemU::WriteC(TUint aChar)
95 User::WaitForRequest(s);
98 TInt YModemU::ReadBlock(TDes8& aDest)
101 TRequestStatus s1, s2;
102 iTimer.After(s1,iTimeout);
103 // test.Printf(_L("@%dms %d\n"),User::FastCounter(),iComm.QueryReceiveBuffer());
104 iComm.Read(s2,aDest);
105 User::WaitForRequest(s1,s2);
106 if (s2!=KRequestPending)
109 User::WaitForRequest(s1);
113 User::WaitForRequest(s2);
117 TInt ReadYModemInputData(TUint8* aDest, TInt& aLength)
119 if( TheYModem->IsHeaderStored() )
121 DEBUG_PRINT((_L(">>ReadYModemInputData(aDest:0x%08x, aLength:%d)\r\n"), aDest, aLength))
122 TInt r = TheYModem->GetHeaderBufferContent(aDest, aLength);
123 DEBUG_PRINT((_L("<<ReadYModemInputData(aDest:0x%08x, aLength:%d):%d\r\n"), aDest, aLength, r))
129 TInt r=TheYModem->ReadPackets(pD,aLength);
138 DEBUG_PRINT((_L(">>CloseYModem()\r\n")));
141 TheYModem->StartDownload(DownloadMode, size, name);
142 DEBUG_PRINT((_L("<<CloseYModem()\r\n")));
145 GLDEF_C TInt InitSerialDownload(TInt aPort)
147 // RThread().SetSystem(ETrue);
149 TInt r=LoadDriver(KSerialLddName,0);
152 r=LoadDriver(KSerialPddName,1);
156 TInt PortNumber=aPort;
157 DownloadMode=KYModemGMode;
159 TRAP(r,TheYModem=YModemU::NewL(PortNumber,ETrue));
160 if (r!=KErrNone || TheYModem==NULL)
163 // r=YModemB::New(TheYModem,PortNumber,DownloadMode);
164 // TEST(r==KErrNone && TheYModem!=NULL);
165 YModemU* pY=TheYModem;
168 r=pY->StartDownload(DownloadMode, FileSize, name);
172 #ifdef __SUPPORT_UNZIP__
173 if (name.Length()>=4 && name.Right(4).MatchF(_L(".zip"))==0 && FileSize!=0)
179 #ifdef __SUPPORT_FLASH_REPRO__
180 if (name.Length()>=8 && (name.Left(8).MatchF(_L("FLASHIMG"))==0 || name.Left(8).MatchF(_L("FLASHLDR"))==0) && FileSize!=0)
183 if (name.Left(8).MatchF(_L("FLASHLDR"))==0)
184 FlashBootLoader=ETrue;
193 r = pY->GetInnerCompression(ImageDeflated, RomLoaderHeaderExists);
196 PrintToScreen(_L("Unable to determine the compression!\r\n"));
200 LoadDevice=ELoadSerial;
201 InputFunction=ReadYModemInputData;
202 CloseInputFunction=CloseYModem;