data/full_repos/permissive/14432793/rfid-verilog/reader/rfid_reader.v
1: b'%Warning-WIDTH: data/full_repos/permissive/14432793/rfid-verilog/reader/rfid_reader.v:51: Operator ASSIGNW expects 3 bits on the Assign RHS, but Assign RHS\'s VARREF \'M\' generates 2 bits.\n                                                                                        : ... In instance rfid_reader\nassign      miller        = M;\n                          ^\n                ... Use "/* verilator lint_off WIDTH */" and lint_on around source to disable this message.\n%Error: data/full_repos/permissive/14432793/rfid-verilog/reader/rfid_reader.v:80: Cannot find file containing module: \'rfid_reader_packet_rxtx\'\nrfid_reader_packet_rxtx UREADER (\n^~~~~~~~~~~~~~~~~~~~~~~\n        ... Looked in:\n             data/full_repos/permissive/14432793/rfid-verilog/reader,data/full_repos/permissive/14432793/rfid_reader_packet_rxtx\n             data/full_repos/permissive/14432793/rfid-verilog/reader,data/full_repos/permissive/14432793/rfid_reader_packet_rxtx.v\n             data/full_repos/permissive/14432793/rfid-verilog/reader,data/full_repos/permissive/14432793/rfid_reader_packet_rxtx.sv\n             rfid_reader_packet_rxtx\n             rfid_reader_packet_rxtx.v\n             rfid_reader_packet_rxtx.sv\n             obj_dir/rfid_reader_packet_rxtx\n             obj_dir/rfid_reader_packet_rxtx.v\n             obj_dir/rfid_reader_packet_rxtx.sv\n%Error: Exiting due to 1 error(s), 1 warning(s)\n'
module rfid_reader (

                    reset, clk, tag_backscatter, reader_modulation
                    );

input  reset, clk, tag_backscatter;
output reader_modulation;


parameter QUERYREP   = 0;
parameter ACK        = 1;
parameter QUERY      = 2;
parameter QUERYADJ   = 3;
parameter SELECT     = 4;
parameter NACK       = 5;
parameter REQRN      = 6;
parameter READ       = 7;
parameter WRITE      = 8;
parameter KILL       = 9;
parameter LOCK       = 10;
parameter ACCESS     = 11;
parameter BLOCKWRITE = 12;
parameter BLOCKERASE = 13;


parameter DR         = 1'd0;
parameter M          = 2'd0;
parameter TREXT      = 1'd0;
parameter SEL        = 2'd0;
parameter SESSION    = 2'd0;
parameter TARGET     = 1'd0;
parameter Q          = 4'd2;


parameter DELIM      = 16'd15000;
parameter PW         = 16'd1000;
parameter TARI       = 16'd6250;
parameter RTCAL      = 16'd18750;
parameter TRCAL      = 16'd25000;

wire [2:0]  miller;
assign      miller        = M;
wire        trext;
assign      trext         = TREXT;
wire        divide_ratio;
assign      divide_ratio  = DR;
wire [15:0] tari_ns;
assign      tari_ns       = TARI;
wire [15:0] trcal_ns;
assign      trcal_ns      = TRCAL;

wire [2:0] q_adj;
assign     q_adj    = 0;
wire [3:0] slot_q;
assign     slot_q   = Q;
wire [1:0] session;
assign     session  = SESSION;
wire [1:0] select;
assign     select   = SEL;
wire       target;
assign     target   = TARGET;

reg [3:0] send_packet_type;
reg       start_tx;

reg  [15:0] tx_handle;
wire [15:0] rx_handle;

wire reader_done, rx_timeout, rx_packet_complete, reader_running;

rfid_reader_packet_rxtx UREADER (

                reset, clk, tag_backscatter, reader_modulation,

                miller, trext, divide_ratio, tari_ns, trcal_ns,

                slot_q, q_adj, session, target, select,

                send_packet_type, start_tx, reader_done, rx_timeout, rx_packet_complete, reader_running,

                tx_handle,

                rx_handle
                );



parameter CLK_EXP = 7;

wire [15:0] startup_counts;
assign      startup_counts = 16'd50000 >> CLK_EXP;


reg [5:0] reader_state;
parameter STATE_INIT     = 0;
parameter STATE_QUERY    = 1;
parameter STATE_QUERYREP = 2;
parameter STATE_ACK      = 3;
parameter STATE_REQRN    = 4;
parameter STATE_READ     = 5;
parameter STATE_REQMASK  = 6;
parameter STATE_WRITE    = 7;

reg started;
reg [15:0] counter;

