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