2020-04-21 10:43:21 -05:00
|
|
|
// The four D flip-flops (DFFs) in a Cyclone V/10GX Adaptive Logic Module (ALM)
|
|
|
|
// act as one-bit memory cells that can be placed very flexibly (wherever there's
|
|
|
|
// an ALM); each flop is represented by a MISTRAL_FF cell.
|
|
|
|
//
|
|
|
|
// The flops in these chips are rather flexible in some ways, but in practice
|
|
|
|
// quite crippled by FPGA standards.
|
|
|
|
//
|
|
|
|
// What the flops can do
|
|
|
|
// ---------------------
|
|
|
|
// The core flop acts as a single-bit memory that initialises to zero at chip
|
|
|
|
// reset. It takes in data on the rising edge of CLK if ENA is high,
|
|
|
|
// and outputs it to Q. The ENA (clock enable) pin can therefore be used to
|
|
|
|
// capture the input only if a condition is true.
|
|
|
|
//
|
|
|
|
// The data itself is zero if SCLR (synchronous clear) is high, else it comes
|
|
|
|
// from SDATA (synchronous data) if SLOAD (synchronous load) is high, or DATAIN
|
|
|
|
// if SLOAD is low.
|
|
|
|
//
|
|
|
|
// If ACLR (asynchronous clear) is low then Q is forced to zero, regardless of
|
|
|
|
// the synchronous inputs or CLK edge. This is most often used for an FPGA-wide
|
|
|
|
// power-on reset.
|
|
|
|
//
|
|
|
|
// An asynchronous set that sets Q to one can be emulated by inverting the input
|
|
|
|
// and output of the flop, resulting in ACLR forcing Q to zero, which then gets
|
|
|
|
// inverted to produce one. Likewise, logic can operate on the falling edge of
|
|
|
|
// CLK if CLK is inverted before being passed as an input.
|
|
|
|
//
|
|
|
|
// What the flops *can't* do
|
|
|
|
// -------------------------
|
|
|
|
// The trickiest part of the above capabilities is the lack of configurable
|
|
|
|
// initialisation state. For example, it isn't possible to implement a flop with
|
|
|
|
// asynchronous clear that initialises to one, because the hardware initialises
|
|
|
|
// to zero. Likewise, you can't emulate a flop with asynchronous set that
|
|
|
|
// initialises to zero, because the inverters mean the flop initialises to one.
|
|
|
|
//
|
|
|
|
// If the input design requires one of these cells (which appears to be rare
|
|
|
|
// in practice) then synth_intel_alm will fail to synthesize the design where
|
|
|
|
// other Yosys synthesis scripts might succeed.
|
|
|
|
//
|
|
|
|
// This stands in notable contrast to e.g. Xilinx flip-flops, which have
|
|
|
|
// configurable initialisation state and native synchronous/asynchronous
|
|
|
|
// set/clear (although not at the same time), which means they can generally
|
|
|
|
// implement a much wider variety of logic.
|
|
|
|
|
2019-11-19 04:19:00 -06:00
|
|
|
// DATAIN: synchronous data input
|
|
|
|
// CLK: clock input (positive edge)
|
|
|
|
// ACLR: asynchronous clear (negative-true)
|
|
|
|
// ENA: clock-enable
|
|
|
|
// SCLR: synchronous clear
|
|
|
|
// SLOAD: synchronous load
|
|
|
|
// SDATA: synchronous load data
|
|
|
|
//
|
|
|
|
// Q: data output
|
|
|
|
//
|
|
|
|
// Note: the DFFEAS primitive is mostly emulated; it does not reflect what the hardware implements.
|
2020-05-23 06:52:13 -05:00
|
|
|
|
|
|
|
`ifdef cyclonev
|
|
|
|
`define SYNCPATH 262
|
|
|
|
`define SYNCSETUP 522
|
|
|
|
`define COMBPATH 0
|
|
|
|
`endif
|
|
|
|
`ifdef cyclone10gx
|
|
|
|
`define SYNCPATH 219
|
|
|
|
`define SYNCSETUP 268
|
|
|
|
`define COMBPATH 0
|
|
|
|
`endif
|
|
|
|
|
|
|
|
// fallback for when a family isn't detected (e.g. when techmapping for equivalence)
|
|
|
|
`ifndef SYNCPATH
|
|
|
|
`define SYNCPATH 0
|
|
|
|
`define SYNCSETUP 0
|
|
|
|
`define COMBPATH 0
|
|
|
|
`endif
|
|
|
|
|
|
|
|
(* abc9_box, lib_whitebox *)
|
2019-11-19 04:19:00 -06:00
|
|
|
module MISTRAL_FF(
|
|
|
|
input DATAIN, CLK, ACLR, ENA, SCLR, SLOAD, SDATA,
|
|
|
|
output reg Q
|
|
|
|
);
|
|
|
|
|
|
|
|
specify
|
2020-05-28 05:33:19 -05:00
|
|
|
if (ENA && ACLR !== 1'b0 && !SCLR && !SLOAD) (posedge CLK => (Q : DATAIN)) = `SYNCPATH;
|
|
|
|
if (ENA && SCLR) (posedge CLK => (Q : 1'b0)) = `SYNCPATH;
|
|
|
|
if (ENA && !SCLR && SLOAD) (posedge CLK => (Q : SDATA)) = `SYNCPATH;
|
2020-05-23 06:52:13 -05:00
|
|
|
|
|
|
|
$setup(DATAIN, posedge CLK, `SYNCSETUP);
|
|
|
|
$setup(ENA, posedge CLK, `SYNCSETUP);
|
|
|
|
$setup(SCLR, posedge CLK, `SYNCSETUP);
|
|
|
|
$setup(SLOAD, posedge CLK, `SYNCSETUP);
|
|
|
|
$setup(SDATA, posedge CLK, `SYNCSETUP);
|
|
|
|
|
2020-05-28 05:33:19 -05:00
|
|
|
if (ACLR === 1'b0) (ACLR => Q) = `COMBPATH;
|
2019-11-19 04:19:00 -06:00
|
|
|
endspecify
|
|
|
|
|
|
|
|
initial begin
|
|
|
|
// Altera flops initialise to zero.
|
|
|
|
Q = 0;
|
|
|
|
end
|
|
|
|
|
|
|
|
always @(posedge CLK, negedge ACLR) begin
|
|
|
|
// Asynchronous clear
|
|
|
|
if (!ACLR) Q <= 0;
|
|
|
|
// Clock-enable
|
|
|
|
else if (ENA) begin
|
|
|
|
// Synchronous clear
|
|
|
|
if (SCLR) Q <= 0;
|
|
|
|
// Synchronous load
|
|
|
|
else if (SLOAD) Q <= SDATA;
|
|
|
|
else Q <= DATAIN;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
endmodule
|