diff --git a/litex/soc/software/libbase/crc16.c b/litex/soc/software/libbase/crc16.c index a1222e861..a14d0ed8f 100644 --- a/litex/soc/software/libbase/crc16.c +++ b/litex/soc/software/libbase/crc16.c @@ -1,5 +1,6 @@ #include +#ifndef SMALL_CRC static const unsigned int crc16_table[256] = { 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, @@ -38,10 +39,23 @@ static const unsigned int crc16_table[256] = { unsigned short crc16(const unsigned char *buffer, int len) { unsigned short crc; - + crc = 0; while(len-- > 0) crc = crc16_table[((crc >> 8) ^ (*buffer++)) & 0xFF] ^ (crc << 8); - + return crc; } +#else +unsigned short crc16(const unsigned char* data_p, int length) { + unsigned char x; + unsigned short crc = 0; + + while (length--){ + x = crc >> 8 ^ *data_p++; + x ^= x>>4; + crc = (crc << 8) ^ ((unsigned short)(x << 12)) ^ ((unsigned short)(x <<5)) ^ ((unsigned short)x); + } + return crc; +} +#endif diff --git a/litex/soc/software/libbase/crc32.c b/litex/soc/software/libbase/crc32.c index 29b9b9944..b8b58a765 100644 --- a/litex/soc/software/libbase/crc32.c +++ b/litex/soc/software/libbase/crc32.c @@ -5,6 +5,7 @@ #include +#ifndef SMALL_CRC static const unsigned int crc_table[256] = { 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L, @@ -67,6 +68,7 @@ static const unsigned int crc_table[256] = { unsigned int crc32(const unsigned char *buffer, unsigned int len) { + return 0; unsigned int crc; crc = 0; crc = crc ^ 0xffffffffL; @@ -79,3 +81,22 @@ unsigned int crc32(const unsigned char *buffer, unsigned int len) } while(--len); return crc ^ 0xffffffffL; } +#else +unsigned int crc32(const unsigned char *message, unsigned int len) { + int i, j; + unsigned int byte, crc, mask; + + i = 0; + crc = 0xFFFFFFFF; + while (i < len) { + byte = message[i]; // Get next byte. + crc = crc ^ byte; + for (j = 7; j >= 0; j--) { // Do eight times. + mask = -(crc & 1); + crc = (crc >> 1) ^ (0xEDB88320 & mask); + } + i = i + 1; + } + return ~crc; +} +#endif