test

Dependencies:   mbed Watchdog

Dependents:   STM32-MC_node

Committer:
ommpy
Date:
Mon Jul 06 17:18:59 2020 +0530
Revision:
0:d383e2dee0f7
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ommpy 0:d383e2dee0f7 1 /* mbed Microcontroller Library
ommpy 0:d383e2dee0f7 2 * Copyright (c) 2006-2013 ARM Limited
ommpy 0:d383e2dee0f7 3 * SPDX-License-Identifier: Apache-2.0
ommpy 0:d383e2dee0f7 4 *
ommpy 0:d383e2dee0f7 5 * Licensed under the Apache License, Version 2.0 (the "License");
ommpy 0:d383e2dee0f7 6 * you may not use this file except in compliance with the License.
ommpy 0:d383e2dee0f7 7 * You may obtain a copy of the License at
ommpy 0:d383e2dee0f7 8 *
ommpy 0:d383e2dee0f7 9 * http://www.apache.org/licenses/LICENSE-2.0
ommpy 0:d383e2dee0f7 10 *
ommpy 0:d383e2dee0f7 11 * Unless required by applicable law or agreed to in writing, software
ommpy 0:d383e2dee0f7 12 * distributed under the License is distributed on an "AS IS" BASIS,
ommpy 0:d383e2dee0f7 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ommpy 0:d383e2dee0f7 14 * See the License for the specific language governing permissions and
ommpy 0:d383e2dee0f7 15 * limitations under the License.
ommpy 0:d383e2dee0f7 16 */
ommpy 0:d383e2dee0f7 17
ommpy 0:d383e2dee0f7 18 /** \addtogroup hal */
ommpy 0:d383e2dee0f7 19 /** @{*/
ommpy 0:d383e2dee0f7 20
ommpy 0:d383e2dee0f7 21 #ifndef MBED_RTC_API_H
ommpy 0:d383e2dee0f7 22 #define MBED_RTC_API_H
ommpy 0:d383e2dee0f7 23
ommpy 0:d383e2dee0f7 24 #include "device.h"
ommpy 0:d383e2dee0f7 25
ommpy 0:d383e2dee0f7 26 #include <time.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 hal_rtc RTC hal
ommpy 0:d383e2dee0f7 34 *
ommpy 0:d383e2dee0f7 35 * The RTC hal provides a low level interface to the Real Time Counter (RTC) of a
ommpy 0:d383e2dee0f7 36 * target.
ommpy 0:d383e2dee0f7 37 *
ommpy 0:d383e2dee0f7 38 * # Defined behaviour
ommpy 0:d383e2dee0f7 39 * * The function ::rtc_init is safe to call repeatedly - Verified by test ::rtc_init_test.
ommpy 0:d383e2dee0f7 40 * * RTC accuracy is at least 10% - Verified by test ::rtc_accuracy_test.
ommpy 0:d383e2dee0f7 41 * * Init/free doesn't stop RTC from counting - Verified by test ::rtc_persist_test.
ommpy 0:d383e2dee0f7 42 * * Software reset doesn't stop RTC from counting - Verified by test ::rtc_reset_test.
ommpy 0:d383e2dee0f7 43 * * Sleep modes don't stop RTC from counting - Verified by test ::rtc_sleep_test.
ommpy 0:d383e2dee0f7 44 * * Shutdown mode doesn't stop RTC from counting - Not verified.
ommpy 0:d383e2dee0f7 45 * * The functions ::rtc_write/::rtc_read provides availability to set/get RTC time
ommpy 0:d383e2dee0f7 46 * - Verified by test ::rtc_write_read_test.
ommpy 0:d383e2dee0f7 47 * * The functions ::rtc_isenabled returns 1 if the RTC is counting and the time has been set,
ommpy 0:d383e2dee0f7 48 * 0 otherwise - Verified by test ::rtc_enabled_test.
ommpy 0:d383e2dee0f7 49 *
ommpy 0:d383e2dee0f7 50 * # Undefined behaviour
ommpy 0:d383e2dee0f7 51 * * Calling any function other than ::rtc_init before the initialisation of the RTC
ommpy 0:d383e2dee0f7 52 *
ommpy 0:d383e2dee0f7 53 * # Potential bugs
ommpy 0:d383e2dee0f7 54 * * Incorrect overflow handling - Verified by ::rtc_range_test
ommpy 0:d383e2dee0f7 55 * * Glitches due to ripple counter - Verified by ::rtc_glitch_test
ommpy 0:d383e2dee0f7 56 *
ommpy 0:d383e2dee0f7 57 * @see hal_rtc_tests
ommpy 0:d383e2dee0f7 58 *
ommpy 0:d383e2dee0f7 59 * @{
ommpy 0:d383e2dee0f7 60 */
ommpy 0:d383e2dee0f7 61
ommpy 0:d383e2dee0f7 62 /**
ommpy 0:d383e2dee0f7 63 * \defgroup hal_rtc_tests RTC hal tests
ommpy 0:d383e2dee0f7 64 * The RTC test validate proper implementation of the RTC hal.
ommpy 0:d383e2dee0f7 65 *
ommpy 0:d383e2dee0f7 66 * To run the RTC hal tests use the command:
ommpy 0:d383e2dee0f7 67 *
ommpy 0:d383e2dee0f7 68 * mbed test -t <toolchain> -m <target> -n tests-mbed_hal-rtc*
ommpy 0:d383e2dee0f7 69 */
ommpy 0:d383e2dee0f7 70
ommpy 0:d383e2dee0f7 71
ommpy 0:d383e2dee0f7 72 /** Initialize the RTC peripheral
ommpy 0:d383e2dee0f7 73 *
ommpy 0:d383e2dee0f7 74 * Powerup the RTC in perpetration for access. This function must be called
ommpy 0:d383e2dee0f7 75 * before any other RTC functions ares called. This does not change the state
ommpy 0:d383e2dee0f7 76 * of the RTC. It just enables access to it.
ommpy 0:d383e2dee0f7 77 *
ommpy 0:d383e2dee0f7 78 * @note This function is safe to call repeatedly - Tested by ::rtc_init_test
ommpy 0:d383e2dee0f7 79 *
ommpy 0:d383e2dee0f7 80 * Example Implementation Pseudo Code:
ommpy 0:d383e2dee0f7 81 * @code
ommpy 0:d383e2dee0f7 82 * void rtc_init()
ommpy 0:d383e2dee0f7 83 * {
ommpy 0:d383e2dee0f7 84 * // Enable clock gate so processor can read RTC registers
ommpy 0:d383e2dee0f7 85 * POWER_CTRL |= POWER_CTRL_RTC_Msk;
ommpy 0:d383e2dee0f7 86 *
ommpy 0:d383e2dee0f7 87 * // See if the RTC is already setup
ommpy 0:d383e2dee0f7 88 * if (!(RTC_STATUS & RTC_STATUS_COUNTING_Msk)) {
ommpy 0:d383e2dee0f7 89 *
ommpy 0:d383e2dee0f7 90 * // Setup the RTC clock source
ommpy 0:d383e2dee0f7 91 * RTC_CTRL |= RTC_CTRL_CLK32_Msk;
ommpy 0:d383e2dee0f7 92 * }
ommpy 0:d383e2dee0f7 93 * }
ommpy 0:d383e2dee0f7 94 * @endcode
ommpy 0:d383e2dee0f7 95 */
ommpy 0:d383e2dee0f7 96 void rtc_init(void);
ommpy 0:d383e2dee0f7 97
ommpy 0:d383e2dee0f7 98 /** Deinitialize RTC
ommpy 0:d383e2dee0f7 99 *
ommpy 0:d383e2dee0f7 100 * Powerdown the RTC in preparation for sleep, powerdown or reset. That should only
ommpy 0:d383e2dee0f7 101 * affect the CPU domain and not the time keeping logic.
ommpy 0:d383e2dee0f7 102 * After this function is called no other RTC functions should be called
ommpy 0:d383e2dee0f7 103 * except for ::rtc_init.
ommpy 0:d383e2dee0f7 104 *
ommpy 0:d383e2dee0f7 105 * @note This function does not stop the RTC from counting - Tested by ::rtc_persist_test
ommpy 0:d383e2dee0f7 106 *
ommpy 0:d383e2dee0f7 107 * Example Implementation Pseudo Code:
ommpy 0:d383e2dee0f7 108 * @code
ommpy 0:d383e2dee0f7 109 * void rtc_free()
ommpy 0:d383e2dee0f7 110 * {
ommpy 0:d383e2dee0f7 111 * // Disable clock gate since processor no longer needs to read RTC registers
ommpy 0:d383e2dee0f7 112 * POWER_CTRL &= ~POWER_CTRL_RTC_Msk;
ommpy 0:d383e2dee0f7 113 * }
ommpy 0:d383e2dee0f7 114 * @endcode
ommpy 0:d383e2dee0f7 115 */
ommpy 0:d383e2dee0f7 116 void rtc_free(void);
ommpy 0:d383e2dee0f7 117
ommpy 0:d383e2dee0f7 118 /** Check if the RTC has the time set and is counting
ommpy 0:d383e2dee0f7 119 *
ommpy 0:d383e2dee0f7 120 * @retval 0 The time reported by the RTC is not valid
ommpy 0:d383e2dee0f7 121 * @retval 1 The time has been set the RTC is counting
ommpy 0:d383e2dee0f7 122 *
ommpy 0:d383e2dee0f7 123 * Example Implementation Pseudo Code:
ommpy 0:d383e2dee0f7 124 * @code
ommpy 0:d383e2dee0f7 125 * int rtc_isenabled()
ommpy 0:d383e2dee0f7 126 * {
ommpy 0:d383e2dee0f7 127 * if (RTC_STATUS & RTC_STATUS_COUNTING_Msk) {
ommpy 0:d383e2dee0f7 128 * return 1;
ommpy 0:d383e2dee0f7 129 * } else {
ommpy 0:d383e2dee0f7 130 * return 0;
ommpy 0:d383e2dee0f7 131 * }
ommpy 0:d383e2dee0f7 132 * }
ommpy 0:d383e2dee0f7 133 * @endcode
ommpy 0:d383e2dee0f7 134 */
ommpy 0:d383e2dee0f7 135 int rtc_isenabled(void);
ommpy 0:d383e2dee0f7 136
ommpy 0:d383e2dee0f7 137 /** Get the current time from the RTC peripheral
ommpy 0:d383e2dee0f7 138 *
ommpy 0:d383e2dee0f7 139 * @return The current time in seconds
ommpy 0:d383e2dee0f7 140 *
ommpy 0:d383e2dee0f7 141 * @note Some RTCs are not synchronized with the main clock. If
ommpy 0:d383e2dee0f7 142 * this is the case with your RTC then you must read the RTC time
ommpy 0:d383e2dee0f7 143 * in a loop to prevent reading the wrong time due to a glitch.
ommpy 0:d383e2dee0f7 144 * The test ::rtc_glitch_test is intended to catch this bug.
ommpy 0:d383e2dee0f7 145 *
ommpy 0:d383e2dee0f7 146 * Example implementation for an unsynchronized ripple counter:
ommpy 0:d383e2dee0f7 147 * @code
ommpy 0:d383e2dee0f7 148 * time_t rtc_read()
ommpy 0:d383e2dee0f7 149 * {
ommpy 0:d383e2dee0f7 150 * uint32_t val;
ommpy 0:d383e2dee0f7 151 * uint32_t last_val;
ommpy 0:d383e2dee0f7 152 *
ommpy 0:d383e2dee0f7 153 * // Loop until the same value is read twice
ommpy 0:d383e2dee0f7 154 * val = RTC_SECONDS;
ommpy 0:d383e2dee0f7 155 * do {
ommpy 0:d383e2dee0f7 156 * last_val = val;
ommpy 0:d383e2dee0f7 157 * val = RTC_SECONDS;
ommpy 0:d383e2dee0f7 158 * } while (last_val != val);
ommpy 0:d383e2dee0f7 159 *
ommpy 0:d383e2dee0f7 160 * return (time_t)val;
ommpy 0:d383e2dee0f7 161 * }
ommpy 0:d383e2dee0f7 162 * @endcode
ommpy 0:d383e2dee0f7 163 */
ommpy 0:d383e2dee0f7 164 time_t rtc_read(void);
ommpy 0:d383e2dee0f7 165
ommpy 0:d383e2dee0f7 166 /** Write the current time in seconds to the RTC peripheral
ommpy 0:d383e2dee0f7 167 *
ommpy 0:d383e2dee0f7 168 * @param t The current time to be set in seconds.
ommpy 0:d383e2dee0f7 169 *
ommpy 0:d383e2dee0f7 170 * Example Implementation Pseudo Code:
ommpy 0:d383e2dee0f7 171 * @code
ommpy 0:d383e2dee0f7 172 * void rtc_write(time_t t)
ommpy 0:d383e2dee0f7 173 * {
ommpy 0:d383e2dee0f7 174 * RTC_SECONDS = t;
ommpy 0:d383e2dee0f7 175 * }
ommpy 0:d383e2dee0f7 176 * @endcode
ommpy 0:d383e2dee0f7 177 */
ommpy 0:d383e2dee0f7 178 void rtc_write(time_t t);
ommpy 0:d383e2dee0f7 179
ommpy 0:d383e2dee0f7 180 /**@}*/
ommpy 0:d383e2dee0f7 181
ommpy 0:d383e2dee0f7 182 #ifdef __cplusplus
ommpy 0:d383e2dee0f7 183 }
ommpy 0:d383e2dee0f7 184 #endif
ommpy 0:d383e2dee0f7 185
ommpy 0:d383e2dee0f7 186 #endif
ommpy 0:d383e2dee0f7 187
ommpy 0:d383e2dee0f7 188 /** @}*/