Initial commit

Dependencies:   FastPWM

Committer:
lypinator
Date:
Wed Sep 16 01:11:49 2020 +0000
Revision:
0:bb348c97df44
Added PWM

Who changed what in which revision?

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