-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Paul Scheffler <[email protected]>
- Loading branch information
Showing
6 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2020 ETH Zurich and University of Bologna. | ||
// Solderpad Hardware License, Version 0.51, see LICENSE for details. | ||
// SPDX-License-Identifier: SHL-0.51 | ||
|
||
// Author: Fabian Schuiki <[email protected]> | ||
// Author: Paul Scheffler <[email protected]> | ||
|
||
`include "common_cells/registers.svh" | ||
`include "common_cells/assertions.svh" | ||
|
||
module credit_counter #( | ||
parameter int unsigned NumCredits = 0, | ||
/// Whether credit is full or empty on reset | ||
parameter bit InitCreditEmpty = 1'b0, | ||
/// Derived parameters *Do not override* | ||
parameter int unsigned InitNumCredits = InitCreditEmpty ? '0 : NumCredits, | ||
parameter type credit_cnt_t = logic [$clog2(NumCredits):0] | ||
) ( | ||
input logic clk_i, | ||
input logic rst_ni, | ||
|
||
output credit_cnt_t credit_o, | ||
|
||
input logic credit_give_i, | ||
input logic credit_take_i, | ||
input logic credit_init_i, // Reinitialize (soft-reset) credit; takes priority | ||
|
||
output logic credit_left_o, | ||
output logic credit_crit_o, // Giving one more credit will fill the credits | ||
output logic credit_full_o | ||
); | ||
|
||
credit_cnt_t credit_d, credit_q; | ||
logic increment, decrement; | ||
|
||
assign decrement = credit_take_i & ~credit_give_i; | ||
assign increment = ~credit_take_i & credit_give_i; | ||
|
||
always_comb begin | ||
credit_d = credit_q; | ||
if (decrement) credit_d = credit_q - 1; | ||
else if (increment) credit_d = credit_q + 1; | ||
end | ||
|
||
logic credit_load; | ||
assign credit_load = 1'b1; | ||
`FFLARNC(credit_q, credit_d, credit_load, credit_init_i, InitNumCredits, clk_i, rst_ni) | ||
|
||
assign credit_o = credit_q; | ||
assign credit_left_o = (credit_q != '0); | ||
assign credit_crit_o = (credit_q == NumCredits-1); | ||
assign credit_full_o = (credit_q == NumCredits); | ||
|
||
`ASSERT_NEVER(CreditUnderflow, credit_o == '0 && decrement) | ||
`ASSERT_NEVER(CreditOverflow, credit_o == NumCredits && increment) | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters