2005-02-02 14:25:30 +00:00
|
|
|
static __attribute__((used)) char* rcsid = "$CVSHeader$";
|
|
|
|
/*
|
|
|
|
*
|
2006-09-15 14:55:39 +00:00
|
|
|
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
|
2005-02-02 14:25:30 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libemile.h"
|
|
|
|
|
2006-10-15 16:49:31 +00:00
|
|
|
unsigned short emile_checksum(unsigned char *addr, unsigned int length)
|
2005-02-02 14:25:30 +00:00
|
|
|
{
|
|
|
|
int j;
|
|
|
|
unsigned short sum = 0;
|
|
|
|
|
|
|
|
for (j = 0; j < length; j++)
|
|
|
|
{
|
|
|
|
sum += addr[j];
|
|
|
|
sum = (sum << 1) | (sum >> 15);
|
|
|
|
}
|
|
|
|
if (sum == 0)
|
|
|
|
sum = 0xFFFF;
|
|
|
|
|
|
|
|
return sum;
|
|
|
|
}
|
2006-10-15 16:49:31 +00:00
|
|
|
|
|
|
|
unsigned short emile_checksum_ATA(unsigned char *addr, unsigned int length)
|
2005-02-02 14:25:30 +00:00
|
|
|
{
|
|
|
|
unsigned int sum = 0;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
{
|
|
|
|
sum += addr[i];
|
|
|
|
sum <<= 1;
|
|
|
|
sum |= (sum & 0x00010000) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sum;
|
|
|
|
}
|