5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
26 #include "eeprominterface.h"
38 PACK(struct DirEntArm
{
61 struct t_eeprom_header
63 uint32_t sequence_no
; // sequence # to decide which block is most recent
64 uint16_t data_size
; // # bytes in data area
69 PACK(struct EepromHeaderFile
75 PACK(struct EepromHeader
79 EepromHeaderFile files
[63];
84 uint8_t m_fileId
; //index of file in directory = filename
85 unsigned int m_pos
; //over all filepos
86 unsigned int m_currBlk
; //current block.id
87 unsigned int m_ofs
; //offset inside of the current block
88 uint8_t m_zeroes
; //control byte for run length decoder
89 uint8_t m_bRlc
; //control byte for run length decoder
90 unsigned int m_err
; //error reasons
96 unsigned int eeprom_size
;
99 unsigned int eeFsVersion
;
100 unsigned int eeFsBlockSize
;
101 unsigned int eeFsSize
;
102 unsigned int eeFsFirstBlock
;
103 unsigned int eeFsBlocksOffset
;
104 unsigned int eeFsBlocksMax
;
105 unsigned int eeFsLinkSize
;
107 EepromHeader
* eepromFatHeader
;
109 void eeprom_read_block (void *pointer_ram
, unsigned int pointer_eeprom
, size_t size
);
110 void eeprom_write_block(const void *pointer_ram
, unsigned int pointer_eeprom
, size_t size
);
112 uint8_t EeFsRead(unsigned int blk
, unsigned int ofs
);
113 void EeFsWrite(unsigned int blk
, unsigned int ofs
, uint8_t val
);
115 unsigned int EeFsGetLink(unsigned int blk
);
116 void EeFsSetLink(unsigned int blk
, unsigned int val
);
117 uint8_t EeFsGetDat(unsigned int blk
, unsigned int ofs
);
118 void EeFsSetDat(unsigned int blk
, unsigned int ofs
, const uint8_t *buf
, unsigned int len
);
119 unsigned int EeFsGetFree();
120 void EeFsFree(unsigned int blk
); // free one or more blocks
121 unsigned int EeFsAlloc(); // alloc one block from freelist
128 void EeFsCreate(uint8_t *eeprom
, int size
, Board::Type board
, unsigned int version
);
130 bool EeFsOpen(uint8_t *eeprom
, int size
, Board::Type board
);
132 ///open file for reading, no close necessary
133 ///for writing use writeRlc() or create()
134 unsigned int openRd(unsigned int i_fileId
);
135 /// create a new file with given fileId,
136 /// !!! if this file already exists, then all blocks are reused
137 /// and all contents will be overwritten.
138 /// after writing closeTrunc has to be called
139 void create(unsigned int i_fileId
, unsigned int typ
);
140 /// close file and truncate the blockchain if to long.
143 ///open file, write to file and close it.
144 ///If file existed before, then contents is overwritten.
145 ///If file was larger before, then unused blocks are freed
146 unsigned int writeRlc1(unsigned int i_fileId
, unsigned int typ
, const uint8_t *buf
, unsigned int i_len
);
147 unsigned int writeRlc2(unsigned int i_fileId
, unsigned int typ
, const uint8_t *buf
, unsigned int i_len
);
149 unsigned int read(uint8_t *buf
, unsigned int i_len
);
150 unsigned int write1(uint8_t b
);
151 unsigned int write(const uint8_t *buf
, unsigned int i_len
);
153 ///return size of compressed file without block overhead
154 unsigned int size(unsigned int id
);
155 ///read from opened file and decode rlc-coded data
156 unsigned int readRlc12(uint8_t *buf
, unsigned int i_len
, bool rlc2
);
157 inline unsigned int readRlc1(uint8_t *buf
, unsigned int i_len
)
159 return readRlc12(buf
, i_len
, false);
161 inline unsigned int readRlc2(uint8_t *buf
, unsigned int i_len
)
163 return readRlc12(buf
, i_len
, true);
166 uint8_t byte_checksum(uint8_t *p
, unsigned int size
);
167 unsigned int ee32_check_header(struct t_eeprom_header
*hptr
);
168 unsigned int get_current_block_number(unsigned int block_no
, uint16_t *p_size
);
171 unsigned int importRlc(QByteArray
& dst
, QByteArray
& src
, unsigned int rlcVersion
=2);
173 #endif // _RLEFILE_H_