|
@@ -19,29 +19,20 @@
|
19
|
19
|
#ifdef TARGET_LPC1768
|
20
|
20
|
|
21
|
21
|
#include "../../inc/MarlinConfig.h"
|
22
|
|
-#include <Arduino.h>
|
23
|
|
-#include <pinmapping.h>
|
24
|
|
-//#include "HAL_timers.h"
|
25
|
|
-#include "fastio.h"
|
26
|
22
|
|
27
|
23
|
#define GNUM 31
|
28
|
24
|
|
29
|
25
|
typedef void (*interruptCB)(void);
|
30
|
26
|
|
31
|
|
-static interruptCB callbacksP0[GNUM];
|
32
|
|
-static interruptCB callbacksP2[GNUM];
|
|
27
|
+static interruptCB callbacksP0[GNUM] = {};
|
|
28
|
+static interruptCB callbacksP2[GNUM] = {};
|
33
|
29
|
|
34
|
30
|
extern "C" void GpioEnableInt(const uint32_t port, const uint32_t pin, const uint32_t mode);
|
35
|
31
|
extern "C" void GpioDisableInt(const uint32_t port, const uint32_t pin);
|
36
|
32
|
|
37
|
|
-//void deadloop(void) {}
|
38
|
33
|
|
39
|
|
-/* Configure PIO interrupt sources */
|
40
|
34
|
static void __initialize() {
|
41
|
|
- for (uint8_t i = 0; i < GNUM; i++) {
|
42
|
|
- callbacksP0[i] = 0;
|
43
|
|
- callbacksP2[i] = 0;
|
44
|
|
- }
|
|
35
|
+ NVIC_SetPriority(EINT3_IRQn, NVIC_EncodePriority(0, 1, 0));
|
45
|
36
|
NVIC_EnableIRQ(EINT3_IRQn);
|
46
|
37
|
}
|
47
|
38
|
|
|
@@ -54,6 +45,7 @@ void attachInterrupt(const pin_t pin, void (*callback)(void), uint32_t mode) {
|
54
|
45
|
__initialize();
|
55
|
46
|
++enabled;
|
56
|
47
|
}
|
|
48
|
+
|
57
|
49
|
uint8_t myport = LPC1768_PIN_PORT(pin),
|
58
|
50
|
mypin = LPC1768_PIN_PIN(pin);
|
59
|
51
|
|
|
@@ -130,60 +122,41 @@ extern "C" void GpioDisableInt(const uint32_t port, const uint32_t pin) {
|
130
|
122
|
}
|
131
|
123
|
}
|
132
|
124
|
|
133
|
|
-constexpr bool isPowerOf2(const uint16_t n) {
|
134
|
|
- return IS_POWER_OF_2(n);
|
135
|
|
-}
|
136
|
|
-
|
137
|
|
-#if 0
|
138
|
|
- extern "C" void EINT3_IRQHandler () {
|
139
|
|
- LPC_GPIOINT->IO0IntClr = LPC_GPIOINT->IO2IntClr = 0xFFFFFFFF;
|
140
|
|
- TOGGLE(13);
|
141
|
|
- //NVIC_ClearPendingIRQ(EINT3_IRQn);
|
|
125
|
+extern "C" void EINT3_IRQHandler(void) {
|
|
126
|
+ // Read in all current interrupt registers. We do this once as the
|
|
127
|
+ // GPIO interrupt registers are on the APB bus, and this is slow.
|
|
128
|
+ uint32_t rise0 = LPC_GPIOINT->IO0IntStatR,
|
|
129
|
+ fall0 = LPC_GPIOINT->IO0IntStatF,
|
|
130
|
+ rise2 = LPC_GPIOINT->IO2IntStatR,
|
|
131
|
+ fall2 = LPC_GPIOINT->IO2IntStatF;
|
|
132
|
+
|
|
133
|
+ // Clear the interrupts ASAP
|
|
134
|
+ LPC_GPIOINT->IO0IntClr = LPC_GPIOINT->IO2IntClr = 0xFFFFFFFF;
|
|
135
|
+ NVIC_ClearPendingIRQ(EINT3_IRQn);
|
|
136
|
+
|
|
137
|
+ while (rise0 > 0) { // If multiple pins changes happened continue as long as there are interrupts pending
|
|
138
|
+ const uint8_t bitloc = 31 - __CLZ(rise0); // CLZ returns number of leading zeros, 31 minus that is location of first pending interrupt
|
|
139
|
+ if (callbacksP0[bitloc] != NULL) callbacksP0[bitloc]();
|
|
140
|
+ rise0 -= _BV(bitloc);
|
142
|
141
|
}
|
143
|
|
-#else
|
144
|
|
-
|
145
|
|
- extern "C" void EINT3_IRQHandler(void) {
|
146
|
|
- // Read in all current interrupt registers. We do this once as the
|
147
|
|
- // GPIO interrupt registers are on the APB bus, and this is slow.
|
148
|
|
- uint32_t rise0 = LPC_GPIOINT->IO0IntStatR,
|
149
|
|
- fall0 = LPC_GPIOINT->IO0IntStatF,
|
150
|
|
- rise2 = LPC_GPIOINT->IO2IntStatR,
|
151
|
|
- fall2 = LPC_GPIOINT->IO2IntStatF;
|
152
|
|
- // Clear the interrupts ASAP
|
153
|
|
- LPC_GPIOINT->IO0IntClr = LPC_GPIOINT->IO2IntClr = 0xFFFFFFFF;
|
154
|
|
- NVIC_ClearPendingIRQ(EINT3_IRQn);
|
155
|
|
-
|
156
|
|
- /* multiple pins changes happened.*/
|
157
|
|
- if (rise0) while (rise0 > 0) { // Continue as long as there are interrupts pending
|
158
|
|
- const uint8_t bitloc = 31 - __CLZ(rise0); //CLZ returns number of leading zeros, 31 minus that is location of first pending interrupt
|
159
|
|
- if (callbacksP0[bitloc] != NULL) callbacksP0[bitloc]();
|
160
|
|
- rise0 -= _BV(bitloc);
|
161
|
|
- }
|
162
|
|
-
|
163
|
|
- if (fall0) while (fall0 > 0) {
|
164
|
|
- const uint8_t bitloc = 31 - __CLZ(fall0);
|
165
|
|
- if (callbacksP0[bitloc] != NULL) callbacksP0[bitloc]();
|
166
|
|
- fall0 -= _BV(bitloc);
|
167
|
|
- }
|
168
|
142
|
|
169
|
|
- if (rise2) while(rise2 > 0) {
|
170
|
|
- const uint8_t bitloc = 31 - __CLZ(rise2);
|
171
|
|
- if (callbacksP2[bitloc] != NULL) callbacksP2[bitloc]();
|
172
|
|
- //LPC_GPIOINT->IO2IntClr = 1 << bitloc;
|
173
|
|
- rise2 -= _BV(bitloc);
|
174
|
|
- }
|
|
143
|
+ while (fall0 > 0) {
|
|
144
|
+ const uint8_t bitloc = 31 - __CLZ(fall0);
|
|
145
|
+ if (callbacksP0[bitloc] != NULL) callbacksP0[bitloc]();
|
|
146
|
+ fall0 -= _BV(bitloc);
|
|
147
|
+ }
|
175
|
148
|
|
176
|
|
- if (fall2) while (fall2 > 0) {
|
177
|
|
- const uint8_t bitloc = 31 - __CLZ(fall2);
|
178
|
|
- if (callbacksP2[bitloc] != NULL) callbacksP2[bitloc]();
|
179
|
|
- //LPC_GPIOINT->IO2IntClr = 1 << bitloc;
|
180
|
|
- fall2 -= _BV(bitloc);
|
181
|
|
- }
|
182
|
|
- //NVIC_ClearPendingIRQ(EINT3_IRQn);
|
183
|
|
- //LPC_GPIOINT->IO0IntClr = LPC_GPIOINT->IO2IntClr = 0xFFFFFFFF;
|
184
|
|
- //NVIC_ClearPendingIRQ(EINT3_IRQn);
|
|
149
|
+ while(rise2 > 0) {
|
|
150
|
+ const uint8_t bitloc = 31 - __CLZ(rise2);
|
|
151
|
+ if (callbacksP2[bitloc] != NULL) callbacksP2[bitloc]();
|
|
152
|
+ rise2 -= _BV(bitloc);
|
185
|
153
|
}
|
186
|
154
|
|
187
|
|
-#endif
|
|
155
|
+ while (fall2 > 0) {
|
|
156
|
+ const uint8_t bitloc = 31 - __CLZ(fall2);
|
|
157
|
+ if (callbacksP2[bitloc] != NULL) callbacksP2[bitloc]();
|
|
158
|
+ fall2 -= _BV(bitloc);
|
|
159
|
+ }
|
|
160
|
+}
|
188
|
161
|
|
189
|
162
|
#endif // TARGET_LPC1768
|