CounterUp:
PUBLIC
PROC [b:
NAT]
RETURNS [ct: CellType] = {
ctCell: CellType ← LogicUtils.Extract["counterUp1B.sch", TRUE];
ctCtrl: CellType;
insts: CellInstances;
input, output, nOutput, carry, cout: Wire;
IF b=0 THEN LogicUtils.Error["Please provide the number of bits for the up counter"];
IF b=1 THEN LogicUtils.Error["Sorry, but a counter must have more than one bit"];
Sisyph.Store[LogicUtils.cx, "publicD", NEW[NAT←IF b<4 THEN 1 ELSE b/4]];
ctCtrl ← LogicUtils.Extract["counterUp1BCtrl.sch"];
insts ← LIST[Instance[ctCtrl]];
input ← Seq["Input", b];
output ← Seq["Output", b];
nOutput ← Seq["nOutput", b];
carry ← Seq["carry", b];
cout ← CoreOps.SetShortWireName[carry[0], "Cout"];
FOR i:
NAT
IN [0..b)
DO
insts ←
CONS[
Instance[ctCell,
["Q", output[i]],
["nQ", nOutput[i]],
["input", input[i]],
["carryIn", IF i=b-1 THEN "Cin" ELSE carry[i+1]],
["carryOut", carry[i]],
["load", "load"], ["count", "count"], ["en", "en"], ["nEn", "nEn"], ["CK", "CK"]],
insts];
ENDLOOP;
ct ← Cell[
name: CounterUpName,
public: Wires["Vdd", "Gnd", "CK", "Load", "Count", "Cin", cout, input, output, nOutput],
onlyInternal: Wires["load", "count", "en", "nEn", carry ],
instances: insts];
};
TestCounterUp: PROC [b: NAT] RETURNS [ct: CellType] = {
ctCell: CellType ← LogicUtils.SCBlock[LogicUtils.Extract["counterUp1B.sch", TRUE]];
ctCtrl: CellType;
insts: CellInstances;
input, output, nOutput, carry, cout: Wire;
IF b=0 THEN LogicUtils.Error["Please provide the number of bits for the up counter"];
IF b=1 THEN LogicUtils.Error["Sorry, but a counter must have more than one bit"];
Sisyph.Store[LogicUtils.cx, "publicD", NEW[NAT←IF b<4 THEN 1 ELSE b/4]];
ctCtrl ← LogicUtils.Extract["counterUp1BCtrl.sch"];
insts ← LIST[Instance[ctCtrl]];
input ← Seq["Input", b];
output ← Seq["Output", b];
nOutput ← Seq["nOutput", b];
carry ← Seq["carry", b];
cout ← CoreOps.SetShortWireName[carry[0], "Cout"];
FOR i: NAT IN [0..b) DO
insts ← CONS[
Instance[ctCell,
["Q", output[i]],
["nQ", nOutput[i]],
["input", input[i]],
["carryIn", IF i=b-1 THEN "Cin" ELSE carry[i+1]],
["carryOut", carry[i]],
["load", "load"], ["count", "count"], ["freeze", "freeze"], ["CK", "CK"]],
insts];
ENDLOOP;
ct ← Cell[
name: CounterUpName,
public: Wires["Vdd", "Gnd", "CK", "Load", "Count", "Cin", cout, input, output, nOutput],
onlyInternal: Wires["load", "count", "freeze", carry ],
instances: insts];
};