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