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

RE: [ethmac] got my CRC running(mine is not)



Hi,
Thnaks for the suggestions. I am posting my code here.
So if any of you guys can have a look at it and
suggest me something. I'll appriciate that.

Thanks,

Waman.


module rxfcs
(RxClk,Reset,CrcEn,RxDI,CrcOut,CrcBuffer);

input RxClk, Reset, CrcEn;
input [7:0]RxDI;
output CrcOut;
output [31:0] CrcBuffer;
wire [7:0] RxDI;
wire RxClk, Reset, CrcEn;
reg CrcOut;
reg [31:0] CrcBuffer;


  // polynomial: (0 1 2 4 5 7 8 10 11 12 16 22 23 26
32)
  // data width: 8
  // convention: the first serial data bit is D[7]
  function [31:0] CountCrc;

    input [7:0] Data;
    input [31:0] CRC;

    reg [7:0] D;
    reg [31:0] C;
    reg [31:0] NewCRC;

  begin

    D = Data;
    C = CRC;

    NewCRC[0] = D[6] ^ D[0] ^ C[24] ^ C[30];
    NewCRC[1] = D[7] ^ D[6] ^ D[1] ^ D[0] ^ C[24] ^
C[25] ^ C[30] ^ 
                C[31];
    NewCRC[2] = D[7] ^ D[6] ^ D[2] ^ D[1] ^ D[0] ^
C[24] ^ C[25] ^ 
                C[26] ^ C[30] ^ C[31];
    NewCRC[3] = D[7] ^ D[3] ^ D[2] ^ D[1] ^ C[25] ^
C[26] ^ C[27] ^ 
                C[31];
    NewCRC[4] = D[6] ^ D[4] ^ D[3] ^ D[2] ^ D[0] ^
C[24] ^ C[26] ^ 
                C[27] ^ C[28] ^ C[30];
    NewCRC[5] = D[7] ^ D[6] ^ D[5] ^ D[4] ^ D[3] ^
D[1] ^ D[0] ^ C[24] ^ 
                C[25] ^ C[27] ^ C[28] ^ C[29] ^ C[30]
^ C[31];
    NewCRC[6] = D[7] ^ D[6] ^ D[5] ^ D[4] ^ D[2] ^
D[1] ^ C[25] ^ C[26] ^ 
                C[28] ^ C[29] ^ C[30] ^ C[31];
    NewCRC[7] = D[7] ^ D[5] ^ D[3] ^ D[2] ^ D[0] ^
C[24] ^ C[26] ^ 
                C[27] ^ C[29] ^ C[31];
    NewCRC[8] = D[4] ^ D[3] ^ D[1] ^ D[0] ^ C[0] ^
C[24] ^ C[25] ^ 
                C[27] ^ C[28];
    NewCRC[9] = D[5] ^ D[4] ^ D[2] ^ D[1] ^ C[1] ^
C[25] ^ C[26] ^ 
                C[28] ^ C[29];
    NewCRC[10] = D[5] ^ D[3] ^ D[2] ^ D[0] ^ C[2] ^
C[24] ^ C[26] ^ 
                 C[27] ^ C[29];
    NewCRC[11] = D[4] ^ D[3] ^ D[1] ^ D[0] ^ C[3] ^
C[24] ^ C[25] ^ 
                 C[27] ^ C[28];
    NewCRC[12] = D[6] ^ D[5] ^ D[4] ^ D[2] ^ D[1] ^
D[0] ^ C[4] ^ C[24] ^ 
                 C[25] ^ C[26] ^ C[28] ^ C[29] ^
C[30];
    NewCRC[13] = D[7] ^ D[6] ^ D[5] ^ D[3] ^ D[2] ^
D[1] ^ C[5] ^ C[25] ^ 
                 C[26] ^ C[27] ^ C[29] ^ C[30] ^
C[31];
    NewCRC[14] = D[7] ^ D[6] ^ D[4] ^ D[3] ^ D[2] ^
C[6] ^ C[26] ^ C[27] ^ 
                 C[28] ^ C[30] ^ C[31];
    NewCRC[15] = D[7] ^ D[5] ^ D[4] ^ D[3] ^ C[7] ^
