Checksum calculation in AN2399

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Checksum calculation in AN2399

1,519 Views
Magnus
Contributor I
Hi!
 
In AN2399 it says that the checksum is calculated as the 1's complement of the sum of flash memory from 0xF600 to 0xF7FD, but in the example firmware code (last row in icp-kbd.asm in AN2399SW.ZIP) I can see it is calculated as the two's complement. I have verified this by using the CHECKSUM_ADD method in the .prm file and calculated it myself.
 
This is what I added in the default.prm file:
 
CHECKSUM
    CHECKSUM_ENTRY
        METHOD_ADD SIZE 1
        OF      READ_ONLY   0xF600 TO 0xF7FD
        INTO    READ_ONLY   0xF7FE SIZE 2
        UNDEFINED 0xFF
    END
END
 
Then I just did a one's complement of the sum and got the value 0x0994.
But in the last row in source file icp-kbd.asm it says:
 
dc.w $0995     ;;ICP_Flag (Checksum) 
 
And also, in JB16_ICP.ASM in AN2399 it is just calculated as the sum with no complement.
 
What method is the correct one to use? 1's complement, 2's complement or just the sum?
 
 
Labels (1)
0 Kudos
1 Reply

308 Views
Encoder
Contributor I
Usually for checksum purpose you must add the simple sum of your data list with the known complemented sum to achieve a fixed value, i.e. $FFFF (not $0000).
 
This may well be one's complement
 
Encoder
0 Kudos