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