Lecture 10: Multiple Clock Domains



Similar documents
A New Paradigm for Synchronous State Machine Design in Verilog

PROGETTO DI SISTEMI ELETTRONICI DIGITALI. Digital Systems Design. Digital Circuits Advanced Topics

PROGETTO DI SISTEMI ELETTRONICI DIGITALI. Digital Systems Design. Digital Circuits Advanced Topics

Modeling Sequential Elements with Verilog. Prof. Chien-Nan Liu TEL: ext: Sequential Circuit

Introduction to CMOS VLSI Design (E158) Lecture 8: Clocking of VLSI Systems

DIGITAL COUNTERS. Q B Q A = 00 initially. Q B Q A = 01 after the first clock pulse.

Lab #5: Design Example: Keypad Scanner and Encoder - Part 1 (120 pts)

Lecture 7: Clocking of VLSI Systems

Timing Methodologies (cont d) Registers. Typical timing specifications. Synchronous System Model. Short Paths. System Clock Frequency

Latch Timing Parameters. Flip-flop Timing Parameters. Typical Clock System. Clocking Overhead

Chapter 7. Registers & Register Transfers. J.J. Shann. J. J. Shann

EE 42/100 Lecture 24: Latches and Flip Flops. Rev B 4/21/2010 (2:04 PM) Prof. Ali M. Niknejad

Asynchronous & Synchronous Reset Design Techniques - Part Deux

Using SystemVerilog Assertions for Creating Property-Based Checkers

Life Cycle of a Memory Request. Ring Example: 2 requests for lock 17

ASYNCHRONOUS COUNTERS

A Verilog HDL Test Bench Primer Application Note

Experiment # 9. Clock generator circuits & Counters. Eng. Waleed Y. Mousa

LAB #4 Sequential Logic, Latches, Flip-Flops, Shift Registers, and Counters

FPGA Clocking. Clock related issues: distribution generation (frequency synthesis) multiplexing run time programming domain crossing

Cascaded Counters. Page 1 BYU

Design and Verification of Nine port Network Router

Sequential Logic: Clocks, Registers, etc.

To design digital counter circuits using JK-Flip-Flop. To implement counter using 74LS193 IC.

Counters and Decoders

ARM Thumb Microcontrollers. Application Note. Software ISO 7816 I/O Line Implementation. Features. Introduction

ETEC 2301 Programmable Logic Devices. Chapter 10 Counters. Shawnee State University Department of Industrial and Engineering Technologies

Module 3: Floyd, Digital Fundamental

Modeling Registers and Counters

WEEK 8.1 Registers and Counters. ECE124 Digital Circuits and Systems Page 1

A Pausible Bisynchronous FIFO for GALS Systems

