Ejemplo n.º 1
0
/* Disable interrupts
*
*/
void ADC_Module::disableInterrupts() {

    var_enableInterrupts = 0;
    *ADC_SC1A_aien = 0;
    #if defined(__MK20DX128__)
    NVIC_DISABLE_IRQ(IRQ_ADC0);
    #elif defined(__MK20DX256__)
    if(ADC_num==1) { // enable correct interrupt
        NVIC_DISABLE_IRQ(IRQ_ADC1);
    } else {
        NVIC_DISABLE_IRQ(IRQ_ADC0);
    }
    #endif // defined
}
Ejemplo n.º 2
0
/* Disable interrupts
*
*/
void ADC_Module::disableInterrupts() {

    var_enableInterrupts = 0;
    // *ADC_SC1A_aien = 0;
    clearBit(ADC_SC1A, ADC_SC1A_AIEN_BIT);

    NVIC_DISABLE_IRQ(IRQ_ADC);

}
Ejemplo n.º 3
0
void Servo::detach()  
{
	if (servoIndex >= MAX_SERVOS) return;
	servo_active_mask &= ~(1<<servoIndex);
	servo_allocated_mask &= ~(1<<servoIndex);
	if (servo_active_mask == 0) {
		NVIC_DISABLE_IRQ(IRQ_PDB);
	}
}
void AudioPlaySdAac::stop(void)
{
	NVIC_DISABLE_IRQ(IRQ_AUDIOCODEC);

	playing = codec_stopped;
	if (buf[1]) {free(buf[1]);buf[1] = NULL;}
	if (buf[0]) {free(buf[0]);buf[0] = NULL;}
	freeBuffer();
	if (hAACDecoder) {AACFreeDecoder(hAACDecoder);hAACDecoder=NULL;};
	fclose();
}
Ejemplo n.º 5
0
// ------------------------------------------------------------
// stops an active PIT by disabling its interrupt, writing to
// its control register, and freeing up its state for future use.
// also, if no PITs remain in use, disables the core PIT clock
// ------------------------------------------------------------
void IntervalTimer::stop_PIT() {
  
  // disable interrupt and PIT
  *PIT_TCTRL = 0;
#if defined(KINETISK)
  NVIC_DISABLE_IRQ(IRQ_PIT_CH);
#elif defined(KINETISL)
  NVIC_DISABLE_IRQ(IRQ_PIT);
#endif
  
  // free PIT for future use
  PIT_used[PIT_id] = false;
  
  // check if we're still using any PIT
  for (uint8_t id = 0; id < NUM_PIT; id++) {
    if (PIT_used[id]) return;
  }
  
  // none used, disable PIT clock
  disable_PIT();
  
}
Ejemplo n.º 6
0
void TwoWire::end()
{
	if (!(hardware.clock_gate_register & hardware.clock_gate_mask)) return;
	NVIC_DISABLE_IRQ(hardware.irq);
	// TODO: should this try to create a stop condition??
	port().C1 = 0;
	volatile uint32_t *reg;
	reg = portConfigRegister(hardware.scl_pin[scl_pin_index]);
	*reg = 0;
	reg = portConfigRegister(hardware.sda_pin[sda_pin_index]);
	*reg = 0;
	hardware.clock_gate_register &= ~hardware.clock_gate_mask;
}
void TwoWire::end()
{
	if (!(SIM_SCGC4 & SIM_SCGC4_I2C0)) return;
	NVIC_DISABLE_IRQ(IRQ_I2C0);
	I2C0_C1 = 0;
	if (sda_pin_num == 18) {
		CORE_PIN18_CONFIG = 0;
	} else if (sda_pin_num == 17) {
		CORE_PIN17_CONFIG = 0;
	}
	if (scl_pin_num == 19) {
		CORE_PIN19_CONFIG = 0;
	} else if (scl_pin_num == 16) {
		CORE_PIN16_CONFIG = 0;
	}
	SIM_SCGC4 &= ~SIM_SCGC4_I2C0; // TODO: use bitband
}
Ejemplo n.º 8
0
/**
 *  wakeupISR - handle LLWU interrupts after wakeup.
 */
