top of page

Frame check error in UART protocol checker

In last tutorial we just enhanced our protocol checker to check for the checking baud rate. 

Now, let's try to check for the frame check error during our transmission.

But before that let's understand it and using the two friends example that we always use. 

​

Imagine you have two friends, let's call them Alice and Bob, who want to send each other messages using a special language. They use a system called UART,.This system works by dividing messages into small pieces called "frames" and sending them one by one.

Now, when Alice sends a frame to Bob, she includes some extra information at the beginning and end of the frame. This extra information is like a special code that helps Bob understand the message properly. It's similar to when you write a letter and put your name at the top and a big smiley face at the bottom.

But sometimes, while the frame is traveling from Alice to Bob, something can go wrong. Maybe there's a noisy signal or a disturbance in the communication line. When that happens, the special code at the beginning and end of the frame can get messed up. It's like if you were playing a game of telephone, and someone whispered the wrong word to the person next to them.

When Bob receives the frame, he checks the special code at the beginning and end. If the codes match, it means the frame arrived safely, just like when you receive a letter with your name at the top and a smiley face at the bottom. But if the codes don't match, it means something went wrong during transmission, and Bob can't understand the message correctly. It's like if you received a letter with a strange name at the top and a sad face at the bottom.

So, when Bob sees that the special codes don't match, he knows there was a "frame check error." It tells him that the message he received is not reliable and might be garbled or incomplete. It's like getting a puzzle with some missing pieces or a coloring book with some pages torn out.

To fix this, Alice and Bob can try sending the frame again to make sure it arrives safely with the correct codes. They want to make sure their messages are clear and understandable, just like when you talk to your friends and want them to hear everything you say.

​

To test if the framing error checker is working correctly in your UART protocol checker, you can follow these steps:

Step 1: Create a Test Case
- Define a UVM test case specifically for testing the framing error checker.
- In this test case, generate test stimuli that include valid UART frames as well as frames with intentional framing errors.
- Randomize the timing of the frames to simulate realistic conditions.

Step 2: Instantiate the Framing Error Checker
- Instantiate the `FramingErrorChecker` component in your UVM testbench environment.
- Connect the relevant signals from the Device Under Test (DUT) to the `FramingErrorChecker` component, such as the RX signal.

Step 3: Drive Test Stimuli
- In your test case, drive the test stimuli by sending UART frames to the DUT.
- Include a mix of valid frames and frames with intentional framing errors.
- Ensure the test stimuli covers various scenarios, such as missing start bits, extra bits, or corrupted bits within the frame.

Step 4: Monitor and Verify Framing Errors
- During the simulation, monitor the output of the `FramingErrorChecker` component.
- Check if the framing error count matches the expected value for each frame with intentional errors.
- Ensure that the framing error checker correctly detects and reports framing errors.

Step 5: Assertions and Coverage
- Implement assertions in your testbench to check specific properties related to framing errors.
- Use coverage analysis to ensure that different types of framing errors are adequately tested.

Step 6: Analyze Results
- After running the simulation, review the results and check if the framing error checker behaves as expected.
- Verify that the framing errors are correctly detected and reported by the checker.
- If any issues are identified, debug and refine your implementation accordingly.

By following these steps, you can test the framing error checker in your UART protocol checker to ensure its correctness and effectiveness in detecting framing errors. Remember to consider various scenarios and intentional errors during the test case generation to thoroughly validate the functionality of the checker.

​

UVM Code: 

`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_driver uart_drv;
 
  // 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_drv = uart_driver::type_id::create("uart_drv", 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_drv.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 framing error check implementation here...
endclass

// UVM driver for UART
class uart_driver extends uvm_driver;
  // Driver variables and tasks...
  // Add transmit functionality 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_drv.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