From b24866225a6301d3a663f874725e83c012dc25d3 Mon Sep 17 00:00:00 2001 From: Florent Duchon Date: Wed, 26 Dec 2012 17:36:00 +0100 Subject: digital/beacon: add bitcloud stack into common directory digital/zigbit --- .../stack/Components/HAL/avr/common/src/sleep.c | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 digital/zigbit/bitcloud/stack/Components/HAL/avr/common/src/sleep.c (limited to 'digital/zigbit/bitcloud/stack/Components/HAL/avr/common/src/sleep.c') diff --git a/digital/zigbit/bitcloud/stack/Components/HAL/avr/common/src/sleep.c b/digital/zigbit/bitcloud/stack/Components/HAL/avr/common/src/sleep.c new file mode 100644 index 00000000..1ad72df2 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/HAL/avr/common/src/sleep.c @@ -0,0 +1,79 @@ +/**************************************************************************//** + \file sleep.c + + \brief The implementation of common sleep and wake up. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 1/12/09 A. Khromykh - Created + ******************************************************************************/ +/****************************************************************************** + * WARNING: CHANGING THIS FILE MAY AFFECT CORE FUNCTIONALITY OF THE STACK. * + * EXPERT USERS SHOULD PROCEED WITH CAUTION. * + ******************************************************************************/ +/****************************************************************************** + Includes section +******************************************************************************/ +#include + +/****************************************************************************** + Define(s) section +******************************************************************************/ +#define HAL_NULL_POINTER -1 +#define HAL_SLEEP_TIMER_HAS_ALREADY_STARTED -3 +#define HAL_SLEEP_TIMER_IS_BUSY -2 +#define HAL_SLEEP_SYSTEM_HAS_ALREADY_STARTED -3 + +/****************************************************************************** + Global variables section +******************************************************************************/ +HalSleepControl_t halSleepControl = +{ + .wakeupStation = HAL_ACTIVE_MODE, + .sleepTimerState = HAL_SLEEP_TIMER_IS_STOPPED +}; + +/****************************************************************************** + Implementations section +******************************************************************************/ +/**************************************************************************//** +\brief Starts sleep timer and HAL sleep. When system is wake up send callback +\param[in] + sleepParam - pointer to sleep structure. +\return + -1 - bad pointer, \n + -2 - sleep timer is busy, \n + -3 - sleep system has been started. + 0 - success. +******************************************************************************/ +int HAL_StartSystemSleep(HAL_Sleep_t *sleepParam) +{ + HAL_SleepTimer_t sleepTimer; + int sleepTimerStatus; + + if (!sleepParam) + return HAL_NULL_POINTER; + + halSleepControl.callback = sleepParam->callback; + sleepTimer.interval = sleepParam->sleepTime; + sleepTimer.mode = TIMER_ONE_SHOT_MODE; + sleepTimer.callback = NULL; + + sleepTimerStatus = HAL_StartSleepTimer(&sleepTimer); + if ((HAL_NULL_POINTER == sleepTimerStatus) || (HAL_SLEEP_TIMER_HAS_ALREADY_STARTED == sleepTimerStatus)) + return HAL_SLEEP_TIMER_IS_BUSY; + + if (-1 == HAL_Sleep()) + return HAL_SLEEP_SYSTEM_HAS_ALREADY_STARTED; + + return 0; +} + +//eof sleep.c -- cgit v1.2.3