-
Notifications
You must be signed in to change notification settings - Fork 55
Modules, Hierarchy, Composability
Julian Kemmerer edited this page Oct 15, 2020
·
24 revisions
// sub.c
output_t sub(input_t input)
{
// Do work on input to get output
return work(input);
}// top.c
#include "sub.c"
output_t top(input_t input)
{
return sub(input);
}// top.c
// Globally visible ports/wires with built in READ and WRITE
input_t top_to_sub; // Output from top, input to sub
output_t sub_to_top; // Input into top, output from sub
output_t top(input_t input)
{
WRITE(top_to_sub, input);
return READ(sub_to_top);
}// sub.c
#include "top.c"
void sub()
{
// Do work on input to get output
input_t input = READ(top_to_sub);
output_t output = work(input);
WRITE(sub_to_top, output);
}As opposed to rewiring the LEDs manually through the ports of top,sub, and work using a globally visible point to point wire makes reading and writing arbitrary signals in the design possible.
// leds.c
// Globally visible port/wire name
uint4_t leds;
uint4_t leds_module()
{
// Drive the output port with the global wire
return READ(leds);
}#include "leds.c"
output_t work(input_t input)
{
// Doing lots of complicated stuff
// ...
// Lets drive status leds
uint4_t leds = 0xF;
WRITE(leds);
// ...
}
output_t sub(input_t input)
{
return work(input);
}
output_t top(input_t input)
{
return sub(input);
}The above code snippets are pseudo code as the real C syntax is a bit uglier for global wires (a type of non volatile clock crossing wires).

