| // Copyright lowRISC contributors. |
| // Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| // SPDX-License-Identifier: Apache-2.0 |
| module prim_edge_detector #( |
| parameter int unsigned Width = 1, |
| parameter logic [Width-1:0] ResetValue = '0, |
| // Enable Synchronizer to the input signal. |
| // It is assumed that the input signal is glitch free (registered input). |
| parameter bit EnSync = 1'b 1 |
| output logic [Width-1:0] q_sync_o, |
| output logic [Width-1:0] q_posedge_pulse_o, |
| output logic [Width-1:0] q_negedge_pulse_o |
| logic [Width-1:0] q_sync_d, q_sync_q; |
| if (EnSync) begin : g_sync |
| assign q_sync_o = q_sync_d; |
| always_ff @(posedge clk_i or negedge rst_ni) begin |
| if (!rst_ni) q_sync_q <= ResetValue; |
| else q_sync_q <= q_sync_d; |
| assign q_posedge_pulse_o = q_sync_d & ~q_sync_q; |
| assign q_negedge_pulse_o = ~q_sync_d & q_sync_q; |
| endmodule : prim_edge_detector |