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