rp2040js 0.19.4 → 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.
Files changed (69) hide show
  1. package/dist/cjs/clock/clock.d.ts +6 -8
  2. package/dist/cjs/clock/mock-clock.d.ts +2 -15
  3. package/dist/cjs/clock/mock-clock.js +4 -46
  4. package/dist/cjs/clock/simulation-clock.d.ts +26 -0
  5. package/dist/cjs/clock/simulation-clock.js +97 -0
  6. package/dist/cjs/cortex-m0-core.d.ts +1 -1
  7. package/dist/cjs/cortex-m0-core.js +39 -37
  8. package/dist/cjs/gdb/gdb-connection.d.ts +1 -1
  9. package/dist/cjs/gdb/gdb-connection.js +2 -2
  10. package/dist/cjs/gdb/gdb-server.d.ts +3 -3
  11. package/dist/cjs/gdb/gdb-server.js +12 -11
  12. package/dist/cjs/gdb/gdb-target.d.ts +7 -0
  13. package/dist/cjs/gdb/gdb-target.js +2 -0
  14. package/dist/cjs/gdb/gdb-tcp-server.d.ts +2 -2
  15. package/dist/cjs/gdb/gdb-tcp-server.js +2 -2
  16. package/dist/cjs/index.d.ts +4 -3
  17. package/dist/cjs/index.js +7 -5
  18. package/dist/cjs/peripherals/adc.d.ts +7 -2
  19. package/dist/cjs/peripherals/adc.js +12 -8
  20. package/dist/cjs/peripherals/dma.d.ts +1 -1
  21. package/dist/cjs/peripherals/dma.js +6 -15
  22. package/dist/cjs/peripherals/rtc.d.ts +1 -1
  23. package/dist/cjs/peripherals/rtc.js +3 -3
  24. package/dist/cjs/peripherals/timer.js +12 -17
  25. package/dist/cjs/peripherals/usb.d.ts +4 -0
  26. package/dist/cjs/peripherals/usb.js +56 -50
  27. package/dist/cjs/rp2040.d.ts +0 -5
  28. package/dist/cjs/rp2040.js +2 -27
  29. package/dist/cjs/simulator.d.ts +13 -0
  30. package/dist/cjs/simulator.js +45 -0
  31. package/dist/cjs/utils/timer32.d.ts +3 -3
  32. package/dist/cjs/utils/timer32.js +14 -16
  33. package/dist/esm/clock/clock.d.ts +6 -8
  34. package/dist/esm/clock/mock-clock.d.ts +2 -15
  35. package/dist/esm/clock/mock-clock.js +3 -44
  36. package/dist/esm/clock/simulation-clock.d.ts +26 -0
  37. package/dist/esm/clock/simulation-clock.js +92 -0
  38. package/dist/esm/cortex-m0-core.d.ts +1 -1
  39. package/dist/esm/cortex-m0-core.js +39 -37
  40. package/dist/esm/gdb/gdb-connection.d.ts +1 -1
  41. package/dist/esm/gdb/gdb-connection.js +2 -2
  42. package/dist/esm/gdb/gdb-server.d.ts +3 -3
  43. package/dist/esm/gdb/gdb-server.js +12 -11
  44. package/dist/esm/gdb/gdb-target.d.ts +7 -0
  45. package/dist/esm/gdb/gdb-target.js +1 -0
  46. package/dist/esm/gdb/gdb-tcp-server.d.ts +2 -2
  47. package/dist/esm/gdb/gdb-tcp-server.js +2 -2
  48. package/dist/esm/index.d.ts +4 -3
  49. package/dist/esm/index.js +2 -1
  50. package/dist/esm/peripherals/adc.d.ts +7 -2
  51. package/dist/esm/peripherals/adc.js +12 -8
  52. package/dist/esm/peripherals/dma.d.ts +1 -1
  53. package/dist/esm/peripherals/dma.js +6 -15
  54. package/dist/esm/peripherals/rtc.d.ts +1 -1
  55. package/dist/esm/peripherals/rtc.js +3 -3
  56. package/dist/esm/peripherals/timer.js +12 -17
  57. package/dist/esm/peripherals/usb.d.ts +4 -0
  58. package/dist/esm/peripherals/usb.js +56 -50
  59. package/dist/esm/rp2040.d.ts +0 -5
  60. package/dist/esm/rp2040.js +2 -27
  61. package/dist/esm/simulator.d.ts +13 -0
  62. package/dist/esm/simulator.js +41 -0
  63. package/dist/esm/utils/timer32.d.ts +3 -3
  64. package/dist/esm/utils/timer32.js +14 -16
  65. package/package.json +1 -1
  66. package/dist/cjs/clock/realtime-clock.d.ts +0 -23
  67. package/dist/cjs/clock/realtime-clock.js +0 -73
  68. package/dist/esm/clock/realtime-clock.d.ts +0 -23
  69. package/dist/esm/clock/realtime-clock.js +0 -68
