mbed-dev-f303

Committer:
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4
Date:
Tue Jun 14 09:21:18 2022 +0000
Revision:
0:bdf663c61a82
lib

Who changed what in which revision?

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