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