コード例 #1
0
ファイル: main.c プロジェクト: Humhu/bootloader
int main(void) {

    SetupClock();
    SwitchClocks();
    SetupPorts();
    //lcdSetup(4,20); // 4 rows & 20 cols
    radioSetup();   // polling mode
    bootSetup();

    LED_1 = 1; LED_2 = 1; LED_3 = 1;
    delay_ms(500);
    LED_1 = 0; LED_2 = 0; LED_3 = 0;
    delay_ms(200);
    LED_1 = 1; LED_2 = 1; LED_3 = 1;
    delay_ms(500);

    // check if radio is working and at the right state.
    while (radioGetTrxState() != 0x16);
        
    LED_1 = 0;
    LED_2 = 0;
    LED_3 = 0;
    
    //print("Ready");
    //bootTestRadio();
    bootRun();
    bootReset();

    while(1);
    return 1;

}
コード例 #2
0
ファイル: sleep.c プロジェクト: garyStofer/Rum_802154
void nodeSleep(u16 tenthSeconds)
{

    // ************** Power down the other board peripherals
    Leds_off();

    // ************** Power down the radio
    // wait for radio to be done
    u8 state = BUSY_TX_ARET;
    while (state == BUSY_TX_ARET ||
           state == BUSY_RX_AACK)
        state = radioGetTrxState();

    // Now put radio to sleep
    radioEnterSleepMode();


// TODO: figure out what needs to be put to sleep to minimize current consumption
// ************** Power down the on-chip modules
// PRR = 0xbf; ??? 
// Disable ADC
//        ADCSRA &= ~(1 << ADEN);
// Turn off comparator
//        ACSR |= (1 << 
    
// turn off ports  etc

// Turn off BOD

// This should only be done once -- No need to do it over again
/*
        AVR_ENTER_CRITICAL_REGION();
#define BODS  6
#define BODSE 5
        MCUCR  |= (1 << BODSE) | (1<< BODS);
        MCUCR  &= ~(1 << BODSE);
        AVR_LEAVE_CRITICAL_REGION();
    
*/


    // ************** Set the timer to wake up
	// Set TIMER2 Asyncronous Mode.
	ASSR |= (1 << AS2);
	// Set TIMER2 Prescaler to 1024.
	TCCR2B |= ((1 << CS22)|(1 << CS21)|(1 << CS20));
	// Wait for TCNT2 write to finish.
	while(ASSR & (1 << TCR2BUB))
		;


    // Sleep as many times as needed to sleep for the full time
    while (tenthSeconds)
    {
		// This is to get the node manually out of sleeping mode --
    	// Might take up to 7.5Sec to detect button press
    	//
    	if (BUTTON_PRESSED() )
    	{
    		Led1_on();
    		macConfig.sleeping = false;
    		while (BUTTON_PRESSED())
    			;
    		Led1_off();
    		break;		//  exit the Sleeping loop
    	}
		// Set TIMER2 output compare register from user.
		if (tenthSeconds > 75)
		{
			// Just decrement by the max timeout
			OCR2A = 240; // 7.5 seconds, max timeout
			tenthSeconds -= 75;
		}
		else
		{
			// Can measure the remaining time in one timer cycle

			tenthSeconds = tenthSeconds * 16 / 5;
			if (!tenthSeconds)
				tenthSeconds++;
			OCR2A = tenthSeconds;
			tenthSeconds = 0;
		}
		// Wait for OCR2 write to finish.
		while(ASSR & (1 << OCR2AUB))
			;
		// Reset TIMER2 timer counter value.
		TCNT2 = 0;
		// Wait for TCNT2 write to finish before entering sleep.
		while(ASSR & (1 << TCN2UB))
			;

		// Clear interrupt flag
		TIFR2 |= (1 << OCF2A);
		// Enable TIMER2 output compare interrupt.
		TIMSK2 |= (1 << OCIE2A);


        // ************** Go to sleep
        AVR_ENTER_CRITICAL_REGION();
        set_sleep_mode( SLEEP_MODE_PWR_SAVE);
        sleep_enable();
        sei();
        sleep_cpu();   // sleeping right here
        sleep_disable();
        AVR_LEAVE_CRITICAL_REGION();

        wdt_disable();
    }

    // ************** Awake now, wake up everything

 //    PRR = 0x03; ??


    if (SERIAL)
        serial_init(NULL);

    debugMsgStr("\r\nNode slept");
    if ( macConfig.associated)
        HAL_ADC_INIT();

    // Bring SPI port back up (must re-init after sleep)
    radio_spi_init();

    // Wake up radio.
    radioLeaveSleepMode();

    // Set RF212 to 250KB mode.
// TODO: do I need to call this??
    //radioSetup900();

    radioSetTrxState(PLL_ON);
}