diff options
| author | Julian Blake Kongslie | 2022-02-16 14:44:01 -0800 |
|---|---|---|
| committer | Julian Blake Kongslie | 2022-02-16 14:44:01 -0800 |
| commit | 92420e248d4449a2aa61e92f05c0867912d48d56 (patch) | |
| tree | 889d0af684d648713cd1ae68b5b2c550d2b6dc7f /hdl/result_printer.sv | |
| parent | Complete rewrite to break out the separate state machines and fix timing (diff) | |
| download | simple-memory-controller-92420e248d4449a2aa61e92f05c0867912d48d56.tar.xz | |
Split into multiple files.
Diffstat (limited to 'hdl/result_printer.sv')
| -rw-r--r-- | hdl/result_printer.sv | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/hdl/result_printer.sv b/hdl/result_printer.sv new file mode 100644 index 0000000..7bcaf31 --- /dev/null +++ b/hdl/result_printer.sv | |||
| @@ -0,0 +1,55 @@ | |||
| 1 | module result_printer | ||
| 2 | ( input bit clock | ||
| 3 | , input bit resetn | ||
| 4 | |||
| 5 | , output bit result_ready | ||
| 6 | , input bit result_valid | ||
| 7 | , input bit [15:0] result_data | ||
| 8 | |||
| 9 | , input bit echo_ready | ||
| 10 | , output bit echo_valid | ||
| 11 | , output bit [7:0] echo_data | ||
| 12 | ); | ||
| 13 | |||
| 14 | bit hold_valid; | ||
| 15 | bit [15:0] hold; | ||
| 16 | |||
| 17 | enum | ||
| 18 | { DIGIT_1 | ||
| 19 | , DIGIT_2 | ||
| 20 | , DIGIT_3 | ||
| 21 | , DIGIT_4 | ||
| 22 | } state; | ||
| 23 | |||
| 24 | always @(posedge clock) begin | ||
| 25 | if (!resetn) begin | ||
| 26 | result_ready = 0; | ||
| 27 | echo_valid = 0; | ||
| 28 | echo_data = 0; | ||
| 29 | hold_valid = 0; | ||
| 30 | hold = 0; | ||
| 31 | state = state.first; | ||
| 32 | end else begin | ||
| 33 | if (echo_ready) echo_valid = 0; | ||
| 34 | if (result_ready && result_valid) begin | ||
| 35 | hold_valid = 1; | ||
| 36 | hold = result_data; | ||
| 37 | end | ||
| 38 | |||
| 39 | if (hold_valid && !echo_valid) begin | ||
| 40 | echo_valid = 1; | ||
| 41 | echo_data = hold[15:12]; | ||
| 42 | hold = hold << 4; | ||
| 43 | if (echo_data < 10) | ||
| 44 | echo_data = echo_data + "0"; | ||
| 45 | else | ||
| 46 | echo_data = echo_data + "A" - 10; | ||
| 47 | state = state.next; | ||
| 48 | if (state == state.first) hold_valid = 0; | ||
| 49 | end | ||
| 50 | |||
| 51 | result_ready = !hold_valid; | ||
| 52 | end | ||
| 53 | end | ||
| 54 | |||
| 55 | endmodule | ||
