The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
Anna Bridge
Date:
Fri Jun 22 15:38:59 2018 +0100
Revision:
169:a7c7b631e539
Parent:
158:1c57384330a6
Child:
171:3a7713b1edbc
mbed library. Release version 162

Who changed what in which revision?

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