source: ReferenceDesigns/w3_802.11/sysgen/wlan_phy_tx_pmd/util/CRC_table_gen.m

Last change on this file was 2088, checked in by murphpo, 11 years ago

Initial commit of Sysgen cores

File size: 553 bytes
Line 
1function CRC_Table = CRC_table_gen(CRCPolynomial, bitLen)
2%Calculates table of polynomial remainders for CRC computation
3%Based on example code at http://www.netrino.com/Embedded-Systems/How-To/CRC-Calculation-C-Code
4
5if(bitLen > 32 | bitLen < 1)
6    error('bitLen must be in [1,32]');
7end
8
9crc_accum = 0;
10
11for n=0:255
12    crc_accum = bitshift(n,(bitLen-8),bitLen);
13
14    for m=0:7
15        x = bitshift(crc_accum, 1, bitLen);
16        if(crc_accum >= 2^(bitLen-1))
17            crc_accum = bitxor(x, CRCPolynomial);
18        else
19            crc_accum = x;
20        end
21    end
22
23    CRC_Table(n+1) = crc_accum;
24end
Note: See TracBrowser for help on using the repository browser.