00

Committer:
ganlikun
Date:
Sun Jun 12 14:02:44 2022 +0000
Revision:
0:13413ea9a877
00

Who changed what in which revision?

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