Timothy Chen | bc16a17 | 2020-04-07 23:45:23 -0700 | [diff] [blame] | 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 | // Power Manager Wake Information |
| 6 | // |
| 7 | |
| 8 | `include "prim_assert.sv" |
| 9 | |
Timothy Chen | 6ecbe92 | 2020-06-16 18:15:30 -0700 | [diff] [blame] | 10 | module pwrmgr_wake_info import pwrmgr_pkg::*; import pwrmgr_reg_pkg::*; |
| 11 | ( |
Timothy Chen | bc16a17 | 2020-04-07 23:45:23 -0700 | [diff] [blame] | 12 | 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 Chen | 6ecbe92 | 2020-06-16 18:15:30 -0700 | [diff] [blame] | 18 | input [NumWkups-1:0] wakeups_i, |
Timothy Chen | bc16a17 | 2020-04-07 23:45:23 -0700 | [diff] [blame] | 19 | input fall_through_i, |
| 20 | input abort_i, |
Timothy Chen | 4791da5 | 2021-03-24 20:45:45 -0700 | [diff] [blame] | 21 | output pwrmgr_hw2reg_wake_info_reg_t info_o |
Timothy Chen | bc16a17 | 2020-04-07 23:45:23 -0700 | [diff] [blame] | 22 | ); |
| 23 | |
| 24 | logic record_en; |
| 25 | |
Timothy Chen | 383afb8 | 2021-02-23 13:18:53 -0800 | [diff] [blame] | 26 | // 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 Chen | bc16a17 | 2020-04-07 23:45:23 -0700 | [diff] [blame] | 38 | // 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 Chen | 383afb8 | 2021-02-23 13:18:53 -0800 | [diff] [blame] | 44 | end else if (start_capture && !record_dis_i) begin |
Timothy Chen | bc16a17 | 2020-04-07 23:45:23 -0700 | [diff] [blame] | 45 | // 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 Chen | 4791da5 | 2021-03-24 20:45:45 -0700 | [diff] [blame] | 55 | logic [TotalWakeWidth-1:0] info; |
Timothy Chen | bc16a17 | 2020-04-07 23:45:23 -0700 | [diff] [blame] | 56 | always_ff @(posedge clk_i or negedge rst_ni) begin |
| 57 | if (!rst_ni) begin |
Timothy Chen | 4791da5 | 2021-03-24 20:45:45 -0700 | [diff] [blame] | 58 | info <= '0; |
Timothy Chen | bc16a17 | 2020-04-07 23:45:23 -0700 | [diff] [blame] | 59 | end else if (wr_i) begin |
Timothy Chen | 4791da5 | 2021-03-24 20:45:45 -0700 | [diff] [blame] | 60 | info <= info & ~data_i; // W1C |
Timothy Chen | bc16a17 | 2020-04-07 23:45:23 -0700 | [diff] [blame] | 61 | end else if (record_en) begin // If set once, hold until clear |
Timothy Chen | 4791da5 | 2021-03-24 20:45:45 -0700 | [diff] [blame] | 62 | info[0 +: NumWkups] <= info[0 +: NumWkups] | wakeups_i; |
| 63 | info[NumWkups +: 2] <= info[NumWkups +: 2] | {abort_i, fall_through_i}; |
Timothy Chen | bc16a17 | 2020-04-07 23:45:23 -0700 | [diff] [blame] | 64 | end |
| 65 | end |
| 66 | |
Timothy Chen | 4791da5 | 2021-03-24 20:45:45 -0700 | [diff] [blame] | 67 | // 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 Chen | bc16a17 | 2020-04-07 23:45:23 -0700 | [diff] [blame] | 73 | |
| 74 | endmodule |