mbed library sources. Supersedes mbed-src.

Fork of mbed by teralytic

Committer:
rodriguise
Date:
Mon Oct 17 18:47:01 2016 +0000
Revision:
148:4802eb17e82b
Parent:
144:ef7eb2e8f9f7
backup

Who changed what in which revision?

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