OpenFirmware Service PicCard & FunCard
--------------------------------------

Software for PicCard and FunCard for moving flash sections between PC and tuner without programming
throught COM+LPT cables or Jtag device.

'PicCard.hex' - for PicCard with PIC16[C/F]84(A)
'FunCard.hex' - for FunCard with AT90S8515(A)

Required eeprom memory on card is 24C512 (64KB i2c eeprom, with other memories it won't work properly).

The writing and reading protocol was designed in that way that the bytes are written and read from eeprom during
communication, so there is no additional time reserved for writing or reading besides the time needed to transmit or
receive bytes from card.
Using of 128-byte packages (maximal allowed by 24C512) decreases the writing/reading cycles of the specified section which
also shorts the writing and reading process.

The entire eeprom space is used for writing and there isn't any special data in it for the card to work.
All you have to do is to replace memory with 24C512 (doesn't concern FunCard5 which already has 24C512)
and program processor's flash and the card is ready to work.

New instructions responsible for writing and reading the card's eeprom:
-----------------------------------------------------------------------

info:
> - from tuner to card
< - from card to tuner

- ins 0xF0 - setting section for writing/reading:

>C1 F0 00 00 01
<F0
>xx
<90 00 or 90 11

xx:
-0x00: beginning of the eeprom (when using card's flash as loader)
-0x01: TCS
-0x02: TPT
-0x03: TSR
-0x04: EMU
-0x05: TSETTING
-0x06: section status clearing
-other value: section pointer not set and card answer is 90 11

Eeprom memory map:
0000-0BFF: TPT (3KB) - 24 writing/reading cycles
0C00-13FF: TSR (2KB) - 16 writing/reading cycles
1400-FFFF: TCS (59KB) - 472 writing/reading cycles
1400-23FF: EMU (4KB) - 32 writing/reading cycles
2400-2BFF: TSETTING (2KB) - 16 writing/reading cycles
FFFF: section status (1B)

TCS overlaps with EMU i TSETTING, so it's possible to write everything except TCS and in the next turn write only TCS or
write TCS+TPT+TSR and EMU+TSETING or update single sections eg. only EMU.

Meaning of each bit in section status byte:
000abcde

a - TSETTING
b - EMU
c - TSR
d - TPT
e - TCS

Bits a-e shows presence of each section in eeprom. Bit set to '1' means that this section is already in eeprom and it is
possibe to read it. Each bit is set during writing the proper section with instructions 0xF1. Of course during writing
section that overlaps with other section, the bit responsibe for the second section is ceared.
After preparing the whole eeprom to write in loader mode or in external programmer, the section status byte must has a
valid value (last position in eeprom). As it is shown in eeprom map, section status byte is the last byte in eeprom and
TCS overlaps with it. But the software doesn't allow to overwrite this byte when writing the last write cyce of TCS and
it is ony possible when writing data in loader mode (in that case the card writes everything and doesn't care about
section structure and section status byte).

- ins 0xF1 - writing:

>C1 F1 00 00 80
<F1
>{yy}
<90 00

{yy}: 128 bytes to write in eeprom

- ins 0xF2 - reading:

>C1 F2 00 00 80
<F2
<{yy}
<90 00

{yy}: 128 bytes read from eeprom

- ins 0xF3 - status byte read
>C1 F3 00 00 01
<F3
<yy
<90 00

yy: status byte read from eeprom

After setting section the proper quantity of writing/reading cycles must be done to write/read this section to eeprom/from
eeprom.

LEDs configuration (only for FunCard with installed LEDs):
----------------------------------------------------------
oooo ooo
1234 567

1-5: green
6: yellow/orange
7: red

567 - sending ATR
5 - processing standard Seca instruction
When the card receives the standard seca instruction LEDs 1-4 become off (if some of them are on).
67 - processing 0xF0 instruction (setting section for writing/reading), after this instruction the state of LEDs 1-4
changes:
- all LEDs are off: 
1) 0x06 byte was given as a parameter, the status byte was cleared and the card answered 90 02
2) bad parameter was given, the pointer is not set and the card answered 90 11
- all LEDs are on: 00 was given as a parameter and the pointer is set at the beginning of the eeprom (loader mode)
- other combination: the pointer was set for the proper section and LEDs 1-4 show it's number in binary mode:
info:
o - on
x - off
xxxo - TCS
xxoo - TPT
xoxx - TSR
xoxo - EMU
xoox - TSETTING
7 - processing 0xF1 instruction (writing) - LEDs 1-4 shows writing section
6 - processing 0xF2 instruction (reading) - LEDs 1-4 shows reading section
56 - processing instruction 0xF3 (reading section status byte)

bezerker
(ameal@poczta.onet.pl)

Homepage: http://www.warsztat.piwko.pl
DVHK Board: http://shadown.risp.pl/DVHK/Board_/index.php