@typecad/framework-zephyr 1.0.0-alpha.16 → 1.0.0-alpha.19
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 +202 -21
- package/README.md +49 -87
- package/dist/as-built.d.ts +2 -2
- package/dist/as-built.js +2 -2
- package/dist/audit.d.ts +111 -0
- package/dist/audit.js +416 -0
- package/dist/boardgen.d.ts +1 -9
- package/dist/boardgen.js +288 -47
- package/dist/chips/resolve.js +20 -0
- package/dist/chips/types.d.ts +22 -1
- package/dist/debug-codegen.js +1 -1
- package/dist/display/bindings.d.ts +55 -0
- package/dist/display/bindings.js +316 -0
- package/dist/display/gfx.d.ts +2 -3
- package/dist/display/gfx.js +166 -154
- package/dist/display/index.js +20 -1
- package/dist/display/mipi-dbi-host.d.ts +9 -0
- package/dist/display/mipi-dbi-host.js +174 -0
- package/dist/display/profiles.d.ts +109 -4
- package/dist/display/profiles.js +270 -7
- package/dist/display/touch-adapter.js +119 -49
- package/dist/display/ui-adapter-eink.d.ts +2 -0
- package/dist/display/ui-adapter-eink.js +4 -0
- package/dist/display/ui-adapter-gray.d.ts +8 -0
- package/dist/display/ui-adapter-gray.js +170 -0
- package/dist/display/ui-adapter-mono.d.ts +13 -0
- package/dist/display/ui-adapter-mono.js +230 -0
- package/dist/display/ui-adapter-native.d.ts +10 -0
- package/dist/display/ui-adapter-native.js +295 -0
- package/dist/display/ui-adapter-shared.d.ts +11 -0
- package/dist/display/ui-adapter-shared.js +122 -0
- package/dist/display/ui-adapter.js +510 -558
- package/dist/doctor.js +4 -4
- package/dist/dt-config/custom-board.js +2 -2
- package/dist/dt-config/kconfig.d.ts +62 -1
- package/dist/dt-config/kconfig.js +141 -38
- package/dist/dt-config/overlay.d.ts +15 -2
- package/dist/dt-config/overlay.js +433 -18
- package/dist/framework.manifest.d.ts +10 -4
- package/dist/framework.manifest.js +133 -17
- package/dist/index.d.ts +2 -0
- package/dist/index.js +14 -6
- package/dist/licenses.d.ts +2 -2
- package/dist/licenses.js +13 -92
- package/dist/lowering/can.d.ts +25 -0
- package/dist/lowering/can.js +97 -0
- package/dist/lowering/clock.d.ts +17 -0
- package/dist/lowering/clock.js +58 -0
- package/dist/lowering/fs.js +1 -1
- package/dist/lowering/gpio.js +0 -32
- package/dist/lowering/hid.d.ts +27 -0
- package/dist/lowering/hid.js +244 -0
- package/dist/lowering/http.js +264 -32
- package/dist/lowering/i2c.d.ts +8 -0
- package/dist/lowering/i2c.js +137 -5
- package/dist/lowering/i2s.d.ts +27 -0
- package/dist/lowering/i2s.js +98 -0
- package/dist/lowering/index.d.ts +9 -1
- package/dist/lowering/index.js +25 -1
- package/dist/lowering/interrupts.js +6 -0
- package/dist/lowering/matrix.d.ts +15 -0
- package/dist/lowering/matrix.js +63 -0
- package/dist/lowering/mqtt.js +110 -8
- package/dist/lowering/power.d.ts +3 -2
- package/dist/lowering/power.js +20 -45
- package/dist/lowering/pwm.js +25 -0
- package/dist/lowering/sensor.d.ts +2 -2
- package/dist/lowering/sensor.js +8 -4
- package/dist/lowering/strip.d.ts +16 -0
- package/dist/lowering/strip.js +70 -0
- package/dist/lowering/thread.js +5 -1
- package/dist/lowering/trace.d.ts +44 -0
- package/dist/lowering/trace.js +239 -0
- package/dist/lowering/uart.js +6 -1
- package/dist/lowering/usb.d.ts +3 -1
- package/dist/lowering/usb.js +16 -13
- package/dist/lowering/wdt.js +2 -29
- package/dist/sbom.d.ts +181 -0
- package/dist/sbom.js +901 -0
- package/dist/sdk/board-catalog-sync.d.ts +1 -3
- package/dist/sdk/board-catalog-sync.js +4 -10
- package/dist/strategy.d.ts +82 -46
- package/dist/strategy.js +639 -182
- package/dist/tmp-probe.d.ts +2 -0
- package/dist/tmp-probe.js +9 -0
- package/dist/toolchain/debug-config.d.ts +50 -90
- package/dist/toolchain/debug-config.js +239 -510
- package/dist/toolchain/env-check.d.ts +1 -3
- package/dist/toolchain/env-check.js +2 -7
- package/dist/toolchain/index.d.ts +28 -3
- package/dist/toolchain/index.js +498 -62
- package/dist/toolchain/runners.d.ts +16 -0
- package/dist/toolchain/runners.js +75 -0
- package/dist/toolchain/scaffold.d.ts +5 -2
- package/dist/toolchain/scaffold.js +79 -15
- package/dist/toolchain/west-discover.d.ts +6 -0
- package/dist/toolchain/west-discover.js +36 -13
- package/dist/toolchain/west-spawn.js +8 -2
- package/dist/west-inventory.d.ts +25 -0
- package/dist/west-inventory.js +97 -0
- package/installer/README.md +328 -328
- package/installer/install.sh +2 -2
- package/installer/templates/project/.typecad/activate-zephyr.ps1 +1 -1
- package/installer/templates/project/.typecad/activate-zephyr.sh +1 -1
- package/installer/templates/project/.vscode/settings.json +1 -1
- package/installer/templates/project/README.md +2 -2
- package/package.json +5 -5
- package/src/as-built.ts +206 -206
- package/src/audit.ts +529 -0
- package/src/boardgen.ts +265 -50
- package/src/chips/resolve.ts +21 -0
- package/src/chips/types.ts +10 -1
- package/src/display/bindings.ts +347 -0
- package/src/display/gfx.ts +318 -306
- package/src/display/index.ts +87 -70
- package/src/display/mipi-dbi-host.ts +183 -0
- package/src/display/profiles.ts +458 -139
- package/src/display/touch-adapter.ts +119 -49
- package/src/display/ui-adapter-eink.ts +13 -0
- package/src/display/ui-adapter-gray.ts +178 -0
- package/src/display/ui-adapter-mono.ts +238 -0
- package/src/display/ui-adapter-native.ts +304 -0
- package/src/display/ui-adapter-shared.ts +125 -0
- package/src/display/ui-adapter.ts +732 -781
- package/src/doctor.ts +4 -4
- package/src/dt-config/custom-board.ts +2 -2
- package/src/dt-config/kconfig.ts +647 -505
- package/src/dt-config/overlay.ts +1475 -1058
- package/src/framework.manifest.ts +659 -535
- package/src/index.ts +16 -6
- package/src/licenses.ts +346 -425
- package/src/lowering/can.ts +140 -0
- package/src/lowering/clock.ts +91 -0
- package/src/lowering/fs.ts +135 -135
- package/src/lowering/gpio.ts +0 -33
- package/src/lowering/hid.ts +261 -0
- package/src/lowering/http.ts +264 -32
- package/src/lowering/i2c.ts +142 -5
- package/src/lowering/i2s.ts +143 -0
- package/src/lowering/index.ts +18 -1
- package/src/lowering/interrupts.ts +6 -0
- package/src/lowering/matrix.ts +70 -0
- package/src/lowering/mqtt.ts +109 -8
- package/src/lowering/power.ts +41 -0
- package/src/lowering/pwm.ts +192 -167
- package/src/lowering/sensor.ts +159 -155
- package/src/lowering/strip.ts +81 -0
- package/src/lowering/thread.ts +5 -1
- package/src/lowering/trace.ts +270 -0
- package/src/lowering/uart.ts +6 -1
- package/src/lowering/usb.ts +16 -13
- package/src/lowering/wdt.ts +2 -25
- package/src/sbom.ts +1117 -0
- package/src/sdk/board-catalog-sync.ts +4 -25
- package/src/strategy.ts +2680 -2309
- package/src/toolchain/debug-config.ts +262 -522
- package/src/toolchain/env-check.ts +279 -285
- package/src/toolchain/index.ts +1792 -1359
- package/src/toolchain/runners.ts +80 -0
- package/src/toolchain/scaffold.ts +355 -296
- package/src/toolchain/west-discover.ts +35 -13
- package/src/toolchain/west-spawn.ts +174 -168
- package/src/west-inventory.ts +102 -0
- package/dist/async/timer-polyfill.d.ts +0 -10
- package/dist/async/timer-polyfill.js +0 -95
- package/dist/chips/board-overrides.d.ts +0 -7
- package/dist/chips/board-overrides.js +0 -11
- package/dist/chips/esp32.d.ts +0 -2
- package/dist/chips/esp32.js +0 -71
- package/dist/chips/esp32s3.d.ts +0 -2
- package/dist/chips/esp32s3.js +0 -103
- package/dist/chips/soc/.d.ts +0 -2
- package/dist/chips/soc/.js +0 -129
- package/dist/chips/soc/esp32.d.ts +0 -2
- package/dist/chips/soc/esp32.js +0 -120
- package/dist/chips/soc/esp32c3.d.ts +0 -2
- package/dist/chips/soc/esp32c3.js +0 -90
- package/dist/chips/soc/esp32c6.d.ts +0 -2
- package/dist/chips/soc/esp32c6.js +0 -109
- package/dist/chips/soc/esp32s3.d.ts +0 -2
- package/dist/chips/soc/esp32s3.js +0 -189
- package/dist/chips/soc/index.d.ts +0 -2
- package/dist/chips/soc/index.js +0 -23
- package/dist/chips/soc/nrf52840.d.ts +0 -2
- package/dist/chips/soc/nrf52840.js +0 -130
- package/dist/chips/soc/rp2040.d.ts +0 -2
- package/dist/chips/soc/rp2040.js +0 -141
- package/dist/chips/soc/rp2350a.d.ts +0 -2
- package/dist/chips/soc/rp2350a.js +0 -145
- package/dist/chips/soc/samd21g18a.d.ts +0 -2
- package/dist/chips/soc/samd21g18a.js +0 -143
- package/dist/chips/soc/stm32f411xe.d.ts +0 -2
- package/dist/chips/soc/stm32f411xe.js +0 -251
- package/dist/chips/xiao-ble.d.ts +0 -2
- package/dist/chips/xiao-ble.js +0 -100
- package/dist/lowering/pulse.d.ts +0 -7
- package/dist/lowering/pulse.js +0 -51
- package/dist/lowering/tone.d.ts +0 -10
- package/dist/lowering/tone.js +0 -63
- package/dist/lowering/worker-backing.d.ts +0 -14
- package/dist/lowering/worker-backing.js +0 -79
- package/dist/lowering/worker.d.ts +0 -6
- package/dist/lowering/worker.js +0 -14
- package/dist/sdk/board-data.generated.d.ts +0 -2
- package/dist/sdk/board-data.generated.js +0 -4
- package/dist/sdk/catalog-walker.d.ts +0 -90
- package/dist/sdk/catalog-walker.js +0 -682
- package/dist/sdk/dts-reader.d.ts +0 -83
- package/dist/sdk/dts-reader.js +0 -596
- package/src/debug-codegen.ts +0 -207
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HALOpIR } from '@typecad/cuttlefish/api/shared';
|
|
2
|
+
import type { ZephyrChipDescriptor } from '../chips/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Emit the per-strip state. Called from shimLines for each SPI controller
|
|
5
|
+
* the program drives a strip on: one `struct led_rgb` buffer sized by the
|
|
6
|
+
* construction chain length + the DT device handle.
|
|
7
|
+
*/
|
|
8
|
+
export declare function stripInitLines(chip: ZephyrChipDescriptor, busIndex: number, count: number): string[];
|
|
9
|
+
/**
|
|
10
|
+
* Resolve a HAL strip.* op to Zephyr C++.
|
|
11
|
+
* Returns `{ code }` for statement ops.
|
|
12
|
+
*/
|
|
13
|
+
export declare function lowerStrip(op: HALOpIR, chip: ZephyrChipDescriptor): {
|
|
14
|
+
code?: string;
|
|
15
|
+
expression?: string;
|
|
16
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Strip lowering — ws2812-spi child node + led_strip_update_rgb
|
|
3
|
+
//
|
|
4
|
+
// The strip is an spi-device child of one of the board's wired SPI
|
|
5
|
+
// controllers (Zephyr's ws2812-spi driver synthesizes the WS2812 waveform
|
|
6
|
+
// on the bus's MOSI line — the board-equal form: the strip uses whatever
|
|
7
|
+
// pads the board's devicetree routes that SPI to). The shim block declares
|
|
8
|
+
// the pixel buffer + device handle; the overlay generator synthesizes the
|
|
9
|
+
// DT child node (chain length + tuned frames — see dt-config/overlay.ts).
|
|
10
|
+
// set/fill edit the buffer; show() is one led_strip_update_rgb.
|
|
11
|
+
// ----------------------------------------------------------------------------
|
|
12
|
+
import { parseControllerIndex } from './util.js';
|
|
13
|
+
/** The C variable names for a strip on controller index `idx`. */
|
|
14
|
+
function stripVars(idx) {
|
|
15
|
+
return { buf: `__tc_strip${idx}_buf`, dev: `__tc_strip${idx}_dev` };
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Emit the per-strip state. Called from shimLines for each SPI controller
|
|
19
|
+
* the program drives a strip on: one `struct led_rgb` buffer sized by the
|
|
20
|
+
* construction chain length + the DT device handle.
|
|
21
|
+
*/
|
|
22
|
+
export function stripInitLines(chip, busIndex, count) {
|
|
23
|
+
const ctrl = chip.spi?.controllers[busIndex];
|
|
24
|
+
if (!ctrl)
|
|
25
|
+
return [];
|
|
26
|
+
const { buf, dev } = stripVars(busIndex);
|
|
27
|
+
return [
|
|
28
|
+
'// CUTTLEFISH_STRIP_BEGIN',
|
|
29
|
+
`static struct led_rgb ${buf}[${count}];`,
|
|
30
|
+
`static const struct device* ${dev} = DEVICE_DT_GET(DT_NODELABEL(tc_strip${busIndex}));`,
|
|
31
|
+
'// CUTTLEFISH_STRIP_END',
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Resolve a HAL strip.* op to Zephyr C++.
|
|
36
|
+
* Returns `{ code }` for statement ops.
|
|
37
|
+
*/
|
|
38
|
+
export function lowerStrip(op, chip) {
|
|
39
|
+
const o = op;
|
|
40
|
+
// DAC discipline: a board with no wired SPI (or an out-of-range bus)
|
|
41
|
+
// lowers to a comment naming the constraint — the honest per-board answer
|
|
42
|
+
// (the manifest probe runs boardless; profileDiagnostics flags the usage).
|
|
43
|
+
const idx = parseControllerIndex(typeof o.bus === 'string' ? o.bus : String(o.bus));
|
|
44
|
+
if (!chip.spi || idx >= chip.spi.controllers.length) {
|
|
45
|
+
const wired = chip.spi ? `this board wires ${chip.spi.controllers.length} SPI controller(s)` : 'this board wires no SPI controller';
|
|
46
|
+
return { code: `/* strip on bus ${o.bus}: no such SPI controller — ${wired}; a Strip rides one of the board's SPI buses */` };
|
|
47
|
+
}
|
|
48
|
+
const { buf, dev } = stripVars(idx);
|
|
49
|
+
const count = Number(o.count ?? 1) || 1;
|
|
50
|
+
switch (op.operation) {
|
|
51
|
+
case 'strip.set_pixel': {
|
|
52
|
+
// Buffer assignment — runtime index and channel values splice as C++.
|
|
53
|
+
// The driver applies the strip's color order (GRB mapping) at show.
|
|
54
|
+
return {
|
|
55
|
+
code: `{ uint32_t __tc_strip_i = static_cast<uint32_t>(${o.index}); if (__tc_strip_i < ${count}U) { ${buf}[__tc_strip_i].r = static_cast<uint8_t>(${o.r}); ${buf}[__tc_strip_i].g = static_cast<uint8_t>(${o.g}); ${buf}[__tc_strip_i].b = static_cast<uint8_t>(${o.b}); } }`,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
case 'strip.fill': {
|
|
59
|
+
return {
|
|
60
|
+
code: `{ for (uint32_t __tc_strip_j = 0U; __tc_strip_j < ${count}U; ++__tc_strip_j) { ${buf}[__tc_strip_j].r = static_cast<uint8_t>(${o.r}); ${buf}[__tc_strip_j].g = static_cast<uint8_t>(${o.g}); ${buf}[__tc_strip_j].b = static_cast<uint8_t>(${o.b}); } }`,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
case 'strip.show': {
|
|
64
|
+
return { code: `(void)led_strip_update_rgb(${dev}, ${buf}, ${count}U);` };
|
|
65
|
+
}
|
|
66
|
+
default:
|
|
67
|
+
throw new Error(`framework-zephyr does not yet support HAL op \`${op.operation}\`. ` +
|
|
68
|
+
`Open an issue or use rawCpp() to emit it manually.`);
|
|
69
|
+
}
|
|
70
|
+
}
|
package/dist/lowering/thread.js
CHANGED
|
@@ -42,8 +42,12 @@ export function lowerThread(op) {
|
|
|
42
42
|
case 'thread.start': {
|
|
43
43
|
// Store the entry, create + schedule immediately. The stack size comes
|
|
44
44
|
// from the state block (the construction fact), via K_THREAD_STACK_SIZEOF.
|
|
45
|
+
// The thread gets a name so trace heartbeats report it as something
|
|
46
|
+
// other than "unnamed" — k_thread_name_set returns -ENOSYS without
|
|
47
|
+
// CONFIG_THREAD_NAME (which the scaffold turns on for traced builds),
|
|
48
|
+
// so the call is emitted unconditionally.
|
|
45
49
|
return {
|
|
46
|
-
code: `${p}_fn = (${o.handler}); (void)k_thread_create(&${p}_thread, ${p}_stack, K_THREAD_STACK_SIZEOF(${p}_stack), ${p}_tramp, NULL, NULL, NULL, ${o.priority ?? 5}, 0, K_NO_WAIT);`,
|
|
50
|
+
code: `${p}_fn = (${o.handler}); (void)k_thread_create(&${p}_thread, ${p}_stack, K_THREAD_STACK_SIZEOF(${p}_stack), ${p}_tramp, NULL, NULL, NULL, ${o.priority ?? 5}, 0, K_NO_WAIT); (void)k_thread_name_set(&${p}_thread, "tc_thread_${instance}");`,
|
|
47
51
|
};
|
|
48
52
|
}
|
|
49
53
|
case 'thread.join':
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { HALOpIR } from '@typecad/cuttlefish/api/shared';
|
|
2
|
+
/**
|
|
3
|
+
* Resolve a HAL trace.* op to Zephyr C++. The device helpers
|
|
4
|
+
* (__tc_trace_mark / __tc_trace_event) are emitted unconditionally by
|
|
5
|
+
* shimLines — they are two printf calls, and a Trace.mark() call site must
|
|
6
|
+
* never fail to link because tracing was disabled (the lines simply have no
|
|
7
|
+
* capture listening).
|
|
8
|
+
*/
|
|
9
|
+
export declare function lowerTrace(op: HALOpIR): {
|
|
10
|
+
code?: string;
|
|
11
|
+
expression?: string;
|
|
12
|
+
};
|
|
13
|
+
/** Default heartbeat interval (ms) when zephyr.trace.intervalMs is absent. */
|
|
14
|
+
export declare const TRACE_HB_DEFAULT_INTERVAL_MS = 1000;
|
|
15
|
+
/** Clamp for zephyr.trace.intervalMs — faster than 50 ms floods the console
|
|
16
|
+
* and skews the measured CPU load; slower than a minute adds nothing. */
|
|
17
|
+
export declare function clampTraceIntervalMs(intervalMs: number | undefined): number;
|
|
18
|
+
/**
|
|
19
|
+
* UI frame-time trace block — emitted UNCONDITIONALLY for UI-mounted
|
|
20
|
+
* programs (the call site the emitter stamps after ui_tick must never fail
|
|
21
|
+
* to link), but every body compiles away unless the heartbeat block defined
|
|
22
|
+
* CUTTLEFISH_TRACE_UI (zephyr.trace enabled). Wall-time stats only: frame
|
|
23
|
+
* count / total / max ms per heartbeat interval — the per-phase breakdown
|
|
24
|
+
* inside ui_tick stays a ui-engine change for a later stage.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* On-device alarm thresholds (zephyr.trace.alarms) — the sampler prints
|
|
28
|
+
* [TR:ALARM:<seq>:<code>:<detail>] the moment one is breached, so an
|
|
29
|
+
* untethered device still DETECTS the degradation; reading it only needs a
|
|
30
|
+
* capture (or a serial console) after the fact.
|
|
31
|
+
*/
|
|
32
|
+
export interface TraceAlarmThresholds {
|
|
33
|
+
/** Alarm when a thread's unused stack falls below this (bytes). */
|
|
34
|
+
stackMinBytes?: number;
|
|
35
|
+
/** Alarm when an interval's worst UI frame exceeds this (ms). */
|
|
36
|
+
frameMaxMs?: number;
|
|
37
|
+
}
|
|
38
|
+
export declare function uiFrameTraceLines(frameAlarmMs?: number): string[];
|
|
39
|
+
/**
|
|
40
|
+
* The heartbeat shim lines (definitions + SYS_INIT self-start). Emitted by
|
|
41
|
+
* shimLines when the platform context carries zephyr.trace.enabled.
|
|
42
|
+
* `withUi` adds the [TR:UI: frame-stats line (UI-mounted programs).
|
|
43
|
+
*/
|
|
44
|
+
export declare function traceHeartbeatLines(intervalMs: number, withUi: boolean, alarms?: TraceAlarmThresholds): string[];
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Trace heartbeat — the runtime-stats sampler behind `typecad-hal trace`
|
|
3
|
+
//
|
|
4
|
+
// Emits a self-starting sampler into the ENTRY translation unit only (the
|
|
5
|
+
// block compiles under CUTTLEFISH_ENTRY_TU, which the emitter defines once
|
|
6
|
+
// per program — a copy in a split-file TU would register the SYS_INIT hook
|
|
7
|
+
// twice and double every heartbeat). A k_work_delayable on the system work
|
|
8
|
+
// queue samples, every intervalMs:
|
|
9
|
+
//
|
|
10
|
+
// - per-thread execution cycles (CONFIG_THREAD_RUNTIME_STATS)
|
|
11
|
+
// - per-thread stack unused/size (CONFIG_INIT_STACKS / THREAD_STACK_INFO)
|
|
12
|
+
// - the system-wide cycle counter (k_thread_runtime_stats_all_get — the
|
|
13
|
+
// CPU-time denominator; per-thread CPU% is computed HOST-side as
|
|
14
|
+
// delta_thread_exec / delta_sys_exec, so no cycle/Hz units leak onto
|
|
15
|
+
// the wire and idle shows up as its own thread)
|
|
16
|
+
//
|
|
17
|
+
// and prints `[TR:` lines on the console (printf → STDOUT_CONSOLE, the same
|
|
18
|
+
// channel the test-runner protocol uses). Sampling, not event tracing: the
|
|
19
|
+
// device cost is O(live threads) arithmetic per interval — no context-switch
|
|
20
|
+
// hook, no ring buffer, no per-frame work — so the probe effect on the
|
|
21
|
+
// measured system is one short work-queue visit per interval.
|
|
22
|
+
//
|
|
23
|
+
// Heap usage is deliberately NOT sampled: engine-emitted C++ is no-malloc by
|
|
24
|
+
// construction (AUTOSAR rule set), so a heap series would be a constant line.
|
|
25
|
+
//
|
|
26
|
+
// The whole block also gates on CONFIG_THREAD_MONITOR + CONFIG_THREAD_RUNTIME
|
|
27
|
+
// _STATS: the scaffold enables both when zephyr.trace.enabled is set, but a
|
|
28
|
+
// user override in zephyr.kconfig compiles the sampler out instead of
|
|
29
|
+
// failing the link (k_thread_foreach lives in kernel/thread_monitor.c and
|
|
30
|
+
// only builds under THREAD_MONITOR).
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
/**
|
|
33
|
+
* Resolve a HAL trace.* op to Zephyr C++. The device helpers
|
|
34
|
+
* (__tc_trace_mark / __tc_trace_event) are emitted unconditionally by
|
|
35
|
+
* shimLines — they are two printf calls, and a Trace.mark() call site must
|
|
36
|
+
* never fail to link because tracing was disabled (the lines simply have no
|
|
37
|
+
* capture listening).
|
|
38
|
+
*/
|
|
39
|
+
export function lowerTrace(op) {
|
|
40
|
+
const o = op;
|
|
41
|
+
switch (op.operation) {
|
|
42
|
+
case 'trace.mark':
|
|
43
|
+
return { code: `__tc_trace_mark(${o.name ?? '""'});` };
|
|
44
|
+
case 'trace.event':
|
|
45
|
+
// The value may be a runtime expression (variable, ternary) — the
|
|
46
|
+
// plugin resolved it as text; interpolate inside static_cast so any
|
|
47
|
+
// numeric C++ expression is valid here.
|
|
48
|
+
return { code: `__tc_trace_event(${o.name ?? '""'}, static_cast<double>(${o.value ?? 0}));` };
|
|
49
|
+
default:
|
|
50
|
+
throw new Error(`framework-zephyr does not yet support HAL op \`${op.operation}\`. ` +
|
|
51
|
+
`Open an issue or use rawCpp() to emit it manually.`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** Default heartbeat interval (ms) when zephyr.trace.intervalMs is absent. */
|
|
55
|
+
export const TRACE_HB_DEFAULT_INTERVAL_MS = 1000;
|
|
56
|
+
/** Clamp for zephyr.trace.intervalMs — faster than 50 ms floods the console
|
|
57
|
+
* and skews the measured CPU load; slower than a minute adds nothing. */
|
|
58
|
+
export function clampTraceIntervalMs(intervalMs) {
|
|
59
|
+
if (typeof intervalMs !== 'number' || !Number.isFinite(intervalMs)) {
|
|
60
|
+
return TRACE_HB_DEFAULT_INTERVAL_MS;
|
|
61
|
+
}
|
|
62
|
+
return Math.min(60_000, Math.max(50, Math.round(intervalMs)));
|
|
63
|
+
}
|
|
64
|
+
export function uiFrameTraceLines(frameAlarmMs) {
|
|
65
|
+
const alarmDefine = frameAlarmMs !== undefined ? [`#define __TC_TRACE_ALARM_FRAME ${frameAlarmMs}U`] : [];
|
|
66
|
+
const frameAlarm = frameAlarmMs !== undefined
|
|
67
|
+
? [
|
|
68
|
+
' // Continual monitoring: the worst frame breaching the ceiling is an',
|
|
69
|
+
' // alarm, not a statistic — printed the moment it happens.',
|
|
70
|
+
' if (__tc_trace_ui_max_ms > __TC_TRACE_ALARM_FRAME) {',
|
|
71
|
+
' printf("[TR:ALARM:%u:frame:%u\\n", static_cast<unsigned int>(seq),',
|
|
72
|
+
' static_cast<unsigned int>(__tc_trace_ui_max_ms));',
|
|
73
|
+
' }',
|
|
74
|
+
]
|
|
75
|
+
: [];
|
|
76
|
+
return [
|
|
77
|
+
'// CUTTLEFISH_TRACE_UI_BEGIN',
|
|
78
|
+
'#if defined(CUTTLEFISH_TRACE_UI)',
|
|
79
|
+
...alarmDefine,
|
|
80
|
+
'static uint32_t __tc_trace_ui_frames = 0U;',
|
|
81
|
+
'static uint32_t __tc_trace_ui_total_ms = 0U;',
|
|
82
|
+
'static uint32_t __tc_trace_ui_max_ms = 0U;',
|
|
83
|
+
'static uint64_t __tc_trace_ui_phase[5];',
|
|
84
|
+
'#endif',
|
|
85
|
+
'static inline void __tc_trace_ui_frame(uint32_t frame_delta_ms) {',
|
|
86
|
+
'#if defined(CUTTLEFISH_TRACE_UI)',
|
|
87
|
+
' __tc_trace_ui_frames += 1U;',
|
|
88
|
+
' __tc_trace_ui_total_ms += frame_delta_ms;',
|
|
89
|
+
' if (frame_delta_ms > __tc_trace_ui_max_ms) { __tc_trace_ui_max_ms = frame_delta_ms; }',
|
|
90
|
+
'#else',
|
|
91
|
+
' (void)frame_delta_ms;',
|
|
92
|
+
'#endif',
|
|
93
|
+
'}',
|
|
94
|
+
// Called from the seams the ui-engine's emitTick interleaves between its
|
|
95
|
+
// five phase slices (bindings / transitions / draw / scroll / flush).
|
|
96
|
+
// Cycles are accumulated raw; the report converts to µs once per
|
|
97
|
+
// heartbeat via sys_clock_hw_cycles_per_sec().
|
|
98
|
+
'static inline void __tc_trace_ui_phase_add(uint8_t idx, uint64_t cycles) {',
|
|
99
|
+
'#if defined(CUTTLEFISH_TRACE_UI)',
|
|
100
|
+
' if (idx < 5U) { __tc_trace_ui_phase[idx] += cycles; }',
|
|
101
|
+
'#else',
|
|
102
|
+
' (void)idx; (void)cycles;',
|
|
103
|
+
'#endif',
|
|
104
|
+
'}',
|
|
105
|
+
'static inline void __tc_trace_ui_report(uint32_t seq) {',
|
|
106
|
+
'#if defined(CUTTLEFISH_TRACE_UI)',
|
|
107
|
+
' if (__tc_trace_ui_frames > 0U) {',
|
|
108
|
+
' const uint32_t avg_x10 = (__tc_trace_ui_total_ms * 10U) / __tc_trace_ui_frames;',
|
|
109
|
+
' printf("[TR:UI:%u:%u:%u:%u\\n", static_cast<unsigned int>(seq),',
|
|
110
|
+
' static_cast<unsigned int>(__tc_trace_ui_frames),',
|
|
111
|
+
' static_cast<unsigned int>(avg_x10),',
|
|
112
|
+
' static_cast<unsigned int>(__tc_trace_ui_max_ms));',
|
|
113
|
+
' printf("[TR:UP:%u:%llu:%llu:%llu:%llu:%llu\\n", static_cast<unsigned int>(seq),',
|
|
114
|
+
' static_cast<unsigned long long>((__tc_trace_ui_phase[0] * 1000000ULL) / sys_clock_hw_cycles_per_sec()),',
|
|
115
|
+
' static_cast<unsigned long long>((__tc_trace_ui_phase[1] * 1000000ULL) / sys_clock_hw_cycles_per_sec()),',
|
|
116
|
+
' static_cast<unsigned long long>((__tc_trace_ui_phase[2] * 1000000ULL) / sys_clock_hw_cycles_per_sec()),',
|
|
117
|
+
' static_cast<unsigned long long>((__tc_trace_ui_phase[3] * 1000000ULL) / sys_clock_hw_cycles_per_sec()),',
|
|
118
|
+
' static_cast<unsigned long long>((__tc_trace_ui_phase[4] * 1000000ULL) / sys_clock_hw_cycles_per_sec()));',
|
|
119
|
+
...frameAlarm,
|
|
120
|
+
' }',
|
|
121
|
+
'#else',
|
|
122
|
+
' (void)seq;',
|
|
123
|
+
'#endif',
|
|
124
|
+
'}',
|
|
125
|
+
'static inline void __tc_trace_ui_reset(void) {',
|
|
126
|
+
'#if defined(CUTTLEFISH_TRACE_UI)',
|
|
127
|
+
' __tc_trace_ui_frames = 0U;',
|
|
128
|
+
' __tc_trace_ui_total_ms = 0U;',
|
|
129
|
+
' __tc_trace_ui_max_ms = 0U;',
|
|
130
|
+
' for (uint8_t i = 0U; i < 5U; i++) { __tc_trace_ui_phase[i] = 0ULL; }',
|
|
131
|
+
'#endif',
|
|
132
|
+
'}',
|
|
133
|
+
'// CUTTLEFISH_TRACE_UI_END',
|
|
134
|
+
];
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The heartbeat shim lines (definitions + SYS_INIT self-start). Emitted by
|
|
138
|
+
* shimLines when the platform context carries zephyr.trace.enabled.
|
|
139
|
+
* `withUi` adds the [TR:UI: frame-stats line (UI-mounted programs).
|
|
140
|
+
*/
|
|
141
|
+
export function traceHeartbeatLines(intervalMs, withUi, alarms) {
|
|
142
|
+
const ms = clampTraceIntervalMs(intervalMs);
|
|
143
|
+
const stackAlarmDefine = alarms?.stackMinBytes !== undefined
|
|
144
|
+
? [`#define __TC_TRACE_ALARM_STACK ${alarms.stackMinBytes}U`]
|
|
145
|
+
: [];
|
|
146
|
+
const stackAlarm = alarms?.stackMinBytes !== undefined
|
|
147
|
+
? [
|
|
148
|
+
' // Continual monitoring: headroom under the floor is an alarm, printed',
|
|
149
|
+
' // the moment the sampler sees it (once per interval while held).',
|
|
150
|
+
'#ifdef __TC_TRACE_ALARM_STACK',
|
|
151
|
+
' if (stack_ok && unused < __TC_TRACE_ALARM_STACK) {',
|
|
152
|
+
' printf("[TR:ALARM:%u:stack:%s:%u\\n", static_cast<unsigned int>(seq), name,',
|
|
153
|
+
' static_cast<unsigned int>(unused));',
|
|
154
|
+
' }',
|
|
155
|
+
'#endif',
|
|
156
|
+
]
|
|
157
|
+
: [];
|
|
158
|
+
return [
|
|
159
|
+
'// CUTTLEFISH_TRACE_BEGIN',
|
|
160
|
+
'#if defined(CUTTLEFISH_ENTRY_TU) && defined(CONFIG_THREAD_MONITOR) && defined(CONFIG_THREAD_RUNTIME_STATS)',
|
|
161
|
+
`#define __TC_TRACE_HB_MS ${ms}U`,
|
|
162
|
+
...stackAlarmDefine,
|
|
163
|
+
'static uint32_t __tc_trace_seq = 0U;',
|
|
164
|
+
// One [TR:TH:<seq>:<name>:<exec>:<unused>:<size>] line per live thread.
|
|
165
|
+
// Stack fields print -1 when the platform cannot inspect that thread
|
|
166
|
+
// (ARC-style NO_UNUSED_STACK_INSPECTION faults) — the host reads the
|
|
167
|
+
// sentinel as "unknown", not zero.
|
|
168
|
+
'static void __tc_trace_thread_line(const struct k_thread* cthread, void* user_data) {',
|
|
169
|
+
' (void)user_data;',
|
|
170
|
+
' // The foreach callback hands out a const thread; the stats/name',
|
|
171
|
+
' // syscalls take k_tid_t (non-const) — the same const_cast Zephyr\'s',
|
|
172
|
+
' // own thread_analyzer performs at this exact boundary.',
|
|
173
|
+
' struct k_thread* thread = const_cast<struct k_thread*>(cthread);',
|
|
174
|
+
' const uint32_t seq = __tc_trace_seq;',
|
|
175
|
+
' k_thread_runtime_stats_t stats;',
|
|
176
|
+
' uint64_t exec = 0U;',
|
|
177
|
+
' if (k_thread_runtime_stats_get(thread, &stats) == 0) {',
|
|
178
|
+
' exec = stats.execution_cycles;',
|
|
179
|
+
' }',
|
|
180
|
+
' size_t unused = 0U;',
|
|
181
|
+
' const bool stack_ok = k_thread_stack_space_get(thread, &unused) == 0;',
|
|
182
|
+
'#ifdef CONFIG_THREAD_STACK_INFO',
|
|
183
|
+
' const size_t size = thread->stack_info.size;',
|
|
184
|
+
'#else',
|
|
185
|
+
' const size_t size = 0U;',
|
|
186
|
+
'#endif',
|
|
187
|
+
' char name[24];',
|
|
188
|
+
' const char* thread_name = k_thread_name_get(thread);',
|
|
189
|
+
' uint32_t n = 0U;',
|
|
190
|
+
' if (thread_name != nullptr) {',
|
|
191
|
+
' for (; thread_name[n] != \'\\0\' && n < (sizeof(name) - 1U); n++) {',
|
|
192
|
+
' const char c = thread_name[n];',
|
|
193
|
+
' const bool plain = (c >= \'a\' && c <= \'z\') || (c >= \'A\' && c <= \'Z\')',
|
|
194
|
+
' || (c >= \'0\' && c <= \'9\') || c == \'_\' || c == \'-\' || c == \'.\';',
|
|
195
|
+
' name[n] = plain ? c : \'_\';',
|
|
196
|
+
' }',
|
|
197
|
+
' }',
|
|
198
|
+
' name[n] = \'\\0\';',
|
|
199
|
+
' if (n == 0U) { name[0] = \'u\'; name[1] = \'n\'; name[2] = \'\\0\'; }',
|
|
200
|
+
' printf("[TR:TH:%u:%s:%llu:%lld:%u\\n",',
|
|
201
|
+
' static_cast<unsigned int>(seq), name,',
|
|
202
|
+
' static_cast<unsigned long long>(exec),',
|
|
203
|
+
' stack_ok ? static_cast<long long>(unused) : -1LL,',
|
|
204
|
+
' static_cast<unsigned int>(size));',
|
|
205
|
+
...stackAlarm,
|
|
206
|
+
'}',
|
|
207
|
+
'static void __tc_trace_hb_work(struct k_work* work);',
|
|
208
|
+
'static K_WORK_DELAYABLE_DEFINE(__tc_trace_hb_dwork, __tc_trace_hb_work);',
|
|
209
|
+
'static void __tc_trace_hb_work(struct k_work* work) {',
|
|
210
|
+
' (void)work;',
|
|
211
|
+
' k_thread_runtime_stats_t all;',
|
|
212
|
+
' uint64_t sys_exec = 0U;',
|
|
213
|
+
' if (k_thread_runtime_stats_all_get(&all) == 0) {',
|
|
214
|
+
' sys_exec = all.execution_cycles;',
|
|
215
|
+
' }',
|
|
216
|
+
' __tc_trace_seq += 1U;',
|
|
217
|
+
' printf("[TR:HB:%u:%u:%llu\\n",',
|
|
218
|
+
' static_cast<unsigned int>(__tc_trace_seq),',
|
|
219
|
+
' static_cast<unsigned int>(k_uptime_get_32()),',
|
|
220
|
+
' static_cast<unsigned long long>(sys_exec));',
|
|
221
|
+
...(withUi
|
|
222
|
+
? [
|
|
223
|
+
' __tc_trace_ui_report(__tc_trace_seq);',
|
|
224
|
+
' __tc_trace_ui_reset();',
|
|
225
|
+
]
|
|
226
|
+
: []),
|
|
227
|
+
' k_thread_foreach(__tc_trace_thread_line, nullptr);',
|
|
228
|
+
' k_work_reschedule(&__tc_trace_hb_dwork, K_MSEC(__TC_TRACE_HB_MS));',
|
|
229
|
+
'}',
|
|
230
|
+
'static int __tc_trace_hb_boot(void) {',
|
|
231
|
+
` printf("[TR:CFG:1:${ms}]\\n");`,
|
|
232
|
+
' k_work_schedule(&__tc_trace_hb_dwork, K_MSEC(__TC_TRACE_HB_MS));',
|
|
233
|
+
' return 0;',
|
|
234
|
+
'}',
|
|
235
|
+
'SYS_INIT(__tc_trace_hb_boot, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);',
|
|
236
|
+
'#endif // CUTTLEFISH_ENTRY_TU && THREAD_MONITOR && THREAD_RUNTIME_STATS',
|
|
237
|
+
'// CUTTLEFISH_TRACE_END',
|
|
238
|
+
];
|
|
239
|
+
}
|
package/dist/lowering/uart.js
CHANGED
|
@@ -26,7 +26,12 @@ export function uartInitLines(chip, controllerIndex) {
|
|
|
26
26
|
'// CUTTLEFISH_UART_BEGIN',
|
|
27
27
|
`static const struct device* ${p}_dev = DEVICE_DT_GET(DT_NODELABEL(${ctrl.nodeLabel}));`,
|
|
28
28
|
`static void ${p}_init(uint32_t baud) {`,
|
|
29
|
-
|
|
29
|
+
// 115200 8N1 is the console default — reconfiguring an already-matching
|
|
30
|
+
// port RESETS the ESP32 UART's TX path and silently eats the FIRST write
|
|
31
|
+
// that follows (poll_out completes into a reconfiguring FIFO). Only a
|
|
32
|
+
// genuinely different rate reconfigures.
|
|
33
|
+
` if (baud == 0U || baud == 115200U) { return; }`,
|
|
34
|
+
` const struct uart_config cfg = { .baudrate = baud, .parity = UART_CFG_PARITY_NONE, .stop_bits = UART_CFG_STOP_BITS_1, .data_bits = UART_CFG_DATA_BITS_8, .flow_ctrl = UART_CFG_FLOW_CTRL_NONE };`,
|
|
30
35
|
` uart_configure(${p}_dev, &cfg);`,
|
|
31
36
|
`}`,
|
|
32
37
|
'// CUTTLEFISH_UART_END',
|
package/dist/lowering/usb.d.ts
CHANGED
|
@@ -16,7 +16,9 @@ import type { ZephyrChipDescriptor } from '../chips/types.js';
|
|
|
16
16
|
* subsys/usb/device_next/Kconfig, include/zephyr/usb/usbd.h, and
|
|
17
17
|
* samples/subsys/usb/common/sample_usbd_init.c.
|
|
18
18
|
*/
|
|
19
|
-
export declare function usbdDeviceLines(chip: ZephyrChipDescriptor
|
|
19
|
+
export declare function usbdDeviceLines(chip: ZephyrChipDescriptor, opts?: {
|
|
20
|
+
hid?: boolean;
|
|
21
|
+
}): string[];
|
|
20
22
|
/**
|
|
21
23
|
* Emit the per-instance CDC device + init helper. Called from shimLines when
|
|
22
24
|
* the program uses USB and the chip declares `usb`; must be paired with one
|
package/dist/lowering/usb.js
CHANGED
|
@@ -44,11 +44,11 @@ function nodeLabel(idx) {
|
|
|
44
44
|
* subsys/usb/device_next/Kconfig, include/zephyr/usb/usbd.h, and
|
|
45
45
|
* samples/subsys/usb/common/sample_usbd_init.c.
|
|
46
46
|
*/
|
|
47
|
-
export function usbdDeviceLines(chip) {
|
|
47
|
+
export function usbdDeviceLines(chip, opts) {
|
|
48
48
|
if (!chip.usb)
|
|
49
49
|
return [];
|
|
50
50
|
const vid = chip.usb.vid ?? '0x2fe3';
|
|
51
|
-
const pid = chip.usb.pid ?? '0x0001';
|
|
51
|
+
const pid = chip.usb.pid ?? (opts?.hid ? '0x0008' : '0x0001');
|
|
52
52
|
// 1200-baud touch-to-reset (BOSSA-bootloader boards): a usbd message
|
|
53
53
|
// callback that reboots into the bootloader when the host sets the CDC
|
|
54
54
|
// baud rate to 1200. Zephyr's CDC-ACM class publishes
|
|
@@ -87,13 +87,13 @@ export function usbdDeviceLines(chip) {
|
|
|
87
87
|
` ${vid}, ${pid});`,
|
|
88
88
|
'USBD_DESC_LANG_DEFINE(__tc_usbd_lang);',
|
|
89
89
|
'USBD_DESC_MANUFACTURER_DEFINE(__tc_usbd_mfr, "typecad");',
|
|
90
|
-
'USBD_DESC_PRODUCT_DEFINE(__tc_usbd_product, "
|
|
90
|
+
'USBD_DESC_PRODUCT_DEFINE(__tc_usbd_product, "typecad-hal app");',
|
|
91
91
|
// Serial number from hwinfo: Windows keys USB devnodes without a serial
|
|
92
92
|
// on the physical port, so flash-cycle re-enumerations reuse stale
|
|
93
93
|
// port-keyed nodes (the "access denied" open wedge). Identity-based
|
|
94
94
|
// instance paths are stable across ports and never hit that pool.
|
|
95
95
|
'USBD_DESC_SERIAL_NUMBER_DEFINE(__tc_usbd_sn);',
|
|
96
|
-
'USBD_DESC_CONFIG_DEFINE(__tc_usbd_cfg_desc, "
|
|
96
|
+
'USBD_DESC_CONFIG_DEFINE(__tc_usbd_cfg_desc, "typecad-hal");',
|
|
97
97
|
'USBD_CONFIGURATION_DEFINE(__tc_usbd_cfg, 0, 250, &__tc_usbd_cfg_desc);',
|
|
98
98
|
'static bool __tc_usbd_started = false;',
|
|
99
99
|
...touchLines,
|
|
@@ -101,17 +101,17 @@ export function usbdDeviceLines(chip) {
|
|
|
101
101
|
' if (__tc_usbd_started) { return; }',
|
|
102
102
|
' __tc_usbd_started = true;',
|
|
103
103
|
' int err = usbd_add_descriptor(&__tc_usbd, &__tc_usbd_lang);',
|
|
104
|
-
' if (err != 0) { printk("
|
|
104
|
+
' if (err != 0) { printk("typecad-hal usb: lang descriptor failed: %d\\n", err); return; }',
|
|
105
105
|
' err = usbd_add_descriptor(&__tc_usbd, &__tc_usbd_sn);',
|
|
106
|
-
' if (err != 0) { printk("
|
|
106
|
+
' if (err != 0) { printk("typecad-hal usb: serial descriptor failed: %d\\n", err); return; }',
|
|
107
107
|
' err = usbd_add_descriptor(&__tc_usbd, &__tc_usbd_mfr);',
|
|
108
|
-
' if (err != 0) { printk("
|
|
108
|
+
' if (err != 0) { printk("typecad-hal usb: manufacturer descriptor failed: %d\\n", err); return; }',
|
|
109
109
|
' err = usbd_add_descriptor(&__tc_usbd, &__tc_usbd_product);',
|
|
110
|
-
' if (err != 0) { printk("
|
|
110
|
+
' if (err != 0) { printk("typecad-hal usb: product descriptor failed: %d\\n", err); return; }',
|
|
111
111
|
' err = usbd_add_configuration(&__tc_usbd, USBD_SPEED_FS, &__tc_usbd_cfg);',
|
|
112
|
-
' if (err != 0) { printk("
|
|
112
|
+
' if (err != 0) { printk("typecad-hal usb: add configuration failed: %d\\n", err); return; }',
|
|
113
113
|
' err = usbd_register_all_classes(&__tc_usbd, USBD_SPEED_FS, 1, NULL);',
|
|
114
|
-
' if (err != 0) { printk("
|
|
114
|
+
' if (err != 0) { printk("typecad-hal usb: register classes failed: %d\\n", err); return; }',
|
|
115
115
|
// Registered before usbd_init so no line-coding event can be missed.
|
|
116
116
|
...touchRegister,
|
|
117
117
|
// usbd_init builds the descriptor tables from the registered
|
|
@@ -119,14 +119,17 @@ export function usbdDeviceLines(chip) {
|
|
|
119
119
|
// refuses with -EPERM ("not initialized") without it (sample_usbd_init.c
|
|
120
120
|
// calls it between setup and enable).
|
|
121
121
|
' err = usbd_init(&__tc_usbd);',
|
|
122
|
-
' if (err != 0) { printk("
|
|
122
|
+
' if (err != 0) { printk("typecad-hal usb: init failed: %d\\n", err); return; }',
|
|
123
123
|
// Boards with VBUS detection start on the VBUS event in the Zephyr
|
|
124
124
|
// sample, via a message callback we do not register; enabling
|
|
125
125
|
// unconditionally (and reporting the error) is the sample's own path
|
|
126
126
|
// for boards without detection (STM32 OTG_FS).
|
|
127
127
|
' err = usbd_enable(&__tc_usbd);',
|
|
128
|
-
' if (err != 0) { printk("
|
|
129
|
-
|
|
128
|
+
' if (err != 0) { printk("typecad-hal usb: enable failed: %d\\n", err); return; }',
|
|
129
|
+
// No success printk: the message interleaves with the hardware-test
|
|
130
|
+
// protocol on the shared uart console (a [TC:EXPECT] line corrupted
|
|
131
|
+
// mid-suite when the HID tests first brought the device up). Failures
|
|
132
|
+
// still print — a broken USB is worth the noise.
|
|
130
133
|
'}',
|
|
131
134
|
'// CUTTLEFISH_USBD_END',
|
|
132
135
|
];
|
package/dist/lowering/wdt.js
CHANGED
|
@@ -6,36 +6,9 @@
|
|
|
6
6
|
// wdt_install_timeout in a static var so wdt.reset can feed it.
|
|
7
7
|
//
|
|
8
8
|
// enable(timeout): wdt_install_timeout + wdt_setup. Zephyr expects the timeout
|
|
9
|
-
// in milliseconds (wdt_window.max)
|
|
10
|
-
//
|
|
9
|
+
// in milliseconds (wdt_window.max); the thin Watchdog (hal/watchdog.ts)
|
|
10
|
+
// construction already carries a plain timeoutMs number.
|
|
11
11
|
// ---------------------------------------------------------------------------
|
|
12
|
-
/** Parse a HAL wdt timeout ("250ms", WDTO_2S, or a bare number) to ms.
|
|
13
|
-
* Tolerates undefined (the manifest validator's probe sends a minimal op)
|
|
14
|
-
* and quote-wrapped strings (resolveSemanticArg can hand the literal's
|
|
15
|
-
* quoted source text through). */
|
|
16
|
-
function timeoutToMs(timeout) {
|
|
17
|
-
if (typeof timeout === 'number')
|
|
18
|
-
return timeout;
|
|
19
|
-
if (!timeout)
|
|
20
|
-
return 1000; // default 1s when absent (e.g. the validator probe)
|
|
21
|
-
timeout = timeout.replace(/^['"]|['"]$/g, '');
|
|
22
|
-
// Arduino WDTO_* constants.
|
|
23
|
-
const wdto = {
|
|
24
|
-
WDTO_15MS: 15, WDTO_30MS: 30, WDTO_60MS: 60, WDTO_120MS: 120,
|
|
25
|
-
WDTO_250MS: 250, WDTO_500MS: 500, WDTO_1S: 1000, WDTO_2S: 2000,
|
|
26
|
-
WDTO_4S: 4000, WDTO_8S: 8000,
|
|
27
|
-
};
|
|
28
|
-
if (wdto[timeout])
|
|
29
|
-
return wdto[timeout];
|
|
30
|
-
const m = timeout.match(/^(\d+)\s*ms$/i);
|
|
31
|
-
if (m)
|
|
32
|
-
return parseInt(m[1], 10);
|
|
33
|
-
const s = timeout.match(/^(\d+)\s*s$/i);
|
|
34
|
-
if (s)
|
|
35
|
-
return parseInt(s[1], 10) * 1000;
|
|
36
|
-
const n = parseInt(timeout, 10);
|
|
37
|
-
return isNaN(n) ? 1000 : n;
|
|
38
|
-
}
|
|
39
12
|
/**
|
|
40
13
|
* Emit the WDT device + channel state. Called from shimLines when the program
|
|
41
14
|
* uses the watchdog.
|