hal_sleep.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
  3. *
  4. * All Rights Reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. *
  10. * 1. Redistributions of source code must retain the above copyright notice, this
  11. * list of conditions and the following disclaimer.
  12. *
  13. * 2. Redistributions in binary form, except as embedded into a Nordic
  14. * Semiconductor ASA integrated circuit in a product or a software update for
  15. * such product, must reproduce the above copyright notice, this list of
  16. * conditions and the following disclaimer in the documentation and/or other
  17. * materials provided with the distribution.
  18. *
  19. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * 4. This software, with or without modification, must only be used with a
  24. * Nordic Semiconductor ASA integrated circuit.
  25. *
  26. * 5. Any software provided in binary form under this license must not be reverse
  27. * engineered, decompiled, modified and/or disassembled.
  28. *
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  31. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  33. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  34. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  35. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  36. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  38. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  39. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. *
  41. */
  42. #ifndef HAL_SLEEP_H_INCLUDED
  43. #define HAL_SLEEP_H_INCLUDED
  44. #include <stdint.h>
  45. /** @file
  46. * This file contains declaration of the HAL sleep interface.
  47. *
  48. * @defgroup hal_sleep HAL Sleep API
  49. * @ingroup hal_15_4
  50. * @{
  51. * @brief Module to declare HAL Sleep API
  52. * @details The Sleep module implements the only hal_sleep() routine to put the hardware to the sleep mode for some
  53. * milliseconds. The user can use convenient macros DAYS_TO_MS(), HOURS_TO_MS(), MINS_TO_MS(), and SEC_TO_MS()
  54. * to convert different time periods into milliseconds. Please note that this module requires a call to
  55. * hal_sleep_init() which is in turn called by sys_init() before using any module routines. This module is
  56. * only used to implement the System Sleep interface. The hal_sleep() routine is not assumed to be used by
  57. * the user explicitly.
  58. */
  59. /**@brief Converts days to milliseconds */
  60. #define DAYS_TO_MS(d) ((d) * 3600L * 24L * 1000L )
  61. /**@brief Converts hours to milliseconds */
  62. #define HOURS_TO_MS(h) ((h) * 3600L * 1000L )
  63. /**@brief Converts minutes to milliseconds */
  64. #define MINS_TO_MS(m) ((m) * 60L * 1000L )
  65. /**@brief Converts seconds to milliseconds */
  66. #define SEC_TO_MS(s) ((s) * 1000L )
  67. /**@brief Information, provided by the HAL, in order to explain the reason,
  68. * which caused the system to wake up.
  69. */
  70. typedef enum
  71. {
  72. UNKNOWN_INTERRUPT, /**< HAL can't define a wake up reason */
  73. RTC_CC_INTERRUPT /**< RTC interrupt was the awakening reason */
  74. } hal_wakeup_reason_t;
  75. /**@brief Puts hardware into the sleep mode for some milliseconds.
  76. *
  77. * @param[in] sleep_time_ms Time to sleep in ms
  78. *
  79. * @retval wakeup_reason Specifies reason of awakening
  80. */
  81. hal_wakeup_reason_t hal_sleep(uint32_t sleep_time_ms);
  82. /**@brief Initialization of the sleep module
  83. *
  84. */
  85. void hal_sleep_init(void);
  86. /** @} */
  87. #endif /* HAL_SLEEP_H_INCLUDED */