root / usrp2 / vrt / vita_tx_control.v @ a9d30712
History | View | Annotate | Download (6.21 KB)
| 1 | bfaa5d14 | Josh Blum | // |
|---|---|---|---|
| 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 | 913cc668 | Matt Ettus | |
| 19 | 72cc0e23 | Matt Ettus | module vita_tx_control |
| 20 | 913cc668 | Matt Ettus | #(parameter BASE=0, |
| 21 | parameter WIDTH=32) |
||
| 22 | (input clk, input reset, input clear, |
||
| 23 | input set_stb, input [7:0] set_addr, input [31:0] set_data, |
||
| 24 | |||
| 25 | input [63:0] vita_time, |
||
| 26 | e7fbdbce | Matt Ettus | output error, output ack, |
| 27 | 4a82c064 | Matt Ettus | output reg [31:0] error_code, |
| 28 | 4139894f | Matt Ettus | output reg packet_consumed, |
| 29 | |||
| 30 | 72cc0e23 | Matt Ettus | // From vita_tx_deframer |
| 31 | 4a82c064 | Matt Ettus | input [5+64+16+WIDTH-1:0] sample_fifo_i, |
| 32 | 72cc0e23 | Matt Ettus | input sample_fifo_src_rdy_i, |
| 33 | output sample_fifo_dst_rdy_o, |
||
| 34 | 913cc668 | Matt Ettus | |
| 35 | 72cc0e23 | Matt Ettus | // To DSP Core |
| 36 | output [WIDTH-1:0] sample, |
||
| 37 | e0db4716 | Matt Ettus | output reg run, |
| 38 | 42d8dc7e | Matt Ettus | input strobe, |
| 39 | 913cc668 | Matt Ettus | |
| 40 | 42d8dc7e | Matt Ettus | output [31:0] debug |
| 41 | ); |
||
| 42 | 0cf5dc0a | Matt Ettus | |
| 43 | 7adc781f | Matt Ettus | wire [63:0] send_time = sample_fifo_i[63:0]; |
| 44 | 4a82c064 | Matt Ettus | wire [15:0] seqnum = sample_fifo_i[79:64]; |
| 45 | wire eop = sample_fifo_i[80]; |
||
| 46 | wire eob = sample_fifo_i[81]; |
||
| 47 | wire sob = sample_fifo_i[82]; |
||
| 48 | wire send_at = sample_fifo_i[83]; |
||
| 49 | wire seqnum_err = sample_fifo_i[84]; |
||
| 50 | 0cf5dc0a | Matt Ettus | |
| 51 | 7adc781f | Matt Ettus | wire now, early, late, too_early; |
| 52 | 8d19387a | Matt Ettus | |
| 53 | // FIXME ignore too_early for now for timing reasons |
||
| 54 | assign too_early = 0; |
||
| 55 | 7adc781f | Matt Ettus | time_compare |
| 56 | f04a49aa | Matt Ettus | time_compare (.time_now(vita_time), .trigger_time(send_time), |
| 57 | .now(now), .early(early), .late(late), .too_early()); |
||
| 58 | ac41c5a7 | Matt Ettus | |
| 59 | reg late_qual, late_del; |
||
| 60 | |||
| 61 | always @(posedge clk) |
||
| 62 | if(reset | clear) |
||
| 63 | late_del <= 0; |
||
| 64 | else |
||
| 65 | late_del <= late; |
||
| 66 | 913cc668 | Matt Ettus | |
| 67 | ac41c5a7 | Matt Ettus | always @(posedge clk) |
| 68 | if(reset | clear) |
||
| 69 | late_qual <= 0; |
||
| 70 | else |
||
| 71 | late_qual <= (sample_fifo_src_rdy_i & ~sample_fifo_dst_rdy_o); |
||
| 72 | |||
| 73 | 913cc668 | Matt Ettus | localparam IBS_IDLE = 0; |
| 74 | f238468d | Matt Ettus | localparam IBS_RUN = 1; // FIXME do we need this? |
| 75 | localparam IBS_CONT_BURST = 2; |
||
| 76 | a3b53a92 | Matt Ettus | localparam IBS_ERROR = 3; |
| 77 | localparam IBS_ERROR_DONE = 4; |
||
| 78 | e1591e4f | Matt Ettus | localparam IBS_ERROR_WAIT = 5; |
| 79 | 0cf5dc0a | Matt Ettus | |
| 80 | f39dc8ef | Matt Ettus | wire [31:0] CODE_EOB_ACK = {seqnum,16'd1};
|
| 81 | 4a82c064 | Matt Ettus | wire [31:0] CODE_UNDERRUN = {seqnum,16'd2};
|
| 82 | wire [31:0] CODE_SEQ_ERROR = {seqnum,16'd4};
|
||
| 83 | wire [31:0] CODE_TIME_ERROR = {seqnum,16'd8};
|
||
| 84 | wire [31:0] CODE_UNDERRUN_MIDPKT = {seqnum,16'd16};
|
||
| 85 | wire [31:0] CODE_SEQ_ERROR_MIDBURST = {seqnum,16'd32};
|
||
| 86 | f238468d | Matt Ettus | |
| 87 | 7adc781f | Matt Ettus | reg [2:0] ibs_state; |
| 88 | 5f54616b | Matt Ettus | |
| 89 | 4a82c064 | Matt Ettus | wire [31:0] error_policy; |
| 90 | setting_reg #(.my_addr(BASE+3)) sr_error_policy |
||
| 91 | b357b627 | Matt Ettus | (.clk(clk),.rst(reset),.strobe(set_stb),.addr(set_addr), |
| 92 | 4a82c064 | Matt Ettus | .in(set_data),.out(error_policy),.changed()); |
| 93 | |||
| 94 | wire policy_wait = error_policy[0]; |
||
| 95 | wire policy_next_packet = error_policy[1]; |
||
| 96 | wire policy_next_burst = error_policy[2]; |
||
| 97 | e7fbdbce | Matt Ettus | reg send_error, send_ack; |
| 98 | 4a82c064 | Matt Ettus | |
| 99 | 913cc668 | Matt Ettus | always @(posedge clk) |
| 100 | 587dfe7d | Matt Ettus | if(reset | clear) |
| 101 | 4a82c064 | Matt Ettus | begin |
| 102 | ibs_state <= IBS_IDLE; |
||
| 103 | send_error <= 0; |
||
| 104 | e7fbdbce | Matt Ettus | send_ack <= 0; |
| 105 | 048dd370 | Matt Ettus | error_code <= 0; |
| 106 | 4a82c064 | Matt Ettus | end |
| 107 | 913cc668 | Matt Ettus | else |
| 108 | case(ibs_state) |
||
| 109 | IBS_IDLE : |
||
| 110 | 7adc781f | Matt Ettus | if(sample_fifo_src_rdy_i) |
| 111 | 0cf5dc0a | Matt Ettus | if(seqnum_err) |
| 112 | a3b53a92 | Matt Ettus | begin |
| 113 | ibs_state <= IBS_ERROR; |
||
| 114 | error_code <= CODE_SEQ_ERROR; |
||
| 115 | 4a82c064 | Matt Ettus | send_error <= 1; |
| 116 | a3b53a92 | Matt Ettus | end |
| 117 | 0cf5dc0a | Matt Ettus | else if(~send_at | now) |
| 118 | 7adc781f | Matt Ettus | ibs_state <= IBS_RUN; |
| 119 | ac41c5a7 | Matt Ettus | else if((late_qual & late_del) | too_early) |
| 120 | a3b53a92 | Matt Ettus | begin |
| 121 | ibs_state <= IBS_ERROR; |
||
| 122 | error_code <= CODE_TIME_ERROR; |
||
| 123 | 4a82c064 | Matt Ettus | send_error <= 1; |
| 124 | a3b53a92 | Matt Ettus | end |
| 125 | 7adc781f | Matt Ettus | |
| 126 | IBS_RUN : |
||
| 127 | 913cc668 | Matt Ettus | if(strobe) |
| 128 | 7adc781f | Matt Ettus | if(~sample_fifo_src_rdy_i) |
| 129 | a3b53a92 | Matt Ettus | begin |
| 130 | ibs_state <= IBS_ERROR; |
||
| 131 | 9715fc38 | Matt Ettus | error_code <= CODE_UNDERRUN_MIDPKT; |
| 132 | 4a82c064 | Matt Ettus | send_error <= 1; |
| 133 | a3b53a92 | Matt Ettus | end |
| 134 | f238468d | Matt Ettus | else if(eop) |
| 135 | if(eob) |
||
| 136 | f39dc8ef | Matt Ettus | begin |
| 137 | 10427284 | Matt Ettus | ibs_state <= IBS_ERROR_DONE; // Not really an error |
| 138 | f39dc8ef | Matt Ettus | error_code <= CODE_EOB_ACK; |
| 139 | e7fbdbce | Matt Ettus | send_ack <= 1; |
| 140 | f39dc8ef | Matt Ettus | end |
| 141 | f238468d | Matt Ettus | else |
| 142 | ibs_state <= IBS_CONT_BURST; |
||
| 143 | 913cc668 | Matt Ettus | |
| 144 | f238468d | Matt Ettus | IBS_CONT_BURST : |
| 145 | if(strobe) |
||
| 146 | a3b53a92 | Matt Ettus | begin |
| 147 | e1591e4f | Matt Ettus | if(policy_next_packet) |
| 148 | ibs_state <= IBS_ERROR_DONE; |
||
| 149 | else if(policy_wait) |
||
| 150 | ibs_state <= IBS_ERROR_WAIT; |
||
| 151 | else |
||
| 152 | ibs_state <= IBS_ERROR; |
||
| 153 | a3b53a92 | Matt Ettus | error_code <= CODE_UNDERRUN; |
| 154 | 4a82c064 | Matt Ettus | send_error <= 1; |
| 155 | a3b53a92 | Matt Ettus | end |
| 156 | f238468d | Matt Ettus | else if(sample_fifo_src_rdy_i) |
| 157 | 0cf5dc0a | Matt Ettus | if(seqnum_err) |
| 158 | a3b53a92 | Matt Ettus | begin |
| 159 | ibs_state <= IBS_ERROR; |
||
| 160 | 9715fc38 | Matt Ettus | error_code <= CODE_SEQ_ERROR_MIDBURST; |
| 161 | 4a82c064 | Matt Ettus | send_error <= 1; |
| 162 | a3b53a92 | Matt Ettus | end |
| 163 | 0cf5dc0a | Matt Ettus | else |
| 164 | ibs_state <= IBS_RUN; |
||
| 165 | f238468d | Matt Ettus | |
| 166 | a3b53a92 | Matt Ettus | IBS_ERROR : |
| 167 | 4a82c064 | Matt Ettus | begin |
| 168 | send_error <= 0; |
||
| 169 | if(sample_fifo_src_rdy_i & eop) |
||
| 170 | if(policy_next_packet | (policy_next_burst & eob)) |
||
| 171 | ibs_state <= IBS_IDLE; |
||
| 172 | e1591e4f | Matt Ettus | else if(policy_wait) |
| 173 | ibs_state <= IBS_ERROR_WAIT; |
||
| 174 | 4a82c064 | Matt Ettus | end |
| 175 | 0cf5dc0a | Matt Ettus | |
| 176 | e1591e4f | Matt Ettus | IBS_ERROR_DONE : |
| 177 | c174bf9a | Matt Ettus | begin |
| 178 | send_error <= 0; |
||
| 179 | e7fbdbce | Matt Ettus | send_ack <= 0; |
| 180 | c174bf9a | Matt Ettus | ibs_state <= IBS_IDLE; |
| 181 | end |
||
| 182 | e1591e4f | Matt Ettus | |
| 183 | IBS_ERROR_WAIT : |
||
| 184 | send_error <= 0; |
||
| 185 | 7adc781f | Matt Ettus | endcase // case (ibs_state) |
| 186 | |||
| 187 | e0db4716 | Matt Ettus | |
| 188 | a3b53a92 | Matt Ettus | assign sample_fifo_dst_rdy_o = (ibs_state == IBS_ERROR) | (strobe & (ibs_state == IBS_RUN)); // FIXME also cleanout |
| 189 | e0db4716 | Matt Ettus | |
| 190 | 6bbcb202 | Josh Blum | //register the output sample |
| 191 | reg [31:0] sample_held; |
||
| 192 | assign sample = sample_held; |
||
| 193 | always @(posedge clk) |
||
| 194 | if(reset | clear) |
||
| 195 | sample_held <= 0; |
||
| 196 | else if (~run) |
||
| 197 | sample_held <= 0; |
||
| 198 | else if (strobe) |
||
| 199 | sample_held <= sample_fifo_i[5+64+16+WIDTH-1:5+64+16]; |
||
| 200 | |||
| 201 | 4a82c064 | Matt Ettus | assign error = send_error; |
| 202 | e7fbdbce | Matt Ettus | assign ack = send_ack; |
| 203 | 42d8dc7e | Matt Ettus | |
| 204 | e0db4716 | Matt Ettus | localparam MAX_IDLE = 1000000; |
| 205 | // approx 10 ms timeout with a 100 MHz clock, but burning samples will slow that down |
||
| 206 | reg [19:0] countdown; |
||
| 207 | |||
| 208 | always @(posedge clk) |
||
| 209 | if(reset | clear) |
||
| 210 | begin |
||
| 211 | run <= 0; |
||
| 212 | countdown <= 0; |
||
| 213 | end |
||
| 214 | else |
||
| 215 | 19dafcc4 | Matt Ettus | if (ibs_state == IBS_RUN) |
| 216 | if(eob & eop & strobe & sample_fifo_src_rdy_i) |
||
| 217 | run <= 0; |
||
| 218 | else |
||
| 219 | begin |
||
| 220 | run <= 1; |
||
| 221 | countdown <= MAX_IDLE; |
||
| 222 | end |
||
| 223 | e0db4716 | Matt Ettus | else |
| 224 | if (countdown == 0) |
||
| 225 | run <= 0; |
||
| 226 | else |
||
| 227 | countdown <= countdown - 1; |
||
| 228 | |||
| 229 | 4139894f | Matt Ettus | always @(posedge clk) |
| 230 | 587dfe7d | Matt Ettus | if(reset | clear) |
| 231 | 4139894f | Matt Ettus | packet_consumed <= 0; |
| 232 | else |
||
| 233 | packet_consumed <= eop & sample_fifo_src_rdy_i & sample_fifo_dst_rdy_o; |
||
| 234 | |||
| 235 | ac41c5a7 | Matt Ettus | assign debug = { { now,late_qual,late_del,ack,eop,eob,sob,send_at },
|
| 236 | 0cf5dc0a | Matt Ettus | { sample_fifo_src_rdy_i, sample_fifo_dst_rdy_o, strobe, run, error, ibs_state[2:0] },
|
| 237 | 42d8dc7e | Matt Ettus | { 8'b0 },
|
| 238 | { 8'b0 } };
|
||
| 239 | 913cc668 | Matt Ettus | |
| 240 | 7adc781f | Matt Ettus | endmodule // vita_tx_control |