ArbTest.Mesa
Last Edited by: Spreitzer, May 28, 1984 11:38:34 am PDT
DIRECTORY IO, Random, Rope, RoseClocks, RoseCreate, RoseRun, RoseReadSim, RoseTypes, SwitchTypes;
ArbTest: CEDAR PROGRAM
IMPORTS IO, RoseCreate, RoseReadSim, RoseRun, SwitchTypes =
BEGIN OPEN RoseCreate, RoseRun, RoseTypes;
DataBits: CARDINAL = 8;
AddressBits: CARDINAL = 2;
MemLength: CARDINAL = TwoToThe[AddressBits];
CmdBits: CARDINAL = 2;
BusWidth: CARDINAL = DataBits + AddressBits + CmdBits;
Modules: CARDINAL = 3;
Clients: CARDINAL = 16;
inputH: SwitchTypes.SwitchVal = [[input, input, none], H];
inputL: SwitchTypes.SwitchVal = [[input, none, input], L];
driveH: SwitchTypes.SwitchVal = [[drive, drive, none], H];
driveX: SwitchTypes.SwitchVal = [[drive, drive, drive], X];
driveL: SwitchTypes.SwitchVal = [[drive, none, drive], L];
ClientIndex: TYPE = [0 .. Clients);
ArbIO: TYPE = REF ArbIORep;
ArbIORep: TYPE = MACHINE DEPENDENT RECORD [
fill0(0:0..SwitchTypes.bitsPerSwitchValFiller-1): SwitchTypes.SwitchValFiller,
PhA(0:16-SwitchTypes.bitsPerSwitchVal..15): SwitchTypes.SwitchVal,
fill1(1:0..SwitchTypes.bitsPerSwitchValFiller-1): SwitchTypes.SwitchValFiller,
PhB(1:16-SwitchTypes.bitsPerSwitchVal..15): SwitchTypes.SwitchVal,
fill2(2:0..SwitchTypes.bitsPerSwitchValFiller-1): SwitchTypes.SwitchValFiller,
NewRqBar(2:16-SwitchTypes.bitsPerSwitchVal..15): SwitchTypes.SwitchVal,
clients(3:0..511): ARRAY ClientIndex OF Client];
Client: TYPE = MACHINE DEPENDENT RECORD [
fill0(0:0..SwitchTypes.bitsPerSwitchValFiller-1): SwitchTypes.SwitchValFiller,
RqBar(0:16-SwitchTypes.bitsPerSwitchVal..15): SwitchTypes.SwitchVal,
fill1(1:0..SwitchTypes.bitsPerSwitchValFiller-1): SwitchTypes.SwitchValFiller,
GnBar(1:16-SwitchTypes.bitsPerSwitchVal..15): SwitchTypes.SwitchVal];
CreateArbIO: IOCreator--PROC [cell: Cell, initData: REF ANY]-- =
BEGIN
cell.realCellStuff.switchIO ← NEW [ArbIORep];
cell.realCellStuff.newIO ← NEW [ArbIORep];
cell.realCellStuff.oldIO ← NEW [ArbIORep];
END;
ArbState: TYPE = REF ArbStateRep;
ArbStateRep: TYPE = RECORD [
startAt: ClientIndex ← 0,
hasGrant: [0 .. Clients] ← Clients];
InitializeArb: Initializer--PROC [cell: Cell, initData: REF ANY, leafily: BOOLEAN]-- =
BEGIN
IF leafily THEN cell.realCellStuff.state ← NEW [ArbStateRep ← []];
END;
ArbOther: CellProc--PROC [cell: Cell]-- =
BEGIN
as: ArbState ← NARROW[cell.realCellStuff.state];
newIO: ArbIO ← NARROW[cell.realCellStuff.newIO];
oldIO: ArbIO ← NARROW[cell.realCellStuff.oldIO];
oldIO^ ← newIO^;
BEGIN OPEN as, newIO;
AnyRq: PROC RETURNS [any: BOOLEAN] =
{FOR client: ClientIndex IN ClientIndex DO
IF NOT clients[client].RqBar THEN RETURN [TRUE];
ENDLOOP;
any ← FALSE};
IF PhA THEN
FOR client: ClientIndex IN ClientIndex DO
clients[client].GnBar ← client # hasGrant;
ENDLOOP;
IF PhB THEN
IF (NOT NewRqBar) OR (IF hasGrant < Clients THEN clients[hasGrant].RqBar ELSE AnyRq[]) THEN
BEGIN
hasGrant ← Clients;
FOR offset: ClientIndex IN ClientIndex DO
client: ClientIndex ← (offset + startAt) MOD Clients;
IF NOT clients[client].RqBar THEN
{hasGrant ← client; startAt ← (hasGrant+1) MOD Clients; EXIT};
ENDLOOP;
END;
END;
END;
ExpandArb: ExpandProc--PROCEDURE [thisCell: Cell, initData: REF ANY]-- =
BEGIN
RoseReadSim.ReadSim[within: thisCell, fileName: "Passarb.sim", smallNode: 0.02, bigNode: 0.3];
END;
TestArbiter: CellTestProc--PROC [handle: CellTestHandle, initData, testData, io: REF ANY]-- =
BEGIN
instructions: ArbIO ← NARROW[io];
BEGIN OPEN instructions;
Cycle: PROC =
BEGIN
PhA ← inputH;
PhB ← inputL;
[] ← Eval[handle];
PhA ← inputL;
[] ← Eval[handle];
PhB ← inputH;
[] ← Eval[handle];
PhB ← inputL;
[] ← Eval[handle];
END;
NewRqBar ← inputL;
FOR ci: ClientIndex IN ClientIndex DO
clients[ci].RqBar ← inputH;
ENDLOOP;
clients[0].RqBar ← inputL;
Cycle[];
Cycle[];
Cycle[];
FOR ci: ClientIndex IN ClientIndex DO
IF clients[ci].GnBar.val # (IF ci = 0 THEN L ELSE H) THEN ERROR;
ENDLOOP;
END;
END;
ExpandArbTest: ExpandProc--PROCEDURE [thisCell: Cell, initData: REF ANY]-- =
BEGIN
PhA: Node ← CreateNode[thisCell, "PHASEA", SwitchTypes.bitType, NIL, SwitchTypes.refInput];
PhB: Node ← CreateNode[thisCell, "PHASEB", SwitchTypes.bitType, NIL, SwitchTypes.refInput];
Requests, Grants: ARRAY ClientIndex OF Node;
NewRqBar: Node ← CreateNode[thisCell, "NEWRQ'", SwitchTypes.bitType, "L", SwitchTypes.refInput];
FOR client: ClientIndex IN ClientIndex DO
Requests[client] ← CreateNode[thisCell, IO.PutFR["RQ%02g'", IO.card[client]], SwitchTypes.bitType, "H", SwitchTypes.refInput];
Grants[client] ← CreateNode[thisCell, IO.PutFR["GP%02g'", IO.card[client]], SwitchTypes.bitType, "H"];
ENDLOOP;
[] ← CreateCell[thisCell, "Arbiter", "Arbiter", ""];
END;
Setup: PROC =
BEGIN
arbPorts: Ports ← NEW [PortsRep[35]];
arbPorts[0] ← [0, 1, "PHASEA", SwitchTypes.bitType, TRUE, TRUE];
arbPorts[1] ← [1, 1, "PHASEB", SwitchTypes.bitType, TRUE, TRUE];
arbPorts[2] ← [2, 1, "NEWRQ'", SwitchTypes.bitType, TRUE, TRUE];
FOR client: ClientIndex IN ClientIndex DO
arbPorts[3+2*client] ← [3+2*client, 1, IO.PutFR["RQ%02g'", IO.card[client]], SwitchTypes.bitType, TRUE, TRUE];
arbPorts[4+2*client] ← [4+2*client, 1, IO.PutFR["GP%02g'", IO.card[client]], SwitchTypes.bitType, TRUE, TRUE];
ENDLOOP;
[] ← RegisterCellClass[
className: "Arbiter",
ioCreator: CreateArbIO,
expandProc: ExpandArb,
initializer: InitializeArb,
evals: [--Other: ArbOther--],
blackBox: TestArbiter,
ports: arbPorts];
[] ← RegisterCellClass[
className: "ArbTest",
expandProc: ExpandArbTest,
evals: [],
ports: NEW [PortsRep[0]]];
END;
Setup[];
END.