Gan likun / mbed-dev11
Committer:
ganlikun
Date:
Mon Oct 24 15:19:39 2022 +0000
Revision:
0:06036f8bee2d
11

Who changed what in which revision?

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