The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
Anna Bridge
Date:
Fri Jun 22 15:38:59 2018 +0100
Revision:
169:a7c7b631e539
Parent:
165:d1b4690b3f8b
Child:
170:e95d10626187
mbed library. Release version 162

Who changed what in which revision?

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