Skip to content

Commit 77a086f

Browse files
micprogpaulsc96niwis
authored
Add credit_counter (#225)
* Add credit_counter Co-authored-by: Paul Scheffler <[email protected]> * credit_counter: replace FFLARNC with FFARNC Co-authored-by: Nils Wistoff <[email protected]> --------- Co-authored-by: Paul Scheffler <[email protected]> Co-authored-by: Nils Wistoff <[email protected]>
1 parent be3866e commit 77a086f

File tree

6 files changed

+63
-0
lines changed

6 files changed

+63
-0
lines changed

Bender.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ sources:
3232
- src/cdc_reset_ctrlr_pkg.sv
3333
- src/cf_math_pkg.sv
3434
- src/clk_int_div.sv
35+
- src/credit_counter.sv
3536
- src/delta_counter.sv
3637
- src/ecc_pkg.sv
3738
- src/edge_propagator_tx.sv

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## Unreleased
8+
### Added
9+
- `credit_counter`: Add up/down counter for credit.
10+
711
## 1.36.0 - 2024-07-08
812
### Fixed
913
- `registers`: Fix else statement in FFARNC macro.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Please note that cells with status *deprecated* are not to be used for new desig
5555
| Name | Description | Status | Superseded By |
5656
| ------------------- | ----------------------------------------------------------------- | ------------ | ------------- |
5757
| `counter` | Generic up/down counter with overflow detection | active | |
58+
| `credit_counter` | Up/down counter for credit | active | |
5859
| `delta_counter` | Up/down counter with variable delta and overflow detection | active | |
5960
| `generic_LFSR_8bit` | 8-bit linear feedback shift register (LFSR) | *deprecated* | `lfsr_8bit` |
6061
| `lfsr_8bit` | 8-bit linear feedback shift register (LFSR) | active | |

common_cells.core

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ filesets:
1616
- src/cc_onehot.sv
1717
- src/cf_math_pkg.sv
1818
- src/clk_int_div.sv
19+
- src/credit_counter.sv
1920
- src/delta_counter.sv
2021
- src/ecc_pkg.sv
2122
- src/edge_propagator_tx.sv

src/credit_counter.sv

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2020 ETH Zurich and University of Bologna.
2+
// Solderpad Hardware License, Version 0.51, see LICENSE for details.
3+
// SPDX-License-Identifier: SHL-0.51
4+
5+
// Author: Fabian Schuiki <[email protected]>
6+
// Author: Paul Scheffler <[email protected]>
7+
8+
`include "common_cells/registers.svh"
9+
`include "common_cells/assertions.svh"
10+
11+
module credit_counter #(
12+
parameter int unsigned NumCredits = 0,
13+
/// Whether credit is full or empty on reset
14+
parameter bit InitCreditEmpty = 1'b0,
15+
/// Derived parameters *Do not override*
16+
parameter int unsigned InitNumCredits = InitCreditEmpty ? '0 : NumCredits,
17+
parameter type credit_cnt_t = logic [$clog2(NumCredits):0]
18+
) (
19+
input logic clk_i,
20+
input logic rst_ni,
21+
22+
output credit_cnt_t credit_o,
23+
24+
input logic credit_give_i,
25+
input logic credit_take_i,
26+
input logic credit_init_i, // Reinitialize (soft-reset) credit; takes priority
27+
28+
output logic credit_left_o,
29+
output logic credit_crit_o, // Giving one more credit will fill the credits
30+
output logic credit_full_o
31+
);
32+
33+
credit_cnt_t credit_d, credit_q;
34+
logic increment, decrement;
35+
36+
assign decrement = credit_take_i & ~credit_give_i;
37+
assign increment = ~credit_take_i & credit_give_i;
38+
39+
always_comb begin
40+
credit_d = credit_q;
41+
if (decrement) credit_d = credit_q - 1;
42+
else if (increment) credit_d = credit_q + 1;
43+
end
44+
45+
`FFARNC(credit_q, credit_d, credit_init_i, InitNumCredits, clk_i, rst_ni)
46+
47+
assign credit_o = credit_q;
48+
assign credit_left_o = (credit_q != '0);
49+
assign credit_crit_o = (credit_q == NumCredits-1);
50+
assign credit_full_o = (credit_q == NumCredits);
51+
52+
`ASSERT_NEVER(CreditUnderflow, credit_o == '0 && decrement)
53+
`ASSERT_NEVER(CreditOverflow, credit_o == NumCredits && increment)
54+
55+
endmodule

src_files.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ common_cells_all:
1111
- src/cc_onehot.sv
1212
- src/cf_math_pkg.sv
1313
- src/clk_int_div.sv
14+
- src/credit_counter.sv
1415
- src/delta_counter.sv
1516
- src/ecc_pkg.sv
1617
- src/edge_propagator_tx.sv

0 commit comments

Comments
 (0)