aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-09-24 16:51:51 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-09-24 18:47:13 +0300
commitfecb86f6093c1e8aed6ab05c29c5af9d0cb93157 (patch)
tree10171c839d77167fc98fbae0b315d2c87aa13fa5 /tests
parentb1d67364b4b4832b8efed112f7b0ead1a0b3cd3b (diff)
downloadgran-fecb86f6093c1e8aed6ab05c29c5af9d0cb93157.tar.gz
gran-fecb86f6093c1e8aed6ab05c29c5af9d0cb93157.zip
initial work towards message passing interface
+ As they are currently implemented, grid *may* get stuck if two nodes try to send to eachother at the same time, I should probably add in some kind of input buffer as well
Diffstat (limited to 'tests')
-rw-r--r--tests/simple_grid/sim.c3
-rw-r--r--tests/simple_mem/no_bus.c1
-rw-r--r--tests/simple_mem/traffic_gen.c64
3 files changed, 34 insertions, 34 deletions
diff --git a/tests/simple_grid/sim.c b/tests/simple_grid/sim.c
index e0c485b..f11be21 100644
--- a/tests/simple_grid/sim.c
+++ b/tests/simple_grid/sim.c
@@ -67,7 +67,8 @@ static stat build_grid(struct clock_domain *clk, uint8_t x, uint8_t y)
struct component *router = create_node_router(0, 0, i, j);
node_router_add(router, dmem, 4096, 4096);
- struct component *rv64 = create_simple_riscv64(0, imem, router);
+ uint64_t rcv = grid_addr(0, 0, i, j, 16384);
+ struct component *rv64 = create_simple_riscv64(rcv, 0, imem, router);
simple_riscv64_set_reg(rv64, 10, i); /* a0 */
simple_riscv64_set_reg(rv64, 11, j); /* a1 */
diff --git a/tests/simple_mem/no_bus.c b/tests/simple_mem/no_bus.c
index 8c67e1e..f4622c8 100644
--- a/tests/simple_mem/no_bus.c
+++ b/tests/simple_mem/no_bus.c
@@ -17,6 +17,7 @@ int main()
struct clock_domain *clk = create_clock_domain(NS(1));
clock_domain_add(clk, traffic_gen);
+ clock_domain_add(clk, simple_mem);
struct gran_root *root = create_root();
root_add_clock(root, clk);
diff --git a/tests/simple_mem/traffic_gen.c b/tests/simple_mem/traffic_gen.c
index 192e2c4..a4d5064 100644
--- a/tests/simple_mem/traffic_gen.c
+++ b/tests/simple_mem/traffic_gen.c
@@ -12,53 +12,61 @@ struct traffic_gen {
struct component component;
struct component *stress;
- struct packet *pkt;
+ struct packet pkt;
- uintptr_t addr;
- uintptr_t end;
+ uint64_t rcv;
+ uint64_t addr;
+ uint64_t end;
size_t counter;
};
+static stat traffic_gen_receive(struct traffic_gen *tg, struct component *from, struct packet pkt)
+{
+ (void)from;
+ tg->pkt = pkt;
+ return OK;
+}
+
static stat traffic_gen_clock(struct traffic_gen *tg)
{
if (tg->addr == tg->end)
return DONE;
uint8_t c = 0;
- if (tg->pkt) {
- assert(packet_state(tg->pkt) != PACKET_FAILED);
- /* wait for packet */
- if (packet_state(tg->pkt) != PACKET_DONE)
- return OK;
- }
-
switch (tg->counter) {
case 0:
c = 13;
- tg->pkt = create_packet(PACKET_WRITE, tg->addr, sizeof(c));
- *(uint8_t *)packet_data(tg->pkt) = c;
- assert(write(tg->stress, tg->pkt) == OK);
+ tg->pkt = create_packet(tg->rcv, tg->addr, sizeof(c), &c, PACKET_WRITE);
+ assert(SEND(tg, tg->stress, tg->pkt) == OK);
tg->counter++;
break;
case 1:
- /* destroy write packet now that the write is done */
- destroy_packet(tg->pkt);
- tg->pkt = NULL;
+ /* wait for write to finish */
+ if (!is_set(&tg->pkt, PACKET_DONE))
+ break;
+
tg->counter++;
break;
case 2:
- tg->pkt = create_packet(PACKET_READ, tg->addr, sizeof(c));
- assert(read(tg->stress, tg->pkt) == OK);
+ tg->pkt = create_packet(0, tg->addr, sizeof(c), NULL, PACKET_READ);
+ assert(SEND(tg, tg->stress, tg->pkt) == OK);
tg->counter++;
break;
case 3:
- c = *(uint8_t *)packet_data(tg->pkt);
- destroy_packet(tg->pkt);
- tg->pkt = NULL;
+ /* wait for read to finish */
+ if (!is_set(&tg->pkt, PACKET_DONE))
+ break;
+
+ tg->counter++;
+ break;
+
+ case 4:
+ c = packet_convu8(&tg->pkt);
+ assert(c == 13);
tg->counter = 0;
tg->addr++;
break;
@@ -67,17 +75,7 @@ static stat traffic_gen_clock(struct traffic_gen *tg)
return OK;
}
-void traffic_gen_destroy(struct traffic_gen *tg)
-{
- if (tg->pkt)
- destroy_packet(tg->pkt);
-
- destroy(tg->stress);
- free(tg);
-}
-
-struct component *create_traffic_gen(struct component *stress, uintptr_t start,
- size_t size)
+struct component *create_traffic_gen(struct component *stress, uintptr_t start, size_t size)
{
struct traffic_gen *new = calloc(1, sizeof(struct traffic_gen));
if (!new)
@@ -88,7 +86,7 @@ struct component *create_traffic_gen(struct component *stress, uintptr_t start,
new->end = start + size;
new->counter = 0;
+ new->component.receive = (receive_callback)traffic_gen_receive;
new->component.clock = (clock_callback)traffic_gen_clock;
- new->component.destroy = (destroy_callback)traffic_gen_destroy;
return (struct component *)new;
}