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