void net_add_bus_port(struct net_t *net, struct net_node_t *src_node, struct net_node_t *dst_node, int bus_src_buffer, int bus_dst_buffer) { /* Checks */ assert(src_node->net == net); assert(dst_node->net == net); struct net_buffer_t *buffer = NULL; /* Condition 1: No support for direct BUS to BUS connection */ if (src_node->kind == net_node_bus && dst_node->kind == net_node_bus) fatal("network \"%s\" : BUS to BUS connection is not supported.", net->name); /* Condition 2: In case source node is BUS, we add an input buffer to * destination node and add it to the list of destination nodes in * BUS */ if (src_node->kind == net_node_bus && dst_node->kind != net_node_bus) { int dst_buffer_size = (bus_dst_buffer) ? bus_dst_buffer : dst_node-> input_buffer_size; buffer = net_node_add_input_buffer(dst_node, dst_buffer_size); assert(!buffer->link); list_add(src_node->dst_buffer_list, buffer); buffer->bus = list_get(src_node->bus_lane_list, 0); } /* Condition 3: In case destination node is BUS, we add an output * buffer to source node and add it to the list of source nodes in * BUS */ else if (src_node->kind != net_node_bus && dst_node->kind == net_node_bus) { int src_buffer_size = (bus_src_buffer) ? bus_src_buffer : src_node-> output_buffer_size; buffer = net_node_add_output_buffer(src_node, src_buffer_size); assert(!buffer->link); list_add(dst_node->src_buffer_list, buffer); buffer->bus = list_get(dst_node->bus_lane_list, 0); } else { fatal("network: unsuported condition in %s", __FUNCTION__); } /* We make the buffer as type port for clarification and use in event * handler */ buffer->kind = net_buffer_bus; }
struct net_link_t *net_link_create(struct net_t *net, struct net_node_t *src_node, struct net_node_t *dst_node, int bandwidth, int link_src_bsize, int link_dst_bsize, int virtual_channel) { struct net_link_t *link; struct net_buffer_t *src_buffer; struct net_buffer_t *dst_buffer; char name[MAX_STRING_SIZE]; /* Fields */ link = xcalloc(1, sizeof(struct net_link_t)); link->net = net; link->src_node = src_node; link->dst_node = dst_node; link->bandwidth = bandwidth; link->virtual_channel = virtual_channel; for (int i = 0; i < virtual_channel; i++) { src_buffer = net_node_add_output_buffer(src_node, link_src_bsize); src_buffer->kind = net_buffer_link; dst_buffer = net_node_add_input_buffer(dst_node, link_dst_bsize); dst_buffer->kind = net_buffer_link; if (i == 0) { /* Name */ snprintf(name, sizeof(name), "link_<%s.%s>_<%s.%s>", src_node->name, src_buffer->name, dst_node->name, dst_buffer->name); link->name = xstrdup(name); link->src_buffer = src_buffer; link->dst_buffer = dst_buffer; } /* Connect buffers to link */ assert(!src_buffer->link); assert(!dst_buffer->link); src_buffer->link = link; dst_buffer->link = link; } if (bandwidth < 1) panic("%s: invalid bandwidth", __FUNCTION__); /* Return */ return link; }