Initial commit

Dependencies:   FastPWM

Committer:
lypinator
Date:
Wed Sep 16 01:11:49 2020 +0000
Revision:
0:bb348c97df44
Added PWM

Who changed what in which revision?

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