[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [usb] crc algorithm



On 20 Feb 2002 at 16:16, Bo wrote:

> Hi Tambunan,
>     For my understanding, it really doesn't
> matter what pattern you should fill during the
> initialization. As far as you use the same
> pattern on both encode and decode part, it should
> come out the same result. You can check it use
> math calculation, C or even verilog.

Hi Bo... I've checked the CRC calculation when CRC
register initial value filled with 0 and 1 with some examples
and I found that the result are different.
I follow the rules from USB 1.1 specification and here is
the algorithm for 5-bit CRC (CMIIW...):

// from 2nd paragraph section 8.3.5
integer         i;
reg [4..0]      crc5out, crc5poly;
reg [11..0]    data;    

crc5out = 'b11111; // or crc5out = 'b00000;
crc5poly = 'b00101;
for (i=0; i<12; i=i+1) begin
    msb = crc5out[4];
    crc5out = crc5out << 1;
    if ( (msb XOR data[i]) = 1) then begin
        crc5out = crc5out XOR crc5poly;
    end
end

// from 3rd paragraph section 8.3.5 for CRC generator
crc5out = ~crc5out;


There are some examples in "CRC in USB" whitepaper
I used to check above algorithm.
 
- setup addr 15 endp e
  data = 'b10101000111
  crc5out = 'b10111     ; for initial = 'b11111
  crc5out = 'b00000     ; for initial = 'b00000

- out addr 3a endp a
  data = 'b01011100101
  crc5out = 'b11100     ; for initial = 'b11111
  crc5out = 'b10100     ; for initial = 'b00000

- in addr 70 endp 4
  data = 'b00001110010
  crc5out = 'b01110     ; for initial = 'b11111
  crc5out = 'b11001     ; for initial = 'b00000

Also have you check Mr. Rudi's core ?
He also prefills crc5 and crc16 register with '1'
(check usbf_pa.v and usb_pd.v).
Btw... there is also an online document, which
is a thesis of Mr. Myilone Anandarajah, that
uses '0' to prefill CRC initial value.
Any comment for this :-)....

Best regard,


RE Tambunan
--
To unsubscribe from usb mailing list please visit http://www.opencores.org/mailinglists.shtml