rtctime.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright 2015 Dius Computing Pty Ltd. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * - Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * - Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the
  13. * distribution.
  14. * - Neither the name of the copyright holders nor the names of
  15. * its contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  21. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  22. * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  23. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  25. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  27. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  29. * OF THE POSSIBILITY OF SUCH DAMAGE.
  30. *
  31. * @author Johny Mattsson <jmattsson@dius.com.au>
  32. */
  33. #ifndef _RTCTIME_H_
  34. #define _RTCTIME_H_
  35. /* We don't want to expose the raw rtctime interface as it is heavily
  36. * 'static inline' and used by a few things, so instead we wrap the
  37. * relevant functions and expose these instead, through the rtctime.c module.
  38. */
  39. #include <c_types.h>
  40. #include "sections.h"
  41. #ifndef _RTCTIME_INTERNAL_H_
  42. struct rtc_timeval
  43. {
  44. uint32_t tv_sec;
  45. uint32_t tv_usec;
  46. };
  47. #endif
  48. struct rtc_tm{
  49. int tm_sec; /* Seconds. [0-60] (1 leap second) */
  50. int tm_min; /* Minutes. [0-59] */
  51. int tm_hour; /* Hours. [0-23] */
  52. int tm_mday; /* Day. [1-31] */
  53. int tm_mon; /* Month. [0-11] */
  54. int tm_year; /* Year - 1900. */
  55. int tm_wday; /* Day of week. [0-6] */
  56. int tm_yday; /* Days in year.[0-365] */
  57. };
  58. void TEXT_SECTION_ATTR rtctime_early_startup (void);
  59. void rtctime_late_startup (void);
  60. void rtctime_adjust_rate (int rate);
  61. void rtctime_gettimeofday (struct rtc_timeval *tv);
  62. void rtctime_settimeofday (const struct rtc_timeval *tv);
  63. bool rtctime_have_time (void);
  64. void rtctime_deep_sleep_us (uint32_t us);
  65. void rtctime_deep_sleep_until_aligned_us (uint32_t align_us, uint32_t min_us);
  66. void rtctime_gmtime (const int32 stamp, struct rtc_tm *r);
  67. #endif