mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
mbed_mktime.h
00001 00002 /** \addtogroup platform */ 00003 /** @{*/ 00004 /* mbed Microcontroller Library 00005 * Copyright (c) 2017-2017 ARM Limited 00006 * SPDX-License-Identifier: Apache-2.0 00007 * 00008 * Licensed under the Apache License, Version 2.0 (the "License"); 00009 * you may not use this file except in compliance with the License. 00010 * You may obtain a copy of the License at 00011 * 00012 * http://www.apache.org/licenses/LICENSE-2.0 00013 * 00014 * Unless required by applicable law or agreed to in writing, software 00015 * distributed under the License is distributed on an "AS IS" BASIS, 00016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00017 * See the License for the specific language governing permissions and 00018 * limitations under the License. 00019 */ 00020 00021 #ifndef MBED_MKTIME_H 00022 #define MBED_MKTIME_H 00023 00024 #include <time.h> 00025 #include <stdbool.h> 00026 #include <stdint.h> 00027 00028 #ifdef __cplusplus 00029 extern "C" { 00030 #endif 00031 00032 /** 00033 * \defgroup platform_mktime mktime functions 00034 * @{ 00035 */ 00036 00037 /* Time range across the whole 32-bit range should be supported which means that years in range 1970 - 2106 can be 00038 * encoded. We have two types of RTC devices: 00039 * a) RTCs which handles all leap years in the mentioned year range correctly. Leap year is determined by checking if 00040 * the year counter value is divisible by 400, 100, and 4. No problem here. 00041 * b) RTCs which handles leap years correctly up to 2100. The RTC does a simple bit comparison to see if the two 00042 * lowest order bits of the year counter are zero. In this case 2100 year will be considered 00043 * 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 00044 * 29.02.2100 (invalid). So after 28.02.2100 the day counter will be off by a day. 00045 */ 00046 typedef enum { 00047 RTC_FULL_LEAP_YEAR_SUPPORT, 00048 RTC_4_YEAR_LEAP_YEAR_SUPPORT 00049 } rtc_leap_year_support_t; 00050 00051 /** Compute if a year is a leap year or not. 00052 * 00053 * @param year The year to test it shall be in the range [70:206]. Year 0 is 00054 * translated into year 1900 CE. 00055 * @param leap_year_support use RTC_FULL_LEAP_YEAR_SUPPORT if RTC device is able 00056 * to correctly detect all leap years in range [70:206] otherwise use RTC_4_YEAR_LEAP_YEAR_SUPPORT. 00057 * 00058 * @return true if the year in input is a leap year and false otherwise. 00059 * 00060 * @note For use by the HAL only 00061 * @note Year 2100 is treated differently for devices with full leap year support and devices with 00062 * partial leap year support. Devices with partial leap year support treats 2100 as a leap year. 00063 */ 00064 bool _rtc_is_leap_year(int year, rtc_leap_year_support_t leap_year_support); 00065 00066 /* Convert a calendar time into time since UNIX epoch as a time_t. 00067 * 00068 * This function is a thread safe (partial) replacement for mktime. It is 00069 * tailored around RTC peripherals needs and is not by any mean a complete 00070 * replacement of mktime. 00071 * 00072 * @param time The calendar time to convert into a time_t since epoch. 00073 * The fields from tm used for the computation are: 00074 * - tm_sec 00075 * - tm_min 00076 * - tm_hour 00077 * - tm_mday 00078 * - tm_mon 00079 * - tm_year 00080 * Other fields are ignored and won't be renormalized by a call to this function. 00081 * A valid calendar time is comprised between: 00082 * the 1st of January 1970 at 00:00:00 to the 7th of February 2106 at 06:28:15. 00083 * @param leap_year_support use RTC_FULL_LEAP_YEAR_SUPPORT if RTC device is able 00084 * to correctly detect all leap years in range [70:206] otherwise use RTC_4_YEAR_LEAP_YEAR_SUPPORT. 00085 * @param seconds holder for the result - calendar time as seconds since UNIX epoch. 00086 * 00087 * @return true on success, false if conversion error occurred. 00088 * 00089 * @note Leap seconds are not supported. 00090 * @note Values in output range from 0 to UINT_MAX. 00091 * @note Full and partial leap years support. 00092 * @note For use by the HAL only 00093 */ 00094 bool _rtc_maketime(const struct tm *time, time_t *seconds, rtc_leap_year_support_t leap_year_support); 00095 00096 /* Convert a given time in seconds since epoch into calendar time. 00097 * 00098 * This function is a thread safe (partial) replacement for localtime. It is 00099 * tailored around RTC peripherals specification and is not by any means a 00100 * complete of localtime. 00101 * 00102 * @param timestamp The time (in seconds) to convert into calendar time. Valid 00103 * input are in the range [0 : UINT32_MAX]. 00104 * @param calendar_time Pointer to the object which will contain the result of 00105 * the conversion. The tm fields filled by this function are: 00106 * - tm_sec 00107 * - tm_min 00108 * - tm_hour 00109 * - tm_mday 00110 * - tm_mon 00111 * - tm_year 00112 * - tm_wday 00113 * - tm_yday 00114 * The object remains untouched if the time in input is invalid. 00115 * @param leap_year_support use RTC_FULL_LEAP_YEAR_SUPPORT if RTC device is able 00116 * to correctly detect all leap years in range [70:206] otherwise use RTC_4_YEAR_LEAP_YEAR_SUPPORT. 00117 * @return true if the conversion was successful, false otherwise. 00118 * 00119 * @note For use by the HAL only. 00120 * @note Full and partial leap years support. 00121 */ 00122 bool _rtc_localtime(time_t timestamp, struct tm *time_info, rtc_leap_year_support_t leap_year_support); 00123 00124 /** @}*/ 00125 00126 #ifdef __cplusplus 00127 } 00128 #endif 00129 00130 #endif /* MBED_MKTIME_H */ 00131 00132 /** @}*/
Generated on Tue Jul 12 2022 20:41:15 by 1.7.2