// Copyright lowRISC contributors (OpenTitan project).
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
//
// Macros that define assertions that relate to FIFO implementations

`ifndef PRIM_FIFO_ASSERT_SVH
`define PRIM_FIFO_ASSERT_SVH

// Use PRIM_COUNT_ERROR_TRIGGER_ALERT appropriately to check that the three prim_counts generated by
// a prim_fifo_sync with depth at least two do indeed generate an alert if they detect an error.
//
// - NAME_ is used as the root of the names of the generated assertions.
// - HIER_ is a hierarchical path to the prim_fifo_sync in question.
// - ALERT_ is the name of the alert that should be generated.
// - GATE_ is a signal that, if true, will cause an error to be ignored.
// - MAX_CYCLES_ is the number of cycles allowed until the alert must be generated.
`define ASSERT_PRIM_FIFO_SYNC_ERROR_TRIGGERS_ALERT(NAME_, HIER_, ALERT_, GATE_ = 0, MAX_CYCLES_ = `_SEC_CM_ALERT_MAX_CYC) \
  `ASSERT_PRIM_COUNT_ERROR_TRIGGER_ALERT(``NAME_``WptrCheck_A,                                                            \
                                         HIER_.gen_normal_fifo.u_fifo_cnt.gen_secure_ptrs.u_wptr,                         \
                                         ALERT_,                                                                          \
                                         GATE_,                                                                           \
                                         MAX_CYCLES_)                                                                     \
  `ASSERT_PRIM_COUNT_ERROR_TRIGGER_ALERT(``NAME_``RptrCheck_A,                                                            \
                                         HIER_.gen_normal_fifo.u_fifo_cnt.gen_secure_ptrs.u_rptr,                         \
                                         ALERT_,                                                                          \
                                         GATE_,                                                                           \
                                         MAX_CYCLES_)

// An analagous assertion to PRIM_COUNT_ERROR_TRIGGER_ALERT, but specialised for the case where the
// fifo has depth 1, which means there aren't actually three prim_count instances but instead there
// is just a single error signal.
//
// - NAME_ is used as a root for the name of the generated assertion.
// - HIER_ is a hierarchical path to the prim_fifo_sync in question.
// - ALERT_ is the name of the alert that should be generated.
// - GATE_ is a signal that, if true, will cause an error to be ignored.
// - MAX_CYCLES_ is the number of cycles allowed until the alert must be generated.
`define ASSERT_PRIM_FIFO_SYNC_ERROR_TRIGGERS_ALERT1(NAME_, HIER_, ALERT_, GATE_ = 0, MAX_CYCLES_ = `_SEC_CM_ALERT_MAX_CYC) \
  `ASSERT_ERROR_TRIGGER_ALERT(``NAME_``FullCheck_A,                                                                        \
                              HIER_,                                                                                       \
                              ALERT_,                                                                                      \
                              GATE_,                                                                                       \
                              MAX_CYCLES_,                                                                                 \
                              err_o)

`endif // PRIM_FIFO_ASSERT_SVH
