mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
Parent:
188:bcfe06ba3d64
mbed library release version 165

Who changed what in which revision?

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