/****************************************************************************** Prepares system for power-save, power-down. Power-down the mode is possible only when internal RC is used Parameters: none. Returns: -1 there is no possibility to power-down system. ******************************************************************************/ int HAL_Sleep(void) { if (INTERNAL_RC != halGetClockSource()) { if (HAL_SLEEP_TIMER_IS_STOPPED == halSleepControl.sleepTimerState) { // sleep timer isn't started return -1; } GPIO_RF_SLP_TR_make_in(); while (ASSR & HAL_ASSR_FLAGS); if (!(TIMSK2 & (1 << OCIE2A))) { // compare interrupt is disabled OCR2A = 0xFF; while (ASSR & HAL_ASSR_FLAGS); } TCCR2A |= ((1 << COM2A1) | (1 << COM2A0)); // set OC2A on compare while (ASSR & HAL_ASSR_FLAGS); TCCR2B |= (1 << FOC2A); // force output to set OC2A while (ASSR & HAL_ASSR_FLAGS); TCCR2A &= ~((1 << COM2A1) | (1 << COM2A0)); // no compare while (ASSR & HAL_ASSR_FLAGS); TCCR2A |= (1 << COM2A1); // clear OC2A on compare while (ASSR & HAL_ASSR_FLAGS); } halSleepControl.wakeupStation = HAL_SLEEP_MODE; // the reset of sign of entry to the sleep mode. while (ASSR & HAL_ASSR_FLAGS); halPostTask4(HAL_SLEEP); return 0; }
/**************************************************************************//** \brief Switch on system power. \param[in] wakeupSource - wake up source ******************************************************************************/ void halPowerOn(const uint8_t wakeupSource) { halSleepControl.wakeupStation = HAL_ACTIVE_MODE; halSleepControl.wakeupSource = wakeupSource; if (INTERNAL_RC == halGetClockSource()) { GPIO_RF_SLP_TR_clr(); } else { GPIO_RF_SLP_TR_make_in(); TCCR2A &= ~((1 << COM2A1) | (1 << COM2A0)); // no compare while (ASSR & HAL_ASSR_FLAGS); } GPIO_RF_SLP_TR_make_out(); #ifdef _HAL_USE_AMPLIFIER_ // set one on pin. Enable power amplifier. GPIO_POW_AMPLF_SLP_set(); #endif halPostTask4(HAL_WAKEUP); }
/**************************************************************************//** \brief Posts specific USART task. \param[in] taskId - unique identifier of the task to be posted. ******************************************************************************/ static void usbfifoPostTask(UsbfifoTaskId_t taskId) { usbfifoTaskBitMask |= (UsbfifoTaskBitMask_t)1 << taskId; halPostTask4(HAL_EXT_HANDLER); }
/**************************************************************************//** \brief Takes account of the sleep interval. \param[in] interval - time of sleep ******************************************************************************/ void halAdjustSleepInterval(uint32_t interval) { halAppTime += interval; halPostTask4(HAL_TIMER4_COMPA); }