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

Subversion Repositories ulpi_wrapper

[/] [ulpi_wrapper/] [trunk/] [testbench/] [sc_vpi_clock.h] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 ultra_embe
#ifndef __SC_VPI_CLOCK_H__
2
#define __SC_VPI_CLOCK_H__
3
 
4
#include <systemc.h>
5
#include <vpi_user.h>
6
 
7
 
8
static int sc_vpi_clock_after_delay(p_cb_data cb_data);
9
 
10
class sc_vpi_clock
11
{
12
public:
13
 
14
    sc_signal <bool> m_clk;
15
    int              m_low_ns;
16
    int              m_high_ns;
17
    uint64_t         m_last_time;
18
 
19
    sc_module_name   m_name;
20
 
21
    vpiHandle        m_vpi_handle;
22
 
23
    sc_vpi_clock(sc_module_name name) : m_clk(name), m_name(name)
24
    {
25
        m_low_ns  = 5;
26
        m_high_ns = 5;
27
        m_last_time = 0;
28
 
29
        m_vpi_handle = vpi_handle_by_name((const char*)name, NULL);
30
        sc_assert(m_vpi_handle != NULL);
31
    }
32
 
33
    void start(void) { after_delay(); }
34
 
35
    int after_delay(void)
36
    {
37
        bool clk_next = !m_clk.read();
38
        s_vpi_time  vpi_time_s;
39
        s_cb_data   cb_data_s;
40
 
41
        vpi_time_s.type = vpiSimTime;
42
        vpi_time_s.high = 0;
43
        vpi_time_s.low  = 0;
44
 
45
        s_vpi_value  value_s;
46
        value_s.format = vpiIntVal;
47
        value_s.value.integer = clk_next;
48
        vpi_put_value(m_vpi_handle, &value_s, &vpi_time_s, vpiInertialDelay);
49
 
50
        // Setup wait time
51
        vpi_time_s.high = 0;
52
        vpi_time_s.low  = clk_next ? m_high_ns : m_low_ns;
53
        vpi_time_s.type = vpiSimTime;
54
 
55
        m_clk.write(clk_next);
56
 
57
        // Get current time
58
        uint64_t time_value = 0;
59
        s_vpi_time time_now;
60
        time_now.type = vpiSimTime;
61
        vpi_get_time (0, &time_now);
62
 
63
        time_value = time_now.high;
64
        time_value <<= 32;
65
        time_value |= time_now.low;
66
 
67
        // Update systemC TB
68
        if(sc_pending_activity())
69
            sc_start((int)(time_value-m_last_time),SC_NS);
70
 
71
        // Attach value change callbacks for outputs
72
        cb_data_s.user_data = (PLI_BYTE8*)this;
73
        cb_data_s.reason    = cbAfterDelay;
74
        cb_data_s.cb_rtn    = sc_vpi_clock_after_delay;
75
        cb_data_s.time      = &vpi_time_s;
76
        cb_data_s.value     = NULL;
77
        vpi_register_cb(&cb_data_s);
78
    }
79
};
80
 
81
static int sc_vpi_clock_after_delay(p_cb_data cb_data)
82
{
83
    sc_vpi_clock *p = (sc_vpi_clock*)cb_data->user_data;
84
    return p->after_delay();
85
}
86
 
87
 
88
#endif

powered by: WebSVN 2.1.0

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