void SnoozeClass::wakeupISR( void ) {
    NVIC_DISABLE_IRQ( IRQ_LLWU ); // disable wakeup isr
    if ( sleep_mode == LLS ) {
        __disable_irq( );
        llwuFlag = llwu_clear_flags( );// clear flags
        lptmrISR( );
        cmp0ISR( );
#ifdef KINETISK
        rtcISR( );
#endif
        tsiISR( );
        /************************************
         * back to PEE if in PBE, else it is
         * in either BLPI/BLPE, if so nothing
         * to do.
         ************************************/
        pbe_pee( );
        __enable_irq( );
    }
}
Ejemplo n.º 9
0
/*******************************************************************************
 *  Enable digital interrupt and configure the pin
 *******************************************************************************/
void SnoozeDigital::enableDriver( void ) {
    if ( mode == RUN_LP ) { return; }
#if defined(KINETISK)
    uint64_t _pin = pin;
    isr_pin = pin;
    if ( mode == VLPW || mode == VLPS ) {

        return_isr_a_enabled = NVIC_IS_ENABLED( IRQ_PORTA );
        return_isr_b_enabled = NVIC_IS_ENABLED( IRQ_PORTB );
        return_isr_c_enabled = NVIC_IS_ENABLED( IRQ_PORTC );
        return_isr_d_enabled = NVIC_IS_ENABLED( IRQ_PORTD );
        return_isr_e_enabled = NVIC_IS_ENABLED( IRQ_PORTE );
        NVIC_DISABLE_IRQ(IRQ_PORTA);
        NVIC_DISABLE_IRQ(IRQ_PORTB);
        NVIC_DISABLE_IRQ(IRQ_PORTC);
        NVIC_DISABLE_IRQ(IRQ_PORTD);
        NVIC_DISABLE_IRQ(IRQ_PORTE);
        NVIC_CLEAR_PENDING(IRQ_PORTA);
        NVIC_CLEAR_PENDING(IRQ_PORTB);
        NVIC_CLEAR_PENDING(IRQ_PORTC);
        NVIC_CLEAR_PENDING(IRQ_PORTD);
        NVIC_CLEAR_PENDING(IRQ_PORTE);
        
        int priority = nvic_execution_priority( );// get current priority
        // if running from interrupt set priority higher than current interrupt
        priority = ( priority < 256 ) && ( ( priority - 16 ) > 0 ) ? priority - 16 : 128;
        return_priority_a = NVIC_GET_PRIORITY( IRQ_PORTA );//get current priority
        return_priority_b = NVIC_GET_PRIORITY( IRQ_PORTB );//get current priority
        return_priority_c = NVIC_GET_PRIORITY( IRQ_PORTC );//get current priority
        return_priority_d = NVIC_GET_PRIORITY( IRQ_PORTD );//get current priority
        return_priority_e = NVIC_GET_PRIORITY( IRQ_PORTE );//get current priority
        NVIC_SET_PRIORITY( IRQ_PORTA, priority );//set priority to new level
        NVIC_SET_PRIORITY( IRQ_PORTB, priority );//set priority to new level
        NVIC_SET_PRIORITY( IRQ_PORTC, priority );//set priority to new level
        NVIC_SET_PRIORITY( IRQ_PORTD, priority );//set priority to new level
        NVIC_SET_PRIORITY( IRQ_PORTE, priority );//set priority to new level
        
        __disable_irq( );
        return_porta_irq = _VectorsRam[IRQ_PORTA+16];// save prev isr handler
        return_portb_irq = _VectorsRam[IRQ_PORTB+16];// save prev isr handler
        return_portc_irq = _VectorsRam[IRQ_PORTC+16];// save prev isr handler
        return_portd_irq = _VectorsRam[IRQ_PORTD+16];// save prev isr handler
        return_porte_irq = _VectorsRam[IRQ_PORTE+16];// save prev isr handler
        attachInterruptVector( IRQ_PORTA, isr );// set snooze digA isr
        attachInterruptVector( IRQ_PORTB, isr );// set snooze digB isr
        attachInterruptVector( IRQ_PORTC, isr );// set snooze digC isr
        attachInterruptVector( IRQ_PORTD, isr );// set snooze digD isr
        attachInterruptVector( IRQ_PORTE, isr );// set snooze digE isr
        __enable_irq( );
        
        NVIC_ENABLE_IRQ( IRQ_PORTA );
        NVIC_ENABLE_IRQ( IRQ_PORTB );
        NVIC_ENABLE_IRQ( IRQ_PORTC );
        NVIC_ENABLE_IRQ( IRQ_PORTD );
        NVIC_ENABLE_IRQ( IRQ_PORTE );
    }
    _pin = pin;
    while ( __builtin_popcountll( _pin ) ) {
        uint32_t pinNumber  = 63 - __builtin_clzll( _pin );// get pin
        
        if ( pinNumber > 33 ) break;
        
        uint32_t pin_mode = irqType[pinNumber] >> 4;// get type
        uint32_t pin_type = irqType[pinNumber] & 0x0F;// get mode
        
        volatile uint32_t *config;
        config = portConfigRegister( pinNumber );
        return_core_pin_config[pinNumber] = *config;
        
        if ( pin_mode == INPUT || pin_mode == INPUT_PULLUP ) {// setup pin mode/type/interrupt
            *portModeRegister( pinNumber ) = 0;
            if ( pin_mode == INPUT ) *config = PORT_PCR_MUX( 1 );
            else *config = PORT_PCR_MUX( 1 ) | PORT_PCR_PE | PORT_PCR_PS;// pullup
            if ( mode == VLPW || mode == VLPS ) {
                attachDigitalInterrupt( pinNumber, pin_type );// set pin interrupt
            }
            else {
                llwu_configure_pin_mask( pinNumber, mode );
            }
        } else {
            //pinMode( pinNumber, pin_mode );
            //digitalWriteFast( pinNumber, pin_type );
        }
        _pin &= ~( ( uint64_t )1 << pinNumber );// remove pin from list
    }
#elif defined(KINETISL)
    uint32_t _pin = pin;
    isr_pin = pin;
    if ( mode == VLPW || mode == VLPS ) {// if using sleep must setup pin interrupt to wake
        return_isr_a_enabled  = NVIC_IS_ENABLED( IRQ_PORTA );
        return_isr_cd_enabled = NVIC_IS_ENABLED( IRQ_PORTCD );
        NVIC_DISABLE_IRQ(IRQ_PORTA);
        NVIC_DISABLE_IRQ(IRQ_PORTCD);
        NVIC_CLEAR_PENDING(IRQ_PORTA);
        NVIC_CLEAR_PENDING(IRQ_PORTCD);
        int priority = nvic_execution_priority( );// get current priority
        // if running from interrupt set priority higher than current interrupt
        priority = ( priority < 256 ) && ( ( priority - 16 ) > 0 ) ? priority - 16 : 128;
        return_priority_a = NVIC_GET_PRIORITY( IRQ_PORTA );//get current priority
        return_priority_cd = NVIC_GET_PRIORITY( IRQ_PORTCD );//get current priority
        NVIC_SET_PRIORITY( IRQ_PORTA, priority );//set priority to new level
        NVIC_SET_PRIORITY( IRQ_PORTCD, priority );//set priority to new level
        __disable_irq( );
        return_porta_irq = _VectorsRam[IRQ_PORTA+16];// save prev isr handler
        return_portcd_irq = _VectorsRam[IRQ_PORTCD+16];// save prev isr handler
        attachInterruptVector( IRQ_PORTA, isr );// set snooze isr
        attachInterruptVector( IRQ_PORTCD, isr );// set snooze isr
        __enable_irq( );
        NVIC_ENABLE_IRQ( IRQ_PORTA );
        NVIC_ENABLE_IRQ( IRQ_PORTCD );
    }
    _pin = pin;
    while ( __builtin_popcount( _pin ) ) {
        uint32_t pinNumber  = 31 - __builtin_clz( _pin );// get pin
        
        if ( pinNumber > 33 ) break;
        
        uint32_t pin_mode = irqType[pinNumber] >> 4;// get type
        uint32_t pin_type = irqType[pinNumber] & 0x0F;// get mode
        
        volatile uint32_t *config;
        config = portConfigRegister( pinNumber );
        return_core_pin_config[pinNumber] = *config;
        
        if ( pin_mode == INPUT || pin_mode == INPUT_PULLUP ) {// setup pin mode/type/interrupt
            *portModeRegister( pinNumber ) &= ~digitalPinToBitMask( pinNumber ); // TODO: atomic
            if ( pin_mode == INPUT ) *config = PORT_PCR_MUX( 1 );
            else *config = PORT_PCR_MUX( 1 ) | PORT_PCR_PE | PORT_PCR_PS;// pullup
            if ( pin_mode == VLPW || pin_mode == VLPS ) {
               attachDigitalInterrupt( pinNumber, pin_type );// set pin interrupt
            }
            else {
                llwu_configure_pin_mask( pinNumber, pin_mode );
            }
        } else {
            //pinMode( pinNumber, pin_mode );
            //digitalWriteFast( pinNumber, pin_type );
        }
        _pin &= ~( ( uint32_t )1 << pinNumber );// remove pin from list
    }
#endif
}
Ejemplo n.º 10
0
/*******************************************************************************
 *  Disable interrupt and configure pin to orignal state.
 *******************************************************************************/
