From ae441981d7ade3ac00837ace14bc1e4f308f6653 Mon Sep 17 00:00:00 2001 From: Jonathan BAUDIN <jonathan.baudin@atmel.com> Date: Mon, 2 Jun 2014 13:40:20 +0200 Subject: [PATCH] Validation Interrupt --- cores/arduino/WInterrupts.c | 33 ++++++++++++++++------- cores/arduino/delay.c | 2 +- cores/arduino/delay.h | 9 +++++-- cores/validation/validation_core/test.cpp | 10 +++---- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/cores/arduino/WInterrupts.c b/cores/arduino/WInterrupts.c index 6bbdf362..25b45d79 100644 --- a/cores/arduino/WInterrupts.c +++ b/cores/arduino/WInterrupts.c @@ -51,6 +51,8 @@ static void __initialize() NVIC_SetPriority( EIC_IRQn, 0 ) ; NVIC_EnableIRQ( EIC_IRQn ) ; + + // Enable GCLK for IEC (External Interrupt Controller) GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID( GCM_EIC )) ; @@ -60,9 +62,18 @@ static void __initialize() while ( (EIC->CTRL.SWRST.bit == 1) && (EIC->STATUS.SYNCBUSY.bit == 1) ) { - // Wait for synchronisation + // Waiting for synchronisation } */ + + // Enable EIC + EIC->CTRL.bit.ENABLE = 1 ; + + while ( EIC->STATUS.bit.SYNCBUSY == 1 ) + { + // Waiting for synchronisation + } + } /* @@ -109,27 +120,31 @@ void attachInterrupt( uint32_t ulPin, voidFuncPtr callback, uint32_t ulMode ) } // Configure the interrupt mode - ulPos = ((digitalPinToInterrupt( ulPin ) >> ulConfig ) << 2) ; + ulPos = ((digitalPinToInterrupt( ulPin ) - (8*ulConfig) ) << 2) ; switch ( ulMode ) { case LOW: - EIC->CONFIG[ulConfig].reg = EIC_CONFIG_SENSE0_LOW_Val << ulPos ; + EIC->CONFIG[ulConfig].reg |= EIC_CONFIG_SENSE0_LOW_Val << ulPos ; break ; case HIGH: - EIC->CONFIG[ulConfig].reg = EIC_CONFIG_SENSE0_HIGH_Val << ((digitalPinToInterrupt( ulPin ) >> ulConfig ) << 2) ; + // EIC->CONFIG[ulConfig].reg = EIC_CONFIG_SENSE0_HIGH_Val << ((digitalPinToInterrupt( ulPin ) >> ulConfig ) << ulPos) ; + EIC->CONFIG[ulConfig].reg |= EIC_CONFIG_SENSE0_HIGH_Val << ulPos ; break ; case CHANGE: - EIC->CONFIG[ulConfig].reg = EIC_CONFIG_SENSE0_BOTH_Val << ((digitalPinToInterrupt( ulPin ) >> ulConfig ) << 2) ; + // EIC->CONFIG[ulConfig].reg = EIC_CONFIG_SENSE0_BOTH_Val << ((digitalPinToInterrupt( ulPin ) >> ulConfig ) << ulPos) ; + EIC->CONFIG[ulConfig].reg |= EIC_CONFIG_SENSE0_BOTH_Val << ulPos ; break ; case FALLING: - EIC->CONFIG[ulConfig].reg = EIC_CONFIG_SENSE0_FALL_Val << ((digitalPinToInterrupt( ulPin ) >> ulConfig ) << 2) ; + // EIC->CONFIG[ulConfig].reg = EIC_CONFIG_SENSE0_FALL_Val << ((digitalPinToInterrupt( ulPin ) >> ulConfig ) << ulPos) ; + EIC->CONFIG[ulConfig].reg |= EIC_CONFIG_SENSE0_FALL_Val << ulPos ; break ; case RISING: - EIC->CONFIG[ulConfig].reg = EIC_CONFIG_SENSE0_RISE_Val << ((digitalPinToInterrupt( ulPin ) >> ulConfig ) << 2) ; + // EIC->CONFIG[ulConfig].reg = EIC_CONFIG_SENSE0_RISE_Val << ((digitalPinToInterrupt( ulPin ) >> ulConfig ) << ulPos) ; + EIC->CONFIG[ulConfig].reg |= EIC_CONFIG_SENSE0_RISE_Val << ulPos ; break ; } @@ -209,9 +224,9 @@ void EIC_Handler( void ) } // Test the 16 normal interrupts - for ( ul = EXTERNAL_INT_0 ; ul < EXTERNAL_INT_15 ; ul++ ) + for ( ul = EXTERNAL_INT_0 ; ul < EXTERNAL_INT_NMI ; ul++ ) { - if ( (EIC->INTFLAG.reg & 1 << ul) != 0 ) + if ( (EIC->INTFLAG.reg & ( 1 << ul ) ) != 0 ) { // Call the callback function if assigned if ( callbacksInt[ul]._callback != NULL ) diff --git a/cores/arduino/delay.c b/cores/arduino/delay.c index 83427841..2548f91e 100644 --- a/cores/arduino/delay.c +++ b/cores/arduino/delay.c @@ -55,7 +55,7 @@ void delay( uint32_t ms ) do { yield() ; - } while ( _ulTickCount - start < ms ) ; + } while ( _ulTickCount - start <= ms ) ; } void SysTick_Handler( void ) diff --git a/cores/arduino/delay.h b/cores/arduino/delay.h index f9b08efe..9809fc37 100644 --- a/cores/arduino/delay.h +++ b/cores/arduino/delay.h @@ -64,13 +64,18 @@ static inline void delayMicroseconds(uint32_t) __attribute__((always_inline, unu static inline void delayMicroseconds(uint32_t usec){ if (usec == 0) return; uint32_t n = usec * (VARIANT_MCK / 3000000); - +#if 0 __asm__ volatile( "L_%=_delayMicroseconds:" "\n\t" - "subs %0, #1" "\n\t" + "subs %0, %0, #1" "\n\t" "bne L_%=_delayMicroseconds" "\n" : "+r" (n) : ); +#else + for ( ; n != 0 ; n-- ) + { + } +#endif } /* diff --git a/cores/validation/validation_core/test.cpp b/cores/validation/validation_core/test.cpp index 85e5315d..e86988ab 100644 --- a/cores/validation/validation_core/test.cpp +++ b/cores/validation/validation_core/test.cpp @@ -56,9 +56,9 @@ void setup( void ) //********************************************** // Clock output on pin 4 for measure - pinPeripheral( 4, PIO_AC_CLK ) ; // Clock Gen 0 + /* pinPeripheral( 4, PIO_AC_CLK ) ; // Clock Gen 0 pinPeripheral( 5, PIO_AC_CLK ) ; // Clock Gen 1 - pinPeripheral( 13, PIO_AC_CLK ) ; // Clock Gen 3 + pinPeripheral( 13, PIO_AC_CLK ) ; // Clock Gen 3*/ //********************************************** Serial5.begin( 115200 ) ; // Output to EDBG Virtual COM Port @@ -113,10 +113,6 @@ void loop( void ) analogWrite( 10 ,duty_cycle ) ; analogWrite( 9, duty_cycle ) ; analogWrite( 8, duty_cycle ) ; - analogWrite( 7, duty_cycle ) ; - analogWrite( 6, duty_cycle ) ; - analogWrite( 5, duty_cycle ) ; - analogWrite( 4, duty_cycle ) ; Serial5.print("\r\nAnalog pins: "); @@ -157,7 +153,7 @@ void loop( void ) if ( ul_Interrupt_Pin7 == 1 ) { - Serial5.println( "Pin 3 triggered (CHANGE)" ) ; + Serial5.println( "Pin 7 triggered (CHANGE)" ) ; ul_Interrupt_Pin7 = 0 ; } } -- GitLab