58d5e12ca3dd92d0b4095b3c751a06406f8d810a
[fleet.git] / ships / Stack.ship
1 ship: Stack
2
3 == Ports ===========================================================
4 data  in:   push
5 data  out:  pop
6
7 == Constants ========================================================
8
9 == TeX ==============================================================
10 A stack ship with capacity for at least 32 elements.
11
12 Push operations are executed as soon as an inbound datum is {\tt
13 deliver}ed on the {\tt push} port.  Completion of a push can be
14 confirmed by sending a {\tt notify} token from the {\tt push} port.
15
16 Pop operations are executed no earlier than the time at which the {\tt
17 pop} port attempts to {\tt take} data from the ship.
18
19 When the stack becomes full, it will simply not process any new {\tt
20 push} operations.  When the stack becomes empty, it will simply not
21 process any new {\tt pop} operations.
22
23 == Fleeterpreter ====================================================
24     private ArrayList<Long> stack = new ArrayList<Long>();
25     public void service() {
26         if (box_push.dataReadyForShip() && stack.size()<32) {
27             stack.add(box_push.removeDataForShip());
28         }
29         if (box_pop.readyForDataFromShip() && stack.size() > 0) {
30             box_pop.addDataFromShip(stack.get(stack.size()-1));
31             stack.remove(stack.size()-1);
32         }
33     }
34
35 == FleetSim ==============================================================
36 == FPGA ==============================================================
37
38   reg    [(`DATAWIDTH-1):0] mem [4:0];
39   reg    [5:0]              depth;
40
41   always @(posedge clk) begin
42     if (depth < 32) begin
43       `onread(push_r, push_a)
44         pop_d       = push_d;
45         mem[depth] <= push_d;
46         depth       = depth + 1;
47       end
48     end
49     if (depth > 0) begin
50       `onwrite(pop_r, pop_d)
51         depth = depth - 1;
52         if (depth > 0) begin
53           pop_d = mem[depth];
54         end
55       end
56     end
57   end
58
59
60 == Contributors =========================================================
61 Adam Megacz <megacz@cs.berkeley.edu>