Esempio n. 1
0
/* sleep() - sets the microcontroller to the lowest consumption sleep mode
 *
 * It sets the microcontroller to the lowest consumption sleep mode. Before setting this state, some interruption
 * should be enabled to be able to wake up the microcontroller from this state.
 *
 * It switches off all the switches on the Waspmote board.
 *
 * It returns nothing.
 */
void	WaspPWR::sleep(uint8_t option)
{
	switchesOFF(option);
	set_sleep_mode(SLEEP_MODE_PWR_DOWN);
	sleep_enable();
	sleep_mode();
	sleep_disable();
	switchesON(option);
}
Esempio n. 2
0
/* sleep(timer) - sets the microcontroller to the lowest consumption sleep mode
 *
 * It sets the microcontroller to the lowest consumption sleep mode. It enables watchdog interruption to be able to
 * wake up the microcontroller after 'timer' time.
 *
 * 'timer' --> it specifies the time before the watchdog activates the interruption. Possible values are:
 * 	WTD_16MS	0
 *	WTD_32MS	1
 *	WTD_64MS	2
 *	WTD_128MS	3
 *	WTD_250MS	4
 *	WTD_500MS	5
 *	WTD_1S		6
 *	WTD_2S		7
 *	WTD_4S		8
 *	WTD_8S		9
 * 
 * It switches off all the switches on the Waspmote board.
 *
 * It returns nothing.
 */
void WaspPWR::sleep(uint8_t	timer, uint8_t option)
{
	uint8_t retries=0;
		
	// Switch off both multiplexers in UART_0 and UART_1
	Utils.muxOFF();
	
	// set the XBee monitorization pin to zero
	pinMode(XBEE_MON,OUTPUT);
	digitalWrite(XBEE_MON,LOW);
	
    // switch on and off the RTC so as to unset RTC interruption signal
	RTC.ON();
    RTC.OFF(); 
     
	// switches off depending on the option selected       
	switchesOFF(option);
	
	// mandatory delay to wait for MUX_RX stabilization 
	// after switching off the sensor boards 
	delay(100);	
	
	// make sure interruption pin is LOW before entering a low power state
	// if not the interruption will never come
	while(digitalRead(MUX_RX)==HIGH)
	{
		// clear all detected interruption signals
		delay(1);
		PWR.clearInterruptionPin();
		retries++;
		if(retries>10)
		{
			return (void)0;
		}
	}
	
	set_sleep_mode(SLEEP_MODE_PWR_DOWN);
	sleep_enable();
	
	// set watchdog timer to cause interruption for selected time
	setWatchdog(WTD_ON,timer);
	sleep_mode();
	sleep_disable();
		
	if( intFlag & RTC_INT )
	{
		RTC.ON();
		RTC.clearAlarmFlag();
		RTC.OFF();
	}
	//~ switchesON(option);
	
}
Esempio n. 3
0
/* sleep(timer) - sets the microcontroller to the lowest consumption sleep mode
 *
 * It sets the microcontroller to the lowest consumption sleep mode. It enables watchdog interruption to be able to
 * wake up the microcontroller after 'timer' time.
 *
 * 'timer' --> it specifies the time before the watchdog activates the interruption. Possible values are:
 * 	WTD_16MS	0
 *	WTD_32MS	1
 *	WTD_64MS	2
 *	WTD_128MS	3
 *	WTD_250MS	4
 *	WTD_500MS	5
 *	WTD_1S		6
 *	WTD_2S		7
 *	WTD_4S		8
 *	WTD_8S		9
 * 
 * It switches off all the switches on the Waspmote board.
 *
 * It returns nothing.
 */
void	WaspPWR::sleep(uint8_t	timer, uint8_t option)
{
	switchesOFF(option);
	set_sleep_mode(SLEEP_MODE_PWR_DOWN);
	sleep_enable();
	
	setWatchdog(WTD_ON,timer);
	sleep_mode();
	sleep_disable();
	switchesON(option);
	
}
Esempio n. 4
0
/* sleep(timer) - sets the microcontroller to the lowest consumption sleep mode
 *
 * It sets the microcontroller to the lowest consumption sleep mode. It enables watchdog interruption to be able to
 * wake up the microcontroller after 'timer' time.
 *
 * 'timer' --> it specifies the time before the watchdog activates the interruption. Possible values are:
 * 	WTD_16MS	0
 *	WTD_32MS	1
 *	WTD_64MS	2
 *	WTD_128MS	3
 *	WTD_250MS	4
 *	WTD_500MS	5
 *	WTD_1S		6
 *	WTD_2S		7
 *	WTD_4S		8
 *	WTD_8S		9
 * 
 * It switches off all the switches on the MakeSuremote board.
 *
 * It returns nothing.
 */
