Backup 1

Committer:
borlanic
Date:
Tue Apr 24 11:45:18 2018 +0000
Revision:
0:02dd72d1d465
BaBoRo_test2 - backup 1

Who changed what in which revision?

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