C[27] ^ C[28] ^ 
                 C[29] ^ C[31];
    NewCRC[16] = D[5] ^ D[4] ^ D[0] ^ C[8] ^ C[24] ^
C[28] ^ C[29];
    NewCRC[17] = D[6] ^ D[5] ^ D[1] ^ C[9] ^ C[25] ^
C[29] ^ C[30];
    NewCRC[18] = D[7] ^ D[6] ^ D[2] ^ C[10] ^ C[26] ^
C[30] ^ C[31];
    NewCRC[19] = D[7] ^ D[3] ^ C[11] ^ C[27] ^ C[31];
    NewCRC[20] = D[4] ^ C[12] ^ C[28];
    NewCRC[21] = D[5] ^ C[13] ^ C[29];
    NewCRC[22] = D[0] ^ C[14] ^ C[24];
    NewCRC[23] = D[6] ^ D[1] ^ D[0] ^ C[15] ^ C[24] ^
C[25] ^ C[30];
    NewCRC[24] = D[7] ^ D[2] ^ D[1] ^ C[16] ^ C[25] ^
C[26] ^ C[31];
    NewCRC[25] = D[3] ^ D[2] ^ C[17] ^ C[26] ^ C[27];
    NewCRC[26] = D[6] ^ D[4] ^ D[3] ^ D[0] ^ C[18] ^
C[24] ^ C[27] ^ 
                 C[28] ^ C[30];
    NewCRC[27] = D[7] ^ D[5] ^ D[4] ^ D[1] ^ C[19] ^
C[25] ^ C[28] ^ 
                 C[29] ^ C[31];
    NewCRC[28] = D[6] ^ D[5] ^ D[2] ^ C[20] ^ C[26] ^
C[29] ^ C[30];
    NewCRC[29] = D[7] ^ D[6] ^ D[3] ^ C[21] ^ C[27] ^
C[30] ^ C[31];
    NewCRC[30] = D[7] ^ D[4] ^ C[22] ^ C[28] ^ C[31];
    NewCRC[31] = D[5] ^ C[23] ^ C[29];

   CountCrc = NewCRC;

  end

  endfunction

