Thursday, July 23, 2020

Telephone dialer code in system verilog

Problem Statement :
Write a sequence item for telephone dialer with the following data
1. RECEPTION             - 0
2. EMERGENCY          - 911
3. LOCAL                     - 8 Digit Number
4. INTERNATIONAL  - 11 Digit number starting with 1. < 1-10Digits >

With the above code we can derive the constraints for each dial type.
RECEPTION - Just 0
EMERGENCY - Just 911
LOCAL - 8 Digit number must not start with 0 or have 911 as its first few numbers
INTERNATIONAL - 11 digit telephone number must start with 1.


CODE

typedef enum { RECEPTION, EMERGENCY, LOCAL, INTERNATIONAL } dial_type;
class telephone;
  rand bit [3:0] tele[];
  rand dial_type d;

  constraint c_tele {
    d dist { RECEPTION:= 1, EMERGENCY:= 1, LOCAL:= 1, INTERNATIONAL:= 1};
    if(d == RECEPTION) {
      tele.size() == 1;
      tele[0] == 'd0;
    }
    if(d == EMERGENCY) {
      tele.size() == 3;
      tele[0] == 'd9;
      tele[1] == 'd1;
      tele[2] == 'd1;
    }
    if(d == LOCAL) {
      tele.size() == 8;
      foreach(tele[i]) {
        if(i==0) { tele[i] inside {[2:9]}; }
        else     { tele[i] inside {[0:9]}; }
    }
     {tele[0],tele[1],tele[2]} != {4'h9,4'h1,4'h1}; }
    if(d == INTERNATIONAL) {
      tele.size() == 11;
      foreach(tele[i]) {
        if(i==0) { tele[i] == 'd1; }
        else     { tele[i] inside {[0:9]}; }
      } 
    }

  }

  function void display();
    $display("DIAL_TYPE:%s NUM:%p",d,tele);
  endfunction: display
endclass

module top;
 telephone t;

 initial begin
   t = new;
   repeat(20) begin
   void'(t.randomize());
   t.display();
   end
 end

endmodule: top

No comments:

Post a Comment

Generating prime numbers between 1 to 100

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 class test ; int prime_q[$]; function voi...