SPKT

Dependents:   WAV

Committer:
phungductung
Date:
Tue Jun 04 21:51:46 2019 +0000
Revision:
0:e87aa4c49e95
libray

Who changed what in which revision?

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