Thursday, December 6, 2012

Difference between data types logic and reg and wire

Wire:-
  1. Wires are used for connecting different elements
  2. They can be treated as a physical wire
  3. They can be read or assigned
  4. No values get stored in them
  5. They need to be driven by either continuous assign statement or from a port of a module
Reg:-
  1. Contrary to their name, regs doesn't necessarily corresponds to physical registers
  2. They represents data storage elements in Verilog/SystemVerilog
  3. They retain their value till next value is assigned to them (not through assign statement)
  4. They can be synthesized to FF, latch or combinational circuit (They might not be synthesizable !!!)
Wires and Regs are present from Verilog timeframe. SystemVerilog added a new data type called logic to them. So the next question is what is this logic data type and how it is different from our good old wire/reg.

Logic:-
  1. As we have seen, reg data type is bit mis-leading in Verilog. SystemVerilog's logic data type addition is to remove the above confusion. The idea behind having a new data type called logic which at least doesn't give an impression that it is hardware synthesizable
  2. Logic data type doesn't permit multiple driver. It has a last assignment wins behavior in case of multiple assignment (which implies it has no hardware equivalence). Reg/Wire data type give X if multiple driver try to drive them with different value. Logic data type simply assign the last assignment value.
  3. The next difference between reg/wire and logic is that logic can be both driven by assign block, output of a port and inside a procedural block like this
    logic a;
    assign a = b ^ c;                   // wire style 
    always (c or d) a = c + d;          // reg style
    MyModule module(.out(a), .in(xyz)); // wire style
source : internet

Friday, November 30, 2012

UVM video lactures link

http://videos.accellera.org/uvmreadysetdeploy/uvm38mtR57B/index.html

Virtual Interface

1. We cannot pass a port (interface) directly in a class, so we use the concept of the virtual interface that points to the actual interface and can be passed in a class as a class is a dynamic entity.

2. The interface is used for connection of two modules.

3. The virtual interface is used to connect a class (dynamic entity) to a module (static entity)

4. Virtual interfaces provide a mechanism for separating abstract models and test programs from the actual signals that make up the design.

5. A virtual interface allows the same subprogram to operate on different portions of a design and to dynamically control the set of signals associated with the subprogram.

6. Instead of referring to the actual set of signals directly, users are able to manipulate a set of virtual signals. Changes to the underlying design do not require the code using virtual interfaces to be rewritten.

7. By abstracting the connectivity and functionality of a set of blocks, virtual interfaces promote code reuse.

8. Virtual interfaces can be declared as class properties, which can be initialized procedurally or by an argument to new(). This allows the same virtual interface to be used in different classes.

8. In UVM based environment we can set the virtual interface using config_db in the tb_top and then it will be available down the hierarchy.


9. The following example shows how the same transactor class can be used to interact with various different devices:

01.interface SBus; // A Simple bus interface
02.logic req, grant;
03.logic [7:0] addr, data;
04.endinterface

05.class SBusTransctor; // SBus transactor class
06.virtual SBus bus; // virtual interface of type Sbus

07 function new( virtual SBus s );
08.bus = s; // initialize the virtual interface
09.endfunction

10.task request(); // request the bus
11.bus.req <= 1'b1;
12.endtask

13.task wait_for_bus(); // wait for the bus to be granted
14.@(posedge bus.grant);
15.endtask

16.endclass

17.module devA( Sbus s ) ... endmodule // devices that use SBus
18.module devB( Sbus s ) ... endmodule

19.module top;
20.SBus s[1:4] (); // instantiate 4 interfaces
21.devA a1( s[1] ); // instantiate 4 devices
22.devB b1( s[2] );
23.devA a2( s[3] );
24.devB b2( s[4] );

25.initial begin
26.SbusTransactor t[1:4]; // create 4 bus-transactors and bind
27.t[1] = new( s[1] );
28.t[2] = new( s[2] );
29.t[3] = new( s[3] );
30.t[4] = new( s[4] );
31. end

32.endmodule


In the preceding example, the transaction class SbusTransctor is a simple reusable component. It is written without any global or hierarchical references and is unaware of the particular device with which it will interact. Nevertheless, the class can interact with any number of devices (four in the example) that adhere to the interface’s protocol.



