root / usrp2 / timing / time_64bit.v @ cc1f4638
History | View | Annotate | Download (4.29 KB)
| 1 | 350d6bf4 | matt | |
|---|---|---|---|
| 2 | |||
| 3 | module time_64bit |
||
| 4 | #(parameter TICKS_PER_SEC = 32'd100000000, |
||
| 5 | parameter BASE = 0) |
||
| 6 | 8fbedd86 | Matt Ettus | (input clk, input rst, |
| 7 | input set_stb, input [7:0] set_addr, input [31:0] set_data, |
||
| 8 | input pps, |
||
| 9 | cc1f4638 | Matt Ettus | output [63:0] vita_time, |
| 10 | output reg [63:0] vita_time_pps, |
||
| 11 | output pps_int, |
||
| 12 | c9744083 | Matt Ettus | input exp_time_in, output exp_time_out, |
| 13 | output [31:0] debug |
||
| 14 | 8fbedd86 | Matt Ettus | ); |
| 15 | |||
| 16 | 75f85f71 | Matt Ettus | localparam NEXT_SECS = 0; |
| 17 | 1dc61299 | Matt Ettus | localparam NEXT_TICKS = 1; |
| 18 | 58e21876 | Matt Ettus | localparam PPS_POLSRC = 2; |
| 19 | localparam PPS_IMM = 3; |
||
| 20 | 9560e541 | Matt Ettus | localparam TPS = 4; |
| 21 | 003df1ee | Matt Ettus | localparam MIMO_SYNC = 5; |
| 22 | 1dc61299 | Matt Ettus | |
| 23 | 9560e541 | Matt Ettus | reg [31:0] seconds, ticks; |
| 24 | 75f85f71 | Matt Ettus | wire end_of_second; |
| 25 | 350d6bf4 | matt | assign vita_time = {seconds,ticks};
|
| 26 | 003df1ee | Matt Ettus | wire [63:0] vita_time_rcvd; |
| 27 | 350d6bf4 | matt | |
| 28 | 9560e541 | Matt Ettus | wire [31:0] next_ticks_preset, next_seconds_preset; |
| 29 | wire [31:0] ticks_per_sec_reg; |
||
| 30 | 350d6bf4 | matt | wire set_on_pps_trig; |
| 31 | reg set_on_next_pps; |
||
| 32 | 9560e541 | Matt Ettus | wire pps_polarity, pps_source, set_imm; |
| 33 | 003df1ee | Matt Ettus | reg [1:0] pps_del; |
| 34 | reg pps_reg_p, pps_reg_n, pps_reg; |
||
| 35 | wire pps_edge; |
||
| 36 | |||
| 37 | reg [15:0] sync_counter; |
||
| 38 | wire sync_rcvd; |
||
| 39 | wire [31:0] mimo_secs, mimo_ticks; |
||
| 40 | wire mimo_sync_now; |
||
| 41 | wire mimo_sync; |
||
| 42 | wire [7:0] sync_delay; |
||
| 43 | 58e21876 | Matt Ettus | |
| 44 | 350d6bf4 | matt | setting_reg #(.my_addr(BASE+NEXT_TICKS)) sr_next_ticks |
| 45 | (.clk(clk),.rst(rst),.strobe(set_stb),.addr(set_addr), |
||
| 46 | .in(set_data),.out(next_ticks_preset),.changed()); |
||
| 47 | |||
| 48 | setting_reg #(.my_addr(BASE+NEXT_SECS)) sr_next_secs |
||
| 49 | (.clk(clk),.rst(rst),.strobe(set_stb),.addr(set_addr), |
||
| 50 | .in(set_data),.out(next_seconds_preset),.changed(set_on_pps_trig)); |
||
| 51 | 1dc61299 | Matt Ettus | |
| 52 | 9560e541 | Matt Ettus | setting_reg #(.my_addr(BASE+PPS_POLSRC), .width(2)) sr_pps_polsrc |
| 53 | 58e21876 | Matt Ettus | (.clk(clk),.rst(rst),.strobe(set_stb),.addr(set_addr), |
| 54 | .in(set_data),.out({pps_source,pps_polarity}),.changed());
|
||
| 55 | |||
| 56 | 9560e541 | Matt Ettus | setting_reg #(.my_addr(BASE+PPS_IMM), .width(1)) sr_pps_imm |
| 57 | 1dc61299 | Matt Ettus | (.clk(clk),.rst(rst),.strobe(set_stb),.addr(set_addr), |
| 58 | 58e21876 | Matt Ettus | .in(set_data),.out(set_imm),.changed()); |
| 59 | 1dc61299 | Matt Ettus | |
| 60 | 9560e541 | Matt Ettus | setting_reg #(.my_addr(BASE+TPS), .at_reset(TICKS_PER_SEC)) sr_tps |
| 61 | (.clk(clk),.rst(rst),.strobe(set_stb),.addr(set_addr), |
||
| 62 | .in(set_data),.out(ticks_per_sec_reg),.changed()); |
||
| 63 | |||
| 64 | 003df1ee | Matt Ettus | setting_reg #(.my_addr(BASE+MIMO_SYNC), .at_reset(0), .width(9)) sr_mimosync |
| 65 | (.clk(clk),.rst(rst),.strobe(set_stb),.addr(set_addr), |
||
| 66 | .in(set_data),.out({mimo_sync,sync_delay}),.changed());
|
||
| 67 | |||
| 68 | 1dc61299 | Matt Ettus | always @(posedge clk) pps_reg_p <= pps; |
| 69 | always @(negedge clk) pps_reg_n <= pps; |
||
| 70 | always @* pps_reg <= pps_polarity ? pps_reg_p : pps_reg_n; |
||
| 71 | |||
| 72 | always @(posedge clk) |
||
| 73 | if(rst) |
||
| 74 | pps_del <= 2'b00; |
||
| 75 | else |
||
| 76 | pps_del <= {pps_del[0],pps_reg};
|
||
| 77 | |||
| 78 | assign pps_edge = pps_del[0] & ~pps_del[1]; |
||
| 79 | cc1f4638 | Matt Ettus | |
| 80 | always @(posedge clk) |
||
| 81 | if(pps_edge) |
||
| 82 | vita_time_pps <= vita_time; |
||
| 83 | 350d6bf4 | matt | |
| 84 | always @(posedge clk) |
||
| 85 | if(rst) |
||
| 86 | set_on_next_pps <= 0; |
||
| 87 | else if(set_on_pps_trig) |
||
| 88 | set_on_next_pps <= 1; |
||
| 89 | 7ebcf79e | Matt Ettus | else if(set_imm | pps_edge) |
| 90 | 350d6bf4 | matt | set_on_next_pps <= 0; |
| 91 | 9560e541 | Matt Ettus | |
| 92 | wire [31:0] ticks_plus_one = ticks + 1; |
||
| 93 | 350d6bf4 | matt | |
| 94 | always @(posedge clk) |
||
| 95 | if(rst) |
||
| 96 | begin |
||
| 97 | seconds <= 32'd0; |
||
| 98 | ticks <= 32'd0; |
||
| 99 | end |
||
| 100 | 7ebcf79e | Matt Ettus | else if((set_imm | pps_edge) & set_on_next_pps) |
| 101 | 350d6bf4 | matt | begin |
| 102 | seconds <= next_seconds_preset; |
||
| 103 | ticks <= next_ticks_preset; |
||
| 104 | end |
||
| 105 | 003df1ee | Matt Ettus | else if(mimo_sync_now) |
| 106 | begin |
||
| 107 | seconds <= mimo_secs; |
||
| 108 | ticks <= mimo_ticks; |
||
| 109 | end |
||
| 110 | 9560e541 | Matt Ettus | else if(ticks_plus_one == ticks_per_sec_reg) |
| 111 | 350d6bf4 | matt | begin |
| 112 | seconds <= seconds + 1; |
||
| 113 | ticks <= 0; |
||
| 114 | end |
||
| 115 | else |
||
| 116 | 9560e541 | Matt Ettus | ticks <= ticks_plus_one; |
| 117 | 1dc61299 | Matt Ettus | |
| 118 | assign pps_int = pps_edge; |
||
| 119 | 8fbedd86 | Matt Ettus | |
| 120 | 003df1ee | Matt Ettus | // MIMO Connector Time Sync |
| 121 | wire send_sync = (sync_counter == 59999); // X % 10 = 9 |
||
| 122 | |||
| 123 | 8fbedd86 | Matt Ettus | always @(posedge clk) |
| 124 | if(rst) |
||
| 125 | sync_counter <= 0; |
||
| 126 | else |
||
| 127 | if(send_sync) |
||
| 128 | sync_counter <= 0; |
||
| 129 | else |
||
| 130 | sync_counter <= sync_counter + 1; |
||
| 131 | |||
| 132 | time_sender time_sender |
||
| 133 | (.clk(clk),.rst(rst), |
||
| 134 | .vita_time(vita_time), |
||
| 135 | .send_sync(send_sync), |
||
| 136 | 19073f68 | Matt Ettus | .exp_time_out(exp_time_out) ); |
| 137 | 8fbedd86 | Matt Ettus | |
| 138 | time_receiver time_receiver |
||
| 139 | (.clk(clk),.rst(rst), |
||
| 140 | .vita_time(vita_time_rcvd), |
||
| 141 | .sync_rcvd(sync_rcvd), |
||
| 142 | 19073f68 | Matt Ettus | .exp_time_in(exp_time_in) ); |
| 143 | 8fbedd86 | Matt Ettus | |
| 144 | 003df1ee | Matt Ettus | assign mimo_secs = vita_time_rcvd[63:32]; |
| 145 | assign mimo_ticks = vita_time_rcvd[31:0] + {16'd0,sync_delay};
|
||
| 146 | assign mimo_sync_now = mimo_sync & sync_rcvd & (mimo_ticks <= TICKS_PER_SEC); |
||
| 147 | c9744083 | Matt Ettus | |
| 148 | assign debug = { { 24'b0} ,
|
||
| 149 | { 2'b0, exp_time_in, exp_time_out, mimo_sync, mimo_sync_now, sync_rcvd, send_sync} };
|
||
| 150 | 350d6bf4 | matt | |
| 151 | endmodule // time_64bit |