Verification Practice - CPU - POR - EDA Playground
Warning! This exercise has been opened in another tab; autosave has been disabled. Close this tab or refresh to reactivate.

 Languages & Libraries

 Tools & Simulators

 Examples

208


7
 
1
package cpu_rtl_pkg;
2
// opcodes
3
typedef enum logic [2:0] {HLT, SKZ, ADD, AND, XOR, LDA, STO, JMP} opcode_t;
4
// sequential states of controller state machine
5
typedef enum {INST_ADDR, INST_FETCH, INST_LOAD, IDLE, OP_ADDR, OP_FETCH, ALU_OP, STORE} state_t; 
6
7
endpackage : cpu_rtl_pkg
79
 
1
///////////////////////////////////////////////////////////////////////////
2
// (c) Copyright 2013 Cadence Design Systems, Inc. All Rights Reserved.
3
//
4
// File name   : control.sv
5
// Title       : Control Module
6
// Project     : SystemVerilog Training
7
// Created     : 2013-4-8
8
// Description : Defines the Control module
9
// Notes       :
10
// 
11
///////////////////////////////////////////////////////////////////////////
12
13
// SystemVerilog package for opcode_t and state_t
14
import cpu_rtl_pkg::*;
15
16
module control  (
17
                output logic      load_ac ,
18
                output logic      mem_rd  ,
19
                output logic      mem_wr  ,
20
                output logic      inc_pc  ,
21
                output logic      load_pc ,
22
                output logic      load_ir ,
23
                output logic      halt    ,
24
                input  opcode_t opcode  ,
25
                input             zero    ,
26
                input             clk     ,
27
                input             rst_   
28
                );
29
// SystemVerilog: time units and time precision specification
30
timeunit 1ns;
31
timeprecision 100ps;
32
33
state_t state;
34
35
logic aluop;
36
37
assign aluop = (opcode inside {ADD, AND, XOR, LDA});
38
39
always_ff @(posedge clk or negedge rst_)
40
  if (!rst_)
41
     state <= INST_ADDR;
42
  else
43
     state <= state.next();
44
45
always_comb  begin
46
  {mem_rd, load_ir, halt, inc_pc, load_ac, load_pc, mem_wr}  =  7'b000_0000;
47
  unique case (state)
48
    INST_ADDR : ;
49
    INST_FETCH: mem_rd = 1;    
50
    INST_LOAD : begin         
51
                mem_rd = 1;   
52
                load_ir = 1;  
53
                end
54
    IDLE      : begin
55
                mem_rd = 1;  
56
                load_ir = 1; 
57
                end
58
    OP_ADDR   : begin       
59
                inc_pc = 1;
60
                halt = (opcode == HLT);
61
                end
62
    OP_FETCH  : mem_rd = aluop; 
63
    ALU_OP    : begin          
64
                load_ac = aluop;
65
                mem_rd = aluop;
66
                inc_pc = ((opcode == SKZ) && zero);
67
                load_pc = ( opcode == JMP);
68
                end
69
    STORE     : begin
70
                load_ac = aluop;
71
                mem_rd = aluop;
72
                inc_pc = (opcode == JMP);
73
                load_pc = ( opcode == JMP);
74
                mem_wr = ( opcode == STO);
75
                end
76
  endcase
77
  end
78
79
endmodule
194 views and 1 likes     
 
Verification Practice - CPU - POR
Notes:
-An EDA Playground bug may require untoggling the "Show output file after run" radio button under "Run Options".
-EDA Playground is great, but can be glitchy and laggy. Sim last confirmed functional June 21, 2023.
-CPU test details: Binary loaded into memory from cpu_testbench_top.sv ($readmemb), prior to test start.  A test is run without stimulus (already loaded in memory), and an objection in the scoreboard is dropped when the CPU has reached a designated 'success address'. The assumption is that if the CPU is not working properly, it will not reach the 'success address'.
-I produced the testbench (and improved it with feedback from others!), but the CPU RTL is from a Cadence training course.
-Block level testbenches linked on project github page, below.
Project summary: 
https://github.com/taylortempleton/VerificationPractice_SimpleCPU

Verification Practice - CPU - POR

Notes:
-An EDA Playground bug may require untoggling the "Show output file after run" radio button under "Run Options".
-EDA Playground is great, but can be glitchy and laggy. Sim last confirmed functional June 21, 2023.
-CPU test details: Binary loaded into memory from cpu_testbench_top.sv ($readmemb), prior to test start. A test is run without stimulus (already loaded in memory), and an objection in the scoreboard is dropped when the CPU has reached a designated 'success address'. The assumption is that if the CPU is not working properly, it will not reach the 'success address'.
-I produced the testbench (and improved it with feedback from others!), but the CPU RTL is from a Cadence training course.
-Block level testbenches linked on project github page, below.

Project summary:
https://github.com/taylortempleton/VerificationPractice_SimpleCPU

121370:0