Mistake on this page?
Report an issue in GitHub or email us
mbed_rtc_time.h
1 
2 /** \addtogroup platform */
3 /** @{*/
4 /**
5  * \defgroup platform_rtc_time rtc_time functions
6  * @{
7  */
8 /* mbed Microcontroller Library
9  * Copyright (c) 2006-2013 ARM Limited
10  * SPDX-License-Identifier: Apache-2.0
11  *
12  * Licensed under the Apache License, Version 2.0 (the "License");
13  * you may not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  * http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  */
24 
25 #include <time.h>
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 /* Timeval definition for non GCC_ARM toolchains */
32 #if !defined(__GNUC__) || defined(__CC_ARM) || defined(__clang__)
33 struct timeval {
34  time_t tv_sec;
35  int32_t tv_usec;
36 };
37 #endif
38 
39 /** Implementation of the C time.h functions
40  *
41  * Provides mechanisms to set and read the current time, based
42  * on the microcontroller Real-Time Clock (RTC), plus some
43  * standard C manipulation and formatting functions.
44  *
45  * Example:
46  * @code
47  * #include "mbed.h"
48  *
49  * int main() {
50  * set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37
51  *
52  * while (true) {
53  * time_t seconds = time(NULL);
54  *
55  * printf("Time as seconds since January 1, 1970 = %u\n", (unsigned int)seconds);
56  *
57  * printf("Time as a basic string = %s", ctime(&seconds));
58  *
59  * char buffer[32];
60  * strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
61  * printf("Time as a custom formatted string = %s", buffer);
62  *
63  * wait(1);
64  * }
65  * }
66  * @endcode
67  */
68 
69 /** Set the current time
70  *
71  * Initializes and sets the time of the microcontroller Real-Time Clock (RTC)
72  * to the time represented by the number of seconds since January 1, 1970
73  * (the UNIX timestamp).
74  *
75  * @param t Number of seconds since January 1, 1970 (the UNIX timestamp)
76  *
77  * @note Synchronization level: Thread safe
78  *
79  * Example:
80  * @code
81  * #include "mbed.h"
82  *
83  * int main() {
84  * set_time(1256729737); // Set time to Wed, 28 Oct 2009 11:35:37
85  * }
86  * @endcode
87  */
88 void set_time(time_t t);
89 
90 /** Attach an external RTC to be used for the C time functions
91  *
92  * @note Synchronization level: Thread safe
93  *
94  * @param read_rtc pointer to function which returns current UNIX timestamp
95  * @param write_rtc pointer to function which sets current UNIX timestamp, can be NULL
96  * @param init_rtc pointer to function which initializes RTC, can be NULL
97  * @param isenabled_rtc pointer to function which returns if the RTC is enabled, can be NULL
98  */
99 void attach_rtc(time_t (*read_rtc)(void), void (*write_rtc)(time_t), void (*init_rtc)(void), int (*isenabled_rtc)(void));
100 
101 /** Standard lib retarget, get time since Epoch
102  *
103  * @param tv Structure containing time_t seconds and useconds_t microseconds. Due to
104  * separate target specific RTC implementations only the seconds component is used.
105  * @param tz DEPRECATED IN THE STANDARD: This parameter is left in for legacy code. It is
106  * not used.
107  * @return 0 on success, -1 on a failure.
108  * @note Synchronization level: Thread safe
109  *
110  */
111 int gettimeofday(struct timeval *tv, void *tz);
112 
113 /** Standard lib retarget, set time since Epoch
114  *
115  * @param tv Structure containing time_t seconds and useconds_t microseconds. Due to
116  * separate target specific RTC implementations only the seconds component is used.
117  * @param tz DEPRECATED IN THE STANDARD: This parameter is left in for legacy code. It is
118  * not used.
119  * @return Time in seconds on success, -1 on a failure.
120  * @note Synchronization level: Thread safe
121  *
122  */
123 int settimeofday(const struct timeval *tv, const struct timezone *tz);
124 
125 #ifdef __cplusplus
126 }
127 #endif
128 
129 /** @}*/
130 /** @}*/
void set_time(time_t t)
Implementation of the C time.h functions.
int gettimeofday(struct timeval *tv, void *tz)
Standard lib retarget, get time since Epoch.
int settimeofday(const struct timeval *tv, const struct timezone *tz)
Standard lib retarget, set time since Epoch.
void attach_rtc(time_t(*read_rtc)(void), void(*write_rtc)(time_t), void(*init_rtc)(void), int(*isenabled_rtc)(void))
Attach an external RTC to be used for the C time functions.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.