@ -19,29 +19,20 @@
# ifdef TARGET_LPC1768
# ifdef TARGET_LPC1768
# include "../../inc/MarlinConfig.h"
# include "../../inc/MarlinConfig.h"
# include <Arduino.h>
# include <pinmapping.h>
//#include "HAL_timers.h"
# include "fastio.h"
# define GNUM 31
# define GNUM 31
typedef void ( * interruptCB ) ( void ) ;
typedef void ( * interruptCB ) ( void ) ;
static interruptCB callbacksP0 [ GNUM ] ;
static interruptCB callbacksP0 [ GNUM ] = { } ;
static interruptCB callbacksP2 [ GNUM ] ;
static interruptCB callbacksP2 [ GNUM ] = { } ;
extern " C " void GpioEnableInt ( const uint32_t port , const uint32_t pin , const uint32_t mode ) ;
extern " C " void GpioEnableInt ( const uint32_t port , const uint32_t pin , const uint32_t mode ) ;
extern " C " void GpioDisableInt ( const uint32_t port , const uint32_t pin ) ;
extern " C " void GpioDisableInt ( const uint32_t port , const uint32_t pin ) ;
//void deadloop(void) {}
/* Configure PIO interrupt sources */
static void __initialize ( ) {
static void __initialize ( ) {
for ( uint8_t i = 0 ; i < GNUM ; i + + ) {
NVIC_SetPriority ( EINT3_IRQn , NVIC_EncodePriority ( 0 , 1 , 0 ) ) ;
callbacksP0 [ i ] = 0 ;
callbacksP2 [ i ] = 0 ;
}
NVIC_EnableIRQ ( EINT3_IRQn ) ;
NVIC_EnableIRQ ( EINT3_IRQn ) ;
}
}
@ -54,6 +45,7 @@ void attachInterrupt(const pin_t pin, void (*callback)(void), uint32_t mode) {
__initialize ( ) ;
__initialize ( ) ;
+ + enabled ;
+ + enabled ;
}
}
uint8_t myport = LPC1768_PIN_PORT ( pin ) ,
uint8_t myport = LPC1768_PIN_PORT ( pin ) ,
mypin = LPC1768_PIN_PIN ( pin ) ;
mypin = LPC1768_PIN_PIN ( pin ) ;
@ -130,60 +122,41 @@ extern "C" void GpioDisableInt(const uint32_t port, const uint32_t pin) {
}
}
}
}
constexpr bool isPowerOf2 ( const uint16_t n ) {
extern " C " void EINT3_IRQHandler ( void ) {
return IS_POWER_OF_2 ( n ) ;
// Read in all current interrupt registers. We do this once as the
}
// GPIO interrupt registers are on the APB bus, and this is slow.
uint32_t rise0 = LPC_GPIOINT - > IO0IntStatR ,
#if 0
fall0 = LPC_GPIOINT - > IO0IntStatF ,
extern " C " void EINT3_IRQHandler ( ) {
rise2 = LPC_GPIOINT - > IO2IntStatR ,
LPC_GPIOINT - > IO0IntClr = LPC_GPIOINT - > IO2IntClr = 0xFFFFFFFF ;
fall2 = LPC_GPIOINT - > IO2IntStatF ;
TOGGLE ( 13 ) ;
//NVIC_ClearPendingIRQ(EINT3_IRQn);
// Clear the interrupts ASAP
LPC_GPIOINT - > IO0IntClr = LPC_GPIOINT - > IO2IntClr = 0xFFFFFFFF ;
NVIC_ClearPendingIRQ ( EINT3_IRQn ) ;
while ( rise0 > 0 ) { // If multiple pins changes happened continue as long as there are interrupts pending
const uint8_t bitloc = 31 - __CLZ ( rise0 ) ; // CLZ returns number of leading zeros, 31 minus that is location of first pending interrupt
if ( callbacksP0 [ bitloc ] ! = NULL ) callbacksP0 [ bitloc ] ( ) ;
rise0 - = _BV ( bitloc ) ;
}
}
# else
extern " C " void EINT3_IRQHandler ( void ) {
// Read in all current interrupt registers. We do this once as the
// GPIO interrupt registers are on the APB bus, and this is slow.
uint32_t rise0 = LPC_GPIOINT - > IO0IntStatR ,
fall0 = LPC_GPIOINT - > IO0IntStatF ,
rise2 = LPC_GPIOINT - > IO2IntStatR ,
fall2 = LPC_GPIOINT - > IO2IntStatF ;
// Clear the interrupts ASAP
LPC_GPIOINT - > IO0IntClr = LPC_GPIOINT - > IO2IntClr = 0xFFFFFFFF ;
NVIC_ClearPendingIRQ ( EINT3_IRQn ) ;
/* multiple pins changes happened.*/
if ( rise0 ) while ( rise0 > 0 ) { // Continue as long as there are interrupts pending
const uint8_t bitloc = 31 - __CLZ ( rise0 ) ; //CLZ returns number of leading zeros, 31 minus that is location of first pending interrupt
if ( callbacksP0 [ bitloc ] ! = NULL ) callbacksP0 [ bitloc ] ( ) ;
rise0 - = _BV ( bitloc ) ;
}
if ( fall0 ) while ( fall0 > 0 ) {
const uint8_t bitloc = 31 - __CLZ ( fall0 ) ;
if ( callbacksP0 [ bitloc ] ! = NULL ) callbacksP0 [ bitloc ] ( ) ;
fall0 - = _BV ( bitloc ) ;
}
if ( rise2 ) while ( rise2 > 0 ) {
while ( fall0 > 0 ) {
const uint8_t bitloc = 31 - __CLZ ( rise2 ) ;
const uint8_t bitloc = 31 - __CLZ ( fall0 ) ;
if ( callbacksP2 [ bitloc ] ! = NULL ) callbacksP2 [ bitloc ] ( ) ;
if ( callbacksP0 [ bitloc ] ! = NULL ) callbacksP0 [ bitloc ] ( ) ;
//LPC_GPIOINT->IO2IntClr = 1 << bitloc;
fall0 - = _BV ( bitloc ) ;
rise2 - = _BV ( bitloc ) ;
}
}
if ( fall2 ) while ( fall2 > 0 ) {
while ( rise2 > 0 ) {
const uint8_t bitloc = 31 - __CLZ ( fall2 ) ;
const uint8_t bitloc = 31 - __CLZ ( rise2 ) ;
if ( callbacksP2 [ bitloc ] ! = NULL ) callbacksP2 [ bitloc ] ( ) ;
if ( callbacksP2 [ bitloc ] ! = NULL ) callbacksP2 [ bitloc ] ( ) ;
//LPC_GPIOINT->IO2IntClr = 1 << bitloc;
rise2 - = _BV ( bitloc ) ;
fall2 - = _BV ( bitloc ) ;
}
//NVIC_ClearPendingIRQ(EINT3_IRQn);
//LPC_GPIOINT->IO0IntClr = LPC_GPIOINT->IO2IntClr = 0xFFFFFFFF;
//NVIC_ClearPendingIRQ(EINT3_IRQn);
}
}
# endif
while ( fall2 > 0 ) {
const uint8_t bitloc = 31 - __CLZ ( fall2 ) ;
if ( callbacksP2 [ bitloc ] ! = NULL ) callbacksP2 [ bitloc ] ( ) ;
fall2 - = _BV ( bitloc ) ;
}
}
# endif // TARGET_LPC1768
# endif // TARGET_LPC1768