copied over old one which works with icarus
[debian/gnuradio] / usrp2 / fpga / control_lib / wb_bus_writer.v
1
2 // wb_bus_writer
3 //
4 // WB Bus Master device to send a sequence of single-word transactions
5 // based on a list in a RAM or ROM (FASM interface)
6 // ROM data format is {WB_ADDR[15:0],WB_DATA[31:0]}
7 // continues until it gets an all-1s entry
8
9 module wb_bus_writer (input start,
10                       output done,
11                       output reg [15:0] rom_addr,
12                       input [47:0] rom_data,
13                       // WB Master Interface, don't need wb_dat_i
14                       input wb_clk_i,
15                       input wb_rst_i,
16                       output [31:0] wb_dat_o,
17                       input wb_ack_i,
18                       output [15:0] wb_adr_o,
19                       output wb_cyc_o,
20                       output [3:0] wb_sel_o,
21                       output wb_stb_o,
22                       output wb_we_o
23                       );
24
25 `define IDLE 0
26 `define READ 1
27    
28    reg [3:0]                 state;
29    
30    assign                    done = (state != `IDLE) && (&rom_data);  // Done when we see all 1s
31    
32    always @(posedge wb_clk_i)
33      if(wb_rst_i)
34        begin
35           rom_addr <= #1 0;
36           state <= #1 0;
37        end
38      else if(start)
39        begin
40           rom_addr <= #1 0;
41           state <= #1 `READ;
42        end
43      else if((state == `READ) && wb_ack_i)
44        if(done)
45          state <= #1 `IDLE;
46        else
47          rom_addr <= #1 rom_addr + 1;
48    
49    assign wb_dat_o = rom_data[31:0];
50    assign wb_adr_o = rom_data[47:32];
51    assign wb_sel_o = 4'b1111;    // All writes are the full 32 bits
52    
53    assign wb_cyc_o = !done & (state != `IDLE);
54    assign wb_stb_o = !done & (state != `IDLE);
55    assign wb_we_o = !done & (state != `IDLE);
56    
57 endmodule // wb_bus_writer