PDA

View Full Version : saving to E2PROM


rob
04-25-00, 02:48 PM
Tech Tip note about EEPROM and NMIX-0020 Rob Chapman Nov 13, 1999<p> When using EEPROM in the memory sockets provided (U2-4), it must<br> not overlap any other memory usage or it will not work. In<br> certain selections for the memory segmentation on the NMIX-0020<br> the memory area will overlap an internal memory mapped entity.<br> When the external memory is RAM or ROM, this does not matter,<br> the memory unit is read or written but it does not affect the<br> whole memory unit.<p> Not so with EEPROMs like 28C256 which allow a page mode write. Each page<br> is 64 bytes in size. When a byte or series of bytes is written to the<br> page within 150 us, the memory unit no longer will respond to external<br> memory requests and instead writes its 64 byte RAM cache to EEPROM which<br> takes up to 10 ms.<p> When the EEPROMs are put in the 0020s memory space and part of it<br> overlaps with an internal memory mapped peripheral such as internal<br> RAM which is written to constantly, then the EEPROM sees the same write<br> signals since they share the same space. The EEPROM always thinks<br> it is being written to and thusly will not respond to memory requests.<p> There are three solutions to using EEPROM with the NMIX-0020 board:<br> 1. move the memory mapped peripheral<br> 2. use an entire memory segment without overlaps<br> 3. add a few external components for a 32k non-overlapped segment<p> This technote explores the second option as it can be done easily<br> and memory size is not too important. A 16K or smaller EEPROM can<br> fit into the segmented memory space without overlapping any other<br> peripheral. The sacrifice is that the spaces available for RAM<br> are also segmented which can mean less RAM available even though<br> you have 32K chips.<p> There are several configurations to choose from with different<br> ammounts of RAM and EEPROM available:<br> 20K RAM and 16K EEPROM maximum.<p> In terms of time, the EEPROM memory is expensive to write to.<br> After each byte is written, it is polled until it is the<br> written value. During this period of time, the memory is<br> unavailable for reading or running a program out of. So if<br> there is one program for writing to the memory, it must exist<br> outside of the memory when it is executing. It can either be<br> copied out or it can live in the onboard EEPROM.<p> The choice of memory for runtime can affect where the program<br> exists as well. There are two memory schemes we can run here:<br> o roll each new word into EEPROM as it is defined and run out<br> of EEPROM<br> o leave and run in RAM but save and restore images to EEPROM<br> as a disk<p> EEWORD is used for rolling definitions from RAM into on-chip<br> EEPROM where they will execute from. This can be extended<br> to roll definitions into external EEPROM by defining a new<br> word E2WORD. Once the definitions are in E2PROM, they cannot<br> be forgotten with FORGET or DP ends up pointing to E2PROM and<br> carnage happens. This is a slight drawback but could be<br> addressed by redefining FORGET. Periodically, one would<br> rebuild E2PROM contents from source. This method dictates<br> a lot of writes to the E2PROM and will compile slower.<p> A more elegant method which also takes more RAM, is to keep<br> and run the image in RAM, saving a copy to E2PROM for reset<br> or power-up. In this case, FORGET would work and there would<br> be no need for periodic rebuilds. After a compile, save the<br> new image. When compiling, start with a fresh image using<br> COLD. This supports incremental refinement and small grouped<br> files. In this scheme, the E2PROM write program can live in<br> RAM and be backed up in E2PROM. This frees up any need for<br> on-chip EEPROM containing a copy of the write program.<p>Jumper Settings:<br> These are the jumper settings for the following code. This gives up to<br> 16K of RAM at 0000 to 3FFF, up to 16K of E2PROM at 4000 to 7FFF and 4K of<br> RAM at C000. If you only have 8K chips, then they will appear twice. I'm<br> using 32K chips and this gives me the full 16K.<p> ALL 8K X 8 DEVICES<br> 2764, 2864, 6264<p> PIN 1 PIN 26 PIN 27<br> +---+---+---+---+---+---+<br> &brvbar; &brvbar; X &brvbar; X &brvbar; &brvbar; &brvbar; X &brvbar;<br> &brvbar; &brvbar; X &brvbar; X &brvbar; &brvbar; &brvbar; X &brvbar;<br> +---+---+---+---+---+---+<br> A14 +5V +5V A13 A14 RR/W<p> 16K or 32K X 8 EEPROM or RAM<br> 28256, 28128<br> PIN 1 PIN 26 PIN 27<br> +---+---+---+---+---+---+<br> &brvbar; &brvbar; X &brvbar; &brvbar; X &brvbar; &brvbar; X &brvbar;<br> &brvbar; &brvbar; X &brvbar; &brvbar; X &brvbar; &brvbar; X &brvbar;<br> +---+---+---+---+---+---+<br> A14 +5V +5V A13 A14 RR/W<p><br> +5V A A13<br> +---------+<br> &brvbar; o XXXX &brvbar;<br> +---------+ 16K POSITION<br> &brvbar; XXXX o &brvbar;<br> +---------+<br> +5V B A14<p> C<br> +------+<br> O0 &brvbar; o o &brvbar;-+<br> &brvbar; &brvbar; &brvbar;<br> 0000-3FFF O1 &brvbar; XXXX &brvbar;-+<br> &brvbar; &brvbar; &brvbar;<br> O2 &brvbar; o o &brvbar;-+<br> &brvbar; &brvbar; &brvbar; ___________ 0000<br> 4000-7FFF O3 &brvbar; X o &brvbar;-+-U2 CHIP SELECT ---- RAM<br> &brvbar; &brvbar; &brvbar; &brvbar; 3FFF<br> O4 &brvbar; o\ o &brvbar;-+<br> &brvbar; \ &brvbar; ___________ 4000<br> 8000-BFFF O5 &brvbar; o X &brvbar;-+-U3 CHIP SELECT ---- E2PROM<br> &brvbar; &brvbar; &brvbar; 7FFF<br> O6 &brvbar; o o &brvbar;-+<br> &brvbar; &brvbar; ___________ C000<br> C000-FFFF O7 &brvbar; *--* &brvbar;---U4 CHIP SELECT ---- RAM<br> +------+ FFFF<p>Code:<br> This code is for saving and restoring images from E2PROM to RAM.<br> E2PROM is located at 0x4000.<p>( E2PROM writing algorithms Rob Chapman Nov 11, 1999 <br>( release 4 - save RAM to E2PROM as images for backup; RESTORE in E2PROM<p>CANCEL ( cancel any previous image<br>COLD ( reset dictionary<br>HEX<br>' TASK NFA CONSTANT RAM-START ( start address of dictionary RAM<br>4000 CONSTANT E2-START ( start of externel EEPROM<p>( ==== E2PROM storage words ==== )<br> VARIABLE E2DP ( dictionary pointer for e2prom )<p>: E2C! ( c \ a -- ) 2DUP C! SWAP FF AND SWAP ( store a byte<br> BEGIN 2DUP C@ = UNTIL 2DROP ; ( wait till done<br>: E2! ( n \ a -- ) OVER &gt;&lt; OVER E2C! 1+ E2C! ;<br>: E2MOVE ( a \ b \ n -- ) 0 DO &gt;R COUNT R@ E2C! R&gt; 1 + LOOP 2DROP ;<p>: E2WORD ( -- ) ( move latest definition to e2prom<br> E2DP @ &gt;R ( address of dest e2prom<br> R@ LATEST - ( calculate offset<br> LATEST PFAPTR ( pfa of word<br> DUP CFA DUP @ SWAP 2+ = ( check for code word<br> IF 2DUP CFA +! THEN ( add offset to CFA if true<br> +! ( add offset to pfa pointer<br> LATEST ( start of word<br> R@ ( dest for word<br> HERE LATEST - ( length of word<br> DUP E2DP +! ( increment e2prom ptr<br> E2MOVE ( move into e2prom<br> LATEST DP ! ( update dictionary pointer<br> R&gt; CURRENT @ ! ; ( update link pointer<p>( ==== Tools, extensions ==== )<br>: .B ( b -- ) ( print 8 bits as two nibbles ) BASE @ SWAP 2 BASE !<br> 0 &lt;# # # # # BL HOLD # # # # #&gt; TYPE SPACE BASE ! ;<br>: EE! ( n \ a -- ) OVER &gt;&lt; OVER EEC! 1+ EEC! ;<p>( ==== Startup services ==== )<br>: CANCEL 0 E2-START E2C! ; ( turn off autostart flag )<br>: E2+ E2-START + ;<p>( ==== Image and properties ==== )<br>( + 0 A44A<br>( + 2 RESTORE<br>( + 4 HI<br>( + 6 DP<br>( + 8 LATEST<br>( + A EDP<br>( + C length of image<br>( + 100 image<p>: RESTORE<br> [ 100 E2+ ] LITERAL [ RAM-START ] LITERAL ( can't call nonexistant words<br> [ C E2+ ] LITERAL @ CMOVE ( restore image to RAM<br> 6 E2+ @ DP ! ( restore system dictionary pointer<br> 8 E2+ @ CURRENT @ ! ( restore word list<br> A E2+ @ 30 ! ( restore EDP<br> 4 E2+ @ EXECUTE ; ( run any other programs<br> 10 E2+ E2DP ! E2WORD ( need to run boot program in e2prom<p><br>: SAVE<br> A44A E2-START E2! ( fire once autostart flag for startup )<br> ['] RESTORE CFA 2 E2+ E2! ( restoration vector )<br> ['] TASK CFA 4 E2+ E2! ( null vector )<br> DP @ 6 E2+ E2! ( save dictionary pointer )<br> LATEST 8 E2+ E2! ( save latest word )<br> 30 @ A E2+ E2! ( save EDP )<br> RAM-START <br> 100 E2+<br> HERE RAM-START - DUP C E2+ E2! E2MOVE ( save length & dictionary ) ;<p>: INSTALL ( a -- ) SAVE CFA 4 E2+ E2! ;<p>( ==== Test Program ==== )<br>: HI .&quot; Hello world &quot; ;<br>' HI INSTALL COLD<p>Linguistic Interface:<br> SAVE ( -- ) save current dictionary<br> INSTALL ( tick -- ) install ticked word to autorun at startup<br> CANCEL ( -- ) disable auto boot in E2PROM<p>Notes:<br> o writing to E2PROM during a crash - if the E2PROM hasn't been<br> write protected, then when a program crashes, it could write<br> to E2PROM while trying to run out of E2PROM. This has the<br> nasty side effect of scrambling E2PROM contents and in the<br> worst case, you have to remove it from the system, boot and<br> then reinsert it and write zero to its first location. Then<br> the code needs to be recompiled. To prevent the E2PROM from<br> being written to unnecessarily, install the pullup resister<br> beside pins 27 and 28 and then use the R/W jumper as a write<br> enable when in and write protect when out. For this to work<br> VBB needs to be connected. I just connected it to +5V.<br>

jya
05-05-00, 09:34 AM
Thanks!<p>Jerry<p>----------<br>Engineering is the art of making what you want from things you can get.<br>

eds
07-10-00, 11:59 AM
I have a little confusion involving the EEPROM. I have read that the memory map for the EEPROM is from $B600 to $B7FF. Then I have read some documents that describe the E2PROM (EsquaredPROM) differently than the EEPROM. It might not make sense, but I have taken the EEPROM to be internal to the chip, while the E2PROM to be an EXTERNAL EEPROM. <p>Now that I have come to the point of storing code in the EEPROM, I have noticed that there is no chips inserted in the U2 or U3 socket. If that is the only EEPROM, then I do not have EEPROM at all -- correct? If so, I assume I can obtain one from nmi.<p>Thanks<br><p>----------<br>Ed Seng<br>

rob
08-14-00, 05:04 PM
Correct. We have a few different external EEPROMs available for your needs. You can get by with an 8K for smaller needs or the 32K for larger needs.

TDEdwards
11-06-01, 04:45 AM
Question to Rob Chapman - do your comments in "Tech Tip note about EEPROM and NMIX-0020" also apply to the NMIY-0031 card?

If not, how are they different?

Trefor Edwards