Ejemplo n.º 1
0
// IMPORTANT: if interrupts are not enabled, the processor will never wake
// from sleep
void sleep_proc() {
	enable_pcint();
	// Turn off timer0
	disable_pwm();
	disp_off();

	// probably want power save mode
	// everything off but Timer2 interrupts
	set_sleep_mode(SLEEP_MODE_PWR_SAVE);

	sleep_mode(); 
	// Continue here on wake

	disable_pcint();
	return;
}
Ejemplo n.º 2
0
/// @details
/// Wait for completion of the preceding rf12_sendStart() call, using the
/// specified low-power mode.
/// @note rf12_sendWait() should only be called right after rf12_sendStart().
/// @param mode Power-down mode during wait: 0 = NORMAL, 1 = IDLE, 2 = STANDBY,
///             3 = PWR_DOWN. Values 2 and 3 can cause the millisecond time to
///             lose a few interrupts. Value 3 can only be used if the ATmega
///             fuses have been set for fast startup, i.e. 258 CK - the default
///             Arduino fuse settings are not suitable for full power down.
void rf12_sendWait (uint8_t mode) {
    // wait for packet to actually finish sending
    // go into low power mode, as interrupts are going to come in very soon
    while (rxstate != TXIDLE)
        if (mode) {
            // power down mode is only possible if the fuses are set to start
            // up in 258 clock cycles, i.e. approx 4 us - else must use standby!
            // modes 2 and higher may lose a few clock timer ticks
            set_sleep_mode(mode == 3 ? SLEEP_MODE_PWR_DOWN :
#ifdef SLEEP_MODE_STANDBY
                           mode == 2 ? SLEEP_MODE_STANDBY :
#endif
                           SLEEP_MODE_IDLE);
            sleep_mode();
        }
}
Ejemplo n.º 3
0
void go_sleep()
{
  cbi(ADCSRA,ADEN);  // switch Analog to Digitalconverter OFF
	set_sleep_mode(SLEEP_MODE_PWR_DOWN);
        cli();
	sleep_enable();	
	sleep_bod_disable();
	sei();
	sleep_cpu();
	//sleep_mode();
	/* wake up here */
	sleep_disable();
        sbi(ADCSRA,ADEN);                    // switch Analog to Digitalconverter ON
        initvars();
        setup();
}
Ejemplo n.º 4
0
obj fn_wait_for_event (obj args)
{
  (void) args;
  sleep_enable ();
  set_sleep_mode (SLEEP_MODE_IDLE);
  for (;;)
  {
    noInterrupts ();
    if (isReady ())
      break;
    interrupts ();
    sleep_cpu ();
  }
  interrupts ();
  return (obj_NIL);
}
Ejemplo n.º 5
0
int main(void)
{
	cli();
	ir.enableIRIn();
	TIMER_DISABLE_INTR; //start up the IR thing, then turn off the interrupt
	DDRB &= ~((1 << IR_PIN) | (1 << SCL));    //Configure clock and IR pin as input
	SETUP_PIN_CHANGE;
	ENABLE_PIN_INTR;
	sei();
	set_sleep_mode(2);
	sleep_enable();
    while (1) 
    {
		sleep_cpu();
    }
}
Ejemplo n.º 6
0
int main(void) {
	
	WDT_off(); //watchdog erstmal abschalten
	wdt_disable();
	LED_DDR = (1<<LED_PIN); //register setzen
		
	LED(0); //LED auf LOW ziehen --> AN
	delayms(20); //Delayzeit stellt die Impulsdauer und damit den Helligkeitseindruck ein
	LED(1); //LED auf HIGH setzen --> AUS
	wdt_enable(WDTO_2S); //setze den Watchdogtimer auf 2s
	set_sleep_mode(SLEEP_MODE_PWR_DOWN); //PWR_DOWN --> quasi nur wdt kann chip wecken
    sleep_mode(); //in den Tiefschlaf wechseln
	
	while(1);
	return 0;
}
static int acx565akm_panel_power_on(struct omap_dss_device *dssdev)
{
	struct panel_drv_data *ddata = to_panel_data(dssdev);
	struct omap_dss_device *in = ddata->in;
	int r;

	dev_dbg(&ddata->spi->dev, "%s\n", __func__);

	in->ops.sdi->set_timings(in, &ddata->vm);

	r = in->ops.sdi->enable(in);
	if (r) {
		pr_err("%s sdi enable failed\n", __func__);
		return r;
	}

	/*FIXME tweak me */
	msleep(50);

	if (gpio_is_valid(ddata->reset_gpio))
		gpio_set_value(ddata->reset_gpio, 1);

	if (ddata->enabled) {
		dev_dbg(&ddata->spi->dev, "panel already enabled\n");
		return 0;
	}

	/*
	 * We have to meet all the following delay requirements:
	 * 1. tRW: reset pulse width 10usec (7.12.1)
	 * 2. tRT: reset cancel time 5msec (7.12.1)
	 * 3. Providing PCLK,HS,VS signals for 2 frames = ~50msec worst
	 *    case (7.6.2)
	 * 4. 120msec before the sleep out command (7.12.1)
	 */
	msleep(120);

	set_sleep_mode(ddata, 0);
	ddata->enabled = 1;

	/* 5msec between sleep out and the next command. (8.2.16) */
	usleep_range(5000, 10000);
	set_display_state(ddata, 1);
	set_cabc_mode(ddata, ddata->cabc_mode);

	return acx565akm_bl_update_status(ddata->bl_dev);
}
Ejemplo n.º 8
0
void initialise(void)
{
    /* Disable interrupts during initialisation
     */
    cli();

    /* Setup i/o pins
     * PORTB - all output except input MISO on PB4
     * PORTC - all input except outputs PC0(?), PC4 (?) and PC5 (Led)
     * PORTD - all output except inputs PD0 (RX), PD2 (signal) and
     *         PD3(int1)
     */
    DDRB = ~(1 << DDB4);
    DDRC = (1 << ACTIVITY_LED) | (1 << DDC4) | (1 << DDC0);
    DDRD = ~((1 << DDD3) | (1 << DDD2) | (1 << DDD0));

    /* Enable external interrupt on INT0 (PD2) - falling edge trigger
     */
    EICRA = (1 << ISC01);
    EIMSK = (1 << INT0);

    /* Setup a 16 bit timer to generate 1s interrupts for display updates
     */
    TCCR1B |= (1 << CS12) | (1 << WGM12);
    OCR1A = (F_CPU / 256) - 1;
    TIMSK1 |= (1 << OCIE1A);

    /* Setup UART0
     */
    UCSR0B |= (GEIGER_XFER);
    UCSR0C |= (GEIGER_XFER_CFG);
    UBRR0H = UBRRH_VALUE;
    UBRR0L = UBRRL_VALUE;
#if USE_2X
    UCSR0A |= (1 << U2X0);
#else
    UCSR0A &= ~(1 << U2X0);
#endif

    PORTC |= LED_OFF_MASK;

    /* Allow the CPU to sleep and be woken on timer and external
     * interrupts
     */ 
    set_sleep_mode(SLEEP_MODE_IDLE);
    sei();
}
Ejemplo n.º 9
0
Archivo: main.c Proyecto: mick909/ncnl
/*-----------------------------------------------------------------------*/
static
uint8_t sleep(void)
{
  /* 1/32 Clock */
  cli();
  CLKPR = _BV(CLKPCE);
  CLKPR = 0b0101;
  sei();

  PRR = _BV(PRTWI) | _BV(PRTIM2) | _BV(PRTIM0) | _BV(PRTIM1) | _BV(PRSPI)
        | _BV(PRUSART0) | _BV(PRADC);

  /* CA2's dp on */
  PORTB |= 0b00101000;
  PORTD  = 0b00000010;

  set_sleep_mode(SLEEP_MODE_PWR_DOWN);

  /* PCINT enable */
  PCMSK1 = _BV(PCINT9) | _BV(PCINT11) | _BV(PCINT13);

  do {
    cli();
    wdt_reset();
    WDTCSR = _BV(WDCE) | _BV(WDE);
    WDTCSR = _BV(WDIE) | 0b110;    /* 1s */
    sei();

    sleep_mode();

    if ( !(PCMSK1 & _BV(PCINT9)) ) break;

    xorshift();

    /* blink dot per 0.5ms */
    PIND = 0b00000010;
  } while (1);

  cli();
  wdt_reset();
  WDTCSR = _BV(WDCE) | _BV(WDE);
  WDTCSR = 0;
  sei();

  /* if s1 pushed exit idle loop, else continue idle */
  return (PINC & _BV(5));
}
Ejemplo n.º 10
0
void su_sleep(int16_t seconds)
{
	s_toSleep = seconds;

	ADCSRA |= (0<<ADEN); // Switch Analog to Digital converter OFF

	while ( true )
	{
		set_sleep_mode( SLEEP_MODE_PWR_DOWN);
	    sleep_mode();

	    s_toSleep -= 10;
	    if ( s_toSleep < 0 ) break;
	}

	ADCSRA |= (1<<ADEN); // Switch Analog to Digital converter ON
}
Ejemplo n.º 11
0
// go to sleep until the MCU is reset
void sleepNow(void)
{
    // configure sleep mode and enable it
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    sleep_enable();
    sleep_bod_disable();
    
    // disable interupts
    cli();
    
    // set ports to inputs and disabled pullups
    DDRB = 0;
    PORTB = 0;
    
    // sleep
    sleep_mode();
}
Ejemplo n.º 12
0
int main()
{
	cli();
	state = 0;

	/*
	 * Setup LED display.
	 *
	 * Fortunately, LED pins are the exactly the DDRB pins (8-13),
	 * so setting it all of them to input output mode is as simple as
	 * setting all bits of DDRB to 1.
	 */ 
	DDRB = ~((uint8_t)0);

	/*
	 * Setup button controls.
	 *
	 * We treat all DDRD pins (except for RX and TX ones) as our input
	 * controls. Therefore, we just clear the whole mask leaving only
	 * original RX (pin 0) and TX (pin 1) values.
	 */
	DDRD = (DDRD & _BV(0)) | (DDRD & _BV(1));

	/*
	 * Setup interrupts.
	 *
	 * The clear button is connected to the pin 3 (interrupt 1) and we want
	 * it to trigger on the falling signal (when use raises his finger).
	 *
	 * Signal of the value keys is combined with diodes and connected to the
	 * pin 2 (interrupt 1). We want interrupt to trigger on the rising signal
	 * to be able to determine which button is being pressed.
	 */
	sei();
	EICRA = (EICRA & ~(_BV(ISC01) | _BV(ISC00))) | _BV(ISC01) | _BV(ISC00);
	EICRA = (EICRA & ~(_BV(ISC11) | _BV(ISC10))) | _BV(ISC11);
	EIMSK = _BV(INT0) | _BV(INT1);


	set_sleep_mode(SLEEP_MODE_IDLE);
	sleep_enable();

	for (;;) {
		sleep_mode();
	}
}
Ejemplo n.º 13
0
void tileSetup(void){
	//Initialization routines
	initIO();
	setPort(&PORTB);
	sendColor(LEDCLK,LEDDAT,dark);
	sei();
	initAD();
	initTimer();
	set_sleep_mode(SLEEP_MODE_PWR_DOWN);
	sleep_enable();
	//Set up timing ring buffers
	uint8_t i;
	for(i = 0; i<6; i++){
		timeBuf[i]=0;
	}
	mode = running;
}
Ejemplo n.º 14
0
int main(void)
{
	set_sleep_mode(SLEEP_MODE_IDLE);
	PORTF.DIRSET |= 0x01;
	initialize_console();
	initialize_games();
	start_vga();
	
    while(1)
    {
		sleep_mode();
		if(vsync_backporch) {
			vsync_backporch = 0x00;
			update_state();
		}
    }
}
/// @see http://www.nongnu.org/avr-libc/user-manual/group__avr__sleep.html
void Sleepy::powerDown() {
	byte adcsraSave = ADCSRA;
	ADCSRA &= ~bit(ADEN); // disable the ADC
	set_sleep_mode(SLEEP_MODE_PWR_DOWN);
	ATOMIC_BLOCK(ATOMIC_FORCEON) {
		sleep_enable();
		// sleep_bod_disable(); // can't use this - not in my avr-libc version!
#ifdef BODSE
		MCUCR = MCUCR | bit(BODSE) | bit(BODS); // timed sequence
		MCUCR = (MCUCR & ~bit(BODSE)) | bit(BODS);
#endif
	}
	sleep_cpu();
	sleep_disable();
	// re-enable what we disabled
	ADCSRA = adcsraSave;
}
Ejemplo n.º 16
0
int main(void)
{
	uint8_t i, 
		led;		/* port D LEDs */

	DDRD = 0xFF;		/* set port D as output */
	DDRE &= ~(_BV(PORTE4));	/* set PE4 as input */
	PORTE |= _BV(PORTE4);	/* enable PE4 pull up resistor */

	cli();			/* global interrupt disable */
	EIMSK = 0x00;		/* disable all external interrupts */
	EICRB = 0x00;		/* 0 0 The low level of INT4 generates an interrupt request. */
	EIFR = 0x00;		/* clear all interrupt flags */
	EIMSK = _BV(INT4);	/* enable external interrupts */
	sei();			/* global interrupt enable */

	/*
	 * SLEEP_MODE_IDLE          ... Idle
	 * SLEEP_MODE_ADC           ... ADC Noise Reduction
	 * SLEEP_MODE_PWR_DOWN      ... Power-down
	 * SLEEP_MODE_PWR_SAVE      ... Power-save
	 * SLEEP_MODE_STANDBY       ... Standby
	 * SLEEP_MODE_EXT_STANDBY   ... Extended Standby
	 */

	set_sleep_mode(SLEEP_MODE_IDLE); /* set sleep mode */

	while(1) 
	{
		led = 1;	/* indicate we are ready */
		PORTD = ~led;

		sleep_enable();		/* set Sleep Enable bit */
		sleep_cpu();		/* sleep - waiting for INT4 */
		sleep_disable();	/* clear Sleep Enable bit */

		while (led)	/* action after wake-up */
		{
			led <<= 1;	/* walking LED */
			PORTD = ~led;	

			for (i = 0; i < 100; i++)	/* delay 1s */
				_delay_ms(10);
		}
	}
}
Ejemplo n.º 17
0
//---------------------------------------------------------------------------
static void IdleMain( void *unused )
{
    while(1)
    {
#if 1
        // LPM code;
        set_sleep_mode(SLEEP_MODE_IDLE);
        cli();
        sleep_enable();
        sei();
        sleep_cpu();
        sleep_disable();
        sei();
#endif        
    }
    return 0;
}
Ejemplo n.º 18
0
void sleepWithWDT(uint8_t wdt_period) {
  wdt_enable(wdt_period);
  wdt_reset();
  #if defined(__AVR_ATtiny85__) 
    WDTCR |= _BV(WDIE); //wake up interrupt when time is up
  #else //ATTiny84, ATMega328
    WDTCSR |= _BV(WDIE); //wake up interrupt when time is up
  #endif 
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_mode();
  wdt_disable();
  #if defined(__AVR_ATtiny85__) 
    WDTCR &= ~_BV(WDIE);
  #else //ATTiny84, ATMega328
    WDTCSR &= ~_BV(WDIE);
  #endif 
}
Ejemplo n.º 19
0
int main(void)
{	
	_delay_ms(1000); //power_on_delay
	RFM73_Initialize();
	RED_LED_OUT();
	RED_LED_OFF();
	
	set_sleep_mode(SLEEP_MODE_PWR_DOWN);
	sei();   // enable interrupts globally
	sleep_mode();  // go to sleep
	
	while(1)
	{
		Receive_Packet();
		sleep_mode();
	}
}
// Start program
int main(void)
{
	// Timer initialize
	InitTimer1();
	InitTimer0();

	// Set LED pin to output
	LED_DDR = (1 << LED_OUT);

	// Enable interrupts
	sei();

	while(1)
	{
		// Sleep Mode
		set_sleep_mode(SLEEP_MODE_IDLE);
		sleep_mode();

		// If command exists ... compare
		if (CmdDone == 1)
		{
			// If matches required command
			if (RC5_cmd_val == RC5_CMD)
			{
				// Sleep disablen
				//sleep_disable();

				// Set output to 1
				LED_PORT |= (1 << LED_OUT);
				// Set CmdMatch to 1 ... no new command will be sampled
				CmdMatch = 1;
				// Set TimerValue to zero
				TimerValue = 0;
				// Start counting
				StartTimer0();
			}

			// Reset all values
			RC5_cmd_val = 0x00;
			CmdBitNumber = 7;
			StartBit = 0;
			CmdDone = 0;
		}
	}
}
Ejemplo n.º 21
0
int main(void) {
    // Configure PORTB-pins
    DDRD = 0x07;

    rtc_init();  //initialise the timer
    sei();
    set_sleep_mode(SLEEP_MODE_PWR_SAVE); 

    unsigned int lastsecond = 0;

    // Loop forever
    while(1) {
    
    if ( seconds != lastsecond )
    {
        PORTD ^= 0b00000100;
        lastsecond = seconds;
    }
  
    if ( seconds == 0 )
    {
        // If one minute passed, pulse 2ms signal
        // We must also alternate polarity of the
        // pulse sent to the clock, so every other
        // time we pulse the other way of the H-bridge.
        //
        // 0bxxxxxx10 -> 0bxxxxxx01 -> 0bxxxxxx10 -> ...(contd.)
        //
        if ( direction == 0 ){
            PORTD |= 0x02;
            _delay_ms( MOTOR_PULSE_DURATION_MS );
            PORTD &= 0xFD;
            // Increment direction to alternate next time
            direction = 1;
        } else {
            PORTD |= 0x01;
            _delay_ms( MOTOR_PULSE_DURATION_MS );
            PORTD &= 0xFE;
            // Increment direction to alternate next time
            direction = 0;
        }
    }
    gnight();
    }
}
Ejemplo n.º 22
0
static void ioinit() {
	DDRD = (uint8_t) 0xff & ~(_BV(3));	// PORTD 3 is input (INT1, RECVINT)
	DDRC = 0xff;	// LCD lines
	DDRB = 0x0f;	// SS_RECV, LCD_BACKLIGHT, SS/SNDRST, MOSI (see spi.c)
	PORTD = _BV(4);
	PORTC = 0x0;
	PORTB = 0x0;
	
	
	set_sleep_mode(SLEEP_MODE_IDLE);

	// set INT0 and INT1 on rising edge
	MCUCR |= _BV(ISC11) | _BV(ISC10) | _BV(ISC01) | _BV(ISC00);
	GICR |= _BV(INT1);		// enable INT1
	
	// Enable GIE
	sei();
}
Ejemplo n.º 23
0
/********************************************************************
*
*	sleepNow
*
********************************************************************/
void Sleep::sleepInterrupt(int interrupt,int mode) {

	if(mode == FALLING || mode == LOW)
	{
	   int pin = interrupt + 2; //will fail on the mega	
	   pinMode (pin, INPUT);
	   digitalWrite (pin, HIGH);
	}

	set_sleep_mode(sleepMode_);
	sleep_enable();
	attachInterrupt(interrupt,sleepHandler,mode);
	sei(); //make sure interrupts are on!
	sleep_mode();
	 //----------------------------- ZZZZZZ sleeping here----------------------
	sleep_disable(); //disable sleep, awake now
	detachInterrupt(interrupt);
}
Ejemplo n.º 24
0
void osx_tlsche_execute( TiOsxTimeLineScheduler * sche )
{
	rtc_setinterval( sche->timer, 0, 2, 0x01); //定时周期为一秒 
	hal_enable_interrupts();
	rtc_start( sche->timer );

    while (1)
    {
        osx_tlsche_evolve( sche, NULL );
	
        set_sleep_mode(SLEEP_MODE_IDLE);
	    sleep_enable();
	    sleep_cpu();
	    sleep_disable();
    }

    // rtc_stop( sche->rtc );
}
Ejemplo n.º 25
0
void sleepNow()
{
    PORTA = 0;
    DDRA = 0;
    PORTB = 0;
    DDRB = 0;
    TCCR1B = 0;
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    sleep_enable();
    GIMSK |= _BV(INT0);
    asm("sleep");
    GIMSK &=~_BV(INT0);
    sleep_disable();
    currDemo ++;
    if(currDemo > DEMOCOUNT) {
    	currDemo = 0;
    }
}
Ejemplo n.º 26
0
int main(void)
{
    DDRB = (1 << PB0);

    // Watchdog signal will be active low
    //PORTB |= (1 << PB0);

    // Setup the power reduction register
    PRR = (1 << PRTIM1) | (1 << PRTIM0) | (1 << PRUSI) | (1 << PRADC);

    sei();
    
    while (1)
    {
        // Disable the watchdog
    
        WDTCR |= (1 << WDCE) | (1 << WDE);
        WDTCR &= ~(1 << WDE);
        
        // Enable the watchdog. It will fire every 4 seconds.
        
        WDTCR = (1 << WDIE) | (1 << WDE) | (1 << WDP3);

        // Sleep in power down mode. We will be woken up by the watchdog interrupt

        set_sleep_mode(SLEEP_MODE_PWR_DOWN);
        sleep_enable();
        sleep_cpu();

        // When we wake up the watchdog interrupt has fired, chck if we have done enough
        // iterations for an hour. If so, pulse PB0 low.

        if (counter >= (60 / 60))
        {
            counter = 0;

            PINB |= (1 << PB0);
            _delay_us(4);
            PINB &= ~(1 << PB0);
        }
    }

    return 0;
}
Ejemplo n.º 27
0
//Main body in fact, an inifinite loop
void ReadTemp(){
	
	set_sleep_mode(SLEEP_MODE_PWR_SAVE);
	
    while(1)
    {
		uint32_t v = ReadADCx16();
		//convert to centigrad and *10 (because we are working with INT and want to display 1 decimal)
		//v = (v * 5 * 100 * 10) / 1024; <=> v * 5 * 1000 / 1024 <=> v *5 but we loose a bit of precision
		//v = v * 5; 
		v = (v * 5 * 100 * 10) >> 10; //>> 10 <=> /1024
		
		//ad'hoc calibration
		//apparently my system reads a bit too high temp, about 5% too high
		//I don't have the will to make extensive test, calculate formula etc... 
		//v = v - v/20; //finally readings are ok like that after comparison, just keep the code for memory
		
		//average the temp with latest readings
		mTempBufferAverage[mTempBufferHead] = v;
		mTempBufferHead = (mTempBufferHead +1) % AVGBUFFER_LEN;
		
		//calculate an average with a circle buffer
		v= 0;
		for (uint16_t j = 0; j < AVGBUFFER_LEN; j++){
			v += mTempBufferAverage[j];
		}
		v = v / AVGBUFFER_LEN;
		
		//just some silly temporisation
		for (uint16_t j = 0; j < 10000; j++){
			showDigit(v);
			//_delay_us(1000);
			//_delay_ms(1); // save about 0.5mA per ms of sleep. 1 does not change the brightness, after it does but saves more power... depends if you want to read the temperature by daylight too.
		}
		
		
		//and now the sleep n time 8 sec
		for (int i =0; i < 2; i++){
			wdt_reset();
			myWatchdogEnable();
			sleep_mode();
		}		
    }	
}
Ejemplo n.º 28
0
int __attribute__((noreturn)) main(void)
{
	uint8_t i;

	/* disable watchdog */
	i = MCUSR;
	MCUSR = 0;
	wdt_disable();

	/* power down unused peripherals */
	PRR = ( (1 << PRTWI) |    /* TWI */
		(0 << PRTIM0) |   /* Timer 0 */
		(0 << PRTIM1) |   /* Timer 1 */
		(1 << PRTIM2) |   /* Timer 2 */
		(1 << PRSPI) |    /* SPI */
		(1 << PRUSART0) | /* USART0 */
		(0 << PRADC) );   /* ADC */

	/* clock */
	led_init();
	clock_init();
	hello();

	/* USB */
	usbInit();
	usbDeviceDisconnect();

	i = 0;
	while (--i) {
		_delay_ms(1);
	}

	usbDeviceConnect();

	sei();
	for (;;) {
		usbPoll();

		clock_poll();

		set_sleep_mode(SLEEP_MODE_IDLE);
		sleep_mode();
	}
}
Ejemplo n.º 29
0
int main(void)
{
	
	init_avr();

	uart_init();

	TCCR1B=(0<<ICNC1) | (0<<ICES1) | (0<<WGM13) | (0<<WGM12) | (1<<CS12) | (0<<CS11) | (0<<CS10);
	// Timer/Counter 1 Interrupt(s) initialization
	TIMSK1=(0<<ICIE1) | (0<<OCIE1B) | (0<<OCIE1A) | (1<<TOIE1);

	sei();
	
	Task[0] = 0;
	
	while(1)
	{
		
		if(BytesRead != 0)
		{
			TCCR1B = 0x00; // stop timer1
			memcpy(data_buffer, uart_buffer, BytesRead);
			uart_flush();
			for(int i = 0; i < 16; i++)
			Task[i] = data_buffer[i];
			run_task(Task);
			for(int i = 0; i < 16; i++)
			Task[i] = 0;
			TCCR1B = 0x04; // run timer1
			TimerEvent = false;
		}
		
		if(TimerEvent)
		{
			TimerEvent = false;
			run_task(Task);
			for(int i = 0; i < 16; i++)
			Task[i] = 0;
		}
		set_sleep_mode(SLEEP_MODE_IDLE);
		sleep_mode();
	}
		
}
Ejemplo n.º 30
0
//------------------------------------End of Setup-------------------------------------------------//
 //Main Loop//
 void loop () 
 {   
  flash ();                        //HeartBeat Flash//
  AwakeTimer();                    //Awake Timer// 
    if ( ATimer == SleepTime)
    { 
      BattRead();
      DataTX();
    } // End of Main loop if timer was reached

//----------------------------------- End of Actual executing code---------------------------//
  //Preparing to go to sleep//
  
  digitalWrite(DataRadioSwitch,LOW);               //Switch Data Radio off

  byte old_ADCSRA = ADCSRA;                        // disable ADC //
  ADCSRA = 0;                                      // disable ADC //

  byte old_PRR = PRR;                              // disable Internal modules//
  PRR = 0xFF;                                      // disable Internal modules//

  MCUSR = 0;                                       // clear various "reset" flags// 

  // Watchdog Timer Parameters//
  WDTCSR = bit (WDCE) | bit (WDE);                 // allow changes, disable reset
  WDTCSR = bit (WDIE) | bit (WDP3) | bit (WDP0);   // set WDIE, and 8 seconds delay
  wdt_reset();                                     // pat the dog once program has executed.

  // Sleep Activation //
  set_sleep_mode (SLEEP_MODE_PWR_DOWN);            //Sleep mode Selection//
  sleep_enable();                                  //Sleep Now//

  // turn off brown-out enable in software//
  MCUCR = bit (BODS) | bit (BODSE);                //Brown out settings
  MCUCR = bit (BODS);                              //Brown out set.
  sleep_cpu ();                                    //CPU is now sleeping

  //--------------------------------------End of sleep Preperation-------------------------------//
  // Once awake code executes from this point//
  // Once CPU wakes up do the follwoing to restore full operations//
  sleep_disable();
  PRR = old_PRR;
  ADCSRA = old_ADCSRA;
}