-
Notifications
You must be signed in to change notification settings - Fork 5
/
fork-ctrl.js
47 lines (35 loc) · 1.19 KB
/
fork-ctrl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict';
const express = require('./express.js');
const forkCtrl = p => {
let res = [];
res = res.concat((p.targets.length > 1) ?
'reg ' + p.targets.map((e, ei) => `ack${p.id}_${ei}_r`).join(', ') :
[]
);
res = res.concat((p.targets.length > 1) ?
'wire ' + p.targets.map((e, ei) => `ack${p.id}_${ei}_s`).join(', ') :
[]
);
res = res.concat((p.targets.length > 1) ?
p.targets.map((e, ei) =>
`assign req${p.id}_${ei} = req${p.id}m & ~ack${p.id}_${ei}_r`) :
[`assign req${p.id}_0 = req${p.id}m`]
);
res = res.concat((p.targets.length > 1) ?
p.targets.map((e, ei) =>
`assign ack${p.id}_${ei}_s = ack${p.id}_${ei} | ~req${p.id}_${ei}`) :
[]
);
const ackm = (p.targets.length > 1) ?
p.targets.map((e, ei) => `ack${p.id}_${ei}_s`).join(' & ') :
`ack${p.id}_0`;
res = res.concat(`assign ack${p.id}m = ${ackm}`);
res = res.concat((p.targets.length > 1) ?
p.targets.map((e, ei) =>
`always @(posedge clk or negedge reset_n) if (~reset_n) ack${p.id}_${ei}_r <= 1'b0; else ack${p.id}_${ei}_r <= ack${p.id}_${ei}_s & ~ack${p.id}m`) :
[]
);
return `// edge:${p.id} fork
${express(res)}`;
};
module.exports = forkCtrl;