diff options
| author | Julian Blake Kongslie | 2021-03-23 21:52:41 -0700 |
|---|---|---|
| committer | Julian Blake Kongslie | 2021-03-23 21:54:44 -0700 |
| commit | 8056863ce3e95db52e027a0f0babe51df1cb9a4e (patch) | |
| tree | d35ce72f92e8a9b6f1dce49572a49b3117c5827e /ntoa.sv | |
| parent | Adding olamic hook to autobuild source archives. (diff) | |
| download | toycpu-8056863ce3e95db52e027a0f0babe51df1cb9a4e.tar.xz | |
Additional cleanup to make it Quartus-friendly.
Diffstat (limited to '')
| -rw-r--r-- | ntoa.sv | 38 |
1 files changed, 22 insertions, 16 deletions
| @@ -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; |