void MakeSurePWR::sleep(uint8_t	timer, uint8_t option)
{
	uint8_t retries=0;
		
	// Switch off both multiplexers in UART_0 and UART_1 when 
	// no interruption is expected through the UART1
   	if( !(option & UART1_OFF) )
	{	
		// keep multiplexer on
	}
	else
	{
		Utils.muxOFF();
	}
	delay(100);
	
	RTC.ON();
   
    pinMode(XBEE_MON,INPUT);
	digitalWrite(XBEE_MON,LOW);
           
	switchesOFF(option);
	pinMode(I2C_SDA,OUTPUT);
	digitalWrite(I2C_SDA,LOW);
	pinMode(I2C_SCL,OUTPUT);
	digitalWrite(I2C_SCL,LOW); 
	
	// make sure interruption pin is LOW before entering a low power state
	// if not the interruption will never come
	while(digitalRead(MUX_RX)==HIGH)
	{
		// clear all detected interruption signals
		delay(1);
		PWR.clearInt();
		retries++;
		if(retries>10)
		{
			return (void)0;
		}
	}
	
	set_sleep_mode(SLEEP_MODE_PWR_DOWN);
	sleep_enable();
	
	setWatchdog(WTD_ON,timer);
	sleep_mode();
	sleep_disable();
	switchesON(option);
	
}
Esempio n. 5
0
/* deepSleep(time2wake, offset, mode) - sets the microcontroller to the lowest consumption sleep mode
 *
 * It sets the microcontroller to the lowest consumption sleep mode. It enables RTC interruption to be able to
 * wake up the microcontroller when the RTC alarm is launched.
 *
 * 'time2wake' --> it specifies the time at which the RTC alarm will activate. It must follow the next format:
 *	"DD:HH:MM:SS"
 * 'offset' --> it specifies if 'time2wake' is added to the actual time or if this time is set as the alarm
 * 'mode' --> it specifies the mode for RTC alarm
 *
 * It uses Alarm1 on the RTC due to this Alarm has more precision than Alarm2
 * 
 * It switches off all the switches on the Waspmote board.
 *
 * It returns nothing.
 */
void	WaspPWR::deepSleep(const char*	time2wake, uint8_t offset, uint8_t mode, uint8_t option)
{
	// Set RTC alarme to wake up from Sleep Power Down Mode
	RTC.setAlarm1(time2wake,offset,mode);
	RTC.close();
	switchesOFF(option);
	set_sleep_mode(SLEEP_MODE_PWR_DOWN);
	sleep_enable();
	sleep_mode();
	sleep_disable();
	switchesON(option);
	RTC.ON();
	RTC.clearAlarmFlag();
	if( option & RTC_OFF ) RTC.OFF();
}
Esempio n. 6
0
/* deepSleep(time2wake, offset, mode) - sets the microcontroller to the lowest consumption sleep mode
 *
 * It sets the microcontroller to the lowest consumption sleep mode. It enables RTC interruption to be able to
 * wake up the microcontroller when the RTC alarm is launched.
 *
 * 'time2wake' --> it specifies the time at which the RTC alarm will activate. It must follow the next format:
 *	"DD:HH:MM:SS"
 * 'offset' --> it specifies if 'time2wake' is added to the actual time or if this time is set as the alarm
 * 'mode' --> it specifies the mode for RTC alarm
 *
 * It uses Alarm1 on the RTC due to this Alarm has more precision than Alarm2
 * 
 * It switches off all the switches on the Waspmote board.
 *
 * It returns nothing.
 */