void SnoozeDigital::disableDriver( void ) {
    if ( mode == RUN_LP ) { return; }
#if defined(KINETISK)
    uint64_t _pin = pin;
    while ( __builtin_popcountll( _pin ) ) {
        uint32_t pinNumber = 63 - __builtin_clzll( _pin );
        
        if ( pinNumber > 33 ) break;
        
        *portModeRegister( pinNumber ) = 0;
        volatile uint32_t *config;
        config = portConfigRegister( pinNumber );
        *config = return_core_pin_config[pinNumber];
        
        _pin &= ~( ( uint64_t )1 << pinNumber );// remove pin from list
    }
#elif defined(KINETISL)
    uint32_t _pin = pin;
    while ( __builtin_popcount( _pin ) ) {
        uint32_t pinNumber = 31 - __builtin_clz( _pin );
        
        if ( pinNumber > 33 ) break;
        
        *portModeRegister( pinNumber ) &= ~digitalPinToBitMask( pinNumber );
        volatile uint32_t *config;
        config = portConfigRegister( pinNumber );
        *config = return_core_pin_config[pinNumber];
        
        _pin &= ~( ( uint32_t )1 << pinNumber );// remove pin from list
    }
#endif
    if ( mode == VLPW || mode == VLPS ) {
#if defined(KINETISK)
        NVIC_SET_PRIORITY( IRQ_PORTA, return_priority_a );//set priority to new level
        NVIC_SET_PRIORITY( IRQ_PORTB, return_priority_b );//set priority to new level
        NVIC_SET_PRIORITY( IRQ_PORTC, return_priority_c );//set priority to new level
        NVIC_SET_PRIORITY( IRQ_PORTD, return_priority_d );//set priority to new level
        NVIC_SET_PRIORITY( IRQ_PORTE, return_priority_e );//set priority to new level
        __disable_irq( );
        attachInterruptVector( IRQ_PORTA, return_porta_irq );// set snooze isr
        attachInterruptVector( IRQ_PORTB, return_portb_irq );// set snooze isr
        attachInterruptVector( IRQ_PORTC, return_portc_irq );// set snooze isr
        attachInterruptVector( IRQ_PORTD, return_portd_irq );// set snooze isr
        attachInterruptVector( IRQ_PORTE, return_porte_irq );// set snooze isr
        __enable_irq( );
        if ( return_isr_a_enabled == 0 ) NVIC_DISABLE_IRQ( IRQ_PORTA );
        if ( return_isr_b_enabled == 0 ) NVIC_DISABLE_IRQ( IRQ_PORTB );
        if ( return_isr_c_enabled == 0 ) NVIC_DISABLE_IRQ( IRQ_PORTC );
        if ( return_isr_d_enabled == 0 ) NVIC_DISABLE_IRQ( IRQ_PORTD );
        if ( return_isr_e_enabled == 0 ) NVIC_DISABLE_IRQ( IRQ_PORTE );
#elif defined(KINETISL)
        NVIC_SET_PRIORITY( IRQ_PORTA,  return_priority_a );//set priority to new level
        NVIC_SET_PRIORITY( IRQ_PORTCD, return_priority_cd );//set priority to new level
        __disable_irq( );
        attachInterruptVector( IRQ_PORTA,  return_porta_irq );// set snooze isr
        attachInterruptVector( IRQ_PORTCD, return_portcd_irq );// set snooze isr
        __enable_irq( );
        if ( return_isr_a_enabled == 0 )  NVIC_DISABLE_IRQ( IRQ_PORTA );
        if ( return_isr_cd_enabled == 0 ) NVIC_DISABLE_IRQ( IRQ_PORTCD );
#endif
    }
}
Ejemplo n.º 11
0
// ------------------------------------------------------------
// stops the timer and disables its interrupts
// ------------------------------------------------------------
void PITimer::stop() {
    isRunning = false;
    NVIC_DISABLE_IRQ(IRQ_PIT_CH);
    *PIT_TCTRL = 0;
}
Ejemplo n.º 12
0
/*******************************************************************************
 *  Disable Driver
 *******************************************************************************/
