Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: STM32F031_Blink_Aug17
Fork of mbed-STM32F030F4 by
api/rtc_time.h@0:38ccae254a29, 2014-10-18 (annotated)
- Committer:
- mega64
- Date:
- Sat Oct 18 02:40:17 2014 +0000
- Revision:
- 0:38ccae254a29
only for STM32F030F4
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mega64 | 0:38ccae254a29 | 1 | /* mbed Microcontroller Library |
| mega64 | 0:38ccae254a29 | 2 | * Copyright (c) 2006-2013 ARM Limited |
| mega64 | 0:38ccae254a29 | 3 | * |
| mega64 | 0:38ccae254a29 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| mega64 | 0:38ccae254a29 | 5 | * you may not use this file except in compliance with the License. |
| mega64 | 0:38ccae254a29 | 6 | * You may obtain a copy of the License at |
| mega64 | 0:38ccae254a29 | 7 | * |
| mega64 | 0:38ccae254a29 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| mega64 | 0:38ccae254a29 | 9 | * |
| mega64 | 0:38ccae254a29 | 10 | * Unless required by applicable law or agreed to in writing, software |
| mega64 | 0:38ccae254a29 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| mega64 | 0:38ccae254a29 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| mega64 | 0:38ccae254a29 | 13 | * See the License for the specific language governing permissions and |
| mega64 | 0:38ccae254a29 | 14 | * limitations under the License. |
| mega64 | 0:38ccae254a29 | 15 | */ |
| mega64 | 0:38ccae254a29 | 16 | |
| mega64 | 0:38ccae254a29 | 17 | #include <time.h> |
| mega64 | 0:38ccae254a29 | 18 | |
| mega64 | 0:38ccae254a29 | 19 | #ifdef __cplusplus |
| mega64 | 0:38ccae254a29 | 20 | extern "C" { |
| mega64 | 0:38ccae254a29 | 21 | #endif |
| mega64 | 0:38ccae254a29 | 22 | |
| mega64 | 0:38ccae254a29 | 23 | /** Implementation of the C time.h functions |
| mega64 | 0:38ccae254a29 | 24 | * |
| mega64 | 0:38ccae254a29 | 25 | * Provides mechanisms to set and read the current time, based |
| mega64 | 0:38ccae254a29 | 26 | * on the microcontroller Real-Time Clock (RTC), plus some |
| mega64 | 0:38ccae254a29 | 27 | * standard C manipulation and formating functions. |
| mega64 | 0:38ccae254a29 | 28 | * |
| mega64 | 0:38ccae254a29 | 29 | * Example: |
| mega64 | 0:38ccae254a29 | 30 | * @code |
| mega64 | 0:38ccae254a29 | 31 | * #include "mbed.h" |
| mega64 | 0:38ccae254a29 | 32 | * |
| mega64 | 0:38ccae254a29 | 33 | * int main() { |
| mega64 | 0:38ccae254a29 | 34 | * set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37 |
| mega64 | 0:38ccae254a29 | 35 | * |
| mega64 | 0:38ccae254a29 | 36 | * while(1) { |
| mega64 | 0:38ccae254a29 | 37 | * time_t seconds = time(NULL); |
| mega64 | 0:38ccae254a29 | 38 | * |
| mega64 | 0:38ccae254a29 | 39 | * printf("Time as seconds since January 1, 1970 = %d\n", seconds); |
| mega64 | 0:38ccae254a29 | 40 | * |
| mega64 | 0:38ccae254a29 | 41 | * printf("Time as a basic string = %s", ctime(&seconds)); |
| mega64 | 0:38ccae254a29 | 42 | * |
| mega64 | 0:38ccae254a29 | 43 | * char buffer[32]; |
| mega64 | 0:38ccae254a29 | 44 | * strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds)); |
| mega64 | 0:38ccae254a29 | 45 | * printf("Time as a custom formatted string = %s", buffer); |
| mega64 | 0:38ccae254a29 | 46 | * |
| mega64 | 0:38ccae254a29 | 47 | * wait(1); |
| mega64 | 0:38ccae254a29 | 48 | * } |
| mega64 | 0:38ccae254a29 | 49 | * } |
| mega64 | 0:38ccae254a29 | 50 | * @endcode |
| mega64 | 0:38ccae254a29 | 51 | */ |
| mega64 | 0:38ccae254a29 | 52 | |
| mega64 | 0:38ccae254a29 | 53 | /** Set the current time |
| mega64 | 0:38ccae254a29 | 54 | * |
| mega64 | 0:38ccae254a29 | 55 | * Initialises and sets the time of the microcontroller Real-Time Clock (RTC) |
| mega64 | 0:38ccae254a29 | 56 | * to the time represented by the number of seconds since January 1, 1970 |
| mega64 | 0:38ccae254a29 | 57 | * (the UNIX timestamp). |
| mega64 | 0:38ccae254a29 | 58 | * |
| mega64 | 0:38ccae254a29 | 59 | * @param t Number of seconds since January 1, 1970 (the UNIX timestamp) |
| mega64 | 0:38ccae254a29 | 60 | * |
| mega64 | 0:38ccae254a29 | 61 | * Example: |
| mega64 | 0:38ccae254a29 | 62 | * @code |
| mega64 | 0:38ccae254a29 | 63 | * #include "mbed.h" |
| mega64 | 0:38ccae254a29 | 64 | * |
| mega64 | 0:38ccae254a29 | 65 | * int main() { |
| mega64 | 0:38ccae254a29 | 66 | * set_time(1256729737); // Set time to Wed, 28 Oct 2009 11:35:37 |
| mega64 | 0:38ccae254a29 | 67 | * } |
| mega64 | 0:38ccae254a29 | 68 | * @endcode |
| mega64 | 0:38ccae254a29 | 69 | */ |
| mega64 | 0:38ccae254a29 | 70 | void set_time(time_t t); |
| mega64 | 0:38ccae254a29 | 71 | |
| mega64 | 0:38ccae254a29 | 72 | #ifdef __cplusplus |
| mega64 | 0:38ccae254a29 | 73 | } |
| mega64 | 0:38ccae254a29 | 74 | #endif |
