File size: 3,229 Bytes
d39fee6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright lowRISC contributors (OpenTitan project).
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
//
// This module gathers and synchronizes the clock gating and reset indication signals for all
// low-power groups (LPGs), synchronizes them to the alert handler clock domain. The clock gating
// and reset indication signals are then logically OR'ed to produce one multibit value for each
// LPG. The LPG multibit values are then mapped to the alert channels using the LpgMap parameter,
// and each multibit output value is buffered independently.
//

`include "prim_assert.sv"

module alert_handler_lpg_ctrl import alert_handler_pkg::*; (
  input  clk_i,
  input  rst_ni,
  // Low power clk and rst indication signals.
  input  prim_mubi_pkg::mubi4_t [NLpg-1:0]    lpg_cg_en_i,
  input  prim_mubi_pkg::mubi4_t [NLpg-1:0]    lpg_rst_en_i,
  // Init requests going to the individual alert channels.
  output prim_mubi_pkg::mubi4_t [NAlerts-1:0] alert_init_trig_o
);

  import prim_mubi_pkg::mubi4_t;
  import prim_mubi_pkg::mubi4_or_hi;
  import prim_mubi_pkg::MuBi4True;

  ///////////////////////////////////////////////////
  // Aggregate multibit indication signals per LPG //
  ///////////////////////////////////////////////////

  mubi4_t [NLpg-1:0] synced_lpg_cg_en, synced_lpg_rst_en, lpg_init_trig;
  for (genvar k = 0; k < NLpg; k++) begin : gen_lpgs
    prim_mubi4_sync #(
      .ResetValue(MuBi4True)
    ) u_prim_mubi4_sync_cg_en (
      .clk_i,
      .rst_ni,
      .mubi_i(lpg_cg_en_i[k]),
      .mubi_o(synced_lpg_cg_en[k:k])
    );
    prim_mubi4_sync #(
      .ResetValue(MuBi4True)
    ) u_prim_mubi4_sync_rst_en (
      .clk_i,
      .rst_ni,
      .mubi_i(lpg_rst_en_i[k]),
      .mubi_o(synced_lpg_rst_en[k:k])
    );

    // Perform a logical OR operation of the multibit life cycle signals.
    // I.e., if any of the incoming multibit signals is On, the output will also be On.
    // Otherwise, the output may have any value other than On.
    assign lpg_init_trig[k] = mubi4_or_hi(synced_lpg_cg_en[k], synced_lpg_rst_en[k]);
  end

  //////////////////////////////////
  // LPG to Alert Channel Mapping //
  //////////////////////////////////

  // select the correct lpg for the alert channel at index j and buffer the multibit signal for each
  // alert channel.
  for (genvar j=0; j < NAlerts; j++) begin : gen_alert_map
    prim_mubi4_sync #(
      .AsyncOn(0) // no sync flops
    ) u_prim_mubi4_sync_lpg_en (
      .clk_i,
      .rst_ni,
      .mubi_i(lpg_init_trig[LpgMap[j]]),
      .mubi_o({alert_init_trig_o[j]})
    );
  end

  if (NLpg > 1) begin : gen_read_unused_lpg
    // explicitly read all unused lpg triggers to avoid lint errors.
    // Only needed when there are at least two LPGs.
    logic [NLpg-1:0] lpg_used;
    logic unused_lpg_init_trig;
    always_comb begin
      lpg_used = '0;
      unused_lpg_init_trig = 1'b0;
      for (int j=0; j < NAlerts; j++) begin
        lpg_used[LpgMap[j]] |= 1'b1;
      end
      for (int k=0; k < NLpg; k++) begin
        if (!lpg_used) begin
          unused_lpg_init_trig ^= ^lpg_init_trig[k];
        end
      end
    end
  end

endmodule : alert_handler_lpg_ctrl