OpenCores
URL https://opencores.org/ocsvn/apb2spi/apb2spi/trunk

Subversion Repositories apb2spi

[/] [apb2spi/] [trunk/] [tb/] [env/] [apb_agent/] [apb_driver.sv] - Blame information for rev 15

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 15 vlnaran
 
2
class apb_driver extends uvm_driver#(apb_seq_item);
3
        `uvm_component_utils(apb_driver)
4
 
5
        //uvm_analysis_port#(apb_seq_item) apb_ap;
6
 
7
        virtual apb_if v_intf;
8
        apb_seq_item txns;
9
 
10
function new(string name,uvm_component parent);
11
        super.new(name,parent);
12
        //apb_ap = new("apb_ap",this);
13
endfunction
14
 
15
function void build_phase(uvm_phase phase);
16
        super.build_phase(phase);
17
        if(!uvm_config_db #(virtual apb_if)::get(this,"*","apb_vif",v_intf))
18
                `uvm_fatal("NO_APB_V_INTF","Virtual interface couldn't be obtained for apb driver")
19
        else
20
                `uvm_info("APB_V_INTF","Virtual interface has been obtained driver",UVM_NONE)
21
 
22
        txns = apb_seq_item::type_id::create("txns");
23
endfunction
24
 
25
task run_phase(uvm_phase phase);
26
        v_intf.PENABLE = 1'b0;
27
        forever begin
28
                `uvm_info("DRVR_RUN","Inside the run phase of driver",UVM_NONE)
29
                seq_item_port.get_next_item(txns);
30
                `uvm_info("DRVR_RUN",$psprintf("After getting the seq_item from seq, value of seq_item is %p",this.txns),UVM_NONE)
31
                v_intf.PADDR = txns.paddr;
32
                //repeat(1)@(posedge v_intf.PCLK);
33
                `uvm_info("DRVR_RUN","After assigning PADDR from sequence_item",UVM_NONE)
34
                if(txns.pwrite==1'b1)begin
35
                        `uvm_info("DRVR_RUN","Invoking the apb_write task",UVM_NONE)
36
                        apb_write(txns);
37
                end else begin
38
                        `uvm_info("DRVR_RUN","Invoking the apb_read task",UVM_NONE)
39
                        apb_read(txns);
40
                end
41
                repeat(1)@(posedge v_intf.PCLK);
42
                seq_item_port.item_done();
43
        end
44
endtask
45
 
46
task apb_write(apb_seq_item txns);
47
begin
48
        @(posedge v_intf.PCLK);
49
        //wait(v_intf.PREADY==1'b0);
50
        v_intf.PSEL = 1'b1;
51
        v_intf.PENABLE = 1'b0;
52
        v_intf.PADDR = txns.paddr;
53
        v_intf.PWRITE = txns.pwrite;
54
        @(posedge v_intf.PCLK);
55
        v_intf.PENABLE = 1'b1;
56
        wait(v_intf.PREADY==1'b1);
57
        v_intf.PWDATA = txns.pwdata;
58
        wait(v_intf.PREADY==1'b0);
59
        v_intf.PSEL = 1'b0;
60
        v_intf.PADDR = 'h0;
61
        v_intf.PWRITE = 'h0;
62
        v_intf.PENABLE = 1'b0;
63
end
64
endtask
65
 
66
task apb_read(apb_seq_item txns);
67
begin
68
        @(posedge v_intf.PCLK);
69
        //wait(v_intf.PREADY==1'b0);
70
        v_intf.PSEL = 1'b1;
71
        v_intf.PENABLE = 1'b0;
72
        v_intf.PADDR = txns.paddr;
73
        v_intf.PWRITE = 1'b0;
74
        repeat(1)@(posedge v_intf.PCLK);
75
        v_intf.PENABLE = 1'b1;
76
        wait(v_intf.PREADY==1'b1);
77
        txns.prdata = v_intf.PRDATA;
78
        wait(v_intf.PREADY==1'b0);
79
        v_intf.PSEL = 1'b0;
80
        v_intf.PADDR = 'h0;
81
        v_intf.PWRITE = 'h0;
82
        v_intf.PENABLE = 1'b0;
83
end
84
endtask
85
 
86
 
87
endclass

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.