Notes :
1. virtual i/f is just a handle (like pointers) when a virtual i/f is declared, it only creates handles, doesn't create a local interface.

2. Virtual interface variables can be passed as arguments to tasks, functions, or methods. A single virtual interface variable can thus represent different interface instances at different times throughout the simulation. 

3. A virtual interface must be initialized before it can be used; it has the value null before it is initialized.


Benefits of using interface :
1. can contain protocol checking using assertions and functional coverage blocks. 
2. maintainability and reusability. 
3. can contain tasks and functions.








Friday, November 23, 2012

Post 16: Why virtual class

http://www.systemverilog.in/forum/showthread.php?tid=143

Post 14 : Introduction to OOPs

OOP Can be described with following concepts : 

  • Follows bottom up approach.
  • Emphasis is on data.  //need to search explanation 
  • Programs are divided into objects.
  • Functions and data are bound together.
  • Communication is done through objects.
  • Data is hidden.
The following are the basic concepts of OOPs:
Classes, Objects, Data abstraction and encapsulation, Polymorphism, Inheritance, Message Passing, and Dynamic Binding.

1. What is a class?
Class is an entity which consists of member data and member functions which operate on the member data bound together.

2. What is an object?
i)Objects are instances of classes.
ii) Class is a collection of similar kind of objects.
iii) When a class is created it doesn’t occupy any memory
iv) but when instances of class is created i.e., when objects are created they occupy memory space.

3. What is encapsulation?
Encapsulation is welding of code and data together into objects.

4. What is inheritance?
Inheritance is a mechanism through which a subclass inherits the properties and behavior of its superclass.
The derived class inherits the properties and method implementations of the base class and extends it by overriding methods and adding additional properties and methods.

5. What is polymorphism?
i) In Greek this means "many shapes."
ii) As a consequence of inheritance and virtual functions, a single task (for example, drawing a geometrical shape) can be implemented using the same name (like draw()) and implemented differently (via virtual functions) as each type in object hierarchy requires(circle.draw() or rectangle.draw()).
iii) Later, when a polymorphic object (whose type is not known at compile time) executes the draw() virtual function, the correct implementation is chosen and executed at run time.

6. What is the difference between function overloading and function overriding?
i) Overloading is a method that allows defining multiple member functions with the same name but different signatures.
The compiler will pick the correct function based on the signature.

ii) Overriding is a method that allows the derived class to redefine the behavior of member functions which the derived class inherits from a base class.
The signatures of both base class member function and derived class member function are the same; however, the implementation and, therefore, the behavior will differ.

7. What are the advantages of OOP?
  • Data hiding helps create secure programs.
  • Redundant code can be avoided by using inheritance.
  • Multiple instances of objects can be created.
  • Work can be divided easily based on objects.
  • Inheritance helps to save time and cost.
  • Easy upgrading of systems is possible using object oriented systems.
8. Explain about the virtual task and methods .
#important : Virtual tasks and functions are the ways to achieve the polymorphism in system verilog.

Example :
01.class base ;
03.virtual function int print;
04.$display("INSIDE BASE \n");
05.endfunction : print
06. 
07.endclass : base
08. 
09.class derived extends base;
10. 
11.function int print;
12.$display("INSIDE DERIVED \n");
13.endfunction : print
14. 
15.endclass : derived
16. 
17. 
18. 
19.program test ;
20. 
21.derived d1;
22.initial
23.begin
24.d1 = new();
25.d1.print();
26.callPrint (d1);
27.end
28. 
29.task callPrint (base b1);
30.$display("Inside callPrint \n");
31.b1.print;
32.endtask : callPrint
33. 
34.endprogram
35. 
36.Output :
37.========
38. 
39.VSIM 1> run
40.# INSIDE DERIVED
41.#
42.# Inside callPrint
43.#
44.# INSIDE BASE
45.#

Thursday, November 22, 2012

UVM : Introduction

What is UVM

1)UVM is standardization in verification methodology by Accellera.
2) UVM is based on the best features in the existing methodologies OVM/VMM. But it is mostly derived from the OVM methodology and in fact it's backward compatible with the OVM. It has all the features of the proven OVM methodology
3) It is based on the System Verilog standard so it will compile on all the simulators which support the system Verilog standard.

