English
Language : 

PIC32MX795F512L-80IPT Datasheet, PDF (46/68 Pages) Microchip Technology – PIC32 Flash Programming Specification
PIC32
17.3 Algorithm
An example of a high-level algorithm for calculating the
checksum for a PIC32 device is illustrated in Figure 17-1
to demonstrate one method to derive a checksum. This
is merely an example of how the actual calculations can
be accomplished, the method that is ultimately used is
left to the discretion of the software developer.
As stated earlier, the PIC32 checksum is calculated as
the 32-bit summation of all bytes (8-bit quantities) in
program Flash, boot Flash (except device
Configuration Words), the Device ID register with
applicable mask, and the device Configuration Words
with applicable masks.
Next, the 2’s complement of the summation is
calculated. This final 32-bit number is presented as the
checksum.
The mask values of the device Configuration and
Device ID registers are derived as described in the
previous section, Section 17.2 “Mask Values”.
Another noteworthy point is that the last four 32-bit
quantities in boot Flash are the device Configuration
registers. An arithmetic AND operation of these device
Configuration register values is performed with the
appropriate mask value, before adding their bytes to
the checksum.
Similarly, an arithmetic AND operation of the Device ID
register is performed with the appropriate mask value,
before adding its bytes to the checksum.
FIGURE 17-1:
HIGH-LEVEL ALGORITHM FOR CHECKSUM CALCULATION
pic32_checksum
Read Program Flash, Boot Flash (including DEVCFG
registers) and DEVID register in tempBuffer
Apply DEVCFG and DEVID masks to appropriate
locations in tempBuffer
tmpChecksum (32-bit quantity) = 0
Finish processing all
No
bytes (8-bit quantities) in
tempBuffer?
Yes
Checksum (32-bit quantity) = 2’s complement
of tmpChecksum
tmpChecksum = tempChecksum + Current Byte Value
(8-bit quantity) in tmpBuffer
Done
DS61145L-page 46
 2007-2013 Microchip Technology Inc.