mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
platform/mbed_rtc_time.h@181:57724642e740, 2018-02-16 (annotated)
- Committer:
- AnnaBridge
- Date:
- Fri Feb 16 16:09:33 2018 +0000
- Revision:
- 181:57724642e740
- Parent:
- 178:79309dc6340a
- Child:
- 188:bcfe06ba3d64
mbed-dev library. Release version 159.
Who changed what in which revision?
User | Revision | Line number | New 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 |
<> | 160:d5399cc887bb | 10 | * |
<> | 160:d5399cc887bb | 11 | * Licensed under the Apache License, Version 2.0 (the "License"); |
<> | 160:d5399cc887bb | 12 | * you may not use this file except in compliance with the License. |
<> | 160:d5399cc887bb | 13 | * You may obtain a copy of the License at |
<> | 160:d5399cc887bb | 14 | * |
<> | 160:d5399cc887bb | 15 | * http://www.apache.org/licenses/LICENSE-2.0 |
<> | 160:d5399cc887bb | 16 | * |
<> | 160:d5399cc887bb | 17 | * Unless required by applicable law or agreed to in writing, software |
<> | 160:d5399cc887bb | 18 | * distributed under the License is distributed on an "AS IS" BASIS, |
<> | 160:d5399cc887bb | 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
<> | 160:d5399cc887bb | 20 | * See the License for the specific language governing permissions and |
<> | 160:d5399cc887bb | 21 | * limitations under the License. |
<> | 160:d5399cc887bb | 22 | */ |
<> | 160:d5399cc887bb | 23 | |
<> | 160:d5399cc887bb | 24 | #include <time.h> |
<> | 160:d5399cc887bb | 25 | |
<> | 160:d5399cc887bb | 26 | #ifdef __cplusplus |
<> | 160:d5399cc887bb | 27 | extern "C" { |
<> | 160:d5399cc887bb | 28 | #endif |
<> | 160:d5399cc887bb | 29 | |
<> | 160:d5399cc887bb | 30 | /** Implementation of the C time.h functions |
<> | 160:d5399cc887bb | 31 | * |
<> | 160:d5399cc887bb | 32 | * Provides mechanisms to set and read the current time, based |
<> | 160:d5399cc887bb | 33 | * on the microcontroller Real-Time Clock (RTC), plus some |
<> | 160:d5399cc887bb | 34 | * standard C manipulation and formating functions. |
<> | 160:d5399cc887bb | 35 | * |
<> | 160:d5399cc887bb | 36 | * Example: |
<> | 160:d5399cc887bb | 37 | * @code |
<> | 160:d5399cc887bb | 38 | * #include "mbed.h" |
<> | 160:d5399cc887bb | 39 | * |
<> | 160:d5399cc887bb | 40 | * int main() { |
<> | 160:d5399cc887bb | 41 | * set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37 |
<> | 160:d5399cc887bb | 42 | * |
<> | 160:d5399cc887bb | 43 | * while(1) { |
<> | 160:d5399cc887bb | 44 | * time_t seconds = time(NULL); |
<> | 160:d5399cc887bb | 45 | * |
<> | 160:d5399cc887bb | 46 | * printf("Time as seconds since January 1, 1970 = %d\n", seconds); |
<> | 160:d5399cc887bb | 47 | * |
<> | 160:d5399cc887bb | 48 | * printf("Time as a basic string = %s", ctime(&seconds)); |
<> | 160:d5399cc887bb | 49 | * |
<> | 160:d5399cc887bb | 50 | * char buffer[32]; |
<> | 160:d5399cc887bb | 51 | * strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds)); |
<> | 160:d5399cc887bb | 52 | * printf("Time as a custom formatted string = %s", buffer); |
<> | 160:d5399cc887bb | 53 | * |
<> | 160:d5399cc887bb | 54 | * wait(1); |
<> | 160:d5399cc887bb | 55 | * } |
<> | 160:d5399cc887bb | 56 | * } |
<> | 160:d5399cc887bb | 57 | * @endcode |
<> | 160:d5399cc887bb | 58 | */ |
<> | 160:d5399cc887bb | 59 | |
<> | 160:d5399cc887bb | 60 | /** Set the current time |
<> | 160:d5399cc887bb | 61 | * |
<> | 160:d5399cc887bb | 62 | * Initialises and sets the time of the microcontroller Real-Time Clock (RTC) |
<> | 160:d5399cc887bb | 63 | * to the time represented by the number of seconds since January 1, 1970 |
<> | 160:d5399cc887bb | 64 | * (the UNIX timestamp). |
<> | 160:d5399cc887bb | 65 | * |
<> | 160:d5399cc887bb | 66 | * @param t Number of seconds since January 1, 1970 (the UNIX timestamp) |
<> | 160:d5399cc887bb | 67 | * |
AnnaBridge | 167:e84263d55307 | 68 | * @note Synchronization level: Thread safe |
<> | 160:d5399cc887bb | 69 | * |
<> | 160:d5399cc887bb | 70 | * Example: |
<> | 160:d5399cc887bb | 71 | * @code |
<> | 160:d5399cc887bb | 72 | * #include "mbed.h" |
<> | 160:d5399cc887bb | 73 | * |
<> | 160:d5399cc887bb | 74 | * int main() { |
<> | 160:d5399cc887bb | 75 | * set_time(1256729737); // Set time to Wed, 28 Oct 2009 11:35:37 |
<> | 160:d5399cc887bb | 76 | * } |
<> | 160:d5399cc887bb | 77 | * @endcode |
<> | 160:d5399cc887bb | 78 | */ |
<> | 160:d5399cc887bb | 79 | void set_time(time_t t); |
<> | 160:d5399cc887bb | 80 | |
<> | 160:d5399cc887bb | 81 | /** Attach an external RTC to be used for the C time functions |
<> | 160:d5399cc887bb | 82 | * |
AnnaBridge | 167:e84263d55307 | 83 | * @note Synchronization level: Thread safe |
<> | 160:d5399cc887bb | 84 | * |
<> | 160:d5399cc887bb | 85 | * @param read_rtc pointer to function which returns current UNIX timestamp |
<> | 160:d5399cc887bb | 86 | * @param write_rtc pointer to function which sets current UNIX timestamp, can be NULL |
<> | 160:d5399cc887bb | 87 | * @param init_rtc pointer to funtion which initializes RTC, can be NULL |
<> | 160:d5399cc887bb | 88 | * @param isenabled_rtc pointer to function wich returns if the rtc is enabled, can be NULL |
<> | 160:d5399cc887bb | 89 | */ |
<> | 160:d5399cc887bb | 90 | void attach_rtc(time_t (*read_rtc)(void), void (*write_rtc)(time_t), void (*init_rtc)(void), int (*isenabled_rtc)(void)); |
<> | 160:d5399cc887bb | 91 | |
<> | 160:d5399cc887bb | 92 | #ifdef __cplusplus |
<> | 160:d5399cc887bb | 93 | } |
<> | 160:d5399cc887bb | 94 | #endif |
<> | 160:d5399cc887bb | 95 | |
<> | 160:d5399cc887bb | 96 | /** @}*/ |
AnnaBridge | 178:79309dc6340a | 97 | /** @}*/ |