rtc_api_hal.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* mbed Microcontroller Library
  2. *******************************************************************************
  3. * Copyright (c) 2018, STMicroelectronics
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice,
  10. * this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  15. * may be used to endorse or promote products derived from this software
  16. * without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  22. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  24. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  25. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  26. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *******************************************************************************
  29. */
  30. #ifndef MBED_RTC_API_HAL_H
  31. #define MBED_RTC_API_HAL_H
  32. #include "rtc_api.h"
  33. #include "lp_ticker_api.h"
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. #if MBED_CONF_TARGET_LSE_AVAILABLE
  38. #define RTC_CLOCK LSE_VALUE
  39. #else
  40. #define RTC_CLOCK LSI_VALUE
  41. #endif
  42. #if DEVICE_LPTICKER && !MBED_CONF_TARGET_LPTICKER_LPTIM
  43. /* PREDIV_A : 7-bit asynchronous prescaler */
  44. /* PREDIV_A is set to set LPTICKER frequency to RTC_CLOCK/4 */
  45. #define PREDIV_A_VALUE 3
  46. /** Read RTC counter with sub second precision
  47. *
  48. * @return LP ticker counter
  49. */
  50. uint32_t rtc_read_lp(void);
  51. /** Program a wake up timer event
  52. *
  53. * @param timestamp: counter to set
  54. */
  55. void rtc_set_wake_up_timer(timestamp_t timestamp);
  56. /** Call RTC Wake Up IT
  57. */
  58. void rtc_fire_interrupt(void);
  59. /** Disable the wake up timer event.
  60. *
  61. * The wake up timer use auto reload, you have to deactivate it manually.
  62. */
  63. void rtc_deactivate_wake_up_timer(void);
  64. #else /* DEVICE_LPTICKER && !MBED_CONF_TARGET_LPTICKER_LPTIM */
  65. /* PREDIV_A : 7-bit asynchronous prescaler */
  66. /* PREDIV_A is set to the maximum value to improve the consumption */
  67. #define PREDIV_A_VALUE 127
  68. #endif /* DEVICE_LPTICKER && !MBED_CONF_TARGET_LPTICKER_LPTIM */
  69. /* PREDIV_S : 15-bit synchronous prescaler */
  70. /* PREDIV_S is set in order to get a 1 Hz clock */
  71. #define PREDIV_S_VALUE RTC_CLOCK / (PREDIV_A_VALUE + 1) - 1
  72. /** Synchronise the RTC shadow registers.
  73. *
  74. * Must be called after a deepsleep.
  75. */
  76. void rtc_synchronize(void);
  77. #ifdef __cplusplus
  78. }
  79. #endif
  80. #endif