inport from local
Dependents: Hobbyking_Cheetah_0511
platform/mbed_mktime.h@0:85b3fd62ea1a, 2020-03-16 (annotated)
- Committer:
- NYX
- Date:
- Mon Mar 16 06:35:48 2020 +0000
- Revision:
- 0:85b3fd62ea1a
reinport to mbed;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
NYX | 0:85b3fd62ea1a | 1 | |
NYX | 0:85b3fd62ea1a | 2 | /** \addtogroup platform */ |
NYX | 0:85b3fd62ea1a | 3 | /** @{*/ |
NYX | 0:85b3fd62ea1a | 4 | /* mbed Microcontroller Library |
NYX | 0:85b3fd62ea1a | 5 | * Copyright (c) 2017-2017 ARM Limited |
NYX | 0:85b3fd62ea1a | 6 | * |
NYX | 0:85b3fd62ea1a | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
NYX | 0:85b3fd62ea1a | 8 | * you may not use this file except in compliance with the License. |
NYX | 0:85b3fd62ea1a | 9 | * You may obtain a copy of the License at |
NYX | 0:85b3fd62ea1a | 10 | * |
NYX | 0:85b3fd62ea1a | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
NYX | 0:85b3fd62ea1a | 12 | * |
NYX | 0:85b3fd62ea1a | 13 | * Unless required by applicable law or agreed to in writing, software |
NYX | 0:85b3fd62ea1a | 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
NYX | 0:85b3fd62ea1a | 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
NYX | 0:85b3fd62ea1a | 16 | * See the License for the specific language governing permissions and |
NYX | 0:85b3fd62ea1a | 17 | * limitations under the License. |
NYX | 0:85b3fd62ea1a | 18 | */ |
NYX | 0:85b3fd62ea1a | 19 | |
NYX | 0:85b3fd62ea1a | 20 | #ifndef MBED_MKTIME_H |
NYX | 0:85b3fd62ea1a | 21 | #define MBED_MKTIME_H |
NYX | 0:85b3fd62ea1a | 22 | |
NYX | 0:85b3fd62ea1a | 23 | #include <time.h> |
NYX | 0:85b3fd62ea1a | 24 | #include <stdbool.h> |
NYX | 0:85b3fd62ea1a | 25 | #include <stdint.h> |
NYX | 0:85b3fd62ea1a | 26 | |
NYX | 0:85b3fd62ea1a | 27 | #ifdef __cplusplus |
NYX | 0:85b3fd62ea1a | 28 | extern "C" { |
NYX | 0:85b3fd62ea1a | 29 | #endif |
NYX | 0:85b3fd62ea1a | 30 | |
NYX | 0:85b3fd62ea1a | 31 | /** Compute if a year is a leap year or not. |
NYX | 0:85b3fd62ea1a | 32 | * |
NYX | 0:85b3fd62ea1a | 33 | * @param year The year to test it shall be in the range [70:138]. Year 0 is |
NYX | 0:85b3fd62ea1a | 34 | * translated into year 1900 CE. |
NYX | 0:85b3fd62ea1a | 35 | * @return true if the year in input is a leap year and false otherwise. |
NYX | 0:85b3fd62ea1a | 36 | * @note - For use by the HAL only |
NYX | 0:85b3fd62ea1a | 37 | */ |
NYX | 0:85b3fd62ea1a | 38 | bool _rtc_is_leap_year(int year); |
NYX | 0:85b3fd62ea1a | 39 | |
NYX | 0:85b3fd62ea1a | 40 | /* Convert a calendar time into time since UNIX epoch as a time_t. |
NYX | 0:85b3fd62ea1a | 41 | * |
NYX | 0:85b3fd62ea1a | 42 | * This function is a thread safe (partial) replacement for mktime. It is |
NYX | 0:85b3fd62ea1a | 43 | * tailored around RTC peripherals needs and is not by any mean a complete |
NYX | 0:85b3fd62ea1a | 44 | * replacement of mktime. |
NYX | 0:85b3fd62ea1a | 45 | * |
NYX | 0:85b3fd62ea1a | 46 | * @param calendar_time The calendar time to convert into a time_t since epoch. |
NYX | 0:85b3fd62ea1a | 47 | * The fields from tm used for the computation are: |
NYX | 0:85b3fd62ea1a | 48 | * - tm_sec |
NYX | 0:85b3fd62ea1a | 49 | * - tm_min |
NYX | 0:85b3fd62ea1a | 50 | * - tm_hour |
NYX | 0:85b3fd62ea1a | 51 | * - tm_mday |
NYX | 0:85b3fd62ea1a | 52 | * - tm_mon |
NYX | 0:85b3fd62ea1a | 53 | * - tm_year |
NYX | 0:85b3fd62ea1a | 54 | * Other fields are ignored and won't be renormalized by a call to this function. |
NYX | 0:85b3fd62ea1a | 55 | * A valid calendar time is comprised between the 1st january of 1970 at |
NYX | 0:85b3fd62ea1a | 56 | * 00:00:00 and the 19th of january 2038 at 03:14:07. |
NYX | 0:85b3fd62ea1a | 57 | * |
NYX | 0:85b3fd62ea1a | 58 | * @return The calendar time as seconds since UNIX epoch if the input is in the |
NYX | 0:85b3fd62ea1a | 59 | * valid range. Otherwise ((time_t) -1). |
NYX | 0:85b3fd62ea1a | 60 | * |
NYX | 0:85b3fd62ea1a | 61 | * @note Leap seconds are not supported. |
NYX | 0:85b3fd62ea1a | 62 | * @note Values in output range from 0 to INT_MAX. |
NYX | 0:85b3fd62ea1a | 63 | * @note - For use by the HAL only |
NYX | 0:85b3fd62ea1a | 64 | */ |
NYX | 0:85b3fd62ea1a | 65 | time_t _rtc_mktime(const struct tm* calendar_time); |
NYX | 0:85b3fd62ea1a | 66 | |
NYX | 0:85b3fd62ea1a | 67 | /* Convert a given time in seconds since epoch into calendar time. |
NYX | 0:85b3fd62ea1a | 68 | * |
NYX | 0:85b3fd62ea1a | 69 | * This function is a thread safe (partial) replacement for localtime. It is |
NYX | 0:85b3fd62ea1a | 70 | * tailored around RTC peripherals specification and is not by any means a |
NYX | 0:85b3fd62ea1a | 71 | * complete of localtime. |
NYX | 0:85b3fd62ea1a | 72 | * |
NYX | 0:85b3fd62ea1a | 73 | * @param timestamp The time (in seconds) to convert into calendar time. Valid |
NYX | 0:85b3fd62ea1a | 74 | * input are in the range [0 : INT32_MAX]. |
NYX | 0:85b3fd62ea1a | 75 | * @param calendar_time Pointer to the object which will contain the result of |
NYX | 0:85b3fd62ea1a | 76 | * the conversion. The tm fields filled by this function are: |
NYX | 0:85b3fd62ea1a | 77 | * - tm_sec |
NYX | 0:85b3fd62ea1a | 78 | * - tm_min |
NYX | 0:85b3fd62ea1a | 79 | * - tm_hour |
NYX | 0:85b3fd62ea1a | 80 | * - tm_mday |
NYX | 0:85b3fd62ea1a | 81 | * - tm_mon |
NYX | 0:85b3fd62ea1a | 82 | * - tm_year |
NYX | 0:85b3fd62ea1a | 83 | * - tm_wday |
NYX | 0:85b3fd62ea1a | 84 | * - tm_yday |
NYX | 0:85b3fd62ea1a | 85 | * The object remains untouched if the time in input is invalid. |
NYX | 0:85b3fd62ea1a | 86 | * @return true if the conversion was successful, false otherwise. |
NYX | 0:85b3fd62ea1a | 87 | * |
NYX | 0:85b3fd62ea1a | 88 | * @note - For use by the HAL only |
NYX | 0:85b3fd62ea1a | 89 | */ |
NYX | 0:85b3fd62ea1a | 90 | bool _rtc_localtime(time_t timestamp, struct tm* calendar_time); |
NYX | 0:85b3fd62ea1a | 91 | |
NYX | 0:85b3fd62ea1a | 92 | #ifdef __cplusplus |
NYX | 0:85b3fd62ea1a | 93 | } |
NYX | 0:85b3fd62ea1a | 94 | #endif |
NYX | 0:85b3fd62ea1a | 95 | |
NYX | 0:85b3fd62ea1a | 96 | #endif /* MBED_MKTIME_H */ |
NYX | 0:85b3fd62ea1a | 97 | |
NYX | 0:85b3fd62ea1a | 98 | /** @}*/ |