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 /bin2bcd.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 'bin2bcd.sv')
| -rw-r--r-- | bin2bcd.sv | 13 |
1 files changed, 7 insertions, 6 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 | ||