always @ (posedge clk or posedge reset) begin
  if (reset) begin
    reader_state   <= 0;
    started        <= 0;
    tx_handle      <= 0;
    start_tx       <= 0;
    counter        <= 0;
    send_packet_type <= 0;
  end else begin
    case(reader_state)
      STATE_INIT: begin
        if (!started) begin
          counter <= 0;
          started <= 1;
        end else begin
          if (counter >= startup_counts) begin
            reader_state <= STATE_QUERY;
            started      <= 0;
          end else begin
            counter <= counter + 1;
          end
        end
      end
      
      STATE_QUERY: begin
        send_packet_type <= QUERY;
        
        if (!started && reader_running) begin
          start_tx     <= 0;
          started      <= 1;
        end else if (!started && !reader_running) begin
          start_tx     <= 1;
        end else if (started && reader_done && rx_packet_complete) begin
          tx_handle    <= rx_handle;
          reader_state <= STATE_ACK;
          started      <= 0;
        end else if (started && reader_done && !rx_packet_complete) begin
          reader_state <= STATE_QUERYREP;
          started      <= 0;
        end
      end
      
      STATE_QUERYREP: begin
        send_packet_type <= QUERYREP;
        
        if (!started && reader_running) begin
          start_tx     <= 0;
          started      <= 1;
        end else if (!started && !reader_running) begin
          start_tx     <= 1;
        end else if (started && reader_done && rx_packet_complete) begin
          tx_handle    <= rx_handle;
          reader_state <= STATE_ACK;
          started      <= 0;
        end else if (started && reader_done && !rx_packet_complete) begin
          reader_state <= STATE_QUERYREP;
          started      <= 0;
        end
      end
      
      STATE_ACK: begin
        send_packet_type <= ACK;
        
        if (!started && reader_running) begin
          start_tx     <= 0;
          started      <= 1;
        end else if (!started && !reader_running) begin
          start_tx     <= 1;
        end else if (started && reader_done && rx_packet_complete) begin
          tx_handle    <= rx_handle;
          reader_state <= STATE_REQRN;
          started      <= 0;
        end else if (started && reader_done && !rx_packet_complete) begin
          reader_state <= STATE_QUERY;
          started      <= 0;
        end
      end
      
      STATE_REQRN: begin
        send_packet_type <= REQRN;
        
        if (!started && reader_running) begin
          start_tx     <= 0;
          started      <= 1;
        end else if (!started && !reader_running) begin
          start_tx     <= 1;
        end else if (started && reader_done && rx_packet_complete) begin
          tx_handle    <= rx_handle;
          reader_state <= STATE_READ;
          started      <= 0;
        end else if (started && reader_done && !rx_packet_complete) begin
          reader_state <= STATE_QUERY;
          started      <= 0;
        end
      end
      
      STATE_READ: begin
        send_packet_type <= READ;
        
        if (!started && reader_running) begin
          start_tx     <= 0;
          started      <= 1;
        end else if (!started && !reader_running) begin
          start_tx     <= 1;
        end else if (started && reader_done && rx_packet_complete) begin
          tx_handle    <= rx_handle;
          reader_state <= STATE_QUERY;
          started      <= 0;
        end else if (started && reader_done && !rx_packet_complete) begin
          reader_state <= STATE_QUERY;
          started      <= 0;
        end
      end
      
      default: begin
        reader_state <= 0;
      end
    endcase
  end
end


endmodule
module rfid_reader (

                    reset, clk, tag_backscatter, reader_modulation
                    );


input  reset, clk, tag_backscatter;
output reader_modulation;


parameter QUERYREP   = 0;
parameter ACK        = 1;
parameter QUERY      = 2;
parameter QUERYADJ   = 3;
parameter SELECT     = 4;
parameter NACK       = 5;
parameter REQRN      = 6;
parameter READ       = 7;
parameter WRITE      = 8;
parameter KILL       = 9;
parameter LOCK       = 10;
parameter ACCESS     = 11;
parameter BLOCKWRITE = 12;
parameter BLOCKERASE = 13;


parameter DR         = 1'd0;
parameter M          = 2'd0;
parameter TREXT      = 1'd0;
parameter SEL        = 2'd0;
parameter SESSION    = 2'd0;
parameter TARGET     = 1'd0;
parameter Q          = 4'd2;


parameter DELIM      = 16'd15000;
parameter PW         = 16'd1000;
parameter TARI       = 16'd6250;
parameter RTCAL      = 16'd18750;
parameter TRCAL      = 16'd25000;

wire [2:0]  miller;
assign      miller        = M;
wire        trext;
assign      trext         = TREXT;
wire        divide_ratio;
assign      divide_ratio  = DR;
wire [15:0] tari_ns;
assign      tari_ns       = TARI;
wire [15:0] trcal_ns;
assign      trcal_ns      = TRCAL;

