data/full_repos/permissive/447976230/fpga/usrp2/control_lib/ram_loader.v
1: b"%Error: data/full_repos/permissive/447976230/fpga/usrp2/control_lib/ram_loader.v:260: Cannot find file containing module: 'fifo_xlnx_16x40_2clk'\n   fifo_xlnx_16x40_2clk crossclk\n   ^~~~~~~~~~~~~~~~~~~~\n        ... Looked in:\n             data/full_repos/permissive/447976230/fpga/usrp2/control_lib,data/full_repos/permissive/447976230/fifo_xlnx_16x40_2clk\n             data/full_repos/permissive/447976230/fpga/usrp2/control_lib,data/full_repos/permissive/447976230/fifo_xlnx_16x40_2clk.v\n             data/full_repos/permissive/447976230/fpga/usrp2/control_lib,data/full_repos/permissive/447976230/fifo_xlnx_16x40_2clk.sv\n             fifo_xlnx_16x40_2clk\n             fifo_xlnx_16x40_2clk.v\n             fifo_xlnx_16x40_2clk.sv\n             obj_dir/fifo_xlnx_16x40_2clk\n             obj_dir/fifo_xlnx_16x40_2clk.v\n             obj_dir/fifo_xlnx_16x40_2clk.sv\n%Error: Exiting due to 1 error(s)\n"
module ram_loader
  #(parameter AWIDTH=16, RAM_SIZE=16384)
    (

     input wb_clk,
     input dsp_clk,
     input ram_loader_rst,
     output wire [31:0] wb_dat,
     output wire [AWIDTH-1:0] wb_adr,
     output wb_stb,
     output reg [3:0] wb_sel,
     output wb_we,
     output reg ram_loader_done,

     input cpld_clk,
     input cpld_din,
     output reg cpld_start,
     output reg cpld_mode,
     output reg cpld_done,
     input cpld_detached
     );

   localparam S0 = 0;
   localparam S1 = 1;
   localparam S2 = 2;
   localparam S3 = 3;
   localparam S4 = 4;
   localparam S5 = 5;
   localparam S6 = 6;
   localparam RESET = 7;
   
   localparam WB_IDLE = 0;
   localparam WB_WRITE = 1;
  

   reg [AWIDTH+2:0] count;
   reg [6:0] 	    shift_reg;
   reg [7:0] 	    data_reg;
   reg 		    sampled_clk;
   reg 		    sampled_clk_meta;
   reg 		    sampled_din;
   reg 		    inc_count;
   reg 		    load_data_reg;
   reg 		    shift;  
   reg 		    wb_state, wb_next_state;
   reg [2:0] 	    state, next_state;
    






   always @(posedge dsp_clk or posedge ram_loader_rst)
      if (ram_loader_rst)
	begin
	   sampled_clk_meta <= 1'b0;
	   sampled_clk <= 1'b0;
	   sampled_din <= 1'b0;
	   count <= 'h7FFF8;
	   data_reg <= 0;
	   shift_reg <= 0;
	end
      else 
	begin
	   sampled_clk_meta <= cpld_clk;
	   sampled_clk <= sampled_clk_meta;
	   sampled_din <= cpld_din;
	   if (inc_count)
	     count <= count + 1'b1;
	   if (load_data_reg)
	     data_reg <= {shift_reg,sampled_din};
	   if (shift)
	     shift_reg <= {shift_reg[5:0],sampled_din};	   
	end
   
	   
   always @(posedge dsp_clk or posedge ram_loader_rst)
     if (ram_loader_rst)
       state <= RESET;
     else
       state <= next_state;


   always @*
     begin

	next_state = state;
	cpld_start = 1'b0;
	shift = 1'b0;
	inc_count = 0;
	load_data_reg = 1'b0;
	ram_loader_done = 1'b0;
	cpld_mode = 1'b0;
	cpld_done = 1'b1;
	
	
	
	case (state)

	  RESET: begin		     
	     if (cpld_detached)
	       next_state = S0;
	     else
	       next_state = RESET;
	  end



	  S0: begin
	     cpld_start = 1'b1;	 
	     cpld_done = 1'b0;	 
	     if (~cpld_detached)
	       next_state = S2;
	     else
	       next_state = S0;   
	  end
	  

	  S1: begin
	     cpld_start = 1'b1;	   
	     cpld_done = 1'b0;	 
	     if (sampled_clk)
	       begin

		  if (count[2:0] == 3'b111)

		    begin
		       load_data_reg = 1'b1;
		       inc_count = 1'b1;
		    end
		  else 

		     begin
		       shift = 1'b1;
		       inc_count = 1'b1;
		     end
		  next_state = S2;
	       end
	     else
	       next_state = S1;
	  end
	  

	  S2: begin
	     cpld_start = 1'b1;	    
	     cpld_done = 1'b0;
	     if (~sampled_clk)

	       if (count[AWIDTH+2:3] == RAM_SIZE-1)

		 next_state = S3;
	       else
		 next_state = S1;
	     else
	       next_state = S2;
	  end
	  


	  S3: begin
	     if (sampled_clk)
	       begin
		  cpld_mode = 1'b1;
		  cpld_done = 1'b1;
		  next_state = S4;
	       end
	     else
	       next_state = S3;	     
	  end



	  S4: begin
	     cpld_mode = 1'b1;
	     cpld_done = 1'b1;
	     if (~sampled_clk)
	       next_state = S5;
	     else
	       next_state = S4;
	  end


	  S5: begin
	     cpld_mode = 1'b1;
	     cpld_done = 1'b1;
	     if (sampled_clk)
	       next_state = S6;
	     else	      
	       next_state = S5;	       
	  end


	  S6: begin
	     ram_loader_done = 1'b1;
	     cpld_done = 1'b1;
	     cpld_mode = 1'b1;
	     next_state = S6;
	  end

	endcase
     end

   always @(posedge dsp_clk or posedge ram_loader_rst)
     if (ram_loader_rst)
       wb_state <= WB_IDLE;
     else
       wb_state <= wb_next_state;

   reg do_write;
   wire empty, full;
   
   always @*
     begin
	wb_next_state = wb_state;
	do_write = 1'b0;
	
	case (wb_state)

	  WB_IDLE: begin
	     if (load_data_reg)

	       wb_next_state  =  WB_WRITE;
	     else
	       wb_next_state = WB_IDLE;
	  end


	  WB_WRITE: begin
      	     do_write = 1'b1;
	     if (~full)	       
	       wb_next_state =  WB_IDLE;		      
	     else
	       wb_next_state = WB_WRITE;	       
	  end

	endcase
     end
   
   wire [1:0] count_out;
   wire [7:0] data_out;

   fifo_xlnx_16x40_2clk crossclk
     (.rst(ram_loader_rst),
      .wr_clk(dsp_clk), .din({count[4:3],count[AWIDTH+2:3],data_reg}), .wr_en(do_write), .full(full),
      .rd_clk(wb_clk), .dout({count_out,wb_adr,data_out}), .rd_en(~empty), .empty(empty));

   assign wb_dat = {4{data_out}};

   always @*
     case(count_out[1:0])
       2'b00 : wb_sel = 4'b1000;
       2'b01 : wb_sel = 4'b0100;
       2'b10 : wb_sel = 4'b0010;
       2'b11 : wb_sel = 4'b0001;
     endcase

   assign wb_we = ~empty;
   assign wb_stb = ~empty;
   
endmodule
module ram_loader
  #(parameter AWIDTH=16, RAM_SIZE=16384)
    (

     input wb_clk,
     input dsp_clk,
     input ram_loader_rst,
     output wire [31:0] wb_dat,
     output wire [AWIDTH-1:0] wb_adr,
     output wb_stb,
     output reg [3:0] wb_sel,
     output wb_we,
     output reg ram_loader_done,

     input cpld_clk,
     input cpld_din,
     output reg cpld_start,
     output reg cpld_mode,
     output reg cpld_done,
     input cpld_detached
     );


   localparam S0 = 0;
   localparam S1 = 1;
   localparam S2 = 2;
   localparam S3 = 3;
   localparam S4 = 4;
   localparam S5 = 5;
   localparam S6 = 6;
   localparam RESET = 7;
   
   localparam WB_IDLE = 0;
   localparam WB_WRITE = 1;
  

   reg [AWIDTH+2:0] count;
   reg [6:0] 	    shift_reg;
   reg [7:0] 	    data_reg;
   reg 		    sampled_clk;
   reg 		    sampled_clk_meta;
   reg 		    sampled_din;
   reg 		    inc_count;
   reg 		    load_data_reg;
   reg 		    shift;  
   reg 		    wb_state, wb_next_state;
   reg [2:0] 	    state, next_state;
    






   always @(posedge dsp_clk or posedge ram_loader_rst)
      if (ram_loader_rst)
	begin
	   sampled_clk_meta <= 1'b0;
	   sampled_clk <= 1'b0;
	   sampled_din <= 1'b0;
	   count <= 'h7FFF8;
	   data_reg <= 0;
	   shift_reg <= 0;
	end
      else 
	begin
	   sampled_clk_meta <= cpld_clk;
	   sampled_clk <= sampled_clk_meta;
	   sampled_din <= cpld_din;
	   if (inc_count)
	     count <= count + 1'b1;
	   if (load_data_reg)
	     data_reg <= {shift_reg,sampled_din};
	   if (shift)
	     shift_reg <= {shift_reg[5:0],sampled_din};	   
	end
   
	   
   always @(posedge dsp_clk or posedge ram_loader_rst)
     if (ram_loader_rst)
       state <= RESET;
     else
       state <= next_state;


   always @*
     begin

	next_state = state;
	cpld_start = 1'b0;
	shift = 1'b0;
	inc_count = 0;
	load_data_reg = 1'b0;
	ram_loader_done = 1'b0;
	cpld_mode = 1'b0;
	cpld_done = 1'b1;
	
	
	
	case (state)

	  RESET: begin		     
	     if (cpld_detached)
	       next_state = S0;
	     else
	       next_state = RESET;
	  end



	  S0: begin
	     cpld_start = 1'b1;	 
	     cpld_done = 1'b0;	 
	     if (~cpld_detached)
	       next_state = S2;
	     else
	       next_state = S0;   
	  end
	  

	  S1: begin
	     cpld_start = 1'b1;	   
	     cpld_done = 1'b0;	 
	     if (sampled_clk)
	       begin

		  if (count[2:0] == 3'b111)

		    begin
		       load_data_reg = 1'b1;
		       inc_count = 1'b1;
		    end
		  else 

		     begin
		       shift = 1'b1;
		       inc_count = 1'b1;
		     end
		  next_state = S2;
	       end
	     else
	       next_state = S1;
	  end
	  

	  S2: begin
	     cpld_start = 1'b1;	    
	     cpld_done = 1'b0;
	     if (~sampled_clk)

	       if (count[AWIDTH+2:3] == RAM_SIZE-1)

		 next_state = S3;
	       else
		 next_state = S1;
	     else
	       next_state = S2;
	  end
	  


	  S3: begin
	     if (sampled_clk)
	       begin
		  cpld_mode = 1'b1;
		  cpld_done = 1'b1;
		  next_state = S4;
	       end
	     else
	       next_state = S3;	     
	  end



	  S4: begin
	     cpld_mode = 1'b1;
	     cpld_done = 1'b1;
	     if (~sampled_clk)
	       next_state = S5;
	     else
	       next_state = S4;
	  end


	  S5: begin
	     cpld_mode = 1'b1;
	     cpld_done = 1'b1;
	     if (sampled_clk)
	       next_state = S6;
	     else	      
	       next_state = S5;	       
	  end


	  S6: begin
	     ram_loader_done = 1'b1;
	     cpld_done = 1'b1;
	     cpld_mode = 1'b1;
	     next_state = S6;
	  end

	endcase
     end

   always @(posedge dsp_clk or posedge ram_loader_rst)
     if (ram_loader_rst)
       wb_state <= WB_IDLE;
     else
       wb_state <= wb_next_state;

   reg do_write;
   wire empty, full;
   
   always @*
     begin
	wb_next_state = wb_state;
	do_write = 1'b0;
	
	case (wb_state)

	  WB_IDLE: begin
	     if (load_data_reg)

	       wb_next_state  =  WB_WRITE;
	     else
	       wb_next_state = WB_IDLE;
	  end


	  WB_WRITE: begin
      	     do_write = 1'b1;
	     if (~full)	       
	       wb_next_state =  WB_IDLE;		      
	     else
	       wb_next_state = WB_WRITE;	       
	  end

	endcase
     end
   
   wire [1:0] count_out;
   wire [7:0] data_out;

   fifo_xlnx_16x40_2clk crossclk
     (.rst(ram_loader_rst),
      .wr_clk(dsp_clk), .din({count[4:3],count[AWIDTH+2:3],data_reg}), .wr_en(do_write), .full(full),
      .rd_clk(wb_clk), .dout({count_out,wb_adr,data_out}), .rd_en(~empty), .empty(empty));

   assign wb_dat = {4{data_out}};

   always @*
     case(count_out[1:0])
       2'b00 : wb_sel = 4'b1000;
       2'b01 : wb_sel = 4'b0100;
       2'b10 : wb_sel = 4'b0010;
       2'b11 : wb_sel = 4'b0001;
     endcase

   assign wb_we = ~empty;
   assign wb_stb = ~empty;
   
endmodule