| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
module master_control |
|---|
| 26 |
( input master_clk, input usbclk, |
|---|
| 27 |
input wire [6:0] serial_addr, input wire [31:0] serial_data, input wire serial_strobe, |
|---|
| 28 |
output tx_bus_reset, output rx_bus_reset, |
|---|
| 29 |
output wire tx_dsp_reset, output wire rx_dsp_reset, |
|---|
| 30 |
output wire enable_tx, output wire enable_rx, |
|---|
| 31 |
output wire [7:0] interp_rate, output wire [7:0] decim_rate, |
|---|
| 32 |
output tx_sample_strobe, output strobe_interp, |
|---|
| 33 |
output rx_sample_strobe, output strobe_decim, |
|---|
| 34 |
input tx_empty, |
|---|
| 35 |
input wire [15:0] debug_0,input wire [15:0] debug_1,input wire [15:0] debug_2,input wire [15:0] debug_3, |
|---|
| 36 |
output wire [15:0] reg_0, output wire [15:0] reg_1, output wire [15:0] reg_2, output wire [15:0] reg_3 |
|---|
| 37 |
); |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
wire [7:0] master_controls; |
|---|
| 42 |
setting_reg #(`FR_MASTER_CTRL) sr_mstr_ctrl(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(master_controls)); |
|---|
| 43 |
assign enable_tx = master_controls[0]; |
|---|
| 44 |
assign enable_rx = master_controls[1]; |
|---|
| 45 |
assign tx_dsp_reset = master_controls[2]; |
|---|
| 46 |
assign rx_dsp_reset = master_controls[3]; |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
setting_reg #(`FR_INTERP_RATE) sr_interp(.clock(master_clk),.reset(tx_dsp_reset),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(interp_rate)); |
|---|
| 51 |
setting_reg #(`FR_DECIM_RATE) sr_decim(.clock(master_clk),.reset(rx_dsp_reset),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(decim_rate)); |
|---|
| 52 |
|
|---|
| 53 |
strobe_gen da_strobe_gen |
|---|
| 54 |
( .clock(master_clk),.reset(tx_dsp_reset),.enable(enable_tx), |
|---|
| 55 |
.rate(8'd1),.strobe_in(1'b1),.strobe(tx_sample_strobe) ); |
|---|
| 56 |
|
|---|
| 57 |
strobe_gen tx_strobe_gen |
|---|
| 58 |
( .clock(master_clk),.reset(tx_dsp_reset),.enable(enable_tx), |
|---|
| 59 |
.rate(interp_rate),.strobe_in(tx_sample_strobe),.strobe(strobe_interp) ); |
|---|
| 60 |
|
|---|
| 61 |
assign rx_sample_strobe = 1'b1; |
|---|
| 62 |
|
|---|
| 63 |
strobe_gen decim_strobe_gen |
|---|
| 64 |
( .clock(master_clk),.reset(rx_dsp_reset),.enable(enable_rx), |
|---|
| 65 |
.rate(decim_rate),.strobe_in(rx_sample_strobe),.strobe(strobe_decim) ); |
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
reg tx_reset_bus_sync1, rx_reset_bus_sync1, tx_reset_bus_sync2, rx_reset_bus_sync2; |
|---|
| 70 |
|
|---|
| 71 |
always @(posedge usbclk) |
|---|
| 72 |
begin |
|---|
| 73 |
tx_reset_bus_sync1 <= #1 tx_dsp_reset; |
|---|
| 74 |
rx_reset_bus_sync1 <= #1 rx_dsp_reset; |
|---|
| 75 |
tx_reset_bus_sync2 <= #1 tx_reset_bus_sync1; |
|---|
| 76 |
rx_reset_bus_sync2 <= #1 rx_reset_bus_sync1; |
|---|
| 77 |
end |
|---|
| 78 |
|
|---|
| 79 |
assign tx_bus_reset = tx_reset_bus_sync2; |
|---|
| 80 |
assign rx_bus_reset = rx_reset_bus_sync2; |
|---|
| 81 |
|
|---|
| 82 |
wire [7:0] txa_refclk, rxa_refclk, txb_refclk, rxb_refclk; |
|---|
| 83 |
wire txaclk,txbclk,rxaclk,rxbclk; |
|---|
| 84 |
wire [3:0] debug_en, txcvr_ctrl; |
|---|
| 85 |
|
|---|
| 86 |
wire [31:0] txcvr_rxlines, txcvr_txlines; |
|---|
| 87 |
|
|---|
| 88 |
setting_reg #(`FR_TX_A_REFCLK) sr_txaref(.clock(master_clk),.reset(tx_dsp_reset),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(txa_refclk)); |
|---|
| 89 |
setting_reg #(`FR_RX_A_REFCLK) sr_rxaref(.clock(master_clk),.reset(rx_dsp_reset),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(rxa_refclk)); |
|---|
| 90 |
setting_reg #(`FR_TX_B_REFCLK) sr_txbref(.clock(master_clk),.reset(tx_dsp_reset),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(txb_refclk)); |
|---|
| 91 |
setting_reg #(`FR_RX_B_REFCLK) sr_rxbref(.clock(master_clk),.reset(rx_dsp_reset),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(rxb_refclk)); |
|---|
| 92 |
|
|---|
| 93 |
setting_reg #(`FR_DEBUG_EN) sr_debugen(.clock(master_clk),.reset(rx_dsp_reset|tx_dsp_reset),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(debug_en)); |
|---|
| 94 |
|
|---|
| 95 |
clk_divider clk_div_0 (.reset(tx_dsp_reset),.in_clk(master_clk),.out_clk(txaclk),.ratio(txa_refclk[6:0])); |
|---|
| 96 |
clk_divider clk_div_1 (.reset(rx_dsp_reset),.in_clk(master_clk),.out_clk(rxaclk),.ratio(rxa_refclk[6:0])); |
|---|
| 97 |
clk_divider clk_div_2 (.reset(tx_dsp_reset),.in_clk(master_clk),.out_clk(txbclk),.ratio(txb_refclk[6:0])); |
|---|
| 98 |
clk_divider clk_div_3 (.reset(rx_dsp_reset),.in_clk(master_clk),.out_clk(rxbclk),.ratio(rxb_refclk[6:0])); |
|---|
| 99 |
|
|---|
| 100 |
reg [15:0] io_0_reg,io_1_reg,io_2_reg,io_3_reg; |
|---|
| 101 |
|
|---|
| 102 |
always @(posedge master_clk) |
|---|
| 103 |
if(serial_strobe) |
|---|
| 104 |
case(serial_addr) |
|---|
| 105 |
`FR_IO_0 : io_0_reg |
|---|
| 106 |
<= #1 (io_0_reg & ~serial_data[31:16]) | (serial_data[15:0] & serial_data[31:16] ); |
|---|
| 107 |
`FR_IO_1 : io_1_reg |
|---|
| 108 |
<= #1 (io_1_reg & ~serial_data[31:16]) | (serial_data[15:0] & serial_data[31:16] ); |
|---|
| 109 |
`FR_IO_2 : io_2_reg |
|---|
| 110 |
<= #1 (io_2_reg & ~serial_data[31:16]) | (serial_data[15:0] & serial_data[31:16] ); |
|---|
| 111 |
`FR_IO_3 : io_3_reg |
|---|
| 112 |
<= #1 (io_3_reg & ~serial_data[31:16]) | (serial_data[15:0] & serial_data[31:16] ); |
|---|
| 113 |
endcase |
|---|
| 114 |
|
|---|
| 115 |
wire transmit_now; |
|---|
| 116 |
wire atr_ctl; |
|---|
| 117 |
wire [11:0] atr_tx_delay, atr_rx_delay; |
|---|
| 118 |
wire [15:0] atr_mask_0, atr_txval_0, atr_rxval_0, atr_mask_1, atr_txval_1, atr_rxval_1, atr_mask_2, atr_txval_2, atr_rxval_2, atr_mask_3, atr_txval_3, atr_rxval_3; |
|---|
| 119 |
|
|---|
| 120 |
setting_reg #(`FR_ATR_MASK_0) sr_atr_mask_0(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_mask_0)); |
|---|
| 121 |
setting_reg #(`FR_ATR_TXVAL_0) sr_atr_txval_0(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_txval_0)); |
|---|
| 122 |
setting_reg #(`FR_ATR_RXVAL_0) sr_atr_rxval_0(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_rxval_0)); |
|---|
| 123 |
|
|---|
| 124 |
setting_reg #(`FR_ATR_MASK_1) sr_atr_mask_1(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_mask_1)); |
|---|
| 125 |
setting_reg #(`FR_ATR_TXVAL_1) sr_atr_txval_1(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_txval_1)); |
|---|
| 126 |
setting_reg #(`FR_ATR_RXVAL_1) sr_atr_rxval_1(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_rxval_1)); |
|---|
| 127 |
|
|---|
| 128 |
setting_reg #(`FR_ATR_MASK_2) sr_atr_mask_2(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_mask_2)); |
|---|
| 129 |
setting_reg #(`FR_ATR_TXVAL_2) sr_atr_txval_2(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_txval_2)); |
|---|
| 130 |
setting_reg #(`FR_ATR_RXVAL_2) sr_atr_rxval_2(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_rxval_2)); |
|---|
| 131 |
|
|---|
| 132 |
setting_reg #(`FR_ATR_MASK_3) sr_atr_mask_3(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_mask_3)); |
|---|
| 133 |
setting_reg #(`FR_ATR_TXVAL_3) sr_atr_txval_3(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_txval_3)); |
|---|
| 134 |
setting_reg #(`FR_ATR_RXVAL_3) sr_atr_rxval_3(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_rxval_3)); |
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
setting_reg #(`FR_ATR_TX_DELAY) sr_atr_tx_delay(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_tx_delay)); |
|---|
| 138 |
setting_reg #(`FR_ATR_RX_DELAY) sr_atr_rx_delay(.clock(master_clk),.reset(1'b0),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(atr_rx_delay)); |
|---|
| 139 |
|
|---|
| 140 |
assign atr_ctl = 1'b1; |
|---|
| 141 |
|
|---|
| 142 |
atr_delay atr_delay(.clk_i(master_clk),.rst_i(tx_dsp_reset),.ena_i(atr_ctl),.tx_empty_i(tx_empty), |
|---|
| 143 |
.tx_delay_i(atr_tx_delay),.rx_delay_i(atr_rx_delay),.atr_tx_o(transmit_now)); |
|---|
| 144 |
|
|---|
| 145 |
wire [15:0] atr_selected_0 = transmit_now ? atr_txval_0 : atr_rxval_0; |
|---|
| 146 |
wire [15:0] io_0 = ({{16{atr_ctl}}} & atr_mask_0 & atr_selected_0) | (~({{16{atr_ctl}}} & atr_mask_0) & io_0_reg); |
|---|
| 147 |
|
|---|
| 148 |
wire [15:0] atr_selected_1 = transmit_now ? atr_txval_1 : atr_rxval_1; |
|---|
| 149 |
wire [15:0] io_1 = ({{16{atr_ctl}}} & atr_mask_1 & atr_selected_1) | (~({{16{atr_ctl}}} & atr_mask_1) & io_1_reg); |
|---|
| 150 |
|
|---|
| 151 |
wire [15:0] atr_selected_2 = transmit_now ? atr_txval_2 : atr_rxval_2; |
|---|
| 152 |
wire [15:0] io_2 = ({{16{atr_ctl}}} & atr_mask_2 & atr_selected_2) | (~({{16{atr_ctl}}} & atr_mask_2) & io_2_reg); |
|---|
| 153 |
|
|---|
| 154 |
wire [15:0] atr_selected_3 = transmit_now ? atr_txval_3 : atr_rxval_3; |
|---|
| 155 |
wire [15:0] io_3 = ({{16{atr_ctl}}} & atr_mask_3 & atr_selected_3) | (~({{16{atr_ctl}}} & atr_mask_3) & io_3_reg); |
|---|
| 156 |
|
|---|
| 157 |
assign reg_0 = debug_en[0] ? debug_0 : txa_refclk[7] ? {io_0[15:1],txaclk} : io_0; |
|---|
| 158 |
assign reg_1 = debug_en[1] ? debug_1 : rxa_refclk[7] ? {io_1[15:1],rxaclk} : io_1; |
|---|
| 159 |
assign reg_2 = debug_en[2] ? debug_2 : txb_refclk[7] ? {io_2[15:1],txbclk} : io_2; |
|---|
| 160 |
assign reg_3 = debug_en[3] ? debug_3 : rxb_refclk[7] ? {io_3[15:1],rxbclk} : io_3; |
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
endmodule |
|---|
| 164 |
|
|---|