PDA

View Full Version : Porting legacy code to 68HC12


Charles Greenlaw
09-14-00, 01:04 PM
I have a large legacy program that I would like to move from a 68HC11 board (NMIS-0021) over to a 68HC12 board (NMIS-L-0912).<p>On the '11 board, I would load the program into high RAM ($8004 and up, with a couple of ALLOT's to jump over registers and memory-mapped IO), overload a modified version of hexdump.4th in low RAM, and save an image of the code from high RAM as an S-file to disk.<p>On the '12 board, the internal RAM is WAAY too small to hold my code and the external RAM is low RAM.<p>Is there any way to load my code into the external RAM and transfer it to Flash for testing? Or is there a direct route to Flash?<br>

rob
09-14-00, 05:06 PM
&lt;HTML&gt; <br>&lt;BODY&gt;<br> Yes to both options. You can compile your code directly into Flash.<br> This is useful when you don't have any external RAM like our<br> NMIN-0912 or our PillBox NMIB-0912. Include this code at the<br> beginning of your code:<p>HEX<br>( ==== Find empty space in Flash ROM ==== )<br>: FLBLANK ( -- a ) F800 F000 8000<br> DO FF I 10 OVER + SWAP DO I C@ AND LOOP FF = IF DROP I LEAVE THEN<br> 100 +LOOP DUP F800 = IF CR .&quot; Flash is full.&quot; CR ELSE DUP U. THEN ;<p>FLBLANK FDP ! FORGET FLBLANK<p>( ==== ROM it all with auto-rom words <br>: ; [COMPILE] ; FLWORD ; IMMEDIATE FLWORD<br>: CONSTANT CONSTANT FLWORD ;<br>: CREATE HERE CONSTANT ;<br>: VARIABLE CREATE 2 ALLOT ;<br>: FL! ( n \ a -- ) OVER &gt;&lt; OVER FLC! 1+ FLC! ; ( Fixes a defect )<p> It finds an empty spot in Flash and sets the flash dictionary pointer <br> there. Any code that is created is written to flash memory. Variables<br> just point to alloted RAM. Once Flash has been filled, you must clear<br> it and reload Forth again. But using this method you can go for quite<br> a while with a little ammount of code. This puts code into Flash but<br> doesn't call it at startup. For this you to do:<p> : HI CR .&quot; HELLO WORLD &quot; ; OK<br> A44A D00 EE! OK<br> ' HI CFA D02 EE! OK<br> D00 1 DUMP<br> 0 1 2 3 4 5 6 7 8 9 A B C D E F<br> D00: A4 4A 81 56 FF FF FF FF FF FF FF FF FF FF FF FF .J.V............ OK<p> Then press the reset button and you'll get:<p> HELLO WORLD<br> Max-FORTH V5.0L<p> If you want to get all the words back into the dictionary, and context<br> restored, then you'll have to save a copy of the system variables into<br> EEPROM and restore them upon bootup.<p> Note: when a word has been placed into Flash ROM or EPROM, it can no<br> longer have its header modified by IMMEDIATE. If ; is made to<br> automatically place code in a ROM, then any word that is to be immediate<br> must use the following sequence which works for all cases:<p> [ IMMEDIATE ] ;<p> in place of the more conventinal which works only for RAM case:<p> ; IMMEDIATE<p><br> The other alternative as you mentioned, is to compile to RAM if it's<br> there, and then copy to Flash and have it copy back upon startup and<br> run. This can be done with these tools:<p>( Image saver and restorer for autobooting )<p>( Image components and offsets )<br>( In EEPROM:<br>( D00 A44A - just run and return<br>( D02 RESTORE - must point to saved image of restore<br>( D04 main startup word stored by INSTALL<br>( in Flash:<br>( system variables 0 copy of RAM locations in system<br>( image size + sys-size length of image<br>( image + sys-size + 2 image of code<p>COLD<br>HEX<br>HERE DP ! ( choose another RAM location such as 2000 )<p>( ==== Image and properties ==== )<br> HERE CONSTANT RAM-START ( start of user image )<br> D00 CONSTANT BOOT-VECT ( start of EEPROM: boot vector<br> R0 CURRENT MIN CONSTANT sys-start ( start of system variables<br> FDP BLK MAX 2+ CONSTANT sys-end ( end of system variables<br> sys-end sys-start - CONSTANT sys-size ( size of variables<p>( ==== Startup services ==== )<br>: -AUTOBOOT 0 BOOT-VECT EE! ; ( turn off autostart flag )<p>( Find empty space in Flash ROM )<br>: FLBLANK ( -- a ) F800 F000 8000<br> DO FF I 10 OVER + SWAP DO I C@ AND LOOP FF = IF DROP I LEAVE THEN<br> 100 +LOOP DUP F800 =<br> IF CR .&quot; Flash is full.&quot; CR 0 ERROR THEN DUP U. ;<p>FLBLANK FORGET FLBLANK CONSTANT FL-START ( start of flash: where to save to<p>: FL+ FL-START + ;<p>: RESTORE ( can't call nonexistant words so [ ] LITERAL is used<br> [ FL-START ] LITERAL ( start of saved system image )<br> [ sys-start ] LITERAL ( start of system variables )<br> [ sys-size ] LITERAL CMOVE ( restore system RAM image<br> [ sys-size 2+ FL+ ] LITERAL ( start of dict image )<br> [ RAM-START ] LITERAL ( start of dict space <br> [ sys-size FL+ ] LITERAL @ ( size of dict image )<br> ?DUP IF CMOVE ( restore dictionary image to RAM ) ELSE 2DROP THEN<br> [ BOOT-VECT 4 + ] LITERAL @ EXECUTE ; ( run main program<p>: SAVE<br> ['] RESTORE CFA RAM-START - sys-size + 2 + FL+ BOOT-VECT 2+ EE!<br> ( restoration vector )<br> ['] TASK CFA BOOT-VECT 4 + EE! ( null vector )<br> sys-start FL-START sys-size FLMOVE ( save system variables )<br> RAM-START sys-size 2+ FL+ HERE RAM-START - ( src \ dst \ siz )<br> DUP sys-size FL+ FL! <br> ?DUP IF FLMOVE ( save length & dictionary ) ELSE 2DROP THEN<br> A44A BOOT-VECT EE! ( fire once autostart flag for startup ) ;<p>: INSTALL ( a -- ) SAVE CFA BOOT-VECT 4 + EE! ;<p>( Example usage:)<br>: MAIN CR .&quot; HELLO &quot; ; ' MAIN INSTALL<p> Then press the reset button and you'll get:<p> HELLO<br> Max-FORTH V5.0L<p> You can remove the example booter by using -AUTOBOOT. The example is small<br> enough that internal RAM is used but for larger programs make sure you set<br> DP to external RAM at the beginning of this code.<p> Rob<br>&lt;/BODY&gt;<br>&lt;/HTML&gt;<br>