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 UART Scoreboard
   

space.gif


  1 class uart_sb {
  2    integer tx;
  3    integer rx;
  4 
  5   task new() {
  6     tx = alloc(MAILBOX,0,1);
  7     rx = alloc(MAILBOX,0,1);
  8   }
  9 
 10   task txAdd(bit [7:0] data) {
 11     mailbox_put(tx,data);
 12     printf("%dns : txAdd     : Added data %x\n",get_cycle(), data);
 13   }
 14 
 15   task rxAdd(bit [7:0] data) {
 16     mailbox_put(rx,data);
 17     printf("%dns : rxAdd     : Added data %x\n",get_cycle(), data);
 18   }
 19 
 20   task txCompare(bit [7:0] data) {
 21     bit [7:0] org_data;
 22     mailbox_get (WAIT,tx,org_data);
 23     if (data  ! = org_data) {
 24       printf("%dns : txCompare : Error : Expected data %x, Got %x\n",
 25        get_cycle(), org_data, data); 
 26     } else {
 27       printf("%dns : txCompare : Match : Expected data %x, Got %x\n",
 28        get_cycle(), org_data, data); 
 29     }
 30   }
 31 
 32   task rxCompare(bit [7:0] data) {
 33     bit [7:0] org_data;
 34     mailbox_get (WAIT,rx,org_data);
 35     if (data  ! = org_data) {
 36       printf("%dns : rxCompare : Error : Expected data %x, Got %x\n",
 37         get_cycle(), org_data, data); 
 38     } else {
 39       printf("%dns : rxCompare : Match : Expected data %x, Got %x\n",
 40        get_cycle(), org_data, data); 
 41     }
 42   }
 43 }
You could download file vera_examples here
   

space.gif

  ../../images/main/bulllet_4dots_orange.gif UART Transcation Generator
   

