summaryrefslogtreecommitdiffhomepage
path: root/digital/zigbit/bitcloud/stack/Components/HAL/avr/common/src/sleep.c
diff options
context:
space:
mode:
authorFlorent Duchon2012-12-26 17:36:00 +0100
committerFlorent Duchon2013-02-13 21:21:12 +0100
commitb24866225a6301d3a663f874725e83c012dc25d3 (patch)
treeca527a2aab9abcdfbaf244c53ca63f0c531892b0 /digital/zigbit/bitcloud/stack/Components/HAL/avr/common/src/sleep.c
parent2ba279f4eb2f23fa08a7c13465d16ae6ba5d0f96 (diff)
digital/beacon: add bitcloud stack into common directory digital/zigbit
Diffstat (limited to 'digital/zigbit/bitcloud/stack/Components/HAL/avr/common/src/sleep.c')
-rw-r--r--digital/zigbit/bitcloud/stack/Components/HAL/avr/common/src/sleep.c79
1 files changed, 79 insertions, 0 deletions
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 <halSleep.h>
+
+/******************************************************************************
+ 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