Statistics
| Branch: | Tag: | Revision:

root / usrp2 / control_lib / dbsm.v @ c7adcbe4

History | View | Annotate | Download (4.95 KB)

1
//
2
// Copyright 2011 Ettus Research LLC
3
//
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
//
17

    
18
module dbsm
19
  (input clk,
20
   input reset,
21
   input clear,
22
   
23
   output write_ok,
24
   output write_ptr,
25
   input write_done,
26

    
27
   output read_ok,
28
   output read_ptr,
29
   input read_done,
30

    
31
   output access_ok,
32
   output access_ptr,
33
   input access_done,
34
   input access_skip_read
35
   );
36

    
37
   localparam PORT_WAIT_0 = 0;
38
   localparam PORT_USE_0 = 1;
39
   localparam PORT_WAIT_1 = 2;
40
   localparam PORT_USE_1 = 3;
41

    
42
   reg [1:0] write_port_state, access_port_state, read_port_state;
43

    
44
   localparam BUFF_WRITABLE = 0;
45
   localparam BUFF_ACCESSIBLE = 1;
46
   localparam BUFF_READABLE = 2;
47
   localparam BUFF_ERROR = 3;
48

    
49
   wire [1:0] buff_state[0:1];
50
   
51
   always @(posedge clk)
52
     if(reset | clear)
53
       write_port_state <= PORT_WAIT_0;
54
     else
55
       case(write_port_state)
56
	 PORT_WAIT_0 :
57
	   if(buff_state[0]==BUFF_WRITABLE)
58
	     write_port_state <= PORT_USE_0;
59
	 PORT_USE_0 :
60
	   if(write_done)
61
	     write_port_state <= PORT_WAIT_1;
62
	 PORT_WAIT_1 :
63
	   if(buff_state[1]==BUFF_WRITABLE)
64
	     write_port_state <= PORT_USE_1;
65
	 PORT_USE_1 :
66
	   if(write_done)
67
	     write_port_state <= PORT_WAIT_0;
68
       endcase // case (write_port_state)
69

    
70
   assign write_ok = (write_port_state == PORT_USE_0) | (write_port_state == PORT_USE_1);
71
   assign write_ptr = (write_port_state == PORT_USE_1);
72
   
73
   always @(posedge clk)
74
     if(reset | clear)
75
       access_port_state <= PORT_WAIT_0;
76
     else
77
       case(access_port_state)
78
	 PORT_WAIT_0 :
79
	   if(buff_state[0]==BUFF_ACCESSIBLE)
80
	     access_port_state <= PORT_USE_0;
81
	 PORT_USE_0 :
82
	   if(access_done)
83
	     access_port_state <= PORT_WAIT_1;
84
	 PORT_WAIT_1 :
85
	   if(buff_state[1]==BUFF_ACCESSIBLE)
86
	     access_port_state <= PORT_USE_1;
87
	 PORT_USE_1 :
88
	   if(access_done)
89
	     access_port_state <= PORT_WAIT_0;
90
       endcase // case (access_port_state)
91
   
92
   assign access_ok = (access_port_state == PORT_USE_0) | (access_port_state == PORT_USE_1);
93
   assign access_ptr = (access_port_state == PORT_USE_1);
94

    
95
   always @(posedge clk)
96
     if(reset | clear)
97
       read_port_state <= PORT_WAIT_0;
98
     else
99
       case(read_port_state)
100
	 PORT_WAIT_0 :
101
	   if(buff_state[0]==BUFF_READABLE)
102
	     read_port_state <= PORT_USE_0;
103
	 PORT_USE_0 :
104
	   if(read_done)
105
	     read_port_state <= PORT_WAIT_1;
106
	 PORT_WAIT_1 :
107
	   if(buff_state[1]==BUFF_READABLE)
108
	     read_port_state <= PORT_USE_1;
109
	 PORT_USE_1 :
110
	   if(read_done)
111
	     read_port_state <= PORT_WAIT_0;
112
       endcase // case (read_port_state)
113
   
114
   assign read_ok = (read_port_state == PORT_USE_0) | (read_port_state == PORT_USE_1);
115
   assign read_ptr = (read_port_state == PORT_USE_1);
116

    
117
   buff_sm #(.PORT_USE_FLAG(PORT_USE_0)) buff0_sm
118
     (.clk(clk), .reset(reset), .clear(clear),
119
      .write_done(write_done), .access_done(access_done), .access_skip_read(access_skip_read), .read_done(read_done),
120
      .write_port_state(write_port_state), .access_port_state(access_port_state), .read_port_state(read_port_state),
121
      .buff_state(buff_state[0]));
122
   
123
   buff_sm #(.PORT_USE_FLAG(PORT_USE_1)) buff1_sm
124
     (.clk(clk), .reset(reset), .clear(clear),
125
      .write_done(write_done), .access_done(access_done), .access_skip_read(access_skip_read), .read_done(read_done),
126
      .write_port_state(write_port_state), .access_port_state(access_port_state), .read_port_state(read_port_state),
127
      .buff_state(buff_state[1]));
128
   
129
endmodule // dbsm
130

    
131
module buff_sm
132
  #(parameter PORT_USE_FLAG=0)
133
   (input clk, input reset, input clear,
134
    input write_done, input access_done, input access_skip_read, input read_done,
135
    input [1:0] write_port_state, input [1:0] access_port_state, input [1:0] read_port_state,
136
    output reg [1:0] buff_state);
137
   
138
   localparam BUFF_WRITABLE = 0;
139
   localparam BUFF_ACCESSIBLE = 1;
140
   localparam BUFF_READABLE = 2;
141
   localparam BUFF_ERROR = 3;
142

    
143
   always @(posedge clk)
144
     if(reset | clear)
145
       buff_state <= BUFF_WRITABLE;
146
     else
147
       case(buff_state)
148
	 BUFF_WRITABLE :
149
	   if(write_done & (write_port_state == PORT_USE_FLAG))
150
	     buff_state <= BUFF_ACCESSIBLE;
151
	 BUFF_ACCESSIBLE :
152
	   if(access_done & (access_port_state == PORT_USE_FLAG))
153
	     if(access_skip_read)
154
	       buff_state <= BUFF_WRITABLE;
155
	     else
156
	       buff_state <= BUFF_READABLE;
157
	 BUFF_READABLE :
158
	   if(read_done & (read_port_state == PORT_USE_FLAG))
159
	     buff_state <= BUFF_WRITABLE;
160
	 BUFF_ERROR :
161
	   ;
162
       endcase
163
	 
164
endmodule // buff_sm