algorithm calculate CRC7 for MMC

Status
Not open for further replies.

derun

Newbie level 4
Joined
Nov 9, 2004
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
40
crc-7

I search program or algorithm calculate CRC7 for MMC.
 

crc 7

Here's some code reference from a past project. CRC initialized at zero.
Code:
WORD addCRC(WORD crc,BYTE value) {
   crc  = (int)(crc >> 8) | (crc << 8);
   crc ^= value;
   crc ^= (int)(crc & 0xff) >> 4;
   crc ^= (crc << 8) << 4;
   crc ^= ((crc & 0xff) << 4) << 1;
	return crc;
}

Some other references I found on the net.
Code:
CRC16:
  crc = 0;
  for(i = 0; i < bits; i++) {
    ix = i / 8;
    mask = 1 << (7-(i & 7));

    xor = (crc & 0x8000) ^ (in[ix] & mask) ? 1 : 0;
    crc <<= 1;
    if(xor != 0) {
      crc ^= 0x1021;
    }
    crc &= 0xffff;
    printf("i %4i  in 0x%02X  ix %2i   mask %3i  crc 0x%04X  xor 0x%04X\n",
      i, in[ix], ix, mask, crc, xor);
  }


CRC7:
  crc = 0;
  for(i = 0; i < bits; i++) {
    ix = i / 8;
    mask = 1 << (7-(i & 7));

    xor = (crc & 0x40) ^ (in[ix] & mask) ? 1 : 0;
    crc <<= 1;
    if(xor != 0) {
      crc ^= 0x9;
    }
    crc &= 0x7f;
    printf("i %2i   ix %i   mask %3i  crc 0x%02X  xor 0x%02X  res 0x%02X\n",
      i, ix, mask, crc, xor, crc*2+1);
  }
 

crc7 code

My algorithm, i used it:
unsigned char CRC7(unsigned char * chr, int cnt) {
int i,a;
unsigned char crc,Data;

crc=0;
for (a=0;a<cnt;a++) {
Data=chr[a];
for (i=0;i<8;i++) {
crc <<= 1;

if ((Data & 0x80)^(crc & 0x80))
crc ^=0x09;
Data <<= 1;
}
}
crc=(crc<<1)|1;
return(crc);
}
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…