@mica-js/simulator 0.3.0 → 1.0.0
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.
- package/README.md +10 -2
- package/dist/index.d.ts +226 -158
- package/dist/index.js +2364 -705
- package/dist/index.js.map +1 -1
- package/dist/sandbox.d.ts +6 -0
- package/dist/sandbox.js +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { CanvasBindingTarget } from '@mica-js/core/canvas';
|
|
|
4
4
|
import { DeviceReference } from '@mica-js/core/schematic';
|
|
5
5
|
import { DeviceSymbolProvider } from '@mica-js/core/schematic';
|
|
6
6
|
import { Disposable } from '@mica-js/core/lifecycle';
|
|
7
|
+
import { EntryRef } from '@mica-js/ir';
|
|
7
8
|
import { Event as Event_2 } from '@mica-js/core/lifecycle';
|
|
8
9
|
import { FunctionBuilder } from '@mica-js/ir';
|
|
9
10
|
import { FunctionRef } from '@mica-js/ir';
|
|
@@ -12,9 +13,12 @@ import { IRJITTuning } from '@mica-js/ir';
|
|
|
12
13
|
import { IRModule } from '@mica-js/ir';
|
|
13
14
|
import { IRValidationOptions } from '@mica-js/ir';
|
|
14
15
|
import { PayloadType } from '@mica-js/core/canvas';
|
|
16
|
+
import { PropertyValue } from '@mica-js/core/schematic';
|
|
15
17
|
import { RpcEndpoint } from '@mica-js/core/rpc';
|
|
18
|
+
import { RuntimeScalar } from '@mica-js/ir';
|
|
16
19
|
import { ScalarType } from '@mica-js/ir';
|
|
17
20
|
import { SchematicDocument } from '@mica-js/core/schematic';
|
|
21
|
+
import { StateRef } from '@mica-js/ir';
|
|
18
22
|
import { Value } from '@mica-js/ir';
|
|
19
23
|
|
|
20
24
|
/**
|
|
@@ -36,7 +40,6 @@ import { Value } from '@mica-js/ir';
|
|
|
36
40
|
* expect(circuit.tickCount).toBe(1_000_000n);
|
|
37
41
|
*
|
|
38
42
|
* circuit.reset();
|
|
39
|
-
* circuit.setPin('drive1.PA0', true); // host drives the pin
|
|
40
43
|
* circuit.step();
|
|
41
44
|
* expect(circuit.devices.sink1.getState('lamp')).toBe(true);
|
|
42
45
|
* ```
|
|
@@ -64,18 +67,18 @@ export declare class Circuit<I extends CircuitCompilationInput = CircuitCompilat
|
|
|
64
67
|
/**
|
|
65
68
|
* Runs `count` ticks inside one generated loop — the throughput path.
|
|
66
69
|
*
|
|
67
|
-
* The whole batch is one engine call
|
|
68
|
-
*
|
|
70
|
+
* The whole batch is one engine call. The clock advances by completed ticks,
|
|
71
|
+
* including the completed prefix of a failed batch.
|
|
69
72
|
*
|
|
70
73
|
* @throws {CircuitError} with code `invalid-count` unless `count` is a u32.
|
|
71
74
|
*/
|
|
72
|
-
runBatch(count: number): void;
|
|
75
|
+
runBatch(count: number, dt?: number): void;
|
|
73
76
|
/**
|
|
74
77
|
* Advances exactly one tick — the debugging path.
|
|
75
78
|
*
|
|
76
79
|
* Every call is one engine entry, so prefer `runBatch` for throughput.
|
|
77
80
|
*/
|
|
78
|
-
step(): void;
|
|
81
|
+
step(dt?: number): void;
|
|
79
82
|
/**
|
|
80
83
|
* Restores every memory to its declared initial value, re-runs `initialize`
|
|
81
84
|
* and resets `tickCount` to `0n`.
|
|
@@ -87,23 +90,18 @@ export declare class Circuit<I extends CircuitCompilationInput = CircuitCompilat
|
|
|
87
90
|
/**
|
|
88
91
|
* Reads the level one pin observes.
|
|
89
92
|
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* `false` unless it is configured push-pull.
|
|
93
|
+
* Requires an explicitly initialized digital input capability and applies
|
|
94
|
+
* the circuit interpretation to the solved physical voltage.
|
|
93
95
|
*
|
|
94
96
|
* @throws {CircuitError} with code `pin-not-found`.
|
|
95
97
|
*/
|
|
96
98
|
getPin(pinName: string): boolean;
|
|
97
|
-
/**
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
*
|
|
104
|
-
* @throws {CircuitError} with code `pin-not-found`.
|
|
105
|
-
*/
|
|
106
|
-
setPin(pinName: string, value: boolean): void;
|
|
99
|
+
/** Physical pin voltage; floating results never contain a synthetic voltage. */
|
|
100
|
+
getVoltage(pinName: string): ElectricalReading;
|
|
101
|
+
/** Resistor/contact currents follow endpoint order; source and pin contributions flow outward. */
|
|
102
|
+
getCurrent(resource: string | ElectricalCurrentTarget): ElectricalReading;
|
|
103
|
+
/** Pull-based active diagnostics: one warning per resource; successful recovery removes it. */
|
|
104
|
+
getDiagnostics(): readonly ElectricalDiagnostic[];
|
|
107
105
|
/** Number of ticks completed since creation or the last `reset()`. */
|
|
108
106
|
get tickCount(): bigint;
|
|
109
107
|
/** Virtual tick time completed since creation or the last `reset()`. */
|
|
@@ -127,13 +125,13 @@ export declare interface CircuitCompilationInput {
|
|
|
127
125
|
|
|
128
126
|
/** Options for the compiler. */
|
|
129
127
|
export declare interface CircuitCompilationOptions {
|
|
130
|
-
/**
|
|
131
|
-
readonly
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
readonly
|
|
128
|
+
/** Explicit GND-referenced voltage sources; GND itself is always 0 V. */
|
|
129
|
+
readonly sources?: Readonly<Record<string, {
|
|
130
|
+
readonly voltage: number;
|
|
131
|
+
}>>;
|
|
132
|
+
readonly interpretation?: 'two-state' | 'retain-in-band';
|
|
133
|
+
/** Reproducible mica-floating-v2 input seed; defaults to 0. */
|
|
134
|
+
readonly floatingSeed?: number;
|
|
137
135
|
/** Runs `validateIR` over the generated module. Defaults to `true`. */
|
|
138
136
|
readonly validate?: boolean;
|
|
139
137
|
/** Overrides for the generated entry-point names. */
|
|
@@ -161,23 +159,11 @@ export declare interface CircuitDeviceSimulationHostOptions {
|
|
|
161
159
|
|
|
162
160
|
/** Electrical-solve options forwarded to `compileCircuit`. */
|
|
163
161
|
export declare interface CircuitElectricalOptions {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
*/
|
|
168
|
-
readonly allowMultiDriver?: boolean;
|
|
169
|
-
/** Named fixed-level rails; merged over `GND`/`VCC`/`VDD`. */
|
|
170
|
-
readonly rails?: Readonly<Record<string, boolean>>;
|
|
162
|
+
readonly sources?: CircuitCompilationOptions['sources'];
|
|
163
|
+
readonly interpretation?: CircuitCompilationOptions['interpretation'];
|
|
164
|
+
readonly floatingSeed?: CircuitCompilationOptions['floatingSeed'];
|
|
171
165
|
}
|
|
172
166
|
|
|
173
|
-
/**
|
|
174
|
-
* Types of the unified circuit runtime (U02).
|
|
175
|
-
*
|
|
176
|
-
* `Circuit` is the host-facing facade over one compiled unified IR module: it
|
|
177
|
-
* owns the engine instance, exposes typed per-device accessors and keeps the
|
|
178
|
-
* tick counter. Everything here is transport-neutral; no type mentions the
|
|
179
|
-
* scheduler, the device host or the schematic editor.
|
|
180
|
-
*/
|
|
181
167
|
/** Execution engine a `Circuit` runs on. */
|
|
182
168
|
export declare type CircuitEngine = 'jit' | 'reference';
|
|
183
169
|
|
|
@@ -197,7 +183,7 @@ export declare class CircuitError extends Error {
|
|
|
197
183
|
}
|
|
198
184
|
|
|
199
185
|
/** Error codes raised by `CircuitError`. */
|
|
200
|
-
export declare type CircuitErrorCode = 'invalid-options' | 'invalid-count' | '
|
|
186
|
+
export declare type CircuitErrorCode = 'invalid-options' | 'invalid-count' | 'unsupported-operation' | 'resource-not-found' | 'pin-not-found' | 'state-not-found' | 'invalid-state-value' | 'unresolved-device' | 'disposed';
|
|
201
187
|
|
|
202
188
|
export declare interface CircuitErrorOptions {
|
|
203
189
|
readonly deviceId?: string;
|
|
@@ -228,20 +214,6 @@ export declare interface CircuitRuntimeOptions {
|
|
|
228
214
|
readonly instanceId?: string;
|
|
229
215
|
}
|
|
230
216
|
|
|
231
|
-
/** One electrical-analysis finding; errors abort `compileCircuit`. */
|
|
232
|
-
export declare interface CompilationDiagnostic {
|
|
233
|
-
readonly code: CompilationDiagnosticCode;
|
|
234
|
-
readonly severity: CompilationDiagnosticSeverity;
|
|
235
|
-
readonly message: string;
|
|
236
|
-
readonly netId: number | undefined;
|
|
237
|
-
readonly endpoints: readonly string[];
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/** Diagnostic codes produced by the compiler's electrical analysis. */
|
|
241
|
-
export declare type CompilationDiagnosticCode = 'driver-conflict' | 'power-short' | 'rail-conflict' | 'floating-net';
|
|
242
|
-
|
|
243
|
-
declare type CompilationDiagnosticSeverity = 'error' | 'warning';
|
|
244
|
-
|
|
245
217
|
/**
|
|
246
218
|
* Compiles several devices and their wiring into one unified IR module (U01).
|
|
247
219
|
*
|
|
@@ -267,7 +239,7 @@ declare type CompilationDiagnosticSeverity = 'error' | 'warning';
|
|
|
267
239
|
*
|
|
268
240
|
* The pipeline is: validate the input, allocate the global pin and state
|
|
269
241
|
* spaces, analyse the electrical topology, generate one function per device
|
|
270
|
-
* phase, generate
|
|
242
|
+
* phase, generate the resistive network solver and main loop, then validate the
|
|
271
243
|
* resulting module with `validateIR`.
|
|
272
244
|
*
|
|
273
245
|
* @throws {UnifiedIRCompilerError} for malformed input, duplicate ids, unknown
|
|
@@ -279,28 +251,21 @@ export declare function compileCircuit(input: CircuitCompilationInput, options?:
|
|
|
279
251
|
export declare interface CompiledCircuit {
|
|
280
252
|
readonly module: IRModule;
|
|
281
253
|
readonly entryPoints: CompiledEntryPoints;
|
|
254
|
+
/** Completed ticks in the most recent step/batch, including before a fault. */
|
|
255
|
+
readonly progress: StateRef<'u32'>;
|
|
282
256
|
/** `'mcu1.PA0'` -> global pin id. */
|
|
283
257
|
readonly pinMap: ReadonlyMap<string, number>;
|
|
284
258
|
readonly deviceMap: ReadonlyMap<string, DeviceMetadata>;
|
|
285
|
-
readonly netlist: CompiledNetlist;
|
|
286
259
|
readonly pins: GlobalPinMap;
|
|
287
260
|
readonly states: GlobalStateMap;
|
|
288
|
-
readonly memory: CompiledCircuitMemory;
|
|
289
261
|
/** Validation grants covering every instruction and memory of the module. */
|
|
290
262
|
readonly validation: IRValidationOptions;
|
|
291
|
-
/** Device ids in
|
|
263
|
+
/** Device ids in stable declaration order. */
|
|
292
264
|
readonly executionOrder: readonly string[];
|
|
293
265
|
/** Every generated function name, in definition order. */
|
|
294
266
|
readonly functions: readonly string[];
|
|
295
267
|
}
|
|
296
268
|
|
|
297
|
-
/** Pin memories every device and every net solver shares. */
|
|
298
|
-
declare interface CompiledCircuitMemory {
|
|
299
|
-
readonly mode: ArrayRef<'u8'>;
|
|
300
|
-
readonly output: ArrayRef<'bool'>;
|
|
301
|
-
readonly input: ArrayRef<'bool'>;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
269
|
/** Generated entry points, both by name and as executable refs. */
|
|
305
270
|
declare interface CompiledEntryPoints {
|
|
306
271
|
readonly tick: string;
|
|
@@ -313,50 +278,6 @@ declare interface CompiledEntryPoints {
|
|
|
313
278
|
};
|
|
314
279
|
}
|
|
315
280
|
|
|
316
|
-
/** One electrical net: a connected component of pins and rails. */
|
|
317
|
-
declare interface CompiledNet {
|
|
318
|
-
readonly netId: number;
|
|
319
|
-
readonly pins: readonly CompiledPinConnection[];
|
|
320
|
-
readonly rails: readonly CompiledRail[];
|
|
321
|
-
readonly drivers: readonly CompiledPinConnection[];
|
|
322
|
-
/** Pins whose role is `load`. */
|
|
323
|
-
readonly loads: readonly CompiledPinConnection[];
|
|
324
|
-
/** Every pin that reads the solved level, including bidirectional drivers. */
|
|
325
|
-
readonly sinks: readonly CompiledPinConnection[];
|
|
326
|
-
readonly source: CompiledNetSource;
|
|
327
|
-
/** Constant level of a driver-less net; unused when `source === 'driver'`. */
|
|
328
|
-
readonly level: boolean;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
/** Result of the network topology analysis. */
|
|
332
|
-
declare interface CompiledNetlist {
|
|
333
|
-
readonly nets: readonly CompiledNet[];
|
|
334
|
-
readonly diagnostics: readonly CompilationDiagnostic[];
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/** Where a net's level comes from. */
|
|
338
|
-
declare type CompiledNetSource = 'driver' | 'rail' | 'floating';
|
|
339
|
-
|
|
340
|
-
/** One pin resolved onto a net. */
|
|
341
|
-
declare interface CompiledPinConnection {
|
|
342
|
-
/** `'mcu1.PA0'`. */
|
|
343
|
-
readonly endpoint: string;
|
|
344
|
-
readonly deviceId: string;
|
|
345
|
-
readonly pinName: string;
|
|
346
|
-
readonly globalPinId: number;
|
|
347
|
-
readonly role: CompiledPinRole;
|
|
348
|
-
readonly senses: boolean;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
/** Role a pin plays on its net; v1 supports one driver per net. */
|
|
352
|
-
declare type CompiledPinRole = 'driver' | 'load';
|
|
353
|
-
|
|
354
|
-
/** One fixed-level rail on a net, e.g. `GND` (low) or `VCC` (high). */
|
|
355
|
-
declare interface CompiledRail {
|
|
356
|
-
readonly name: string;
|
|
357
|
-
readonly level: boolean;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
281
|
/** One pin-to-pin (or pin-to-rail) connection. */
|
|
361
282
|
export declare interface Connection {
|
|
362
283
|
/** `'mcu1.PA0'` or a rail name such as `'GND'`. */
|
|
@@ -364,6 +285,10 @@ export declare interface Connection {
|
|
|
364
285
|
readonly to: string;
|
|
365
286
|
}
|
|
366
287
|
|
|
288
|
+
export declare interface ContactDeclaration extends ResistorDeclaration {
|
|
289
|
+
readonly initial: 'open' | 'closed';
|
|
290
|
+
}
|
|
291
|
+
|
|
367
292
|
/**
|
|
368
293
|
* Adapts one already-loaded unified-IR circuit to the RFC 0018 device host.
|
|
369
294
|
*
|
|
@@ -426,19 +351,16 @@ export declare function createSchematicCircuit(schematic: SchematicDocument, opt
|
|
|
426
351
|
*/
|
|
427
352
|
export declare function createSchematicDeviceSimulationHost(options: SchematicDeviceSimulationHostOptions): DeviceSimulationHost;
|
|
428
353
|
|
|
429
|
-
/**
|
|
430
|
-
export declare const
|
|
431
|
-
|
|
432
|
-
/** Global pin addresses reserved per device (one 32-pin port). */
|
|
433
|
-
export declare const DEVICE_PIN_STRIDE = 32;
|
|
354
|
+
/** Global pin addresses one device may own; enough for the largest packages. */
|
|
355
|
+
export declare const DEVICE_PIN_STRIDE = 512;
|
|
434
356
|
|
|
435
357
|
/**
|
|
436
358
|
* What every device accessor offers, whatever its type.
|
|
437
359
|
*
|
|
438
360
|
* `readPin` returns the level the *device* drives onto one of its pins (its
|
|
439
361
|
* output latch), while `Circuit.getPin('device.pin')` returns the level the pin
|
|
440
|
-
* *observes* after the electrical solve.
|
|
441
|
-
*
|
|
362
|
+
* *observes* after the electrical solve. Host changes use device state; there
|
|
363
|
+
* is no direct pin override API.
|
|
442
364
|
*/
|
|
443
365
|
export declare interface DeviceAccessor {
|
|
444
366
|
/** Circuit-unique device id. */
|
|
@@ -452,11 +374,14 @@ export declare interface DeviceAccessor {
|
|
|
452
374
|
/** Reads the level the device drives onto `pinName`. */
|
|
453
375
|
readPin(pinName: string): boolean;
|
|
454
376
|
/** Writes the level the device drives onto `pinName`. */
|
|
455
|
-
writePin(pinName: string, value: boolean): void;
|
|
456
377
|
/** Reads one declared internal state. */
|
|
457
378
|
getState(name: string): unknown;
|
|
458
379
|
/** Writes one declared internal state. */
|
|
459
380
|
setState(name: string, value: unknown): void;
|
|
381
|
+
/** Consumes inputs at a host step boundary, when declared by the paired factory. */
|
|
382
|
+
applyInputs?(inputs: readonly DeviceInput[]): void;
|
|
383
|
+
/** Publishes outputs after the host finishes evaluating the step. */
|
|
384
|
+
flushOutputs?(publish: (port: string, payload: unknown) => void): void;
|
|
460
385
|
}
|
|
461
386
|
|
|
462
387
|
/**
|
|
@@ -509,7 +434,6 @@ declare interface DeviceAccessorSurface {
|
|
|
509
434
|
readonly pinNames: readonly string[];
|
|
510
435
|
readonly stateNames: readonly string[];
|
|
511
436
|
readPin(pinName: string): boolean;
|
|
512
|
-
writePin(pinName: string, value: boolean): void;
|
|
513
437
|
getState(name: string): unknown;
|
|
514
438
|
setState(name: string, value: unknown): void;
|
|
515
439
|
}
|
|
@@ -524,15 +448,17 @@ export declare interface DeviceBehaviorApi {
|
|
|
524
448
|
* simple devices never need to touch it.
|
|
525
449
|
*/
|
|
526
450
|
readonly module: IRModule;
|
|
527
|
-
/** Shared `pin_mode` / `pin_output` / `pin_input` memories. */
|
|
528
|
-
readonly memory: CompiledCircuitMemory;
|
|
529
451
|
/** Instance configuration from {@link DeviceConfig.config}. */
|
|
530
452
|
readonly config: Readonly<Record<string, unknown>> | undefined;
|
|
531
453
|
/** Every declared pin of the device, in declaration order. */
|
|
532
454
|
readonly pins: readonly DevicePinHandle[];
|
|
533
|
-
/** Pins
|
|
455
|
+
/** Pins initialized with physical drive capability. */
|
|
534
456
|
readonly outputs: readonly DevicePinHandle[];
|
|
535
457
|
pin(name: string): DevicePinHandle;
|
|
458
|
+
resistor(name: string): DeviceResistorHandle;
|
|
459
|
+
writeDigitalGroup(names: readonly string[], levels: readonly Value<'bool'>[]): void;
|
|
460
|
+
applyResistors(names: readonly string[], ohms: readonly Value<'f64'>[]): void;
|
|
461
|
+
applyConnections(names: readonly string[], closed: readonly Value<'bool'>[]): void;
|
|
536
462
|
state<T extends ScalarType = ScalarType>(name: string): DeviceStateHandle<T>;
|
|
537
463
|
}
|
|
538
464
|
|
|
@@ -547,6 +473,11 @@ export declare interface DeviceBehaviors {
|
|
|
547
473
|
readonly update?: (api: DeviceBehaviorApi) => void;
|
|
548
474
|
}
|
|
549
475
|
|
|
476
|
+
export declare interface DeviceBridgeHooks {
|
|
477
|
+
readonly applyInputs?: (io: DeviceInputIo) => void;
|
|
478
|
+
readonly flushOutputs?: (io: DeviceOutputIo) => void;
|
|
479
|
+
}
|
|
480
|
+
|
|
550
481
|
/** One device instance of the circuit. */
|
|
551
482
|
export declare interface DeviceConfig {
|
|
552
483
|
/** Circuit-unique identity; prefix of every generated function name. */
|
|
@@ -554,14 +485,21 @@ export declare interface DeviceConfig {
|
|
|
554
485
|
/** Device type, e.g. `'push-pull-driver'`; free-form label of the device model. */
|
|
555
486
|
readonly type: string;
|
|
556
487
|
readonly description: DeviceDescription;
|
|
488
|
+
/** Persistent instance values resolved against the JSON property declarations. */
|
|
489
|
+
readonly properties?: Readonly<Record<string, PropertyValue>>;
|
|
557
490
|
/** Instance configuration; reserved for device kernels that take parameters. */
|
|
558
491
|
readonly config?: Readonly<Record<string, unknown>>;
|
|
559
492
|
}
|
|
560
493
|
|
|
561
494
|
/** IR-level device description consumed by the compiler. */
|
|
562
|
-
export declare interface DeviceDescription {
|
|
495
|
+
export declare interface DeviceDescription extends DeviceBridgeHooks {
|
|
563
496
|
readonly name?: string;
|
|
564
497
|
readonly pins: DevicePinMap;
|
|
498
|
+
readonly properties?: Readonly<Record<string, unknown>>;
|
|
499
|
+
readonly resistors?: Readonly<Record<string, ResistorDeclaration>>;
|
|
500
|
+
readonly connections?: Readonly<Record<string, ContactDeclaration>>;
|
|
501
|
+
/** Paired synchronous JS factory, invoked once per instance before IR generation. */
|
|
502
|
+
readonly factory: (context: ElectricalFactoryContext) => DeviceImplementation | void;
|
|
565
503
|
readonly states?: Readonly<Record<string, DeviceStateDescription>>;
|
|
566
504
|
readonly behaviors?: DeviceBehaviors;
|
|
567
505
|
/**
|
|
@@ -583,16 +521,38 @@ export declare interface DeviceDescription {
|
|
|
583
521
|
readonly updateResources?: readonly BytesRef[];
|
|
584
522
|
}
|
|
585
523
|
|
|
524
|
+
export declare interface DeviceElectricalInitialization {
|
|
525
|
+
initializeResistor(id: string, initial: ResistorInitialState): void;
|
|
526
|
+
initializePin(id: string, initial: PinElectricalDescription): void;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/** Per-instance construction and boundary hooks returned by the paired factory. */
|
|
530
|
+
export declare interface DeviceImplementation extends DeviceBehaviors, DeviceBridgeHooks {
|
|
531
|
+
readonly kernel?: DeviceKernelFactory;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
export declare interface DeviceInput {
|
|
535
|
+
readonly port: string;
|
|
536
|
+
readonly payload: unknown;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
export declare interface DeviceInputIo {
|
|
540
|
+
takeInput(port: string): unknown;
|
|
541
|
+
takeInputs(port: string): readonly unknown[];
|
|
542
|
+
writeState(name: string, value: unknown): void;
|
|
543
|
+
call(entry: EntryRef, args: readonly RuntimeScalar[]): void;
|
|
544
|
+
}
|
|
545
|
+
|
|
586
546
|
/**
|
|
587
547
|
* Everything a complex device kernel needs to declare its own IR before any
|
|
588
548
|
* phase function body is opened: the module (for `array`/`bytes`/`provider`),
|
|
589
|
-
*
|
|
549
|
+
* typed operations through `bind(builder)` and the allocated pin ids.
|
|
590
550
|
*/
|
|
591
551
|
export declare interface DeviceKernelContext {
|
|
592
552
|
readonly deviceId: string;
|
|
593
553
|
readonly config: Readonly<Record<string, unknown>> | undefined;
|
|
594
554
|
readonly module: IRModule;
|
|
595
|
-
readonly
|
|
555
|
+
bind(builder: FunctionBuilder<readonly []>): DeviceBehaviorApi;
|
|
596
556
|
readonly pins: readonly DeviceKernelPin[];
|
|
597
557
|
}
|
|
598
558
|
|
|
@@ -611,7 +571,6 @@ export declare type DeviceKernelFactory = (context: DeviceKernelContext) => Devi
|
|
|
611
571
|
declare interface DeviceKernelPin {
|
|
612
572
|
readonly name: string;
|
|
613
573
|
readonly globalPinId: number;
|
|
614
|
-
readonly role: CompiledPinRole;
|
|
615
574
|
}
|
|
616
575
|
|
|
617
576
|
/**
|
|
@@ -626,8 +585,9 @@ export declare interface DeviceKernelRuntime {
|
|
|
626
585
|
}
|
|
627
586
|
|
|
628
587
|
/** Metadata of one compiled device. */
|
|
629
|
-
declare interface DeviceMetadata {
|
|
588
|
+
declare interface DeviceMetadata extends DeviceBridgeHooks {
|
|
630
589
|
readonly deviceId: string;
|
|
590
|
+
readonly entries?: readonly EntryRef[];
|
|
631
591
|
readonly type: string;
|
|
632
592
|
/** First global pin id of the device. */
|
|
633
593
|
readonly pinOffset: number;
|
|
@@ -642,8 +602,11 @@ declare interface DeviceMetadata {
|
|
|
642
602
|
readonly update: string | undefined;
|
|
643
603
|
/** Typed accessor factory supplied by the device description, if any. */
|
|
644
604
|
readonly accessor: DeviceAccessorFactory | undefined;
|
|
645
|
-
|
|
646
|
-
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
export declare interface DeviceOutputIo {
|
|
608
|
+
readState(name: string): unknown;
|
|
609
|
+
publish(port: string, payload: unknown): void;
|
|
647
610
|
}
|
|
648
611
|
|
|
649
612
|
/** Pins of one device mapped into the global pin space. */
|
|
@@ -655,16 +618,6 @@ declare interface DevicePinAllocation {
|
|
|
655
618
|
readonly resolved: ReadonlyMap<string, ResolvedDevicePin>;
|
|
656
619
|
}
|
|
657
620
|
|
|
658
|
-
/** One pin declared by a device description. */
|
|
659
|
-
export declare interface DevicePinDescription {
|
|
660
|
-
/** Defaults to `'passive'`: the pin only senses the net. */
|
|
661
|
-
readonly direction?: DevicePinDirection;
|
|
662
|
-
/** Overrides the role derived from `direction`. */
|
|
663
|
-
readonly role?: CompiledPinRole;
|
|
664
|
-
/** Purely informational kind, e.g. `'signal'`, `'power'`, `'gnd'`. */
|
|
665
|
-
readonly kind?: string;
|
|
666
|
-
}
|
|
667
|
-
|
|
668
621
|
/**
|
|
669
622
|
* Types for the unified IR compiler (U01).
|
|
670
623
|
*
|
|
@@ -677,20 +630,27 @@ export declare interface DevicePinDescription {
|
|
|
677
630
|
* live in `../pin-space` and are reused here. The compiler ships no device
|
|
678
631
|
* models: every description is supplied by the caller.
|
|
679
632
|
*/
|
|
680
|
-
/**
|
|
681
|
-
export declare
|
|
633
|
+
/** One pin declared by the paired electrical device definition. */
|
|
634
|
+
export declare interface DevicePinDescription {
|
|
635
|
+
readonly kind: 'signal' | 'power' | 'gnd';
|
|
636
|
+
readonly side?: 'left' | 'right' | 'top' | 'bottom';
|
|
637
|
+
}
|
|
682
638
|
|
|
683
639
|
/** Pin operations a behavior may use; each call inlines into global memory. */
|
|
684
640
|
declare interface DevicePinHandle {
|
|
685
641
|
readonly name: string;
|
|
686
642
|
readonly globalId: number;
|
|
687
|
-
/**
|
|
643
|
+
/** Selects the physical output configuration. */
|
|
688
644
|
configure(mode: number): void;
|
|
689
|
-
|
|
645
|
+
setOutputEnabled(enabled: Value<'bool'>): void;
|
|
646
|
+
setPull(pull: 'none' | 'up' | 'down'): void;
|
|
647
|
+
writeVoltage(voltage: Value<'f64'>): void;
|
|
648
|
+
/** Writes digital drive intent through the finite output impedance. */
|
|
690
649
|
writeDigital(level: Value<'bool'>): void;
|
|
691
|
-
/**
|
|
650
|
+
/** Samples the solved voltage with the explicitly declared input thresholds. */
|
|
692
651
|
sampleDigital(): Value<'bool'>;
|
|
693
|
-
|
|
652
|
+
sampleVoltage(): Value<'f64'>;
|
|
653
|
+
/** Reads this pin's digital drive intent. */
|
|
694
654
|
readDrivenDigital(): Value<'bool'>;
|
|
695
655
|
}
|
|
696
656
|
|
|
@@ -700,12 +660,25 @@ declare interface DevicePinHandle {
|
|
|
700
660
|
*/
|
|
701
661
|
declare type DevicePinMap = ReadonlyMap<string, DevicePinDescription> | Readonly<Record<string, DevicePinDescription>>;
|
|
702
662
|
|
|
663
|
+
declare interface DeviceResistorHandle {
|
|
664
|
+
setResistance(ohms: Value<'f64'>): void;
|
|
665
|
+
setEnabled(enabled: Value<'bool'>): void;
|
|
666
|
+
/** Solved current in amperes, positive from the first declared pin to the second. */
|
|
667
|
+
sampleCurrent(): Value<'f64'>;
|
|
668
|
+
}
|
|
669
|
+
|
|
703
670
|
/** What one {@link DeviceSimulationHost.tick} call executed. */
|
|
704
671
|
export declare interface DeviceSimTickReport {
|
|
705
672
|
/** Simulation time after the step, in picoseconds. */
|
|
706
673
|
readonly simTime: number;
|
|
707
674
|
/** Circuit steps executed by this call. */
|
|
708
675
|
readonly executed: number;
|
|
676
|
+
/** Isolated device boundary-hook failures; absent when the step has none. */
|
|
677
|
+
readonly diagnostics?: readonly {
|
|
678
|
+
readonly code: 'device/input-failed' | 'device/output-failed';
|
|
679
|
+
readonly deviceId: string;
|
|
680
|
+
readonly message: string;
|
|
681
|
+
}[];
|
|
709
682
|
}
|
|
710
683
|
|
|
711
684
|
/**
|
|
@@ -762,6 +735,8 @@ export declare interface DeviceSimulationHostGuest {
|
|
|
762
735
|
* package that owns devices bundles its own worker script and supplies these.
|
|
763
736
|
*/
|
|
764
737
|
export declare interface DeviceSimulationHostGuestOptions {
|
|
738
|
+
/** Fixed electrical configuration supplied by the owning worker module. */
|
|
739
|
+
readonly electrical?: CircuitElectricalOptions;
|
|
765
740
|
/** Symbol geometry of the schematics this guest loads, or a factory called per load. */
|
|
766
741
|
readonly devices?: DeviceSymbolProvider | (() => DeviceSymbolProvider);
|
|
767
742
|
/** Resolves a schematic device reference; when omitted every reference stays unresolved. */
|
|
@@ -822,6 +797,75 @@ export declare interface DeviceTopic {
|
|
|
822
797
|
|
|
823
798
|
export { Disposable }
|
|
824
799
|
|
|
800
|
+
/**
|
|
801
|
+
* Types of the unified circuit runtime (U02).
|
|
802
|
+
*
|
|
803
|
+
* `Circuit` is the host-facing facade over one compiled unified IR module: it
|
|
804
|
+
* owns the engine instance, exposes typed per-device accessors and keeps the
|
|
805
|
+
* tick counter. Everything here is transport-neutral; no type mentions the
|
|
806
|
+
* device host or the schematic editor.
|
|
807
|
+
*/
|
|
808
|
+
export declare type ElectricalCurrentTarget = {
|
|
809
|
+
readonly kind: 'resistor' | 'contact';
|
|
810
|
+
readonly device: string;
|
|
811
|
+
readonly name: string;
|
|
812
|
+
} | {
|
|
813
|
+
readonly kind: 'drive' | 'pull-up' | 'pull-down';
|
|
814
|
+
readonly device: string;
|
|
815
|
+
readonly pin: string;
|
|
816
|
+
} | {
|
|
817
|
+
readonly kind: 'source';
|
|
818
|
+
readonly name: string;
|
|
819
|
+
};
|
|
820
|
+
|
|
821
|
+
export declare class ElectricalDefinitionError extends Error {
|
|
822
|
+
readonly code: ElectricalDefinitionErrorCode;
|
|
823
|
+
readonly name = "ElectricalDefinitionError";
|
|
824
|
+
constructor(code: ElectricalDefinitionErrorCode, message: string);
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
export declare type ElectricalDefinitionErrorCode = 'electrical/invalid-definition' | 'electrical/invalid-parameter' | 'electrical/unknown-resource' | 'electrical/duplicate-initialization' | 'electrical/missing-initialization' | 'electrical/factory-closed';
|
|
828
|
+
|
|
829
|
+
/** Active diagnostics of the last published electrical snapshot, plus any latched solve fault. */
|
|
830
|
+
export declare type ElectricalDiagnostic = {
|
|
831
|
+
readonly code: 'electrical/overcurrent';
|
|
832
|
+
readonly severity: 'warning';
|
|
833
|
+
readonly target: ElectricalCurrentTarget;
|
|
834
|
+
readonly current: number;
|
|
835
|
+
readonly maxAbsCurrent: number;
|
|
836
|
+
} | {
|
|
837
|
+
readonly code: 'electrical/invalid-parameter' | 'electrical/source-conflict' | 'electrical/numerical-failure';
|
|
838
|
+
readonly severity: 'error';
|
|
839
|
+
/** Identifiable failed operation or resource; absent for a matrix-level failure. */
|
|
840
|
+
readonly target?: ElectricalCurrentTarget;
|
|
841
|
+
/** Resources associated with the affected network, not a list of proven culprits. */
|
|
842
|
+
readonly resources: readonly ElectricalCurrentTarget[];
|
|
843
|
+
readonly pins: readonly string[];
|
|
844
|
+
};
|
|
845
|
+
|
|
846
|
+
export declare interface ElectricalFactoryContext {
|
|
847
|
+
readonly properties: Readonly<Record<string, PropertyValue>>;
|
|
848
|
+
readonly electrical: DeviceElectricalInitialization;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
export declare interface ElectricalPinDeclaration {
|
|
852
|
+
readonly kind: 'signal' | 'power' | 'gnd';
|
|
853
|
+
readonly side?: 'left' | 'right' | 'top' | 'bottom';
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
declare type ElectricalReading = {
|
|
857
|
+
readonly state: 'determinate';
|
|
858
|
+
readonly value: number;
|
|
859
|
+
} | {
|
|
860
|
+
readonly state: 'floating';
|
|
861
|
+
} | {
|
|
862
|
+
readonly state: 'indeterminate';
|
|
863
|
+
};
|
|
864
|
+
|
|
865
|
+
export declare interface ElectricalReference {
|
|
866
|
+
readonly source: string;
|
|
867
|
+
}
|
|
868
|
+
|
|
825
869
|
export { Event_2 as Event }
|
|
826
870
|
|
|
827
871
|
/** Result of the global pin allocation. */
|
|
@@ -843,7 +887,7 @@ declare interface GlobalStateMap {
|
|
|
843
887
|
readonly totalStates: number;
|
|
844
888
|
}
|
|
845
889
|
|
|
846
|
-
/**
|
|
890
|
+
/** Physical output configuration values. */
|
|
847
891
|
export declare const PIN_MODE: Readonly<{
|
|
848
892
|
readonly highZ: 0;
|
|
849
893
|
readonly pushPull: 1;
|
|
@@ -851,18 +895,44 @@ export declare const PIN_MODE: Readonly<{
|
|
|
851
895
|
readonly analog: 3;
|
|
852
896
|
}>;
|
|
853
897
|
|
|
854
|
-
|
|
898
|
+
export declare interface PinElectricalDescription {
|
|
899
|
+
readonly drive?: {
|
|
900
|
+
readonly reference: ElectricalReference;
|
|
901
|
+
readonly highResistance: number;
|
|
902
|
+
readonly lowResistance: number;
|
|
903
|
+
readonly analogResistance?: number;
|
|
904
|
+
readonly maxAbsCurrent?: number;
|
|
905
|
+
};
|
|
906
|
+
readonly bias?: {
|
|
907
|
+
readonly reference: ElectricalReference;
|
|
908
|
+
readonly upResistance: number;
|
|
909
|
+
readonly downResistance: number;
|
|
910
|
+
};
|
|
911
|
+
readonly input?: {
|
|
912
|
+
readonly reference: ElectricalReference;
|
|
913
|
+
readonly low: number;
|
|
914
|
+
readonly high: number;
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
/** One physical output configuration value. */
|
|
855
919
|
export declare type PinMode = (typeof PIN_MODE)[keyof typeof PIN_MODE];
|
|
856
920
|
|
|
921
|
+
export declare interface ResistorDeclaration {
|
|
922
|
+
readonly pins: readonly [string, string];
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
export declare interface ResistorInitialState {
|
|
926
|
+
readonly resistance: number;
|
|
927
|
+
readonly enabled: boolean;
|
|
928
|
+
readonly maxAbsCurrent?: number;
|
|
929
|
+
}
|
|
930
|
+
|
|
857
931
|
/** One resolved pin in the global pin space. */
|
|
858
932
|
declare interface ResolvedDevicePin {
|
|
859
933
|
readonly name: string;
|
|
860
934
|
readonly deviceId: string;
|
|
861
935
|
readonly globalPinId: number;
|
|
862
|
-
readonly direction: DevicePinDirection;
|
|
863
|
-
readonly role: CompiledPinRole;
|
|
864
|
-
/** Whether the device reads the solved value of this pin. */
|
|
865
|
-
readonly senses: boolean;
|
|
866
936
|
}
|
|
867
937
|
|
|
868
938
|
/** One component symbol of a compiled schematic. */
|
|
@@ -915,6 +985,8 @@ export declare interface SchematicDeviceBinding {
|
|
|
915
985
|
|
|
916
986
|
/** Reads the bytes of one schematic URI; the caller resolves relative references. */
|
|
917
987
|
export declare interface SchematicDeviceSimulationHostOptions {
|
|
988
|
+
/** Local startup configuration, not an RPC method or payload. */
|
|
989
|
+
readonly electrical?: CircuitElectricalOptions;
|
|
918
990
|
readonly read: (uri: string) => Promise<Uint8Array>;
|
|
919
991
|
/**
|
|
920
992
|
* Symbol geometry of the schematics this host loads. Pass the same provider the schematic was
|
|
@@ -963,8 +1035,8 @@ export declare interface SimulationPublish {
|
|
|
963
1035
|
*/
|
|
964
1036
|
export declare function startDeviceSimulationHostGuest(port: MessagePort, options?: DeviceSimulationHostGuestOptions): DeviceSimulationHostGuest;
|
|
965
1037
|
|
|
966
|
-
/** Global pin addresses available to one circuit (8 devices x
|
|
967
|
-
export declare const UNIFIED_PIN_CAPACITY =
|
|
1038
|
+
/** Global pin addresses available to one circuit (8 devices x 512 pins). */
|
|
1039
|
+
export declare const UNIFIED_PIN_CAPACITY = 4096;
|
|
968
1040
|
|
|
969
1041
|
/** Error raised while compiling a circuit. */
|
|
970
1042
|
export declare class UnifiedIRCompilerError extends Error {
|
|
@@ -972,19 +1044,15 @@ export declare class UnifiedIRCompilerError extends Error {
|
|
|
972
1044
|
readonly code: UnifiedIRCompilerErrorCode;
|
|
973
1045
|
readonly deviceId: string | undefined;
|
|
974
1046
|
readonly pinName: string | undefined;
|
|
975
|
-
readonly netId: number | undefined;
|
|
976
|
-
readonly diagnostics: readonly CompilationDiagnostic[];
|
|
977
1047
|
constructor(code: UnifiedIRCompilerErrorCode, message: string, options?: UnifiedIRCompilerErrorOptions);
|
|
978
1048
|
}
|
|
979
1049
|
|
|
980
1050
|
/** Error codes raised by {@link UnifiedIRCompilerError}. */
|
|
981
|
-
export declare type UnifiedIRCompilerErrorCode = 'invalid-input' | 'duplicate-device' | '
|
|
1051
|
+
export declare type UnifiedIRCompilerErrorCode = 'invalid-input' | 'duplicate-device' | 'state-not-found' | 'capacity-exceeded' | 'invalid-ir';
|
|
982
1052
|
|
|
983
1053
|
export declare interface UnifiedIRCompilerErrorOptions {
|
|
984
1054
|
readonly deviceId?: string;
|
|
985
1055
|
readonly pinName?: string;
|
|
986
|
-
readonly netId?: number;
|
|
987
|
-
readonly diagnostics?: readonly CompilationDiagnostic[];
|
|
988
1056
|
readonly cause?: unknown;
|
|
989
1057
|
}
|
|
990
1058
|
|