AN2400 Freescale Semiconductor / Motorola, AN2400 Datasheet - Page 35

no-image

AN2400

Manufacturer Part Number
AN2400
Description
HCS12 NVM Guidelines
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
Very Frequently
Updated Variables
EEPROM Protection
MOTOROLA
of these variables matches the specified maximum of write erase cycles of a
sector. This may be done by defining the variable to be of size 4 bytes (e.g. type
‘long’) and ensuring that it is aligned to a sector boundary by correct linking. If
the ‘natural’ size of the variable is less than 4 bytes, the remaining bytes in the
sector are unused, and the variable should be cast to its ‘natural’ size in
expressions to avoid unnecessary computation.
If a data variable must be updated more than the maximum permitted number
of write/erase cycles for a sector of EEPROM, then an alternative approach is
necessary. First, consider that it may be possible to store the variable in RAM
whilst the microcontroller is powered and to update a copy in EEPROM only
when a power-down is imminent. If this is not possible and the variable must be
stored in EEPROM at all times, then it becomes necessary to allocate a number
of separate sectors for the variable. This can be done by creating a circular
buffer in EEPROM, with each element of the buffer corresponding to one or
more EEPROM sectors. A pointer in RAM can be used to store the address of
the most recent data. When the variable is to be updated, the next element of
the buffer is written, the ‘old’ data is erased, and the pointer is updated. In this
way, the maximum number of updates for the variable becomes the maximum
permitted number of write/erase cycles for a sector of EEPROM multiplied by
the number of elements in the circular buffer.
The EEPROM block may be protected against accidental erasure or
programming. EEPROM protection is controlled by an EEPROM Protection
register (EPROT). During the microcontroller reset sequence, the EEPROM
Protection register is loaded from the EEPROM Protection byte, located within
EEPROM. The EEPROM Protection byte is located within the smallest
EEPROM protected area, so protecting EEPROM always protects the
EEPROM protection byte, thus guaranteeing the reset state of EEPROM
protection. The value of the EPROT register determines whether the entire
EEPROM or just subsections are protected from being accidentally erased or
programmed. Software can write to the EPROT register to increase the amount
of protected EEPROM by clearing additional bits in the register. It is possible to
decrease the amount of protected EEPROM by setting bits in the EPROT
register only in special modes.
The EEPROM Protection Register is loaded from the EEPROM memory during
a reset sequence. The erased state of these EEPROM memory bytes is $FF,
which corresponds to EEPROM protection disabled.
EPOPEN
Freescale Semiconductor, Inc.
7
For More Information On This Product,
Figure 22. EEPROM Protection Register (EPROT)
NV6
Go to: www.freescale.com
6
HCS12 NVM Guidelines
NV5
5
NV4
4
EPDIS
3
EP2
2
EP1
1
AN2400/D
EP0
EEPROM
0
35

Related parts for AN2400