ArbTest.Mesa
Last Edited by: Spreitzer, January 25, 1985 4:17:16 pm PST
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:
PROC [ct: CellType]
RETURNS [ioAsAny:
REF
ANY]
--IOCreator-- =
BEGIN
ioAsAny ← 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:
PROCEDURE [thisCell: Cell, to: ExpansionReceiver]
--ExpandProc-- =
BEGIN
RoseReadSim.ReadSim[to: to, within: thisCell, fileName: "Passarb.sim", smallNode: 0.02, bigNode: 0.3];
END;
TestArbiter:
PROC [handle: CellTestHandle, testeeType: CellType, testData, io, driveAsAny, stateAsAny:
REF
ANY]
--CellTestProc-- =
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:
PROCEDURE [thisCell: Cell, to: ExpansionReceiver]
--ExpandProc-- =
BEGIN
PhA: Node ← to.class.NodeInstance[to.instance, "PHASEA", SwitchTypes.bitType, NIL, NIL, SwitchTypes.refInput];
PhB: Node ← to.class.NodeInstance[to.instance, "PHASEB", SwitchTypes.bitType, NIL, NIL, SwitchTypes.refInput];
Requests, Grants: ARRAY ClientIndex OF Node;
NewRqBar: Node ← to.class.NodeInstance[to.instance, "NEWRQ'", SwitchTypes.bitType, "L", NIL, SwitchTypes.refInput];
FOR client: ClientIndex
IN ClientIndex
DO
Requests[client] ← to.class.NodeInstance[to.instance, IO.PutFR["RQ%02g'", IO.card[client]], SwitchTypes.bitType, "H", NIL, SwitchTypes.refInput];
Grants[client] ← to.class.NodeInstance[to.instance, IO.PutFR["GP%02g'", IO.card[client]], SwitchTypes.bitType, "H"];
ENDLOOP;
[] ← to.class.CellInstance[to.instance, "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;
[] ← RegisterCellType[
name: "Arbiter",
ioCreator: CreateArbIO,
expandProc: ExpandArb,
initializer: InitializeArb,
evals: [--Other: ArbOther--],
tests: LIST[ ["Test", TestArbiter, FALSE] ],
ports: arbPorts];
[] ← RegisterCellType[
name: "ArbTest",
expandProc: ExpandArbTest,
evals: [],
ports: NEW [PortsRep[0]]];
END;
Setup[];
END.