test

Dependencies:   mbed Watchdog

Dependents:   STM32-MC_node

Committer:
ommpy
Date:
Wed Aug 26 14:26:27 2020 +0530
Revision:
11:32eeb052cda5
Parent:
0:d383e2dee0f7
added temp sensor in code

Who changed what in which revision?

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