1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 2<HTML> 3<HEAD> 4<META http-equiv="Content-Type" content="text/html; charset=windows-1252"> 5<META name="GENERATOR" content="IBM WebSphere Studio Homepage Builder Version 7.0.0.0 for Windows"> 6<META http-equiv="Content-Style-Type" content="text/css"> 7<TITLE>SVC_UncompressLZ8FromDevice</TITLE> 8<LINK rel="stylesheet" href="../css/nitro.css" type="text/css"> 9</HEAD> 10<BODY> 11<H1 align="left">SVC_UncompressLZ8FromDevice <IMG src="../image/BPT.gif" align="middle"><IMG src="../image/TWL.gif" align="middle"></H1> 12<H2>Syntax</H2> 13<DL> 14 <DD> 15 <PRE><CODE>#include <nitro/os/common/systemCall.h></CODE></PRE> 16 <PRE><CODE>s32 SVC_UncompressLZ8FromDevice( const void* srcp, 17 void* destp, 18 const void* paramp, 19 const MIReadStreamCallbacks* callbacks );</CODE></PRE> 20</DL> 21<H2>Arguments</H2> 22<TABLE border="1"> 23 <TBODY> 24 <TR> 25 <TD><B><I>srcp</I></B></TD> 26 <TD>Source address where the LZ77 compressed data is stored.</TD> 27 </TR> 28 <TR> 29 <TD><B><I>destp</I></B></TD> 30 <TD>Destination address for decompression.</TD> 31 </TR> 32 <TR> 33 <TD><B><I>paramp</I></B></TD> 34 <TD>Parameter address that is passed to the <code>initStream</code> function of the <CODE>MIReadStreamCallbacks</CODE> structure.</TD> 35 </TR> 36 <TR> 37 <TD><B><I>callbacks</I></B></TD> 38 <TD>Address of the <code>MIReadStreamCallbacks</code> socket.</TD> 39 </TR> 40 </TBODY> 41</TABLE> 42<H2>Return Values</H2> 43<P>A value of 0 or higher denotes the decompressed size. A value less than 0 denotes an error.</P> 44<H2>Description</H2> 45<P>This function decompresses LZ77 compressed data and writes the data to the specified region of memory.</P> 46<P>Decompresses compressed data that is specified by <B><I>srcp</I></B>, and stores the result in the area specified in <B><I>destp</I></B>.</P> 47<P>Compressed data on devices that are not memory-mapped can be decompressed directly without using a temporary buffer. You can also decompress in RAM where byte-level access is not possible.</P> 48<P>The data specified by <B><I>srcp</I></B> should be data that was compressed using the command "<CODE><A href="../tools/ntrcomp.html">ntrcomp</A> -l 2</CODE>". The boundary restrictions of <B><I>srcp</I></B> depend on the implementation of the <CODE>initStream</CODE> callback.</P> 49<P><BR> <BR> <B>Sample code</B></P> 50<pre> 51<CODE>s32 NVRAMi_UncompressLZ8( const u8 *nvram, void *ram, int limit ) 52{ 53 static const MIReadStreamCallbacks cb = {NVRAMi_InitReadStream, NVRAMi_TerminateReadStream, 54 NVRAMi_ReadByteStream, NULL, NVRAMi_ReadWordStream}; 55 56 return SVC_UncompressLZ8FromDevice( nvram, ram, &limit, &cb ); 57} 58 59s32 NVRAMi_InitReadStream( const u8 *nvram, void *ram, const void *param ) 60{ 61 int limit = *(int*)param; 62 u32 comp_header; 63 u32 address = (u32)nvram; 64 u8 adr[3]; 65 int size; 66 int i; 67 s32 retval; 68 69 adr[0] = (u8)(address >> 16); 70 adr[1] = (u8)(address >> 8); 71 adr[2] = (u8)(address); 72 73 // Send 4 bytes for the instruction portion 74 SPI_Wait(); 75 NVRAM_SPIChangeMode( SPI_TRANSMODE_CONTINUOUS ); 76 SPI_Send( NVRAM_INSTRUCTION_READ ); 77 for (i = 0; i < 3; i++) 78 { 79 SPI_Wait(); 80 SPI_Send(adr[i]); 81 } 82 83 // preload 84 SPI_Wait(); 85 SPI_Dummy(); 86 87 comp_header = NVRAMi_ReadWordStream( nvram ); 88 retval = comp_header; 89 90 size = comp_header >> 8; 91 if ( (int)(nvram + size) > NVRAM_SIZE_MAX || 92 size <= 0 || size > limit ) 93 { 94 retval = -1; 95 } 96 97 return retval; 98} 99 100u8 NVRAMi_ReadByteStream( const u8 *nvram ) 101{ 102 u8 byte; 103 104 SPI_Wait(); 105 byte = SPI_Receive(); 106 107 // preload 108 SPI_Dummy(); 109 110 return byte; 111} 112 113u32 NVRAMi_ReadWordStream( const u8 *nvram ) 114{ 115 u32 word; 116 u8* bytep = (u8*)&word; 117 int i; 118 119 for (i=0; i<4; i++) 120 { 121 *bytep++ = NVRAMi_ReadByteStream( NULL ); 122 } 123 124 return word; 125} 126 127s32 NVRAMi_TerminateReadStream( const u8 *nvram ) 128{ 129 // 1st dummy read 130 SPI_Wait(); 131 (void)SPI_Receive(); 132 133 // 2nd dummy read 134 NVRAM_SPIChangeMode(SPI_TRANSMODE_1BYTE); 135 SPI_DummyWait(); 136 (void)SPI_Receive(); 137 138 return 0; 139}</CODE></pre> 140</P> 141 142<H2>See Also</H2> 143<P><CODE><A href="SVC_UncompressLZ.html">SVC_UncompressLZ16FromDevice</A><BR></CODE></P> 144<H2>Revision History</H2> 145<P>2007/10/22 Initial version.</P> 146<hr><p>CONFIDENTIAL</p></body> 147</HTML>