From 07de394ddb3438637d4038114d34a2048b448017 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 9 Sep 2024 12:47:19 -0700 Subject: [PATCH] lib/PinSync: use an explicit type To make them more obviously not normal registers, and to add annotations to make the scheduling more annoying if you try holding them wrong. --- lib/PinSync.bsv | 8 +++++++- lib/PinSync_Test.bsv | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/PinSync.bsv b/lib/PinSync.bsv index a7db442..9b50f84 100644 --- a/lib/PinSync.bsv +++ b/lib/PinSync.bsv @@ -1,5 +1,11 @@ package PinSync; +(* always_ready, always_enabled *) +interface PinSync#(type val); + method Action _write(val a); + method val _read(); +endinterface + // mkPinSync builds a synchronizer for use with asynchronous inputs. // // You should only use this to capture asynchronous inputs coming from @@ -18,7 +24,7 @@ package PinSync; // source domain. Conceptually, we assume that register exists outside // our design and is driving the input of mkPinSync, so we just need // the metastability mitigation within our own domain. -module mkPinSync(val init_value, Reg#(val) ifc) +module mkPinSync(val init_value, PinSync#(val) ifc) provisos(Bits#(val, _)); Reg#(val) r1 <- mkReg(init_value); diff --git a/lib/PinSync_Test.bsv b/lib/PinSync_Test.bsv index 37fec83..6052e88 100644 --- a/lib/PinSync_Test.bsv +++ b/lib/PinSync_Test.bsv @@ -10,7 +10,7 @@ module mkTB(); let testflags <- mkTestFlags(); let cycles <- mkCycleCounter(); - Reg#(UInt#(2)) dut <- mkPinSync(0); + PinSync#(UInt#(2)) dut <- mkPinSync(0); function Action check_dut_val(UInt#(2) want_val); return action