Alternative library and kernel for add-in development on fx-9860G and fx-CG50 under Linux.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rtc.h 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //---
  2. // gint:rtc - Real-Time Clock
  3. //---
  4. #ifndef GINT_RTC
  5. #define GINT_RTC
  6. #include <gint/defs/types.h>
  7. //---
  8. // Time management
  9. //---
  10. /* rtc_time_t - a point in time, representable in the RTC registers */
  11. typedef struct
  12. {
  13. uint16_t year; /* Years (exact value, e.g. 2018) */
  14. uint8_t week_day; /* Day of week, (0=Sunday, 6=Saturday) */
  15. uint8_t month; /* Month (0..11) */
  16. uint8_t month_day; /* Day of month (1..31) */
  17. uint8_t hours; /* Hour (0..23) */
  18. uint8_t minutes; /* Minute (0..59) */
  19. uint8_t seconds; // Second (0..59) */
  20. } rtc_time_t;
  21. /* rtc_get_time() - read the current time from the RTC
  22. @time Pointer to rtc_time_t structure (needs not be initialized) */
  23. void rtc_get_time(rtc_time_t *time);
  24. /* rtc_set_time() - write a new current time to the RTC
  25. If [time->week_day] is not in the valid range, it is set to 0. Other fields
  26. are not checked.
  27. @time Pointer to new time */
  28. void rtc_set_time(const rtc_time_t *time);
  29. //---
  30. // RTC timer
  31. // The real-time clock produces a regular interrupt which may be used as a
  32. // timer with a maximum frequency of 256 Hz. It is also useful to check
  33. // that the clock settings (see <gint/clock.h>) are properly detected, by
  34. // comparing the detected frequencies with the RTC.
  35. //---
  36. /* rtc_frequency_t - possible frequency settings for the RTC's interrupt */
  37. typedef enum
  38. {
  39. RTC_500mHz = 7,
  40. RTC_1Hz = 6,
  41. RTC_2Hz = 5,
  42. RTC_4Hz = 4,
  43. RTC_16Hz = 3,
  44. RTC_64Hz = 2,
  45. RTC_256Hz = 1,
  46. RTC_NONE = 0,
  47. } rtc_frequency_t;
  48. /* rtc_start_timer() - configure the RTC timer
  49. This function sets up the RTC timer to invoke the provided callback function
  50. with its argument regularly. This works like normal timers (<gint/timer.h>);
  51. [callback] is passed [arg] as argument and the RTC timer is stopped if it
  52. returns non-zero.
  53. This function will replace any existing callback!
  54. Note that, as opposed to timers, it is not possible to know how much time
  55. will elapse before the callback will first be called. For instance, setting
  56. up a 1 Hz-callback when the current time ends in 950 ms will result in the
  57. callback being called after 50 ms, then every second. This is not a problem
  58. for most uses. */
  59. void rtc_start_timer(rtc_frequency_t freq,
  60. int (*callback)(volatile void *arg), volatile void *arg);
  61. /* rtc_stop_timer() - stop the RTC timer
  62. This function stops the RTC timer that was set up with rtc_start_timer(). If
  63. the decision of stopping the timer comes from the callback, it is preferable
  64. to return non-zero. */
  65. void rtc_stop_timer(void);
  66. #endif /* GINT_RTC */