Rtos API example

Committer:
marcozecchini
Date:
Sat Feb 23 12:13:36 2019 +0000
Revision:
0:9fca2b23d0ba
final commit

Who changed what in which revision?

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