@cascode/cascode-js 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +98 -0
  2. package/binding.gyp +26 -0
  3. package/lib/std/Bundles.cas +6 -0
  4. package/lib/std/InverterLike.cas +11 -0
  5. package/lib/std/amp/Common.cas +16 -0
  6. package/lib/std/amp/FullyDifferentialOpAmp.cas +61 -0
  7. package/lib/std/amp/SingleEndedAmp.cas +48 -0
  8. package/lib/std/amp/SingleEndedOpAmp.cas +48 -0
  9. package/lib/std/bench/DCBiasBenches.cas +41 -0
  10. package/lib/std/bench/NoiseBenches.cas +167 -0
  11. package/lib/std/bench/PowerBenches.cas +202 -0
  12. package/lib/std/bench/TranBenches.cas +164 -0
  13. package/lib/std/bench/TransferBenches.cas +329 -0
  14. package/lib/std/composites/PadDriver.cas +10 -0
  15. package/lib/std/prim/Devices.cas +20 -0
  16. package/lib/std/prim/Passives.cas +23 -0
  17. package/lib/std/refs/ConstantGm.cas +25 -0
  18. package/lib/std/refs/CurrentReference.cas +7 -0
  19. package/lib/std/refs/ReferenceCircuit.cas +6 -0
  20. package/lib/std/refs/VoltageReference.cas +7 -0
  21. package/native/cascode_native_addon.c +788 -0
  22. package/native/osx-arm64/Cascode.Native.dylib +0 -0
  23. package/native/osx-arm64/google-ortools-native.dylib +0 -0
  24. package/native/osx-arm64/libortools.9.dylib +0 -0
  25. package/package.json +48 -0
  26. package/platform-packages/cascode-js-darwin-arm64/README.md +4 -0
  27. package/platform-packages/cascode-js-darwin-arm64/index.js +10 -0
  28. package/platform-packages/cascode-js-darwin-arm64/package.json +28 -0
  29. package/platform-packages/cascode-js-darwin-x64/README.md +4 -0
  30. package/platform-packages/cascode-js-darwin-x64/index.js +10 -0
  31. package/platform-packages/cascode-js-darwin-x64/package.json +28 -0
  32. package/platform-packages/cascode-js-linux-x64/README.md +4 -0
  33. package/platform-packages/cascode-js-linux-x64/index.js +10 -0
  34. package/platform-packages/cascode-js-linux-x64/package.json +28 -0
  35. package/platform-packages/cascode-js-win32-x64/README.md +4 -0
  36. package/platform-packages/cascode-js-win32-x64/index.js +10 -0
  37. package/platform-packages/cascode-js-win32-x64/package.json +28 -0
  38. package/scripts/stage-platform-package.mjs +128 -0
  39. package/scripts/sync-stdlib.mjs +35 -0
  40. package/src/index.d.ts +38 -0
  41. package/src/index.js +453 -0
