rp2040js 0.17.16 → 0.18.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 (183) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/clock/clock.d.ts +11 -11
  3. package/dist/cjs/clock/clock.js +2 -2
  4. package/dist/cjs/clock/mock-clock.d.ts +17 -17
  5. package/dist/cjs/clock/mock-clock.js +52 -52
  6. package/dist/cjs/clock/realtime-clock.d.ts +23 -23
  7. package/dist/cjs/clock/realtime-clock.js +73 -73
  8. package/dist/cjs/cortex-m0-core.d.ts +87 -87
  9. package/dist/cjs/cortex-m0-core.js +1251 -1251
  10. package/dist/cjs/gdb/gdb-connection.d.ts +11 -11
  11. package/dist/cjs/gdb/gdb-connection.js +57 -57
  12. package/dist/cjs/gdb/gdb-server.d.ts +23 -23
  13. package/dist/cjs/gdb/gdb-server.js +232 -232
  14. package/dist/cjs/gdb/gdb-tcp-server.d.ts +10 -10
  15. package/dist/cjs/gdb/gdb-tcp-server.js +34 -34
  16. package/dist/cjs/gdb/gdb-utils.d.ts +9 -9
  17. package/dist/cjs/gdb/gdb-utils.js +48 -48
  18. package/dist/cjs/gpio-pin.d.ts +56 -56
  19. package/dist/cjs/gpio-pin.js +216 -216
  20. package/dist/cjs/index.d.ts +11 -11
  21. package/dist/cjs/index.js +36 -36
  22. package/dist/cjs/interpolator.d.ts +36 -36
  23. package/dist/cjs/interpolator.js +150 -150
  24. package/dist/cjs/irq.d.ts +29 -29
  25. package/dist/cjs/irq.js +33 -33
  26. package/dist/cjs/peripherals/adc.d.ts +52 -52
  27. package/dist/cjs/peripherals/adc.js +261 -261
  28. package/dist/cjs/peripherals/busctrl.d.ts +10 -10
  29. package/dist/cjs/peripherals/busctrl.js +84 -84
  30. package/dist/cjs/peripherals/clocks.d.ts +9 -9
  31. package/dist/cjs/peripherals/clocks.js +42 -42
  32. package/dist/cjs/peripherals/dma.d.ts +109 -109
  33. package/dist/cjs/peripherals/dma.js +520 -520
  34. package/dist/cjs/peripherals/i2c.d.ts +54 -54
  35. package/dist/cjs/peripherals/i2c.js +458 -458
  36. package/dist/cjs/peripherals/io.d.ts +11 -11
  37. package/dist/cjs/peripherals/io.js +100 -100
  38. package/dist/cjs/peripherals/pads.d.ts +13 -13
  39. package/dist/cjs/peripherals/pads.js +58 -58
  40. package/dist/cjs/peripherals/peripheral.d.ts +22 -22
  41. package/dist/cjs/peripherals/peripheral.js +61 -61
  42. package/dist/cjs/peripherals/pio.d.ts +120 -120
  43. package/dist/cjs/peripherals/pio.js +1086 -1086
  44. package/dist/cjs/peripherals/ppb.d.ts +25 -25
  45. package/dist/cjs/peripherals/ppb.js +229 -229
  46. package/dist/cjs/peripherals/pwm.d.ts +65 -65
  47. package/dist/cjs/peripherals/pwm.js +372 -372
  48. package/dist/cjs/peripherals/reset.d.ts +8 -8
  49. package/dist/cjs/peripherals/reset.js +40 -40
  50. package/dist/cjs/peripherals/rtc.d.ts +10 -10
  51. package/dist/cjs/peripherals/rtc.js +74 -74
  52. package/dist/cjs/peripherals/spi.d.ts +38 -30
  53. package/dist/cjs/peripherals/spi.js +240 -218
  54. package/dist/cjs/peripherals/ssi.d.ts +6 -6
  55. package/dist/cjs/peripherals/ssi.js +43 -43
  56. package/dist/cjs/peripherals/syscfg.d.ts +5 -5
  57. package/dist/cjs/peripherals/syscfg.js +26 -26
  58. package/dist/cjs/peripherals/sysinfo.d.ts +4 -4
  59. package/dist/cjs/peripherals/sysinfo.js +22 -22
  60. package/dist/cjs/peripherals/tbman.d.ts +4 -4
  61. package/dist/cjs/peripherals/tbman.js +17 -17
  62. package/dist/cjs/peripherals/timer.d.ts +18 -18
  63. package/dist/cjs/peripherals/timer.js +156 -156
  64. package/dist/cjs/peripherals/uart.d.ts +31 -28
  65. package/dist/cjs/peripherals/uart.js +132 -135
  66. package/dist/cjs/peripherals/usb.d.ts +29 -29
  67. package/dist/cjs/peripherals/usb.js +309 -309
  68. package/dist/cjs/rp2040.d.ts +71 -71
  69. package/dist/cjs/rp2040.js +361 -346
  70. package/dist/cjs/sio.d.ts +21 -21
  71. package/dist/cjs/sio.js +425 -425
  72. package/dist/cjs/usb/cdc.d.ts +20 -20
  73. package/dist/cjs/usb/cdc.js +126 -126
  74. package/dist/cjs/usb/interfaces.d.ts +47 -47
  75. package/dist/cjs/usb/interfaces.js +46 -46
  76. package/dist/cjs/usb/setup.d.ts +5 -5
  77. package/dist/cjs/usb/setup.js +53 -53
  78. package/dist/cjs/utils/assembler.d.ts +79 -79
  79. package/dist/cjs/utils/assembler.js +328 -328
  80. package/dist/cjs/utils/bit.d.ts +3 -3
  81. package/dist/cjs/utils/bit.js +15 -15
  82. package/dist/cjs/utils/fifo.d.ts +15 -15
  83. package/dist/cjs/utils/fifo.js +56 -56
  84. package/dist/cjs/utils/logging.d.ts +23 -23
  85. package/dist/cjs/utils/logging.js +48 -48
  86. package/dist/cjs/utils/pio-assembler.d.ts +45 -45
  87. package/dist/cjs/utils/pio-assembler.js +87 -87
  88. package/dist/cjs/utils/time.d.ts +2 -2
  89. package/dist/cjs/utils/time.js +32 -32
  90. package/dist/cjs/utils/timer32.d.ts +57 -57
  91. package/dist/cjs/utils/timer32.js +208 -208
  92. package/dist/esm/clock/clock.d.ts +11 -11
  93. package/dist/esm/clock/clock.js +1 -1
  94. package/dist/esm/clock/mock-clock.d.ts +17 -17
  95. package/dist/esm/clock/mock-clock.js +47 -47
  96. package/dist/esm/clock/realtime-clock.d.ts +23 -23
  97. package/dist/esm/clock/realtime-clock.js +68 -68
  98. package/dist/esm/cortex-m0-core.d.ts +87 -87
  99. package/dist/esm/cortex-m0-core.js +1247 -1247
  100. package/dist/esm/gdb/gdb-connection.d.ts +11 -11
  101. package/dist/esm/gdb/gdb-connection.js +53 -53
  102. package/dist/esm/gdb/gdb-server.d.ts +23 -23
  103. package/dist/esm/gdb/gdb-server.js +228 -228
  104. package/dist/esm/gdb/gdb-tcp-server.d.ts +10 -10
  105. package/dist/esm/gdb/gdb-tcp-server.js +30 -30
  106. package/dist/esm/gdb/gdb-utils.d.ts +9 -9
  107. package/dist/esm/gdb/gdb-utils.js +36 -36
  108. package/dist/esm/gpio-pin.d.ts +56 -56
  109. package/dist/esm/gpio-pin.js +212 -212
  110. package/dist/esm/index.d.ts +11 -11
  111. package/dist/esm/index.js +11 -11
  112. package/dist/esm/interpolator.d.ts +36 -36
  113. package/dist/esm/interpolator.js +145 -145
  114. package/dist/esm/irq.d.ts +29 -29
  115. package/dist/esm/irq.js +30 -30
  116. package/dist/esm/peripherals/adc.d.ts +52 -52
  117. package/dist/esm/peripherals/adc.js +257 -257
  118. package/dist/esm/peripherals/busctrl.d.ts +10 -10
  119. package/dist/esm/peripherals/busctrl.js +80 -80
  120. package/dist/esm/peripherals/clocks.d.ts +9 -9
  121. package/dist/esm/peripherals/clocks.js +38 -38
  122. package/dist/esm/peripherals/dma.d.ts +109 -109
  123. package/dist/esm/peripherals/dma.js +515 -515
  124. package/dist/esm/peripherals/i2c.d.ts +54 -54
  125. package/dist/esm/peripherals/i2c.js +454 -454
  126. package/dist/esm/peripherals/io.d.ts +11 -11
  127. package/dist/esm/peripherals/io.js +96 -96
  128. package/dist/esm/peripherals/pads.d.ts +13 -13
  129. package/dist/esm/peripherals/pads.js +54 -54
  130. package/dist/esm/peripherals/peripheral.d.ts +22 -22
  131. package/dist/esm/peripherals/peripheral.js +55 -55
  132. package/dist/esm/peripherals/pio.d.ts +120 -120
  133. package/dist/esm/peripherals/pio.js +1081 -1081
  134. package/dist/esm/peripherals/ppb.d.ts +25 -25
  135. package/dist/esm/peripherals/ppb.js +225 -225
  136. package/dist/esm/peripherals/pwm.d.ts +65 -65
  137. package/dist/esm/peripherals/pwm.js +368 -368
  138. package/dist/esm/peripherals/reset.d.ts +8 -8
  139. package/dist/esm/peripherals/reset.js +36 -36
  140. package/dist/esm/peripherals/rtc.d.ts +10 -10
  141. package/dist/esm/peripherals/rtc.js +70 -70
  142. package/dist/esm/peripherals/spi.d.ts +38 -30
  143. package/dist/esm/peripherals/spi.js +236 -214
  144. package/dist/esm/peripherals/ssi.d.ts +6 -6
  145. package/dist/esm/peripherals/ssi.js +39 -39
  146. package/dist/esm/peripherals/syscfg.d.ts +5 -5
  147. package/dist/esm/peripherals/syscfg.js +22 -22
  148. package/dist/esm/peripherals/sysinfo.d.ts +4 -4
  149. package/dist/esm/peripherals/sysinfo.js +18 -18
  150. package/dist/esm/peripherals/tbman.d.ts +4 -4
  151. package/dist/esm/peripherals/tbman.js +13 -13
  152. package/dist/esm/peripherals/timer.d.ts +18 -18
  153. package/dist/esm/peripherals/timer.js +152 -152
  154. package/dist/esm/peripherals/uart.d.ts +31 -28
  155. package/dist/esm/peripherals/uart.js +128 -131
  156. package/dist/esm/peripherals/usb.d.ts +29 -29
  157. package/dist/esm/peripherals/usb.js +305 -305
  158. package/dist/esm/rp2040.d.ts +71 -71
  159. package/dist/esm/rp2040.js +357 -342
  160. package/dist/esm/sio.d.ts +21 -21
  161. package/dist/esm/sio.js +421 -421
  162. package/dist/esm/usb/cdc.d.ts +20 -20
  163. package/dist/esm/usb/cdc.js +121 -121
  164. package/dist/esm/usb/interfaces.d.ts +47 -47
  165. package/dist/esm/usb/interfaces.js +43 -43
  166. package/dist/esm/usb/setup.d.ts +5 -5
  167. package/dist/esm/usb/setup.js +46 -46
  168. package/dist/esm/utils/assembler.d.ts +79 -79
  169. package/dist/esm/utils/assembler.js +245 -245
  170. package/dist/esm/utils/bit.d.ts +3 -3
  171. package/dist/esm/utils/bit.js +9 -9
  172. package/dist/esm/utils/fifo.d.ts +15 -15
  173. package/dist/esm/utils/fifo.js +52 -52
  174. package/dist/esm/utils/logging.d.ts +23 -23
  175. package/dist/esm/utils/logging.js +44 -44
  176. package/dist/esm/utils/pio-assembler.d.ts +45 -45
  177. package/dist/esm/utils/pio-assembler.js +75 -75
  178. package/dist/esm/utils/time.d.ts +2 -2
  179. package/dist/esm/utils/time.js +27 -27
  180. package/dist/esm/utils/timer32.d.ts +57 -57
  181. package/dist/esm/utils/timer32.js +203 -203
  182. package/package.json +34 -22
  183. package/dist/esm/package.json +0 -1