@@ -8,7 +8,7 @@ export declare class Timer32 {
8
8
  readonly clock: IClock;
9
9
  private baseFreq;
10
10
  private baseValue;
11
- private baseMicros;
11
+ private baseNanos;
12
12
  private topValue;
13
13
  private prescalerValue;
14
14
  private timerMode;
@@ -32,7 +32,7 @@ export declare class Timer32 {
32
32
  set frequency(value: number);
33
33
  get prescaler(): number;
34
34
  set prescaler(value: number);
35
- toMicros(cycles: number): number;
35
+ toNanos(cycles: number): number;
36
36
  get enable(): boolean;
37
37
  set enable(value: boolean);
38
38
  get mode(): TimerMode;
@@ -44,7 +44,7 @@ export declare class Timer32PeriodicAlarm {
44
44
  readonly callback: () => void;
45
45
  private targetValue;
46
46
  private enabled;
47
- private clockTimer?;
47
+ private clockAlarm;
48
48
  constructor(timer: Timer32, callback: () => void);
49
49
  get enable(): boolean;
50
50
  set enable(value: boolean);
@@ -12,7 +12,7 @@ class Timer32 {
12
12
  this.clock = clock;
13
13
  this.baseFreq = baseFreq;
14
14
  this.baseValue = 0;
15
- this.baseMicros = 0;
15
+ this.baseNanos = 0;
16
16
  this.topValue = 0xffffffff;
17
17
  this.prescalerValue = 1;
18
18
  this.timerMode = TimerMode.Increment;
@@ -20,13 +20,13 @@ class Timer32 {
20
20
  this.listeners = [];
21
21
  }
22
22
  reset() {
23
- this.baseMicros = this.clock.micros;
23
+ this.baseNanos = this.clock.nanos;
24
24
  this.baseValue = 0;
25
25
  this.updated();
26
26
  }
27
27
  set(value, zigZagDown = false) {
28
28
  this.baseValue = zigZagDown ? this.topValue * 2 - value : value;
29
- this.baseMicros = this.clock.micros;
29
+ this.baseNanos = this.clock.nanos;
30
30
  this.updated();
31
31
  }
32
32
  /**
@@ -39,12 +39,12 @@ class Timer32 {
39
39
  this.baseValue += delta;
40
40
  }
41
41
  get rawCounter() {
42
- const { baseFreq, prescalerValue, baseMicros, baseValue, enabled, timerMode } = this;
42
+ const { baseFreq, prescalerValue, baseNanos, baseValue, enabled, timerMode } = this;
43
43
  if (!baseFreq || !prescalerValue || !enabled) {
44
44
  return this.baseValue;
45
45
  }
46
46
  const zigzag = timerMode == TimerMode.ZigZag;
47
- const ticks = ((this.clock.micros - baseMicros) / 1e6) * (baseFreq / prescalerValue);
47
+ const ticks = ((this.clock.nanos - baseNanos) / 1e9) * (baseFreq / prescalerValue);
48
48
  const topModulo = zigzag ? this.topValue * 2 : this.topValue + 1;
49
49
  const delta = timerMode == TimerMode.Decrement ? topModulo - (ticks % topModulo) : ticks;
50
50
  let currentValue = Math.round(baseValue + delta);
@@ -73,7 +73,7 @@ class Timer32 {
73
73
  }
74
74
  set frequency(value) {
75
75
  this.baseValue = this.counter;
76
- this.baseMicros = this.clock.micros;
76
+ this.baseNanos = this.clock.nanos;
77
77
  this.baseFreq = value;
78
78
  this.updated();
79
79
  }
@@ -82,14 +82,14 @@ class Timer32 {
82
82
  }
83
83
  set prescaler(value) {
84
84
  this.baseValue = this.counter;
85
- this.baseMicros = this.clock.micros;
85
+ this.baseNanos = this.clock.nanos;
86
86
  this.enabled = this.prescalerValue !== 0;
87
87
  this.prescalerValue = value;
88
88
  this.updated();
89
89
  }
90
- toMicros(cycles) {
90
+ toNanos(cycles) {
91
91
  const { baseFreq, prescalerValue } = this;
92
- return (cycles * 1e6) / (baseFreq / prescalerValue);
92
+ return (cycles * 1e9) / (baseFreq / prescalerValue);
93
93
  }
94
94
  get enable() {
95
95
  return this.enabled;
@@ -97,7 +97,7 @@ class Timer32 {
97
97
  set enable(value) {
98
98
  if (value !== this.enabled) {
99
99
  if (value) {
100
- this.baseMicros = this.clock.micros;
100
+ this.baseNanos = this.clock.nanos;
101
101
  }
102
102
  else {
103
103
  this.baseValue = this.counter;
@@ -141,6 +141,7 @@ class Timer32PeriodicAlarm {
141
141
  this.schedule();
142
142
  }
143
143
  };
144
+ this.clockAlarm = this.timer.clock.createAlarm(this.handleAlarm);
144
145
  timer.listeners.push(this.update);
145
146
  }
146
147
  get enable() {
@@ -195,14 +196,11 @@ class Timer32PeriodicAlarm {
195
196
  cycleDelta = top + 1 - cycleDelta;
196
197
  }
197
198
  const cyclesToAlarm = cycleDelta >>> 0;
198
- const microsToAlarm = timer.toMicros(cyclesToAlarm);
199
- this.clockTimer = this.timer.clock.createTimer(microsToAlarm, this.handleAlarm);
199
+ const nanosToAlarm = timer.toNanos(cyclesToAlarm);
200
+ this.clockAlarm.schedule(nanosToAlarm);
200
201
  }
201
202
  cancel() {
202
- if (this.clockTimer) {
203
- this.timer.clock.deleteTimer(this.clockTimer);
204
- this.clockTimer = undefined;
205
- }
203
+ this.clockAlarm.cancel();
206
204
  }
207
205
  }
208
206
  exports.Timer32PeriodicAlarm = Timer32PeriodicAlarm;
@@ -1,11 +1,9 @@
1
- export interface IClockTimer {
2
- pause(currentMicros: number): void;
3
- resume(currentMicros: number): void;
1
+ export type AlarmCallback = () => void;
2
+ export interface IAlarm {
3
+ schedule(deltaNanos: number): void;
4
+ cancel(): void;
4
5
  }
5
6
  export interface IClock {
6
- readonly micros: number;
7
- pause(): void;
8
- resume(): void;
9
- createTimer(deltaMicros: number, callback: () => void): IClockTimer;
10
- deleteTimer(timer: IClockTimer): void;
7
+ readonly nanos: number;
8
+ createAlarm(callback: AlarmCallback): IAlarm;
11
9
  }
@@ -1,17 +1,4 @@
1
- import { IClock, IClockTimer } from './clock.js';
2
- export declare class MockClockTimer implements IClockTimer {
3
- readonly micros: number;
4
- readonly callback: () => void;
5
- constructor(micros: number, callback: () => void);
6
- pause(): void;
7
- resume(): void;
8
- }
9
- export declare class MockClock implements IClock {
10
- micros: number;
11
- readonly timers: MockClockTimer[];
12
- pause(): void;
13
- resume(): void;
1
+ import { SimulationClock } from './simulation-clock.js';
2
+ export declare class MockClock extends SimulationClock {
14
3
  advance(deltaMicros: number): void;
15
- createTimer(deltaMicros: number, callback: () => void): MockClockTimer;
16
- deleteTimer(timer: IClockTimer): void;
17
4
  }
@@ -1,47 +1,6 @@
1
- export class MockClockTimer {
2
- constructor(micros, callback) {
3
- this.micros = micros;
4
- this.callback = callback;
5
- }
6
- pause() {
7
- /* intentionally empty */
8
- }
9
- resume() {
10
- /* intentionally empty */
11
- }
12
- }
13
- export class MockClock {
14
- constructor() {
15
- this.micros = 0;
16
- this.timers = [];
17
- }
18
- pause() {
19
- /* intentionally empty */
20
- }
21
- resume() {
22
- /* intentionally empty */
23
- }
1
+ import { SimulationClock } from './simulation-clock.js';
2
+ export class MockClock extends SimulationClock {
24
3
  advance(deltaMicros) {
25
- const { timers } = this;
26
- const targetTime = this.micros + Math.max(deltaMicros, 0.01);
27
- while (timers[0] && timers[0].micros <= targetTime) {
28
- const timer = timers.shift();
29
- if (timer) {
30
- this.micros = timer.micros;
31
- timer.callback();
32
- }
33
- }
34
- }
35
- createTimer(deltaMicros, callback) {
36
- const timer = new MockClockTimer(this.micros + deltaMicros, callback);
37
- this.timers.push(timer);
38
- this.timers.sort((a, b) => a.micros - b.micros);
39
- return timer;
40
- }
41
- deleteTimer(timer) {
42
- const timerIndex = this.timers.indexOf(timer);
43
- if (timerIndex >= 0) {
44
- this.timers.splice(timerIndex, 1);
45
- }
4
+ this.tick(this.nanos + deltaMicros * 1000);
46
5
  }
47
6
  }
@@ -0,0 +1,26 @@
1
+ import { AlarmCallback, IAlarm, IClock } from './clock.js';
2
+ type ClockEventCallback = () => void;
3
+ export declare class ClockAlarm implements IAlarm {
4
+ private readonly clock;
5
+ readonly callback: AlarmCallback;
6
+ next: ClockAlarm | null;
7
+ nanos: number;
8
+ scheduled: boolean;
9
+ constructor(clock: SimulationClock, callback: AlarmCallback);
10
+ schedule(deltaNanos: number): void;
11
+ cancel(): void;
12
+ }
13
+ export declare class SimulationClock implements IClock {
14
+ readonly frequency: number;
15
+ private nextAlarm;
16
+ private nanosCounter;
17
+ constructor(frequency?: number);
18
+ get nanos(): number;
19
+ get micros(): number;
20
+ createAlarm(callback: ClockEventCallback): ClockAlarm;
21
+ linkAlarm(nanos: number, alarm: ClockAlarm): ClockAlarm;
22
+ unlinkAlarm(alarm: ClockAlarm): boolean;
23
+ tick(deltaNanos: number): void;
24
+ get nanosToNextAlarm(): number;
25
+ }
26
+ export {};
@@ -0,0 +1,92 @@
1
+ export class ClockAlarm {
2
+ constructor(clock, callback) {
3
+ this.clock = clock;
4
+ this.callback = callback;
5
+ this.next = null;
6
+ this.nanos = 0;
7
+ this.scheduled = false;
8
+ }
9
+ schedule(deltaNanos) {
10
+ if (this.scheduled) {
11
+ this.cancel();
12
+ }
13
+ this.clock.linkAlarm(deltaNanos, this);
14
+ }
15
+ cancel() {
16
+ this.clock.unlinkAlarm(this);
17
+ this.scheduled = false;
18
+ }
19
+ }
20
+ export class SimulationClock {
21
+ constructor(frequency = 125e6) {
22
+ this.frequency = frequency;
23
+ this.nextAlarm = null;
24
+ this.nanosCounter = 0;
25
+ }
26
+ get nanos() {
27
+ return this.nanosCounter;
28
+ }
29
+ get micros() {
30
+ return this.nanos / 1000;
31
+ }
32
+ createAlarm(callback) {
33
+ return new ClockAlarm(this, callback);
34
+ }
35
+ linkAlarm(nanos, alarm) {
36
+ alarm.nanos = this.nanos + nanos;
37
+ let alarmListItem = this.nextAlarm;
38
+ let lastItem = null;
39
+ while (alarmListItem && alarmListItem.nanos < alarm.nanos) {
40
+ lastItem = alarmListItem;
41
+ alarmListItem = alarmListItem.next;
42
+ }
43
+ if (lastItem) {
44
+ lastItem.next = alarm;
45
+ alarm.next = alarmListItem;
46
+ }
47
+ else {
48
+ this.nextAlarm = alarm;
49
+ alarm.next = alarmListItem;
50
+ }
51
+ alarm.scheduled = true;
52
+ return alarm;
53
+ }
54
+ unlinkAlarm(alarm) {
55
+ let alarmListItem = this.nextAlarm;
56
+ if (!alarmListItem) {
57
+ return false;
58
+ }
59
+ let lastItem = null;
60
+ while (alarmListItem) {
61
+ if (alarmListItem === alarm) {
62
+ if (lastItem) {
63
+ lastItem.next = alarmListItem.next;
64
+ }
65
+ else {
66
+ this.nextAlarm = alarmListItem.next;
67
+ }
68
+ return true;
69
+ }
70
+ lastItem = alarmListItem;
71
+ alarmListItem = alarmListItem.next;
72
+ }
73
+ return false;
74
+ }
75
+ tick(deltaNanos) {
76
+ const targetNanos = this.nanosCounter + deltaNanos;
77
+ let alarm = this.nextAlarm;
78
+ while (alarm && alarm.nanos <= targetNanos) {
79
+ this.nextAlarm = alarm.next;
80
+ this.nanosCounter = alarm.nanos;
81
+ alarm.callback();
82
+ alarm = this.nextAlarm;
83
+ }
84
+ this.nanosCounter = targetNanos;
85
+ }
86
+ get nanosToNextAlarm() {
87
+ if (this.nextAlarm) {
88
+ return this.nextAlarm.nanos - this.nanos;
89
+ }
90
+ return 0;
91
+ }
92
+ }
@@ -82,6 +82,6 @@ export declare class CortexM0Core {
82
82
  private substractUpdateFlags;
83
83
  private addUpdateFlags;
84
84
  cyclesIO(addr: number, write?: boolean): 0 | 1 | 3 | 4;
85
- executeInstruction(): void;
85
+ executeInstruction(): number;
86
86
  }
87
87
  export {};
@@ -526,7 +526,7 @@ export class CortexM0Core {
526
526
  const wideInstruction = opcode >> 12 === 0b1111 || opcode >> 11 === 0b11101;
527
527
  const opcode2 = wideInstruction ? this.readUint16(opcodePC + 2) : 0;
528
528
  this.PC += 2;
529
- this.cycles++;
529
+ let deltaCycles = 1;
530
530
  // ADCS
531
531
  if (opcode >> 6 === 0b0100000101) {
532
532
  const Rm = (opcode >> 3) & 0x7;
@@ -576,7 +576,7 @@ export class CortexM0Core {
576
576
  }
577
577
  else if (Rdn === pcRegister) {
578
578
  this.registers[Rdn] = result & ~0x1;
579
- this.cycles++;
579
+ deltaCycles++;
580
580
  }
581
581
  else if (Rdn === spRegister) {
582
582
  this.registers[Rdn] = result & ~0x3;
@@ -631,7 +631,7 @@ export class CortexM0Core {
631
631
  }
632
632
  if (this.checkCondition(cond)) {
633
633
  this.PC += imm8 + 2;
634
- this.cycles++;
634
+ deltaCycles++;
635
635
  }
636
636
  }
637
637
  // B
@@ -641,7 +641,7 @@ export class CortexM0Core {
641
641
  imm11 = (imm11 & 0x7ff) - 0x800;
642
642
  }
643
643
  this.PC += imm11 + 2;
644
- this.cycles++;
644
+ deltaCycles++;
645
645
  }
646
646
  // BICS
647
647
  else if (opcode >> 6 === 0b0100001110) {
@@ -669,7 +669,7 @@ export class CortexM0Core {
669
669
  const imm32 = ((S ? 0b11111111 : 0) << 24) | ((I1 << 23) | (I2 << 22) | (imm10 << 12) | (imm11 << 1));
670
670
  this.LR = (this.PC + 2) | 0x1;
671
671
  this.PC += 2 + imm32;
672
- this.cycles += 2;
672
+ deltaCycles += 2;
673
673
  this.blTaken(this, false);
674
674
  }
675
675
  // BLX
@@ -677,14 +677,14 @@ export class CortexM0Core {
677
677
  const Rm = (opcode >> 3) & 0xf;
678
678
  this.LR = this.PC | 0x1;
679
679
  this.PC = this.registers[Rm] & ~1;
680
- this.cycles++;
680
+ deltaCycles++;
681
681
  this.blTaken(this, true);
682
682
  }
683
683
  // BX
684
684
  else if (opcode >> 7 === 0b010001110 && (opcode & 0x7) === 0) {
685
685
  const Rm = (opcode >> 3) & 0xf;
686
686
  this.BXWritePC(this.registers[Rm]);
687
- this.cycles++;
687
+ deltaCycles++;
688
688
  }
689
689
  // CMN (register)
690
690
  else if (opcode >> 6 === 0b0100001011) {
@@ -722,12 +722,12 @@ export class CortexM0Core {
722
722
  // DMB SY
723
723
  else if (opcode === 0xf3bf && (opcode2 & 0xfff0) === 0x8f50) {
724
724
  this.PC += 2;
725
- this.cycles += 2;
725
+ deltaCycles += 2;
726
726
  }
727
727
  // DSB SY
728
728
  else if (opcode === 0xf3bf && (opcode2 & 0xfff0) === 0x8f40) {
729
729
  this.PC += 2;
730
- this.cycles += 2;
730
+ deltaCycles += 2;
731
731
  }
732
732
  // EORS
733
733
  else if (opcode >> 6 === 0b0100000001) {
@@ -741,7 +741,7 @@ export class CortexM0Core {
741
741
  // ISB SY
742
742
  else if (opcode === 0xf3bf && (opcode2 & 0xfff0) === 0x8f60) {
743
743
  this.PC += 2;
744
- this.cycles += 2;
744
+ deltaCycles += 2;
745
745
  }
746
746
  // LDMIA
747
747
  else if (opcode >> 11 === 0b11001) {
@@ -752,7 +752,7 @@ export class CortexM0Core {
752
752
  if (registers & (1 << i)) {
753
753
  this.registers[i] = this.readUint32(address);
754
754
  address += 4;
755
- this.cycles++;
755
+ deltaCycles++;
756
756
  }
757
757
  }
758
758
  // Write back
@@ -766,7 +766,7 @@ export class CortexM0Core {
766
766
  const Rn = (opcode >> 3) & 0x7;
767
767
  const Rt = opcode & 0x7;
768
768
  const addr = this.registers[Rn] + imm5;
769
- this.cycles += this.cyclesIO(addr);
769
+ deltaCycles += this.cyclesIO(addr);
770
770
  this.registers[Rt] = this.readUint32(addr);
771
771
  }
772
772
  // LDR (sp + immediate)
@@ -774,7 +774,7 @@ export class CortexM0Core {
774
774
  const Rt = (opcode >> 8) & 0x7;
775
775
  const imm8 = opcode & 0xff;
776
776
  const addr = this.SP + (imm8 << 2);
777
- this.cycles += this.cyclesIO(addr);
777
+ deltaCycles += this.cyclesIO(addr);
778
778
  this.registers[Rt] = this.readUint32(addr);
779
779
  }
780
780
  // LDR (literal)
@@ -783,7 +783,7 @@ export class CortexM0Core {
783
783
  const Rt = (opcode >> 8) & 7;
784
784
  const nextPC = this.PC + 2;
785
785
  const addr = (nextPC & 0xfffffffc) + imm8;
786
- this.cycles += this.cyclesIO(addr);
786
+ deltaCycles += this.cyclesIO(addr);
787
787
  this.registers[Rt] = this.readUint32(addr);
788
788
  }
789
789
  // LDR (register)
@@ -792,7 +792,7 @@ export class CortexM0Core {
792
792
  const Rn = (opcode >> 3) & 0x7;
793
793
  const Rt = opcode & 0x7;
794
794
  const addr = this.registers[Rm] + this.registers[Rn];
795
- this.cycles += this.cyclesIO(addr);
795
+ deltaCycles += this.cyclesIO(addr);
796
796
  this.registers[Rt] = this.readUint32(addr);
797
797
  }
798
798
  // LDRB (immediate)
@@ -801,7 +801,7 @@ export class CortexM0Core {
801
801
  const Rn = (opcode >> 3) & 0x7;
802
802
  const Rt = opcode & 0x7;
803
803
  const addr = this.registers[Rn] + imm5;
804
- this.cycles += this.cyclesIO(addr);
804
+ deltaCycles += this.cyclesIO(addr);
805
805
  this.registers[Rt] = this.readUint8(addr);
806
806
  }
807
807
  // LDRB (register)
@@ -810,7 +810,7 @@ export class CortexM0Core {
810
810
  const Rn = (opcode >> 3) & 0x7;
811
811
  const Rt = opcode & 0x7;
812
812
  const addr = this.registers[Rm] + this.registers[Rn];
813
- this.cycles += this.cyclesIO(addr);
813
+ deltaCycles += this.cyclesIO(addr);
814
814
  this.registers[Rt] = this.readUint8(addr);
815
815
  }
816
816
  // LDRH (immediate)
@@ -819,7 +819,7 @@ export class CortexM0Core {
819
819
  const Rn = (opcode >> 3) & 0x7;
820
820
  const Rt = opcode & 0x7;
821
821
  const addr = this.registers[Rn] + (imm5 << 1);
822
- this.cycles += this.cyclesIO(addr);
822
+ deltaCycles += this.cyclesIO(addr);
823
823
  this.registers[Rt] = this.readUint16(addr);
824
824
  }
825
825
  // LDRH (register)
@@ -828,7 +828,7 @@ export class CortexM0Core {
828
828
  const Rn = (opcode >> 3) & 0x7;
829
829
  const Rt = opcode & 0x7;
830
830
  const addr = this.registers[Rm] + this.registers[Rn];
831
- this.cycles += this.cyclesIO(addr);
831
+ deltaCycles += this.cyclesIO(addr);
832
832
  this.registers[Rt] = this.readUint16(addr);
833
833
  }
834
834
  // LDRSB
@@ -837,7 +837,7 @@ export class CortexM0Core {
837
837
  const Rn = (opcode >> 3) & 0x7;
838
838
  const Rt = opcode & 0x7;
839
839
  const addr = this.registers[Rm] + this.registers[Rn];
840
- this.cycles += this.cyclesIO(addr);
840
+ deltaCycles += this.cyclesIO(addr);
841
841
  this.registers[Rt] = signExtend8(this.readUint8(addr));
842
842
  }
843
843
  // LDRSH
@@ -846,7 +846,7 @@ export class CortexM0Core {
846
846
  const Rn = (opcode >> 3) & 0x7;
847
847
  const Rt = opcode & 0x7;
848
848
  const addr = this.registers[Rm] + this.registers[Rn];
849
- this.cycles += this.cyclesIO(addr);
849
+ deltaCycles += this.cyclesIO(addr);
850
850
  this.registers[Rt] = signExtend16(this.readUint16(addr));
851
851
  }
852
852
  // LSLS (immediate)
@@ -903,7 +903,7 @@ export class CortexM0Core {
903
903
  const Rd = ((opcode >> 4) & 0x8) | (opcode & 0x7);
904
904
  let value = Rm === pcRegister ? this.PC + 2 : this.registers[Rm];
905
905
  if (Rd === pcRegister) {
906
- this.cycles++;
906
+ deltaCycles++;
907
907
  value &= ~1;
908
908
  }
909
909
  else if (Rd === spRegister) {
@@ -925,7 +925,7 @@ export class CortexM0Core {
925
925
  const Rd = (opcode2 >> 8) & 0xf;
926
926
  this.registers[Rd] = this.readSpecialRegister(SYSm);
927
927
  this.PC += 2;
928
- this.cycles += 2;
928
+ deltaCycles += 2;
929
929
  }
930
930
  // MSR
931
931
  else if (opcode >> 4 === 0b111100111000 && opcode2 >> 8 == 0b10001000) {
@@ -933,7 +933,7 @@ export class CortexM0Core {
933
933
  const Rn = opcode & 0xf;
934
934
  this.writeSpecialRegister(SYSm, this.registers[Rn]);
935
935
  this.PC += 2;
936
- this.cycles += 2;
936
+ deltaCycles += 2;
937
937
  }
938
938
  // MULS
939
939
  else if (opcode >> 6 === 0b0100001101) {
@@ -970,13 +970,13 @@ export class CortexM0Core {
970
970
  if (opcode & (1 << i)) {
971
971
  this.registers[i] = this.readUint32(address);
972
972
  address += 4;
973
- this.cycles++;
973
+ deltaCycles++;
974
974
  }
975
975
  }
976
976
  if (P) {
977
977
  this.SP = address + 4;
978
978
  this.BXWritePC(this.readUint32(address));
979
- this.cycles += 2;
979
+ deltaCycles += 2;
980
980
  }
981
981
  else {
982
982
  this.SP = address;
@@ -994,7 +994,7 @@ export class CortexM0Core {
994
994
  for (let i = 0; i <= 7; i++) {
995
995
  if (opcode & (1 << i)) {
996
996
  this.writeUint32(address, this.registers[i]);
997
- this.cycles++;
997
+ deltaCycles++;
998
998
  address += 4;
999
999
  }
1000
1000
  }
@@ -1073,7 +1073,7 @@ export class CortexM0Core {
1073
1073
  if (registers & (1 << i)) {
1074
1074
  this.writeUint32(address, this.registers[i]);
1075
1075
  address += 4;
1076
- this.cycles++;
1076
+ deltaCycles++;
1077
1077
  }
1078
1078
  }
1079
1079
  // Write back
@@ -1087,7 +1087,7 @@ export class CortexM0Core {
1087
1087
  const Rn = (opcode >> 3) & 0x7;
1088
1088
  const Rt = opcode & 0x7;
1089
1089
  const address = this.registers[Rn] + imm5;
1090
- this.cycles += this.cyclesIO(address, true);
1090
+ deltaCycles += this.cyclesIO(address, true);
1091
1091
  this.writeUint32(address, this.registers[Rt]);
1092
1092
  }
1093
1093
  // STR (sp + immediate)
@@ -1095,7 +1095,7 @@ export class CortexM0Core {
1095
1095
  const Rt = (opcode >> 8) & 0x7;
1096
1096
  const imm8 = opcode & 0xff;
1097
1097
  const address = this.SP + (imm8 << 2);
1098
- this.cycles += this.cyclesIO(address, true);
1098
+ deltaCycles += this.cyclesIO(address, true);
1099
1099
  this.writeUint32(address, this.registers[Rt]);
1100
1100
  }
1101
1101
  // STR (register)
@@ -1104,7 +1104,7 @@ export class CortexM0Core {
1104
1104
  const Rn = (opcode >> 3) & 0x7;
1105
1105
  const Rt = opcode & 0x7;
1106
1106
  const address = this.registers[Rm] + this.registers[Rn];
1107
- this.cycles += this.cyclesIO(address, true);
1107
+ deltaCycles += this.cyclesIO(address, true);
1108
1108
  this.writeUint32(address, this.registers[Rt]);
1109
1109
  }
1110
1110
  // STRB (immediate)
@@ -1113,7 +1113,7 @@ export class CortexM0Core {
1113
1113
  const Rn = (opcode >> 3) & 0x7;
1114
1114
  const Rt = opcode & 0x7;
1115
1115
  const address = this.registers[Rn] + imm5;
1116
- this.cycles += this.cyclesIO(address, true);
1116
+ deltaCycles += this.cyclesIO(address, true);
1117
1117
  this.writeUint8(address, this.registers[Rt]);
1118
1118
  }
1119
1119
  // STRB (register)
@@ -1122,7 +1122,7 @@ export class CortexM0Core {
1122
1122
  const Rn = (opcode >> 3) & 0x7;
1123
1123
  const Rt = opcode & 0x7;
1124
1124
  const address = this.registers[Rm] + this.registers[Rn];
1125
- this.cycles += this.cyclesIO(address, true);
1125
+ deltaCycles += this.cyclesIO(address, true);
1126
1126
  this.writeUint8(address, this.registers[Rt]);
1127
1127
  }
1128
1128
  // STRH (immediate)
@@ -1131,7 +1131,7 @@ export class CortexM0Core {
1131
1131
  const Rn = (opcode >> 3) & 0x7;
1132
1132
  const Rt = opcode & 0x7;
1133
1133
  const address = this.registers[Rn] + imm5;
1134
- this.cycles += this.cyclesIO(address, true);
1134
+ deltaCycles += this.cyclesIO(address, true);
1135
1135
  this.writeUint16(address, this.registers[Rt]);
1136
1136
  }
1137
1137
  // STRH (register)
@@ -1140,7 +1140,7 @@ export class CortexM0Core {
1140
1140
  const Rn = (opcode >> 3) & 0x7;
1141
1141
  const Rt = opcode & 0x7;
1142
1142
  const address = this.registers[Rm] + this.registers[Rn];
1143
- this.cycles += this.cyclesIO(address, true);
1143
+ deltaCycles += this.cyclesIO(address, true);
1144
1144
  this.writeUint16(address, this.registers[Rt]);
1145
1145
  }
1146
1146
  // SUB (SP minus immediate)
@@ -1221,7 +1221,7 @@ export class CortexM0Core {
1221
1221
  }
1222
1222
  // WFE
1223
1223
  else if (opcode === 0b1011111100100000) {
1224
- this.cycles++;
1224
+ deltaCycles++;
1225
1225
  if (this.eventRegistered) {
1226
1226
  this.eventRegistered = false;
1227
1227
  }
@@ -1231,7 +1231,7 @@ export class CortexM0Core {
1231
1231
  }
1232
1232
  // WFI
1233
1233
  else if (opcode === 0b1011111100110000) {
1234
- this.cycles++;
1234
+ deltaCycles++;
1235
1235
  this.waiting = true;
1236
1236
  }
1237
1237
  // YIELD
@@ -1243,5 +1243,7 @@ export class CortexM0Core {
1243
1243
  this.logger.warn(LOG_NAME, `Warning: Instruction at ${opcodePC.toString(16)} is not implemented yet!`);
1244
1244
  this.logger.warn(LOG_NAME, `Opcode: 0x${opcode.toString(16)} (0x${opcode2.toString(16)})`);
1245
1245
  }
1246
+ this.cycles += deltaCycles;
1247
+ return deltaCycles;
1246
1248
  }
1247
1249
  }
@@ -3,7 +3,7 @@ export type GDBResponseHandler = (value: string) => void;
3
3
  export declare class GDBConnection {
4
4
  private server;
5
5
  private onResponse;
6
- readonly rp2040: import("../rp2040.js").RP2040;
6
+ readonly target: import("./gdb-target.js").IGDBTarget;
7
7
  private buf;
8
8
  constructor(server: GDBServer, onResponse: GDBResponseHandler);
9
9
  feedData(data: string): void;