void SnoozeCompare::disableDriver( void ) {
    if ( mode == RUN_LP ) { return; }
    if ( mode == VLPW || mode == VLPS ) {
        IRQ_NUMBER_t IRQ_CMP;
        switch (pin) {
            case 11:
                IRQ_CMP = IRQ_CMP0;
                break;
#if defined(KINETISK)
            case 9:
                IRQ_CMP = IRQ_CMP1;
                break;
            case 4:
                IRQ_CMP = IRQ_CMP2;
                break;
#endif
            default:
                IRQ_CMP = IRQ_CMP;
                return;
        }
        if ( return_isr_enabled == 0 ) NVIC_DISABLE_IRQ( IRQ_CMP );
        NVIC_SET_PRIORITY( IRQ_CMP, return_priority );
        __disable_irq( );
        attachInterruptVector( IRQ_CMP, return_cmp_irq );// return prev interrupt
        __enable_irq( );
    }

    if ( pin == 11 ) {
        CORE_PIN11_CONFIG = return_core_pin_config[0];
    }
    else if ( pin == 4 ) {
#if defined(KINETISK)
        CORE_PIN4_CONFIG = return_core_pin_config[1];
#else 
        return;
#endif
    }
    else if ( pin == 9 ) {
#if defined(KINETISK)
        CORE_PIN9_CONFIG = return_core_pin_config[2];
#else
        return;
#endif
    }
    
#if defined(__MKL26Z64__) || defined(__MK66FX1M0__)
    LPTMR0_PSR = PSR;
    LPTMR0_CMR = CMR;
    LPTMR0_CSR = CSR;
    if ( !SIM_SCGC5_clock_active ) SIM_SCGC5 &= ~SIM_SCGC5_LPTIMER;
#endif
    
    *cmpx_cr0   = CR0;
    *cmpx_cr1   = CR1;
    *cmpx_scr   = SCR;
    *cmpx_fpr   = FPR;
    *cmpx_muxcr = MUXCR;
    *cmpx_daccr = DACCR;
    
    if ( !SIM_SCGC4_clock_active ) SIM_SCGC4 &= ~SIM_SCGC4_CMP;
}
Ejemplo n.º 13
0
Archivo: ADC.cpp Proyecto: jimparis/ADC
/* Disable interrupts
*
*/
void ADC::disableInterrupts() {
    var_enableInterrupts = 0;
    NVIC_DISABLE_IRQ(IRQ_ADC0);
}