mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Thu Apr 19 17:12:19 2018 +0100
Revision:
184:08ed48f1de7f
Parent:
178:79309dc6340a
Child:
187:0387e8f68319
mbed-dev library. Release version 161

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 167:e84263d55307 1
AnnaBridge 167:e84263d55307 2 /** \addtogroup platform */
AnnaBridge 167:e84263d55307 3 /** @{*/
AnnaBridge 167:e84263d55307 4 /* mbed Microcontroller Library
AnnaBridge 167:e84263d55307 5 * Copyright (c) 2017-2017 ARM Limited
AnnaBridge 167:e84263d55307 6 *
AnnaBridge 167:e84263d55307 7 * Licensed under the Apache License, Version 2.0 (the "License");
AnnaBridge 167:e84263d55307 8 * you may not use this file except in compliance with the License.
AnnaBridge 167:e84263d55307 9 * You may obtain a copy of the License at
AnnaBridge 167:e84263d55307 10 *
AnnaBridge 167:e84263d55307 11 * http://www.apache.org/licenses/LICENSE-2.0
AnnaBridge 167:e84263d55307 12 *
AnnaBridge 167:e84263d55307 13 * Unless required by applicable law or agreed to in writing, software
AnnaBridge 167:e84263d55307 14 * distributed under the License is distributed on an "AS IS" BASIS,
AnnaBridge 167:e84263d55307 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
AnnaBridge 167:e84263d55307 16 * See the License for the specific language governing permissions and
AnnaBridge 167:e84263d55307 17 * limitations under the License.
AnnaBridge 167:e84263d55307 18 */
AnnaBridge 167:e84263d55307 19
AnnaBridge 167:e84263d55307 20 #ifndef MBED_MKTIME_H
AnnaBridge 167:e84263d55307 21 #define MBED_MKTIME_H
AnnaBridge 167:e84263d55307 22
AnnaBridge 167:e84263d55307 23 #include <time.h>
AnnaBridge 167:e84263d55307 24 #include <stdbool.h>
AnnaBridge 167:e84263d55307 25 #include <stdint.h>
AnnaBridge 167:e84263d55307 26
AnnaBridge 167:e84263d55307 27 #ifdef __cplusplus
AnnaBridge 167:e84263d55307 28 extern "C" {
AnnaBridge 167:e84263d55307 29 #endif
AnnaBridge 167:e84263d55307 30
AnnaBridge 178:79309dc6340a 31 /**
AnnaBridge 178:79309dc6340a 32 * \defgroup platform_mktime mktime functions
AnnaBridge 178:79309dc6340a 33 * @{
AnnaBridge 178:79309dc6340a 34 */
AnnaBridge 178:79309dc6340a 35
AnnaBridge 184:08ed48f1de7f 36 /* Time range across the whole 32-bit range should be supported which means that years in range 1970 - 2106 can be
AnnaBridge 184:08ed48f1de7f 37 * encoded. We have two types of RTC devices:
AnnaBridge 184:08ed48f1de7f 38 * a) RTCs which handles all leap years in the mentioned year range correctly. Leap year is determined by checking if
AnnaBridge 184:08ed48f1de7f 39 * the year counter value is divisible by 400, 100, and 4. No problem here.
AnnaBridge 184:08ed48f1de7f 40 * b) RTCs which handles leap years correctly up to 2100. The RTC does a simple bit comparison to see if the two
AnnaBridge 184:08ed48f1de7f 41 * lowest order bits of the year counter are zero. In this case 2100 year will be considered
AnnaBridge 184:08ed48f1de7f 42 * incorrectly as a leap year, so the last valid point in time will be 28.02.2100 23:59:59 and next day will be
AnnaBridge 184:08ed48f1de7f 43 * 29.02.2100 (invalid). So after 28.02.2100 the day counter will be off by a day.
AnnaBridge 184:08ed48f1de7f 44 */
AnnaBridge 184:08ed48f1de7f 45 typedef enum {
AnnaBridge 184:08ed48f1de7f 46 RTC_FULL_LEAP_YEAR_SUPPORT,
AnnaBridge 184:08ed48f1de7f 47 RTC_4_YEAR_LEAP_YEAR_SUPPORT
AnnaBridge 184:08ed48f1de7f 48 } rtc_leap_year_support_t;
AnnaBridge 184:08ed48f1de7f 49
AnnaBridge 167:e84263d55307 50 /** Compute if a year is a leap year or not.
AnnaBridge 167:e84263d55307 51 *
AnnaBridge 184:08ed48f1de7f 52 * @param year The year to test it shall be in the range [70:206]. Year 0 is
AnnaBridge 167:e84263d55307 53 * translated into year 1900 CE.
AnnaBridge 184:08ed48f1de7f 54 * @param leap_year_support use RTC_FULL_LEAP_YEAR_SUPPORT if RTC device is able
AnnaBridge 184:08ed48f1de7f 55 * to correctly detect all leap years in range [70:206] otherwise use RTC_4_YEAR_LEAP_YEAR_SUPPORT.
AnnaBridge 184:08ed48f1de7f 56 *
AnnaBridge 167:e84263d55307 57 * @return true if the year in input is a leap year and false otherwise.
AnnaBridge 184:08ed48f1de7f 58 *
AnnaBridge 184:08ed48f1de7f 59 * @note For use by the HAL only
AnnaBridge 184:08ed48f1de7f 60 * @note Year 2100 is treated differently for devices with full leap year support and devices with
AnnaBridge 184:08ed48f1de7f 61 * partial leap year support. Devices with partial leap year support treats 2100 as a leap year.
AnnaBridge 167:e84263d55307 62 */
AnnaBridge 184:08ed48f1de7f 63 bool _rtc_is_leap_year(int year, rtc_leap_year_support_t leap_year_support);
AnnaBridge 167:e84263d55307 64
AnnaBridge 167:e84263d55307 65 /* Convert a calendar time into time since UNIX epoch as a time_t.
AnnaBridge 167:e84263d55307 66 *
AnnaBridge 167:e84263d55307 67 * This function is a thread safe (partial) replacement for mktime. It is
AnnaBridge 167:e84263d55307 68 * tailored around RTC peripherals needs and is not by any mean a complete
AnnaBridge 167:e84263d55307 69 * replacement of mktime.
AnnaBridge 167:e84263d55307 70 *
AnnaBridge 184:08ed48f1de7f 71 * @param time The calendar time to convert into a time_t since epoch.
AnnaBridge 167:e84263d55307 72 * The fields from tm used for the computation are:
AnnaBridge 167:e84263d55307 73 * - tm_sec
AnnaBridge 167:e84263d55307 74 * - tm_min
AnnaBridge 167:e84263d55307 75 * - tm_hour
AnnaBridge 167:e84263d55307 76 * - tm_mday
AnnaBridge 167:e84263d55307 77 * - tm_mon
AnnaBridge 167:e84263d55307 78 * - tm_year
AnnaBridge 167:e84263d55307 79 * Other fields are ignored and won't be renormalized by a call to this function.
AnnaBridge 184:08ed48f1de7f 80 * A valid calendar time is comprised between:
AnnaBridge 184:08ed48f1de7f 81 * the 1st of January 1970 at 00:00:00 to the 7th of February 2106 at 06:28:15.
AnnaBridge 184:08ed48f1de7f 82 * @param leap_year_support use RTC_FULL_LEAP_YEAR_SUPPORT if RTC device is able
AnnaBridge 184:08ed48f1de7f 83 * to correctly detect all leap years in range [70:206] otherwise use RTC_4_YEAR_LEAP_YEAR_SUPPORT.
AnnaBridge 184:08ed48f1de7f 84 * @param seconds holder for the result - calendar time as seconds since UNIX epoch.
AnnaBridge 167:e84263d55307 85 *
AnnaBridge 184:08ed48f1de7f 86 * @return true on success, false if conversion error occurred.
AnnaBridge 167:e84263d55307 87 *
AnnaBridge 167:e84263d55307 88 * @note Leap seconds are not supported.
AnnaBridge 184:08ed48f1de7f 89 * @note Values in output range from 0 to UINT_MAX.
AnnaBridge 184:08ed48f1de7f 90 * @note Full and partial leap years support.
AnnaBridge 184:08ed48f1de7f 91 * @note For use by the HAL only
AnnaBridge 167:e84263d55307 92 */
AnnaBridge 184:08ed48f1de7f 93 bool _rtc_maketime(const struct tm* time, time_t * seconds, rtc_leap_year_support_t leap_year_support);
AnnaBridge 167:e84263d55307 94
AnnaBridge 167:e84263d55307 95 /* Convert a given time in seconds since epoch into calendar time.
AnnaBridge 167:e84263d55307 96 *
AnnaBridge 167:e84263d55307 97 * This function is a thread safe (partial) replacement for localtime. It is
AnnaBridge 167:e84263d55307 98 * tailored around RTC peripherals specification and is not by any means a
AnnaBridge 167:e84263d55307 99 * complete of localtime.
AnnaBridge 167:e84263d55307 100 *
AnnaBridge 167:e84263d55307 101 * @param timestamp The time (in seconds) to convert into calendar time. Valid
AnnaBridge 184:08ed48f1de7f 102 * input are in the range [0 : UINT32_MAX].
AnnaBridge 167:e84263d55307 103 * @param calendar_time Pointer to the object which will contain the result of
AnnaBridge 167:e84263d55307 104 * the conversion. The tm fields filled by this function are:
AnnaBridge 167:e84263d55307 105 * - tm_sec
AnnaBridge 167:e84263d55307 106 * - tm_min
AnnaBridge 167:e84263d55307 107 * - tm_hour
AnnaBridge 167:e84263d55307 108 * - tm_mday
AnnaBridge 167:e84263d55307 109 * - tm_mon
AnnaBridge 167:e84263d55307 110 * - tm_year
AnnaBridge 167:e84263d55307 111 * - tm_wday
AnnaBridge 167:e84263d55307 112 * - tm_yday
AnnaBridge 167:e84263d55307 113 * The object remains untouched if the time in input is invalid.
AnnaBridge 184:08ed48f1de7f 114 * @param leap_year_support use RTC_FULL_LEAP_YEAR_SUPPORT if RTC device is able
AnnaBridge 184:08ed48f1de7f 115 * to correctly detect all leap years in range [70:206] otherwise use RTC_4_YEAR_LEAP_YEAR_SUPPORT.
AnnaBridge 167:e84263d55307 116 * @return true if the conversion was successful, false otherwise.
AnnaBridge 167:e84263d55307 117 *
AnnaBridge 184:08ed48f1de7f 118 * @note For use by the HAL only.
AnnaBridge 184:08ed48f1de7f 119 * @note Full and partial leap years support.
AnnaBridge 167:e84263d55307 120 */
AnnaBridge 184:08ed48f1de7f 121 bool _rtc_localtime(time_t timestamp, struct tm* time_info, rtc_leap_year_support_t leap_year_support);
AnnaBridge 167:e84263d55307 122
AnnaBridge 178:79309dc6340a 123 /** @}*/
AnnaBridge 178:79309dc6340a 124
AnnaBridge 167:e84263d55307 125 #ifdef __cplusplus
AnnaBridge 167:e84263d55307 126 }
AnnaBridge 167:e84263d55307 127 #endif
AnnaBridge 167:e84263d55307 128
AnnaBridge 167:e84263d55307 129 #endif /* MBED_MKTIME_H */
AnnaBridge 167:e84263d55307 130
AnnaBridge 167:e84263d55307 131 /** @}*/