aboutsummaryrefslogtreecommitdiff
path: root/src/devices/electrical_value_list_source.cpp
blob: 02b6af54047c6f3a5aa6997ef1a66a09f573ad48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "specs.h"
#include "electrical_value_list_source.h"

using std::cout;
using std::cerr;
using std::endl;

void EVLSource::runner()
{
    if (specsGlobalConfig.verbose_component_initialization)
    {
        cout << name() << ":" << endl;
        cout << "value list (" << m_values_queue.size() << " values)";
        if (false)
        {
            cout << ":" << endl;
            for (const auto& val : m_values_queue)
                cout << "\t" << "@" << sc_time(val.first, SC_SEC) << ": " << val.second << endl;
        }
        cout << endl;
        cout << "--> " <<
            (dynamic_cast<spx::ea_signal_type *>(p_out.get_interface()))->name() << endl;
        cout << endl;
    }

    // Wait for enable signal
    if (! enable.read().to_bool())
    {
        // cout << name() << " waiting for enable" << endl;
        wait(enable.posedge_event());
        cout << name() << " was enabled" << endl;
    }

    // Emitting 0 at enable (will only go through if there is no value at t=0)
    if (m_values_queue.cbegin() == m_values_queue.cend()
        || sc_time(m_values_queue.front().first, SC_SEC).value() > 0)
    {
        cout << "@" << sc_time_stamp() << ", " << name() << " emitted: " << spx::ea_value_type(0) << endl;
        p_out->write(spx::ea_value_type(0));
    }

    auto it = m_values_queue.cbegin();
    while (it != m_values_queue.cend())
    {
        sc_time now = sc_time_stamp();
        if (it->first < now.to_seconds())
        {
            ++it;
            continue;
        }
        sc_time delay = sc_time(it->first, SC_SEC) - now;

        // Wait until next output time
        wait(delay);

        auto Vout = it->second;

        // Write value to output
        p_out->write(Vout);
        cout << "@" << sc_time_stamp() << ", " << name() << " emitted: " << Vout << endl;

        ++it;
    }

    // cout << name() << " completed" << endl;
    while(true) { wait(); }
}