Skip to content

Commit

Permalink
Added gpio binds for sc_signal (fixes #77)
Browse files Browse the repository at this point in the history
  • Loading branch information
janweinstock committed Jan 25, 2024
1 parent f75b448 commit f6f74f6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
4 changes: 4 additions & 0 deletions include/vcml/protocols/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ void gpio_bind(const sc_object& obj1, const string& port1, size_t idx1,
void gpio_bind(const sc_object& obj1, const string& port1, size_t idx1,
const sc_object& obj2, const string& port2, size_t idx2);

void gpio_bind(const sc_object& obj, const string& port, sc_signal<bool>& s);
void gpio_bind(const sc_object& obj, const string& port, size_t idx,
sc_signal<bool>& s);

} // namespace vcml

#endif
31 changes: 31 additions & 0 deletions src/vcml/protocols/gpio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,4 +516,35 @@ void gpio_bind(const sc_object& obj1, const string& port1, size_t idx1,
t1->bind(*t2);
}

void gpio_bind(const sc_object& obj, const string& port, sc_signal<bool>& s) {
auto* p = find_child(obj, port);
VCML_ERROR_ON(!p, "%s.%s does not exist", obj.name(), port.c_str());

auto* i = get_initiator_socket(p);
auto* t = get_target_socket(p);

VCML_ERROR_ON(!i && !t, "%s is not a valid gpio port", p->name());

if (i)
i->bind(s);
else if (t)
t->bind(s);
}

void gpio_bind(const sc_object& obj, const string& port, size_t idx,
sc_signal<bool>& s) {
auto* p = find_child(obj, port);
VCML_ERROR_ON(!p, "%s.%s does not exist", obj.name(), port.c_str());

auto* i = get_initiator_socket(p, idx);
auto* t = get_target_socket(p, idx);

VCML_ERROR_ON(!i && !t, "%s is not a valid gpio port", p->name());

if (i)
i->bind(s);
else if (t)
t->bind(s);
}

} // namespace vcml
24 changes: 21 additions & 3 deletions test/core/gpio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class gpio_test_harness : public test_base
sc_signal<bool> signal;
gpio_target_socket a_in;

gpio_initiator_array arr_out;
sc_signal<bool> signal2;
gpio_target_array arr_in;

gpio_test_harness(const sc_module_name& nm):
test_base(nm),
out("out"),
Expand All @@ -48,7 +52,10 @@ class gpio_test_harness : public test_base
h_in("h_in"),
a_out("a_out"),
signal("signal"),
a_in("a_in") {
a_in("a_in"),
arr_out("arr_out"),
signal2("signal2"),
arr_in("arr_in") {
// check socket lookup
EXPECT_EQ(&out, &gpio_initiator(*this, "out"));
EXPECT_EQ(&out2, &gpio_initiator(*this, "out2"));
Expand All @@ -69,8 +76,10 @@ class gpio_test_harness : public test_base
EXPECT_TRUE(in[2].is_stubbed());

// check adapters
a_out.bind(signal);
a_in.bind(signal);
gpio_bind(*this, "a_out", signal);
gpio_bind(*this, "a_in", signal);
gpio_bind(*this, "arr_out", 14, signal2);
gpio_bind(*this, "arr_in", 102, signal2);

// did the port get created?
EXPECT_TRUE(find_object("gpio.out2"));
Expand All @@ -83,6 +92,8 @@ class gpio_test_harness : public test_base
// did the adapters get created?
EXPECT_TRUE(find_object("gpio.a_out_adapter"));
EXPECT_TRUE(find_object("gpio.a_in_adapter"));
EXPECT_TRUE(find_object("gpio.arr_out[14]_adapter"));
EXPECT_TRUE(find_object("gpio.arr_in[102]_adapter"));
}

MOCK_METHOD(void, gpio_notify,
Expand Down Expand Up @@ -143,6 +154,13 @@ class gpio_test_harness : public test_base
a_out.raise();
wait(signal.default_event());
EXPECT_TRUE(a_in);

// test array adapters
EXPECT_CALL(*this,
gpio_notify(gpio("arr_in[102]"), true, GPIO_NO_VECTOR));
arr_out[14].raise();
wait(signal2.default_event());
EXPECT_TRUE(arr_in[102]);
}
};

Expand Down

0 comments on commit f6f74f6

Please sign in to comment.