# How to resolve this error

**URL:** <https://verificationacademy.com/forums/t/how-to-resolve-this-error/35745>\
**Category:** UVM\
**Tags:** uvm-factory, UVM, uvm-ral, UVM-callback, uvm-verilog\
**Created:** [February 13, 2019, 2:08pm UTC](https://verificationacademy.com/forums/t/how-to-resolve-this-error/35745 "2019-02-13T14:08:39Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sree\_N](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@Sree\_N](https://verificationacademy.com/forums/u/Sree_N)\
**Post date:** [February 13, 2019, 2:08pm UTC](https://verificationacademy.com/forums/t/how-to-resolve-this-error/35745/1 "2019-02-13T14:08:39Z")

</div>

\*\* Error: (vlog-13069) E:/uvmp/sequence\_item.sv(1): near “uvm\_sequence\_item”: syntax error, unexpected IDENTIFIER.

# 

# \*\* Error: E:/uvmp/sequence\_item.sv(1): Error in class extension specification.

---

<div class="post-metadata">

**Author:** ![chr\_sue](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/chr_sue/32/1199_2.png) [@chr\_sue](https://verificationacademy.com/forums/u/chr_sue)\
**Post date:** [February 13, 2019, 6:46pm UTC](https://verificationacademy.com/forums/t/how-to-resolve-this-error/35745/2 "2019-02-13T18:46:49Z")

</div>

_In reply to [Sree N](https://verificationacademy.com/forums/t/how-to-resolve-this-error/35745):_

> \*\* Error: (vlog-13069) E:/uvmp/sequence\_item.sv(1): near “uvm\_sequence\_item”: syntax error, unexpected IDENTIFIER.

# 

# \*\* Error: E:/uvmp/sequence\_item.sv(1): Error in class extension specification.

It seems you did not import the uvm\_pkg.

---

<div class="post-metadata">

**Author:** ![Sree\_N](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@Sree\_N](https://verificationacademy.com/forums/u/Sree_N)\
**Post date:** [February 14, 2019, 1:25pm UTC](https://verificationacademy.com/forums/t/how-to-resolve-this-error/35745/3 "2019-02-14T13:25:37Z")

</div>

//top module  
`include "uvm_macros.svh" `include “spi\_pkg.sv”  
`include "spi_if.sv" //`include “uvm\_pkg.sv”  
//-------------------------------------------------------------  
module test;  
import uvm\_pkg::_;  
import spi\_pkg::_;  
//import my\_package::\*;  
spi\_if master(clock); // Interface declaration  
spi\_if slave(clock); // Interface declaration

/_------------------SPI master core--------------------------- /  
spi top (  
/ tb to DUT connection /  
.wb\_clk\_i(clock),  
.wb\_rst\_i(rstn),  
.wb\_adr\_i(master.adr[4:0]),  
.wb\_dat\_i(master.dout),  
.wb\_sel\_i(master.sel),  
.wb\_we\_i(master.we),  
.wb\_stb\_i(master.stb),  
.wb\_cyc\_i(master.cyc),  
.wb\_dat\_o(master.din),  
.wb\_ack\_o(master.ack),  
.wb\_err\_o(master.err),  
.wb\_int\_o(master.intp),  
.scan\_in0(scan\_in0),  
.scan\_out0(scan\_out0),  
.scan\_en(scan\_en),  
.test\_mode(test\_mode),  
/ master ito slave connection /  
.ss\_pad\_o(ss),  
.sclk\_pad\_o(sclk),  
.mosi\_pad\_o(mosi),  
.miso\_pad\_i(miso),  
.tip(master.pit));  
/------------------SPI slave core---------------------------_/   
spi\_slave spi\_slave (  
/\* tb to DUT connection _/  
.wb\_clk\_i(clock),  
.wb\_rst\_i(rstn),  
.wb\_adr\_i(slave.adr[4:0]),  
.wb\_dat\_i(slave.dout),  
.wb\_sel\_i(slave.sel),  
.wb\_we\_i(slave.we),  
.wb\_stb\_i(slave.stb),  
.wb\_cyc\_i(slave.cyc),  
.wb\_dat\_o(slave.din ),  
.wb\_ack\_o(slave.ack),  
.wb\_err\_o(slave.err),  
.wb\_int\_o(slave.intp),  
.scan\_in0(scan\_in0),  
.scan\_en(scan\_en),  
.test\_mode(test\_mode),  
.scan\_out0(scan\_out0),  
/_ slave to master connection \*/  
.ss\_pad\_i(ss),  
.sclk\_pad\_i(sclk),  
.mosi\_pad\_i(mosi),  
.miso\_pad\_o(miso));  
//-------------------------------------------------------------  
initial begin  
$timeformat(-9,2,“ns”,16);  
//$timeformat [( units\_number , precision\_number , suffix\_string , minimum\_field\_width )];  
$set\_coverage\_db\_name(“spi”);  
`ifdef SDFSCAN $sdf_annotate("sdf/spi_tsmc18_scan.sdf",test.top); `endif  
generate\_clock();  
reg\_intf\_to\_config\_db();  
initalize\_dut();  
// reset\_dut(); // could also be carried out inside pre\_reset\_phase  
run\_test();  
end

// --------------------------------------------------------------  
task generate\_clock();  
fork  
forever begin  
clock =`LOW; #(CLOCK_PERIOD/2); clock =`HIGH;  
#(CLOCK\_PERIOD/2);  
end  
join\_none  
endtask:generate\_clock

//-------------------------------------------------------------

function void reg\_intf\_to\_config\_db();  
// Registers the Interface in the configuration block so that other blocks can use it retrived using get  
uvm\_config\_db#(virtual spi\_if)::set(null, “_" , “m\_if” , master);  
uvm\_config\_db#(virtual spi\_if)::set(null, "_” , “s\_if” , slave);  
endfunction : reg\_intf\_to\_config\_db

//-------------------------------------------------------------

function void initalize\_dut();  
test\_mode = 1’b0;  
scan\_in0 = 1’b0;  
scan\_in1 = 1’b0;  
scan\_en = 1’b0;  
endfunction : initalize\_dut

//-------------------------------------------------------------

task reset\_dut();  
rstn \<= `LOW; repeat (RESET_PERIOD)@( posedge clock); rstn <= `HIGH;  
repeat (RESET\_PERIOD)@( posedge clock);  
rstn = `LOW;  
//-\>RST\_DONE;  
endtask : reset\_dut  
//-------------------------------------------------------------  
endmodule : test

---

<div class="post-metadata">

**Author:** ![Sree\_N](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@Sree\_N](https://verificationacademy.com/forums/u/Sree_N)\
**Post date:** [February 14, 2019, 1:26pm UTC](https://verificationacademy.com/forums/t/how-to-resolve-this-error/35745/4 "2019-02-14T13:26:41Z")

</div>

//test module  
class spi\_test extends uvm\_test;

//-------------------------------------------------------------  
`uvm_component_utils(spi_test) spi_env env; spi_sequence h_seq; //Constructor function new(string name=" spi_test " , uvm_component parent); super.new(name,parent); endfunction : new //Build Phase function void build_phase(uvm_phase phase); super.build_phase(phase); `uvm\_info(get\_full\_name() ,"Build phase called in spi\_test " ,UVM\_LOW)  
/\* Build environment component\*/  
env=spi\_env::type\_id::create(“env” , this);  
endfunction : build\_phase  
//Connect Phase  
function void connect\_phase(uvm\_phase phase);  
super.connect\_phase(phase);  
`uvm_info(get_full_name() ,"Connect phase called in spi_test " ,UVM_LOW) endfunction : connect_phase //Reset Phase task reset_phase(uvm_phase phase); phase.raise_objection(this); rstn <=`LOW;  
repeat (RESET\_PERIOD) @(posedge clock);  
rstn \<=`HIGH; repeat (RESET_PERIOD) @(posedge clock); rstn =`LOW;  
phase.drop\_objection(this);  
endtask : reset\_phase  
//Main Phase  
virtual task main\_phase(uvm\_phase phase);  
`uvm\_info(get\_full\_name() ,“in main phase” ,UVM\_LOW)  
phase.raise\_objection(this);  
h\_seq=spi\_sequence::type\_id::create(“h\_seq”);  
repeat (100)  
h\_seq.start(env.agent.sequencer);  
phase.drop\_objection(this);  
endtask : main\_phase  
endclass : spi\_test

---

<div class="post-metadata">

**Author:** ![Sree\_N](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@Sree\_N](https://verificationacademy.com/forums/u/Sree_N)\
**Post date:** [February 14, 2019, 1:27pm UTC](https://verificationacademy.com/forums/t/how-to-resolve-this-error/35745/5 "2019-02-14T13:27:56Z")

</div>

//env module  
class spi\_env extends uvm\_env;  
//-------------------------------------------------------------  
`uvm\_component\_utils(spi\_env)  
spi\_agent agent;  
spi\_scoreboard scoreboard;

//Constructor  
function new(string name=“spi\_env” ,uvm\_component parent);  
super.new(name,parent);  
endfunction : new

//Build Phase  
function void build\_phase(uvm\_phase phase);  
super.build\_phase(phase);  
`uvm\_info(get\_full\_name (),“Build phase called in spi\_environment” ,UVM\_LOW)  
/\* Build agent and scoreboard components \*/  
agent=spi\_agent::type\_id::create(“agent” , this);  
scoreboard=spi\_scoreboard::type\_id::create(“scoreboard” , this);  
endfunction : build\_phase

//Connect Phase  
function void connect\_phase(uvm\_phase phase);  
super.connect\_phase(phase);  
`uvm\_info(get\_full\_name() ,“Connect phase called in spi\_environment” ,UVM\_LOW)  
/\* Connect the analysis port for monitor and driver respectively with scorboard \*/  
agent.monitor.dut\_out\_pkt.connect(scoreboard.mon2sb);  
agent.driver.dut\_in\_pkt.connect(scoreboard.drv2sb);  
endfunction : connect\_phase  
//-------------------------------------------------------------  
endclass : spi\_env

---

<div class="post-metadata">

**Author:** ![Sree\_N](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@Sree\_N](https://verificationacademy.com/forums/u/Sree_N)\
**Post date:** [February 14, 2019, 1:28pm UTC](https://verificationacademy.com/forums/t/how-to-resolve-this-error/35745/6 "2019-02-14T13:28:29Z")

</div>

class spi\_monitor extends uvm\_monitor;  
`uvm_component_utils(spi_monitor) spi_vif m_vif , s_vif; spi_sequence_item packet; uvm_analysis_port #(spi_sequence_item)dut_out_pkt; //Constructor function new(string name=" spi_monitor " ,uvm_component parent); super.new(name , parent); dut_out_pkt=new(" dut_out_pkt " , this); endfunction : new //Build Phase function void build_phase(uvm_phase phase); super.build_phase(phase); `uvm\_info(get\_full\_name(),“Build phase called in spi\_monitor " ,UVM\_LOW)  
if (!uvm\_config\_db#(virtual spi\_if)::get(this , “” , “m\_if” , m\_vif))  
`uvm_fatal ("NO_VIF" ,{" virtual interface must be set for : " ,get_full_name() ,".m_vif"}) if (!uvm_config_db#(virtual spi_if)::get(this , "" , "s_if",s_vif )) `uvm\_fatal(“NO\_VIF” ,{“virtual interface must be set for : " , get\_full\_name() ,”.s\_vif”})  
endfunction : build\_phase  
//Run Phase  
task run\_phase(uvm\_phase phase);  
packet=spi\_sequence\_item::type\_id::create(“packet”);  
wait (m\_vif.monitor\_cb.pit==1’b1) // wait\_to\_start  
forever begin  
wait(m\_vif.monitor\_cb.pi ==1’b0) // wait\_to\_complete  
wb\_bfm::wb\_read(m\_vif , 1, SPI\_RX\_0 , packet.out\_master\_data);  
wb\_bfm::wb\_read(s\_vif , 1, SPI\_RX\_0 , packet.out\_slave\_data);  
dut\_out\_pkt.write(packet);  
wait (m\_vif.monitor\_cb.pit ==1’b1); // wait\_to\_start  
end  
endtask : run\_phase  
endclass : spi\_monitor

---

<div class="post-metadata">

**Author:** ![Sree\_N](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@Sree\_N](https://verificationacademy.com/forums/u/Sree_N)\
**Post date:** [February 14, 2019, 1:29pm UTC](https://verificationacademy.com/forums/t/how-to-resolve-this-error/35745/7 "2019-02-14T13:29:09Z")

</div>

class spi\_driver extends uvm\_driver #(spi\_sequence\_item);  
`uvm_component_utils(spi_driver) spi_vif m_vif , s_vif; spi_sequence_item packet; uvm_analysis_port#(spi_sequence_item)dut_in_pkt; //Constructor function new(string name="spi_monitor" ,uvm_component parent); super.new(name , parent); dut_in_pkt=new("dut_in_pkt " , this); endfunction : new //Build Phase function void build_phase(uvm_phase phase); super.build_phase(phase); `uvm\_info(get\_full\_name() ,“Build phase called in spi\_driver " ,UVM\_LOW)  
if(!uvm\_config\_db#(virtual spi\_if)::get(this , “” , “m\_if " , m\_vif))  
`uvm_fatal("NO_VIF" ,{" virtual interface must be set for : " , get_full_name() ,".m_vif"}) if(!uvm_config_db#(virtual spi_if)::get(this , "" , " s_if " , s_vif ) ) `uvm\_fatal (“NO\_VIF” ,{” virtual interface must be set for : " , get\_full\_name () ,” . s\_vif "})  
endfunction : build\_phase  
//Run Phase  
task run\_phase(uvm\_phase phase);  
packet=spi\_sequence\_item::type\_id::create("packet ");  
wb\_bfm::wb\_reset(m\_vif);  
wb\_bfm::wb\_reset(s\_vif);  
fork  
forever begin  
seq\_item\_port.get\_next\_item(req);  
drive\_transfer(req);  
$cast(packet,req.clone());  
packet=req;  
dut\_in\_pkt.write(packet);  
seq\_item\_port.item\_done();  
wait(m\_vif.monitor\_cb.pit==1’b0);  
end  
join\_none  
endtask : run\_phase  
task drive\_transfer(spi\_sequence\_item seq);  
wb\_bfm::wb\_write(m\_vif , 0, SPI\_DIVIDE , seq.divider\_reg); // set divider register  
wb\_bfm::wb\_write(m\_vif , 0, SPI\_SS , seq.slave\_select\_reg); // set ss 0  
wb\_bfm::wb\_write(m\_vif , 0, SPI\_TX\_0 , seq.in\_master\_data); // set master data register  
wb\_bfm::wb\_write(m\_vif , 0, SPI\_CTRL, seq.master\_ctrl\_reg); // set master ctrl register  
wb\_bfm::wb\_write(s\_vif, 0, SPI\_CTRL, seq.slave\_ctrl\_reg); // set slave ctrl register  
wb\_bfm::wb\_write(s\_vif, 0, SPI\_TX\_0 , seq.in\_slave\_data); // set slave data register  
wb\_bfm::wb\_write(m\_vif , 0, SPI\_CTRL, seq.start\_dut\_reg); // start data transfer  
endtask : drive\_transfer  
endclass : spi\_driver

---

<div class="post-metadata">

**Author:** ![Sree\_N](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@Sree\_N](https://verificationacademy.com/forums/u/Sree_N)\
**Post date:** [February 14, 2019, 1:29pm UTC](https://verificationacademy.com/forums/t/how-to-resolve-this-error/35745/8 "2019-02-14T13:29:38Z")

</div>

class spi\_sequencer extends uvm\_sequencer#(spi\_sequence\_item);  
`uvm\_component\_utils(spi\_sequencer)  
//Constructor  
function new(string name=" spi\_sequencer " ,uvm\_component parent);  
super.new(name , parent);  
endfunction : new  
endclass : spi\_sequencer

---

<div class="post-metadata">

**Author:** ![Sree\_N](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@Sree\_N](https://verificationacademy.com/forums/u/Sree_N)\
**Post date:** [February 14, 2019, 1:30pm UTC](https://verificationacademy.com/forums/t/how-to-resolve-this-error/35745/9 "2019-02-14T13:30:20Z")

</div>

class spi\_sequence extends uvm\_sequence #(spi\_sequence\_item);  
`uvm\_object\_utils(spi\_sequence)  
//Constructor  
function new(string name=“spi\_sequence”);  
super.new(name);  
endfunction : new  
//Task Body  
virtual task body();  
req=spi\_sequence\_item::type\_id::create(“req”);  
start\_item(req);  
configure\_dut\_register();  
set\_dut\_data();  
finish\_item(req);  
endtask : body  
virtual function void configure\_dut\_register();  
assert(req.randomize() with  
{  
req.master\_ctrl\_reg == 32’h00002208;  
req.slave\_ctrl\_reg == 32’h00000200;  
req.divider\_reg == 32’h00000000;  
req.slave\_select\_reg == 32’h00000001;  
req.start\_dut\_reg == 32’h00000320;  
});  
endfunction : configure\_dut\_register  
virtual function void set\_dut\_data();  
assert (req.randomize() with {  
req.divider\_reg == 32’h00000000;  
req.master\_ctrl\_reg == 32’h00002208;  
req.slave\_ctrl\_reg == 32’h00000200;  
req.slave\_select\_reg == 32’h00000001;  
req.start\_dut\_reg == 32’h00000320;  
// req.in\_master\_data == 32’h87654321;  
// req.in\_slave\_data == 32’h11223344;  
req.exp\_master\_data == req.in\_slave\_data;  
req.exp\_slave\_data == req.in\_master\_data;  
});  
endfunction : set\_dut\_data  
endclass : spi\_sequence

---

<div class="post-metadata">

**Author:** ![Sree\_N](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@Sree\_N](https://verificationacademy.com/forums/u/Sree_N)\
**Post date:** [February 14, 2019, 1:31pm UTC](https://verificationacademy.com/forums/t/how-to-resolve-this-error/35745/10 "2019-02-14T13:31:06Z")

</div>

class spi\_sequence\_item extends uvm\_sequence\_item;  
/\* Register configuration \*/  
rand logic [31:0]master\_ctrl\_reg;  
rand logic [31:0]slave\_ctrl\_reg;  
rand logic [31:0]divider\_reg;  
rand logic [31:0]slave\_select\_reg;  
rand logic [31:0]start\_dut\_reg;  
/\*DUT output _/  
logic [31:0]out\_master\_data;  
logic [31:0]out\_slave\_data;  
/_ Expected data \*/  
rand logic [31:0]exp\_master\_data;  
rand logic [31:0]exp\_slave\_data;  
/\*DUT input \*/  
rand logic [31:0]in\_master\_data;  
rand logic [31:0]in\_slave\_data;  
logic [31:0] q;  
`uvm_object_utils_begin(spi_sequence_item) `uvm\_field\_int(master\_ctrl\_reg,UVM\_ALL\_ON)  
`uvm_field_int(slave_ctrl_reg,UVM_ALL_ON) `uvm\_field\_int(divider\_reg,UVM\_ALL\_ON)  
`uvm_field_int(slave_select_reg,UVM_ALL_ON) `uvm\_field\_int(start\_dut\_reg,UVM\_ALL\_ON)  
`uvm_field_int(out_master_data,UVM_ALL_ON) `uvm\_field\_int(out\_slave\_data,UVM\_ALL\_ON)  
`uvm_field_int(exp_master_data,UVM_ALL_ON) `uvm\_field\_int(exp\_slave\_data,UVM\_ALL\_ON)  
`uvm_field_int(in_master_data,UVM_ALL_ON) `uvm\_field\_int(in\_slave\_data,UVM\_ALL\_ON)  
`uvm_field_int(q,UVM_ALL_ON) `uvm\_object\_utils\_end  
//Constructor  
function new(string name=“spi\_sequence\_item”);  
super.new(name);  
endfunction : new  
endclass : spi\_sequence\_item

---

<div class="post-metadata">

**Author:** ![Sree\_N](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@Sree\_N](https://verificationacademy.com/forums/u/Sree_N)\
**Post date:** [February 14, 2019, 1:31pm UTC](https://verificationacademy.com/forums/t/how-to-resolve-this-error/35745/11 "2019-02-14T13:31:53Z")

</div>

class spi\_scoreboard extends uvm\_scoreboard;  
`uvm_component_utils(spi_scoreboard) `uvm\_analysis\_imp\_decl(\_exp\_pkt)  
`uvm_analysis_imp_decl(_act_pkt) uvm_analysis_imp_exp_pkt#(spi_sequence_item , spi_scoreboard)drv2sb; uvm_analysis_imp_act_pkt#(spi_sequence_item , spi_scoreboard)mon2sb; spi_sequence_item drv_pkt[$]; spi_sequence_item mon_pkt[$]; spi_sequence_item ip_pkt; spi_sequence_item op_pkt; static string report_tag; spi_coverage spi_covg; int pass = 0; int fail = 0; //Constructor function new(string name=" spi_scoreboard " , uvm_component parent); super.new(name , parent); report_tag=$sformatf ("%0s" ,name); drv2sb=new("drv2sb" , this); mon2sb=new("mon2sb" , this); endfunction : new //Build Phase function void build_phase(uvm_phase phase); super.build_phase(phase); `uvm\_info(get\_full\_name() ,"Build phase called in spi\_scoreboard " ,UVM\_LOW)  
spi\_covg=spi\_coverage::type\_id::create("spi\_covg " , this);  
endfunction : build\_phase  
//Connect Phase  
function void connect\_phase(uvm\_phase phase);  
super.connect\_phase(phase);  
`uvm\_info(get\_full\_name(),"Connect phase called in spi\_scoreboard " ,UVM\_LOW)  
endfunction : connect\_phase

function void write\_exp\_pkt(spi\_sequence\_item tmp\_pkt );  
spi\_sequence\_item pkt;  
$cast(pkt , tmp\_pkt . clone () );  
// ‘uvm\_info ( report\_tag , $sformatf (" Received packet from driver %0s " , pkt . sprint () ) ,UVM\_LOW)  
drv\_pkt.push\_back(pkt);  
uvm\_test\_done.raise\_objection(this);  
endfunction : write\_exp\_pkt

function void write\_act\_pkt(spi\_sequence\_item tmp\_pkt);  
spi\_sequence\_item pkt;  
$cast(pkt,tmp\_pkt.clone());  
// `uvm_info(report_tag , $sformatf("Received packet from DUT %0s " , pkt.sprint()),UVM_LOW) mon_pkt.push_back(pkt); endfunction : write_act_pkt //Run Phase task run_phase(uvm_phase phase); // fork forever begin wait(mon_pkt.size()!=0); op_pkt=mon_pkt.pop_front(); ip_pkt=drv_pkt.pop_front(); //if(drv_pkt.size()==0) //`uvm\_error("Expected packet was not received in scoreboard " ,UVM\_LOW)  
perform\_check(ip\_pkt , op\_pkt);  
perform\_coverage(ip\_pkt);  
uvm\_test\_done.drop\_objection(this);  
end  
// join\_none  
// disable fork;  
endtask : run\_phase

function void perform\_coverage(spi\_sequence\_item pkt);  
spi\_covg.perform\_coverage(pkt);  
endfunction : perform\_coverage

function void perform\_check(spi\_sequence\_item ip\_pkt , spi\_sequence\_item op\_pkt);  
if(ip\_pkt . exp\_master\_data==op\_pkt . out\_master\_data && ip\_pkt . exp\_slave\_data==op\_pkt . out\_slave\_data)  
begin  
//`uvm_info ( get_full_name () ," Master PASSED" ,UVM_MEDIUM) //`uvm\_info ( get\_full\_name () ," Slave PASSED" ,UVM\_MEDIUM)  
pass++;  
end  
else  
begin  
`uvm_info(get_full_name() , $sformatf ("Slave FAILED: exp data=%0h and out data=%0h" , ip_pkt . exp_slave_data , op_pkt . out_slave_data ) ,UVM_MEDIUM) `uvm\_info(get\_full\_name() , $sformatf (“Master FAILED: exp data=%0h and out master data=%0h” , ip\_pkt . exp\_master\_data , op\_pkt . out\_master\_data ) ,UVM\_MEDIUM)  
fail ++;  
end  
endfunction : perform\_check  
function void extract\_phase (uvm\_phase phase ) ;  
endfunction : extract\_phase  
function void report\_phase (uvm\_phase phase ) ;  
if(fail ==0)  
begin  
$display(“----------------------------------32bit–MSB First–TX: posedge–RX: negedge--------------------------------”);  
$display(“------------------------------------------------TEST PASSED-----------------------------------------------”);  
$display(“\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* “);  
uvm\_report\_info (“Scoreboard Report” , $sformatf(” Trasactions PASS = %0d FAIL = %0d” ,pass , fail ) ,UVM\_MEDIUM);  
$display(“\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* “);  
$display(” ---------------------------------------------------------------------------------------------------------- “);  
$display(” ---------------------------------------------------------------------------------------------------------- “);  
end  
else  
begin  
$display(”----------------------------------32bit–MSB First–TX: posedge–RX: negedge--------------------------------”);  
$display(“------------------------------------------------TEST FAILED-----------------------------------------------”);  
$display(“\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* “);  
uvm\_report\_info (“Scoreboard Report” , $sformatf (” Trasactions PASS = %0d FAIL = %0d” ,pass , fail ) ,UVM\_MEDIUM);  
$display(“\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*”);  
$display(" ---------------------------------------------------------------------------------------------------------- “);  
$display(” ---------------------------------------------------------------------------------------------------------- ");  
end  
endfunction : report\_phase  
endclass : spi\_scoreboard

---

<div class="post-metadata">

**Author:** ![Sree\_N](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@Sree\_N](https://verificationacademy.com/forums/u/Sree_N)\
**Post date:** [February 14, 2019, 1:32pm UTC](https://verificationacademy.com/forums/t/how-to-resolve-this-error/35745/12 "2019-02-14T13:32:25Z")

</div>

class spi\_coverage extends uvm\_component;  
`uvm\_component\_utils(spi\_coverage)  
spi\_sequence\_item c\_pkt;  
//Coverage Details  
covergroup spi\_trans\_cg;  
cp\_dut\_mosi : coverpoint c\_pkt.exp\_master\_data  
{  
bins byte7 = {[0:255]};  
bins byte15= {[256:65535]};  
bins byte23= {[65536:16777215]};  
bins byte31= {[16777216:$]};  
}  
endgroup : spi\_trans\_cg  
//Constructor  
function new(string name=“spi\_covg” , uvm\_component parent= null);  
super.new(name , parent);  
spi\_trans\_cg = new();  
endfunction : new  
//Perform Coverage  
function void perform\_coverage(spi\_sequence\_item pkt);  
this.c\_pkt=pkt;  
spi\_trans\_cg.sample();  
endfunction : perform\_coverage  
endclass : spi\_coverage

---

<div class="post-metadata">

**Author:** ![Sree\_N](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@Sree\_N](https://verificationacademy.com/forums/u/Sree_N)\
**Post date:** [February 14, 2019, 1:32pm UTC](https://verificationacademy.com/forums/t/how-to-resolve-this-error/35745/13 "2019-02-14T13:32:58Z")

</div>

class spi\_agent extends uvm\_agent;  
'uvm\_component\_utils(spi\_agent)  
spi\_sequencer sequencer;  
spi\_monitor monitor;  
spi\_driver driver;  
spi\_vif m\_vif , s\_vif;  
//Constructor   
function new(string name=“spi\_agent”,uvm\_component parent);  
super.new(name , parent );  
endfunction : new  
//Build Phase  
function void build\_phase (uvm\_phase phase);  
super.build\_phase(phase);  
`uvm_info(get_full_name(),"Build phase called in spi_agent ",UVM_LOW) if(!uvm_config_db#(virtual spi_if)::get(this , "" , "m_if " , m_vif)) `uvm\_fatal(“NO\_VIF” ,{“virtual interface must be set for : " , get\_full\_name() ,”.m\_vif"})  
if(!uvm\_config\_db#(virtual spi\_if)::get(this , “” , “s\_if” , s\_vif))  
`uvm_fatal("NO_VIF" ,{"virtual interface must be set for :" , get_full_name() ,".s_vif"}) sequencer=spi_sequencer::type_id::create("sequencer" , this); driver =spi_driver::type_id::create(" driver " , this); driver.m_vif=m_vif; driver.s_vif=s_vif; monitor=spi_monitor::type_id::create("monitor" , this); monitor.m_vif=m_vif; monitor.s_vif=s_vif; endfunction : build_phase //Coonect Phase function void connect_phase(uvm_phase phase); super.connect_phase(phase); `uvm\_info(get\_full\_name(),"Connect phase called in spi\_agent " ,UVM\_LOW)  
driver.seq\_item\_port.connect(sequencer.seq\_item\_export);  
endfunction : connect\_phase  
endclass : spi\_agent

---

<div class="post-metadata">

**Author:** ![Sree\_N](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@Sree\_N](https://verificationacademy.com/forums/u/Sree_N)\
**Post date:** [February 14, 2019, 1:34pm UTC](https://verificationacademy.com/forums/t/how-to-resolve-this-error/35745/14 "2019-02-14T13:34:16Z")

</div>

`include "spi_defines.v" `include “timescale.v”  
module spi(  
/_Wishbone signals /  
wb\_clk\_i , wb\_rst\_i , wb\_adr\_i , wb\_dat\_i , wb\_dat\_o , wb\_sel\_i ,  
wb\_we\_i , wb\_stb\_i , wb\_cyc\_i , wb\_ack\_o , wb\_err\_o , wb\_int\_o ,  
/SPI signals /  
ss\_pad\_o , sclk\_pad\_o , mosi\_pad\_o , miso\_pad\_i ,  
/Scan Insertion /  
scan\_in0 , scan\_en , test\_mode , scan\_out0 , tip);  
/----------------------------Wishbone signals --------------------------------------/  
input wb\_clk\_i; // master clock input  
input wb\_rst\_i; // synchronous active high reset  
input [4:0] wb\_adr\_i; // lower address bits  
input [32-1:0] wb\_dat\_i; // databus input  
output [32-1:0] wb\_dat\_o; // databus output  
input [3:0] wb\_sel\_i; // byte select inputs  
input wb\_we\_i; // write enable input  
input wb\_stb\_i; // stobe / core select signal  
input wb\_cyc\_i; // valid bus cycle input  
output wb\_ack\_o; // bus cycle acknowledge output  
output wb\_err\_o; // termination w/ error  
output wb\_int\_o; // interrupt request signal output  
/---------------------------------SPI signals --------------------------------------/  
output [`SPI_SS_NB-1:0] ss_pad_o; // slave select output sclk_pad_o; // serial clock output mosi_pad_o; // master out slave in input miso_pad_i; // master in slave out //input reset; // system reset //input clk; // system clock input scan_in0; // test scan mode data input input scan_en; // test scan mode enable input test_mode; // test mode select output scan_out0; // test scan mode data output output tip; /*--------------------------------------------------------------------------------*/ reg [32-1:0]wb_dat_o; reg [32-1:0]wb_dat; reg wb_ack_o; reg wb_int_o; reg [`SPI\_CTRL\_BIT\_NB-1:0]ctrl;  
reg [`SPI_DIVIDER_LEN-1:0]divider; reg [`SPI\_SS\_NB-1:0]ss;  
reg scan\_out0;  
// Internal signals  
wire [`SPI_MAX_CHAR-1:0]rx; // Rx register wire rx_negedge; // miso is sampled on negative edge wire tx_negedge; // mosi is driven on negative edge wire [`SPI\_CHAR\_LEN\_BITS-1:0]char\_len; // char len  
wire go; // go  
wire lsb; // lsb first on line  
wire ie; // interrupt enable  
wire ass; // automatic slave select  
wire spi\_divider\_sel; // divider register select  
wire spi\_ctrl\_sel; // ctrl register select  
wire [3:0] spi\_tx\_sel; // tx\_l register select  
wire spi\_ss\_sel; // ss register select  
reg tip; // transfer in progress  
wire pos\_edge; // recognize posedge of sclk  
wire neg\_edge; // recognize negedge of sclk  
wire last\_bit; // marks last character bit  
//-----------------------------------------------------------------------------------  
spi\_clock\_gen clock\_gen(.clk\_in(wb\_clk\_i) , .rst(wb\_rst\_i) , .go(go) , .enable(tip) , .last\_clk(last\_bit) , .divider(divider) , .clk\_out(sclk\_pad\_o) , .pos\_edge(pos\_edge) , .neg\_edge(neg\_edge));  
// . scan\_in0 ( scan\_in0 ) , . scan\_en ( scan\_en ) , . test\_mode ( test\_mode ) , . scan\_out0 ( scan\_out0 ) , . reset ( reset ) , . clk ( clk ) ) ;  
//-----------------------------------------------------------------------------------  
spi\_shift shift(.clk\_shift(wb\_clk\_i) , .rst(wb\_rst\_i) , .len(char\_len[`SPI_CHAR_LEN_BITS-1:0]) , .latch(spi_tx_sel [3:0] & {4{wb_we_i}}) , .byte_sel(wb_sel_i) , .lsb(lsb) , .go(go) , .pos_edge(pos_edge) , .neg_edge(neg_edge) , .rx_negedge(rx_negedge) , .tx_negedge(tx_negedge) , .tip(tip) , .last(last_bit) ,.p_in( wb_dat_i ) , .p_out(rx) ,.s_clk(sclk_pad_o) , .s_in(miso_pad_i) , .s_out(mosi_pad_o)); //. scan_in0 ( scan_in0 ) , . scan_en ( scan_en ) , . test_mode ( test_mode ) , . scan_out0 ( scan_out0 ) , . reset ( reset ) , . clk ( clk ) ) ; /*----------------------------------Address decoder -----------------------------------*/ assign spi_divider_sel = wb_cyc_i & wb_stb_i & ( wb_adr_i [`SPI\_OFS\_BITS] == `SPI_DIVIDE) ; assign spi_ctrl_sel = wb_cyc_i & wb_stb_i & ( wb_adr_i [`SPI\_OFS\_BITS] == `SPI_CTRL) ; assign spi_tx_sel [0] = wb_cyc_i & wb_stb_i & ( wb_adr_i [`SPI\_OFS\_BITS] == `SPI_TX_0) ; assign spi_tx_sel [1] = wb_cyc_i & wb_stb_i & ( wb_adr_i [`SPI\_OFS\_BITS] == `SPI_TX_1) ; assign spi_tx_sel [2] = wb_cyc_i & wb_stb_i & ( wb_adr_i [`SPI\_OFS\_BITS] == `SPI_TX_2) ; assign spi_tx_sel [3] = wb_cyc_i & wb_stb_i & ( wb_adr_i [`SPI\_OFS\_BITS] == `SPI_TX_3) ; assign spi_ss_sel = wb_cyc_i & wb_stb_i & ( wb_adr_i [`SPI\_OFS\_BITS] == `SPI_SS) ; /*-----------------------------Read from registers -------------------------------------*/ always @( wb_adr_i or rx or ctrl or divider or ss ) begin case ( wb_adr_i [`SPI\_OFS\_BITS])  
 `ifdef SPI_MAX_CHAR_128 `SPI\_RX\_0: wb\_dat = rx [31:0];  
 `SPI_RX_1: wb_dat = rx [63:32]; `SPI\_RX\_2: wb\_dat = rx [95:64];  
 `SPI_RX_3: wb_dat = {{128-`SPI\_MAX\_CHAR{1’b0}}, rx [`SPI\_MAX\_CHAR-1:96]};  
`else  
`ifdef SPI\_MAX\_CHAR\_64  
`SPI\_RX\_0: wb\_dat = rx [31:0];  
`SPI_RX_1: wb_dat = {{64-`SPI\_MAX\_CHAR{1’b0}}, rx [`SPI\_MAX\_CHAR-1:32]};  
`SPI\_RX\_2: wb\_dat = 32’b0;  
`SPI\_RX\_3: wb\_dat = 32’b0;  
`else  
`SPI_RX_0: wb_dat = {{32-`SPI\_MAX\_CHAR{1’b0}}, rx [`SPI\_MAX\_CHAR-1:0]};  
`SPI\_RX\_1: wb\_dat = 32’b0;  
`SPI\_RX\_2: wb\_dat = 32’b0;  
`SPI\_RX\_3: wb\_dat = 32’b0;  
`endif  
`endif  
`SPI_CTRL: wb_dat = {{32-`SPI\_CTRL\_BIT\_NB{1’b0}}, ctrl };  
`SPI_DIVIDE: wb_dat = {{32-`SPI\_DIVIDER\_LEN{1’b0}}, divider};  
`SPI_SS: wb_dat = {{32-`SPI\_SS\_NB{1’b0}}, ss };  
default : wb\_dat = 32’bx;  
endcase  
end  
/---------------------------------Wb data out ----------------------------------------_/  
always@(posedge wb\_clk\_i or posedge wb\_rst\_i)  
begin  
if(wb\_rst\_i)  
wb\_dat\_o \<= 32’b0;  
else  
wb\_dat\_o \<= wb\_dat;  
end  
/_------------------------------Wb acknowledge ----------------------------------------_/  
always@(posedge wb\_clk\_i or posedge wb\_rst\_i)  
begin  
if(wb\_rst\_i)  
wb\_ack\_o \<= 1’b0;  
else  
wb\_ack\_o \<= wb\_cyc\_i & wb\_stb\_i & ~wb\_ack\_o;  
end  
/_---------------------------------Wb error ------------------------------------------_/  
assign wb\_err\_o = 1’b0;  
/_---------------------------------Interrupt -----------------------------------------_/  
always@(posedge wb\_clk\_i or posedge wb\_rst\_i)  
begin  
if(wb\_rst\_i)  
wb\_int\_o \<= 1’b0;  
else if ( ie && tip && last\_bit && pos\_edge )  
wb\_int\_o \<= 1’b1;  
else if (wb\_ack\_o)  
wb\_int\_o \<= 1’b0;  
end  
/_-------------------------------Divider register -------------------------------------_/  
always@(posedge wb\_clk\_i or posedge wb\_rst\_i)  
begin  
if(wb\_rst\_i)  
divider \<= {`SPI\_DIVIDER\_LEN{1’b0}};  
else if(spi\_divider\_sel && wb\_we\_i && ! tip )  
begin  
`ifdef SPI\_DIVIDER\_LEN\_8  
if(wb\_sel\_i [0])  
divider \<= wb\_dat\_i [`SPI\_DIVIDER\_LEN-1:0];  
`endif  
`ifdef SPI\_DIVIDER\_LEN\_16  
if(wb\_sel\_i [0])  
divider [7:0] \<= wb\_dat\_i [7:0];  
if(wb\_sel\_i [1])  
divider[`SPI_DIVIDER_LEN-1:8] \<= wb_dat_i [`SPI\_DIVIDER\_LEN-1:8];  
`endif  
`ifdef SPI\_DIVIDER\_LEN\_24  
if(wb\_sel\_i [0])  
divider [7:0] \<= wb\_dat\_i [7:0];  
if(wb\_sel\_i [1])  
divider [15:8] \<= wb\_dat\_i [15:8];  
if(wb\_sel\_i [2])  
divider [`SPI_DIVIDER_LEN-1:16] \<= wb_dat_i [`SPI\_DIVIDER\_LEN-1:16];  
`endif  
`ifdef SPI\_DIVIDER\_LEN\_32  
if(wb\_sel\_i [0])  
divider [7:0] \<= wb\_dat\_i [7:0];  
if(wb\_sel\_i [1])  
divider [15:8] \<= wb\_dat\_i [15:8];  
if(wb\_sel\_i [2])  
divider [23:16] \<= wb\_dat\_i [23:16];  
if(wb\_sel\_i [3])  
divider [`SPI_DIVIDER_LEN-1:24] \<= wb_dat_i [`SPI\_DIVIDER\_LEN-1:24];  
`endif  
end  
end  
/_-------------------------------Ctrl register -------------------------------------_/  
always@(posedge wb\_clk\_i or posedge wb\_rst\_i)  
begin  
if(wb\_rst\_i)  
ctrl \<= {`SPI\_CTRL\_BIT\_NB{1’b0}};  
else if(spi\_ctrl\_sel && wb\_we\_i && ! tip)  
begin  
if(wb\_sel\_i [0])  
ctrl [7:0] \<= wb\_dat\_i [7:0] | {7’b0 , ctrl [0]};  
if( wb\_sel\_i [1])  
ctrl [`SPI_CTRL_BIT_NB-1:8] \<= wb_dat_i [`SPI\_CTRL\_BIT\_NB-1:8];  
end  
else if( tip && last\_bit && pos\_edge )  
ctrl [`SPI\_CTRL\_GO] \<= 1’b0;  
end  
/_-------------------------------Ctrl register decode ------------------------------_/  
assign rx\_negedge = ctrl[`SPI\_CTRL\_RX\_NEGEDGE];  
assign tx\_negedge = ctrl[`SPI\_CTRL\_TX\_NEGEDGE];  
assign go = ctrl[`SPI\_CTRL\_GO];  
assign char\_len = ctrl [`SPI\_CTRL\_CHAR\_LEN];  
assign lsb = ctrl [`SPI\_CTRL\_LSB];  
assign ie = ctrl [`SPI\_CTRL\_IE];  
assign ass = ctrl [`SPI\_CTRL\_ASS];  
/_------------------------------Slave select register ------------------------------_/  
always@(posedge wb\_clk\_i or posedge wb\_rst\_i)  
begin  
if(wb\_rst\_i)  
ss \<= {`SPI\_SS\_NB{1’b0}};  
else if( spi\_ss\_sel && wb\_we\_i && ! tip )  
begin  
`ifdef SPI\_SS\_NB\_8  
if(wb\_sel\_i [0])  
ss \<= wb\_dat\_i [`SPI\_SS\_NB-1:0];  
`endif  
`ifdef SPI\_SS\_NB\_16  
if(wb\_sel\_i [0])  
ss [7:0] \<= wb\_dat\_i [7:0];  
if(wb\_sel\_i [1])  
ss[`SPI_SS_NB-1:8] \<= wb_dat_i [`SPI\_SS\_NB -1:8];  
`endif  
`ifdef SPI\_SS\_NB\_24  
if(wb\_sel\_i [0])  
ss [7:0] \<= wb\_dat\_i [7:0];  
if(wb\_sel\_i [1])  
ss [15:8] \<= wb\_dat\_i [15:8];  
if(wb\_sel\_i [2])  
ss[`SPI_SS_NB-1:16] \<= wb_dat_i [`SPI\_SS\_NB -1:16];  
`endif  
`ifdef SPI\_SS\_NB\_32  
if ( wb\_sel\_i [0])  
ss [7:0] \<= wb\_dat\_i [7:0];  
if ( wb\_sel\_i [1])  
ss [15:8] \<= wb\_dat\_i [15:8];  
if ( wb\_sel\_i [2])  
ss [23:16] \<= wb\_dat\_i [23:16];  
if ( wb\_sel\_i [3])  
ss [`SPI_SS_NB-1:24] \<= wb_dat_i [`SPI\_SS\_NB -1:24];  
`endif  
end  
end  
assign ss\_pad\_o = ~(( ss & {`SPI_SS_NB{ tip & ass }}) | ( ss & {`SPI\_SS\_NB{! ass }}) ) ;  
endmodule

---

<div class="post-metadata">

**Author:** ![Sree\_N](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@Sree\_N](https://verificationacademy.com/forums/u/Sree_N)\
**Post date:** [February 14, 2019, 1:35pm UTC](https://verificationacademy.com/forums/t/how-to-resolve-this-error/35745/15 "2019-02-14T13:35:14Z")

</div>

`include "spi_defines.v" `include “timescale.v”  
module spi\_clock\_gen(clk\_in , rst , go , enable , last\_clk , divider , clk\_out , pos\_edge , neg\_edge);  
//scan\_in0 , scan\_en , test\_mode , scan\_out0 , reset , clk ) ;  
input clk\_in; // input clock ( system clock )  
input rst; // reset  
input enable; // clock enable  
input go; // start transfer  
input last\_clk; // last clock  
input [`SPI_DIVIDER_LEN-1:0]divider; // clock divider ( output clock is divided by this value ) output clk_out; // output clock output pos_edge; // pulse marking positive edge of clk_out output neg_edge; // pulse marking negative edge of clk_out reg clk_out; reg pos_edge; reg neg_edge; reg [`SPI\_DIVIDER\_LEN-1:0] cnt; // clock counter  
wire cnt\_zero; // conter is equal to zero  
wire cnt\_one; // conter is equal to one  
// -----------------------------------------------------------------------------------  
assign cnt\_zero = cnt == {`SPI_DIVIDER_LEN{1'b0}}; assign cnt_one = cnt == {{`SPI\_DIVIDER\_LEN-1{1’b0}}, 1’b1};  
/_--------------------------Counter counts half period ------------------------------_/  
always@(posedge clk\_in or posedge rst)  
begin  
if(rst)  
cnt \<= {`SPI_DIVIDER_LEN{1'b1}}; else begin if (!enable || cnt_zero) cnt <= divider; else cnt <= cnt - {{`SPI\_DIVIDER\_LEN-1{1’b0}},1’b1};  
end  
end  
/_----------------clk\_out is asserted every other half period ------------------------_/  
always@(posedge clk\_in or posedge rst)  
begin  
if(rst)  
clk\_out \<= 1’b0;  
else  
clk\_out \<= (enable && cnt\_zero && (! last\_clk || clk\_out ) ) ? ~clk\_out : clk\_out;  
end  
/_------------------------ Pos and neg edge signals ---------------------------------_/  
always@(posedge clk\_in or posedge rst)  
begin  
if(rst)  
begin  
pos\_edge \<= 1’b0;  
neg\_edge \<= 1’b0;  
end  
else  
begin  
pos\_edge \<= ( enable && ! clk\_out && cnt\_one ) || (!(| divider ) && clk\_out ) || ( !(| divider ) && go && ! enable);  
neg\_edge \<= ( enable && clk\_out && cnt\_one ) || (!(| divider ) && ! clk\_out && enable );  
end  
end  
// -----------------------------------------------------------------------------------  
endmodule

---

<div class="post-metadata">

**Author:** ![Sree\_N](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@Sree\_N](https://verificationacademy.com/forums/u/Sree_N)\
**Post date:** [February 14, 2019, 1:35pm UTC](https://verificationacademy.com/forums/t/how-to-resolve-this-error/35745/16 "2019-02-14T13:35:40Z")

</div>

// ‘define SPI\_DIVIDER\_LEN\_8 14  
`define SPI_DIVIDER_LEN_16 // ‘define SPI_DIVIDER_LEN_24 // ‘define SPI_DIVIDER_LEN_32 `ifdef SPI\_DIVIDER\_LEN\_8  
`define SPI_DIVIDER_LEN 8 // Can be set from 1 to 8 `endif  
`ifdef SPI_DIVIDER_LEN_16 `define SPI\_DIVIDER\_LEN 16 // Can be set from 9 to 16  
`endif `ifdef SPI\_DIVIDER\_LEN\_24  
`define SPI_DIVIDER_LEN 24 // Can be set from 17 to 24 `endif  
`ifdef SPI_DIVIDER_LEN_32 28 `define SPI\_DIVIDER\_LEN 32 // Can be set from 25 to 32  
`endif // ----------------------------------------------------------------------------------- /* 32 Maximum nuber of bits that can be send / received at once . Use SPI_MAX_CHAR for fine tuning the exact number , when using 34 SPI_MAX_CHAR_32, SPI_MAX_CHAR_24, SPI_MAX_CHAR_16, SPI_MAX_CHAR_8. 35 */ `define SPI\_MAX\_CHAR\_128  
//`define SPI_MAX_CHAR_64 //`define SPI\_MAX\_CHAR\_32  
//`define SPI_MAX_CHAR_24 //`define SPI\_MAX\_CHAR\_16  
//`define SPI_MAX_CHAR_8 43 `ifdef SPI\_MAX\_CHAR\_128  
`define SPI_MAX_CHAR 128 // Can only be set to 128 `define SPI\_CHAR\_LEN\_BITS 7  
`endif `ifdef SPI\_MAX\_CHAR\_64  
`define SPI_MAX_CHAR 64 // Can only be set to 64 `define SPI\_CHAR\_LEN\_BITS 6  
`endif `ifdef SPI\_MAX\_CHAR\_32  
`define SPI_MAX_CHAR 32 // Can be set from 25 to 32 `define SPI\_CHAR\_LEN\_BITS 5  
`endif `ifdef SPI\_MAX\_CHAR\_24  
`define SPI_MAX_CHAR 24 // Can be set from 17 to 24 `define SPI\_CHAR\_LEN\_BITS 5  
`endif `ifdef SPI\_MAX\_CHAR\_16  
`define SPI_MAX_CHAR 16 // Can be set from 9 to 16 `define SPI\_CHAR\_LEN\_BITS 4  
`endif `ifdef SPI\_MAX\_CHAR\_8  
`define SPI_MAX_CHAR 8 // Can be set from 1 to 8 `define SPI\_CHAR\_LEN\_BITS 3  
`endif // ----------------------------------------------------------------------------------- /* 70 Number of device select signals . Use SPI_SS_NB for fine tuning the 71 exact number . 72 */ `define SPI\_SS\_NB\_8  
//`define SPI_SS_NB_16 //`define SPI\_SS\_NB\_24  
//`define SPI_SS_NB_32 `ifdef SPI\_SS\_NB\_8  
`define SPI_SS_NB 8 // Can be set from 1 to 8 `endif  
`ifdef SPI_SS_NB_16 `define SPI\_SS\_NB 16 // Can be set from 9 to 16  
`endif `ifdef SPI\_SS\_NB\_24  
`define SPI_SS_NB 24 // Can be set from 17 to 24 `endif  
`ifdef SPI_SS_NB_32 `define SPI\_SS\_NB 32 // Can be set from 25 to 32  
`endif // ----------------------------------------------------------------------------------- /* Bits of WISHBONE address used for partial decoding of SPI registers. */ `define SPI\_OFS\_BITS 4:2  
// -----------------------------------------------------------------------------------  
/\* Register offset _/  
 `define SPI_RX_0 0 `define SPI\_RX\_1 1  
 `define SPI_RX_2 2 `define SPI\_RX\_3 3  
 `define SPI_TX_0 0 `define SPI\_TX\_1 1  
 `define SPI_TX_2 2 `define SPI\_TX\_3 3  
 `define SPI_CTRL 4 `define SPI\_DIVIDE 5  
 `define SPI_SS 6 // ----------------------------------------------------------------------------------- /* Number of bits in ctrl register */ `define SPI\_CTRL\_BIT\_NB 14  
// -----------------------------------------------------------------------------------  
/_ Control register bit position \*/  
`define SPI_CTRL_ASS 13 `define SPI\_CTRL\_IE 12  
`define SPI_CTRL_LSB 11 `define SPI\_CTRL\_TX\_NEGEDGE 10  
`define SPI_CTRL_RX_NEGEDGE 9 `define SPI\_CTRL\_GO 8  
`define SPI_CTRL_RES_1 7 `define SPI\_CTRL\_CHAR\_LEN 6:0

---

<div class="post-metadata">

**Author:** ![Sree\_N](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@Sree\_N](https://verificationacademy.com/forums/u/Sree_N)\
**Post date:** [February 14, 2019, 1:36pm UTC](https://verificationacademy.com/forums/t/how-to-resolve-this-error/35745/17 "2019-02-14T13:36:16Z")

</div>

interface spi\_if(input bit clk);  
// Wishbone signals  
logic [4:0]adr; // lower address bits  
logic [32-1:0]din; // databus input  
logic [32-1:0]dout; // databus output  
logic [3:0]sel; // byte select inputs  
logic we; // write enable input  
logic stb; // stobe / core select signal  
logic cyc; // valid bus cycle input  
logic ack; // bus cycle acknowledge output  
logic err; // termination w/ error  
logic intp; // interrupt request signal output input  
logic pit;  
//-------------------------------------------------------------  
clocking drive\_cb@(posedge clk);  
input din , ack , err , intp , pit;  
output adr , dout , sel , we, stb , cyc;  
endclocking : drive\_cb  
//-------------------------------------------------------------  
clocking monitor\_cb@(posedge clk);  
input din , ack , err , intp , pit;  
output adr , dout , sel , we, stb , cyc;  
endclocking : monitor\_cb  
//-------------------------------------------------------------  
endinterface : spi\_if

---

<div class="post-metadata">

**Author:** ![Sree\_N](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@Sree\_N](https://verificationacademy.com/forums/u/Sree_N)\
**Post date:** [February 14, 2019, 1:37pm UTC](https://verificationacademy.com/forums/t/how-to-resolve-this-error/35745/18 "2019-02-14T13:37:03Z")

</div>

package spi\_pkg;  
//-------------------------------------------------------------  
import uvm\_pkg::_;  
//import my\_package::_;  
//`include "uvm_macros.svh" `include “spi\_tb\_defines.sv”  
`include "spi_sequence_item.sv" `include “wb\_bfm.sv”  
`include "spi_driver.sv" `include “spi\_monitor.sv”  
`include "spi_sequencer.sv" `include “spi\_agent.sv”  
`include "spi_coverage.sv" `include “spi\_scoreboard.sv”  
`include "spi_sequence.sv" `include “spi\_env.sv”  
`include "spi_test.sv" //`include “spi\_slave\_model”  
endpackage : spi\_pkg

---

<div class="post-metadata">

**Author:** ![Sree\_N](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@Sree\_N](https://verificationacademy.com/forums/u/Sree_N)\
**Post date:** [February 14, 2019, 1:37pm UTC](https://verificationacademy.com/forums/t/how-to-resolve-this-error/35745/19 "2019-02-14T13:37:50Z")

</div>

`include "spi_defines.v" `include “timescale.v”  
module spi\_shift(clk\_shift , rst , latch , byte\_sel , len , lsb , go , pos\_edge , neg\_edge , rx\_negedge , tx\_negedge , tip , last , p\_in , p\_out , s\_clk , s\_in , s\_out);  
// scan\_in0 , scan\_en , test\_mode , scan\_out0 , reset , clk ) ;  
input clk\_shift ; // system clock  
input rst; // reset  
input [3:0]latch; // latch signal for storing the data in shift register  
input [3:0]byte\_sel; // byte select signals for storing the data in shift register  
input [`SPI_CHAR_LEN_BITS-1:0]len; // data len in bits (minus one) input lsb; // lbs first on the line input go; // start stansfer input pos_edge; // recognize posedge of sclk input neg_edge; // recognize negedge of sclk input rx_negedge; // s_in is sampled on negative edge input tx_negedge; // s_out is driven on negative edge output tip; // transfer in progress output last; // last bit input [31:0] p_in; // parallel in output [`SPI\_MAX\_CHAR-1:0]p\_out; // parallel out  
input s\_clk; // serial clock  
input s\_in; // serial in  
output s\_out; // serial out  
reg s\_out;  
reg tip;  
reg [`SPI_CHAR_LEN_BITS:0]cnt; // data bit count reg [`SPI\_MAX\_CHAR-1:0]data; // shift register  
wire [`SPI_CHAR_LEN_BITS:0]tx_bit_pos; // next bit position wire [`SPI\_CHAR\_LEN\_BITS:0]rx\_bit\_pos; // next bit position  
wire rx\_clk; // rx clock enable  
wire tx\_clk; // tx clock enable  
// -----------------------------------------------------------------------------------  
assign p\_out =data;  
assign tx\_bit\_pos = lsb ? {!(| len ) , len} - cnt : cnt - {{ `SPI_CHAR_LEN_BITS{1'b0}},1'b1}; assign rx_bit_pos = lsb ? {!(| len ) , len} - ( rx_negedge ? cnt + {{`SPI\_CHAR\_LEN\_BITS{1’b0}},1’b1} : cnt ) : ( rx\_negedge ? cnt : cnt - {{ `SPI_CHAR_LEN_BITS{1'b0}},1'b1}); assign last = !(| cnt ); assign rx_clk = ( rx_negedge ? neg_edge : pos_edge ) && (! last || s_clk ); assign tx_clk = ( tx_negedge ? neg_edge : pos_edge ) && ! last; /*--------------------------Character bit counter -----------------------------------*/ always@(posedge clk_shift or posedge rst) begin if(rst) cnt <= {`SPI\_CHAR\_LEN\_BITS+1{1’b0}};  
else  
begin  
if(tip)  
cnt \<= pos\_edge ? ( cnt - {{`SPI_CHAR_LEN_BITS{1'b0 }}, 1'b1}) : cnt; else cnt <= !(| len ) ? {1'b1 , {`SPI\_CHAR\_LEN\_BITS{1’b0}}} : {1’b0 , len };  
end  
end  
/_--------------------------Transfer in progress ------------------------------------_/  
always@(posedge clk\_shift or posedge rst)  
begin  
if(rst)  
tip \<= 1’b0;  
else if (go && ~tip)  
tip \<= 1’b1;  
else if ( tip && last && pos\_edge )  
tip \<= 1’b0;  
end  
/_------------------------Sending bits to the line ----------------------------------_/  
always@(posedge clk\_shift or posedge rst)  
begin  
if(rst)  
s\_out \<= 1’b0;  
else  
s\_out \<= ( tx\_clk || ! tip ) ? data [tx\_bit\_pos [`SPI_CHAR_LEN_BITS-1:0]] : s_out; end /*-------------------Receiving bits from the line -----------------------------------*/ always@(posedge clk_shift or posedge rst) begin if(rst) data <= {`SPI\_MAX\_CHAR{1’b0}};  
`ifdef SPI_MAX_CHAR_128 else if(latch [0] && ! tip) begin if(byte_sel [3]) data [31:24] <= p_in [31:24]; if(byte_sel [2]) data [23:16] <= p_in [23:16]; if(byte_sel [1]) data [15:8] <= p_in [15:8]; if(byte_sel [0]) data [7:0] <= p_in [7:0]; end else if(latch [1] && ! tip) begin if(byte_sel [3]) data [63:56] <= p_in [31:24]; if(byte_sel [2]) data [55:48] <= p_in [23:16]; if(byte_sel [1]) data [47:40] <= p_in [15:8]; if(byte_sel [0]) data [39:32] <= p_in [7:0]; end else if( latch [2] && ! tip ) begin if(byte_sel [3]) data [95:88] <= p_in [31:24]; if(byte_sel [2]) data [87:80] <= p_in [23:16]; if(byte_sel [1]) data [79:72] <= p_in [15:8]; if(byte_sel [0]) data [71:64] <= p_in [7:0]; end else if(latch [3] && ! tip) begin if(byte_sel [3]) data [127:120] <= p_in [31:24]; if(byte_sel [2]) 124 data [119:112] <= p_in [23:16]; if(byte_sel [1]) 126 data [111:104] <= p_in [15:8]; if(byte_sel [0]) 128 data [103:96] <= p_in [7:0]; end `else  
`ifdef SPI_MAX_CHAR_64 else if( latch [0] && ! tip ) begin if(byte_sel[3]) data [31:24] <= p_in [31:24]; if(byte_sel[2]) data [23:16] <= p_in [23:16]; if(byte_sel[1]) data [15:8] <= p_in [15:8]; if(byte_sel[0]) data [7:0] <= p_in [7:0]; end else if ( latch [1] && ! tip ) begin if(byte_sel [3]) data [63:56] <= p_in [31:24]; if(byte_sel [2]) data [55:48] <= p_in [23:16]; if(byte_sel [1]) data [47:40] <= p_in [15:8]; if(byte_sel [0]) data [39:32] <= p_in [7:0]; end `else  
else if( latch [0] && ! tip )  
begin  
`ifdef SPI_MAX_CHAR_8 if(byte_sel [0]) data [`SPI\_MAX\_CHAR-1:0] \<= p\_in [`SPI_MAX_CHAR-1:0]; `endif  
`ifdef SPI_MAX_CHAR_16 if(byte_sel [0]) data [7:0] <= p_in [7:0]; if(byte_sel [1]) data [`SPI\_MAX\_CHAR-1:8] \<= p\_in [`SPI_MAX_CHAR-1:8]; `endif  
`ifdef SPI_MAX_CHAR_24 if(byte_sel [0]) data [7:0] <= p_in [7:0]; if(byte_sel [1]) data [15:8] <= p_in [15:8]; if(byte_sel [2]) data [`SPI\_MAX\_CHAR-1:16] \<= p\_in [`SPI_MAX_CHAR -1:16]; `endif  
`ifdef SPI_MAX_CHAR_32 if(byte_sel [0]) data [7:0] <= p_in [7:0]; if(byte_sel [1]) data [15:8] <= p_in [15:8]; if(byte_sel [2]) data [23:16] <= p_in [23:16]; if(byte_sel [3]) data [`SPI\_MAX\_CHAR-1:24] \<= p\_in [`SPI_MAX_CHAR -1:24]; `endif  
end  
`endif `endif  
else  
data [rx\_bit\_pos [`SPI_CHAR_LEN_BITS-1:0]] <= rx_clk ? s_in : data [rx_bit_pos [`SPI\_CHAR\_LEN\_BITS-1:0]];  
end  
// -----------------------------------------------------------------------------------  
endmodule

---

<div class="post-metadata">

**Author:** ![Sree\_N](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@Sree\_N](https://verificationacademy.com/forums/u/Sree_N)\
**Post date:** [February 14, 2019, 1:38pm UTC](https://verificationacademy.com/forums/t/how-to-resolve-this-error/35745/20 "2019-02-14T13:38:40Z")

</div>

`include "spi_defines.v" `include “timescale.v”

// -----------------------------------------------------------------------------------  
module spi\_slave (  
// Wishbone signals  
wb\_clk\_i , wb\_rst\_i , wb\_adr\_i , wb\_dat\_i , wb\_dat\_o , wb\_sel\_i ,  
wb\_we\_i , wb\_stb\_i , wb\_cyc\_i , wb\_ack\_o , wb\_err\_o , wb\_int\_o ,  
// SPI signals  
ss\_pad\_i , sclk\_pad\_i , mosi\_pad\_i , miso\_pad\_o ,  
// Scan Insertion  
scan\_in0 , scan\_en , test\_mode , scan\_out0);  
//, reset ,clk);  
// Wishbone signals 22 input wb\_clk\_i ;  
// master clock input  
input wb\_clk\_i;  
input wb\_rst\_i; // synchronous active high reset  
input [4:0] wb\_adr\_i; // lower address bits  
input [32-1:0] wb\_dat\_i; // databus input  
output [32-1:0] wb\_dat\_o; // databus output  
input [3:0] wb\_sel\_i; // byte select inputs  
input wb\_we\_i; // write enable input  
input wb\_stb\_i; // stobe / core select signal  
input wb\_cyc\_i; // valid bus cycle input  
output wb\_ack\_o; // bus cycle acknowledge output  
output wb\_err\_o; // termination w/ error  
output wb\_int\_o; // interrupt request signal output  
// SPI signals  
input [`SPI_SS_NB-1:0] ss_pad_i; // slave select input sclk_pad_i; // serial clock input mosi_pad_i; // master out slave in output miso_pad_o; // master in slave out input scan_in0; // test scan mode data input input scan_en; // test scan mode enable input test_mode; // test mode select output scan_out0; // test scan mode data output wire rx_negedge; // slave receiving on negedge wire tx_negedge; // slave transmiting on negedge wire spi_tx_sel; // tx_l register select reg [32-1:0] wb_dat_o; reg [32-1:0] wb_dat; reg wb_ack_o; reg wb_int_o; reg [`SPI\_CTRL\_BIT\_NB-1:0] ctrl;  
reg miso\_pad\_o;  
// -----------------------------------------------------------------------------------  
// Address decoder

```
 assign spi_ctrl_sel = wb_cyc_i & wb_stb_i & ( wb_adr_i [`SPI_OFS_BITS] == `SPI_CTRL); 

 assign rx_negedge = ctrl [`SPI_CTRL_RX_NEGEDGE]; 

 assign tx_negedge = ctrl [`SPI_CTRL_TX_NEGEDGE]; 

 assign char_len = ctrl [`SPI_CTRL_CHAR_LEN]; 

 assign ie = ctrl [`SPI_CTRL_IE];

 assign spi_tx_sel = wb_cyc_i & wb_stb_i & ( wb_adr_i [`SPI_OFS_BITS] == `SPI_TX_0);

```

// -----------------------------------------------------------------------------------  
// Wb data out

always@(posedge wb\_clk\_i or posedge wb\_rst\_i)  
begin  
if (wb\_rst\_i)  
wb\_dat\_o \<= 32’b0;  
else  
wb\_dat\_o \<= wb\_dat;  
end  
// -----------------------------------------------------------------------------------  
// Wb acknowledge  
always@(posedge wb\_clk\_i or posedge wb\_rst\_i)  
begin  
if ( wb\_rst\_i )  
wb\_ack\_o \<= 1’b0;  
else  
wb\_ack\_o \<= wb\_cyc\_i & wb\_stb\_i & ~wb\_ack\_o;  
end  
// Wb error  
assign wb\_err\_o = 1’b0;  
// Interrupt  
/\*  
always @( posedge wb\_clk\_i or posedge wb\_rst\_i )  
begin  
if ( wb\_rst\_i )  
wb\_int\_o \<= 1`b0; else if ( ie && ! ss_pad_i && last_bit && pos_edge ) //there needs to be rising edge detector wb_int_o <= 1`b1;  
else if (wb\_ack\_o)  
wb\_int\_o \<= 1`b0; end */ // ----------------------------------------------------------------------------------- // Ctrl register always@(posedge wb_clk_i or posedge wb_rst_i) begin if (wb_rst_i) ctrl <= {`SPI\_CTRL\_BIT\_NB{1’b0}};  
else if (spi\_ctrl\_sel && wb\_we\_i && (!(& ss\_pad\_i) ) ) // ! ss\_pad\_i Because during no transfer we go to tristate mode  
begin  
if (wb\_sel\_i [0])  
ctrl [7:0] \<= wb\_dat\_i [7:0] | {7’b0 , ctrl [0]};  
if (wb\_sel\_i [1])  
ctrl [`SPI_CTRL_BIT_NB-1:8] <= wb_dat_i [`SPI\_CTRL\_BIT\_NB-1:8];  
end  
end  
// -----------------------------------------------------------------------------------  
always@(posedge ( sclk\_pad\_i && ! rx\_negedge ) or negedge ( sclk\_pad\_i && rx\_negedge ) or posedge wb\_rst\_i or posedge ( wb\_clk\_i && (&ss\_pad\_i ) ) )  
begin  
if (wb\_rst\_i)  
wb\_dat \<= 32’b0;  
else if (!(& ss\_pad\_i ) )  
wb\_dat \<= {wb\_dat [30:0] , mosi\_pad\_i };  
else if ((&ss\_pad\_i ) && spi\_tx\_sel )  
wb\_dat \<= wb\_dat\_i ;  
else  
wb\_dat \<= wb\_dat ;  
end  
// -----------------------------------------------------------------------------------  
always@(posedge ( sclk\_pad\_i && ! tx\_negedge ) or negedge ( sclk\_pad\_i && tx\_negedge ) )  
begin  
miso\_pad\_o \<= wb\_dat [31];  
end  
// -----------------------------------------------------------------------------------  
endmodule`include "spi_defines.v" `include “timescale.v”  
module spi\_shift(clk\_shift , rst , latch , byte\_sel , len , lsb , go , pos\_edge , neg\_edge , rx\_negedge , tx\_negedge , tip , last , p\_in , p\_out , s\_clk , s\_in , s\_out);  
// scan\_in0 , scan\_en , test\_mode , scan\_out0 , reset , clk ) ;  
input clk\_shift ; // system clock  
input rst; // reset  
input [3:0]latch; // latch signal for storing the data in shift register  
input [3:0]byte\_sel; // byte select signals for storing the data in shift register  
input [`SPI_CHAR_LEN_BITS-1:0]len; // data len in bits (minus one) input lsb; // lbs first on the line input go; // start stansfer input pos_edge; // recognize posedge of sclk input neg_edge; // recognize negedge of sclk input rx_negedge; // s_in is sampled on negative edge input tx_negedge; // s_out is driven on negative edge output tip; // transfer in progress output last; // last bit input [31:0] p_in; // parallel in output [`SPI\_MAX\_CHAR-1:0]p\_out; // parallel out  
input s\_clk; // serial clock  
input s\_in; // serial in  
output s\_out; // serial out  
reg s\_out;  
reg tip;  
reg [`SPI_CHAR_LEN_BITS:0]cnt; // data bit count reg [`SPI\_MAX\_CHAR-1:0]data; // shift register  
wire [`SPI_CHAR_LEN_BITS:0]tx_bit_pos; // next bit position wire [`SPI\_CHAR\_LEN\_BITS:0]rx\_bit\_pos; // next bit position  
wire rx\_clk; // rx clock enable  
wire tx\_clk; // tx clock enable  
// -----------------------------------------------------------------------------------  
assign p\_out =data;  
assign tx\_bit\_pos = lsb ? {!(| len ) , len} - cnt : cnt - {{ `SPI_CHAR_LEN_BITS{1'b0}},1'b1}; assign rx_bit_pos = lsb ? {!(| len ) , len} - ( rx_negedge ? cnt + {{`SPI\_CHAR\_LEN\_BITS{1’b0}},1’b1} : cnt ) : ( rx\_negedge ? cnt : cnt - {{ `SPI_CHAR_LEN_BITS{1'b0}},1'b1}); assign last = !(| cnt ); assign rx_clk = ( rx_negedge ? neg_edge : pos_edge ) && (! last || s_clk ); assign tx_clk = ( tx_negedge ? neg_edge : pos_edge ) && ! last; /*--------------------------Character bit counter -----------------------------------*/ always@(posedge clk_shift or posedge rst) begin if(rst) cnt <= {`SPI\_CHAR\_LEN\_BITS+1{1’b0}};  
else  
begin  
if(tip)  
cnt \<= pos\_edge ? ( cnt - {{`SPI_CHAR_LEN_BITS{1'b0 }}, 1'b1}) : cnt; else cnt <= !(| len ) ? {1'b1 , {`SPI\_CHAR\_LEN\_BITS{1’b0}}} : {1’b0 , len };  
end  
end  
/_--------------------------Transfer in progress ------------------------------------_/  
always@(posedge clk\_shift or posedge rst)  
begin  
if(rst)  
tip \<= 1’b0;  
else if (go && ~tip)  
tip \<= 1’b1;  
else if ( tip && last && pos\_edge )  
tip \<= 1’b0;  
end  
/_------------------------Sending bits to the line ----------------------------------_/  
always@(posedge clk\_shift or posedge rst)  
begin  
if(rst)  
s\_out \<= 1’b0;  
else  
s\_out \<= ( tx\_clk || ! tip ) ? data [tx\_bit\_pos [`SPI_CHAR_LEN_BITS-1:0]] : s_out; end /*-------------------Receiving bits from the line -----------------------------------*/ always@(posedge clk_shift or posedge rst) begin if(rst) data <= {`SPI\_MAX\_CHAR{1’b0}};  
`ifdef SPI_MAX_CHAR_128 else if(latch [0] && ! tip) begin if(byte_sel [3]) data [31:24] <= p_in [31:24]; if(byte_sel [2]) data [23:16] <= p_in [23:16]; if(byte_sel [1]) data [15:8] <= p_in [15:8]; if(byte_sel [0]) data [7:0] <= p_in [7:0]; end else if(latch [1] && ! tip) begin if(byte_sel [3]) data [63:56] <= p_in [31:24]; if(byte_sel [2]) data [55:48] <= p_in [23:16]; if(byte_sel [1]) data [47:40] <= p_in [15:8]; if(byte_sel [0]) data [39:32] <= p_in [7:0]; end else if( latch [2] && ! tip ) begin if(byte_sel [3]) data [95:88] <= p_in [31:24]; if(byte_sel [2]) data [87:80] <= p_in [23:16]; if(byte_sel [1]) data [79:72] <= p_in [15:8]; if(byte_sel [0]) data [71:64] <= p_in [7:0]; end else if(latch [3] && ! tip) begin if(byte_sel [3]) data [127:120] <= p_in [31:24]; if(byte_sel [2]) 124 data [119:112] <= p_in [23:16]; if(byte_sel [1]) 126 data [111:104] <= p_in [15:8]; if(byte_sel [0]) 128 data [103:96] <= p_in [7:0]; end `else  
`ifdef SPI_MAX_CHAR_64 else if( latch [0] && ! tip ) begin if(byte_sel[3]) data [31:24] <= p_in [31:24]; if(byte_sel[2]) data [23:16] <= p_in [23:16]; if(byte_sel[1]) data [15:8] <= p_in [15:8]; if(byte_sel[0]) data [7:0] <= p_in [7:0]; end else if ( latch [1] && ! tip ) begin if(byte_sel [3]) data [63:56] <= p_in [31:24]; if(byte_sel [2]) data [55:48] <= p_in [23:16]; if(byte_sel [1]) data [47:40] <= p_in [15:8]; if(byte_sel [0]) data [39:32] <= p_in [7:0]; end `else  
else if( latch [0] && ! tip )  
begin  
`ifdef SPI_MAX_CHAR_8 if(byte_sel [0]) data [`SPI\_MAX\_CHAR-1:0] \<= p\_in [`SPI_MAX_CHAR-1:0]; `endif  
`ifdef SPI_MAX_CHAR_16 if(byte_sel [0]) data [7:0] <= p_in [7:0]; if(byte_sel [1]) data [`SPI\_MAX\_CHAR-1:8] \<= p\_in [`SPI_MAX_CHAR-1:8]; `endif  
`ifdef SPI_MAX_CHAR_24 if(byte_sel [0]) data [7:0] <= p_in [7:0]; if(byte_sel [1]) data [15:8] <= p_in [15:8]; if(byte_sel [2]) data [`SPI\_MAX\_CHAR-1:16] \<= p\_in [`SPI_MAX_CHAR -1:16]; `endif  
`ifdef SPI_MAX_CHAR_32 if(byte_sel [0]) data [7:0] <= p_in [7:0]; if(byte_sel [1]) data [15:8] <= p_in [15:8]; if(byte_sel [2]) data [23:16] <= p_in [23:16]; if(byte_sel [3]) data [`SPI\_MAX\_CHAR-1:24] \<= p\_in [`SPI_MAX_CHAR -1:24]; `endif  
end  
`endif `endif  
else  
data [rx\_bit\_pos [`SPI_CHAR_LEN_BITS-1:0]] <= rx_clk ? s_in : data [rx_bit_pos [`SPI\_CHAR\_LEN\_BITS-1:0]];  
end  
// -----------------------------------------------------------------------------------  
endmodule

[Next page](https://verificationacademy.com/forums/t/how-to-resolve-this-error/35745.md?page=2)
