diff options
Diffstat (limited to '')
| -rw-r--r-- | bin2bcd.sv | 13 | ||||
| -rw-r--r-- | fibseq.sv | 4 | ||||
| -rw-r--r-- | init.tcl | 1 | ||||
| -rw-r--r-- | jtag_uart.sv | 8 | ||||
| -rw-r--r-- | ntoa.sv | 38 | ||||
| -rw-r--r-- | top.sv | 17 | ||||
| -rw-r--r-- | utils.svh | 5 |
7 files changed, 54 insertions, 32 deletions
| @@ -1,23 +1,24 @@ | |||
| 1 | `include "utils.svh" | ||
| 2 | |||
| 1 | module bin2bcd | 3 | module bin2bcd |
| 2 | #( BITS = 8 | 4 | #( BITS = 8 |
| 3 | , BASE = 10 | 5 | , BASE = 10 |
| 6 | , BASE_BITS = $clog2(BASE) | ||
| 7 | , DIGITS = 3 // should be ceil[log(2**BITS) base BASE] which is hard to do in Verilog :-( | ||
| 4 | , MAX_SKIP = BITS | 8 | , MAX_SKIP = BITS |
| 5 | ) | 9 | ) |
| 6 | ( input bit clk | 10 | ( input bit clk |
| 7 | , input bit reset | 11 | , input bit reset |
| 8 | 12 | ||
| 9 | , output bit bin_ready | 13 | , output bit bin_ready |
| 10 | , input bit bin_valid `define bin_valid $past(bin_valid) | 14 | , input bit bin_valid `define bin_valid `past(bin_valid) |
| 11 | , input bit [BITS-1:0] bin_data `define bin_data $past(bin_data) | 15 | , input bit [BITS-1:0] bin_data `define bin_data `past(bin_data) |
| 12 | 16 | ||
| 13 | , input bit bcd_ready `define bcd_ready $past(bcd_ready) | 17 | , input bit bcd_ready `define bcd_ready `past(bcd_ready) |
| 14 | , output bit bcd_valid | 18 | , output bit bcd_valid |
| 15 | , output bit [DIGITS-1:0][BASE_BITS-1:0] bcd_data | 19 | , output bit [DIGITS-1:0][BASE_BITS-1:0] bcd_data |
| 16 | ); | 20 | ); |
| 17 | 21 | ||
| 18 | localparam BASE_BITS = $clog2(BASE); | ||
| 19 | localparam DIGITS = $rtoi($ceil($ln(1 << BITS) / $ln(BASE))); | ||
| 20 | |||
| 21 | bit bin_b_valid; | 22 | bit bin_b_valid; |
| 22 | bit [BITS-1:0] bin_b_data; | 23 | bit [BITS-1:0] bin_b_data; |
| 23 | 24 | ||
| @@ -1,10 +1,12 @@ | |||
| 1 | `include "utils.svh" | ||
| 2 | |||
| 1 | module fibseq | 3 | module fibseq |
| 2 | #( BITS = 8 | 4 | #( BITS = 8 |
| 3 | ) | 5 | ) |
| 4 | ( input bit clk | 6 | ( input bit clk |
| 5 | , input bit reset | 7 | , input bit reset |
| 6 | 8 | ||
| 7 | , input bit ready `define ready $past(ready) | 9 | , input bit ready `define ready `past(ready) |
| 8 | , output bit valid | 10 | , output bit valid |
| 9 | , output bit [BITS-1:0] data | 11 | , output bit [BITS-1:0] data |
| 10 | ); | 12 | ); |
| @@ -22,5 +22,6 @@ set_global_assignment -name VERILOG_FILE fibseq.sv | |||
| 22 | set_global_assignment -name VERILOG_FILE jtag_uart.sv | 22 | set_global_assignment -name VERILOG_FILE jtag_uart.sv |
| 23 | set_global_assignment -name VERILOG_FILE ntoa.sv | 23 | set_global_assignment -name VERILOG_FILE ntoa.sv |
| 24 | set_global_assignment -name VERILOG_FILE top.sv | 24 | set_global_assignment -name VERILOG_FILE top.sv |
| 25 | set_global_assignment -name VERILOG_FILE utils.svh | ||
| 25 | 26 | ||
| 26 | project_close | 27 | project_close |
diff --git a/jtag_uart.sv b/jtag_uart.sv index ddb5ecb..5c4857d 100644 --- a/jtag_uart.sv +++ b/jtag_uart.sv | |||
| @@ -1,3 +1,5 @@ | |||
| 1 | `include "utils.svh" | ||
| 2 | |||
| 1 | module jtag_uart | 3 | module jtag_uart |
| 2 | #( INSTANCE = 0 | 4 | #( INSTANCE = 0 |
| 3 | 5 | ||
| @@ -7,13 +9,13 @@ module jtag_uart | |||
| 7 | ( input bit clk | 9 | ( input bit clk |
| 8 | , input bit reset | 10 | , input bit reset |
| 9 | 11 | ||
| 10 | , input bit rx_ready `define rx_ready $past(rx_ready) | 12 | , input bit rx_ready `define rx_ready `past(rx_ready) |
| 11 | , output bit rx_valid | 13 | , output bit rx_valid |
| 12 | , output bit [7:0] rx_data | 14 | , output bit [7:0] rx_data |
| 13 | 15 | ||
| 14 | , output bit tx_ready | 16 | , output bit tx_ready |
| 15 | , input bit tx_valid `define tx_valid $past(tx_valid) | 17 | , input bit tx_valid `define tx_valid `past(tx_valid) |
| 16 | , input bit [7:0] tx_data `define tx_data $past(tx_data) | 18 | , input bit [7:0] tx_data `define tx_data `past(tx_data) |
| 17 | ); | 19 | ); |
| 18 | 20 | ||
| 19 | `ifdef SYNTHESIS | 21 | `ifdef SYNTHESIS |
| @@ -1,26 +1,32 @@ | |||
| 1 | `include "utils.svh" | ||
| 2 | |||
| 1 | module ntoa | 3 | module ntoa |
| 2 | #( BITS = 8 | 4 | #( BITS = 8 |
| 3 | , BASE = 10 | 5 | , BASE = 10 |
| 6 | , BASE_BITS = $clog2(BASE) | ||
| 7 | , DIGITS = 3 // should be ceil[log(2**BITS) base BASE] which is hard to do in Verilog :-( | ||
| 4 | ) | 8 | ) |
| 5 | ( input bit clk | 9 | ( input bit clk |
| 6 | , input bit reset | 10 | , input bit reset |
| 7 | 11 | ||
| 8 | , output bit n_ready | 12 | , output bit n_ready |
| 9 | , input bit n_valid `define n_valid $past(n_valid) | 13 | , input bit n_valid `define n_valid `past(n_valid) |
| 10 | , input bit [BITS-1:0] n_data `define n_data $past(n_data) | 14 | , input bit [BITS-1:0] n_data `define n_data `past(n_data) |
| 11 | 15 | ||
| 12 | , input bit a_ready `define a_ready $past(a_ready) | 16 | , input bit a_ready `define a_ready `past(a_ready) |
| 13 | , output bit a_valid | 17 | , output bit a_valid |
| 14 | , output bit [7:0] a_data | 18 | , output bit [7:0] a_data |
| 15 | ); | 19 | ); |
| 16 | 20 | ||
| 17 | bit bcd_ready; | 21 | bit bcd_ready; |
| 18 | bit bcd_valid; | 22 | bit bcd_valid; |
| 19 | bit [b2b.DIGITS-1:0][b2b.BASE_BITS-1:0] bcd_data; | 23 | bit [DIGITS-1:0][BASE_BITS-1:0] bcd_data; |
| 20 | 24 | ||
| 21 | bin2bcd | 25 | bin2bcd |
| 22 | #( .BITS(BITS) | 26 | #( .BITS(BITS) |
| 23 | , .BASE(BASE) | 27 | , .BASE(BASE) |
| 28 | , .BASE_BITS(BASE_BITS) | ||
| 29 | , .DIGITS(DIGITS) | ||
| 24 | ) b2b | 30 | ) b2b |
| 25 | ( .clk(clk) | 31 | ( .clk(clk) |
| 26 | , .reset(reset) | 32 | , .reset(reset) |
| @@ -30,14 +36,14 @@ bin2bcd | |||
| 30 | , .bin_data(n_data) | 36 | , .bin_data(n_data) |
| 31 | 37 | ||
| 32 | , .bcd_ready(bcd_ready) | 38 | , .bcd_ready(bcd_ready) |
| 33 | , .bcd_valid(bcd_valid) `define bcd_valid $past(bcd_valid) | 39 | , .bcd_valid(bcd_valid) `define bcd_valid `past(bcd_valid) |
| 34 | , .bcd_data(bcd_data) `define bcd_data $past(bcd_data) | 40 | , .bcd_data(bcd_data) `define bcd_data `past(bcd_data) |
| 35 | ); | 41 | ); |
| 36 | 42 | ||
| 37 | bit bcd_b_valid; | 43 | bit bcd_b_valid; |
| 38 | bit [b2b.DIGITS-1:0][b2b.BASE_BITS-1:0] bcd_b_data; | 44 | bit [DIGITS-1:0][BASE_BITS-1:0] bcd_b_data; |
| 39 | 45 | ||
| 40 | bit [$clog2(b2b.DIGITS):0] work; | 46 | bit [$clog2(DIGITS):0] work; |
| 41 | 47 | ||
| 42 | always_ff @(posedge clk) begin | 48 | always_ff @(posedge clk) begin |
| 43 | if (reset) begin | 49 | if (reset) begin |
| @@ -49,11 +55,11 @@ always_ff @(posedge clk) begin | |||
| 49 | bcd_b_valid = 1; | 55 | bcd_b_valid = 1; |
| 50 | bcd_b_data = `bcd_data; | 56 | bcd_b_data = `bcd_data; |
| 51 | // verilator lint_off WIDTH | 57 | // verilator lint_off WIDTH |
| 52 | work = b2b.DIGITS; | 58 | work = DIGITS; |
| 53 | // verilator lint_on WIDTH | 59 | // verilator lint_on WIDTH |
| 54 | for (int i = 0; i < b2b.DIGITS - 1; ++i) begin | 60 | for (int i = 0; i < DIGITS - 1; ++i) begin |
| 55 | if (bcd_b_data[b2b.DIGITS-1] != 0) break; | 61 | if (bcd_b_data[DIGITS-1] != 0) break; |
| 56 | bcd_b_data = { bcd_b_data[b2b.DIGITS-2:0], {b2b.BASE_BITS{1'b0}} }; | 62 | bcd_b_data = { bcd_b_data[DIGITS-2:0], {BASE_BITS{1'b0}} }; |
| 57 | --work; | 63 | --work; |
| 58 | end | 64 | end |
| 59 | end | 65 | end |
| @@ -63,12 +69,12 @@ always_ff @(posedge clk) begin | |||
| 63 | if (work != 0) begin | 69 | if (work != 0) begin |
| 64 | a_valid = 1; | 70 | a_valid = 1; |
| 65 | // verilator lint_off WIDTH | 71 | // verilator lint_off WIDTH |
| 66 | if (bcd_b_data[b2b.DIGITS-1] < 10) | 72 | if (bcd_b_data[DIGITS-1] < 10) |
| 67 | a_data = "0" + bcd_b_data[b2b.DIGITS-1]; | 73 | a_data = "0" + bcd_b_data[DIGITS-1]; |
| 68 | else | 74 | else |
| 69 | a_data = "a" + bcd_b_data[b2b.DIGITS-1] - 10; | 75 | a_data = "a" + bcd_b_data[DIGITS-1] - 10; |
| 70 | // verilator lint_off WIDTH | 76 | // verilator lint_off WIDTH |
| 71 | bcd_b_data = { bcd_b_data[b2b.DIGITS-2:0], {b2b.BASE_BITS{1'b0}} }; | 77 | bcd_b_data = { bcd_b_data[DIGITS-2:0], {BASE_BITS{1'b0}} }; |
| 72 | --work; | 78 | --work; |
| 73 | end else begin | 79 | end else begin |
| 74 | a_valid = 1; | 80 | a_valid = 1; |
| @@ -1,6 +1,10 @@ | |||
| 1 | `include "utils.svh" | ||
| 2 | |||
| 1 | module top | 3 | module top |
| 2 | #( FIB_BITS = 16 | 4 | #( FIB_BITS = 16 |
| 3 | , FIB_BASE = 10 | 5 | , FIB_BASE = 10 |
| 6 | , FIB_DIGITS = 5 | ||
| 7 | |||
| 4 | , ROM_BITS = 8 | 8 | , ROM_BITS = 8 |
| 5 | ) | 9 | ) |
| 6 | ( input bit clk // verilator public | 10 | ( input bit clk // verilator public |
| @@ -30,10 +34,10 @@ jtag_uart | |||
| 30 | , .reset(reset) | 34 | , .reset(reset) |
| 31 | 35 | ||
| 32 | , .rx_ready(rx_ready) | 36 | , .rx_ready(rx_ready) |
| 33 | , .rx_valid(rx_valid) `define rx_valid $past(rx_valid) | 37 | , .rx_valid(rx_valid) `define rx_valid `past(rx_valid) |
| 34 | , .rx_data(rx_data) `define rx_data $past(rx_data) | 38 | , .rx_data(rx_data) `define rx_data `past(rx_data) |
| 35 | 39 | ||
| 36 | , .tx_ready(tx_ready) `define tx_ready $past(tx_ready) | 40 | , .tx_ready(tx_ready) `define tx_ready `past(tx_ready) |
| 37 | , .tx_valid(tx_valid) | 41 | , .tx_valid(tx_valid) |
| 38 | , .tx_data(tx_data) | 42 | , .tx_data(tx_data) |
| 39 | ); | 43 | ); |
| @@ -60,6 +64,7 @@ bit [7:0] fib_a_data; | |||
| 60 | ntoa | 64 | ntoa |
| 61 | #( .BITS(FIB_BITS) | 65 | #( .BITS(FIB_BITS) |
| 62 | , .BASE(FIB_BASE) | 66 | , .BASE(FIB_BASE) |
| 67 | , .DIGITS(FIB_DIGITS) | ||
| 63 | ) fib_ntoa | 68 | ) fib_ntoa |
| 64 | ( .clk(clk) | 69 | ( .clk(clk) |
| 65 | , .reset(reset) | 70 | , .reset(reset) |
| @@ -69,8 +74,8 @@ ntoa | |||
| 69 | , .n_data(fib_data) | 74 | , .n_data(fib_data) |
| 70 | 75 | ||
| 71 | , .a_ready(fib_a_ready) | 76 | , .a_ready(fib_a_ready) |
| 72 | , .a_valid(fib_a_valid) `define fib_a_valid $past(fib_a_valid) | 77 | , .a_valid(fib_a_valid) `define fib_a_valid `past(fib_a_valid) |
| 73 | , .a_data(fib_a_data) `define fib_a_data $past(fib_a_data) | 78 | , .a_data(fib_a_data) `define fib_a_data `past(fib_a_data) |
| 74 | ); | 79 | ); |
| 75 | 80 | ||
| 76 | enum | 81 | enum |
| @@ -91,7 +96,7 @@ always_ff @(posedge clk) begin | |||
| 91 | fib_a_ready = 0; | 96 | fib_a_ready = 0; |
| 92 | state = state.first; | 97 | state = state.first; |
| 93 | tmp_valid = 0; | 98 | tmp_valid = 0; |
| 94 | end else unique0 case (state) | 99 | end else case (state) |
| 95 | 100 | ||
| 96 | INTRO_ECHO, INTRO_FIB: begin | 101 | INTRO_ECHO, INTRO_FIB: begin |
| 97 | automatic bit [7:0] data = rom[addr]; | 102 | automatic bit [7:0] data = rom[addr]; |
diff --git a/utils.svh b/utils.svh new file mode 100644 index 0000000..ddba543 --- /dev/null +++ b/utils.svh | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | `ifdef SYNTHESIS | ||
| 2 | `define past(x) x | ||
| 3 | `else | ||
| 4 | `define past(x) $past(x) | ||
| 5 | `endif | ||
