Blame view

RIOT/drivers/include/periph/rtc.h 2.58 KB
fb11e647   vrobic   reseau statique a...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
  /*
   * Copyright (C) 2014 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
   *
   * This file is subject to the terms and conditions of the GNU Lesser General
   * Public License v2.1. See the file LICENSE in the top level directory for more
   * details.
   */
  
  /**
   * @defgroup    drivers_periph_rtc RTC
   * @ingroup     drivers_periph
   * @brief       Low-level RTC (Real Time Clock) peripheral driver
   *
   * @note
   * The values used for setting and getting the time/alarm should
   * conform to the `struct tm` specification.
   * Compare: http://pubs.opengroup.org/onlinepubs/7908799/xsh/time.h.html
   *
   * @{
   * @file
   * @brief       Low-level RTC peripheral driver interface definitions
   *
   * @author      Thomas Eichinger <thomas.eichinger@fu-berlin.de>
   */
  
  #ifndef RTC_H
  #define RTC_H
  
  #include <time.h>
  #include "periph_conf.h"
  
  #ifdef __cplusplus
  extern "C" {
  #endif
  
  /* guard file in case no RTC device was specified */
  #if RTC_NUMOF
  
  /**
   * @brief Signature for alarm Callback
   *
   * @param[in] arg           optional argument to put the callback in the right context
   */
  typedef void(*rtc_alarm_cb_t)(void *arg);
  
  /**
   * @brief Initialize RTC module
   */
  void rtc_init(void);
  
  /**
   * @brief Set RTC to given time.
   *
   * @param[in] time          Pointer to the struct holding the time to set.
   *
   * @return  0 for success
   * @return -1 an error occurred
   */
  int rtc_set_time(struct tm *time);
  
  /**
   * @brief Get current RTC time.
   *
   * @param[out] time         Pointer to the struct to write the time to.
   *
   * @return  0 for success
   * @return -1 an error occurred
   */
  int rtc_get_time(struct tm *time);
  
  /**
   * @brief Set an alarm for RTC to the specified value.
   *
   * @note Any already set alarm will be overwritten.
   *
   * @param[in] time          The value to trigger an alarm when hit.
   * @param[in] cb            Callback executed when alarm is hit.
   * @param[in] arg           Argument passed to callback when alarm is hit.
   *
   * @return  0 for success
   * @return -2 invalid `time` parameter
   * @return -1 other errors
   */
  int rtc_set_alarm(struct tm *time, rtc_alarm_cb_t cb, void *arg);
  
  /**
   * @brief Gets the current alarm setting
   *
   * @param[out]  time        Pointer to structure to receive alarm time
   *
   * @return  0 for success
   * @return -1 an error occurred
   */
  int rtc_get_alarm(struct tm *time);
  
  /**
   * @brief Clear any set alarm, do nothing if nothing set
   */
  void rtc_clear_alarm(void);
  
  /**
   * @brief Turns the RTC hardware module on
   */
  void rtc_poweron(void);
  
  /**
   * @brief Turns the RTC hardware module off
   */
  void rtc_poweroff(void);
  
  #endif /* RTC_NUMOF */
  
  #ifdef __cplusplus
  }
  #endif
  
  #endif /* RTC_H */
  /** @} */