package/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # @cascode/native
2
+
3
+ Synchronous Node binding for the Cascode native C ABI.
4
+
5
+ This package exposes a thin N-API wrapper around the `cascode_*` exports from
6
+ `Cascode.Native` and intentionally does not add threading or async behavior.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ npm install @cascode/native
12
+ ```
13
+
14
+ ## Runtime Requirements
15
+
16
+ `@cascode/native` needs two native layers:
17
+
18
+ 1. Node addon (`cascode_native_addon.node`)
19
+ 2. Cascode shared library (`Cascode.Native.*`) plus runtime dependencies
20
+
21
+ At runtime, `@cascode/native` resolves in this order:
22
+
23
+ 1. Platform package (optional dependency), for example:
24
+ - `@cascode/native-win32-x64`
25
+ - `@cascode/native-linux-x64`
26
+ - `@cascode/native-darwin-x64`
27
+ - `@cascode/native-darwin-arm64`
28
+ 2. Local development build (`editors/node/build/Release`)
29
+ 3. Local native runtime discovery:
30
+ - `editors/node/native/<rid>/`
31
+ - `<repo>/build/native/<rid>/`
32
+
33
+ `CASCODE_NATIVE_LIB` always overrides discovered shared-library paths.
34
+
35
+ RID examples: `win-x64`, `linux-x64`, `darwin-x64`, `darwin-arm64`.
36
+
37
+ ## Local Co-Development With Designer
38
+
39
+ For active development across repos, point Designer at your local module path
40
+ instead of waiting for a release:
41
+
42
+ ```powershell
43
+ $env:DESIGNER_CASCODE_NATIVE_MODULE="C:\Projects\Repositories\cascode\editors\node"
44
+ ```
45
+
46
+ Then in `cascode/editors/node`:
47
+
48
+ ```powershell
49
+ npm ci --omit=optional
50
+ npm run build
51
+ ```
52
+
53
+ And publish local native runtime once:
54
+
55
+ ```powershell
56
+ dotnet publish tools/native/Cascode.Native/Cascode.Native.csproj `
57
+ --configuration Release `
58
+ -r win-x64 `
59
+ -p:PublishAot=true `
60
+ -o build/native/win-x64
61
+ ```
62
+
63
+ ## Build
64
+
65
+ ```bash
66
+ npm ci
67
+ npm run build
68
+ ```
69
+
70
+ ## Test
71
+
72
+ Publish a native library first, then run tests:
73
+
74
+ ```bash
75
+ dotnet publish tools/native/Cascode.Native/Cascode.Native.csproj \
76
+ --configuration Release \
77
+ -r linux-x64 \
78
+ -p:PublishAot=true \
79
+ -o build/native/linux-x64
80
+
81
+ export CASCODE_NATIVE_LIB="$PWD/build/native/linux-x64/Cascode.Native.so"
82
+ cd editors/node
83
+ npm test
84
+ ```
85
+
86
+ Windows equivalent:
87
+
88
+ ```powershell
89
+ dotnet publish tools/native/Cascode.Native/Cascode.Native.csproj `
90
+ --configuration Release `
91
+ -r win-x64 `
92
+ -p:PublishAot=true `
93
+ -o build/native/win-x64
94
+
95
+ $env:CASCODE_NATIVE_LIB="$PWD\\build\\native\\win-x64\\Cascode.Native.dll"
96
+ cd editors\node
97
+ npm test
98
+ ```
package/binding.gyp ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "targets": [
3
+ {
4
+ "target_name": "cascode_native_addon",
5
+ "sources": [
6
+ "native/cascode_native_addon.c"
7
+ ],
8
+ "cflags": [
9
+ "-std=c11"
10
+ ],
11
+ "xcode_settings": {
12
+ "CLANG_CXX_LANGUAGE_STANDARD": "c++17"
13
+ },
14
+ "conditions": [
15
+ [
16
+ "OS==\"linux\" or OS==\"mac\"",
17
+ {
18
+ "libraries": [
19
+ "-ldl"
20
+ ]
21
+ }
22
+ ]
23
+ ]
24
+ }
25
+ ]
26
+ }
@@ -0,0 +1,6 @@
1
+ library lib.std
2
+
3
+ bundle Diff {
4
+ P : analog
5
+ N : analog
6
+ }
@@ -0,0 +1,11 @@
1
+ library lib.std;
2
+
3
+ interface InverterLike {
4
+ port in IN : digital;
5
+ port out OUT : digital;
6
+ supply VDD; ground GND;
7
+
8
+ // Typical guarantees; library char{ } refines and verifies these bounds
9
+ ens voh(OUT) >= 0.9*VDD;
10
+ ens vol(OUT) <= 0.1*VDD;
11
+ }
@@ -0,0 +1,16 @@
1
+ library lib.std.amp
2
+
3
+ interface CurrentMirrorLike {
4
+ input SENSE : analog
5
+ output TAP[0] : analog
6
+ connectors {
7
+ to DiffPairLike {
8
+ SENSE--OUT.N
9
+ TAP[0]--OUT.P
10
+ }
11
+ }
12
+ }
13
+
14
+ interface DiffPairLike {
15
+ output OUT : Diff
16
+ }
@@ -0,0 +1,61 @@
1
+ library lib.std.amp
2
+ include lib.std.bench
3
+
4
+ // Interface: Fully-differential operational amplifier.
5
+ //
6
+ // Binds the standard library benches for common fully-differential amplifier metrics.
7
+ interface FullyDifferentialOpAmp {
8
+ supply VDD
9
+ ground GND
10
+ input IN : Diff
11
+ output OUT : Diff
12
+ input VTAIL : bias
13
+
14
+ benches {
15
+ bind QuiescentPower as vdd_pwr {
16
+ bench.PWR--dut.VDD
17
+ bench.RET--dut.GND
18
+ }
19
+
20
+ bind DiffDCBias as dc_bias {
21
+ bench.OUT--dut.OUT
22
+ }
23
+
24
+ bind DiffToDiffTransfer as transfer_bench {
25
+ bench.IN--dut.IN
26
+ bench.OUT--dut.OUT
27
+ }
28
+
29
+ bind DiffToDiffNoise as noise_bench {
30
+ bench.IN--dut.IN
31
+ bench.OUT--dut.OUT
32
+ }
33
+
34
+ bind DiffToDiffTran as tran_bench {
35
+ bench.IN--dut.IN
36
+ bench.OUT--dut.OUT
37
+ }
38
+
39
+ bind DiffCMRejection as cmrr_bench {
40
+ bench.CM--dut.IN.P
41
+ bench.CM--dut.IN.N
42
+ bench.OUT--dut.OUT
43
+
44
+ // Binding exports are adapters (not overrides): this exports a no-arg `CMRR` by forwarding to
45
+ // the underlying bench's `CMRR(dmGain=...)` with a default dmGain source.
46
+ measurements {
47
+ measurement CMRR : dB = base::CMRR(dmGain=transfer_bench::PassbandGain)
48
+ }
49
+ }
50
+
51
+ bind SupplyToDiffRejection as psrr_bench {
52
+ bench.IN--dut.IN
53
+ bench.PWR--dut.VDD
54
+ bench.OUT--dut.OUT
55
+
56
+ measurements {
57
+ measurement InputReferredPSRR : dB = base::InputReferredPSRR(dmGain=transfer_bench::PassbandGain)
58
+ }
59
+ }
60
+ }
61
+ }
@@ -0,0 +1,48 @@
1
+ library lib.std.amp
2
+ include lib.std.bench
3
+
4
+ // Interface: Single-ended amplifier (single-ended input, single-ended output).
5
+ //
6
+ // Provides ports and standard bench bindings for common small-signal and time-domain metrics.
7
+ interface SingleEndedAmp {
8
+ supply VDD
9
+ ground GND
10
+ input IN : analog
11
+ output OUT : analog
12
+
13
+ benches {
14
+ bind QuiescentPower as vdd_pwr {
15
+ bench.PWR--dut.VDD
16
+ bench.RET--dut.GND
17
+ }
18
+
19
+ bind SEDCBias as dc_bias {
20
+ bench.OUT--dut.OUT
21
+ }
22
+
23
+ bind SEToSETransfer as transfer_bench {
24
+ bench.IN--dut.IN
25
+ bench.OUT--dut.OUT
26
+ }
27
+
28
+ bind SEToSENoise as noise_bench {
29
+ bench.IN--dut.IN
30
+ bench.OUT--dut.OUT
31
+ }
32
+
33
+ bind SEToSETran as tran_bench {
34
+ bench.IN--dut.IN
35
+ bench.OUT--dut.OUT
36
+ }
37
+
38
+ bind SupplyToSERejectionSEInput as psrr_bench {
39
+ bench.IN--dut.IN
40
+ bench.PWR--dut.VDD
41
+ bench.OUT--dut.OUT
42
+
43
+ measurements {
44
+ measurement InputReferredPSRR : dB = base::InputReferredPSRR(dmGain=transfer_bench::PassbandGain)
45
+ }
46
+ }
47
+ }
48
+ }
@@ -0,0 +1,48 @@
1
+ library lib.std.amp
2
+ include lib.std.bench
3
+
4
+ // Interface: Single-ended operational amplifier (differential input, single-ended output).
5
+ // Provides ports and bench metric mappings for Amplifier metrics.
6
+
7
+ interface SingleEndedOpAmp {
8
+ supply VDD
9
+ ground GND
10
+ input IN : Diff
11
+ output OUT : analog
12
+
13
+ benches {
14
+ bind QuiescentPower as vdd_pwr {
15
+ bench.PWR--dut.VDD
16
+ bench.RET--dut.GND
17
+ }
18
+
19
+ bind SEDCBias as dc_bias {
20
+ bench.OUT--dut.OUT
21
+ }
22
+
23
+ bind DiffToSETransfer as transfer_bench {
24
+ bench.IN--dut.IN
25
+ bench.OUT--dut.OUT
26
+ }
27
+
28
+ bind DiffToSENoise as noise_bench {
29
+ bench.IN--dut.IN
30
+ bench.OUT--dut.OUT
31
+ }
32
+
33
+ bind DiffToSETran as tran_bench {
34
+ bench.IN--dut.IN
35
+ bench.OUT--dut.OUT
36
+ }
37
+
38
+ bind SupplyToSERejection as psrr_bench {
39
+ bench.IN--dut.IN
40
+ bench.PWR--dut.VDD
41
+ bench.OUT--dut.OUT
42
+
43
+ measurements {
44
+ measurement InputReferredPSRR : dB = base::InputReferredPSRR(dmGain=transfer_bench::PassbandGain)
45
+ }
46
+ }
47
+ }
48
+ }
@@ -0,0 +1,41 @@
1
+ VERSION 3.1
2
+
3
+ library lib.std.bench
4
+
5
+ abstract bench AbstractDCBias {
6
+ abstract resp OUT
7
+
8
+ analysis {
9
+ DCAnalysis dc = new DCAnalysis()
10
+ }
11
+
12
+ measurements {
13
+ measurement OutputDCCommonMode : V {
14
+ return voltage(dc, OUT)
15
+ }
16
+ }
17
+ }
18
+
19
+ bench SEDCBias extends AbstractDCBias {
20
+ resp OUT : analog
21
+
22
+ fill { }
23
+
24
+ measurements {
25
+ measurement OutputDCBias : V {
26
+ return voltage(dc, OUT)
27
+ }
28
+ }
29
+ }
30
+
31
+ bench DiffDCBias extends AbstractDCBias {
32
+ resp OUT : Diff
33
+
34
+ fill { }
35
+
36
+ measurements {
37
+ override measurement OutputDCCommonMode : V {
38
+ return (voltage(dc, OUT.P) + voltage(dc, OUT.N)) / 2
39
+ }
40
+ }
41
+ }
@@ -0,0 +1,167 @@
1
+ VERSION 3.1
2
+
3
+ library lib.std.bench
4
+
5
+ abstract bench AbstractNoise {
6
+ abstract stim IN
7
+ abstract resp OUT
8
+
9
+ analysis {
10
+ // ACAnalysis required for input_referred_noise to compute transfer function
11
+ ACAnalysis ac = new ACAnalysis(
12
+ space=Log,
13
+ samples=100,
14
+ start=(if constraints.HighpassBandwidth { constraints.HighpassBandwidth * 0.1 } else { 1Hz }),
15
+ stop=(if constraints.GainBandwidth { constraints.GainBandwidth * 10 } else { 10GHz }))
16
+
17
+ NoiseAnalysis noise_ac = new NoiseAnalysis(
18
+ space=Log,
19
+ samples=100,
20
+ start=(if constraints.HighpassBandwidth { constraints.HighpassBandwidth * 0.1 } else { 1Hz }),
21
+ stop=(if constraints.GainBandwidth { constraints.GainBandwidth * 10 } else { 10GHz }),
22
+ output=OUT)
23
+ }
24
+
25
+ measurements {
26
+ measurement InputReferredNoise : V/rtHz {
27
+ // input_referred_noise uses paired ACAnalysis to compute transfer function
28
+ NoiseSpectrum n_in = input_referred_noise(noise_ac, ac, IN, OUT)
29
+ Frequency f_spot = (if constraints.SpotNoiseFrequency { constraints.SpotNoiseFrequency } else { 1kHz })
30
+ return n_in.ValueAt(f_spot)
31
+ }
32
+
33
+ measurement IntegratedInputNoise(Frequency from, Frequency to) : Vrms {
34
+ NoiseSpectrum n_in = input_referred_noise(noise_ac, ac, IN, OUT)
35
+ return n_in.Integrate(from, to)
36
+ }
37
+
38
+ measurement OutputNoise : V/rtHz {
39
+ NoiseSpectrum n_out = noise(noise_ac, OUT)
40
+ Frequency f_spot = (if constraints.SpotNoiseFrequency { constraints.SpotNoiseFrequency } else { 1kHz })
41
+ return n_out.ValueAt(f_spot)
42
+ }
43
+ }
44
+ }
45
+
46
+ bench DiffToSENoise extends AbstractNoise {
47
+ stim IN : Diff
48
+ resp OUT : analog
49
+
50
+ fill {
51
+ net vcm : analog
52
+ net gnd : ground
53
+
54
+ GND _ = new GND() {
55
+ .GND--gnd
56
+ }
57
+
58
+ VDC commonModeVDC = new VDC(V=env.InputCommonModeRange) {
59
+ .P--vcm
60
+ .N--gnd
61
+ }
62
+
63
+ // Provide an AC-defined input source for ngspice noise analysis.
64
+ // The actual input-referred noise computation uses the paired ACAnalysis transfer function.
65
+ VAC acP = new VAC(A=0.5V, phase=0deg) {
66
+ .N--vcm
67
+ }
68
+ VAC acN = new VAC(A=0.5V, phase=180deg) {
69
+ .N--vcm
70
+ }
71
+
72
+ Impedor sourceP = new Impedor(Z=env.SourceImpedance.DiffToShunt()) { }
73
+ Impedor sourceN = new Impedor(Z=env.SourceImpedance.DiffToShunt()) { }
74
+
75
+ acP.P--sourceP.P
76
+ sourceP.N--IN.P
77
+
78
+ acN.P--sourceN.P
79
+ sourceN.N--IN.N
80
+
81
+ Impedor loadZ = new Impedor(Z=env.LoadImpedance) {
82
+ .P--OUT
83
+ .N--gnd
84
+ }
85
+ }
86
+ }
87
+
88
+ bench DiffToDiffNoise extends AbstractNoise {
89
+ stim IN : Diff
90
+ resp OUT : Diff
91
+
92
+ fill {
93
+ net vcm : analog
94
+ net gnd : ground
95
+
96
+ GND _ = new GND() {
97
+ .GND--gnd
98
+ }
99
+
100
+ VDC commonModeVDC = new VDC(V=env.InputCommonModeRange) {
101
+ .P--vcm
102
+ .N--gnd
103
+ }
104
+
105
+ // Provide an AC-defined input source for ngspice noise analysis.
106
+ // The actual input-referred noise computation uses the paired ACAnalysis transfer function.
107
+ VAC acP = new VAC(A=0.5V, phase=0deg) {
108
+ .N--vcm
109
+ }
110
+ VAC acN = new VAC(A=0.5V, phase=180deg) {
111
+ .N--vcm
112
+ }
113
+
114
+ Impedor sourceP = new Impedor(Z=env.SourceImpedance.DiffToShunt()) { }
115
+ Impedor sourceN = new Impedor(Z=env.SourceImpedance.DiffToShunt()) { }
116
+
117
+ acP.P--sourceP.P
118
+ sourceP.N--IN.P
119
+
120
+ acN.P--sourceN.P
121
+ sourceN.N--IN.N
122
+
123
+ // Differential target load. Diff benches split this to per-side shunts via DiffToShunt().
124
+ Impedor loadP = new Impedor(Z=env.LoadImpedance.DiffToShunt()) {
125
+ .P--OUT.P
126
+ .N--gnd
127
+ }
128
+ Impedor loadN = new Impedor(Z=env.LoadImpedance.DiffToShunt()) {
129
+ .P--OUT.N
130
+ .N--gnd
131
+ }
132
+ }
133
+ }
134
+
135
+ bench SEToSENoise extends AbstractNoise {
136
+ stim IN : analog
137
+ resp OUT : analog
138
+
139
+ fill {
140
+ net vcm : analog
141
+ net gnd : ground
142
+
143
+ GND _ = new GND() {
144
+ .GND--gnd
145
+ }
146
+
147
+ VDC biasDC = new VDC(V=env.InputCommonModeRange) {
148
+ .P--vcm
149
+ .N--gnd
150
+ }
151
+
152
+ // Provide an AC-defined input source for ngspice noise analysis.
153
+ // The actual input-referred noise computation uses the paired ACAnalysis transfer function.
154
+ VAC ac = new VAC(A=1V, phase=0deg) {
155
+ .N--vcm
156
+ }
157
+
158
+ Impedor sourceZ = new Impedor(Z=env.SourceImpedance) { }
159
+ ac.P--sourceZ.P
160
+ sourceZ.N--IN
161
+
162
+ Impedor loadZ = new Impedor(Z=env.LoadImpedance) {
163
+ .P--OUT
164
+ .N--gnd
165
+ }
166
+ }
167
+ }