data/full_repos/permissive/19591557/modules/spinnaker_link/spio_spinnaker_link_packet_con.v
 line:152: before: ";"
data/verilator_xmls/5c78a006-ab21-4b52-bedc-1ad485d15de0.xml
module spio_spinnaker_link_packet_con(
    input clk,
    input reset,
    input fifo_full,
    input  [6:0] code2of7,
    output reg [71:0] packet,
    output reg ack,
    output reg fifo_write
    );

reg [6:0] old_code2of7;
reg [3:0] nibble;
reg [4:0] symbol_count;
reg       eop;
reg       oob;
reg       tom;
reg       long_packet;

reg [2:0] state;

initial
 begin
  state = 0;
  old_code2of7 = 0;
  ack = 0;
  fifo_write = 0;
  packet = 0;
  symbol_count = 0;
  long_packet = 0;
 end

always @(posedge clk or posedge reset)
 if(reset == 1)
  begin
   state <= 0;
   old_code2of7 <= 0;
   ack <= 0;
   fifo_write <= 0;
   packet <= 0;
   symbol_count <= 0;
   long_packet <= 0;
  end
 else 
  case(state)
   0, 1 : begin                                                      
           state <= state +1;  ack <= 0; old_code2of7 <= 0;
          end  
   2 : begin
        state <= 3; ack <= ~ack; old_code2of7 <= code2of7;
       end  
   3 : begin
        if(eop == 1)
         begin
          if(((symbol_count == 10) && (long_packet == 0)) ||
             ((symbol_count == 18) && (long_packet == 1))) 
           begin
            if(fifo_full != 1)
             begin 
              ack <= ~ack; old_code2of7 <= code2of7;
              symbol_count <= 0; fifo_write <= 1;
             end
           end                                                                                         
          else
           begin
            ack <= ~ack; old_code2of7 <= code2of7;
            symbol_count <= 0; fifo_write <= 0; 
           end
         end
        else if(oob == 1)
         begin
          ack <= ~ack; old_code2of7 <= code2of7;
          symbol_count <= 0; fifo_write <= 0;
          state <= 4; 
         end
        else if(tom == 1)
         begin 
          ack <= ~ack; old_code2of7 <= code2of7;
          symbol_count <= symbol_count +1; fifo_write <= 0;
          packet <= packet_order(symbol_count, nibble, packet);
          if(symbol_count == 0) long_packet <= nibble[1];
          if(((symbol_count >= 10) && (long_packet == 0)) ||
            (symbol_count >= 18))  state <= 4;                        
         end
        else fifo_write <= 0;
       end
   4 : begin
        if(eop == 1)
         begin
          ack <= ~ack; old_code2of7 <= code2of7;
          symbol_count <= 0; fifo_write <= 0;
          state <= 3;
         end
        else if(tom == 1) 
         begin 
          ack <= ~ack; old_code2of7 <= code2of7;
          symbol_count <= 0; fifo_write <= 0;
         end
       end

  endcase




always @(code2of7 or old_code2of7)
   begin
    case(code2of7 ^ old_code2of7)
     7'b0010001 : begin nibble = 0;   eop = 0; oob = 0; tom = 1; end
     7'b0010010 : begin nibble = 1;   eop = 0; oob = 0; tom = 1; end
     7'b0010100 : begin nibble = 2;   eop = 0; oob = 0; tom = 1; end
     7'b0011000 : begin nibble = 3;   eop = 0; oob = 0; tom = 1; end
     7'b0100001 : begin nibble = 4;   eop = 0; oob = 0; tom = 1; end
     7'b0100010 : begin nibble = 5;   eop = 0; oob = 0; tom = 1; end
     7'b0100100 : begin nibble = 6;   eop = 0; oob = 0; tom = 1; end
     7'b0101000 : begin nibble = 7;   eop = 0; oob = 0; tom = 1; end
     7'b1000001 : begin nibble = 8;   eop = 0; oob = 0; tom = 1; end
     7'b1000010 : begin nibble = 9;   eop = 0; oob = 0; tom = 1; end
     7'b1000100 : begin nibble = 10;  eop = 0; oob = 0; tom = 1; end
     7'b1001000 : begin nibble = 11;  eop = 0; oob = 0; tom = 1; end
     7'b0000011 : begin nibble = 12;  eop = 0; oob = 0; tom = 1; end
     7'b0000110 : begin nibble = 13;  eop = 0; oob = 0; tom = 1; end
     7'b0001100 : begin nibble = 14;  eop = 0; oob = 0; tom = 1; end
     7'b0001001 : begin nibble = 15;  eop = 0; oob = 0; tom = 1; end
     7'b1100000 : begin nibble = 4'hx;   eop = 1; oob = 0; tom = 1; end
     0, 1, 2, 4,
     8, 16, 32,
     64         : begin nibble = 4'hx;  eop = 0; oob = 0; tom = 0; end
     default    : begin nibble = 4'hx;  eop = 0; oob = 1; tom = 1; end
    endcase
   end    




function  [71:0] packet_order ;
  input   [4:0]  symbol_count;
  input   [3:0]  nibble;
  input   [71:0] packet;
  begin
   if(symbol_count > 9)
    packet_order = {nibble, packet[71:44], packet[39:0]};
   else
    packet_order = {packet[71:40], nibble, packet[39:4]};
 end
