Nxp Semiconductors UM10237 User Manual

Page of 792
UM10237_2
© NXP B.V. 2008. All rights reserved.
User manual
Rev. 02 — 19 December 2008 
279 of 792
NXP Semiconductors
UM10237
Chapter 11: LPC24XX Ethernet
int crc_calc(char frame_no_fcs[], int frame_len) {
int
i;
// iterator
int
j;
// another iterator
char byte; // current byte
int
crc; // CRC result
int q0, q1, q2, q3;
// temporary variables
crc = 0xFFFFFFFF;
for (i = 0; i < frame_len; i++) {
byte = *frame_no_fcs++;
for (j = 0; j < 2; j++) {
if (((crc >> 28) ^ (byte >> 3)) & 0x00000001) {
q3 = 0x04C11DB7;
} else {
q3 = 0x00000000;
}
if (((crc >> 29) ^ (byte >> 2)) & 0x00000001) {
q2 = 0x09823B6E;
} else {
q2 = 0x00000000;
}
if (((crc >> 30) ^ (byte >> 1)) & 0x00000001) {
q1 = 0x130476DC;
} else {
q1 = 0x00000000;
}
if (((crc >> 31) ^ (byte >> 0)) & 0x00000001) {
q0 = 0x2608EDB8;
} else {
q0 = 0x00000000;
}
crc = (crc << 4) ^ q3 ^ q2 ^ q1 ^ q0;
byte >>= 4;
}
}
return crc;
}
For FCS calculation, this function is passed a pointer to the first byte of the frame and the 
length of the frame without the FCS.
For hash filtering, this function is passed a pointer to the destination address part of the 
frame and the CRC is only calculated on the 6 address bytes. The hash filter uses bits 
[28:23] for indexing the 64 bits { HashFilterH, HashFilterL } vector. If the corresponding bit 
is set the packet is passed, otherwise it is rejected by the hash filter.
For obtaining the destination and source address hash CRCs, this function calculates first 
both the 32 bit CRCs, then the nine most significant bits from each 32 bit CRC are 
extracted, concatenated, and written in every StatusHashCRC word of every fragment 
status.