@@ -1,515 +1,515 @@
1
- import { IRQ } from '../irq';
2
- import { BasePeripheral } from './peripheral';
3
- export var DREQChannel;
4
- (function (DREQChannel) {
5
- DREQChannel[DREQChannel["DREQ_PIO0_TX0"] = 0] = "DREQ_PIO0_TX0";
6
- DREQChannel[DREQChannel["DREQ_PIO0_TX1"] = 1] = "DREQ_PIO0_TX1";
7
- DREQChannel[DREQChannel["DREQ_PIO0_TX2"] = 2] = "DREQ_PIO0_TX2";
8
- DREQChannel[DREQChannel["DREQ_PIO0_TX3"] = 3] = "DREQ_PIO0_TX3";
9
- DREQChannel[DREQChannel["DREQ_PIO0_RX0"] = 4] = "DREQ_PIO0_RX0";
10
- DREQChannel[DREQChannel["DREQ_PIO0_RX1"] = 5] = "DREQ_PIO0_RX1";
11
- DREQChannel[DREQChannel["DREQ_PIO0_RX2"] = 6] = "DREQ_PIO0_RX2";
12
- DREQChannel[DREQChannel["DREQ_PIO0_RX3"] = 7] = "DREQ_PIO0_RX3";
13
- DREQChannel[DREQChannel["DREQ_PIO1_TX0"] = 8] = "DREQ_PIO1_TX0";
14
- DREQChannel[DREQChannel["DREQ_PIO1_TX1"] = 9] = "DREQ_PIO1_TX1";
15
- DREQChannel[DREQChannel["DREQ_PIO1_TX2"] = 10] = "DREQ_PIO1_TX2";
16
- DREQChannel[DREQChannel["DREQ_PIO1_TX3"] = 11] = "DREQ_PIO1_TX3";
17
- DREQChannel[DREQChannel["DREQ_PIO1_RX0"] = 12] = "DREQ_PIO1_RX0";
18
- DREQChannel[DREQChannel["DREQ_PIO1_RX1"] = 13] = "DREQ_PIO1_RX1";
19
- DREQChannel[DREQChannel["DREQ_PIO1_RX2"] = 14] = "DREQ_PIO1_RX2";
20
- DREQChannel[DREQChannel["DREQ_PIO1_RX3"] = 15] = "DREQ_PIO1_RX3";
21
- DREQChannel[DREQChannel["DREQ_SPI0_TX"] = 16] = "DREQ_SPI0_TX";
22
- DREQChannel[DREQChannel["DREQ_SPI0_RX"] = 17] = "DREQ_SPI0_RX";
23
- DREQChannel[DREQChannel["DREQ_SPI1_TX"] = 18] = "DREQ_SPI1_TX";
24
- DREQChannel[DREQChannel["DREQ_SPI1_RX"] = 19] = "DREQ_SPI1_RX";
25
- DREQChannel[DREQChannel["DREQ_UART0_TX"] = 20] = "DREQ_UART0_TX";
26
- DREQChannel[DREQChannel["DREQ_UART0_RX"] = 21] = "DREQ_UART0_RX";
27
- DREQChannel[DREQChannel["DREQ_UART1_TX"] = 22] = "DREQ_UART1_TX";
28
- DREQChannel[DREQChannel["DREQ_UART1_RX"] = 23] = "DREQ_UART1_RX";
29
- DREQChannel[DREQChannel["DREQ_PWM_WRAP0"] = 24] = "DREQ_PWM_WRAP0";
30
- DREQChannel[DREQChannel["DREQ_PWM_WRAP1"] = 25] = "DREQ_PWM_WRAP1";
31
- DREQChannel[DREQChannel["DREQ_PWM_WRAP2"] = 26] = "DREQ_PWM_WRAP2";
32
- DREQChannel[DREQChannel["DREQ_PWM_WRAP3"] = 27] = "DREQ_PWM_WRAP3";
33
- DREQChannel[DREQChannel["DREQ_PWM_WRAP4"] = 28] = "DREQ_PWM_WRAP4";
34
- DREQChannel[DREQChannel["DREQ_PWM_WRAP5"] = 29] = "DREQ_PWM_WRAP5";
35
- DREQChannel[DREQChannel["DREQ_PWM_WRAP6"] = 30] = "DREQ_PWM_WRAP6";
36
- DREQChannel[DREQChannel["DREQ_PWM_WRAP7"] = 31] = "DREQ_PWM_WRAP7";
37
- DREQChannel[DREQChannel["DREQ_I2C0_TX"] = 32] = "DREQ_I2C0_TX";
38
- DREQChannel[DREQChannel["DREQ_I2C0_RX"] = 33] = "DREQ_I2C0_RX";
39
- DREQChannel[DREQChannel["DREQ_I2C1_TX"] = 34] = "DREQ_I2C1_TX";
40
- DREQChannel[DREQChannel["DREQ_I2C1_RX"] = 35] = "DREQ_I2C1_RX";
41
- DREQChannel[DREQChannel["DREQ_ADC"] = 36] = "DREQ_ADC";
42
- DREQChannel[DREQChannel["DREQ_XIP_STREAM"] = 37] = "DREQ_XIP_STREAM";
43
- DREQChannel[DREQChannel["DREQ_XIP_SSITX"] = 38] = "DREQ_XIP_SSITX";
44
- DREQChannel[DREQChannel["DREQ_XIP_SSIRX"] = 39] = "DREQ_XIP_SSIRX";
45
- DREQChannel[DREQChannel["DREQ_MAX"] = 40] = "DREQ_MAX";
46
- })(DREQChannel || (DREQChannel = {}));
47
- var TREQ;
48
- (function (TREQ) {
49
- TREQ[TREQ["Timer0"] = 59] = "Timer0";
50
- TREQ[TREQ["Timer1"] = 60] = "Timer1";
51
- TREQ[TREQ["Timer2"] = 61] = "Timer2";
52
- TREQ[TREQ["Timer3"] = 62] = "Timer3";
53
- TREQ[TREQ["Permanent"] = 63] = "Permanent";
54
- })(TREQ || (TREQ = {}));
55
- // Per-channel registers
56
- const CHn_READ_ADDR = 0x000; // DMA Channel n Read Address pointer
57
- const CHn_WRITE_ADDR = 0x004; // DMA Channel n Write Address pointer
58
- const CHn_TRANS_COUNT = 0x008; // DMA Channel n Transfer Count
59
- const CHn_CTRL_TRIG = 0x00c; // DMA Channel n Control and Status
60
- const CHn_AL1_CTRL = 0x010; // Alias for channel n CTRL register
61
- const CHn_AL1_READ_ADDR = 0x014; // Alias for channel n READ_ADDR register
62
- const CHn_AL1_WRITE_ADDR = 0x018; // Alias for channel n WRITE_ADDR register
63
- const CHn_AL1_TRANS_COUNT_TRIG = 0x01c; // Alias for channel n TRANS_COUNT register
64
- const CHn_AL2_CTRL = 0x020; // Alias for channel n CTRL register
65
- const CHn_AL2_TRANS_COUNT = 0x024; // Alias for channel n TRANS_COUNT register
66
- const CHn_AL2_READ_ADDR = 0x028; // Alias for channel n READ_ADDR register
67
- const CHn_AL2_WRITE_ADDR_TRIG = 0x02c; // Alias for channel n WRITE_ADDR register
68
- const CHn_AL3_CTRL = 0x030; // Alias for channel n CTRL register
69
- const CHn_AL3_WRITE_ADDR = 0x034; // Alias for channel n WRITE_ADDR register
70
- const CHn_AL3_TRANS_COUNT = 0x038; // Alias for channel n TRANS_COUNT register
71
- const CHn_AL3_READ_ADDR_TRIG = 0x03c; // Alias for channel n READ_ADDR register
72
- const CHn_DBG_CTDREQ = 0x800;
73
- const CHn_DBG_TCR = 0x804;
74
- const CHANNEL_REGISTERS_SIZE = 12 * 0x40;
75
- const CHANNEL_REGISTERS_MASK = 0x83f;
76
- // General DMA registers
77
- const INTR = 0x400; // Interrupt Status (raw)
78
- const INTE0 = 0x404; // Interrupt Enables for IRQ 0
79
- const INTF0 = 0x408; // Force Interrupts
80
- const INTS0 = 0x40c; // Interrupt Status for IRQ 0
81
- const INTE1 = 0x414; // Interrupt Enables for IRQ 1
82
- const INTF1 = 0x418; // Force Interrupts for IRQ 1
83
- const INTS1 = 0x41c; // Interrupt Status (masked) for IRQ 1
84
- const TIMER0 = 0x420; // Pacing (X/Y) Fractional Timer
85
- const TIMER1 = 0x424; // Pacing (X/Y) Fractional Timer
86
- const TIMER2 = 0x428; // Pacing (X/Y) Fractional Timer
87
- const TIMER3 = 0x42c; // Pacing (X/Y) Fractional Timer
88
- const MULTI_CHAN_TRIGGER = 0x430; // Trigger one or more channels simultaneously
89
- const SNIFF_CTRL = 0x434; // Sniffer Control
90
- const SNIFF_DATA = 0x438; // Data accumulator for sniff hardware
91
- const FIFO_LEVELS = 0x440; // Debug RAF, WAF, TDF levels
92
- const CHAN_ABORT = 0x444; // Abort an in-progress transfer sequence on one or more channels
93
- const N_CHANNELS = 0x448;
94
- // CHn_CTRL_TRIG bits
95
- const AHB_ERROR = 1 << 31;
96
- const READ_ERROR = 1 << 30;
97
- const WRITE_ERROR = 1 << 29;
98
- const BUSY = 1 << 24;
99
- const SNIFF_EN = 1 << 23;
100
- const BSWAP = 1 << 22;
101
- const IRQ_QUIET = 1 << 21;
102
- const TREQ_SEL_MASK = 0x3f;
103
- const TREQ_SEL_SHIFT = 15;
104
- const CHAIN_TO_MASK = 0xf;
105
- const CHAIN_TO_SHIFT = 11;
106
- const RING_SEL = 1 << 10;
107
- const RING_SIZE_MASK = 0xf;
108
- const RING_SIZE_SHIFT = 6;
109
- const INCR_WRITE = 1 << 5;
110
- const INCR_READ = 1 << 4;
111
- const DATA_SIZE_MASK = 0x3;
112
- const DATA_SIZE_SHIFT = 2;
113
- const HIGH_PRIORITY = 1 << 1;
114
- const EN = 1 << 0;
115
- const CHn_CTRL_TRIG_WRITE_MASK = 0xffffff;
116
- const CHn_CTRL_TRIG_WC_MASK = READ_ERROR | WRITE_ERROR;
117
- export class RPDMAChannel {
118
- constructor(dma, rp2040, index) {
119
- this.dma = dma;
120
- this.rp2040 = rp2040;
121
- this.index = index;
122
- this.ctrl = 0;
123
- this.readAddr = 0;
124
- this.writeAddr = 0;
125
- this.transCount = 0;
126
- this.dreqCounter = 0;
127
- this.transCountReload = 0;
128
- this.treqValue = 0;
129
- this.dataSize = 1;
130
- this.chainTo = 0;
131
- this.ringMask = 0;
132
- this.transferFn = () => 0;
133
- this.transferTimer = null;
134
- this.transfer8 = () => {
135
- const { rp2040 } = this;
136
- rp2040.writeUint8(this.writeAddr, rp2040.readUint8(this.readAddr));
137
- };
138
- this.transfer16 = () => {
139
- const { rp2040 } = this;
140
- rp2040.writeUint16(this.writeAddr, rp2040.readUint16(this.readAddr));
141
- };
142
- this.transferSwap16 = () => {
143
- const { rp2040 } = this;
144
- const input = rp2040.readUint16(this.readAddr);
145
- rp2040.writeUint16(this.writeAddr, ((input & 0xff) << 8) | (input >> 8));
146
- };
147
- this.transfer32 = () => {
148
- const { rp2040 } = this;
149
- rp2040.writeUint32(this.writeAddr, rp2040.readUint32(this.readAddr));
150
- };
151
- this.transferSwap32 = () => {
152
- const { rp2040 } = this;
153
- const input = rp2040.readUint32(this.readAddr);
154
- rp2040.writeUint32(this.writeAddr, ((input & 0x000000ff) << 24) |
155
- ((input & 0x0000ff00) << 8) |
156
- ((input & 0x00ff0000) >> 8) |
157
- ((input >> 24) & 0xff));
158
- };
159
- this.transfer = () => {
160
- var _a;
161
- const { ctrl, dataSize, ringMask } = this;
162
- this.transferTimer = null;
163
- this.transferFn();
164
- if (ctrl & INCR_READ) {
165
- if (ringMask && !(ctrl & RING_SEL)) {
166
- this.readAddr = (this.readAddr & ~ringMask) | ((this.readAddr + dataSize) & ringMask);
167
- }
168
- else {
169
- this.readAddr += dataSize;
170
- }
171
- }
172
- if (ctrl & INCR_WRITE) {
173
- if (ringMask && ctrl & RING_SEL) {
174
- this.writeAddr = (this.writeAddr & ~ringMask) | ((this.writeAddr + dataSize) & ringMask);
175
- }
176
- else {
177
- this.writeAddr += dataSize;
178
- }
179
- }
180
- this.transCount--;
181
- if (this.transCount > 0) {
182
- this.scheduleTransfer();
183
- }
184
- else {
185
- this.ctrl &= ~BUSY;
186
- if (!(this.ctrl & IRQ_QUIET)) {
187
- this.dma.intRaw |= 1 << this.index;
188
- this.dma.checkInterrupts();
189
- }
190
- if (this.chainTo !== this.index) {
191
- (_a = this.dma.channels[this.chainTo]) === null || _a === void 0 ? void 0 : _a.start();
192
- }
193
- }
194
- };
195
- this.reset();
196
- }
197
- start() {
198
- if (!(this.ctrl & EN) || this.ctrl & BUSY) {
199
- return;
200
- }
201
- this.ctrl |= BUSY;
202
- this.transCount = this.transCountReload;
203
- if (this.transCount) {
204
- this.scheduleTransfer();
205
- }
206
- }
207
- get treq() {
208
- return this.treqValue;
209
- }
210
- get active() {
211
- return this.ctrl & EN && this.ctrl & BUSY;
212
- }
213
- scheduleTransfer() {
214
- if (this.transferTimer) {
215
- // Already scheduled; do nothing.
216
- return;
217
- }
218
- if (this.dma.dreq[this.treqValue] || this.treqValue === TREQ.Permanent) {
219
- this.transferTimer = this.rp2040.clock.createTimer(0, this.transfer);
220
- }
221
- else {
222
- const delay = this.dma.getTimer(this.treqValue);
223
- if (delay) {
224
- this.transferTimer = this.rp2040.clock.createTimer(delay, this.transfer);
225
- }
226
- }
227
- }
228
- abort() {
229
- this.ctrl &= ~BUSY;
230
- if (this.transferTimer) {
231
- this.rp2040.clock.deleteTimer(this.transferTimer);
232
- this.transferTimer = null;
233
- }
234
- }
235
- readUint32(offset) {
236
- switch (offset) {
237
- case CHn_READ_ADDR:
238
- case CHn_AL1_READ_ADDR:
239
- case CHn_AL2_READ_ADDR:
240
- case CHn_AL3_READ_ADDR_TRIG:
241
- return this.readAddr;
242
- case CHn_WRITE_ADDR:
243
- case CHn_AL1_WRITE_ADDR:
244
- case CHn_AL2_WRITE_ADDR_TRIG:
245
- case CHn_AL3_WRITE_ADDR:
246
- return this.writeAddr;
247
- case CHn_TRANS_COUNT:
248
- case CHn_AL1_TRANS_COUNT_TRIG:
249
- case CHn_AL2_TRANS_COUNT:
250
- case CHn_AL3_TRANS_COUNT:
251
- return this.transCount;
252
- case CHn_CTRL_TRIG:
253
- case CHn_AL1_CTRL:
254
- case CHn_AL2_CTRL:
255
- case CHn_AL3_CTRL:
256
- return this.ctrl;
257
- case CHn_DBG_CTDREQ:
258
- return this.dreqCounter;
259
- case CHn_DBG_TCR:
260
- return this.transCountReload;
261
- }
262
- return 0;
263
- }
264
- writeUint32(offset, value) {
265
- switch (offset) {
266
- case CHn_READ_ADDR:
267
- case CHn_AL1_READ_ADDR:
268
- case CHn_AL2_READ_ADDR:
269
- case CHn_AL3_READ_ADDR_TRIG:
270
- this.readAddr = value;
271
- break;
272
- case CHn_WRITE_ADDR:
273
- case CHn_AL1_WRITE_ADDR:
274
- case CHn_AL2_WRITE_ADDR_TRIG:
275
- case CHn_AL3_WRITE_ADDR:
276
- this.writeAddr = value;
277
- break;
278
- case CHn_TRANS_COUNT:
279
- case CHn_AL1_TRANS_COUNT_TRIG:
280
- case CHn_AL2_TRANS_COUNT:
281
- case CHn_AL3_TRANS_COUNT:
282
- this.transCountReload = value;
283
- break;
284
- case CHn_CTRL_TRIG:
285
- case CHn_AL1_CTRL:
286
- case CHn_AL2_CTRL:
287
- case CHn_AL3_CTRL: {
288
- this.ctrl = (this.ctrl & ~CHn_CTRL_TRIG_WRITE_MASK) | (value & CHn_CTRL_TRIG_WRITE_MASK);
289
- this.ctrl &= ~(value & CHn_CTRL_TRIG_WC_MASK); // Handle write-clear (WC) bits
290
- this.treqValue = (this.ctrl >> TREQ_SEL_SHIFT) & TREQ_SEL_MASK;
291
- this.chainTo = (this.ctrl >> CHAIN_TO_SHIFT) & CHAIN_TO_MASK;
292
- const ringSize = (this.ctrl >> RING_SIZE_SHIFT) & RING_SIZE_MASK;
293
- this.ringMask = ringSize ? (1 << ringSize) - 1 : 0;
294
- switch ((this.ctrl >> DATA_SIZE_SHIFT) & DATA_SIZE_MASK) {
295
- case 1:
296
- this.dataSize = 2;
297
- this.transferFn = this.ctrl & BSWAP ? this.transferSwap16 : this.transfer16;
298
- break;
299
- case 2:
300
- this.dataSize = 4;
301
- this.transferFn = this.ctrl & BSWAP ? this.transferSwap32 : this.transfer32;
302
- break;
303
- case 0:
304
- default:
305
- this.transferFn = this.transfer8;
306
- this.dataSize = 1;
307
- }
308
- if (this.ctrl & EN && this.ctrl & BUSY) {
309
- this.scheduleTransfer();
310
- }
311
- if (!(this.ctrl & EN) && this.transferTimer) {
312
- this.rp2040.clock.deleteTimer(this.transferTimer);
313
- this.transferTimer = null;
314
- }
315
- break;
316
- }
317
- case CHn_DBG_CTDREQ:
318
- this.dreqCounter = 0;
319
- break;
320
- }
321
- if (offset === CHn_AL3_READ_ADDR_TRIG ||
322
- offset === CHn_AL2_WRITE_ADDR_TRIG ||
323
- offset === CHn_AL1_TRANS_COUNT_TRIG ||
324
- offset === CHn_CTRL_TRIG) {
325
- if (value) {
326
- this.start();
327
- }
328
- else if (this.ctrl & IRQ_QUIET) {
329
- // Null trigger interrupts
330
- this.dma.intRaw |= 1 << this.index;
331
- this.dma.checkInterrupts();
332
- }
333
- }
334
- }
335
- reset() {
336
- this.writeUint32(CHn_CTRL_TRIG, this.index << CHAIN_TO_SHIFT);
337
- }
338
- }
339
- export class RPDMA extends BasePeripheral {
340
- constructor() {
341
- super(...arguments);
342
- this.channels = [
343
- new RPDMAChannel(this, this.rp2040, 0),
344
- new RPDMAChannel(this, this.rp2040, 1),
345
- new RPDMAChannel(this, this.rp2040, 2),
346
- new RPDMAChannel(this, this.rp2040, 3),
347
- new RPDMAChannel(this, this.rp2040, 4),
348
- new RPDMAChannel(this, this.rp2040, 5),
349
- new RPDMAChannel(this, this.rp2040, 6),
350
- new RPDMAChannel(this, this.rp2040, 7),
351
- new RPDMAChannel(this, this.rp2040, 8),
352
- new RPDMAChannel(this, this.rp2040, 9),
353
- new RPDMAChannel(this, this.rp2040, 10),
354
- new RPDMAChannel(this, this.rp2040, 11),
355
- ];
356
- this.intRaw = 0;
357
- this.intEnable0 = 0;
358
- this.intForce0 = 0;
359
- this.intEnable1 = 0;
360
- this.intForce1 = 0;
361
- this.timer0 = 0;
362
- this.timer1 = 0;
363
- this.timer2 = 0;
364
- this.timer3 = 0;
365
- this.dreq = Array(DREQChannel.DREQ_MAX);
366
- }
367
- get intStatus0() {
368
- return (this.intRaw & this.intEnable0) | this.intForce0;
369
- }
370
- get intStatus1() {
371
- return (this.intRaw & this.intEnable1) | this.intForce1;
372
- }
373
- readUint32(offset) {
374
- if ((offset & 0x7ff) <= CHANNEL_REGISTERS_SIZE) {
375
- const channelIndex = (offset & 0x7ff) >> 6;
376
- return this.channels[channelIndex].readUint32(offset & CHANNEL_REGISTERS_MASK);
377
- }
378
- switch (offset) {
379
- case TIMER0:
380
- return this.timer0;
381
- case TIMER1:
382
- return this.timer1;
383
- case TIMER2:
384
- return this.timer2;
385
- case TIMER3:
386
- return this.timer3;
387
- case INTR:
388
- return this.intRaw;
389
- case INTE0:
390
- return this.intEnable0;
391
- case INTF0:
392
- return this.intForce0;
393
- case INTS0:
394
- return this.intStatus0;
395
- case INTE1:
396
- return this.intEnable1;
397
- case INTF1:
398
- return this.intForce1;
399
- case INTS1:
400
- return this.intStatus1;
401
- case N_CHANNELS:
402
- return this.channels.length;
403
- }
404
- return super.readUint32(offset);
405
- }
406
- writeUint32(offset, value) {
407
- if ((offset & 0x7ff) <= CHANNEL_REGISTERS_SIZE) {
408
- const channelIndex = (offset & 0x7ff) >> 6;
409
- this.channels[channelIndex].writeUint32(offset & CHANNEL_REGISTERS_MASK, value);
410
- return;
411
- }
412
- switch (offset) {
413
- case TIMER0:
414
- this.timer0 = value;
415
- return;
416
- case TIMER1:
417
- this.timer1 = value;
418
- return;
419
- case TIMER2:
420
- this.timer2 = value;
421
- return;
422
- case TIMER3:
423
- this.timer3 = value;
424
- return;
425
- case INTR:
426
- case INTS0:
427
- case INTS1:
428
- this.intRaw &= ~this.rawWriteValue;
429
- this.checkInterrupts();
430
- return;
431
- case INTE0:
432
- this.intEnable0 = value & 0xffff;
433
- this.checkInterrupts();
434
- return;
435
- case INTF0:
436
- this.intForce0 = value & 0xffff;
437
- this.checkInterrupts();
438
- return;
439
- case INTE1:
440
- this.intEnable1 = value & 0xffff;
441
- this.checkInterrupts();
442
- return;
443
- case INTF1:
444
- this.intForce1 = value & 0xffff;
445
- this.checkInterrupts();
446
- return;
447
- case MULTI_CHAN_TRIGGER:
448
- for (const chan of this.channels) {
449
- if (value & (1 << chan.index)) {
450
- chan.start();
451
- }
452
- }
453
- return;
454
- case CHAN_ABORT:
455
- for (const chan of this.channels) {
456
- if (value & (1 << chan.index)) {
457
- chan.abort();
458
- }
459
- }
460
- return;
461
- default:
462
- super.writeUint32(offset, value);
463
- }
464
- }
465
- setDREQ(dreqChannel) {
466
- const { dreq } = this;
467
- if (!dreq[dreqChannel]) {
468
- dreq[dreqChannel] = true;
469
- for (const channel of this.channels) {
470
- if (channel.treq === dreqChannel && channel.active) {
471
- channel.scheduleTransfer();
472
- }
473
- }
474
- }
475
- }
476
- clearDREQ(dreqChannel) {
477
- this.dreq[dreqChannel] = false;
478
- }
479
- /**
480
- * Returns the number of microseconds for a cycle of the given DMA timer, or 0 if the timer is disabled.
481
- */
482
- getTimer(treq) {
483
- let dividend = 0, divisor = 1;
484
- switch (treq) {
485
- case TREQ.Permanent:
486
- dividend = 1;
487
- divisor = 1;
488
- break;
489
- case TREQ.Timer0:
490
- dividend = this.timer0 >>> 16;
491
- divisor = this.timer0 & 0xffff;
492
- break;
493
- case TREQ.Timer1:
494
- dividend = this.timer1 >>> 16;
495
- divisor = this.timer1 & 0xffff;
496
- break;
497
- case TREQ.Timer2:
498
- dividend = this.timer2 >>> 16;
499
- divisor = this.timer2 & 0xffff;
500
- break;
501
- case TREQ.Timer3:
502
- dividend = this.timer3 >>> 36;
503
- divisor = this.timer3 & 0xffff;
504
- break;
505
- }
506
- if (divisor === 0) {
507
- return 0;
508
- }
509
- return ((dividend / divisor) * 1e6) / this.rp2040.clkSys;
510
- }
511
- checkInterrupts() {
512
- this.rp2040.setInterrupt(IRQ.DMA_IRQ0, !!this.intStatus0);
513
- this.rp2040.setInterrupt(IRQ.DMA_IRQ1, !!this.intStatus1);
514
- }
515
- }
1
+ import { IRQ } from '../irq.js';
2
+ import { BasePeripheral } from './peripheral.js';
3
+ export var DREQChannel;
4
+ (function (DREQChannel) {
5
+ DREQChannel[DREQChannel["DREQ_PIO0_TX0"] = 0] = "DREQ_PIO0_TX0";
6
+ DREQChannel[DREQChannel["DREQ_PIO0_TX1"] = 1] = "DREQ_PIO0_TX1";
7
+ DREQChannel[DREQChannel["DREQ_PIO0_TX2"] = 2] = "DREQ_PIO0_TX2";
8
+ DREQChannel[DREQChannel["DREQ_PIO0_TX3"] = 3] = "DREQ_PIO0_TX3";
9
+ DREQChannel[DREQChannel["DREQ_PIO0_RX0"] = 4] = "DREQ_PIO0_RX0";
10
+ DREQChannel[DREQChannel["DREQ_PIO0_RX1"] = 5] = "DREQ_PIO0_RX1";
11
+ DREQChannel[DREQChannel["DREQ_PIO0_RX2"] = 6] = "DREQ_PIO0_RX2";
12
+ DREQChannel[DREQChannel["DREQ_PIO0_RX3"] = 7] = "DREQ_PIO0_RX3";
13
+ DREQChannel[DREQChannel["DREQ_PIO1_TX0"] = 8] = "DREQ_PIO1_TX0";
14
+ DREQChannel[DREQChannel["DREQ_PIO1_TX1"] = 9] = "DREQ_PIO1_TX1";
15
+ DREQChannel[DREQChannel["DREQ_PIO1_TX2"] = 10] = "DREQ_PIO1_TX2";
16
+ DREQChannel[DREQChannel["DREQ_PIO1_TX3"] = 11] = "DREQ_PIO1_TX3";
17
+ DREQChannel[DREQChannel["DREQ_PIO1_RX0"] = 12] = "DREQ_PIO1_RX0";
18
+ DREQChannel[DREQChannel["DREQ_PIO1_RX1"] = 13] = "DREQ_PIO1_RX1";
19
+ DREQChannel[DREQChannel["DREQ_PIO1_RX2"] = 14] = "DREQ_PIO1_RX2";
20
+ DREQChannel[DREQChannel["DREQ_PIO1_RX3"] = 15] = "DREQ_PIO1_RX3";
21
+ DREQChannel[DREQChannel["DREQ_SPI0_TX"] = 16] = "DREQ_SPI0_TX";
22
+ DREQChannel[DREQChannel["DREQ_SPI0_RX"] = 17] = "DREQ_SPI0_RX";
23
+ DREQChannel[DREQChannel["DREQ_SPI1_TX"] = 18] = "DREQ_SPI1_TX";
24
+ DREQChannel[DREQChannel["DREQ_SPI1_RX"] = 19] = "DREQ_SPI1_RX";
25
+ DREQChannel[DREQChannel["DREQ_UART0_TX"] = 20] = "DREQ_UART0_TX";
26
+ DREQChannel[DREQChannel["DREQ_UART0_RX"] = 21] = "DREQ_UART0_RX";
27
+ DREQChannel[DREQChannel["DREQ_UART1_TX"] = 22] = "DREQ_UART1_TX";
28
+ DREQChannel[DREQChannel["DREQ_UART1_RX"] = 23] = "DREQ_UART1_RX";
29
+ DREQChannel[DREQChannel["DREQ_PWM_WRAP0"] = 24] = "DREQ_PWM_WRAP0";
30
+ DREQChannel[DREQChannel["DREQ_PWM_WRAP1"] = 25] = "DREQ_PWM_WRAP1";
31
+ DREQChannel[DREQChannel["DREQ_PWM_WRAP2"] = 26] = "DREQ_PWM_WRAP2";
32
+ DREQChannel[DREQChannel["DREQ_PWM_WRAP3"] = 27] = "DREQ_PWM_WRAP3";
33
+ DREQChannel[DREQChannel["DREQ_PWM_WRAP4"] = 28] = "DREQ_PWM_WRAP4";
34
+ DREQChannel[DREQChannel["DREQ_PWM_WRAP5"] = 29] = "DREQ_PWM_WRAP5";
35
+ DREQChannel[DREQChannel["DREQ_PWM_WRAP6"] = 30] = "DREQ_PWM_WRAP6";
36
+ DREQChannel[DREQChannel["DREQ_PWM_WRAP7"] = 31] = "DREQ_PWM_WRAP7";
37
+ DREQChannel[DREQChannel["DREQ_I2C0_TX"] = 32] = "DREQ_I2C0_TX";
38
+ DREQChannel[DREQChannel["DREQ_I2C0_RX"] = 33] = "DREQ_I2C0_RX";
39
+ DREQChannel[DREQChannel["DREQ_I2C1_TX"] = 34] = "DREQ_I2C1_TX";
40
+ DREQChannel[DREQChannel["DREQ_I2C1_RX"] = 35] = "DREQ_I2C1_RX";
41
+ DREQChannel[DREQChannel["DREQ_ADC"] = 36] = "DREQ_ADC";
42
+ DREQChannel[DREQChannel["DREQ_XIP_STREAM"] = 37] = "DREQ_XIP_STREAM";
43
+ DREQChannel[DREQChannel["DREQ_XIP_SSITX"] = 38] = "DREQ_XIP_SSITX";
44
+ DREQChannel[DREQChannel["DREQ_XIP_SSIRX"] = 39] = "DREQ_XIP_SSIRX";
45
+ DREQChannel[DREQChannel["DREQ_MAX"] = 40] = "DREQ_MAX";
46
+ })(DREQChannel || (DREQChannel = {}));
47
+ var TREQ;
48
+ (function (TREQ) {
49
+ TREQ[TREQ["Timer0"] = 59] = "Timer0";
50
+ TREQ[TREQ["Timer1"] = 60] = "Timer1";
51
+ TREQ[TREQ["Timer2"] = 61] = "Timer2";
52
+ TREQ[TREQ["Timer3"] = 62] = "Timer3";
53
+ TREQ[TREQ["Permanent"] = 63] = "Permanent";
54
+ })(TREQ || (TREQ = {}));
55
+ // Per-channel registers
56
+ const CHn_READ_ADDR = 0x000; // DMA Channel n Read Address pointer
57
+ const CHn_WRITE_ADDR = 0x004; // DMA Channel n Write Address pointer
58
+ const CHn_TRANS_COUNT = 0x008; // DMA Channel n Transfer Count
59
+ const CHn_CTRL_TRIG = 0x00c; // DMA Channel n Control and Status
60
+ const CHn_AL1_CTRL = 0x010; // Alias for channel n CTRL register
61
+ const CHn_AL1_READ_ADDR = 0x014; // Alias for channel n READ_ADDR register
62
+ const CHn_AL1_WRITE_ADDR = 0x018; // Alias for channel n WRITE_ADDR register
63
+ const CHn_AL1_TRANS_COUNT_TRIG = 0x01c; // Alias for channel n TRANS_COUNT register
64
+ const CHn_AL2_CTRL = 0x020; // Alias for channel n CTRL register
65
+ const CHn_AL2_TRANS_COUNT = 0x024; // Alias for channel n TRANS_COUNT register
66
+ const CHn_AL2_READ_ADDR = 0x028; // Alias for channel n READ_ADDR register
67
+ const CHn_AL2_WRITE_ADDR_TRIG = 0x02c; // Alias for channel n WRITE_ADDR register
68
+ const CHn_AL3_CTRL = 0x030; // Alias for channel n CTRL register
69
+ const CHn_AL3_WRITE_ADDR = 0x034; // Alias for channel n WRITE_ADDR register
70
+ const CHn_AL3_TRANS_COUNT = 0x038; // Alias for channel n TRANS_COUNT register
71
+ const CHn_AL3_READ_ADDR_TRIG = 0x03c; // Alias for channel n READ_ADDR register
72
+ const CHn_DBG_CTDREQ = 0x800;
73
+ const CHn_DBG_TCR = 0x804;
74
+ const CHANNEL_REGISTERS_SIZE = 12 * 0x40;
75
+ const CHANNEL_REGISTERS_MASK = 0x83f;
76
+ // General DMA registers
77
+ const INTR = 0x400; // Interrupt Status (raw)
78
+ const INTE0 = 0x404; // Interrupt Enables for IRQ 0
79
+ const INTF0 = 0x408; // Force Interrupts
80
+ const INTS0 = 0x40c; // Interrupt Status for IRQ 0
81
+ const INTE1 = 0x414; // Interrupt Enables for IRQ 1
82
+ const INTF1 = 0x418; // Force Interrupts for IRQ 1
83
+ const INTS1 = 0x41c; // Interrupt Status (masked) for IRQ 1
84
+ const TIMER0 = 0x420; // Pacing (X/Y) Fractional Timer
85
+ const TIMER1 = 0x424; // Pacing (X/Y) Fractional Timer
86
+ const TIMER2 = 0x428; // Pacing (X/Y) Fractional Timer
87
+ const TIMER3 = 0x42c; // Pacing (X/Y) Fractional Timer
88
+ const MULTI_CHAN_TRIGGER = 0x430; // Trigger one or more channels simultaneously
89
+ const SNIFF_CTRL = 0x434; // Sniffer Control
90
+ const SNIFF_DATA = 0x438; // Data accumulator for sniff hardware
91
+ const FIFO_LEVELS = 0x440; // Debug RAF, WAF, TDF levels
92
+ const CHAN_ABORT = 0x444; // Abort an in-progress transfer sequence on one or more channels
93
+ const N_CHANNELS = 0x448;
94
+ // CHn_CTRL_TRIG bits
95
+ const AHB_ERROR = 1 << 31;
96
+ const READ_ERROR = 1 << 30;
97
+ const WRITE_ERROR = 1 << 29;
98
+ const BUSY = 1 << 24;
99
+ const SNIFF_EN = 1 << 23;
100
+ const BSWAP = 1 << 22;
101
+ const IRQ_QUIET = 1 << 21;
102
+ const TREQ_SEL_MASK = 0x3f;
103
+ const TREQ_SEL_SHIFT = 15;
104
+ const CHAIN_TO_MASK = 0xf;
105
+ const CHAIN_TO_SHIFT = 11;
106
+ const RING_SEL = 1 << 10;
107
+ const RING_SIZE_MASK = 0xf;
108
+ const RING_SIZE_SHIFT = 6;
109
+ const INCR_WRITE = 1 << 5;
110
+ const INCR_READ = 1 << 4;
111
+ const DATA_SIZE_MASK = 0x3;
112
+ const DATA_SIZE_SHIFT = 2;
113
+ const HIGH_PRIORITY = 1 << 1;
114
+ const EN = 1 << 0;
115
+ const CHn_CTRL_TRIG_WRITE_MASK = 0xffffff;
116
+ const CHn_CTRL_TRIG_WC_MASK = READ_ERROR | WRITE_ERROR;
117
+ export class RPDMAChannel {
118
+ constructor(dma, rp2040, index) {
119
+ this.dma = dma;
120
+ this.rp2040 = rp2040;
121
+ this.index = index;
122
+ this.ctrl = 0;
123
+ this.readAddr = 0;
124
+ this.writeAddr = 0;
125
+ this.transCount = 0;
126
+ this.dreqCounter = 0;
127
+ this.transCountReload = 0;
128
+ this.treqValue = 0;
129
+ this.dataSize = 1;
130
+ this.chainTo = 0;
131
+ this.ringMask = 0;
132
+ this.transferFn = () => 0;
133
+ this.transferTimer = null;
134
+ this.transfer8 = () => {
135
+ const { rp2040 } = this;
136
+ rp2040.writeUint8(this.writeAddr, rp2040.readUint8(this.readAddr));
137
+ };
138
+ this.transfer16 = () => {
139
+ const { rp2040 } = this;
140
+ rp2040.writeUint16(this.writeAddr, rp2040.readUint16(this.readAddr));
141
+ };
142
+ this.transferSwap16 = () => {
143
+ const { rp2040 } = this;
144
+ const input = rp2040.readUint16(this.readAddr);
145
+ rp2040.writeUint16(this.writeAddr, ((input & 0xff) << 8) | (input >> 8));
146
+ };
147
+ this.transfer32 = () => {
148
+ const { rp2040 } = this;
149
+ rp2040.writeUint32(this.writeAddr, rp2040.readUint32(this.readAddr));
150
+ };
151
+ this.transferSwap32 = () => {
152
+ const { rp2040 } = this;
153
+ const input = rp2040.readUint32(this.readAddr);
154
+ rp2040.writeUint32(this.writeAddr, ((input & 0x000000ff) << 24) |
155
+ ((input & 0x0000ff00) << 8) |
156
+ ((input & 0x00ff0000) >> 8) |
157
+ ((input >> 24) & 0xff));
158
+ };
159
+ this.transfer = () => {
160
+ var _a;
161
+ const { ctrl, dataSize, ringMask } = this;
162
+ this.transferTimer = null;
163
+ this.transferFn();
164
+ if (ctrl & INCR_READ) {
165
+ if (ringMask && !(ctrl & RING_SEL)) {
166
+ this.readAddr = (this.readAddr & ~ringMask) | ((this.readAddr + dataSize) & ringMask);
167
+ }
168
+ else {
169
+ this.readAddr += dataSize;
170
+ }
171
+ }
172
+ if (ctrl & INCR_WRITE) {
173
+ if (ringMask && ctrl & RING_SEL) {
174
+ this.writeAddr = (this.writeAddr & ~ringMask) | ((this.writeAddr + dataSize) & ringMask);
175
+ }
176
+ else {
177
+ this.writeAddr += dataSize;
178
+ }
179
+ }
180
+ this.transCount--;
181
+ if (this.transCount > 0) {
182
+ this.scheduleTransfer();
183
+ }
184
+ else {
185
+ this.ctrl &= ~BUSY;
186
+ if (!(this.ctrl & IRQ_QUIET)) {
187
+ this.dma.intRaw |= 1 << this.index;
188
+ this.dma.checkInterrupts();
189
+ }
190
+ if (this.chainTo !== this.index) {
191
+ (_a = this.dma.channels[this.chainTo]) === null || _a === void 0 ? void 0 : _a.start();
192
+ }
193
+ }
194
+ };
195
+ this.reset();
196
+ }
197
+ start() {
198
+ if (!(this.ctrl & EN) || this.ctrl & BUSY) {
199
+ return;
200
+ }
201
+ this.ctrl |= BUSY;
202
+ this.transCount = this.transCountReload;
203
+ if (this.transCount) {
204
+ this.scheduleTransfer();
205
+ }
206
+ }
207
+ get treq() {
208
+ return this.treqValue;
209
+ }
210
+ get active() {
211
+ return this.ctrl & EN && this.ctrl & BUSY;
212
+ }
213
+ scheduleTransfer() {
214
+ if (this.transferTimer) {
215
+ // Already scheduled; do nothing.
216
+ return;
217
+ }
218
+ if (this.dma.dreq[this.treqValue] || this.treqValue === TREQ.Permanent) {
219
+ this.transferTimer = this.rp2040.clock.createTimer(0, this.transfer);
220
+ }
221
+ else {
222
+ const delay = this.dma.getTimer(this.treqValue);
223
+ if (delay) {
224
+ this.transferTimer = this.rp2040.clock.createTimer(delay, this.transfer);
225
+ }
226
+ }
227
+ }
228
+ abort() {
229
+ this.ctrl &= ~BUSY;
230
+ if (this.transferTimer) {
231
+ this.rp2040.clock.deleteTimer(this.transferTimer);
232
+ this.transferTimer = null;
233
+ }
234
+ }
235
+ readUint32(offset) {
236
+ switch (offset) {
237
+ case CHn_READ_ADDR:
238
+ case CHn_AL1_READ_ADDR:
239
+ case CHn_AL2_READ_ADDR:
240
+ case CHn_AL3_READ_ADDR_TRIG:
241
+ return this.readAddr;
242
+ case CHn_WRITE_ADDR:
243
+ case CHn_AL1_WRITE_ADDR:
244
+ case CHn_AL2_WRITE_ADDR_TRIG:
245
+ case CHn_AL3_WRITE_ADDR:
246
+ return this.writeAddr;
247
+ case CHn_TRANS_COUNT:
248
+ case CHn_AL1_TRANS_COUNT_TRIG:
249
+ case CHn_AL2_TRANS_COUNT:
250
+ case CHn_AL3_TRANS_COUNT:
251
+ return this.transCount;
252
+ case CHn_CTRL_TRIG:
253
+ case CHn_AL1_CTRL:
254
+ case CHn_AL2_CTRL:
255
+ case CHn_AL3_CTRL:
256
+ return this.ctrl;
257
+ case CHn_DBG_CTDREQ:
258
+ return this.dreqCounter;
259
+ case CHn_DBG_TCR:
260
+ return this.transCountReload;
261
+ }
262
+ return 0;
263
+ }
264
+ writeUint32(offset, value) {
265
+ switch (offset) {
266
+ case CHn_READ_ADDR:
267
+ case CHn_AL1_READ_ADDR:
268
+ case CHn_AL2_READ_ADDR:
269
+ case CHn_AL3_READ_ADDR_TRIG:
270
+ this.readAddr = value;
271
+ break;
272
+ case CHn_WRITE_ADDR:
273
+ case CHn_AL1_WRITE_ADDR:
274
+ case CHn_AL2_WRITE_ADDR_TRIG:
275
+ case CHn_AL3_WRITE_ADDR:
276
+ this.writeAddr = value;
277
+ break;
278
+ case CHn_TRANS_COUNT:
279
+ case CHn_AL1_TRANS_COUNT_TRIG:
280
+ case CHn_AL2_TRANS_COUNT:
281
+ case CHn_AL3_TRANS_COUNT:
282
+ this.transCountReload = value;
283
+ break;
284
+ case CHn_CTRL_TRIG:
285
+ case CHn_AL1_CTRL:
286
+ case CHn_AL2_CTRL:
287
+ case CHn_AL3_CTRL: {
288
+ this.ctrl = (this.ctrl & ~CHn_CTRL_TRIG_WRITE_MASK) | (value & CHn_CTRL_TRIG_WRITE_MASK);
289
+ this.ctrl &= ~(value & CHn_CTRL_TRIG_WC_MASK); // Handle write-clear (WC) bits
290
+ this.treqValue = (this.ctrl >> TREQ_SEL_SHIFT) & TREQ_SEL_MASK;
291
+ this.chainTo = (this.ctrl >> CHAIN_TO_SHIFT) & CHAIN_TO_MASK;
292
+ const ringSize = (this.ctrl >> RING_SIZE_SHIFT) & RING_SIZE_MASK;
293
+ this.ringMask = ringSize ? (1 << ringSize) - 1 : 0;
294
+ switch ((this.ctrl >> DATA_SIZE_SHIFT) & DATA_SIZE_MASK) {
295
+ case 1:
296
+ this.dataSize = 2;
297
+ this.transferFn = this.ctrl & BSWAP ? this.transferSwap16 : this.transfer16;
298
+ break;
299
+ case 2:
300
+ this.dataSize = 4;
301
+ this.transferFn = this.ctrl & BSWAP ? this.transferSwap32 : this.transfer32;
302
+ break;
303
+ case 0:
304
+ default:
305
+ this.transferFn = this.transfer8;
306
+ this.dataSize = 1;
307
+ }
308
+ if (this.ctrl & EN && this.ctrl & BUSY) {
309
+ this.scheduleTransfer();
310
+ }
311
+ if (!(this.ctrl & EN) && this.transferTimer) {
312
+ this.rp2040.clock.deleteTimer(this.transferTimer);
313
+ this.transferTimer = null;
314
+ }
315
+ break;
316
+ }
317
+ case CHn_DBG_CTDREQ:
318
+ this.dreqCounter = 0;
319
+ break;
320
+ }
321
+ if (offset === CHn_AL3_READ_ADDR_TRIG ||
322
+ offset === CHn_AL2_WRITE_ADDR_TRIG ||
323
+ offset === CHn_AL1_TRANS_COUNT_TRIG ||
324
+ offset === CHn_CTRL_TRIG) {
325
+ if (value) {
326
+ this.start();
327
+ }
328
+ else if (this.ctrl & IRQ_QUIET) {
329
+ // Null trigger interrupts
330
+ this.dma.intRaw |= 1 << this.index;
331
+ this.dma.checkInterrupts();
332
+ }
333
+ }
334
+ }
335
+ reset() {
336
+ this.writeUint32(CHn_CTRL_TRIG, this.index << CHAIN_TO_SHIFT);
337
+ }
338
+ }
339
+ export class RPDMA extends BasePeripheral {
340
+ constructor() {
341
+ super(...arguments);
342
+ this.channels = [
343
+ new RPDMAChannel(this, this.rp2040, 0),
344
+ new RPDMAChannel(this, this.rp2040, 1),
345
+ new RPDMAChannel(this, this.rp2040, 2),
346
+ new RPDMAChannel(this, this.rp2040, 3),
347
+ new RPDMAChannel(this, this.rp2040, 4),
348
+ new RPDMAChannel(this, this.rp2040, 5),
349
+ new RPDMAChannel(this, this.rp2040, 6),
350
+ new RPDMAChannel(this, this.rp2040, 7),
351
+ new RPDMAChannel(this, this.rp2040, 8),
352
+ new RPDMAChannel(this, this.rp2040, 9),
353
+ new RPDMAChannel(this, this.rp2040, 10),
354
+ new RPDMAChannel(this, this.rp2040, 11),
355
+ ];
356
+ this.intRaw = 0;
357
+ this.intEnable0 = 0;
358
+ this.intForce0 = 0;
359
+ this.intEnable1 = 0;
360
+ this.intForce1 = 0;
361
+ this.timer0 = 0;
362
+ this.timer1 = 0;
363
+ this.timer2 = 0;
364
+ this.timer3 = 0;
365
+ this.dreq = Array(DREQChannel.DREQ_MAX);
366
+ }
367
+ get intStatus0() {
368
+ return (this.intRaw & this.intEnable0) | this.intForce0;
369
+ }
370
+ get intStatus1() {
371
+ return (this.intRaw & this.intEnable1) | this.intForce1;
372
+ }
373
+ readUint32(offset) {
374
+ if ((offset & 0x7ff) <= CHANNEL_REGISTERS_SIZE) {
375
+ const channelIndex = (offset & 0x7ff) >> 6;
376
+ return this.channels[channelIndex].readUint32(offset & CHANNEL_REGISTERS_MASK);
377
+ }
378
+ switch (offset) {
379
+ case TIMER0:
380
+ return this.timer0;
381
+ case TIMER1:
382
+ return this.timer1;
383
+ case TIMER2:
384
+ return this.timer2;
385
+ case TIMER3:
386
+ return this.timer3;
387
+ case INTR:
388
+ return this.intRaw;
389
+ case INTE0:
390
+ return this.intEnable0;
391
+ case INTF0:
392
+ return this.intForce0;
393
+ case INTS0:
394
+ return this.intStatus0;
395
+ case INTE1:
396
+ return this.intEnable1;
397
+ case INTF1:
398
+ return this.intForce1;
399
+ case INTS1:
400
+ return this.intStatus1;
401
+ case N_CHANNELS:
402
+ return this.channels.length;
403
+ }
404
+ return super.readUint32(offset);
405
+ }
406
+ writeUint32(offset, value) {
407
+ if ((offset & 0x7ff) <= CHANNEL_REGISTERS_SIZE) {
408
+ const channelIndex = (offset & 0x7ff) >> 6;
409
+ this.channels[channelIndex].writeUint32(offset & CHANNEL_REGISTERS_MASK, value);
410
+ return;
411
+ }
412
+ switch (offset) {
413
+ case TIMER0:
414
+ this.timer0 = value;
415
+ return;
416
+ case TIMER1:
417
+ this.timer1 = value;
418
+ return;
419
+ case TIMER2:
420
+ this.timer2 = value;
421
+ return;
422
+ case TIMER3:
423
+ this.timer3 = value;
424
+ return;
425
+ case INTR:
426
+ case INTS0:
427
+ case INTS1:
428
+ this.intRaw &= ~this.rawWriteValue;
429
+ this.checkInterrupts();
430
+ return;
431
+ case INTE0:
432
+ this.intEnable0 = value & 0xffff;
433
+ this.checkInterrupts();
434
+ return;
435
+ case INTF0:
436
+ this.intForce0 = value & 0xffff;
437
+ this.checkInterrupts();
438
+ return;
439
+ case INTE1:
440
+ this.intEnable1 = value & 0xffff;
441
+ this.checkInterrupts();
442
+ return;
443
+ case INTF1:
444
+ this.intForce1 = value & 0xffff;
445
+ this.checkInterrupts();
446
+ return;
447
+ case MULTI_CHAN_TRIGGER:
448
+ for (const chan of this.channels) {
449
+ if (value & (1 << chan.index)) {
450
+ chan.start();
451
+ }
452
+ }
453
+ return;
454
+ case CHAN_ABORT:
455
+ for (const chan of this.channels) {
456
+ if (value & (1 << chan.index)) {
457
+ chan.abort();
458
+ }
459
+ }
460
+ return;
461
+ default:
462
+ super.writeUint32(offset, value);
463
+ }
464
+ }
465
+ setDREQ(dreqChannel) {
466
+ const { dreq } = this;
467
+ if (!dreq[dreqChannel]) {
468
+ dreq[dreqChannel] = true;
469
+ for (const channel of this.channels) {
470
+ if (channel.treq === dreqChannel && channel.active) {
471
+ channel.scheduleTransfer();
472
+ }
473
+ }
474
+ }
475
+ }
476
+ clearDREQ(dreqChannel) {
477
+ this.dreq[dreqChannel] = false;
478
+ }
479
+ /**
480
+ * Returns the number of microseconds for a cycle of the given DMA timer, or 0 if the timer is disabled.
481
+ */
482
+ getTimer(treq) {
483
+ let dividend = 0, divisor = 1;
484
+ switch (treq) {
485
+ case TREQ.Permanent:
486
+ dividend = 1;
487
+ divisor = 1;
488
+ break;
489
+ case TREQ.Timer0:
490
+ dividend = this.timer0 >>> 16;
491
+ divisor = this.timer0 & 0xffff;
492
+ break;
493
+ case TREQ.Timer1:
494
+ dividend = this.timer1 >>> 16;
495
+ divisor = this.timer1 & 0xffff;
496
+ break;
497
+ case TREQ.Timer2:
498
+ dividend = this.timer2 >>> 16;
499
+ divisor = this.timer2 & 0xffff;
500
+ break;
501
+ case TREQ.Timer3:
502
+ dividend = this.timer3 >>> 36;
503
+ divisor = this.timer3 & 0xffff;
504
+ break;
505
+ }
506
+ if (divisor === 0) {
507
+ return 0;
508
+ }
509
+ return ((dividend / divisor) * 1e6) / this.rp2040.clkSys;
510
+ }
511
+ checkInterrupts() {
512
+ this.rp2040.setInterrupt(IRQ.DMA_IRQ0, !!this.intStatus0);
513
+ this.rp2040.setInterrupt(IRQ.DMA_IRQ1, !!this.intStatus1);
514
+ }
515
+ }