diff options
| author | Julian Blake Kongslie | 2022-03-28 10:36:35 -0700 |
|---|---|---|
| committer | Julian Blake Kongslie | 2022-03-28 10:36:35 -0700 |
| commit | 6aff3f26db8d8477ed7cab43b9dc03473627b172 (patch) | |
| tree | a34cac5fe8e224e3a9582c6dab6c18462acf947e | |
| parent | Update PLAN. (diff) | |
| download | multipdp8-6aff3f26db8d8477ed7cab43b9dc03473627b172.tar.xz | |
Integrate wrap bits into grey code for FIFO.
| -rw-r--r-- | hdl/fifo.sv | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/hdl/fifo.sv b/hdl/fifo.sv index a067914..374f051 100644 --- a/hdl/fifo.sv +++ b/hdl/fifo.sv | |||
| @@ -19,13 +19,14 @@ module fifo | |||
| 19 | 19 | ||
| 20 | typedef bit [WIDTH_BITS-1:0] data_t; | 20 | typedef bit [WIDTH_BITS-1:0] data_t; |
| 21 | typedef bit [DEPTH_BITS-1:0] addr_t; | 21 | typedef bit [DEPTH_BITS-1:0] addr_t; |
| 22 | typedef bit [DEPTH_BITS:0] grey_t; | ||
| 22 | 23 | ||
| 23 | data_t data [DEPTH-1:0]; | 24 | data_t data [DEPTH-1:0]; |
| 24 | 25 | ||
| 25 | addr_t oldest, youngest; | 26 | addr_t oldest, youngest; |
| 26 | bit oldest_wrap, youngest_wrap; | 27 | bit oldest_wrap, youngest_wrap; |
| 27 | 28 | ||
| 28 | addr_t oldest_grey, youngest_grey; | 29 | grey_t oldest_grey, oldest_plus_one_wrap_grey, youngest_grey; |
| 29 | 30 | ||
| 30 | always @(posedge clock_in, posedge reset) begin | 31 | always @(posedge clock_in, posedge reset) begin |
| 31 | if (reset) begin | 32 | if (reset) begin |
| @@ -40,9 +41,9 @@ module fifo | |||
| 40 | ++youngest_wrap; | 41 | ++youngest_wrap; |
| 41 | end | 42 | end |
| 42 | 43 | ||
| 43 | youngest_grey = youngest ^ (youngest >> 1); | 44 | youngest_grey = {youngest_wrap, youngest} ^ ({youngest_grey, youngest} >> 1); |
| 44 | 45 | ||
| 45 | in_ready = oldest_grey != youngest_grey || youngest_wrap == oldest_wrap; | 46 | in_ready = oldest_plus_one_wrap_grey != youngest_grey; |
| 46 | end | 47 | end |
| 47 | end | 48 | end |
| 48 | 49 | ||
| @@ -52,15 +53,17 @@ module fifo | |||
| 52 | oldest = 0; | 53 | oldest = 0; |
| 53 | oldest_wrap = 0; | 54 | oldest_wrap = 0; |
| 54 | oldest_grey = 0; | 55 | oldest_grey = 0; |
| 56 | oldest_plus_one_wrap_grey = {!oldest_wrap, oldest} ^ ({!oldest_wrap, oldest} >> 1); | ||
| 55 | end else begin | 57 | end else begin |
| 56 | if (out_ready && out_valid) begin | 58 | if (out_ready && out_valid) begin |
| 57 | if (++oldest == 0) | 59 | if (++oldest == 0) |
| 58 | ++oldest_wrap; | 60 | ++oldest_wrap; |
| 59 | end | 61 | end |
| 60 | 62 | ||
| 61 | oldest_grey = oldest ^ (oldest >> 1); | 63 | oldest_grey = {oldest_grey, oldest} ^ ({oldest_grey, oldest} >> 1); |
| 64 | oldest_plus_one_wrap_grey = {!oldest_wrap, oldest} ^ ({!oldest_wrap, oldest} >> 1); | ||
| 62 | 65 | ||
| 63 | out_valid = oldest_grey != youngest_grey || youngest_wrap != oldest_wrap; | 66 | out_valid = oldest_grey != youngest_grey; |
| 64 | out_data = data[oldest]; | 67 | out_data = data[oldest]; |
| 65 | end | 68 | end |
| 66 | end | 69 | end |
