hw/ip/alert_handler/rtl/alert_handler_accu.sv Cov: 100%

   1: // Copyright lowRISC contributors.
   2: // Licensed under the Apache License, Version 2.0, see LICENSE for details.
   3: // SPDX-License-Identifier: Apache-2.0
   4: //
   5: // This module accumulates incoming alert triggers. Once the current accumulator
   6: // value is greater or equal the accumulator threshold, the next occurence of
   7: // class_trig_i will trigger escalation.
   8: //
   9: // Note that the accumulator is implemented using a saturation counter which
  10: // does not wrap around.
  11: //
  12: 
  13: module alert_handler_accu import alert_pkg::*; (
  14:   input                        clk_i,
  15:   input                        rst_ni,
  16:   input                        class_en_i,   // class enable
  17:   input                        clr_i,        // clear the accumulator
  18:   input                        class_trig_i, // increments the accu
  19:   input        [AccuCntDw-1:0] thresh_i,     // escalation trigger threshold
  20:   output logic [AccuCntDw-1:0] accu_cnt_o,   // output of current accu value
  21:   output logic                 accu_trig_o   // escalation trigger output
  22: );
  23: 
  24:   logic trig_gated;
  25:   logic [AccuCntDw-1:0] accu_d, accu_q;
  26: 
  27:   assign trig_gated = class_trig_i & class_en_i;
  28: 
  29:   assign accu_d = (clr_i)                    ? '0            : // clear
  30:                   (trig_gated && !(&accu_q)) ? accu_q + 1'b1 : // saturate counter at maximum
  31:                                                accu_q;
  32: 
  33:   assign accu_trig_o = (accu_q >= thresh_i) & trig_gated;
  34: 
  35:   assign accu_cnt_o = accu_q;
  36: 
  37:   always_ff @(posedge clk_i or negedge rst_ni) begin : p_regs
  38:     if (!rst_ni) begin
  39:       accu_q <= '0;
  40:     end else begin
  41:       accu_q <= accu_d;
  42:     end
  43:   end
  44: 
  45: 
  46:   ////////////////
  47:   // Assertions //
  48:   ////////////////
  49: 
  50:   `ASSERT(DisabledNoTrigFwd_A, !class_en_i |-> !accu_trig_o, clk_i, !rst_ni)
  51:   `ASSERT(DisabledNoTrigBkwd_A, accu_trig_o |-> class_en_i, clk_i, !rst_ni)
  52: 
  53: endmodule : alert_handler_accu
  54: