From 760f65ffad2b58dddb53a5dae1d6d703523792ae Mon Sep 17 00:00:00 2001 From: adam Date: Sun, 25 Feb 2007 05:39:28 +0100 Subject: [PATCH] add Stack ship and tests --- ships/Stack.ship | 61 +++++++++++++++++++++++++++ src/edu/berkeley/fleet/slipway/Slipway.java | 1 + tests/stack/stack-test.fleet | 21 +++++++++ 3 files changed, 83 insertions(+) create mode 100644 ships/Stack.ship create mode 100644 tests/stack/stack-test.fleet diff --git a/ships/Stack.ship b/ships/Stack.ship new file mode 100644 index 0000000..58d5e12 --- /dev/null +++ b/ships/Stack.ship @@ -0,0 +1,61 @@ +ship: Stack + +== Ports =========================================================== +data in: push +data out: pop + +== Constants ======================================================== + +== TeX ============================================================== +A stack ship with capacity for at least 32 elements. + +Push operations are executed as soon as an inbound datum is {\tt +deliver}ed on the {\tt push} port. Completion of a push can be +confirmed by sending a {\tt notify} token from the {\tt push} port. + +Pop operations are executed no earlier than the time at which the {\tt +pop} port attempts to {\tt take} data from the ship. + +When the stack becomes full, it will simply not process any new {\tt +push} operations. When the stack becomes empty, it will simply not +process any new {\tt pop} operations. + +== Fleeterpreter ==================================================== + private ArrayList stack = new ArrayList(); + public void service() { + if (box_push.dataReadyForShip() && stack.size()<32) { + stack.add(box_push.removeDataForShip()); + } + if (box_pop.readyForDataFromShip() && stack.size() > 0) { + box_pop.addDataFromShip(stack.get(stack.size()-1)); + stack.remove(stack.size()-1); + } + } + +== FleetSim ============================================================== +== FPGA ============================================================== + + reg [(`DATAWIDTH-1):0] mem [4:0]; + reg [5:0] depth; + + always @(posedge clk) begin + if (depth < 32) begin + `onread(push_r, push_a) + pop_d = push_d; + mem[depth] <= push_d; + depth = depth + 1; + end + end + if (depth > 0) begin + `onwrite(pop_r, pop_d) + depth = depth - 1; + if (depth > 0) begin + pop_d = mem[depth]; + end + end + end + end + + +== Contributors ========================================================= +Adam Megacz diff --git a/src/edu/berkeley/fleet/slipway/Slipway.java b/src/edu/berkeley/fleet/slipway/Slipway.java index cb833d1..d35602f 100644 --- a/src/edu/berkeley/fleet/slipway/Slipway.java +++ b/src/edu/berkeley/fleet/slipway/Slipway.java @@ -47,6 +47,7 @@ public class Slipway extends Fleet { createShip("Choice", "Choice"); createShip("Choice", "Choice"); createShip("Choice", "Choice"); + createShip("Stack", "Stack"); dumpFabric(true); } diff --git a/tests/stack/stack-test.fleet b/tests/stack/stack-test.fleet new file mode 100644 index 0000000..835ffc0 --- /dev/null +++ b/tests/stack/stack-test.fleet @@ -0,0 +1,21 @@ +#ship stack : Stack +#ship debug : Debug + +#expect 4 +#expect 3 +#expect 2 +#expect 1 +#expect 0 + +stack.push: [5] take, deliver; notify stack.pop; + +0: sendto stack.push; +1: sendto stack.push; +2: sendto stack.push; +3: sendto stack.push; +4: sendto stack.push; + +stack.pop: wait; [*] take, sendto debug.in; +debug.in: [*] take, deliver; + + -- 1.7.10.4