Здравствуйте! Требуется помощь в нахождениир контрольной суммы программного кода и прошивки. Программа:
#include "dz1612/dz1612.h"
#include <stdio.h>
#define flashStart 0xFA00
#define flashEnd 0xFDFF
#define flashChecksum 0x1080
int tap_count = 0;
int d1, d2, d3, d4;
int i;
u_int8_t mas[5]={0x5A, 0x6B, 0x7C, 0x8D, 0x9E};
void funct(u_int8_t *mas) {
wdog_reassure();
if ( P1IN & 0x40 ) {
if( d3 == 0 ) {
i = i + 1;
if( i > 4 )
i = 4;
d3 = 1;
}
}
else {
d3 = 0;
}
if ( P1IN & 0x80 ) {
if( d4 == 0 ) {
i = i - 1;
if( i < 0 )
i = 0;
d4 = 1;
}
}
else
{
d4 = 0;
}
if ( P1IN & 0x10 ) {
if( d1 == 0 ) {
tap_count = 1;
d1 = 1;
}
}
else
{
d1 = 0;
}
if ( P1IN & 0x20 ) {
if( d2 == 0 ) {
tap_count = 0;
d2 = 1;
}
}
else {
d2 = 0;
}
if( (tap_count&1) == 1 ) {
P1OUT &= 0xF0;
P1OUT |=( ( mas[i] >> 4 ) & 0x0F );
}
else
{
P1OUT &= 0xF0;
P1OUT |=(mas[i] & 0x0F );
}
}
int main()
{
init_pins();
init_clock();
init_systimer(512);
stdio_init(9600);
P1SEL =0;
P1DIR =15;
d1 = d2 = 0;
d3 = d4 = 0;
i = 0;
while (1)
{
funct(mas);
}
halt(11);
return 0;
}
Есть пример нахождения контрольной суммы:
#include <msp430x16x.h>
#define flashStart 0xFA00
#define flashEnd 0xFDFF
#define flashChecksum 0x1080
int verifyFlash(void);
void storeChecksum(void);
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
FCTL2 = FWKEY + FSSEL0 + FN0; // MCLK/2 for flash timing generator
// .
// . Flash writes
// .
storeChecksum();
// Later in the program....
if (!verifyFlash())
{
// Handle the error
}
_BIS_SR(LPM3_bits+GIE); // Sleep until port interrupt
}
int verifyFlash(void)
{
unsigned int i, checksum=0, storedChecksum;
for (i=0;i<0x0200;i++) // Calculate checksum
checksum += ((unsigned int *)flashStart)[i];
storedChecksum = *(unsigned int *)flashChecksum; //Pull stored val from flash
if (checksum==storedChecksum) // Compare and return the result
return(1);
else
return(0);
}
void storeChecksum(void)
{
unsigned int i, checksum=0,*pFlashData;
for (i=0;i<0x0200;i++) // Calculate checksum
checksum += ((unsigned int *)flashStart)[i];
// Erase checksum storage location
pFlashData = (unsigned int *) flashChecksum; // Reset ptr to start of block
FCTL3 = FWKEY; // Unlock flash
FCTL1 = FWKEY + ERASE; // Set Erase bit
*pFlashData = 0x0000; // Dummy write to erase
// Store checksum
FCTL1 = FWKEY+WRT; // Enable flash write
*pFlashData = checksum; // Write checksum to flash
FCTL3 = FWKEY + LOCK; // Lock flash
}
Необходимо их как-то совместить и сравнить контрольную сумму программы и прошивки.)))))