@litz-sim/litz 0.2.0 → 0.3.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/LICENSE +176 -0
- package/README.md +3 -3
- package/index.d.ts +54 -5
- package/litz_wasm.wasm +0 -0
- package/package.json +2 -2
- package/src/constants.js +17 -0
- package/src/litz.js +49 -16
- package/src/session.js +236 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @litz-sim/litz
|
|
2
2
|
|
|
3
|
-
`@litz-sim/litz` is the JavaScript binding for Litz, a deterministic electronics and firmware simulator. The package loads `litz_wasm.wasm`, opens a session
|
|
3
|
+
`@litz-sim/litz` is the JavaScript binding for Litz, a deterministic electronics and firmware simulator. The package loads `litz_wasm.wasm`, opens a session over one or more development boards from a `diagram.json` and their application images, and exposes serial output, part state, pins, probes, decoders, displays, electrical conflicts and a RISC-V debugger as plain objects. It has no DOM code, no workers and no runtime dependencies, and it advances only when the host calls `run` or `advance`.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -12,7 +12,7 @@ The package is an ES module for Node 18 or newer and for browsers. It ships `ind
|
|
|
12
12
|
|
|
13
13
|
## First session
|
|
14
14
|
|
|
15
|
-
`loadLitz` reads, compiles and instantiates the module and returns a `Litz`. `createSession`
|
|
15
|
+
`loadLitz` reads, compiles and instantiates the module and returns a `Litz`. `createSession` boots every development board the diagram names, each from its own image (`boardImages`) or from one `app`. `advance` moves simulated time, `serial.take` drains the console and `close` releases the session. The sample below reads the repository's `blinky` example. In a checkout, `npm run example` runs it from `js/examples/blinky.mjs`, where Node resolves the package name through the enclosing `js/package.json`. In another project, install the package and pass that project's diagram and image.
|
|
16
16
|
|
|
17
17
|
```js
|
|
18
18
|
import { readFile } from "node:fs/promises";
|
|
@@ -224,4 +224,4 @@ The full API reference, including every type, lifecycle rule, host import name a
|
|
|
224
224
|
|
|
225
225
|
## License
|
|
226
226
|
|
|
227
|
-
|
|
227
|
+
Apache-2.0.
|
package/index.d.ts
CHANGED
|
@@ -12,10 +12,12 @@ export declare class Litz {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export interface SessionOptions {
|
|
15
|
-
/** The diagram.json text. The
|
|
15
|
+
/** The diagram.json text. The boards it names select the chips. */
|
|
16
16
|
diagram: string;
|
|
17
|
-
/** The application image. */
|
|
18
|
-
app
|
|
17
|
+
/** The application image for a single-board diagram. */
|
|
18
|
+
app?: Uint8Array | ArrayBuffer | ArrayBufferView;
|
|
19
|
+
/** One image per development board; replaces `app` in a multi-board diagram. */
|
|
20
|
+
boardImages?: BoardImage[];
|
|
19
21
|
/** Mask ROM, when the firmware needs one. */
|
|
20
22
|
rom?: Uint8Array | ArrayBuffer | ArrayBufferView | null;
|
|
21
23
|
/** Second-stage bootloader; requires `ptable`. */
|
|
@@ -36,6 +38,18 @@ export interface SessionOptions {
|
|
|
36
38
|
boards?: Record<string, ChipFactory>;
|
|
37
39
|
}
|
|
38
40
|
|
|
41
|
+
/** One board's images in a multi-board session. */
|
|
42
|
+
export interface BoardImage {
|
|
43
|
+
/** The `diagram.json` instance id; omitted entries match boards by position. */
|
|
44
|
+
id?: string;
|
|
45
|
+
app: Uint8Array | ArrayBuffer | ArrayBufferView;
|
|
46
|
+
rom?: Uint8Array | ArrayBuffer | ArrayBufferView | null;
|
|
47
|
+
boot?: Uint8Array | ArrayBuffer | ArrayBufferView | null;
|
|
48
|
+
ptable?: Uint8Array | ArrayBuffer | ArrayBufferView | null;
|
|
49
|
+
flashSize?: number | null;
|
|
50
|
+
mac?: string | null;
|
|
51
|
+
}
|
|
52
|
+
|
|
39
53
|
/** One instantiated `litz:part` component, as the simulator drives it. */
|
|
40
54
|
export interface HostPart {
|
|
41
55
|
setPin(pin: number, level: Level, atNs: number): void;
|
|
@@ -174,10 +188,35 @@ export interface Display {
|
|
|
174
188
|
}
|
|
175
189
|
|
|
176
190
|
export interface Serial {
|
|
177
|
-
/** Drain what the
|
|
191
|
+
/** Drain what the boards printed since the last call, merged in board order. */
|
|
178
192
|
take(): string;
|
|
179
|
-
/**
|
|
193
|
+
/** Drain one board's console, by list index or board id. */
|
|
194
|
+
takeBoard(board: number | string): string;
|
|
195
|
+
/** Deliver bytes to the first board's UART0 receiver. */
|
|
180
196
|
write(data: string | Uint8Array | ArrayBuffer | ArrayBufferView): void;
|
|
197
|
+
/** Deliver bytes to one board's UART0 receiver. */
|
|
198
|
+
writeBoard(
|
|
199
|
+
board: number | string,
|
|
200
|
+
data: string | Uint8Array | ArrayBuffer | ArrayBufferView,
|
|
201
|
+
): void;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** One development board the session booted. */
|
|
205
|
+
export interface BoardInfo extends ChipInfo {
|
|
206
|
+
readonly index: number;
|
|
207
|
+
readonly id: string;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** The browser-facing debugger over one RISC-V board. */
|
|
211
|
+
export interface Debug {
|
|
212
|
+
available(board?: number | string): boolean;
|
|
213
|
+
pc(board?: number | string): number | null;
|
|
214
|
+
registers(board?: number | string): { values: number[]; pc: number } | null;
|
|
215
|
+
memory(board: number | string, addr: number, length: number): Uint8Array;
|
|
216
|
+
disassemble(board: number | string, addr: number, count?: number): string;
|
|
217
|
+
setBreakpoints(board: number | string, pcs: ArrayLike<number>): void;
|
|
218
|
+
step(board?: number | string): StopWord | "unsupported";
|
|
219
|
+
run(board?: number | string, steps?: number): StopWord | "unsupported";
|
|
181
220
|
}
|
|
182
221
|
|
|
183
222
|
export interface Trace {
|
|
@@ -255,6 +294,10 @@ export declare class Session {
|
|
|
255
294
|
readonly ms: number;
|
|
256
295
|
/** The backend the diagram booted, its clock and its flash layout. */
|
|
257
296
|
chip(): ChipInfo;
|
|
297
|
+
/** Every development board the session booted, in diagram order. */
|
|
298
|
+
boards(): BoardInfo[];
|
|
299
|
+
/** One board by list index or `diagram.json` id. */
|
|
300
|
+
board(board?: number | string): BoardInfo;
|
|
258
301
|
/** How the last `run` ended. */
|
|
259
302
|
readonly stop: StopWord;
|
|
260
303
|
/** The backend's explanation for a trap, or `null`. */
|
|
@@ -281,12 +324,18 @@ export declare class Session {
|
|
|
281
324
|
partPin(id: string, pin?: string): Level | null;
|
|
282
325
|
/** The level the chip sees on its own pad, by GPIO number. */
|
|
283
326
|
gpio(pin: number): Level | null;
|
|
327
|
+
/** The level one board sees on one of its own pads. */
|
|
328
|
+
gpioOn(board: number | string, pin: number): Level | null;
|
|
284
329
|
/** The panel, or `null` when the circuit has no display. */
|
|
285
330
|
display(): Display | null;
|
|
331
|
+
/** One board's panel, by list index or board id. */
|
|
332
|
+
displayOn(board?: number | string): Display | null;
|
|
286
333
|
/** Deliver a touch at panel pixels. False without a panel. */
|
|
287
334
|
touch(x: number, y: number, down?: boolean): boolean;
|
|
288
335
|
/** Probes' samples and decoders' frames. */
|
|
289
336
|
scope(): ScopeDocument;
|
|
337
|
+
/** Registers, memory, breakpoints and single-step. */
|
|
338
|
+
readonly debug: Debug;
|
|
290
339
|
/** Drop the session. */
|
|
291
340
|
close(): void;
|
|
292
341
|
}
|
package/litz_wasm.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@litz-sim/litz",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Deterministic electronics and firmware simulator in WebAssembly",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"simulator",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"electronics",
|
|
11
11
|
"wasm"
|
|
12
12
|
],
|
|
13
|
-
"license": "
|
|
13
|
+
"license": "Apache-2.0",
|
|
14
14
|
"author": "redelectricity",
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
package/src/constants.js
CHANGED
|
@@ -43,6 +43,23 @@ export const REQUIRED_EXPORTS = [
|
|
|
43
43
|
"litz_guest_console",
|
|
44
44
|
"litz_guest_fault",
|
|
45
45
|
"litz_guest_call",
|
|
46
|
+
"litz_board_count",
|
|
47
|
+
"litz_board_id",
|
|
48
|
+
"litz_board_chip_info",
|
|
49
|
+
"litz_board_gpio_level",
|
|
50
|
+
"litz_serial_take_board",
|
|
51
|
+
"litz_serial_write_board",
|
|
52
|
+
"litz_board_display_info",
|
|
53
|
+
"litz_board_display_version",
|
|
54
|
+
"litz_board_display_rgba",
|
|
55
|
+
"litz_debug_available",
|
|
56
|
+
"litz_debug_pc",
|
|
57
|
+
"litz_debug_registers",
|
|
58
|
+
"litz_debug_memory",
|
|
59
|
+
"litz_debug_disassemble",
|
|
60
|
+
"litz_debug_breakpoints",
|
|
61
|
+
"litz_debug_step",
|
|
62
|
+
"litz_debug_run",
|
|
46
63
|
];
|
|
47
64
|
|
|
48
65
|
// State codes from `litz_part_state`; `-1` means the diagram has no such id.
|
package/src/litz.js
CHANGED
|
@@ -166,15 +166,27 @@ export class Litz {
|
|
|
166
166
|
manifests = [],
|
|
167
167
|
parts = {},
|
|
168
168
|
boards = {},
|
|
169
|
+
boardImages = [],
|
|
169
170
|
} = {}) {
|
|
170
171
|
this.#assertOpen();
|
|
171
172
|
if (typeof diagram !== "string" || diagram.length === 0) {
|
|
172
173
|
throw new LitzError("createSession needs the diagram.json text as `diagram`");
|
|
173
174
|
}
|
|
174
|
-
const
|
|
175
|
-
if (
|
|
175
|
+
const fleets = Array.isArray(boardImages) ? boardImages : [];
|
|
176
|
+
if (fleets.length === 0 && (app === undefined || app === null)) {
|
|
176
177
|
throw new LitzError("createSession needs the application image as `app`");
|
|
177
178
|
}
|
|
179
|
+
if (
|
|
180
|
+
fleets.some(
|
|
181
|
+
(board) =>
|
|
182
|
+
typeof board !== "object" ||
|
|
183
|
+
board === null ||
|
|
184
|
+
board.app === undefined ||
|
|
185
|
+
board.app === null,
|
|
186
|
+
)
|
|
187
|
+
) {
|
|
188
|
+
throw new LitzError("every `boardImages` entry needs an `app` image");
|
|
189
|
+
}
|
|
178
190
|
if (flashSize !== null && !(Number.isInteger(flashSize) && flashSize > 0)) {
|
|
179
191
|
throw new LitzError("`flashSize` must be a positive whole number of bytes");
|
|
180
192
|
}
|
|
@@ -196,20 +208,41 @@ export class Litz {
|
|
|
196
208
|
const romBytes = optionalBytes(rom, "rom");
|
|
197
209
|
const bootBytes = optionalBytes(boot, "boot");
|
|
198
210
|
const ptableBytes = optionalBytes(ptable, "ptable");
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
211
|
+
const spec = { diagram };
|
|
212
|
+
const buffers = [];
|
|
213
|
+
if (fleets.length === 0) {
|
|
214
|
+
const appBytes = bytesOf(app, "app");
|
|
215
|
+
if (appBytes.length === 0) {
|
|
216
|
+
throw new LitzError("createSession needs the application image as `app`");
|
|
217
|
+
}
|
|
218
|
+
const appBuf = hold(io, appBytes);
|
|
219
|
+
const romBuf = hold(io, romBytes);
|
|
220
|
+
const bootBuf = hold(io, bootBytes);
|
|
221
|
+
const ptableBuf = hold(io, ptableBytes);
|
|
222
|
+
buffers.push(appBuf, romBuf, bootBuf, ptableBuf);
|
|
223
|
+
spec.app = { ptr: appBuf.ptr, len: appBuf.len };
|
|
224
|
+
if (romBuf.len > 0) spec.rom = { ptr: romBuf.ptr, len: romBuf.len };
|
|
225
|
+
if (bootBuf.len > 0) spec.boot = { ptr: bootBuf.ptr, len: bootBuf.len };
|
|
226
|
+
if (ptableBuf.len > 0) spec.ptable = { ptr: ptableBuf.ptr, len: ptableBuf.len };
|
|
227
|
+
} else {
|
|
228
|
+
spec.boards = fleets.map((board) => {
|
|
229
|
+
const appBuf = hold(io, bytesOf(board.app, "board.app"));
|
|
230
|
+
const romBuf = hold(io, optionalBytes(board.rom, "board.rom"));
|
|
231
|
+
const bootBuf = hold(io, optionalBytes(board.boot, "board.boot"));
|
|
232
|
+
const ptableBuf = hold(io, optionalBytes(board.ptable, "board.ptable"));
|
|
233
|
+
buffers.push(appBuf, romBuf, bootBuf, ptableBuf);
|
|
234
|
+
const entry = { app: { ptr: appBuf.ptr, len: appBuf.len } };
|
|
235
|
+
if (board.id !== undefined && board.id !== null) entry.id = String(board.id);
|
|
236
|
+
if (romBuf.len > 0) entry.rom = { ptr: romBuf.ptr, len: romBuf.len };
|
|
237
|
+
if (bootBuf.len > 0) entry.boot = { ptr: bootBuf.ptr, len: bootBuf.len };
|
|
238
|
+
if (ptableBuf.len > 0) entry.ptable = { ptr: ptableBuf.ptr, len: ptableBuf.len };
|
|
239
|
+
if (board.flashSize !== undefined && board.flashSize !== null) {
|
|
240
|
+
entry.flashSize = board.flashSize;
|
|
241
|
+
}
|
|
242
|
+
if (board.mac !== undefined && board.mac !== null) entry.mac = String(board.mac);
|
|
243
|
+
return entry;
|
|
244
|
+
});
|
|
245
|
+
}
|
|
213
246
|
if (flashSize !== null) spec.flashSize = flashSize;
|
|
214
247
|
if (mac !== null) spec.mac = mac;
|
|
215
248
|
if (analog) spec.analog = true;
|
package/src/session.js
CHANGED
|
@@ -29,7 +29,9 @@ export class Session {
|
|
|
29
29
|
const session = this;
|
|
30
30
|
this.#serial = {
|
|
31
31
|
take: () => session.#takeSerial(),
|
|
32
|
+
takeBoard: (board) => session.#takeBoardSerial(board),
|
|
32
33
|
write: (data) => session.#writeSerial(data),
|
|
34
|
+
writeBoard: (board, data) => session.#writeBoardSerial(board, data),
|
|
33
35
|
};
|
|
34
36
|
this.#trace = Object.freeze({
|
|
35
37
|
start: () => {
|
|
@@ -114,6 +116,52 @@ export class Session {
|
|
|
114
116
|
}
|
|
115
117
|
}
|
|
116
118
|
|
|
119
|
+
/** Every development board the session booted, in diagram order. */
|
|
120
|
+
boards() {
|
|
121
|
+
this.#assertOpen();
|
|
122
|
+
const count = this.#x.litz_board_count(this.#handle);
|
|
123
|
+
const out = [];
|
|
124
|
+
for (let index = 0; index < count; index += 1) {
|
|
125
|
+
const id = this.#readText(
|
|
126
|
+
(ptr, cap) => this.#x.litz_board_id(this.#handle, index, ptr, cap),
|
|
127
|
+
32,
|
|
128
|
+
);
|
|
129
|
+
const info = this.#readText(
|
|
130
|
+
(ptr, cap) => this.#x.litz_board_chip_info(this.#handle, index, ptr, cap),
|
|
131
|
+
128,
|
|
132
|
+
);
|
|
133
|
+
let chip;
|
|
134
|
+
try {
|
|
135
|
+
chip = JSON.parse(info);
|
|
136
|
+
} catch (error) {
|
|
137
|
+
throw new LitzError("the chip description was not valid JSON", { cause: error });
|
|
138
|
+
}
|
|
139
|
+
out.push({ index, id, ...chip });
|
|
140
|
+
}
|
|
141
|
+
return out;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** One board by list index or `diagram.json` id. */
|
|
145
|
+
board(board = 0) {
|
|
146
|
+
this.#assertOpen();
|
|
147
|
+
if (typeof board === "number") {
|
|
148
|
+
const entry = this.boards()[board];
|
|
149
|
+
if (!entry) throw new LitzError(`there is no board at index ${board}`);
|
|
150
|
+
return entry;
|
|
151
|
+
}
|
|
152
|
+
const entry = this.boards().find((candidate) => candidate.id === board);
|
|
153
|
+
if (!entry) throw new LitzError(`there is no board ${board}`);
|
|
154
|
+
return entry;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** The level one board sees on one of its own pads. */
|
|
158
|
+
gpioOn(board, pin) {
|
|
159
|
+
this.#assertOpen();
|
|
160
|
+
const index = this.#boardIndex(board);
|
|
161
|
+
const code = this.#x.litz_board_gpio_level(this.#handle, index, pin >>> 0);
|
|
162
|
+
return code < 0 ? null : LEVELS[code] ?? null;
|
|
163
|
+
}
|
|
164
|
+
|
|
117
165
|
/** How the last `run` ended: budget, idle, halted, trap, reset or breakpoint. */
|
|
118
166
|
get stop() {
|
|
119
167
|
this.#assertOpen();
|
|
@@ -310,6 +358,151 @@ export class Session {
|
|
|
310
358
|
return this.#x.litz_touch(this.#handle, x >>> 0, y >>> 0, down ? 1 : 0) === 1;
|
|
311
359
|
}
|
|
312
360
|
|
|
361
|
+
/** One board's display, addressed by list index or board id. */
|
|
362
|
+
displayOn(board = 0) {
|
|
363
|
+
this.#assertOpen();
|
|
364
|
+
const index = this.#boardIndex(board);
|
|
365
|
+
const info = this.#x.litz_board_display_info(this.#handle, index);
|
|
366
|
+
if (info === 0) return null;
|
|
367
|
+
const width = info >>> 16;
|
|
368
|
+
const height = info & 0xffff;
|
|
369
|
+
const session = this;
|
|
370
|
+
return {
|
|
371
|
+
width,
|
|
372
|
+
height,
|
|
373
|
+
get version() {
|
|
374
|
+
session.#assertOpen();
|
|
375
|
+
return session.#x.litz_board_display_version(session.#handle, index);
|
|
376
|
+
},
|
|
377
|
+
pixels() {
|
|
378
|
+
session.#assertOpen();
|
|
379
|
+
const needed = width * height * 4;
|
|
380
|
+
const cap = session.#io.writeOut(needed);
|
|
381
|
+
const written = session.#x.litz_board_display_rgba(
|
|
382
|
+
session.#handle,
|
|
383
|
+
index,
|
|
384
|
+
cap.ptr,
|
|
385
|
+
cap.len,
|
|
386
|
+
);
|
|
387
|
+
if (written !== needed) {
|
|
388
|
+
throw session.#io.error("the display frame could not be read");
|
|
389
|
+
}
|
|
390
|
+
return session.#io.copyOut(written);
|
|
391
|
+
},
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/** The browser-facing debugger, one board at a time. */
|
|
396
|
+
get debug() {
|
|
397
|
+
const session = this;
|
|
398
|
+
return Object.freeze({
|
|
399
|
+
available: (board = 0) => {
|
|
400
|
+
session.#assertOpen();
|
|
401
|
+
return session.#x.litz_debug_available(session.#handle, session.#boardIndex(board)) === 1;
|
|
402
|
+
},
|
|
403
|
+
pc: (board = 0) => {
|
|
404
|
+
session.#assertOpen();
|
|
405
|
+
const pc = session.#x.litz_debug_pc(session.#handle, session.#boardIndex(board));
|
|
406
|
+
return pc < 0 ? null : pc >>> 0;
|
|
407
|
+
},
|
|
408
|
+
registers: (board = 0) => {
|
|
409
|
+
session.#assertOpen();
|
|
410
|
+
const index = session.#boardIndex(board);
|
|
411
|
+
const cap = session.#io.writeOut(33 * 4);
|
|
412
|
+
const written = session.#x.litz_debug_registers(
|
|
413
|
+
session.#handle,
|
|
414
|
+
index,
|
|
415
|
+
cap.ptr,
|
|
416
|
+
cap.len,
|
|
417
|
+
);
|
|
418
|
+
if (written !== 33 * 4) return null;
|
|
419
|
+
const bytes = session.#io.copyOut(written);
|
|
420
|
+
const values = [];
|
|
421
|
+
for (let offset = 0; offset < written; offset += 4) {
|
|
422
|
+
values.push(
|
|
423
|
+
(bytes[offset] |
|
|
424
|
+
(bytes[offset + 1] << 8) |
|
|
425
|
+
(bytes[offset + 2] << 16) |
|
|
426
|
+
(bytes[offset + 3] << 24)) >>>
|
|
427
|
+
0,
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
return { values: values.slice(0, 32), pc: values[32] };
|
|
431
|
+
},
|
|
432
|
+
memory: (board, addr, length) => {
|
|
433
|
+
session.#assertOpen();
|
|
434
|
+
const index = session.#boardIndex(board);
|
|
435
|
+
const cap = session.#io.writeOut(Math.max(1, length >>> 0));
|
|
436
|
+
const written = session.#x.litz_debug_memory(
|
|
437
|
+
session.#handle,
|
|
438
|
+
index,
|
|
439
|
+
addr >>> 0,
|
|
440
|
+
cap.ptr,
|
|
441
|
+
cap.len,
|
|
442
|
+
);
|
|
443
|
+
return session.#io.copyOut(written | 0);
|
|
444
|
+
},
|
|
445
|
+
disassemble: (board, addr, count = 8) => {
|
|
446
|
+
session.#assertOpen();
|
|
447
|
+
const index = session.#boardIndex(board);
|
|
448
|
+
return session.#readText(
|
|
449
|
+
(ptr, cap) =>
|
|
450
|
+
session.#x.litz_debug_disassemble(
|
|
451
|
+
session.#handle,
|
|
452
|
+
index,
|
|
453
|
+
addr >>> 0,
|
|
454
|
+
count >>> 0,
|
|
455
|
+
ptr,
|
|
456
|
+
cap,
|
|
457
|
+
),
|
|
458
|
+
4096,
|
|
459
|
+
);
|
|
460
|
+
},
|
|
461
|
+
setBreakpoints: (board, pcs) => {
|
|
462
|
+
session.#assertOpen();
|
|
463
|
+
const index = session.#boardIndex(board);
|
|
464
|
+
const list = Array.from(pcs, (pc) => pc >>> 0);
|
|
465
|
+
const bytes = new Uint8Array(list.length * 4);
|
|
466
|
+
list.forEach((pc, slot) => {
|
|
467
|
+
bytes[slot * 4] = pc & 0xff;
|
|
468
|
+
bytes[slot * 4 + 1] = (pc >>> 8) & 0xff;
|
|
469
|
+
bytes[slot * 4 + 2] = (pc >>> 16) & 0xff;
|
|
470
|
+
bytes[slot * 4 + 3] = (pc >>> 24) & 0xff;
|
|
471
|
+
});
|
|
472
|
+
const buf = session.#io.writeIn(bytes);
|
|
473
|
+
let code;
|
|
474
|
+
try {
|
|
475
|
+
code = session.#x.litz_debug_breakpoints(
|
|
476
|
+
session.#handle,
|
|
477
|
+
index,
|
|
478
|
+
buf.ptr,
|
|
479
|
+
list.length,
|
|
480
|
+
);
|
|
481
|
+
} finally {
|
|
482
|
+
session.#io.release(buf);
|
|
483
|
+
}
|
|
484
|
+
if (code !== 1) throw session.#io.error("the breakpoints could not be set");
|
|
485
|
+
},
|
|
486
|
+
step: (board = 0) => {
|
|
487
|
+
session.#assertOpen();
|
|
488
|
+
const code = session.#x.litz_debug_step(
|
|
489
|
+
session.#handle,
|
|
490
|
+
session.#boardIndex(board),
|
|
491
|
+
);
|
|
492
|
+
return code < 0 ? "unsupported" : STOPS[code] ?? "unknown";
|
|
493
|
+
},
|
|
494
|
+
run: (board = 0, steps = DEFAULT_STEPS) => {
|
|
495
|
+
session.#assertOpen();
|
|
496
|
+
const code = session.#x.litz_debug_run(
|
|
497
|
+
session.#handle,
|
|
498
|
+
session.#boardIndex(board),
|
|
499
|
+
steps >>> 0,
|
|
500
|
+
);
|
|
501
|
+
return code < 0 ? "unsupported" : STOPS[code] ?? "unknown";
|
|
502
|
+
},
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
|
|
313
506
|
/** The scope document: every probe's samples and every decoder's frames. */
|
|
314
507
|
scope() {
|
|
315
508
|
this.#assertOpen();
|
|
@@ -352,6 +545,49 @@ export class Session {
|
|
|
352
545
|
return { id, code, kind: entry.kind, state: entry.state, value };
|
|
353
546
|
}
|
|
354
547
|
|
|
548
|
+
#boardIndex(board) {
|
|
549
|
+
if (typeof board === "number") {
|
|
550
|
+
if (!Number.isInteger(board) || board < 0) {
|
|
551
|
+
throw new LitzError(`there is no board ${board}`);
|
|
552
|
+
}
|
|
553
|
+
return board;
|
|
554
|
+
}
|
|
555
|
+
return this.board(board).index;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
#takeBoardSerial(board) {
|
|
559
|
+
this.#assertOpen();
|
|
560
|
+
const index = this.#boardIndex(board);
|
|
561
|
+
const chunks = [];
|
|
562
|
+
for (;;) {
|
|
563
|
+
const cap = this.#io.writeOut(64 * 1024);
|
|
564
|
+
const written = this.#x.litz_serial_take_board(
|
|
565
|
+
this.#handle,
|
|
566
|
+
index,
|
|
567
|
+
cap.ptr,
|
|
568
|
+
cap.len,
|
|
569
|
+
);
|
|
570
|
+
if (written === 0) break;
|
|
571
|
+
chunks.push(this.#io.copyOut(written));
|
|
572
|
+
if (written < cap.len) break;
|
|
573
|
+
}
|
|
574
|
+
return decodeChunks(chunks);
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
#writeBoardSerial(board, data) {
|
|
578
|
+
this.#assertOpen();
|
|
579
|
+
const index = this.#boardIndex(board);
|
|
580
|
+
const bytes = typeof data === "string" ? ENCODER.encode(data) : bytesOf(data, "serial data");
|
|
581
|
+
if (bytes.length === 0) return;
|
|
582
|
+
const buf = this.#io.writeIn(bytes);
|
|
583
|
+
try {
|
|
584
|
+
this.#x.litz_serial_write_board(this.#handle, index, buf.ptr, buf.len);
|
|
585
|
+
} finally {
|
|
586
|
+
this.#io.release(buf);
|
|
587
|
+
}
|
|
588
|
+
this.#throwStored();
|
|
589
|
+
}
|
|
590
|
+
|
|
355
591
|
#takeSerial() {
|
|
356
592
|
this.#assertOpen();
|
|
357
593
|
const chunks = [];
|