RTC auf true

Committer:
kevman
Date:
Wed Mar 13 11:03:24 2019 +0000
Revision:
2:7aab896b1a3b
Parent:
0:38ceb79fef03
2019-03-13

Who changed what in which revision?

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