The main advantages of UVM is :

1) Standardized verification methodology so no more confusion to choose a methodology to start a project.
2) No tool dependency. No more porting issues from one tool to other
3) Less confusion for the engineers. Easy to learn and maintain the skill set
4) Provides the flexibility and ways to connect the legacy VMM/OVM components
5) Backward compatible with OVM and provides the scripts to change OVM environment to UVM.
6) Remove the mess of having so many methodologies and provides a standard solution which compiles on all tools.



Universal Verification Methodology (From Wikipedia)


1. The Universal Verification Methodology (UVM) is a standardized methodology for verifying integrated circuit designs.

2. UVM is derived mainly from the OVM (Open Verification Methodology) which was, to a large part, based on the eRM (e Reuse Methodology) for the e Verification Language developed by Verisity Design in 2001.

3.The UVM class library brings much automation to the SystemVerilog language such as sequences and data automation features (packing, copy, compare) etc.,


History
1). lectronic design automation (EDA) industry — voted to establish the UVM and decided to base this new standard on the Open Verification Methodology (OVM-2.1.1)[1], a verification methodology developed jointly in 2007 by Cadence Design Systems and Mentor Graphics.

2). On February 21, 2011, Accellera approved the 1.0 version of UVM[2]. UVM 1.0 includes a Reference Guide, a Reference Implementation in the form of a SystemVerilog base class library, and a User Guide.[3].

The need of clocking blocks in testbench

The need of clocking blocks?
Clocking blocks have been introduced in SystemVerilog to address the problem of specifying the timing and synchronization requirements of a design in a testbench.
1) It is used to specify synchronization characteristics of the design
2) It Offers a clean way to drive and sample signals
3) It provides race-free operation if input skew > 0
4) It helps in testbench driving the signals at the right time
5) Features
    - Clock specification
    - Input skew,output skew
    - Cycle delay (##)
6) Can be declared inside interface,module or program

Example :
01.Module M1(ck, enin, din, enout, dout);
02.input         ck,enin;
03.input  [31:0] din    ;
04.output        enout  ;
05.output [31:0] dout   ;
06. 
07.clocking sd @(posedge ck);
08.input  #2ns ein,din    ;
09.output #3ns enout, dout;
10.endclocking:sd
11. 
12.reg [7:0] sab ;
13.initial begin
14.sab = sd.din[7:0];
15.end
16.endmodule:M1


#Skew : it is related to set up and hold time.

Input and Output Skew :
A skew number for an input denotes when that input is sampled before the clocking event (such as posedge or negedge) occurs. 
For an output, it is just the opposite - it denotes when an output is synchronized and sent after the clocking event.

clocking clock1 @(posedge clk1);
   input a1, a2;
   output b1;
endclocking
In this case, the default input skew is 1step and the default output skew is 0.

Overwriting default skews

Even if there is a default statement for skews in a clocking block, it can be overwritten later in the block. For example, the example below overwrites the default input skew for signal a1 (to 1step) and output b1 (to 5 ns), but the input skew for a2remains unchanged at 2 ns.
 
clocking clock1 @(posedge clk1);
   default input #2ns output #3ns;
   input #1step a1;
   input a2;
   output #5ns b1;
endclocking




VLSI Interview Questions : Part 1

What are the differences between SIMULATION and SYNTHESIS
i)Simulation <= verify your design.


Simulation is used to verify the functionality of the circuit.
a)Functional Simulation: a study of ckt's operation independent of timing parameters and gate delays.

b) Timing Simulation: study including estimated delays, verify setup, hold and other timing requirements of devices like flip-flops are met.
ii)Synthesis <= Check for your timing

Synthesis: One of the foremost in back-end steps whereby synthesizing is nothing but converting VHDL or VERILOG description to a set of primitives (equations as in CPLD) or components(as in FPGAs) to fit into the target technology.

Basically the synthesis tools convert the design description into equations or components



2. Differences between latches & flipflops?
There are 2 types of circuits:
1. Combinational
2. Sequential

