quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Program with Interface

Program block in most of the cases use intefaces to connect with external world, when number of ports need to connect is large.

   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif Example : Program Interface
   

space.gif


  1 //+++++++++++++++++++++++++++++++++++++++++++++++++
  2 // Define the interface
  3 //+++++++++++++++++++++++++++++++++++++++++++++++++
  4 interface mem_if (
  5   input  wire         clk,
  6   output logic        reset,
  7   output logic        enable,
  8   input  wire [3:0]   count
  9 );
 10 endinterface
 11 //+++++++++++++++++++++++++++++++++++++++++++++++++
 12 // Simple Program with ports
 13 //+++++++++++++++++++++++++++++++++++++++++++++++++
 14 program if_program(mem_if mem);
 15   //=================================================
 16   // Initial block inside program block
 17   //=================================================
 18   initial begin
 19     $monitor("@%0dns count = %0d",$time,mem.count);
 20     mem.reset = 1;
 21     mem.enable = 0;
 22      #20  mem.reset = 0;
 23     @ (posedge mem.clk);
 24     mem.enable = 1;
 25     repeat (5) @ (posedge mem.clk);
 26     mem.enable = 0;
 27   end
 28 endprogram
 29 //=================================================
 30 //  Module which instanciates program block
 31 //=================================================
 32 module simple_program();
 33 logic clk  = 0;
 34 always  #1  clk ++;
 35 logic [3:0] count;
 36 wire reset,enable;
 37 //=================================================
 38 // Connect the interface
 39 //=================================================
 40 mem_if inf(
 41  .clk    (clk)   ,
 42  .reset  (reset) ,
 43  .enable (enable),
 44  .count  (count)
 45 );
 46 //=================================================
 47 // Simple up counter
 48 //=================================================
 49 always @ (posedge clk)
 50  if (reset) count <= 0;
 51  else if (enable) count ++;
 52 //=================================================
 53 // Program is connected like a module
 54 //=================================================
 55 if_program prg_simple(
 56  .mem      (inf)
 57 );
 58 endmodule
You could download file if_program.sv here
   

space.gif

  ../images/main/bullet_star_pink.gif Simulation : Program Interface
   

space.gif

 @0ns count = x
 @1ns count = 0
 @23ns count = 1
 @25ns count = 2
 @27ns count = 3
 @29ns count = 4
 @31ns count = 5
   

space.gif

   

space.gif

   

space.gif

   

space.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

  

Copyright 1998-2014

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at:deepak@asic-world.com