Hardware Reference
In-Depth Information
while(!(FSTAT&CCIF)); // wait for the last command to complete
return 0;
}
Example 14.9
Write a function that performs the erase-and-verify command to the flash memory. The
index register contains a word-aligned address to the flash block to be erased and verified.
Solution: The assembly routine that performs the erase-and-verify command is as follows:
feraseverify
brclr FSTAT,CBEIF,cantE
; command buffer not empty
std
0,x
; write any data to flash sector address
movb
#EraseVerify,FCMD
; write the command
movb
#CBEIF,FSTAT
; launch the erase and verify command
brclr
FSTAT,ACCERR+PVIOL,EVNoErr
ldab
#1
; return error code 1
rts
EVNoErr
brclr
FSTAT,CCIF,EVNoErr
; wait until command is done
brset
FSTAT,BLANK,EVFOK
; successful erase and verify?
cantE
ldab
#1
; flash is not blank
rts
EVFOK
clrb
; erase and verify OK
rts
The C function that performs the erase-and-verify operation is as follows:
int feraseverify(int *ptr)
{
if(!(FSTAT & CBEIF))
return 1;
// command buffer not empty, returns
*ptr 5 0x00;
// write data to flash sector address
FCMD 5 EraseVerify;
// write erase verify command
FSTAT 5 CBEIF;
// launch the command
if(FSTAT&(ACCERR | PVIOL))
return 1;
// errors have occurred
while(!(FSTAT & CCIF)); // wait until command is completed
if(FSTAT & BLANK)
return 0;
// command completed successfully
else
return 1;
}
14.6 The On-Chip EEPROM Memory
An HCS12 device may have 1, 2, or 4 kB of on-chip EEPROM to store nonvolatile data or
programs to be executed out of reset. The EEPROM is organized as an array of 2-byte words. For
example, the 4-kB EEPROM is organized as 2048 rows of 2 bytes (1 word). The EEPROM block's
erase sector size is two rows or two words.
 
Search WWH ::




Custom Search