Latches and flipflops both come under the category of "sequential circuits", whose output depends not only on the current inputs but also on previous inputs and outputs.
Difference: Latches are level-sensitive, whereas, FF are edge sensitive.
By edge sensitive, I mean O/p changes only when there is a clock transition.
( from 1 to 0 or from 0 to 1)

Example: In a flipflop, inputs have arrived on the input lines at time= 2 seconds. But, the output won't change immediately. At time = 3 seconds, clock transition takes place. After that, O/P will change.


Flip-flops are of 2 types:
1. Positive edge triggered
2. negative edge triggered

1) Flip-flops take twice the number of gates as latches
2) so automatically delay is more for flipflops
3) power consumption is also more


# Imp: latch does not have a clock signal, whereas a flip-flop always does.


3. What is slack?
The slack is the time delay difference from the expected delay(1/clock) to the actual delay in a particular path.
Slack may be +ve or -ve.




4. RTL and Behavioral
i) Register transfer language means there should be data flow between two registers and logic is in between them for end registers data should flow.

ii) Behavioral means how hardware behave determine the exact way it works we write using HDL syntax.For complex projects it is better mixed approach or more behavioral is used.



5. Equivalence between VHDL and C?
i)There is a concept of understanding in C there is structure. Based upon requirement structure provide facility to store the collection of different data types.

ii) In VHDL we have direct access to memory so instead of using a pointer in C (and member of structure) we can write interface to store data in memory and access it.

Difference between wire, reg and logic

1). Wire and Reg are present in the Verilog
2). System Verilog adds one more data type called logic.

Wire : 
1) Wire data type is used in the continuous assignments or ports list.
2) It is treated as a wire So it can not hold a value.
3) It can be driven and read.
4) Wires are used for connecting different modules.

Reg : 
1) Reg is a data storage element in System Verilog.
2) It's not an actual hardware register but it can store values.
3) Register retain their value until next assignment statement.

Logic : 
1) System Verilog added this additional datatype to make it easy to use the reg/wire datatype.
2) The main difference between logic datatype and reg/wire is that a logic can be driven by both continuous assignment or blocking/non-blocking assignment.

Source: asicguru.com (with little modification)

Thursday, September 13, 2012

Why we need functional verification?

1) A primary purpose for functional verification is to detect failures so that bugs can be identified and corrected before it gets shipped to costumer.  
2) If RTL designer makes a mistake in designing or coding, this results as a bug in the Chip. If this bug is executed, in certain situations the system will produce wrong results, causing a failure. 
3) Not all mistakes will necessarily result in failures. The bug in the dead code will never result in failure. 
4) A single mistake may result in a wide range of failure symptoms. Not all bugs are caused by coding errors. 
5) There are possibilities that error may in the specification itself. Sometimes miscommunications between teams may lead to wrong design.


Example of coding error:
    
     1 reg [1:0] state;
     2
     3 parameter zero=0, one=1, two=2, three=3;
     4
     5 always @(state)
     6     begin
     7          case (State)
     8               zero:
     9                    out = 4'b0000;
     10               one:
     11                   out = 4'b0001;
     12               two:
     13                   out = 4'b0010;
     14             three:
     15                   out = 4'b0100;
     16            default:
     17                   out = 4'b0000;
     18          endcase
     19     end
    
    

There is a coding error in the preceding example. Designer declared "state" in the line-1. Later in the code it is reference in the line-5. In the line-7 also, the designer intention is to refer "state". But mistakenly he typed "State".  Verilog is a case-sensitive language, and variable "State" and "state" are different and this will produce wrong results.

Tuesday, May 15, 2012

Simple D flipflop code in Verilog


Here is the simple D flipflop code in Verilog :







  // D flip-flop Code  2 module d_ff ( d, clk, q, q_bar);
  input d ,clk;
  output q, q_bar;
  wire d ,clk;
  reg q, q_bar;
       
  always @ (posedge clk)
  begin
    q <= d;
    q_bar <=  ! d;
  end 
 endmodule



Verilog is one of the HDL languages available in the industry for hardware designing. It allows us to design a Digital design at Behavior Level, Register Transfer Level (RTL), Gate level and at switch level. Verilog allows hardware designers to express their designs with behavioral constructs, deferring the details of implementation to a later stage in the final design.


