1 |
|
---|
2 | /** \addtogroup platform */
|
---|
3 | /** @{*/
|
---|
4 | /* mbed Microcontroller Library
|
---|
5 | * Copyright (c) 2006-2013 ARM Limited
|
---|
6 | *
|
---|
7 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
8 | * you may not use this file except in compliance with the License.
|
---|
9 | * You may obtain a copy of the License at
|
---|
10 | *
|
---|
11 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
12 | *
|
---|
13 | * Unless required by applicable law or agreed to in writing, software
|
---|
14 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
16 | * See the License for the specific language governing permissions and
|
---|
17 | * limitations under the License.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #include <time.h>
|
---|
21 |
|
---|
22 | #ifdef __cplusplus
|
---|
23 | extern "C" {
|
---|
24 | #endif
|
---|
25 |
|
---|
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 |
|
---|
56 | /** Set the current time
|
---|
57 | *
|
---|
58 | * Initialises and sets the time of the microcontroller Real-Time Clock (RTC)
|
---|
59 | * to the time represented by the number of seconds since January 1, 1970
|
---|
60 | * (the UNIX timestamp).
|
---|
61 | *
|
---|
62 | * @param t Number of seconds since January 1, 1970 (the UNIX timestamp)
|
---|
63 | *
|
---|
64 | * @Note Synchronization level: Thread safe
|
---|
65 | *
|
---|
66 | * Example:
|
---|
67 | * @code
|
---|
68 | * #include "mbed.h"
|
---|
69 | *
|
---|
70 | * int main() {
|
---|
71 | * set_time(1256729737); // Set time to Wed, 28 Oct 2009 11:35:37
|
---|
72 | * }
|
---|
73 | * @endcode
|
---|
74 | */
|
---|
75 | void set_time(time_t t);
|
---|
76 |
|
---|
77 | /** Attach an external RTC to be used for the C time functions
|
---|
78 | *
|
---|
79 | * @Note Synchronization level: Thread safe
|
---|
80 | *
|
---|
81 | * @param read_rtc pointer to function which returns current UNIX timestamp
|
---|
82 | * @param write_rtc pointer to function which sets current UNIX timestamp, can be NULL
|
---|
83 | * @param init_rtc pointer to funtion which initializes RTC, can be NULL
|
---|
84 | * @param isenabled_rtc pointer to function wich returns if the rtc is enabled, can be NULL
|
---|
85 | */
|
---|
86 | void attach_rtc(time_t (*read_rtc)(void), void (*write_rtc)(time_t), void (*init_rtc)(void), int (*isenabled_rtc)(void));
|
---|
87 |
|
---|
88 | #ifdef __cplusplus
|
---|
89 | }
|
---|
90 | #endif
|
---|
91 |
|
---|
92 | /** @}*/
|
---|