Digital Systems Based on Principles and Applications of Electrical Engineering/Rizzoni (McGraw Hill

Lecture-3 MEMORY: Development of Memory:

Chapter 9 Latches, Flip-Flops, and Timers

Chapter 5 :: Memory and Logic Arrays

Digital Logic Design Sequential circuits

VHDL GUIDELINES FOR SYNTHESIS

Digital Design Verification

Flip-Flops, Registers, Counters, and a Simple Processor

Multiple clock domains

Hardware Implementation of Improved Adaptive NoC Router with Flit Flow History based Load Balancing Selection Strategy

8-ch RAID0 Design by using SATA Host IP Manual Rev1.0 9-Jun-15

Micro-Step Driving for Stepper Motors: A Case Study

Registers & Counters

Chapter 13: Verification

Design and Implementation of an On-Chip timing based Permutation Network for Multiprocessor system on Chip

ModelSim-Altera Software Simulation User Guide

ECE 451 Verilog Exercises. Sept 14, James Barnes

Modeling Latches and Flip-flops

INF5140: Specification and Verification of Parallel Systems

Lecture 11: Sequential Circuit Design

Lecture 10: Sequential Circuits

路 論 Chapter 15 System-Level Physical Design

CLOCK DOMAIN CROSSING CLOSING THE LOOP ON CLOCK DOMAIN FUNCTIONAL IMPLEMENTATION PROBLEMS

Measuring Metastability

How To Develop Software

Asynchronous counters, except for the first block, work independently from a system clock.

SVA4T: SystemVerilog Assertions - Techniques, Tips, Tricks, and Traps

Design Example: Counters. Design Example: Counters. 3-Bit Binary Counter. 3-Bit Binary Counter. Other useful counters:

ECE 3401 Lecture 7. Concurrent Statements & Sequential Statements (Process)

IMPLEMENTATION OF BACKEND SYNTHESIS AND STATIC TIMING ANALYSIS OF PROCESSOR LOCAL BUS(PLB) PERFORMANCE MONITOR

Counters & Shift Registers Chapter 8 of R.P Jain

High-Stability Time Adjustment with Real-Time Clock Module

Chapter 7: Advanced Modeling Techniques

Asynchronous IC Interconnect Network Design and Implementation Using a Standard ASIC Flow

The 104 Duke_ACC Machine

Latches, the D Flip-Flop & Counter Design. ECE 152A Winter 2012

Master/Slave Flip Flops

Set-Reset (SR) Latch

Interconnection Networks

Design Verification & Testing Design for Testability and Scan

DM74LS169A Synchronous 4-Bit Up/Down Binary Counter

Getting the Most Out of Synthesis

LogiCORE IP AXI Performance Monitor v2.00.a

Timing Errors and Jitter

EE552. Advanced Logic Design and Switching Theory. Metastability. Ashirwad Bahukhandi. (Ashirwad Bahukhandi)

Real-Time Systems Prof. Dr. Rajib Mall Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Chapter 13 Embedded Operating Systems

Contents COUNTER. Unit III- Counters

More Verilog. 8-bit Register with Synchronous Reset. Shift Register Example. N-bit Register with Asynchronous Reset.

PLL Dynamic Reconfiguration Author: Karl Kurbjun and Carl Ribbing

Hunting Asynchronous CDC Violations in the Wild

EXPERIMENT 8. Flip-Flops and Sequential Circuits

DATA SHEET. HEF40193B MSI 4-bit up/down binary counter. For a complete data sheet, please also download: INTEGRATED CIRCUITS

Clock Domain Crossing (CDC) Design & Verification Techniques Using SystemVerilog

HT1632C 32 8 &24 16 LED Driver

DIGITAL ELECTRONICS. Counters. By: Electrical Engineering Department

Multiplexers Two Types + Verilog

NTE2053 Integrated Circuit 8 Bit MPU Compatible A/D Converter

DIGITAL TECHNICS II. Dr. Bálint Pődör. Óbuda University, Microelectronics and Technology Institute

DIGITAL TECHNICS II. Dr. Bálint Pődör. Óbuda University, Microelectronics and Technology Institute. 2nd (Spring) term 2012/2013

Decimal Number (base 10) Binary Number (base 2)

Abstract. Cycle Domain Simulator for Phase-Locked Loops

Sequential Circuits. Combinational Circuits Outputs depend on the current inputs

TIMING-DRIVEN PHYSICAL DESIGN FOR DIGITAL SYNCHRONOUS VLSI CIRCUITS USING RESONANT CLOCKING

Programmable Logic Design Grzegorz Budzyń Lecture. 10: FPGA clocking schemes

CHAPTER 3 Boolean Algebra and Digital Logic

Debouncing Switches. Mechanical switches are one of the most common interfaces to a uc.

Best Practises for LabVIEW FPGA Design Flow. uk.ni.com ireland.ni.com

Transcription:

Bluespec SystemVerilog Training Lecture 10: Multiple Clock Domains Copyright Bluespec, Inc., 2005-2008 Lecture 10: Multiple Clock Domains The Clock type, and functions Modules with different clocks Clock families Making clocks Moving data across clock domains Synchronizing interfaces L10-2 1

BSV point of view Automate the simplest things Make it easy to do simple things Make it safe to do the more complicated things Work with gated clocks, to enable power management L10-3 The simplest case Only one clock, one reset Need never be mentioned in BSV source (Note: hasn t been mentioned in any examples so far!) Synthesized modules have an input port called CLK and RST_N This is passed to all interior instantiated modules L10-4 2

The Clock and Reset types Clock and Reset are ordinary first-class types May be passed as parameter, returned as result of function, etc. Can make arrays of them, can test whether two clocks are equal, etc. Clock c1, c2; Clock c = (b? c1 : c2); // b must be known at compile time L10-5 Default Clock and Reset Each module has a special default clock and reset The default clock and reset will be passed to any interior module instantiations (unless otherwise specified) They can be exposed by using the following modules (defined in the Standard Prelude) Example: module exposecurrentclock(clock) ; module exposecurrentreset(reset); Clock clk <- exposecurrentclock; Reset rst <- exposecurrentreset; L10-6 3

The Clock type Conceptually, a clock consists of two signals an oscillator a gating signal In general, implemented as two wires If ungated, oscillator is running Whether the reverse is true depends on implementation library tool doesn t care L10-7 Some Clock constructors mkclock#(t initval, Bool initgate)(makeclockifc#(t)); mkgatedclock#(bool initgate)(gatedclockifc); mkabsoluteclock#(integer start, Integer period)(clock); mkclockdivider#(integer divisor) (ClockDividerIfc); L10-8 4

Making clocks with mkclock Bool gateclk =...; // gate condition Reg#(Bit#(1)) osc <- mkreg(0); MakeClockIfc#(Bit#(1)) mc <- mkclock(false,true); Clock newclk = mc.new_clk; rule oscillate; let new_osc = invert(osc); mc.setclockvalue(new_osc); mc.setgatecond(gateclk); osc <= new_osc; endrule mkclock is a primitive for generating a clock with an arbitrary waveform controlled from within the design. newclk is a clock running at half the speed of the current clock, and is gated by gateclk. L10-9 Making clocks with mkgatedclock Clock clk <- exposecurrentclock; GatedClockIfc gc1 <- mkgatedclock(true); Clock clk1 = gc1.new_clk; GatedClockIfc gc2 <- mkgatedclock(true, clocked_by clk1); Clock clk2 = gc2.new_clk; rule gate_clocks; gc1.setgatecond(gateclk1); gc2.setgatecond(gateclk2); endrule clk1 is a version of clk, gated by gateclk1. clk2 is a version of clk1, gated by gateclk2. i.e. it is as the current clock gated by (gateclk1 && gateclk2) clk, clk1 and clk2 are from the same family clk and clk1 are ancestors of clk2 L10-10 5

Clock families All clocks in a family share the same oscillator They differ only in gating If c2 is a gated version of c1, we say c1 is an ancestor of c2 If some clock is running, then so are all its ancestors The functions isancestor(c1,c2) and samefamily(c1,c2) are provided to test these relationships Can be used to control static elaboration (e.g., to optionally insert or omit a synchronizer) L10-11 The clockof() function May be applied to any BSV expression, and returns a value of type Clock If the expression is a constant, the result is the special value noclock The result is always well-defined Expressions for which it would not be well-defined are illegal Reg#(UInt#(17)) x <- mkreg (0, clocked_by c); let y = x + 2; Clock c1 = clockof (x); Clock c2 = clockof (y); c1 and c2 are equal L10-12 6

Some Reset constructors mkreset#(integer stages, Bool startinrst)(clock dclkin, MakeResetIfc); mkresetsync#(integer stages, Bool startinrst) (Clock dclkin, MakeResetIfc); mkasyncreset#(integer stages)(reset srst, Clock dclkin, Reset); mksyncreset#(integer stages)(reset srst, Clock dclkin, Reset); See details in $BLUESPECDIR/../doc/reference_guide.doc L10-13 Instantiating modules with non-default clocks and resets Example: instantiating a register with explicit clock Clock clk <- exposecurrentclock; // Current Clock Reset rst <- exposecurrentreset; // Current Reset Clock clk1 <- ; // 2 nd clock domain Reset rst1 <- ; // 2 nd reset domain Reg#(Bool) a <- mkrega(false); Reg#(Bool) b <- mkreg(true, clocked_by clk1, reset_by rst1); Modules can also take clocks as ordinary dynamic arguments, to be fed to interior module instantiations (Examples later) L10-14 7

Clock family discipline All the methods invoked by a rule (or by another method) must be clocked by clocks from one family The tool enforces this There is no need for special domain-crossing logic when the clocks involved are from the same family It s all handled by implicit conditions L10-15 Clocks and implicit conditions The gating condition of an Action or ActionValue method s clock becomes one of the method s implicit conditions So, if the clock is off, the method is unready So, a rule can execute only if all the methods it uses have their clocks gated on This doesn t happen for value methods So, they stay ready if they were ready when the clock was switched off L10-16 8

Clocks and implicit conditions Example: FIFO#(Int#(3)) myfifo <- mkfifo(clocked_by clk1); If clk1 is switched off: myfifo.enq, myfifo.deq and f.clear are unready myfifo.first remains ready if the FIFO was nonempty when the clock was switched off L10-17 The clocks of methods and rules Every method, and every rule, has a notional clock For methods of primitive modules (Verilog wrapped in BSV): Their clocks are specified in the BSV wrappers which import them For methods of modules written in BSV: A method s clock is a clock from the same family as the clocks of all the methods that it, in turn, invokes The clock is gated on if the clocks of all invoked methods are gated on If necessary, this is a new clock The notional clock for a rule may be calculated in the same way L10-18 9

Moving Data Across Clock Domains Data moved across clock domains appears asynchronous to the receiving (destination) domain Asynchronous data will cause meta-stability The only safe way: use a synchronizer clk d Setup & hold violation q Meta-stable data L10-19 Synchronizers Good synchronizer design and use reduces the probability of observing meta-stable data Synchronizers needed for all crossings Bluespec delivers conservative (speed independent) synchronizers User can define and use new synchronizers Bluespec does not allow unsynchronized crossings (compiler static checking error) L10-20 10

Bit synchronizer Most common type of (bit) synchronizer FF1 will go meta-stable, but FF2 does not look at data until a clock period later, giving FF1 time to stabilize Limitations: When moving from fast to slow clocks data may be overrun Cannot synchronize words since bits may not be seen at same time sdin FF0 FF1 FF2 ddin sclk srst dclk L10-21 Bit synchronizer send sdin sclk srst FF0 FF1 FF2 mkbitsync ddin dclk read interface SyncBitIfc ; method Action send(bit#(1) bitdata ) ; method Bit#(1) read; Module mkbitsync#(clock sclk, Reset srst, Clock dclk) (SyncBitIfc); Synchronizer design guidelines cannot be violated: No logic between FF0 and FF1 No access to FF1 s output L10-22 11

Small Example Up/down counter, where direction signal comes from separate domain. Registers: Reg# (Bit# (32)) cntr <- mkreg(0); // Default Clk Reg# (Bit#(1)) up_down_bit <- mkreg(0, clocked_by clk2, reset_by rst2); The Rule (attempt 1): rule countup ( up_down_bit == 1 ) ; cntr <= cntr + 1; endrule Illegal Clock Domain Crossing L10-23 Adding the Synchronizer up_down_bit clk2 rst2 send sclk srst read mksyncbit dclk Synchronized up_down_bit CLK module mktoplevel#(clock clk2, Reset rst2) (Empty); Reg# (Bit# (1)) up_down_bit <- mkreg(0, clocked_by clk2, reset_by rst2) ; Reg# (Bit# (32)) cntr <- mkreg (0 ) ; // Default Clock, default Reset Clock currentclk <- exposecurrentclock ; // Default clock SyncBitIfc#(Bit#(1)) sync <- mksyncbit(clk2, rst2, currentclk); // Bit synchronizer rule transfer (True) ; sync.send( up_down_bit ); endrule rule countup ( sync.read == 1 ); cntr <= cntr + 1; endrule endmodule L10-24 12

Pulse Synchronizer Synchronizes single clock width pulses Two send s may not be seen if they occur too close together (faster than 2*dstClk) Also versions from CurrentClock and to CurrentClock interface SyncPulseIfc ; method Action send; method Bool pulse; module mksyncpulse#(clock sclkin, Reset srstin, Clock dclkin)(syncpulseifc); sclk Send dclk pulse L10-25 Handshake Pulse Synchronizer A Pulse Synchronizer with a handshake protocol The send method is ready after the pulse is received and an acknowledge returned. Latency: send to read is (2*dstClk) send to next send (2*dstClks+ 2*srcClk) Also versions from CurrentClock and to CurrentClock interface SyncPulseIfc ; method Action send; method Bool pulse; module mksynchandshake#(clock sclkin, Reset srstin, Clock dclkin)(syncpulseifc); L10-26 13

Register Synchronizer Uses common Reg#(a) interface However, write method has (implicit) ready condition, to allow time for data to be received No guarantee that destination reads the data, only that it arrives Also versions from CurrentClock and to CurrentClock module mksyncreg#(t initialvalue, Clock sclkin, Reset srstin, Clock dclkin)(reg#(t)); interface Reg#(type t); method Action _write(t a); method t _read; L10-27 Example interface Reader ; method Bit#(32) wordout () ; method Bool pulseout() ; // Pulses at new data interface Cruncher ; method Action crunch(bit#(32) dataread) ; Reader sync Cruncher module top#(clock clk2, Reset rst2)(top); Reader reader <- mkwordreader(clocked_by clk2, reset_by rst2) ; Cruncher cruncher <- mkwordcrunch; Clock clk <- exposecurrentclock; Reg#(Bit# (32)) wordsync <- mksyncreg(0, clk2, rst2, clk) ; rule loadsync( reader.pulseout ); // it runs in the clk2, rst2 domain wordsync <= reader.wordout; endrule... cruncher.crunch( sync ); // it runs in the clk domain L10-28 14

FIFO Synchronizer Good for data buffering across clock domains Also versions from CurrentClock, to CurrentClock, etc. interface SyncFIFOIfc#(type t); method Action enq(t a); method Action deq; method t first; module mksyncfifo#(integer depth, Clock sclkin, Reset srstin, Clock dclkin)(syncfifoifc#(t)); L10-29 Example interface Reader ; method Bit#(32) wordout () ; method Bool pulseout() ; // Pulses at new data interface Cruncher ; method Action crunch(bit#(32) dataread) ; Reader sync Cruncher Module top#(clock clk2, Reset rst2)(top); Reader reader <- mkwordreader(clocked_by clk2, reset_by rst2) ; Cruncher cruncher <- mkwordcrunch; Clock clk <- exposecurrentclock; SyncFIFOIfc#(Bit# (32)) fifosync <- mksyncfifo(4, clk2, rst2, clk) ; rule loadsync( reader.pulseout ); fifosync.enq( reader.wordout); endrule... cruncher.crunch(fifosync.first); // it runs in the clk2, rst2 domain // it runs in the clk domain L10-30 15

Null Synchronizer Needed when no synchronization is desired For example, up/down counter module mknullcrossingwire#(clock dclkin, t datain)(syncfifoifc#(t)); module mktoplevel#(clock clk2, Reset rst2) (Empty); interface ReadOnly#(type t); method t _read; Reg# (Bit# (1)) up_down_bit <- mkreg(0) ; // Default Clock, default Reset Reg# (Bit# (32)) cntr <- mkreg (0, clocked_by clk2, reset_by rst2 ) ; ReadOnly#(Bit#(1)) nullsync <- mknullcrossing(clk2, up_down_bit ); // Null Sync rule countup ( nullsync == 1 ); cntr <= cntr + 1; endrule endmodule L10-31 Advantages of Bluespec s synchronizers Bluespec provides a full set of speed-independent data synchronizers, with strong interface semantics preventing their misuse But good design practices are still needed Identify different clock domains early in design Partition design such that there is one clock per module Keep the synchronizations to the interfaces Limit number of signals which cross clock domains L10-32 16

Specialized Synchronizers (Topic for Advanced Training) Above synchronizers work for any clock relations If there are known relations between clock edges, then synchronizer can be removed Bluespec provides some synchronizers for clocks with coincident edges, e.g., divided clocks. Users can create their own synchronizers or import their current ones into Bluespec L10-33 Synchronizing Interfaces The previous examples show a hardware approach to clock-domain crossing Designers instantiate a module having different clocks for different methods, and connect it up explicitly BSV also has an alternative linguistic approach, to convert an interface from one clock domain to another mkconverter converts an existing interface to another one of the same type, but on different clock In this style, more of the details are implicit L10-34 17

Synchronizing Interfaces typedef Server#(QueryType,RespType) IfcType; IfcType oldifc <- mkserver (clocked_by c0); IfcType newifc <- mkconverter(4, oldifc); oldifc is clocked by c0 newifc is clocked by the current clock 4 is a parameter for the conversion (FIFO depth) newifc can be used exactly as oldifc, but in the current clock domain L10-35 Synchronizing Interfaces Convertible interfaces form a typeclass ClockConv Other instances can be added by the user. Need only to define mkconverter, in terms of existing primitives Not all interfaces are convertible. The following are defined to be convertible in the BSV library: Get and Put interfaces Client and Server interfaces Tuples of convertible interfaces L10-36 18

Summary The Clock type, and strong type checking ensures that all circuits are clocked by actual clocks BSV provides ways to create, derive and manipulate clocks, safely BSV clocks are gated, and gating fits into Rule-enabling semantics BSV provides a full set of speed-independent data synchronizers, already tested and verified The user can define new synchronizers BSV precludes unsynchronized domain crossings Roadmap: tool will generate SDC constraints identifying all clocks, clocks associated with signals, false paths at clock-domain crossings, etc. L10-37 End of Lecture Copyright Bluespec, Inc., 2005-2008 19