void WaspPWR::deepSleep(	const char* time2wake, 
							uint8_t offset, 
							uint8_t mode, 
							uint8_t option	)
{	
	uint8_t retries=0;
	
	// Switch off both multiplexers in UART_0 and UART_1
	Utils.muxOFF();
	
	// set the XBee monitorization pin to zero
	pinMode(XBEE_MON,OUTPUT);
	digitalWrite(XBEE_MON,LOW);
	
	// switches off depending on the option selected  
	switchesOFF(option);
	
	// mandatory delay to wait for MUX_RX stabilization 
	// after switching off the sensor boards 
	delay(100);	
	
	// make sure interruption pin is LOW before entering a low power state
	// if not the interruption will never come
	while(digitalRead(MUX_RX)==HIGH)
	{	
		// clear all detected interruption signals
		delay(1);
		PWR.clearInterruptionPin();
		retries++;
		if(retries>10)
		{
			return (void)0;
		}
	}
	
	// RTC ON
	RTC.ON();
	// set Alarm
	RTC.setAlarm1(time2wake,offset,mode); 
	// get backup of selected Alarm	
	uint8_t day_aux = RTC.day_alarm1; 
	uint8_t hour_aux = RTC.hour_alarm1; 
	uint8_t minute_aux = RTC.minute_alarm1; 
	uint8_t second_aux = RTC.second_alarm1; 
	// get Alarm
	RTC.getAlarm1();
	// check Alarm was correctly set	
	if(	( day_aux != RTC.day_alarm1 ) 
	||	( hour_aux != RTC.hour_alarm1 )
	||	( minute_aux != RTC.minute_alarm1 )
	||	( second_aux != RTC.second_alarm1 ) )
	{
		RTC.disableAlarm1();
		RTC.OFF();
		return (void)0;
	}
    RTC.OFF();	
	
	// set sleep mode
	set_sleep_mode(SLEEP_MODE_PWR_DOWN);
	sleep_enable();
	sleep_mode();
	sleep_disable();
		
	// in the case SENS_OFF was an option is mandatory to turn on the
	// sensor boards before setting up the I2C bus
	switchesON(option);
	
	// Switch on the RTC and clear the alarm signals	
	// Disable RTC interruption after waking up 
	RTC.ON();
	RTC.disableAlarm1();
	RTC.clearAlarmFlag();
	RTC.OFF();
	
	// Keep sensor supply powered down if selected
	if( option & SENS_OFF )
	{
		pinMode(SENS_PW_3V3,OUTPUT);
		digitalWrite(SENS_PW_3V3,LOW);	
		pinMode(SENS_PW_5V,OUTPUT);
		digitalWrite(SENS_PW_5V,LOW);
	}
}
Esempio n. 7
0
/* deepSleep(time2wake, offset, mode) - sets the microcontroller to the lowest consumption sleep mode
 *
 * It sets the microcontroller to the lowest consumption sleep mode. It enables RTC interruption to be able to
 * wake up the microcontroller when the RTC alarm is launched.
 *
 * 'time2wake' --> it specifies the time at which the RTC alarm will activate. It must follow the next format:
 *	"DD:HH:MM:SS"
 * 'offset' --> it specifies if 'time2wake' is added to the actual time or if this time is set as the alarm
 * 'mode' --> it specifies the mode for RTC alarm
 *
 * It uses Alarm1 on the RTC due to this Alarm has more precision than Alarm2
 * 
 * It switches off all the switches on the MakeSuremote board.
 *
 * It returns nothing.
 */
void MakeSurePWR::deepSleep(	const char* time2wake, 
							uint8_t offset, 
							uint8_t mode, 
							uint8_t option	)
{	
	uint8_t retries=0;
		
	// set the monitorization pin to zero
	pinMode(XBEE_MON,INPUT);
	digitalWrite(XBEE_MON,LOW);
	
	// Switch off both multiplexers in UART_0 and UART_1 when 
	// no interruption is expected through the UART1
   	if( !(option & UART1_OFF) )
	{	
		// keep multiplexer on
	}
	else
	{
		Utils.muxOFF();
	}
	delay(100);
	
	// Set RTC alarm to wake up from Sleep Power Down Mode
	RTC.ON();
	RTC.setAlarm1(time2wake,offset,mode);
	RTC.close();  
    RTC.OFF();
	
    pinMode(I2C_SDA,OUTPUT);
	digitalWrite(I2C_SDA,LOW);
	pinMode(I2C_SCL,OUTPUT);
	digitalWrite(I2C_SCL,LOW);    
	
	switchesOFF(option);
	
	// make sure interruption pin is LOW before entering a low power state
	// if not the interruption will never come
	while(digitalRead(MUX_RX)==HIGH)
	{
		// clear all detected interruption signals
		delay(1);
		PWR.clearInt();
		retries++;
		if(retries>10)
		{
			return (void)0;
		}
	}
	set_sleep_mode(SLEEP_MODE_PWR_DOWN);
	sleep_enable();
	sleep_mode();
	sleep_disable();
	
	switchesON(option);
	RTC.ON();
	RTC.clearAlarmFlag();
	if( option & RTC_OFF ) RTC.OFF();
	if( option & SENS_OFF )
	{
		pinMode(SENS_PW_3V3,OUTPUT);
		digitalWrite(SENS_PW_3V3,LOW);	
		pinMode(SENS_PW_5V,OUTPUT);
		digitalWrite(SENS_PW_5V,LOW);
	}
}