M16C/62
int clearsrd()
Clears the flash SRD register.
Virtual Flash EEPROM Driver for the M16C/62
int readEE(int tag, int *value)
Upon return, *value contains the EEPROM value at the address “tag”. Returns 1 on no errors, 0 on
invalid tag.
6. Notes
Interrupts assigned to the fixed vector table CANNOT occur during any write to flash operation. This
includes all the function calls above except for readsrd() and readEE(). As a ”safety” feature, interrupts
are suspended during flash operations. The worst case suspend time is over 600 ms (maximum erase
block time). If this delay is unacceptable, remove the “interruptoff” line at the beginning of the function
ramcodestrt() in the file RAM62.c, move the variable vector table to RAM, and then set the “intb” register
accordingly.
Note as the size of the EEPROM increases, so can the time to execute the writeEE() function. For
example, an EEPROM size of 3FF0h or greater requires an erase of both flash blocks and rewrite every
time a value is updated. For sizes near the max. of 7FF0h a rewrite to an EEPROM location could take
up to 4 seconds!
7. Demonstration Program
The driver file virtEE.c contains a demonstration “main.c” (remove or comment out when implementing as
a driver). The program was developed to run on the MSV1632, but it also works with any M16C/62 flash
system running the KD30 debugger in single chip mode.
The following steps are required to run the Demonstration (it is assumed the user has a general
understanding of the KD30 debugger):
1.
Connect the MDECE0620 board to power and the host PC.
2.
Start KD30. In the “INIT” screen, click on the tab “run mode” and select “free run mode”.
3.
Load the “virtEE.x30” file.
4.
Insert a breakpoint in the main() function at the first “y= *read_val;”.
5.
Run the code: debug-> go free.
6.
Hit the red “stop” button on KD30 (in “free run” mode, KD30 does not respond automatically to
breakpoints).
7.
View the global “y” from the C watch window.
8.
Remove the breakpoint and insert one at the next “y= *read_val;”.
9.
Repeat steps 5–8 until you reach the end of main().
10.
You can view the flash blocks and/or change the variables passed (e.g. size, tag, values), recompile,
and run again to see how the changes affect operation.
AN-DECE-MCU-31-A
February 2002
3