Update contrib.
1 // Copyright (c) 2004-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 // e32\drivers\crashflashnor.cpp
18 #include <crashflashnor.h>
20 void CrashFlashNor::StartTransaction()
24 void CrashFlashNor::EndTransaction()
26 #ifdef _CRASHLOG_COMPR
27 // Ensure any buffered data is output not all the data will be valid but
28 // iWriteTotal should reflect this by only increasing by no of valid/buffered bytes
33 #endif //_CRASHLOG_COMPR
36 TUint CrashFlashNor::BytesWritten()
38 return iWriteTotal + iWriteBufBytes;
41 void CrashFlashNor::SetReadPos(TUint aPos)
43 __KTRACE_OPT(KDEBUGGER,Kern::Printf("Setting read position to %d", aPos));
44 if( (aPos%sizeof(TCFIWord)) == 0)
52 __KTRACE_OPT(KDEBUGGER,Kern::Printf("Invalid read position requested, ignoring."));
57 TInt CrashFlashNor::Initialise()
59 __KTRACE_OPT(KDEBUGGER,Kern::Printf("CrashFlashNor::Initialise()"));
60 TInt ret = VariantInitialise();
63 __KTRACE_OPT(KDEBUGGER,Kern::Printf("CrashFlashNor::VariantInitialise() failed"));
66 // start writing after the crash log header
68 #ifdef CDS_CRASH_LOGGER
71 iWritePos = KCrashLogHeaderSize;
72 #endif //CDS_CRASH_LOGGER
80 void CrashFlashNor::SetWritePos(TUint aPos)
82 __KTRACE_OPT(KDEBUGGER,Kern::Printf("CrashFlashNor::SetWritePos"));
83 if( (aPos%sizeof(TCFIWord)) == 0)
85 __KTRACE_OPT(KDEBUGGER,Kern::Printf("Setting write position to %d", aPos));
93 __KTRACE_OPT(KDEBUGGER,Kern::Printf("Invalid read position requested, ignoring."));
96 void CrashFlashNor::Write(const TDesC8& aDes)
98 if (iWritePos >= KMaxCrashLogSize)
100 __KTRACE_OPT(KDEBUGGER,Kern::Printf("Write: log limit already exceeded"));
104 TInt size = aDes.Size();
105 #ifndef _CRASHLOG_COMPR
106 __KTRACE_OPT(KDEBUGGER,Kern::Printf("Write: %S, size: %d",&aDes,size));
108 __KTRACE_OPT(KDEBUGGER,Kern::Printf("Write: writing %d bytes",size));
110 const TUint8* ptr8 = aDes.Ptr();
112 TInt truncated = EFalse;
113 #ifndef _CRASHLOG_COMPR
114 // If this will take us too close to (or past) the end of the crash log, discard the current string
115 // and write the truncation notice instead
116 if (iWritePos+size > KMaxCrashLogSize-KCrashLogTruncated().Size())
118 __KTRACE_OPT(KDEBUGGER,Kern::Printf("Write: truncating log"));
119 size = KCrashLogTruncated().Size();
120 ptr8 = KCrashLogTruncated().Ptr();
124 // If this will take us past the end of the crash log, then truncate it
125 if (iWritePos+size > KMaxCrashLogSize)
127 // no. of bytes left in crash log sector
128 TUint tmp=KMaxCrashLogSize - iWritePos;
129 __KTRACE_OPT(KDEBUGGER,Kern::Printf("Write: truncating log, limiting output to %d bytes as iWritePos=%d",tmp,iWritePos));
135 const TUint8* end = ptr8 + size;
137 for(; ptr8<end; ptr8++)
139 switch(iWriteBufBytes)
142 iWriteBuf |= (*ptr8);
144 #if defined(TCFI_2BYTE_WORD) || defined(TCFI_4BYTE_WORD)
146 iWriteBuf |= (*ptr8)<<8;
148 #if defined(TCFI_4BYTE_WORD)
150 iWriteBuf |= (*ptr8)<<16;
153 iWriteBuf |= (*ptr8)<<24;
159 if(iWriteBufBytes == (sizeof(TCFIWord)))
162 iWritePos+=sizeof(TCFIWord);
163 iWriteTotal+=sizeof(TCFIWord);
166 //equiv to iWriteBufBytes%=sizeof(TCFIWord) as long as TCFIWord is
168 iWriteBufBytes&=sizeof(TCFIWord)-1;
171 // If the log was truncated, skip the write position ahead so we don't try to write any more
174 iWritePos = KMaxCrashLogSize;
176 __KTRACE_OPT(KDEBUGGER,Kern::Printf("Write: total %d, position %d", iWriteTotal, iWritePos));
179 void CrashFlashNor::WriteSignature(const TDesC8& aDes)
181 if (iWriteBufBytes > 0)
191 void CrashFlashNor::Read(TDes8& aDes)
193 TUint8* ptr8 = const_cast<TUint8*>(aDes.Ptr());
194 const TUint8* end = ptr8 + aDes.Size();
195 for( ; ptr8<end; ptr8++)
197 switch(iReadBufBytes)
201 iReadPos+=sizeof(TCFIWord);
202 *ptr8 = (TUint8)(iReadBuf);
204 #if defined(TCFI_2BYTE_WORD) || defined(TCFI_4BYTE_WORD)
206 *ptr8 = (TUint8)(iReadBuf>>8);
208 #if defined(TCFI_4BYTE_WORD)
210 *ptr8 = (TUint8)(iReadBuf>>16);
213 *ptr8 = (TUint8)(iReadBuf>>24);
219 //equiv to iReadBufBytes%=sizeof(TCFIWord) as long as TCFIWord is
221 iReadBufBytes&=sizeof(TCFIWord)-1;
225 void CrashFlashNor::EraseLogArea()
227 __KTRACE_OPT(KDEBUGGER,Kern::Printf("Erasing crash log area..."));
228 for(TUint erased = 0; erased < KMaxCrashLogSize; erased += iEraseBlockSize)
230 DoEraseBlock(erased);
232 __KTRACE_OPT(KDEBUGGER,Kern::Printf("Finished erasing area for crash log."));
235 void CrashFlashNor::EraseFlashBlock(TUint aBlock)
237 __KTRACE_OPT(KDEBUGGER,Kern::Printf("CrashFlashNor::Erasing crash flash block offset [0x%X]", aBlock));
239 if(aBlock%iEraseBlockSize != 0 || aBlock > KMaxCrashLogSize)
241 __KTRACE_OPT(KDEBUGGER,Kern::Printf("Invalid Block Address - Not deleting [0x%X]", aBlock));
245 DoEraseBlock(aBlock);
248 #ifdef _CRASHLOG_COMPR
249 TUint CrashFlashNor::GetOutputLimit()
251 return KMaxCrashLogSize-KCrashLogHeaderSize;
254 TUint CrashFlashNor::GetLogOffset(void)