rp2040js 0.17.5 → 0.17.7

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.
@@ -159,7 +159,7 @@ class RPADC extends peripheral_1.BasePeripheral {
159
159
  if (this.fcs & FCS_SHIFT) {
160
160
  value >>= 4;
161
161
  }
162
- if (this.fcs & FCS_ERR) {
162
+ if (error && this.fcs & FCS_ERR) {
163
163
  value |= FIFO_ERR;
164
164
  }
165
165
  this.fifo.push(value);
@@ -1,6 +1,10 @@
1
1
  import { BasePeripheral, Peripheral } from './peripheral';
2
2
  export declare class RP2040RTC extends BasePeripheral implements Peripheral {
3
- running: boolean;
3
+ setup0: number;
4
+ setup1: number;
5
+ rtc1: number;
6
+ rtc0: number;
7
+ ctrl: number;
4
8
  readUint32(offset: number): number;
5
9
  writeUint32(offset: number, value: number): void;
6
10
  }
@@ -2,27 +2,69 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RP2040RTC = void 0;
4
4
  const peripheral_1 = require("./peripheral");
5
+ const RTC_SETUP0 = 0x04;
6
+ const RTC_SETUP1 = 0x08;
5
7
  const RTC_CTRL = 0x0c;
6
8
  const IRQ_SETUP_0 = 0x10;
9
+ const RTC_RTC1 = 0x18;
10
+ const RTC_RTC0 = 0x1c;
11
+ const RTC_ENABLE_BITS = 0x01;
7
12
  const RTC_ACTIVE_BITS = 0x2;
13
+ const RTC_LOAD_BITS = 0x10;
8
14
  class RP2040RTC extends peripheral_1.BasePeripheral {
9
15
  constructor() {
10
16
  super(...arguments);
11
- this.running = true;
17
+ this.setup0 = 0;
18
+ this.setup1 = 0;
19
+ this.rtc1 = 0;
20
+ this.rtc0 = 0;
21
+ this.ctrl = 0;
12
22
  }
13
23
  readUint32(offset) {
14
24
  switch (offset) {
25
+ case RTC_SETUP0:
26
+ return this.setup0;
27
+ case RTC_SETUP1:
28
+ return this.setup1;
15
29
  case RTC_CTRL:
16
- return this.running ? RTC_ACTIVE_BITS : 0;
30
+ return this.ctrl;
17
31
  case IRQ_SETUP_0:
18
32
  return 0;
33
+ case RTC_RTC1:
34
+ return this.rtc1;
35
+ case RTC_RTC0:
36
+ return this.rtc0;
19
37
  }
20
38
  return super.readUint32(offset);
21
39
  }
22
40
  writeUint32(offset, value) {
23
41
  switch (offset) {
42
+ case RTC_SETUP0:
43
+ this.setup0 = value;
44
+ break;
45
+ case RTC_SETUP1:
46
+ this.setup1 = value;
47
+ break;
24
48
  case RTC_CTRL:
25
- this.running = value > 0; // TODO consult the datasheet
49
+ // Though RTC_LOAD_BITS is type SC and should be cleared on next cycle, pico-sdk write
50
+ // RTC_LOAD_BITS & RTC_ENABLE_BITS seperatly.
51
+ // https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/hardware_rtc/rtc.c#L76-L80
52
+ if (value & RTC_LOAD_BITS) {
53
+ this.ctrl |= RTC_LOAD_BITS;
54
+ }
55
+ if (value & RTC_ENABLE_BITS) {
56
+ this.ctrl |= RTC_ENABLE_BITS;
57
+ this.ctrl |= RTC_ACTIVE_BITS;
58
+ if (this.ctrl & RTC_LOAD_BITS) {
59
+ this.rtc1 = this.setup0;
60
+ this.rtc0 = this.setup1;
61
+ this.ctrl &= ~RTC_LOAD_BITS;
62
+ }
63
+ }
64
+ else {
65
+ this.ctrl &= ~RTC_ENABLE_BITS;
66
+ this.ctrl &= ~RTC_ACTIVE_BITS;
67
+ }
26
68
  break;
27
69
  default:
28
70
  super.writeUint32(offset, value);
@@ -14,7 +14,6 @@ import { RPUSBController } from './peripherals/usb';
14
14
  import { RPSIO } from './sio';
15
15
  import { Logger } from './utils/logging';
16
16
  export declare const FLASH_START_ADDRESS = 268435456;
17
- export declare const FLASH_END_ADDRESS = 335544320;
18
17
  export declare const RAM_START_ADDRESS = 536870912;
19
18
  export declare const DPRAM_START_ADDRESS = 1343225856;
20
19
  export declare const SIO_START_ADDRESS = 3489660928;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RP2040 = exports.SIO_START_ADDRESS = exports.DPRAM_START_ADDRESS = exports.RAM_START_ADDRESS = exports.FLASH_END_ADDRESS = exports.FLASH_START_ADDRESS = void 0;
3
+ exports.RP2040 = exports.SIO_START_ADDRESS = exports.DPRAM_START_ADDRESS = exports.RAM_START_ADDRESS = exports.FLASH_START_ADDRESS = void 0;
4
4
  const realtime_clock_1 = require("./clock/realtime-clock");
5
5
  const cortex_m0_core_1 = require("./cortex-m0-core");
6
6
  const gpio_pin_1 = require("./gpio-pin");
@@ -28,7 +28,6 @@ const sio_1 = require("./sio");
28
28
  const logging_1 = require("./utils/logging");
29
29
  const tbman_1 = require("./peripherals/tbman");
30
30
  exports.FLASH_START_ADDRESS = 0x10000000;
31
- exports.FLASH_END_ADDRESS = 0x14000000;
32
31
  exports.RAM_START_ADDRESS = 0x20000000;
33
32
  exports.DPRAM_START_ADDRESS = 0x50100000;
34
33
  exports.SIO_START_ADDRESS = 0xd0000000;
@@ -168,7 +167,8 @@ class RP2040 {
168
167
  if (address < bootrom.length * 4) {
169
168
  return bootrom[address / 4];
170
169
  }
171
- else if (address >= exports.FLASH_START_ADDRESS && address < exports.FLASH_END_ADDRESS) {
170
+ else if (address >= exports.FLASH_START_ADDRESS &&
171
+ address < exports.FLASH_START_ADDRESS + this.flash.length) {
172
172
  return this.flashView.getUint32(address - exports.FLASH_START_ADDRESS, true);
173
173
  }
174
174
  else if (address >= exports.RAM_START_ADDRESS && address < exports.RAM_START_ADDRESS + this.sram.length) {
@@ -196,7 +196,7 @@ class RP2040 {
196
196
  }
197
197
  /** We assume the address is 16-bit aligned */
198
198
  readUint16(address) {
199
- if (address >= exports.FLASH_START_ADDRESS && address < exports.FLASH_END_ADDRESS) {
199
+ if (address >= exports.FLASH_START_ADDRESS && address < exports.FLASH_START_ADDRESS + this.flash.length) {
200
200
  return this.flashView.getUint16(address - exports.FLASH_START_ADDRESS, true);
201
201
  }
202
202
  else if (address >= exports.RAM_START_ADDRESS && address < exports.RAM_START_ADDRESS + this.sram.length) {
@@ -206,7 +206,7 @@ class RP2040 {
206
206
  return address & 0x2 ? (value & 0xffff0000) >>> 16 : value & 0xffff;
207
207
  }
208
208
  readUint8(address) {
209
- if (address >= exports.FLASH_START_ADDRESS && address < exports.FLASH_END_ADDRESS) {
209
+ if (address >= exports.FLASH_START_ADDRESS && address < exports.FLASH_START_ADDRESS + this.flash.length) {
210
210
  return this.flash[address - exports.FLASH_START_ADDRESS];
211
211
  }
212
212
  else if (address >= exports.RAM_START_ADDRESS && address < exports.RAM_START_ADDRESS + this.sram.length) {
@@ -227,7 +227,8 @@ class RP2040 {
227
227
  else if (address < bootrom.length * 4) {
228
228
  bootrom[address / 4] = value;
229
229
  }
230
- else if (address >= exports.FLASH_START_ADDRESS && address < exports.FLASH_END_ADDRESS) {
230
+ else if (address >= exports.FLASH_START_ADDRESS &&
231
+ address < exports.FLASH_START_ADDRESS + this.flash.length) {
231
232
  this.flashView.setUint32(address - exports.FLASH_START_ADDRESS, value, true);
232
233
  }
233
234
  else if (address >= exports.RAM_START_ADDRESS && address < exports.RAM_START_ADDRESS + this.sram.length) {
@@ -156,7 +156,7 @@ export class RPADC extends BasePeripheral {
156
156
  if (this.fcs & FCS_SHIFT) {
157
157
  value >>= 4;
158
158
  }
159
- if (this.fcs & FCS_ERR) {
159
+ if (error && this.fcs & FCS_ERR) {
160
160
  value |= FIFO_ERR;
161
161
  }
162
162
  this.fifo.push(value);
@@ -1,6 +1,10 @@
1
1
  import { BasePeripheral, Peripheral } from './peripheral';
2
2
  export declare class RP2040RTC extends BasePeripheral implements Peripheral {
3
- running: boolean;
3
+ setup0: number;
4
+ setup1: number;
5
+ rtc1: number;
6
+ rtc0: number;
7
+ ctrl: number;
4
8
  readUint32(offset: number): number;
5
9
  writeUint32(offset: number, value: number): void;
6
10
  }
@@ -1,25 +1,67 @@
1
1
  import { BasePeripheral } from './peripheral';
2
+ const RTC_SETUP0 = 0x04;
3
+ const RTC_SETUP1 = 0x08;
2
4
  const RTC_CTRL = 0x0c;
3
5
  const IRQ_SETUP_0 = 0x10;
6
+ const RTC_RTC1 = 0x18;
7
+ const RTC_RTC0 = 0x1c;
8
+ const RTC_ENABLE_BITS = 0x01;
4
9
  const RTC_ACTIVE_BITS = 0x2;
10
+ const RTC_LOAD_BITS = 0x10;
5
11
  export class RP2040RTC extends BasePeripheral {
6
12
  constructor() {
7
13
  super(...arguments);
8
- this.running = true;
14
+ this.setup0 = 0;
15
+ this.setup1 = 0;
16
+ this.rtc1 = 0;
17
+ this.rtc0 = 0;
18
+ this.ctrl = 0;
9
19
  }
10
20
  readUint32(offset) {
11
21
  switch (offset) {
22
+ case RTC_SETUP0:
23
+ return this.setup0;
24
+ case RTC_SETUP1:
25
+ return this.setup1;
12
26
  case RTC_CTRL:
13
- return this.running ? RTC_ACTIVE_BITS : 0;
27
+ return this.ctrl;
14
28
  case IRQ_SETUP_0:
15
29
  return 0;
30
+ case RTC_RTC1:
31
+ return this.rtc1;
32
+ case RTC_RTC0:
33
+ return this.rtc0;
16
34
  }
17
35
  return super.readUint32(offset);
18
36
  }
19
37
  writeUint32(offset, value) {
20
38
  switch (offset) {
39
+ case RTC_SETUP0:
40
+ this.setup0 = value;
41
+ break;
42
+ case RTC_SETUP1:
43
+ this.setup1 = value;
44
+ break;
21
45
  case RTC_CTRL:
22
- this.running = value > 0; // TODO consult the datasheet
46
+ // Though RTC_LOAD_BITS is type SC and should be cleared on next cycle, pico-sdk write
47
+ // RTC_LOAD_BITS & RTC_ENABLE_BITS seperatly.
48
+ // https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/hardware_rtc/rtc.c#L76-L80
49
+ if (value & RTC_LOAD_BITS) {
50
+ this.ctrl |= RTC_LOAD_BITS;
51
+ }
52
+ if (value & RTC_ENABLE_BITS) {
53
+ this.ctrl |= RTC_ENABLE_BITS;
54
+ this.ctrl |= RTC_ACTIVE_BITS;
55
+ if (this.ctrl & RTC_LOAD_BITS) {
56
+ this.rtc1 = this.setup0;
57
+ this.rtc0 = this.setup1;
58
+ this.ctrl &= ~RTC_LOAD_BITS;
59
+ }
60
+ }
61
+ else {
62
+ this.ctrl &= ~RTC_ENABLE_BITS;
63
+ this.ctrl &= ~RTC_ACTIVE_BITS;
64
+ }
23
65
  break;
24
66
  default:
25
67
  super.writeUint32(offset, value);
@@ -14,7 +14,6 @@ import { RPUSBController } from './peripherals/usb';
14
14
  import { RPSIO } from './sio';
15
15
  import { Logger } from './utils/logging';
16
16
  export declare const FLASH_START_ADDRESS = 268435456;
17
- export declare const FLASH_END_ADDRESS = 335544320;
18
17
  export declare const RAM_START_ADDRESS = 536870912;
19
18
  export declare const DPRAM_START_ADDRESS = 1343225856;
20
19
  export declare const SIO_START_ADDRESS = 3489660928;
@@ -25,7 +25,6 @@ import { RPSIO } from './sio';
25
25
  import { ConsoleLogger, LogLevel } from './utils/logging';
26
26
  import { RPTBMAN } from './peripherals/tbman';
27
27
  export const FLASH_START_ADDRESS = 0x10000000;
28
- export const FLASH_END_ADDRESS = 0x14000000;
29
28
  export const RAM_START_ADDRESS = 0x20000000;
30
29
  export const DPRAM_START_ADDRESS = 0x50100000;
31
30
  export const SIO_START_ADDRESS = 0xd0000000;
@@ -165,7 +164,8 @@ export class RP2040 {
165
164
  if (address < bootrom.length * 4) {
166
165
  return bootrom[address / 4];
167
166
  }
168
- else if (address >= FLASH_START_ADDRESS && address < FLASH_END_ADDRESS) {
167
+ else if (address >= FLASH_START_ADDRESS &&
168
+ address < FLASH_START_ADDRESS + this.flash.length) {
169
169
  return this.flashView.getUint32(address - FLASH_START_ADDRESS, true);
170
170
  }
171
171
  else if (address >= RAM_START_ADDRESS && address < RAM_START_ADDRESS + this.sram.length) {
@@ -193,7 +193,7 @@ export class RP2040 {
193
193
  }
194
194
  /** We assume the address is 16-bit aligned */
195
195
  readUint16(address) {
196
- if (address >= FLASH_START_ADDRESS && address < FLASH_END_ADDRESS) {
196
+ if (address >= FLASH_START_ADDRESS && address < FLASH_START_ADDRESS + this.flash.length) {
197
197
  return this.flashView.getUint16(address - FLASH_START_ADDRESS, true);
198
198
  }
199
199
  else if (address >= RAM_START_ADDRESS && address < RAM_START_ADDRESS + this.sram.length) {
@@ -203,7 +203,7 @@ export class RP2040 {
203
203
  return address & 0x2 ? (value & 0xffff0000) >>> 16 : value & 0xffff;
204
204
  }
205
205
  readUint8(address) {
206
- if (address >= FLASH_START_ADDRESS && address < FLASH_END_ADDRESS) {
206
+ if (address >= FLASH_START_ADDRESS && address < FLASH_START_ADDRESS + this.flash.length) {
207
207
  return this.flash[address - FLASH_START_ADDRESS];
208
208
  }
209
209
  else if (address >= RAM_START_ADDRESS && address < RAM_START_ADDRESS + this.sram.length) {
@@ -224,7 +224,8 @@ export class RP2040 {
224
224
  else if (address < bootrom.length * 4) {
225
225
  bootrom[address / 4] = value;
226
226
  }
227
- else if (address >= FLASH_START_ADDRESS && address < FLASH_END_ADDRESS) {
227
+ else if (address >= FLASH_START_ADDRESS &&
228
+ address < FLASH_START_ADDRESS + this.flash.length) {
228
229
  this.flashView.setUint32(address - FLASH_START_ADDRESS, value, true);
229
230
  }
230
231
  else if (address >= RAM_START_ADDRESS && address < RAM_START_ADDRESS + this.sram.length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rp2040js",
3
- "version": "0.17.5",
3
+ "version": "0.17.7",
4
4
  "description": "Raspberry Pi Pico (RP2040) Emulator",
5
5
  "repository": "https://github.com/wokwi/rp2040js",
6
6
  "keywords": [