blob: d547d1a36f849415b65c998a8bdf7cde3c8cf2c7 [file] [log] [blame]
Timothy Chenbc16a172020-04-07 23:45:23 -07001// 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// Power Manager Wake Information
6//
7
8`include "prim_assert.sv"
9
Timothy Chen6ecbe922020-06-16 18:15:30 -070010module pwrmgr_wake_info import pwrmgr_pkg::*; import pwrmgr_reg_pkg::*;
11(
Timothy Chenbc16a172020-04-07 23:45:23 -070012 input clk_i,
13 input rst_ni,
14 input wr_i,
15 input [TotalWakeWidth-1:0] data_i,
16 input start_capture_i,
17 input record_dis_i,
Timothy Chen6ecbe922020-06-16 18:15:30 -070018 input [NumWkups-1:0] wakeups_i,
Timothy Chenbc16a172020-04-07 23:45:23 -070019 input fall_through_i,
20 input abort_i,
Timothy Chen4791da52021-03-24 20:45:45 -070021 output pwrmgr_hw2reg_wake_info_reg_t info_o
Timothy Chenbc16a172020-04-07 23:45:23 -070022);
23
24 logic record_en;
25
Timothy Chen383afb82021-02-23 13:18:53 -080026 // detect rising edge of start_capture_i
27 logic start_capture_q1, start_capture;
28 always_ff @(posedge clk_i or negedge rst_ni) begin
29 if (!rst_ni) begin
30 start_capture_q1 <= 1'b1;
31 end else begin
32 start_capture_q1 <= start_capture_i;
33 end
34 end
35
36 assign start_capture = start_capture_i & ~start_capture_q1;
37
Timothy Chenbc16a172020-04-07 23:45:23 -070038 // generate the record enbale signal
39 // HW enables the recording
40 // Software can suppress the recording or disable it
41 always_ff @(posedge clk_i or negedge rst_ni) begin
42 if (!rst_ni) begin
43 record_en <= 1'b0;
Timothy Chen383afb82021-02-23 13:18:53 -080044 end else if (start_capture && !record_dis_i) begin
Timothy Chenbc16a172020-04-07 23:45:23 -070045 // if not disabled by software
46 // a recording enable puls by HW starts recording
47 record_en <= 1'b1;
48 end else if (record_dis_i && record_en) begin
49 // if recording is already ongoing
50 // a disable command by software shuts things down
51 record_en <= 1'b0;
52 end
53 end
54
Timothy Chen4791da52021-03-24 20:45:45 -070055 logic [TotalWakeWidth-1:0] info;
Timothy Chenbc16a172020-04-07 23:45:23 -070056 always_ff @(posedge clk_i or negedge rst_ni) begin
57 if (!rst_ni) begin
Timothy Chen4791da52021-03-24 20:45:45 -070058 info <= '0;
Timothy Chenbc16a172020-04-07 23:45:23 -070059 end else if (wr_i) begin
Timothy Chen4791da52021-03-24 20:45:45 -070060 info <= info & ~data_i; // W1C
Timothy Chenbc16a172020-04-07 23:45:23 -070061 end else if (record_en) begin // If set once, hold until clear
Timothy Chen4791da52021-03-24 20:45:45 -070062 info[0 +: NumWkups] <= info[0 +: NumWkups] | wakeups_i;
63 info[NumWkups +: 2] <= info[NumWkups +: 2] | {abort_i, fall_through_i};
Timothy Chenbc16a172020-04-07 23:45:23 -070064 end
65 end
66
Timothy Chen4791da52021-03-24 20:45:45 -070067 // assign outputs
68 assign info_o.abort.d = info[NumWkups + 1];
69 assign info_o.fall_through.d = info[NumWkups];
70 assign info_o.reasons = info[NumWkups-1:0];
71
72
Timothy Chenbc16a172020-04-07 23:45:23 -070073
74endmodule