Note: Sorry, It is a very old post which was stuck in the draft, I will post more simple code to understand the basics of electronics and language

Monday, April 9, 2012

Some useful links/sites for VLSI folks

1. http://www.asic-world
2. https://community.cadence.com
3. http://testbench.in
4. http://www.edaboard.com
5. https://www.edaplayground.com
6. http://vlsi-verification.blogspot.in
7. http://www.vlsiip.com/misc/q.html
8. http://asicwithankit.blogspot.my
9. http://www.learnuvmverification.com/index.php/2016/04/29/uvm-phasing/
10. https://www.youtube.com/watch?v=1pVolaKhxVM&t=6s     //perl tutorial video
11. https://www.linkedin.com/pulse/basics-uvm-structure-robin-garg?trk=hp-feed-article-title
12) http://www.asicguru.com/system-verilog/interview-questions/10/
13) https://neovlsi.wordpress.com
14) www.support.cadence.com //find your error with the abbreviation name or report an issue in the cadence tool
15) http://infocenter.arm.com/help/index.jsp //all the public arm IPs related information you can find here
16) http://www.hitequest.com/Hardware/El_hardware.htm  //digital design questions

Synchronous Reset vs Asynchronous Reset

Why Reset?

A Reset is required to initialize a hardware design for system operation and to force an ASIC into a known state for simulation.

A reset simply changes the state of the device/design/ASIC to a user/designer defined state. There are two types of reset, what are they? As you can guess them, they are Synchronous reset and Asynchronous reset.

Synchronous Reset

A synchronous reset signal will only affect or reset the state of the flip-flop on the active edge of the clock. The reset signal is applied as is any other input to the state machine.

Advantages:
  • The advantage to this type of topology is that the reset presented to all functional flip-flops is fully synchronous to the clock and will always meet the reset recovery time.
  • Synchronous reset logic will synthesize to smaller flip-flops, particularly if the reset is gated with the logic generating the d-input. But in such a case, the combinational logic gate count grows so the overall gate count savings may not be that significant.
  • Synchronous resets provide some filtering for the reset signal such that it is not affected by glitches unless they occur right at the clock edge. A synchronous reset is recommended for some types of designs where the reset is generated by a set of internal conditions. As the clock will filter the logic equation glitches between clock edges.
Disadvantages:
  • The problem in this topology is with reset assertion. If the reset signal is not long enough to be captured at an active clock edge (or the clock may be slow to capture the reset signal), it will result in failure of assertion. In such case, the design needs a pulse stretcher to guarantee that a reset pulse is wide enough to be present during the active clock edge.
  • Another problem with synchronous resets is that the logic synthesis cannot easily distinguish the reset signal from any other data signal. So proper care has to be taken with logic synthesis, else the reset signal may take the fastest path to the flip-flop input thereby making worst-case timing hard to meet.
  • In some power saving designs, the clocked is gated. In such designed only asynchronous reset will work.
  • Faster designs that are demanding low data path timing, can not afford to have extra gates and additional net delays in the data path due to logic inserted to handle synchronous resets.
Asynchronous Reset

An asynchronous reset will affect or reset the state of the flip-flop asynchronously i.e. no matter what the clock signal is. This is considered as high priority signal and system reset happens as soon as the reset assertion is detected.

Advantages:
  • High speeds can be achieved, as the data path is independent of a reset signal.
  • Another advantage favouring asynchronous resets is that the circuit can be reset with or without a clock present.
  • As in synchronous reset, no workaround is required for logic synthesis.
Disadvantages:
  • The problem with this type of reset occurs at logic de-assertion rather than at assertion like in synchronous circuits. If the asynchronous reset is released (reset release or reset removal) at or near the active clock edge of a flip-flop, the output of the flip-flop could go metastable.
  • Spurious resets can happen due to reset signal glitches.
Conclusion

Both types of resets have positives and negatives and none of them assures fail-proof design. So there is something called "Asynchronous assertion and Synchronous de-assertion" reset which can be used for best results.

source: internet and my experience 

Ethernet and more

Ethernet is a protocol under IEEE 802.33 standard User Datagram Protocol (UDP) UDP is a connectionless transport protocol. I...