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