aboutsummaryrefslogtreecommitdiff
path: root/src/components/grid
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/grid')
-rw-r--r--src/components/grid/node.c133
-rw-r--r--src/components/grid/router.c136
-rw-r--r--src/components/grid/source.mk1
3 files changed, 0 insertions, 270 deletions
diff --git a/src/components/grid/node.c b/src/components/grid/node.c
deleted file mode 100644
index 57ef7ed..0000000
--- a/src/components/grid/node.c
+++ /dev/null
@@ -1,133 +0,0 @@
-/* very simple grid node with 32bit private region, does not currently signal
- * being busy or anything. I think I might have to refine the message passing
- * interface I have, but this is good enough.
- *
- * Each node should have a router beneath it, just to simplify my life. A router
- * is basically a bus with a fallback ascension path.
- */
-#include <stdbool.h>
-
-#include <gran/grid/node.h>
-
-struct grid_node {
- struct component component;
- uint8_t u, v, x, y;
- struct component *left, *right, *up, *down, *ascend, *lower;
-
- struct component *send;
- struct packet pkt;
- bool busy;
-};
-
-static stat grid_clock(struct grid_node *grid)
-{
- if (!grid->busy)
- return OK;
-
- stat r = SEND(grid, grid->send, grid->pkt);
- if (r == EBUSY)
- return OK;
-
- grid->busy = false;
- return r;
-}
-
-static stat grid_receive(struct grid_node *grid, struct component *from, struct packet pkt)
-{
- if (grid->busy)
- return EBUSY;
-
- uint8_t u;
- uint8_t v;
- uint8_t x;
- uint8_t y;
- uint64_t addr = pkt.to;
- addr_grid(addr, NULL, &x, &y, &u, &v);
-
- grid->busy = true;
- grid->pkt = pkt;
-
- if (grid->u == u && grid->v == v && grid->x == x && grid->y == y) {
- if (!grid->lower)
- goto nosuch;
-
- grid->send = grid->lower;
- return OK;
- }
-
- if (grid->u != u || grid->v != v) {
- if (!grid->ascend)
- goto nosuch;
-
- grid->send = grid->ascend;
- return OK;
- }
-
- if (y < grid->y) {
- if (!grid->down)
- goto nosuch;
-
- grid->send = grid->down;
- return OK;
- }
-
- if (y > grid->y) {
- if (!grid->up)
- goto nosuch;
-
- grid->send = grid->up;
- return OK;
- }
-
- if (x < grid->x) {
- if (!grid->left)
- goto nosuch;
-
- grid->send = grid->left;
- return OK;
- }
-
- if (x > grid->x) {
- if (!grid->right)
- return EBUS;
-
- grid->send = grid->right;
- return OK;
- }
-
-nosuch:
- grid->send = from;
- grid->pkt = response(pkt);
- set_flags(&grid->pkt, PACKET_ERROR);
- return OK;
-}
-
-struct component *create_grid_node(uint8_t u, uint8_t v, uint8_t x, uint8_t y)
-{
- struct grid_node *node = calloc(1, sizeof(struct grid_node));
- if (!node)
- return NULL;
-
- node->component.receive = (receive_callback)grid_receive;
- node->component.clock = (clock_callback)grid_clock;
- node->u = u;
- node->v = v;
- node->x = x;
- node->y = y;
- return (struct component *)node;
-}
-
-stat grid_node_connect(struct component *node,
- struct component *left, struct component *right,
- struct component *up, struct component *down,
- struct component *lower, struct component *ascend)
-{
- struct grid_node *n = (struct grid_node *)node;
- n->left = left;
- n->right = right;
- n->up = up;
- n->down = down;
- n->lower = lower;
- n->ascend = ascend;
- return OK;
-}
diff --git a/src/components/grid/router.c b/src/components/grid/router.c
deleted file mode 100644
index 63c4011..0000000
--- a/src/components/grid/router.c
+++ /dev/null
@@ -1,136 +0,0 @@
-#include <stdbool.h>
-
-#include <gran/grid/node.h>
-#include <gran/grid/router.h>
-#include <gran/vec.h>
-
-struct router_region {
- uint32_t addr;
- uint32_t size;
- struct component *component;
-};
-
-struct node_router {
- struct component component;
- struct component *ascend;
- struct vec regions;
- uint8_t u, v, x, y;
-
- struct component *send;
- struct packet pkt;
- bool busy;
-};
-
-static struct router_region *find_region(struct node_router *router, uint32_t addr)
-{
- for (size_t i = 0; i < vec_len(&router->regions); ++i) {
- struct router_region *region = vec_at(&router->regions, i);
-
- if (addr >= region->addr && addr < region->addr + region->size)
- return region;
- }
-
- return NULL;
-}
-
-static stat router_clock(struct node_router *router)
-{
- if (!router->busy)
- return OK;
-
- stat r = SEND(router, router->send, router->pkt);
- if (r == EBUSY)
- return OK;
-
- router->busy = false;
- return OK;
-}
-
-static stat router_receive(struct node_router *router, struct component *from, struct packet pkt)
-{
- if (router->busy)
- return EBUSY;
-
- router->busy = true;
-
- uint64_t addr = pkt.to;
- uint8_t u;
- uint8_t v;
- uint8_t x;
- uint8_t y;
- addr_grid(addr, NULL, &x, &y, &u, &v);
-
- router->pkt = pkt;
-
- if (router->u != u || router->v != v || router->x != x || router->y != y) {
- if (!router->ascend)
- goto nosuch;
-
- router->send = router->ascend;
- return OK;
- }
-
- struct router_region *region = find_region(router, addr);
- if (!region)
- goto nosuch;
-
- router->send = region->component;
- return OK;
-
-nosuch:
- router->send = from;
- router->pkt = response(pkt);
- set_flags(&router->pkt, PACKET_ERROR);
- return OK;
-}
-
-struct component *create_node_router(uint8_t u, uint8_t v, uint8_t x, uint8_t y)
-{
- struct node_router *router = calloc(1, sizeof(struct node_router));
- if (!router)
- return NULL;
-
- router->u = u;
- router->v = v;
- router->x = x;
- router->y = y;
-
- router->component.receive = (receive_callback)router_receive;
- router->component.clock = (clock_callback)router_clock;
- router->regions = vec_create(sizeof(struct router_region));
-
- return (struct component *)router;
-}
-
-stat node_router_add(struct component *router, struct component *component, uint32_t addr, uint32_t size)
-{
- struct node_router *nr = (struct node_router *)router;
- struct router_region *found = find_region(nr, addr);
- if (!found) found = find_region(nr, addr + size);
-
- if (found) {
- error("%s overlaps with %s at %x",
- found->component->name,
- component->name,
- found->addr
- );
-
- return EEXISTS;
- }
-
- struct router_region r = (struct router_region){
- .addr = addr,
- .size = size,
- .component = component
- };
- vect_append(struct node_region, nr->regions, &r);
-
- return OK;
-}
-
-stat node_router_ascend(struct component *router, struct component *node)
-{
- struct node_router *nr = (struct node_router *)router;
- nr->ascend = node;
- return OK;
-}
diff --git a/src/components/grid/source.mk b/src/components/grid/source.mk
deleted file mode 100644
index 4fb44ec..0000000
--- a/src/components/grid/source.mk
+++ /dev/null
@@ -1 +0,0 @@
-SOURCES += src/components/grid/node.c src/components/grid/router.c