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