mbed_rtc_time.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /** \addtogroup platform */
  2. /** @{*/
  3. /**
  4. * \defgroup platform_rtc_time rtc_time functions
  5. * @{
  6. */
  7. /* mbed Microcontroller Library
  8. * Copyright (c) 2006-2013 ARM Limited
  9. *
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. */
  22. #include <time.h>
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /** Implementation of the C time.h functions
  27. *
  28. * Provides mechanisms to set and read the current time, based
  29. * on the microcontroller Real-Time Clock (RTC), plus some
  30. * standard C manipulation and formating functions.
  31. *
  32. * Example:
  33. * @code
  34. * #include "mbed.h"
  35. *
  36. * int main() {
  37. * set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37
  38. *
  39. * while(1) {
  40. * time_t seconds = time(NULL);
  41. *
  42. * printf("Time as seconds since January 1, 1970 = %d\n", seconds);
  43. *
  44. * printf("Time as a basic string = %s", ctime(&seconds));
  45. *
  46. * char buffer[32];
  47. * strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
  48. * printf("Time as a custom formatted string = %s", buffer);
  49. *
  50. * wait(1);
  51. * }
  52. * }
  53. * @endcode
  54. */
  55. /** Set the current time
  56. *
  57. * Initialises and sets the time of the microcontroller Real-Time Clock (RTC)
  58. * to the time represented by the number of seconds since January 1, 1970
  59. * (the UNIX timestamp).
  60. *
  61. * @param t Number of seconds since January 1, 1970 (the UNIX timestamp)
  62. *
  63. * @note Synchronization level: Thread safe
  64. *
  65. * Example:
  66. * @code
  67. * #include "mbed.h"
  68. *
  69. * int main() {
  70. * set_time(1256729737); // Set time to Wed, 28 Oct 2009 11:35:37
  71. * }
  72. * @endcode
  73. */
  74. void set_time(time_t t);
  75. /** Attach an external RTC to be used for the C time functions
  76. *
  77. * @note Synchronization level: Thread safe
  78. *
  79. * @param read_rtc pointer to function which returns current UNIX timestamp
  80. * @param write_rtc pointer to function which sets current UNIX timestamp, can be NULL
  81. * @param init_rtc pointer to funtion which initializes RTC, can be NULL
  82. * @param isenabled_rtc pointer to function wich returns if the rtc is enabled, can be NULL
  83. */
  84. void attach_rtc(time_t (*read_rtc)(void), void (*write_rtc)(time_t), void (*init_rtc)(void), int (*isenabled_rtc)(void));
  85. #ifdef __cplusplus
  86. }
  87. #endif
  88. /** @}*/
  89. /** @}*/