Merged r9433:9527 from features/gr-usrp2 into trunk. Adds usrp2 and gr-usrp2 top...
[debian/gnuradio] / usrp2 / fpga / control_lib / wb_semaphore.v
1
2 // up to 8 semaphores
3
4 // After a read operation, the semaphore is always locked
5 //  If it was already locked before the read (meaning someone else holds the lock)
6 //    then a 1 is returned
7 //  If it was not already locked (meaning the reader now holds the lock)
8 //    then a 0 is returned
9
10 // A write operation clears the lock
11
12 module wb_semaphore 
13   #(parameter count=8, DBUS_WIDTH=32)
14     (input wb_clk_i,
15      input wb_rst_i,
16      input [DBUS_WIDTH-1:0] wb_dat_i,
17      input [2:0] wb_adr_i,
18      input wb_cyc_i,
19      input wb_stb_i,
20      input wb_we_i,
21      output wb_ack_o,
22      output [DBUS_WIDTH-1:0] wb_dat_o);
23
24    reg [count-1:0] locked;
25
26    always @(posedge clock)
27      if(wb_rst_i)
28        locked <= {count{1'b0}};
29      else if(wb_stb_i)
30        if(wb_we_i)
31          locked[adr_i] <= 1'b0;
32        else
33          locked[adr_i] <= 1'b1;
34
35    assign          wb_dat_o[DBUS_WIDTH-1:1] = {(DBUS_WIDTH-1){1'b0}};
36    assign          wb_dat_o[0] = locked[adr_i];
37    assign          wb_ack_o = wb_stb_i;
38    
39
40 endmodule // wb_semaphore
41
42