-- T_straight_chans macro 0.002: (C) A E Lawrence 1993,1994 -- #INCLUDE "harp1plc.inc" -- This declares XFPGA.w [2]PORT OF INT FPGA.chan.ports: PLACE FPGA.chan.ports AT XFPGA.w: -- {{{ indices and masks VAL INT flags.index IS 0: -- VAL []INT from.FPGA.indices IS [1]: -- VAL []INT to.FPGA.indices IS [0]: -- VAL []INT from.bit.masks IS [1]: -- VAL []INT to.bit.masks IS [2]: -- }}} PROTOCOL EVENT IS ANY: -- Toolset flavour CHAN OF EVENT EventIn : -- ANY EventIn | EVENT EventIn PLACE EventIn AT 8 : VAL no.of.channels IS 2: -- {{{ ready channels between Event.Handler and clients [no.of.channels]CHAN OF BOOL ready: -- {{{ COMMENT Notes on abbreviations below -- Possible abbreviations using FPGA internal names (`_' changed to `.') -- are included. However, the abbreviations for the PORTS are commented out. -- The reason is that otherwise the compiler may report an aliasing problem. -- Any abbreviation of an array must be disjoint: this is to ensure that there -- is a unique name for any port in any scope. In the current situation, a -- single address really represents two ports, one in each direction. -- -- The commented abbreviations may be used if they are moved into a local -- scope, so that there is only one alias for a given port at any point -- Or the compiler alias checking can be turned off temporarily. -- It is preferable to use the abbreviations in outermost local scope: -- with most compilers, this leads to more efficient code. -- }}} -- {{{ Channels FPGA ----> transputer -- {{{ C.cout.0 ready.C.cout.0 IS ready[0] : -- port.C.cout.0 IS FPGA.chan.ports[1] : -- }}} -- }}} -- {{{ Channels transputer ----> FPGA -- {{{ ChanOut.Bus.3 ready.ChanOut.Bus.3 IS ready[1] : -- port.ChanOut.Bus.3 IS FPGA.chan.ports[0] : -- }}} -- }}} -- }}} -- {{{ Event.Handler, version 1 -- Version 1: Fast, but termination might be awkward in rare circumstances -- active in Event.Handler below must be FPGA.chan.ports[flags.index] -- or an alias defined with an abbreviation. -- {{{ Event.Handler -- Advantages: fewest branches in ALT, and this reduces if any channels -- shut down early. Disadvantage: termination might be awkward in rare -- circumstances -- There is scope for improved efficiency below, including:- -- 1) moving 1 << i out of the replicated ALT; and -- 2) avoiding indexing into ready in the replicated ALT. -- This is automatically generated code, and you may wish to -- use an ALT with explicit rather than replicated branches. -- However, the largest overhead is servicing the Event channel. -- {{{ Event.Handler PROC Event.Handler(PORT OF INT active,[no.of.channels]CHAN OF BOOL ready) -- {{{ COMMENT CSP (FDRish) -- A, "Alive", is the set of channels active, as seen from the transputer -- H, "Hready", is the set of hardware channels both alive *and* ready. -- Thus Hready - Alive = {} is always true. -- -- Event.handler = Ev.hand({},0..n-1) -- Ev.hand(H,{}) = SKIP -- Ev.hand(H,A) = ready(H,A) [] event(H,A) -- -- ready(H,A) = [] i:A @ ( ready.i ? more -> -- ( if more then Ev.hand(H-{i},A) -- else Ev.hand(H-{i},A-{i}) ) ) -- -- event(H,A) = event ? flags -> Ev.hand( (H union flags) intersect A, A) -- }}} VAL flag.mask IS (1 << no.of.channels) MINUS 1 : BOOL any,talking : INT flags,Hready,alive : SEQ Hready,alive := 0,flag.mask -- {{{ main loop WHILE alive <> 0 PRI ALT -- {{{ Any ready ALT i = 0 FOR no.of.channels VAL bit.mask IS 1 << i : -- move out for more speed ((Hready /\ bit.mask) <> 0) & ready[i] ? talking SEQ -- {{{ turn off hardware reflection Hready := Hready /\ (~bit.mask) -- }}} IF -- {{{ more talking SKIP -- }}} -- {{{ otherwise deactivate this channel TRUE alive := alive /\ (~bit.mask) -- }}} -- }}} -- {{{ Event? (This may be very frequent, so lower priority) EventIn ? flags SEQ active ? flags flags := flags /\ alive -- ignore any channels shut down Hready := Hready \/ flags -- }}} -- }}} : -- }}} -- }}} -- }}} -- There may be further occam components below from embedded sub-macros. -- These can probably be ignored and should be deleted:- -- {{{ TP_bd & TP_bdl macros: (C) A E Lawrence 1994 -- {{{ Toolset version -- #COMMENT T_bd macro: (C) A E Lawrence 1994 -- #INCLUDE "harp1plc.inc" -- This declares XFPGA.array as below -- [#400000]INT XFPGA.array : -- allows block move (2^27 words) on array -- PLACE XFPGA.array AT XFPGA.w : -- {{{ COMMENT PORT alternative -- [#400000]PORT OF INT XFPGA : -- This is normally mutually exclusive with -- PLACE XFPGA AT XFPGA.w : -- XFPGA.array. For both, use RETYPE... -- }}} -- }}} -- }}}