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