Skip to content

Commit

Permalink
update to version 5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
duff2013 committed May 31, 2015
1 parent 2d2cd5a commit 37dd570
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 94 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Snooze v5.2.1
#Snooze v5.3

<h1>General Usage</h1>

Expand Down
11 changes: 5 additions & 6 deletions Snooze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ SnoozeClass::SnoozeClass( void ) {
SIM_SOPT1 &= ~SIM_SOPT1_USBSSTBY_MASK;
attachInterruptVector( IRQ_LLWU, wakeupISR );
NVIC_SET_PRIORITY( IRQ_LLWU, 32 );
//lptmr_init( );
//cmp_init( );
clock_mode = mcg_mode( );
#if defined( USE_HIBERNATE )
Expand Down Expand Up @@ -144,15 +143,15 @@ void SnoozeClass::idle( void ) {
*
* @return wakeup source
*/
int SnoozeClass::sleep( SnoozeBlock &configuration ) {
int SnoozeClass::sleep( SnoozeBlock &configuration ) {
SnoozeBlock *p = &configuration;
enable_periph_irq = true;
cmp_set( &p->cmp_mask );
digital_set( &p->digital_mask );
lptmr_set( &p->lptmr_mask );
#ifdef KINETISK
rtc_alarm_set( &p->rtc_mask );
#endif
digital_set( &p->digital_mask );
#ifdef KINETISL
pinMode( 17, OUTPUT );
digitalWriteFast( 17, LOW );
Expand Down Expand Up @@ -182,12 +181,12 @@ int SnoozeClass::sleep( SnoozeBlock &configuration ) {
usbEnable ( );
peripheral_set( &p->setPeripheral.periph_off_mask );
}
digital_disable( &p->digital_mask );
#ifdef KINETISK
rtc_disable( &p->rtc_mask );
#endif
cmp_disable( &p->cmp_mask );
lptmr_disable( &p->lptmr_mask );
digital_disable( &p->digital_mask );
cmp_disable( &p->cmp_mask );
return wakeupSource;
}
//--------------------------------------DeepSleep----------------------------------------
Expand All @@ -204,7 +203,6 @@ int SnoozeClass::deepSleep( SnoozeBlock &configuration, SLEEP_MODE mode ) {
enable_periph_irq = false;
sleep_mode = mode;
cmp_set( &p->cmp_mask );
digital_set( &p->digital_mask );
lptmr_set( &p->lptmr_mask );
#ifdef KINETISK
rtc_alarm_set( &p->rtc_mask );
Expand All @@ -214,6 +212,7 @@ int SnoozeClass::deepSleep( SnoozeBlock &configuration, SLEEP_MODE mode ) {
digitalWriteFast( 17, LOW );
#endif
tsi_set( &p->tsi_mask );
digital_set( &p->digital_mask );
llwu_set( &p->llwu_mask );
if ( mode == LLS ) { enter_lls( ); }
else if ( mode == VLLS3 ) { enter_vlls3( ); }
Expand Down
2 changes: 1 addition & 1 deletion Snooze.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
||
|| @file Snooze.h
|| @version 5.2.1
|| @version 5.3
|| @author duff
|| @contact http://forum.pjrc.com/members/25610-duff
||
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Snooze
version=5.2.1
version=5.3
author=Colin Duffy
maintainer=Colin Duffy
sentence=Low Power for Teensy 3.x/LC
Expand Down
4 changes: 4 additions & 0 deletions revision.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
><b>Updated (5/31/15 v5.3)</b><br>
* Fixed sleep function low power timer.<br>
* Fixed digital pin wake on LOW or HIGH interrupt type, now if pin interrupt type is configured LOW and the pin is LOW when going into sleep it will wake immediately, the same goes for if it is HIGH interrupt type.<br>
><b>Updated (5/28/15 v5.2.1)</b><br>
* Remove debug stuff.<br>
Expand Down
2 changes: 1 addition & 1 deletion utility/cmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ extern "C" {

int priority = nvic_execution_priority( );// get current priority
// if running from handler set priority higher than current handler
priority = ( priority < 256 ) && ( (priority - 16) > 0 ) ? priority - 16 : 128;
priority = ( priority < 256 ) && ( ( priority - 16 ) > 0 ) ? priority - 16 : 128;
NVIC_SET_PRIORITY( IRQ_CMP0, priority );//set priority to new level

__disable_irq( );
Expand Down
141 changes: 76 additions & 65 deletions utility/digital.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,119 +141,121 @@ extern "C" {
if ( mask->state == false ) return;
#if defined(KINETISK)
uint64_t _pin = mask->pin;
while ( __builtin_popcountll( _pin ) ) {
uint32_t pin = 63 - __builtin_clzll( _pin );// get pin
uint32_t mode = mask->mode_irqType[pin] >> 4;// get type
uint32_t type = mask->mode_irqType[pin] & 0x0F;// get mode

volatile uint32_t *config;
config = portConfigRegister( pin );

if ( enable_periph_irq ) {// if using sleep must setup pin interrupt to wake

if ( enable_periph_irq ) {// if using sleep must setup pin interrupt to wake
while ( __builtin_popcountll( _pin ) ) {
uint32_t pin = 63 - __builtin_clzll( _pin );// get pin
if ( pin > 33 ) return;
int priority = nvic_execution_priority( );// get current priority
// if running from handler set priority higher than current handler
priority = ( priority < 256 ) && ( (priority - 16) > 0 ) ? priority - 16 : 128;

// if running from interrupt set priority higher than current interrupt
priority = ( priority < 256 ) && ( ( priority - 16 ) > 0 ) ? priority - 16 : 128;
if ( pin == 3 || pin == 4 || pin == 24 || pin == 33 ) {

NVIC_SET_PRIORITY( IRQ_PORTA, priority );//set priority to new level
__disable_irq( );
return_porta_irq = _VectorsRam[IRQ_PORTA+16];// save prev isr
return_porta_irq = _VectorsRam[IRQ_PORTA+16];// save prev isr handler
attachInterruptVector( IRQ_PORTA, digitalISR );// set snooze isr
__enable_irq( );
}
else if ( pin == 0 || pin == 1 || pin == 16 || pin == 17 || pin == 18 || pin == 19 || pin == 25 || pin == 32 ) {
NVIC_SET_PRIORITY( IRQ_PORTB, priority );//set priority to new level
__disable_irq( );
return_portb_irq = _VectorsRam[IRQ_PORTB+16];// save prev isr
return_portb_irq = _VectorsRam[IRQ_PORTB+16];// save prev isr handler
attachInterruptVector( IRQ_PORTB, digitalISR );// set snooze isr
__enable_irq( );
}
else if ( pin == 9 || pin == 10 || pin == 11 || pin == 12 || pin == 13 || pin == 15 || pin == 22 || pin == 23 || pin == 27 || pin == 28 || pin == 29 || pin == 30 ) {
NVIC_SET_PRIORITY( IRQ_PORTC, priority );//set priority to new level
__disable_irq( );
return_portc_irq = _VectorsRam[IRQ_PORTC+16];// save prev isr
return_portc_irq = _VectorsRam[IRQ_PORTC+16];// save prev isr handler
attachInterruptVector( IRQ_PORTC, digitalISR );// set snooze isr
__enable_irq( );
}
else if ( pin == 2 || pin == 5 || pin == 6 || pin == 7 || pin == 8 || pin == 14 || pin == 20 || pin == 21 ) {
NVIC_SET_PRIORITY( IRQ_PORTD, priority );//set priority to new level
__disable_irq( );
return_portd_irq = _VectorsRam[IRQ_PORTD+16];// save prev isr
return_portd_irq = _VectorsRam[IRQ_PORTD+16];// save prev isr handler
attachInterruptVector( IRQ_PORTD, digitalISR );// set snooze isr
__enable_irq( );
}
else if ( pin == 26 || pin == 31 ) {
NVIC_SET_PRIORITY( IRQ_PORTE, priority );//set priority to new level
__disable_irq( );
return_porte_irq = _VectorsRam[IRQ_PORTE+16];// save prev isr
return_porte_irq = _VectorsRam[IRQ_PORTE+16];// save prev isr handler
attachInterruptVector( IRQ_PORTE, digitalISR );// set snooze isr
__enable_irq( );
}

_pin &= ~( ( uint64_t )1<<pin );// remove pin from list
}
__disable_irq( );// disable all interrupts for attaching an interrupt to a pin
}
_pin = mask->pin;
while ( __builtin_popcountll( _pin ) ) {
uint32_t pin = 63 - __builtin_clzll( _pin );// get pin
uint32_t mode = mask->mode_irqType[pin] >> 4;// get type
uint32_t type = mask->mode_irqType[pin] & 0x0F;// get mode

volatile uint32_t *config;
config = portConfigRegister( pin );

if ( mode == INPUT || mode == INPUT_PULLUP ) {// setup pin mode/type/interrupt
*portModeRegister( pin ) = 0;
if ( mode == INPUT ) *config = PORT_PCR_MUX( 1 );
else *config = PORT_PCR_MUX( 1 ) | PORT_PCR_PE | PORT_PCR_PS;// pullup
if ( enable_periph_irq ) {
attachDigitalInterrupt( pin, type );// set pin interrupt
}
if ( enable_periph_irq ) attachDigitalInterrupt( pin, type );// set pin interrupt
} else {
pinMode( pin, mode );
digitalWriteFast( pin, type );
}

_pin &= ~( ( uint64_t )1<<pin );// remove pin from list

}

#elif defined(KINETISL)
uint32_t _pin = mask->pin;
while ( __builtin_popcount( _pin ) ) {
uint32_t pin = 31 - __builtin_clz( _pin );// get pin
uint32_t mode = mask->mode_irqType[pin] >> 4;// get type
uint32_t type = mask->mode_irqType[pin] & 0x0F;// get mode

volatile uint32_t *config;
config = portConfigRegister( pin );

if ( enable_periph_irq ) {// if using sleep must setup pin interrupt to wake
if ( enable_periph_irq ) {// if using sleep must setup pin interrupt to wake
while ( __builtin_popcount( _pin ) ) {
uint32_t pin = 31 - __builtin_clz( _pin );// get pin

int priority = nvic_execution_priority( );// get current priority
// if running from handler set priority higher than current handler
priority = ( priority < 256 ) && ( (priority - 16) > 0 ) ? priority - 16 : 128;

if ( pin == 3 || pin == 4 ) {
NVIC_SET_PRIORITY( IRQ_PORTA, priority );//set priority to new level
__disable_irq( );
return_porta_irq = _VectorsRam[IRQ_PORTA+16];// save prev isr
return_porta_irq = _VectorsRam[IRQ_PORTA+16];// save prev isr handler
attachInterruptVector( IRQ_PORTA, digitalISR );// set snooze isr
__enable_irq( );
}
else if ( pin == 2 || pin == 5 || pin == 6 || pin == 7 || pin == 8 || pin == 14 || pin == 20 || pin == 21 || pin == 9 || pin == 10 || pin == 11 || pin == 12 || pin == 13 || pin == 15 || pin == 22 || pin == 23 ) {
NVIC_SET_PRIORITY( IRQ_PORTCD, priority );//set priority to new level
__disable_irq( );
return_portcd_irq = _VectorsRam[IRQ_PORTCD+16];// save prev isr
return_portcd_irq = _VectorsRam[IRQ_PORTCD+16];// save prev isr handler
attachInterruptVector( IRQ_PORTCD, digitalISR );// set snooze isr
__enable_irq( );
}
_pin &= ~( ( uint32_t )1<<pin );// remove pin from list
}
__disable_irq( );// disable all interrupts for attaching an interrupt to a pin
}

_pin = mask->pin;
while ( __builtin_popcount( _pin ) ) {
uint32_t pin = 31 - __builtin_clz( _pin );// get pin
uint32_t mode = mask->mode_irqType[pin] >> 4;// get type
uint32_t type = mask->mode_irqType[pin] & 0x0F;// get mode

volatile uint32_t *config;
config = portConfigRegister( pin );

if ( mode == INPUT || mode == INPUT_PULLUP ) {// setup pin mode/type/interrupt
*portModeRegister( pin ) &= ~digitalPinToBitMask( pin ); // TODO: atomic
if ( mode == INPUT ) *config = PORT_PCR_MUX( 1 );
else *config = PORT_PCR_MUX( 1 ) | PORT_PCR_PE | PORT_PCR_PS;// pullup
if ( enable_periph_irq ) {
attachDigitalInterrupt( pin, type );// set pin interrupt
}
if ( enable_periph_irq ) attachDigitalInterrupt( pin, type );// set pin interrupt
} else {
pinMode( pin, mode );
digitalWriteFast( pin, type );
}

_pin &= ~( ( uint32_t )1<<pin );// remove pin from list

}
#endif
}
Expand All @@ -274,75 +276,84 @@ extern "C" {
uint64_t _pin = mask->pin;
while ( __builtin_popcountll( _pin ) ) {
uint32_t pin = 63 - __builtin_clzll( _pin );
if ( pin > 33 ) {
__enable_irq( );// enable interrupts from digital_set function
return;
}
detachDigitalInterrupt( pin );// remove pin interrupt
_pin &= ~( ( uint64_t )1<<pin );// remove pin from list
}
__enable_irq( );// enable interrupts from digital_set function

_pin = mask->pin;
while ( __builtin_popcountll( _pin ) ) {

if ( enable_periph_irq ) {// if using sleep, give back previous isr

detachDigitalInterrupt( pin );// remove interrupt

uint32_t pin = 63 - __builtin_clzll( _pin );
if ( enable_periph_irq ) {// if using sleep, give back previous isr handler
if ( pin == 3 || pin == 4 || pin == 24 || pin == 33 ) {
NVIC_SET_PRIORITY( IRQ_PORTA, 128 );//return priority to core level
__disable_irq( );
attachInterruptVector( IRQ_PORTA, return_porta_irq );// return prev interrupt
attachInterruptVector( IRQ_PORTA, return_porta_irq );// return prev interrupt handler
__enable_irq( );
}
else if ( pin == 0 || pin == 1 || pin == 16 || pin == 17 || pin == 18 || pin == 19 || pin == 25 || pin == 32 ) {
NVIC_SET_PRIORITY( IRQ_PORTB, 128 );//return priority to core level
__disable_irq( );
attachInterruptVector( IRQ_PORTB, return_portb_irq );// return prev interrupt
attachInterruptVector( IRQ_PORTB, return_portb_irq );// return prev interrupt handler
__enable_irq( );
}
else if ( pin == 9 || pin == 10 || pin == 11 || pin == 12 || pin == 13 || pin == 15 || pin == 22 || pin == 23 || pin == 27 || pin == 28 || pin == 29 || pin == 30 ) {
NVIC_SET_PRIORITY( IRQ_PORTC, 128 );//return priority to core level
__disable_irq( );
attachInterruptVector( IRQ_PORTC, return_portc_irq );// return prev interrupt
attachInterruptVector( IRQ_PORTC, return_portc_irq );// return prev interrupt handler
__enable_irq( );
}
else if ( pin == 2 || pin == 5 || pin == 6 || pin == 7 || pin == 8 || pin == 14 || pin == 20 || pin == 21 ) {
NVIC_SET_PRIORITY( IRQ_PORTD, 128 );//return priority to core level
__disable_irq( );
attachInterruptVector( IRQ_PORTD, return_portd_irq );// return prev interrupt
attachInterruptVector( IRQ_PORTD, return_portd_irq );// return prev interrupt handler
__enable_irq( );
if (*return_portd_irq != portd_isr) {
//return_portd_irq();
}
}
else if ( pin == 26 || pin == 31 ) {
NVIC_SET_PRIORITY( IRQ_PORTE, 128 );//return priority to core level
__disable_irq( );
attachInterruptVector( IRQ_PORTE, return_porte_irq );// return prev interrupt
attachInterruptVector( IRQ_PORTE, return_porte_irq );// return prev interrupt handler
__enable_irq( );
}

}

_pin &= ~( ( uint64_t )1<<pin );// remove pin from list

}
#elif defined(KINETISL)
uint32_t _pin = mask->pin;
while ( __builtin_popcount( _pin ) ) {
uint32_t pin = 31 - __builtin_clz( _pin );

if ( enable_periph_irq ) {// if using sleep give back previous isr

detachDigitalInterrupt( pin );// remove interrupt

if ( pin > 33 ) {
__enable_irq( );// enable interrupts from digital_set function
return;
}
detachDigitalInterrupt( pin );// remove pin interrupt
_pin &= ~( ( uint32_t )1<<pin );// remove pin from list
}
__enable_irq( );// enable interrupts from digital_set function

_pin = mask->pin;
while ( __builtin_popcount( _pin ) ) {
uint32_t pin = 31 - __builtin_clz( _pin );
if ( enable_periph_irq ) {// if using sleep give back previous isr handler
if ( pin == 3 || pin == 4 ) {
NVIC_SET_PRIORITY( IRQ_PORTA, 128 );//return priority to core level
__disable_irq( );
attachInterruptVector( IRQ_PORTA, return_porta_irq );// return prev interrupt
attachInterruptVector( IRQ_PORTA, return_porta_irq );// return prev interrupt handler
__enable_irq( );
}
else if ( pin == 2 || pin == 5 || pin == 6 || pin == 7 || pin == 8 || pin == 14 || pin == 20 || pin == 21 || pin == 9 || pin == 10 || pin == 11 || pin == 12 || pin == 13 || pin == 15 || pin == 22 || pin == 23 ) {
NVIC_SET_PRIORITY( IRQ_PORTCD, 128 );//return priority to core level
__disable_irq( );
attachInterruptVector( IRQ_PORTCD, return_portcd_irq );// return prev interrupt
attachInterruptVector( IRQ_PORTCD, return_portcd_irq );// return prev interrupt handler
__enable_irq( );
}
}

_pin &= ~( ( uint32_t )1<<pin );// remove pin from list

}
#endif
}
Expand Down
Loading

0 comments on commit 37dd570

Please sign in to comment.