Rule[from datasheet of nxp lpc21xx]:
The reserved ARM interrupt vector location(0x0000 0014) should contain the 2's complement of the check-sum of the remaining interrupt vectors. This causes the checksum of all of the vectors together to be 0.
Polynomial:
V0 + V1 + V2 + V3 + V4 + Sum + V6 + V7 = 0
Code:
void CCalc_nxp_checksumDlg::OnCalc()
{
// chose bin file
CString sFilename;
CFileDialog dlg(TRUE); // open with TRUE, save with FALSE
if(dlg.DoModal() == IDOK) {
sFilename = dlg.GetPathName(); // full path
}
// read 8 interrupt vectors
CFile file;
if(!file.Open(sFilename, CFile::modeRead)) { return; }
int data[8];
BYTE str[4];
for(int i=0; i<8; i++) {
file.Read(str, 4);
data = *(int *)str;
}
file.Close();
// calc checksum
int sum = 0;
for(i=0; i<8; i++) {
if(i != 5) { sum += data; }
}
sum = 0 - sum;
BYTE checksum[4];
int *sum_ptr = ∑
BYTE *ptr = (BYTE *)sum_ptr;
for(i=0; i<4; i++) {
checksum = *ptr;
ptr++;
}
CString sResult;
sResult.Format("%X %X %X %X", checksum[0], checksum[1], checksum[2], checksum[3]);
GetDlgItem(IDC_EDIT1)->SetWindowText(sResult);
}
Conclusion:
In current most IDE, the interrupt vector checksum can be calculated. But for the other old IDE, we have to calculate the checksum by ourselves.
Written by Allen in Shenzhen
2010.12.04
allen_zhan_752827529 2010-12-4 20:38
用户1277994 2010-12-4 20:02