wire [2:0] q_adj;
assign     q_adj    = 0;
wire [3:0] slot_q;
assign     slot_q   = Q;
wire [1:0] session;
assign     session  = SESSION;
wire [1:0] select;
assign     select   = SEL;
wire       target;
assign     target   = TARGET;

reg [3:0] send_packet_type;
reg       start_tx;

reg  [15:0] tx_handle;
wire [15:0] rx_handle;

wire reader_done, rx_timeout, rx_packet_complete, reader_running;

rfid_reader_packet_rxtx UREADER (

                reset, clk, tag_backscatter, reader_modulation,

                miller, trext, divide_ratio, tari_ns, trcal_ns,

                slot_q, q_adj, session, target, select,

                send_packet_type, start_tx, reader_done, rx_timeout, rx_packet_complete, reader_running,

                tx_handle,

                rx_handle
                );



parameter CLK_EXP = 7;

wire [15:0] startup_counts;
assign      startup_counts = 16'd50000 >> CLK_EXP;


reg [5:0] reader_state;
parameter STATE_INIT     = 0;
parameter STATE_QUERY    = 1;
parameter STATE_QUERYREP = 2;
parameter STATE_ACK      = 3;
parameter STATE_REQRN    = 4;
parameter STATE_READ     = 5;
parameter STATE_REQMASK  = 6;
parameter STATE_WRITE    = 7;

reg started;
reg [15:0] counter;

always @ (posedge clk or posedge reset) begin
  if (reset) begin
    reader_state   <= 0;
    started        <= 0;
    tx_handle      <= 0;
    start_tx       <= 0;
    counter        <= 0;
    send_packet_type <= 0;
  end else begin
    case(reader_state)
      STATE_INIT: begin
        if (!started) begin
          counter <= 0;
          started <= 1;
        end else begin
          if (counter >= startup_counts) begin
            reader_state <= STATE_QUERY;
            started      <= 0;
          end else begin
            counter <= counter + 1;
          end
        end
      end
      
      STATE_QUERY: begin
        send_packet_type <= QUERY;
        
        if (!started && reader_running) begin
          start_tx     <= 0;
          started      <= 1;
        end else if (!started && !reader_running) begin
          start_tx     <= 1;
        end else if (started && reader_done && rx_packet_complete) begin
          tx_handle    <= rx_handle;
          reader_state <= STATE_ACK;
          started      <= 0;
        end else if (started && reader_done && !rx_packet_complete) begin
          reader_state <= STATE_QUERYREP;
          started      <= 0;
        end
      end
      
      STATE_QUERYREP: begin
        send_packet_type <= QUERYREP;
        
        if (!started && reader_running) begin
          start_tx     <= 0;
          started      <= 1;
        end else if (!started && !reader_running) begin
          start_tx     <= 1;
        end else if (started && reader_done && rx_packet_complete) begin
          tx_handle    <= rx_handle;
          reader_state <= STATE_ACK;
          started      <= 0;
        end else if (started && reader_done && !rx_packet_complete) begin
          reader_state <= STATE_QUERYREP;
          started      <= 0;
        end
      end
      
      STATE_ACK: begin
        send_packet_type <= ACK;
        
        if (!started && reader_running) begin
          start_tx     <= 0;
          started      <= 1;
        end else if (!started && !reader_running) begin
          start_tx     <= 1;
        end else if (started && reader_done && rx_packet_complete) begin
          tx_handle    <= rx_handle;
          reader_state <= STATE_REQRN;
          started      <= 0;
        end else if (started && reader_done && !rx_packet_complete) begin
          reader_state <= STATE_QUERY;
          started      <= 0;
        end
      end
      
      STATE_REQRN: begin
        send_packet_type <= REQRN;
        
        if (!started && reader_running) begin
          start_tx     <= 0;
          started      <= 1;
        end else if (!started && !reader_running) begin
          start_tx     <= 1;
        end else if (started && reader_done && rx_packet_complete) begin
          tx_handle    <= rx_handle;
          reader_state <= STATE_READ;
          started      <= 0;
        end else if (started && reader_done && !rx_packet_complete) begin
          reader_state <= STATE_QUERY;
          started      <= 0;
        end
      end
      
      STATE_READ: begin
        send_packet_type <= READ;
        
        if (!started && reader_running) begin
          start_tx     <= 0;
          started      <= 1;
        end else if (!started && !reader_running) begin
          start_tx     <= 1;
        end else if (started && reader_done && rx_packet_complete) begin
          tx_handle    <= rx_handle;
          reader_state <= STATE_QUERY;
          started      <= 0;
        end else if (started && reader_done && !rx_packet_complete) begin
          reader_state <= STATE_QUERY;
          started      <= 0;
        end
      end
      
      default: begin
        reader_state <= 0;
      end
    endcase
  end
end


endmodule