top of page

Parity Check error in UART protocol checker

In last tutorial, we learnt about frame errors and how to add them to our checker. 

Today, let's learn about parity check error in UART. 

Let's again understand this with our example of two friends. 

​

Imagine you and your friend have a secret code to send messages to each other. The secret code is like a special pattern of colors or shapes that only you and your friend understand. 

Now, let's say you want to send a message to your friend, and you decide to use a special trick called parity. Parity is like having a magic ball that can tell you if there is an odd or even number of something.

So, before you send your message, you count the number of special shapes or colors in your message. If the number is even, you say "even" to the magic ball. If the number is odd, you say "odd."

When your friend receives the message, they also count the number of special shapes or colors. They do the same trick with their magic ball. If their magic ball says "even" but the number of shapes or colors is odd, or if their magic ball says "odd" but the number of shapes or colors is even, it means there is a problem. This is called a parity error.

It's like if you and your friend were playing a game and you said, "Let's have an even number of candies," but when your friend counts, they find an odd number of candies. It means something went wrong, and you need to check the message again to make sure it's correct.

The parity error helps you and your friend know if the message got mixed up or changed while it was being sent. It's like having a special detector that can spot if something is not quite right with the message.

So, when you hear the words "parity error," it means that the special trick to check if the number of shapes or colors is odd or even showed that something might be wrong with the message. You and your friend will need to double-check to make sure everything is okay.

​

Certainly! Here's a step-by-step tutorial on how to write a program in UVM (Universal Verification Methodology) to detect a parity error check in a UART protocol checker:

Step 1: Set up your UVM project by creating a new directory and organizing the necessary files and directories for your testbench.

Step 2: Define the UVM test environment by creating a new UVM environment class. This class will contain the components and configurations needed for the UART protocol checker.

Step 3: Create a UVM agent class for the UART protocol checker. This class will handle the monitoring and checking of the UART signals.

Step 4: Inside the UART agent class, create a task or function to monitor the UART signals and detect parity errors. This task/function should run continuously while the simulation is active.

Step 5: In the task/function, sample the received data and the parity bit from the UART signals.

Step 6: Implement the parity check algorithm within the task/function. This algorithm calculates whether the number of ones in the received data, including the parity bit, is odd or even.

Step 7: Compare the calculated parity with the received parity bit. If they do not match, raise a parity error flag or generate an appropriate error message to indicate a parity error.

Step 8: Instantiate the UART agent class in the UVM environment and connect it to the DUT (Device Under Test) module. This will allow the agent to monitor the UART signals from the DUT.

Step 9: Create a UVM test case to exercise the UART communication. This test case should include transactions with various parity settings to ensure that the protocol checker can detect parity errors accurately.

Step 10: Implement assertions or checks within the test case to verify that the parity error detection is working correctly. These assertions can verify that the parity error flag is raised when expected or that appropriate error messages are generated.

Step 11: Set up the UVM configuration and create a UVM test to run the test case.

Step 12: Run the UVM simulation and observe the results. The UART protocol checker should detect any parity errors that occur during the simulation and flag them accordingly.

By following these steps, you can write a UVM program to detect a parity error check in a UART protocol checker. The program will monitor the UART signals, perform the parity check, and raise appropriate flags or messages when a parity error is detected.

​

UVM code for parity error check for UART:

`include "uvm_macros.svh"

module UART;
  // Define the signals for UART communication
  wire rx;
  wire tx;
  // Other UART signals...

  // Your UART implementation goes here...

  // UART testbench
  initial begin
    // Create the UVM testbench
    uart_tb uart_testbench;
    
    // Initialize UVM components
    uvm_config_db#(virtual uart_tb)::set(null, "*", "vif", uart_testbench);
    uvm_config_db#(virtual uart)::set(null, "*", "vif", uart);
    
    // Start the test
    uvm_top.print_topology();
    run_test();
    
    // Simulation finished
    #10;
    $display("Simulation finished.");
    $finish;
  end
endmodule

// UVM testbench for UART
class uart_tb extends uvm_env;
  // Instantiate the UVM components
  uart_monitor uart_mon;
  uart_checker uart_chk;
 
  // Constructor
  function new(string name = "uart_tb", uvm_component parent = null);
    super.new(name, parent);
  endfunction
 
  // UVM macro for registering the component
  `uvm_component_utils(uart_tb)
 
  // Build the testbench components
  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    uart_mon = uart_monitor::type_id::create("uart_mon", this);
    uart_chk = uart_checker::type_id::create("uart_chk", this);
  endfunction
 
  // Connect the signals between DUT and testbench
  function void connect_phase(uvm_phase phase);
    super.connect_phase(phase);
    uart_mon.vif = vif;
    uart_chk.vif = vif;
  endfunction
 
  // Run the test
  task run_phase(uvm_phase phase);
    // Start your test scenario here...
    // Include test sequences, checks, etc.
  endtask
endclass

// UVM monitor for UART
class uart_monitor extends uvm_monitor;
  // Monitor variables and tasks...
  // Add data capture functionality here...
endclass

// UVM checker for UART
class uart_checker extends uvm_checker;
  // Checker variables and tasks...
  // Add parity error check implementation here...
endclass

// Top-level test
module tb;
  initial begin
    // Instantiate the UART module
    UART uart_module();
    
    // Instantiate the testbench
    uart_tb uart_testbench();
    
    // Connect the signals between the UART module and the testbench
    assign uart_module.rx = uart_testbench.uart_mon.rx;
    assign uart_module.tx = uart_testbench.uart_chk.tx;
    
    // Start the simulation
    #100;
    $finish;
  end
endmodule

// Simulation configuration
module top;
  initial begin
    // Configure the simulation time unit and precision
    `timescale 1ns/1ps
    
    // Instantiate the testbench
    tb testbench();
    
    // Start the simulation
    #100;
    $finish;
  end
endmodule

// Run the simulation
initial begin
  $dumpfile("dump.vcd");
  $dumpvars(0, top);
  $display("Starting simulation...");
  $timeformat(-9, 1, " ns", 10);
  top uut();
end
 

bottom of page