always @(posedge RxClk or negedge Reset)
            begin
        if (CrcBuffer == 32'h c704dd7b) //magic number
          begin
          CrcOut <= 1'b1;
          end
        else
          begin
          CrcOut <= 1'b0;
          end 
       end       
     //end

always @(posedge RxClk or negedge Reset)
      begin
        if(!Reset)
          begin
          CrcBuffer <= 32'h FFFFFFFF;
          end
        else
        begin  
			  if(CrcEn==1'b1)
           begin
           CrcBuffer <= CountCrc (RxDI,CrcBuffer);
           end   
         else 
            begin	
            CrcBuffer <= 32'h FFFFFFFF;
            end
        end 
      end


endmodule



--- Illan Glasner <iglasner@zumanetworks.com> wrote:
> Hi,
> 
>    Most likely you either append the crc wrongly or
> the data bit are put wrongly in the formula.
> 
> a short suggestion, look on the 4 bit file I Email
> and see how I append the data and the crc to the
> equation and how the equation compare to the one
> given in asics site.
> 
> that see that your do similar of course with 8 bit
> and equation different BUT the order should be the
> same.
> 
> I enclose an example for the 32 bit which I did the
> same as I did the 4 bit, again the first run is to
> generate the crc than I took the crc value put it as
> data and than in the second run where you need to
> use +define+second_run you will get the magic
> number. this should help you get on the right track.
> 
> have a nice day
> 
>    Illan
> 
> 
> -----Original Message-----
> From: waman mainkar [mailto:waman_m@yahoo.com]
> Sent: Monday, May 06, 2002 5:52 PM
> To: ethmac@opencores.org
> Subject: Re: [ethmac] got my CRC running(mine is
> not)
> 
> 
> HI,
> i have got the equation from www.easic.be for 8 bit
> data path and CRC-32....
> and then for this function i am providing input 8
> bit
> data and a updating value of buffer like:
> 
> crcbuffer = countcrc [this is function]
> (RxDI[data],crcbuffer);
> 
> and then on the positive edge of clk i am comparing
> it
> with the magic no. and if it is equal then CRCOK in
> 1....
> 
> i believe this logic is correct. but, i am not able
> to
> test it. so can anybody help me. i'll really
> appriciate that.
> 
> waiting for replies.
> 
> Thanks,
> 
> Waman.
> 
> 
> 
> 
> --- "Christian R. Brecht" <Brecht@cbedv.com> wrote:
> > Hi all!
> > 
> > Thank you very much for your help! Finally I have
> a
> > running version of my
> > CRC (which in fact was never wrong, I just used it
> > the wrong way )-:  )...
> > 
> > You've bee a big help! Thx!
> > 
> > Christian
> > 
> > 
> >
>
-------------------------------------------------------
> > Christian R. Brecht
> > Brecht@cbEDV.com
> >
>
-------------------------------------------------------
> > 
> > ----- Original Message -----
> > From: "Illan Glasner" <iglasner@zumanetworks.com>
> > To: <ethmac@opencores.org>
> > Sent: Monday, May 06, 2002 7:47 PM
> > Subject: FW: [ethmac] CRC question
> > 
> > 
> > 
> > Hi,
> > 
> >        From some reason my replay Email didn;t
> > appear till now so I will
> > re-send it in hope this time it will pass the
> > barrier.
> > 
> > have a nice day
> > 
> >    Illan
> > 
> > -----Original Message-----
> > From: Illan Glasner
> > Sent: Friday, May 03, 2002 9:59 AM
> > To: 'ethmac@opencores.org'
> > Subject: RE: [ethmac] CRC question
> > 
> > 
> > 
> > Hi,
> > 
> >       Hope the following files will help you and
> any
> > other who might be
> > struggling with this crc as well as anyone who use
> > crc RTL code in his
> > behavoral instead of using task.
> > 
> > crc4.v :
> > basicly the first run you simple compile it and it
> > calculate crc for few
> > data.
> > 
> > than I took this data which have the crc value and
> > push it back and got the
> > magic number.
> > 
> > for the second run you need to use th
> > +define+second_run
> > 
> > of course the second run 8 extra data are
> determine
> > from the first run so it
> > is not "general" solution but it should help yu
> see
> > why you don;t get the
> > right value in your crc
> > 
> > crc_calc_task.v
> > to make your simulation more effective I also
> added
> > a task that you should
> > use in any behavioral test bench which will
> > calcualte the crc in zero time.
> > 
> > if you are intrested in how the crc equation are
> > constract this task is the
> > starting point as it have the basic single bit
> > formula and than you can
> > expand it for using it for any width as well as
> > using De-Morgan rules you
> > can get the equation for any width. (or simple go
> to
> > asics site and get it
> > done more quickly).
> > 
> > have a nice day
> > 
> >    Illan
> > 
> > 
> > 
> > -----Original Message-----
> > From: Christian R. Brecht
> [mailto:Brecht@cbedv.com]
> > Sent: Friday, May 03, 2002 3:42 AM
> > To: ethmac@opencores.org
> > Subject: [ethmac] CRC question
> > 
> > 
> > 
> > Dear All!
> > 
> > I know this is not an ethmac question but for you
> > this will be an easy one:
> > I am working on my diploma work right now and for
> > some reasons I cannot use
> > your ethernetcore as we need some special things
> > implemented. But one thing
> > is similar: the CRC in general.
> > I guess I understood the CRC itself but for me it
> > seems the CRC-32 for
> > ethernet needs some weird extras like inverting
> the
> > 32 bits and reflecting
> > them as well. I will have to initialize the
> register
> > with "F"s as the first
> > step.
> > 
> > Q: After all, usually I have to put zeros into the
> > CRCC. Do I have to put 0s
> > into this CRC-32C as well, or do I need to put Fs
> to
> > get it run (I need
> > nibbles for input). The problem is I have two
> > "testpatterns", one does the
> > job (60 Bytes of zeros work with mine) the other
> > doesn't. I used the CRC-32
> 
=== message truncated ===

> ATTACHMENT part 2 application/octet-stream
name=crc32.v



__________________________________________________
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com
--
To unsubscribe from ethmac mailing list please visit http://www.opencores.org/mailinglists.shtml