AN2504 Freescale Semiconductor / Motorola, AN2504 Datasheet - Page 13

no-image

AN2504

Manufacturer Part Number
AN2504
Description
On-Chip FLASH Programming API for CodeWarrior Software
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
Techniques
ReadByte
Virtual Registers
MOTOROLA
On-Chip FLASH Programming API for CodeWarrior Software
As mentioned above, the routine ReadByte enters an infinite loop if no byte is
received. There is a way to make ReadByte exit the infinite loop. The procedure
is as follows:
This technique has some disadvantages, including the time overhead needed
to verify the flag on each timer ISR.
Virtual registers limit the available RAM. However these registers are only used
when FLASH-programming API is called. This means that most of the time
these registers are only wasting RAM space. A work-around for this problem
can be achieved as follows:
1. Clear a flag before calling ReadByte (a flag indicating the successful
2. Set up the timer to interrupt at a given time (the time to wait before
3. Call ReadByte()
4. If a byte is received, set the flag previously cleared.
5. If a byte is not received, the Timer ISR will execute. Inside the Timer ISR
1. Define global variables through all RAM space (not reserving the virtual
2. Define a section in FLASH memory 64 bytes long called
3. When the need of using the FLASH-programming API arises, before
Freescale Semiconductor, Inc.
For More Information On This Product,
reception of a byte.
exiting ReadByte).
verify the state of the flag. If it is cleared (no byte has been received),
two actions can be taken:
a.
b.
registers bytes).
BACKUP_RAM. In this section no code will be allocated.
doing anything do the following:
a.
b.
c.
d.
e.
f.
Change manually the PC stored in the stack (so when the ISR
returns, it returns out of function ReadByte).
Cause a software reset.
Push into the stack (this must be done in assembly) the first four
bytes of the virtual registers (from RAM+0x08 to RAM+0x0B).
Call API function ErasePage() to erase the section BACKUP_RAM.
Call API function ProgramRange() to backup the DATA virtual
register (from RAM+0x0C to RAM+0x4C).
Use the FLASH-programming API for whatever needed.
Before ending call API function ReadFlash() to restore the data from
BACKUP_RAM to RAM.
Finally, pop the first four bytes of the virtual registers (from
RAM+0x08 to RAM+0x0B).
Go to: www.freescale.com
Techniques
AN2504/D
13

Related parts for AN2504