endfunction;

endmodule
module spio_spinnaker_link_packet_con(
    input clk,
    input reset,
    input fifo_full,
    input  [6:0] code2of7,
    output reg [71:0] packet,
    output reg ack,
    output reg fifo_write
    );


reg [6:0] old_code2of7;
reg [3:0] nibble;
reg [4:0] symbol_count;
reg       eop;
reg       oob;
reg       tom;
reg       long_packet;

reg [2:0] state;

initial
 begin
  state = 0;
  old_code2of7 = 0;
  ack = 0;
  fifo_write = 0;
  packet = 0;
  symbol_count = 0;
  long_packet = 0;
 end

always @(posedge clk or posedge reset)
 if(reset == 1)
  begin
   state <= 0;
   old_code2of7 <= 0;
   ack <= 0;
   fifo_write <= 0;
   packet <= 0;
   symbol_count <= 0;
   long_packet <= 0;
  end
 else 
  case(state)
   0, 1 : begin                                                      
           state <= state +1;  ack <= 0; old_code2of7 <= 0;
          end  
   2 : begin
        state <= 3; ack <= ~ack; old_code2of7 <= code2of7;
       end  
   3 : begin
        if(eop == 1)
         begin
          if(((symbol_count == 10) && (long_packet == 0)) ||
             ((symbol_count == 18) && (long_packet == 1))) 
           begin
            if(fifo_full != 1)
             begin 
              ack <= ~ack; old_code2of7 <= code2of7;
              symbol_count <= 0; fifo_write <= 1;
             end
           end                                                                                         
          else
           begin
            ack <= ~ack; old_code2of7 <= code2of7;
            symbol_count <= 0; fifo_write <= 0; 
           end
         end
        else if(oob == 1)
         begin
          ack <= ~ack; old_code2of7 <= code2of7;
          symbol_count <= 0; fifo_write <= 0;
          state <= 4; 
         end
        else if(tom == 1)
         begin 
          ack <= ~ack; old_code2of7 <= code2of7;
          symbol_count <= symbol_count +1; fifo_write <= 0;
          packet <= packet_order(symbol_count, nibble, packet);
          if(symbol_count == 0) long_packet <= nibble[1];
          if(((symbol_count >= 10) && (long_packet == 0)) ||
            (symbol_count >= 18))  state <= 4;                        
         end
        else fifo_write <= 0;
       end
   4 : begin
        if(eop == 1)
         begin
          ack <= ~ack; old_code2of7 <= code2of7;
          symbol_count <= 0; fifo_write <= 0;
          state <= 3;
         end
        else if(tom == 1) 
         begin 
          ack <= ~ack; old_code2of7 <= code2of7;
          symbol_count <= 0; fifo_write <= 0;
         end
       end

  endcase




always @(code2of7 or old_code2of7)
   begin
    case(code2of7 ^ old_code2of7)
     7'b0010001 : begin nibble = 0;   eop = 0; oob = 0; tom = 1; end
     7'b0010010 : begin nibble = 1;   eop = 0; oob = 0; tom = 1; end
     7'b0010100 : begin nibble = 2;   eop = 0; oob = 0; tom = 1; end
     7'b0011000 : begin nibble = 3;   eop = 0; oob = 0; tom = 1; end
     7'b0100001 : begin nibble = 4;   eop = 0; oob = 0; tom = 1; end
     7'b0100010 : begin nibble = 5;   eop = 0; oob = 0; tom = 1; end
     7'b0100100 : begin nibble = 6;   eop = 0; oob = 0; tom = 1; end
     7'b0101000 : begin nibble = 7;   eop = 0; oob = 0; tom = 1; end
     7'b1000001 : begin nibble = 8;   eop = 0; oob = 0; tom = 1; end
     7'b1000010 : begin nibble = 9;   eop = 0; oob = 0; tom = 1; end
     7'b1000100 : begin nibble = 10;  eop = 0; oob = 0; tom = 1; end
     7'b1001000 : begin nibble = 11;  eop = 0; oob = 0; tom = 1; end
     7'b0000011 : begin nibble = 12;  eop = 0; oob = 0; tom = 1; end
     7'b0000110 : begin nibble = 13;  eop = 0; oob = 0; tom = 1; end
     7'b0001100 : begin nibble = 14;  eop = 0; oob = 0; tom = 1; end
     7'b0001001 : begin nibble = 15;  eop = 0; oob = 0; tom = 1; end
     7'b1100000 : begin nibble = 4'hx;   eop = 1; oob = 0; tom = 1; end
     0, 1, 2, 4,
     8, 16, 32,
     64         : begin nibble = 4'hx;  eop = 0; oob = 0; tom = 0; end
     default    : begin nibble = 4'hx;  eop = 0; oob = 1; tom = 1; end
    endcase
   end    




function  [71:0] packet_order ;
  input   [4:0]  symbol_count;
  input   [3:0]  nibble;
  input   [71:0] packet;
  begin
   if(symbol_count > 9)
    packet_order = {nibble, packet[71:44], packet[39:0]};
   else
    packet_order = {packet[71:40], nibble, packet[39:4]};
 end
endfunction;

endmodule