BA / SerialCom

Fork of OmniWheels by Gustav Atmel

Committer:
gustavatmel
Date:
Tue May 01 15:55:34 2018 +0000
Revision:
2:798925c9e4a8
Parent:
1:9c5af431a1f1
bluetooth

Who changed what in which revision?

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