space.gif


   1 class uart_txgen {
   2    uart_sb sb;
   3    uart_ports ports;
   4    bit tx_done;
   5    bit rx_done;
   6 
   7    // Connects the transmitter output to recevier input
   8    bit loopback;
   9    // Number of frames to send to transmitter
  10    integer no_tx_cmds;
  11    // Number of frames to send to receiver
  12    integer no_rx_cmds;
  13    // Delay the reading of data from receiver
  14    bit rx_over_flow;
  15    // Send frame to transmitter before it has sent out last frame
  16    bit tx_over_flow;
  17    // Insert framming error (stop bit) in frame sent to receiver
  18    bit rx_frame_err;
  19 
  20    task new () {
  21      this.ports = uart_p;
  22      sb = new();
  23      tx_done = 0;
  24      rx_done = 0;
  25      no_tx_cmds = 5;
  26      no_rx_cmds = 5;
  27      rx_over_flow = 0;
  28      rx_frame_err = 0;
  29      ports.$rx_tb_in = 1;
  30      ports.$uld_rx_data = 0;
  31    }
  32   
  33    // Main method, which starts rest of methods 
  34    task goTxgen() {
  35      tx_done = 0;
  36      rx_done = 0;
  37      assertReset();
  38      fork 
  39        { txDriver();  }
  40        { rxDriver();  }
  41        { txMonitor(); }
  42        { rxMonitor(); }
  43      join none
  44    }
  45    // This method asserts method
  46    task assertReset() {
  47       @ (posedge ports.$rxclk);
  48       ports.$reset = 1;
  49       printf("%dns : Asserting reset to Uart\n",get_cycle());
  50       repeat (5) @ (posedge ports.$rxclk);
  51       ports.$reset = 0;
  52    }
  53 
  54    task txDriver()  {
  55      integer i = 0;
  56      integer tx_timeout = 0;
  57      bit [7:0] tx_data = 0;
  58      ports.$tx_enable = 1;
  59      for (i = 0; i < no_tx_cmds; i ++)  {
  60        tx_data = random();
  61        sb.txAdd(tx_data);
  62        if (loopback == 1) {
  63          sb.rxAdd(tx_data);
  64        }
  65        // Check if uart is ready to accept data for transmission
  66        while (ports.$tx_empty == 0) {
  67          @ (posedge ports.$txclk);
  68          tx_timeout ++ ;
  69          if (tx_timeout > 10) {
  70            printf("%dns : txDriver : Warning : tx_empty is 0 for more then 10 clocks\n",
  71              get_cycle());
  72          }
  73        }
  74        tx_timeout = 0;
  75        // Drive the data in UART for transmitting
  76        @ (posedge ports.$txclk);
  77        ports.$ld_tx_data = 1;
  78        ports.$tx_data    = tx_data;
  79        printf("%dns : txDriver  : Transmitting data %x\n",get_cycle(), tx_data);
  80        @ (posedge ports.$txclk);
  81        ports.$ld_tx_data = 0;
  82        ports.$tx_data    = 0;
  83        while (ports.$tx_empty == 1) {
  84          @ (posedge ports.$txclk);
  85          tx_timeout ++ ;
  86          if (tx_timeout > 10) {
  87            printf("%dns : txDriver : Warning : tx_empty is 1 for more then 10 clocks\n",
  88              get_cycle());
  89          }
  90        }
  91        tx_timeout = 0;
  92      }
  93      tx_done = 1;
  94    }
  95 
  96    task rxDriver() {
  97      bit [7:0] rx_data = 0;
  98      integer i,j = 0;
  99      ports.$rx_enable = 1;
 100      if (loopback == 1) {
 101        ports.$loopback = 1;
 102      } else {
 103        ports.$loopback = 0;
 104        for (i = 0; i < no_rx_cmds; i++)  {
 105          rx_data = random(); 
 106          sb.rxAdd(rx_data);
 107          printf("%dns : rxDriver  : Transmitting data %x\n",get_cycle(), rx_data);
 108          @ (posedge ports.$txclk);
 109          ports.$rx_in = 0;
 110          for (j = 0; j < 8; j ++) {
 111            @ (posedge ports.$txclk);
 112            ports.$rx_in = rx_data[j];
 113          }
 114          @ (posedge ports.$txclk);
 115          ports.$rx_in = 1;
 116          @ (posedge ports.$txclk);
 117        }
 118      }
 119      rx_done = 1;
 120    }
 121 
 122    task txMonitor() {
 123      bit [7:0] tx_data = 0;
 124      integer i = 0;
 125      while (1) {
 126        @ (posedge ports.$txclk async);
 127        if (ports.$tx_out == 0) {
 128           printf("%dns : txMonitor : Found start of frame\n",get_cycle());
 129           for (i = 0; i < 8; i ++)  {
 130             @ (posedge ports.$txclk async);
 131             tx_data[i] = ports.$tx_out;
 132           }
 133           @ (posedge ports.$txclk async);
 134           if (ports.$tx_out == 0) {
 135             printf("%dns : txMonitor Error : Framing error detecting\n",get_cycle());
 136             sb.txCompare(8'b0);
 137           } else {
 138             printf("%dns : txMonitor : Sampled data %x\n",get_cycle(), tx_data);
 139             sb.txCompare(tx_data);
 140           }
 141        }
 142      }
 143    }
 144 
 145    task rxMonitor()  {
 146      bit [7:0] rx_data = 0;
 147      while (1) {
 148        @ (posedge ports.$txclk);
 149        if (ports.$rx_empty == 0) {
 150          ports.$uld_rx_data = 1;
 151          @ (posedge ports.$txclk);
 152          rx_data = ports.$rx_data;
 153          ports.$uld_rx_data = 0;
 154          printf("%dns : rxMonitor : Sampled data %x\n",get_cycle(), rx_data);
 155          sb.rxCompare(rx_data);
 156          @ (posedge ports.$txclk);
 157        }
 158      }
 159    }
 160    
 161    function bit isDone() {
 162      if (tx_done == 1 && rx_done == 1) {
 163        isDone =  1;
 164      } else {
 165        isDone = 0;
 166      }
 167    }
 168 }
You could download file vera_examples here
   

space.gif

   

space.gif

  ../../images/main/bulllet_4dots_orange.gif Interface File
   

space.gif


  1 #ifndef UART_IF_VRH
  2 #define UART_IF_VRH
  3 
  4 #include "vera_defines.vrh"
  5 
  6 interface uart_if {
  7   input       rxclk          CLOCK;
  8   input       txclk          PSAMPLE NSAMPLE #-1;
  9   inout       reset          PHOLD NHOLD #1 PSAMPLE NSAMPLE #-1;
 10   inout       ld_tx_data     PHOLD NHOLD #1 PSAMPLE NSAMPLE #-1;
 11   inout [7:0] tx_data        PHOLD NHOLD #1 PSAMPLE NSAMPLE #-1;
 12   inout       tx_enable      PHOLD NHOLD #1 PSAMPLE NSAMPLE #-1;
 13   inout       tx_out         PHOLD NHOLD #1 PSAMPLE NSAMPLE #-1;
 14   inout       tx_empty       PHOLD NHOLD #1 PSAMPLE NSAMPLE #-1;
 15   inout       uld_rx_data    PHOLD NHOLD #1 PSAMPLE NSAMPLE #-1;
 16   inout [7:0] rx_data        PHOLD NHOLD #1 PSAMPLE NSAMPLE #-1;
 17   inout       rx_enable      PHOLD NHOLD #1 PSAMPLE NSAMPLE #-1;
 18   inout       rx_in          PHOLD NHOLD #1 PSAMPLE NSAMPLE #-1;
 19   inout       rx_empty       PHOLD NHOLD #1 PSAMPLE NSAMPLE #-1;
 20   inout       loopback       PHOLD NHOLD #1 PSAMPLE NSAMPLE #-1; 
 21   inout       rx_tb_in       PHOLD NHOLD #1 PSAMPLE NSAMPLE #-1;
 22 }
 23 
 24 #endif
 25 
You could download file vera_examples here
   

space.gif

  ../../images/main/bulllet_4dots_orange.gif Ports File
   

space.gif


  1 #ifndef UART_PORTS_H
  2 #define UART_PORTS_H
  3 port uart_ports {
  4   reset          ;
  5   txclk          ;
  6   ld_tx_data     ;
  7   tx_data        ;
  8   tx_enable      ;
  9   tx_out         ;
 10   tx_empty       ;
 11   rxclk          ;
 12   uld_rx_data    ;
 13   rx_data        ;
 14   rx_enable      ;
 15   rx_in          ;
 16   rx_empty       ;
 17   loopback       ; 
 18   rx_tb_in       ;
 19 }
 20 #endif
You could download file vera_examples here
   

space.gif

  ../../images/main/bulllet_4dots_orange.gif Binds File
   

space.gif


  1 #ifndef UART_BINDS_VRH
  2 #define UART_BINDS_VRH
  3 
  4 bind uart_ports uart_p {
  5   reset         uart_if.reset      ;
  6   txclk         uart_if.txclk      ;
  7   ld_tx_data    uart_if.ld_tx_data ;
  8   tx_data       uart_if.tx_data    ;
  9   tx_enable     uart_if.tx_enable  ;
 10   tx_out        uart_if.tx_out     ;
 11   tx_empty      uart_if.tx_empty   ;
 12   rxclk         uart_if.rxclk      ;
 13   uld_rx_data   uart_if.uld_rx_data;
 14   rx_data       uart_if.rx_data    ;
 15   rx_enable     uart_if.rx_enable  ;
 16   rx_in         uart_if.rx_in      ;
 17   rx_empty      uart_if.rx_empty   ;
 18   loopback      uart_if.loopback   ; 
 19   rx_tb_in      uart_if.rx_tb_in   ;
 20 }
 21 
 22 #endif
You could download file vera_examples here
   

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