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