The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Wed Feb 20 20:53:29 2019 +0000
Revision:
172:65be27845400
Parent:
171:3a7713b1edbc
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 143:86740a56073b 1 /*
AnnaBridge 143:86740a56073b 2 * Copyright (c) 2014 Nordic Semiconductor ASA
AnnaBridge 143:86740a56073b 3 * All rights reserved.
AnnaBridge 143:86740a56073b 4 *
AnnaBridge 143:86740a56073b 5 * Redistribution and use in source and binary forms, with or without modification,
AnnaBridge 143:86740a56073b 6 * are permitted provided that the following conditions are met:
AnnaBridge 143:86740a56073b 7 *
AnnaBridge 143:86740a56073b 8 * 1. Redistributions of source code must retain the above copyright notice, this list
AnnaBridge 143:86740a56073b 9 * of conditions and the following disclaimer.
AnnaBridge 143:86740a56073b 10 *
AnnaBridge 143:86740a56073b 11 * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
AnnaBridge 143:86740a56073b 12 * integrated circuit in a product or a software update for such product, must reproduce
AnnaBridge 143:86740a56073b 13 * the above copyright notice, this list of conditions and the following disclaimer in
AnnaBridge 143:86740a56073b 14 * the documentation and/or other materials provided with the distribution.
AnnaBridge 143:86740a56073b 15 *
AnnaBridge 143:86740a56073b 16 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be
AnnaBridge 143:86740a56073b 17 * used to endorse or promote products derived from this software without specific prior
AnnaBridge 143:86740a56073b 18 * written permission.
AnnaBridge 143:86740a56073b 19 *
AnnaBridge 143:86740a56073b 20 * 4. This software, with or without modification, must only be used with a
AnnaBridge 143:86740a56073b 21 * Nordic Semiconductor ASA integrated circuit.
AnnaBridge 143:86740a56073b 22 *
AnnaBridge 143:86740a56073b 23 * 5. Any software provided in binary or object form under this license must not be reverse
AnnaBridge 143:86740a56073b 24 * engineered, decompiled, modified and/or disassembled.
AnnaBridge 143:86740a56073b 25 *
AnnaBridge 143:86740a56073b 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
AnnaBridge 143:86740a56073b 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
AnnaBridge 143:86740a56073b 28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
AnnaBridge 143:86740a56073b 29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
AnnaBridge 143:86740a56073b 30 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
AnnaBridge 143:86740a56073b 31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
AnnaBridge 143:86740a56073b 32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
AnnaBridge 143:86740a56073b 33 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
AnnaBridge 143:86740a56073b 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
AnnaBridge 143:86740a56073b 35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
AnnaBridge 143:86740a56073b 36 *
AnnaBridge 143:86740a56073b 37 */
AnnaBridge 143:86740a56073b 38
AnnaBridge 143:86740a56073b 39
AnnaBridge 143:86740a56073b 40 /**
AnnaBridge 143:86740a56073b 41 * @defgroup nrf_timer_hal Timer HAL
AnnaBridge 143:86740a56073b 42 * @{
AnnaBridge 143:86740a56073b 43 * @ingroup nrf_timer
AnnaBridge 143:86740a56073b 44 *
AnnaBridge 143:86740a56073b 45 * @brief Hardware access layer for accessing the timer peripheral.
AnnaBridge 143:86740a56073b 46 */
AnnaBridge 143:86740a56073b 47
AnnaBridge 143:86740a56073b 48 #ifndef NRF_TIMER_H__
AnnaBridge 143:86740a56073b 49 #define NRF_TIMER_H__
AnnaBridge 143:86740a56073b 50
AnnaBridge 143:86740a56073b 51 #include <stddef.h>
AnnaBridge 143:86740a56073b 52 #include <stdbool.h>
AnnaBridge 143:86740a56073b 53 #include <stdint.h>
AnnaBridge 143:86740a56073b 54
AnnaBridge 143:86740a56073b 55 #include "nrf.h"
AnnaBridge 143:86740a56073b 56 #include "nrf_assert.h"
AnnaBridge 143:86740a56073b 57
AnnaBridge 143:86740a56073b 58
AnnaBridge 143:86740a56073b 59 /**
AnnaBridge 143:86740a56073b 60 * @brief Macro for validating the correctness of the BIT_WIDTH setting.
AnnaBridge 143:86740a56073b 61 */
AnnaBridge 143:86740a56073b 62 #ifdef NRF51
AnnaBridge 143:86740a56073b 63 /**
AnnaBridge 143:86740a56073b 64 * In the nRF51 Series, timer instance 0 supports all available bit widths.
AnnaBridge 143:86740a56073b 65 * The other two instances support only 8 and 16 bits.
AnnaBridge 143:86740a56073b 66 */
AnnaBridge 143:86740a56073b 67 #define NRF_TIMER_IS_BIT_WIDTH_VALID(p_timer, bit_width) \
AnnaBridge 143:86740a56073b 68 ((p_timer == NRF_TIMER0) || (bit_width <= NRF_TIMER_BIT_WIDTH_16))
AnnaBridge 143:86740a56073b 69 #else
AnnaBridge 143:86740a56073b 70 /**
AnnaBridge 143:86740a56073b 71 * In the nRF52 Series, all timer instances support all available bit widths.
AnnaBridge 143:86740a56073b 72 */
AnnaBridge 143:86740a56073b 73 #define NRF_TIMER_IS_BIT_WIDTH_VALID(p_timer, bit_width) true
AnnaBridge 143:86740a56073b 74 #endif
AnnaBridge 143:86740a56073b 75
AnnaBridge 143:86740a56073b 76 /**
AnnaBridge 143:86740a56073b 77 * @brief Macro for getting the number of capture/compare channels available
AnnaBridge 143:86740a56073b 78 * in a given timer instance.
AnnaBridge 143:86740a56073b 79 */
AnnaBridge 143:86740a56073b 80 #ifdef NRF51
AnnaBridge 143:86740a56073b 81 #define NRF_TIMER_CC_CHANNEL_COUNT(id) 4
AnnaBridge 143:86740a56073b 82 #else
AnnaBridge 143:86740a56073b 83 #define NRF_TIMER_CC_CHANNEL_COUNT(id) ((id) <= 2 ? 4 : 6)
AnnaBridge 143:86740a56073b 84 #endif
AnnaBridge 143:86740a56073b 85
AnnaBridge 143:86740a56073b 86
AnnaBridge 143:86740a56073b 87 /**
AnnaBridge 143:86740a56073b 88 * @brief Timer tasks.
AnnaBridge 143:86740a56073b 89 */
AnnaBridge 143:86740a56073b 90 typedef enum
AnnaBridge 143:86740a56073b 91 {
AnnaBridge 143:86740a56073b 92 /*lint -save -e30 -esym(628,__INTADDR__)*/
AnnaBridge 143:86740a56073b 93 NRF_TIMER_TASK_START = offsetof(NRF_TIMER_Type, TASKS_START), ///< Task for starting the timer.
AnnaBridge 143:86740a56073b 94 NRF_TIMER_TASK_STOP = offsetof(NRF_TIMER_Type, TASKS_STOP), ///< Task for stopping the timer.
AnnaBridge 143:86740a56073b 95 NRF_TIMER_TASK_COUNT = offsetof(NRF_TIMER_Type, TASKS_COUNT), ///< Task for incrementing the timer (in counter mode).
AnnaBridge 143:86740a56073b 96 NRF_TIMER_TASK_CLEAR = offsetof(NRF_TIMER_Type, TASKS_CLEAR), ///< Task for resetting the timer value.
AnnaBridge 143:86740a56073b 97 NRF_TIMER_TASK_SHUTDOWN = offsetof(NRF_TIMER_Type, TASKS_SHUTDOWN), ///< Task for powering off the timer.
AnnaBridge 143:86740a56073b 98 NRF_TIMER_TASK_CAPTURE0 = offsetof(NRF_TIMER_Type, TASKS_CAPTURE[0]), ///< Task for capturing the timer value on channel 0.
AnnaBridge 143:86740a56073b 99 NRF_TIMER_TASK_CAPTURE1 = offsetof(NRF_TIMER_Type, TASKS_CAPTURE[1]), ///< Task for capturing the timer value on channel 1.
AnnaBridge 143:86740a56073b 100 NRF_TIMER_TASK_CAPTURE2 = offsetof(NRF_TIMER_Type, TASKS_CAPTURE[2]), ///< Task for capturing the timer value on channel 2.
AnnaBridge 143:86740a56073b 101 NRF_TIMER_TASK_CAPTURE3 = offsetof(NRF_TIMER_Type, TASKS_CAPTURE[3]), ///< Task for capturing the timer value on channel 3.
AnnaBridge 143:86740a56073b 102 #ifdef NRF52
AnnaBridge 143:86740a56073b 103 NRF_TIMER_TASK_CAPTURE4 = offsetof(NRF_TIMER_Type, TASKS_CAPTURE[4]), ///< Task for capturing the timer value on channel 4.
AnnaBridge 143:86740a56073b 104 NRF_TIMER_TASK_CAPTURE5 = offsetof(NRF_TIMER_Type, TASKS_CAPTURE[5]), ///< Task for capturing the timer value on channel 5.
AnnaBridge 143:86740a56073b 105 #endif
AnnaBridge 143:86740a56073b 106 /*lint -restore*/
AnnaBridge 143:86740a56073b 107 } nrf_timer_task_t;
AnnaBridge 143:86740a56073b 108
AnnaBridge 143:86740a56073b 109 /**
AnnaBridge 143:86740a56073b 110 * @brief Timer events.
AnnaBridge 143:86740a56073b 111 */
AnnaBridge 143:86740a56073b 112 typedef enum
AnnaBridge 143:86740a56073b 113 {
AnnaBridge 143:86740a56073b 114 /*lint -save -e30*/
AnnaBridge 143:86740a56073b 115 NRF_TIMER_EVENT_COMPARE0 = offsetof(NRF_TIMER_Type, EVENTS_COMPARE[0]), ///< Event from compare channel 0.
AnnaBridge 143:86740a56073b 116 NRF_TIMER_EVENT_COMPARE1 = offsetof(NRF_TIMER_Type, EVENTS_COMPARE[1]), ///< Event from compare channel 1.
AnnaBridge 143:86740a56073b 117 NRF_TIMER_EVENT_COMPARE2 = offsetof(NRF_TIMER_Type, EVENTS_COMPARE[2]), ///< Event from compare channel 2.
AnnaBridge 143:86740a56073b 118 NRF_TIMER_EVENT_COMPARE3 = offsetof(NRF_TIMER_Type, EVENTS_COMPARE[3]), ///< Event from compare channel 3.
AnnaBridge 143:86740a56073b 119 #ifdef NRF52
AnnaBridge 143:86740a56073b 120 NRF_TIMER_EVENT_COMPARE4 = offsetof(NRF_TIMER_Type, EVENTS_COMPARE[4]), ///< Event from compare channel 4.
AnnaBridge 143:86740a56073b 121 NRF_TIMER_EVENT_COMPARE5 = offsetof(NRF_TIMER_Type, EVENTS_COMPARE[5]), ///< Event from compare channel 5.
AnnaBridge 143:86740a56073b 122 #endif
AnnaBridge 143:86740a56073b 123 /*lint -restore*/
AnnaBridge 143:86740a56073b 124 } nrf_timer_event_t;
AnnaBridge 143:86740a56073b 125
AnnaBridge 143:86740a56073b 126 /**
AnnaBridge 143:86740a56073b 127 * @brief Types of timer shortcuts.
AnnaBridge 143:86740a56073b 128 */
AnnaBridge 143:86740a56073b 129 typedef enum
AnnaBridge 143:86740a56073b 130 {
AnnaBridge 143:86740a56073b 131 NRF_TIMER_SHORT_COMPARE0_STOP_MASK = TIMER_SHORTS_COMPARE0_STOP_Msk, ///< Shortcut for stopping the timer based on compare 0.
AnnaBridge 143:86740a56073b 132 NRF_TIMER_SHORT_COMPARE1_STOP_MASK = TIMER_SHORTS_COMPARE1_STOP_Msk, ///< Shortcut for stopping the timer based on compare 1.
AnnaBridge 143:86740a56073b 133 NRF_TIMER_SHORT_COMPARE2_STOP_MASK = TIMER_SHORTS_COMPARE2_STOP_Msk, ///< Shortcut for stopping the timer based on compare 2.
AnnaBridge 143:86740a56073b 134 NRF_TIMER_SHORT_COMPARE3_STOP_MASK = TIMER_SHORTS_COMPARE3_STOP_Msk, ///< Shortcut for stopping the timer based on compare 3.
AnnaBridge 143:86740a56073b 135 #ifdef NRF52
AnnaBridge 143:86740a56073b 136 NRF_TIMER_SHORT_COMPARE4_STOP_MASK = TIMER_SHORTS_COMPARE4_STOP_Msk, ///< Shortcut for stopping the timer based on compare 4.
AnnaBridge 143:86740a56073b 137 NRF_TIMER_SHORT_COMPARE5_STOP_MASK = TIMER_SHORTS_COMPARE5_STOP_Msk, ///< Shortcut for stopping the timer based on compare 5.
AnnaBridge 143:86740a56073b 138 #endif
AnnaBridge 143:86740a56073b 139 NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK = TIMER_SHORTS_COMPARE0_CLEAR_Msk, ///< Shortcut for clearing the timer based on compare 0.
AnnaBridge 143:86740a56073b 140 NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK = TIMER_SHORTS_COMPARE1_CLEAR_Msk, ///< Shortcut for clearing the timer based on compare 1.
AnnaBridge 143:86740a56073b 141 NRF_TIMER_SHORT_COMPARE2_CLEAR_MASK = TIMER_SHORTS_COMPARE2_CLEAR_Msk, ///< Shortcut for clearing the timer based on compare 2.
AnnaBridge 143:86740a56073b 142 NRF_TIMER_SHORT_COMPARE3_CLEAR_MASK = TIMER_SHORTS_COMPARE3_CLEAR_Msk, ///< Shortcut for clearing the timer based on compare 3.
AnnaBridge 143:86740a56073b 143 #ifdef NRF52
AnnaBridge 143:86740a56073b 144 NRF_TIMER_SHORT_COMPARE4_CLEAR_MASK = TIMER_SHORTS_COMPARE4_CLEAR_Msk, ///< Shortcut for clearing the timer based on compare 4.
AnnaBridge 143:86740a56073b 145 NRF_TIMER_SHORT_COMPARE5_CLEAR_MASK = TIMER_SHORTS_COMPARE5_CLEAR_Msk, ///< Shortcut for clearing the timer based on compare 5.
AnnaBridge 143:86740a56073b 146 #endif
AnnaBridge 143:86740a56073b 147 } nrf_timer_short_mask_t;
AnnaBridge 143:86740a56073b 148
AnnaBridge 143:86740a56073b 149 /**
AnnaBridge 143:86740a56073b 150 * @brief Timer modes.
AnnaBridge 143:86740a56073b 151 */
AnnaBridge 143:86740a56073b 152 typedef enum
AnnaBridge 143:86740a56073b 153 {
AnnaBridge 143:86740a56073b 154 NRF_TIMER_MODE_TIMER = TIMER_MODE_MODE_Timer, ///< Timer mode: timer.
AnnaBridge 143:86740a56073b 155 NRF_TIMER_MODE_COUNTER = TIMER_MODE_MODE_Counter, ///< Timer mode: counter.
AnnaBridge 143:86740a56073b 156 #ifdef NRF52
AnnaBridge 143:86740a56073b 157 NRF_TIMER_MODE_LOW_POWER_COUNTER = TIMER_MODE_MODE_LowPowerCounter, ///< Timer mode: low-power counter.
AnnaBridge 143:86740a56073b 158 #endif
AnnaBridge 143:86740a56073b 159 } nrf_timer_mode_t;
AnnaBridge 143:86740a56073b 160
AnnaBridge 143:86740a56073b 161 /**
AnnaBridge 143:86740a56073b 162 * @brief Timer bit width.
AnnaBridge 143:86740a56073b 163 */
AnnaBridge 143:86740a56073b 164 typedef enum
AnnaBridge 143:86740a56073b 165 {
AnnaBridge 143:86740a56073b 166 NRF_TIMER_BIT_WIDTH_8 = TIMER_BITMODE_BITMODE_08Bit, ///< Timer bit width 8 bit.
AnnaBridge 143:86740a56073b 167 NRF_TIMER_BIT_WIDTH_16 = TIMER_BITMODE_BITMODE_16Bit, ///< Timer bit width 16 bit.
AnnaBridge 143:86740a56073b 168 NRF_TIMER_BIT_WIDTH_24 = TIMER_BITMODE_BITMODE_24Bit, ///< Timer bit width 24 bit.
AnnaBridge 143:86740a56073b 169 NRF_TIMER_BIT_WIDTH_32 = TIMER_BITMODE_BITMODE_32Bit ///< Timer bit width 32 bit.
AnnaBridge 143:86740a56073b 170 } nrf_timer_bit_width_t;
AnnaBridge 143:86740a56073b 171
AnnaBridge 143:86740a56073b 172 /**
AnnaBridge 143:86740a56073b 173 * @brief Timer prescalers.
AnnaBridge 143:86740a56073b 174 */
AnnaBridge 143:86740a56073b 175 typedef enum
AnnaBridge 143:86740a56073b 176 {
AnnaBridge 143:86740a56073b 177 NRF_TIMER_FREQ_16MHz = 0, ///< Timer frequency 16 MHz.
AnnaBridge 143:86740a56073b 178 NRF_TIMER_FREQ_8MHz, ///< Timer frequency 8 MHz.
AnnaBridge 143:86740a56073b 179 NRF_TIMER_FREQ_4MHz, ///< Timer frequency 4 MHz.
AnnaBridge 143:86740a56073b 180 NRF_TIMER_FREQ_2MHz, ///< Timer frequency 2 MHz.
AnnaBridge 143:86740a56073b 181 NRF_TIMER_FREQ_1MHz, ///< Timer frequency 1 MHz.
AnnaBridge 143:86740a56073b 182 NRF_TIMER_FREQ_500kHz, ///< Timer frequency 500 kHz.
AnnaBridge 143:86740a56073b 183 NRF_TIMER_FREQ_250kHz, ///< Timer frequency 250 kHz.
AnnaBridge 143:86740a56073b 184 NRF_TIMER_FREQ_125kHz, ///< Timer frequency 125 kHz.
AnnaBridge 143:86740a56073b 185 NRF_TIMER_FREQ_62500Hz, ///< Timer frequency 62500 Hz.
AnnaBridge 143:86740a56073b 186 NRF_TIMER_FREQ_31250Hz ///< Timer frequency 31250 Hz.
AnnaBridge 143:86740a56073b 187 } nrf_timer_frequency_t;
AnnaBridge 143:86740a56073b 188
AnnaBridge 143:86740a56073b 189 /**
AnnaBridge 143:86740a56073b 190 * @brief Timer capture/compare channels.
AnnaBridge 143:86740a56073b 191 */
AnnaBridge 143:86740a56073b 192 typedef enum
AnnaBridge 143:86740a56073b 193 {
AnnaBridge 143:86740a56073b 194 NRF_TIMER_CC_CHANNEL0 = 0, ///< Timer capture/compare channel 0.
AnnaBridge 143:86740a56073b 195 NRF_TIMER_CC_CHANNEL1, ///< Timer capture/compare channel 1.
AnnaBridge 143:86740a56073b 196 NRF_TIMER_CC_CHANNEL2, ///< Timer capture/compare channel 2.
AnnaBridge 143:86740a56073b 197 NRF_TIMER_CC_CHANNEL3, ///< Timer capture/compare channel 3.
AnnaBridge 143:86740a56073b 198 #ifdef NRF52
AnnaBridge 143:86740a56073b 199 NRF_TIMER_CC_CHANNEL4, ///< Timer capture/compare channel 4.
AnnaBridge 143:86740a56073b 200 NRF_TIMER_CC_CHANNEL5, ///< Timer capture/compare channel 5.
AnnaBridge 143:86740a56073b 201 #endif
AnnaBridge 143:86740a56073b 202 } nrf_timer_cc_channel_t;
AnnaBridge 143:86740a56073b 203
AnnaBridge 143:86740a56073b 204 /**
AnnaBridge 143:86740a56073b 205 * @brief Timer interrupts.
AnnaBridge 143:86740a56073b 206 */
AnnaBridge 143:86740a56073b 207 typedef enum
AnnaBridge 143:86740a56073b 208 {
AnnaBridge 143:86740a56073b 209 NRF_TIMER_INT_COMPARE0_MASK = TIMER_INTENSET_COMPARE0_Msk, ///< Timer interrupt from compare event on channel 0.
AnnaBridge 143:86740a56073b 210 NRF_TIMER_INT_COMPARE1_MASK = TIMER_INTENSET_COMPARE1_Msk, ///< Timer interrupt from compare event on channel 1.
AnnaBridge 143:86740a56073b 211 NRF_TIMER_INT_COMPARE2_MASK = TIMER_INTENSET_COMPARE2_Msk, ///< Timer interrupt from compare event on channel 2.
AnnaBridge 143:86740a56073b 212 NRF_TIMER_INT_COMPARE3_MASK = TIMER_INTENSET_COMPARE3_Msk, ///< Timer interrupt from compare event on channel 3.
AnnaBridge 143:86740a56073b 213 #ifdef NRF52
AnnaBridge 143:86740a56073b 214 NRF_TIMER_INT_COMPARE4_MASK = TIMER_INTENSET_COMPARE4_Msk, ///< Timer interrupt from compare event on channel 4.
AnnaBridge 143:86740a56073b 215 NRF_TIMER_INT_COMPARE5_MASK = TIMER_INTENSET_COMPARE5_Msk, ///< Timer interrupt from compare event on channel 5.
AnnaBridge 143:86740a56073b 216 #endif
AnnaBridge 143:86740a56073b 217 } nrf_timer_int_mask_t;
AnnaBridge 143:86740a56073b 218
AnnaBridge 143:86740a56073b 219
AnnaBridge 143:86740a56073b 220 /**
AnnaBridge 143:86740a56073b 221 * @brief Function for activating a specific timer task.
AnnaBridge 143:86740a56073b 222 *
AnnaBridge 143:86740a56073b 223 * @param[in] p_timer Timer instance.
AnnaBridge 143:86740a56073b 224 * @param[in] task Task to activate.
AnnaBridge 143:86740a56073b 225 */
AnnaBridge 143:86740a56073b 226 __STATIC_INLINE void nrf_timer_task_trigger(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 227 nrf_timer_task_t task);
AnnaBridge 143:86740a56073b 228
AnnaBridge 143:86740a56073b 229 /**
AnnaBridge 143:86740a56073b 230 * @brief Function for getting the address of a specific timer task register.
AnnaBridge 143:86740a56073b 231 *
AnnaBridge 143:86740a56073b 232 * @param[in] p_timer Timer instance.
AnnaBridge 143:86740a56073b 233 * @param[in] task Requested task.
AnnaBridge 143:86740a56073b 234 *
AnnaBridge 143:86740a56073b 235 * @return Address of the specified task register.
AnnaBridge 143:86740a56073b 236 */
AnnaBridge 143:86740a56073b 237 __STATIC_INLINE uint32_t * nrf_timer_task_address_get(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 238 nrf_timer_task_t task);
AnnaBridge 143:86740a56073b 239
AnnaBridge 143:86740a56073b 240 /**
AnnaBridge 143:86740a56073b 241 * @brief Function for clearing a specific timer event.
AnnaBridge 143:86740a56073b 242 *
AnnaBridge 143:86740a56073b 243 * @param[in] p_timer Timer instance.
AnnaBridge 143:86740a56073b 244 * @param[in] event Event to clear.
AnnaBridge 143:86740a56073b 245 */
AnnaBridge 143:86740a56073b 246 __STATIC_INLINE void nrf_timer_event_clear(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 247 nrf_timer_event_t event);
AnnaBridge 143:86740a56073b 248
AnnaBridge 143:86740a56073b 249 /**
AnnaBridge 143:86740a56073b 250 * @brief Function for checking the state of a specific timer event.
AnnaBridge 143:86740a56073b 251 *
AnnaBridge 143:86740a56073b 252 * @param[in] p_timer Timer instance.
AnnaBridge 143:86740a56073b 253 * @param[in] event Event to check.
AnnaBridge 143:86740a56073b 254 *
AnnaBridge 143:86740a56073b 255 * @retval true If the event is set.
AnnaBridge 143:86740a56073b 256 * @retval false If the event is not set.
AnnaBridge 143:86740a56073b 257 */
AnnaBridge 143:86740a56073b 258 __STATIC_INLINE bool nrf_timer_event_check(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 259 nrf_timer_event_t event);
AnnaBridge 143:86740a56073b 260
AnnaBridge 143:86740a56073b 261 /**
AnnaBridge 143:86740a56073b 262 * @brief Function for getting the address of a specific timer event register.
AnnaBridge 143:86740a56073b 263 *
AnnaBridge 143:86740a56073b 264 * @param[in] p_timer Timer instance.
AnnaBridge 143:86740a56073b 265 * @param[in] event Requested event.
AnnaBridge 143:86740a56073b 266 *
AnnaBridge 143:86740a56073b 267 * @return Address of the specified event register.
AnnaBridge 143:86740a56073b 268 */
AnnaBridge 143:86740a56073b 269 __STATIC_INLINE uint32_t * nrf_timer_event_address_get(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 270 nrf_timer_event_t event);
AnnaBridge 143:86740a56073b 271
AnnaBridge 143:86740a56073b 272 /**
AnnaBridge 143:86740a56073b 273 * @brief Function for enabling specified shortcuts.
AnnaBridge 143:86740a56073b 274 *
AnnaBridge 143:86740a56073b 275 * @param[in] p_timer Timer instance.
AnnaBridge 143:86740a56073b 276 * @param[in] timer_shorts_mask Shortcuts to enable.
AnnaBridge 143:86740a56073b 277 */
AnnaBridge 143:86740a56073b 278 __STATIC_INLINE void nrf_timer_shorts_enable(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 279 uint32_t timer_shorts_mask);
AnnaBridge 143:86740a56073b 280
AnnaBridge 143:86740a56073b 281 /**
AnnaBridge 143:86740a56073b 282 * @brief Function for disabling specified shortcuts.
AnnaBridge 143:86740a56073b 283 *
AnnaBridge 143:86740a56073b 284 * @param[in] p_timer Timer instance.
AnnaBridge 143:86740a56073b 285 * @param[in] timer_shorts_mask Shortcuts to disable.
AnnaBridge 143:86740a56073b 286 */
AnnaBridge 143:86740a56073b 287 __STATIC_INLINE void nrf_timer_shorts_disable(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 288 uint32_t timer_shorts_mask);
AnnaBridge 143:86740a56073b 289
AnnaBridge 143:86740a56073b 290 /**
AnnaBridge 143:86740a56073b 291 * @brief Function for enabling specified interrupts.
AnnaBridge 143:86740a56073b 292 *
AnnaBridge 143:86740a56073b 293 * @param[in] p_timer Timer instance.
AnnaBridge 143:86740a56073b 294 * @param[in] timer_int_mask Interrupts to enable.
AnnaBridge 143:86740a56073b 295 */
AnnaBridge 143:86740a56073b 296 __STATIC_INLINE void nrf_timer_int_enable(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 297 uint32_t timer_int_mask);
AnnaBridge 143:86740a56073b 298
AnnaBridge 143:86740a56073b 299 /**
AnnaBridge 143:86740a56073b 300 * @brief Function for disabling specified interrupts.
AnnaBridge 143:86740a56073b 301 *
AnnaBridge 143:86740a56073b 302 * @param[in] p_timer Timer instance.
AnnaBridge 143:86740a56073b 303 * @param[in] timer_int_mask Interrupts to disable.
AnnaBridge 143:86740a56073b 304 */
AnnaBridge 143:86740a56073b 305 __STATIC_INLINE void nrf_timer_int_disable(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 306 uint32_t timer_int_mask);
AnnaBridge 143:86740a56073b 307
AnnaBridge 143:86740a56073b 308 /**
AnnaBridge 143:86740a56073b 309 * @brief Function for retrieving the state of a given interrupt.
AnnaBridge 143:86740a56073b 310 *
AnnaBridge 143:86740a56073b 311 * @param[in] p_timer Timer instance.
AnnaBridge 143:86740a56073b 312 * @param[in] timer_int Interrupt to check.
AnnaBridge 143:86740a56073b 313 *
AnnaBridge 143:86740a56073b 314 * @retval true If the interrupt is enabled.
AnnaBridge 143:86740a56073b 315 * @retval false If the interrupt is not enabled.
AnnaBridge 143:86740a56073b 316 */
AnnaBridge 143:86740a56073b 317 __STATIC_INLINE bool nrf_timer_int_enable_check(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 318 uint32_t timer_int);
AnnaBridge 143:86740a56073b 319
AnnaBridge 143:86740a56073b 320 /**
AnnaBridge 143:86740a56073b 321 * @brief Function for setting the timer mode.
AnnaBridge 143:86740a56073b 322 *
AnnaBridge 143:86740a56073b 323 * @param[in] p_timer Timer instance.
AnnaBridge 143:86740a56073b 324 * @param[in] mode Timer mode.
AnnaBridge 143:86740a56073b 325 */
AnnaBridge 143:86740a56073b 326 __STATIC_INLINE void nrf_timer_mode_set(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 327 nrf_timer_mode_t mode);
AnnaBridge 143:86740a56073b 328
AnnaBridge 143:86740a56073b 329 /**
AnnaBridge 143:86740a56073b 330 * @brief Function for retrieving the timer mode.
AnnaBridge 143:86740a56073b 331 *
AnnaBridge 143:86740a56073b 332 * @param[in] p_timer Timer instance.
AnnaBridge 143:86740a56073b 333 *
AnnaBridge 143:86740a56073b 334 * @return Timer mode.
AnnaBridge 143:86740a56073b 335 */
AnnaBridge 143:86740a56073b 336 __STATIC_INLINE nrf_timer_mode_t nrf_timer_mode_get(NRF_TIMER_Type * p_timer);
AnnaBridge 143:86740a56073b 337
AnnaBridge 143:86740a56073b 338 /**
AnnaBridge 143:86740a56073b 339 * @brief Function for setting the timer bit width.
AnnaBridge 143:86740a56073b 340 *
AnnaBridge 143:86740a56073b 341 * @param[in] p_timer Timer instance.
AnnaBridge 143:86740a56073b 342 * @param[in] bit_width Timer bit width.
AnnaBridge 143:86740a56073b 343 */
AnnaBridge 143:86740a56073b 344 __STATIC_INLINE void nrf_timer_bit_width_set(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 345 nrf_timer_bit_width_t bit_width);
AnnaBridge 143:86740a56073b 346
AnnaBridge 143:86740a56073b 347 /**
AnnaBridge 143:86740a56073b 348 * @brief Function for retrieving the timer bit width.
AnnaBridge 143:86740a56073b 349 *
AnnaBridge 143:86740a56073b 350 * @param[in] p_timer Timer instance.
AnnaBridge 143:86740a56073b 351 *
AnnaBridge 143:86740a56073b 352 * @return Timer bit width.
AnnaBridge 143:86740a56073b 353 */
AnnaBridge 143:86740a56073b 354 __STATIC_INLINE nrf_timer_bit_width_t nrf_timer_bit_width_get(NRF_TIMER_Type * p_timer);
AnnaBridge 143:86740a56073b 355
AnnaBridge 143:86740a56073b 356 /**
AnnaBridge 143:86740a56073b 357 * @brief Function for setting the timer frequency.
AnnaBridge 143:86740a56073b 358 *
AnnaBridge 143:86740a56073b 359 * @param[in] p_timer Timer instance.
AnnaBridge 143:86740a56073b 360 * @param[in] frequency Timer frequency.
AnnaBridge 143:86740a56073b 361 */
AnnaBridge 143:86740a56073b 362 __STATIC_INLINE void nrf_timer_frequency_set(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 363 nrf_timer_frequency_t frequency);
AnnaBridge 143:86740a56073b 364
AnnaBridge 143:86740a56073b 365 /**
AnnaBridge 143:86740a56073b 366 * @brief Function for retrieving the timer frequency.
AnnaBridge 143:86740a56073b 367 *
AnnaBridge 143:86740a56073b 368 * @param[in] p_timer Timer instance.
AnnaBridge 143:86740a56073b 369 *
AnnaBridge 143:86740a56073b 370 * @return Timer frequency.
AnnaBridge 143:86740a56073b 371 */
AnnaBridge 143:86740a56073b 372 __STATIC_INLINE nrf_timer_frequency_t nrf_timer_frequency_get(NRF_TIMER_Type * p_timer);
AnnaBridge 143:86740a56073b 373
AnnaBridge 143:86740a56073b 374 /**
AnnaBridge 143:86740a56073b 375 * @brief Function for writing the capture/compare register for a specified channel.
AnnaBridge 143:86740a56073b 376 *
AnnaBridge 143:86740a56073b 377 * @param[in] p_timer Timer instance.
AnnaBridge 143:86740a56073b 378 * @param[in] cc_channel Requested capture/compare channel.
AnnaBridge 143:86740a56073b 379 * @param[in] cc_value Value to write to the capture/compare register.
AnnaBridge 143:86740a56073b 380 */
AnnaBridge 143:86740a56073b 381 __STATIC_INLINE void nrf_timer_cc_write(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 382 nrf_timer_cc_channel_t cc_channel,
AnnaBridge 143:86740a56073b 383 uint32_t cc_value);
AnnaBridge 143:86740a56073b 384
AnnaBridge 143:86740a56073b 385 /**
AnnaBridge 143:86740a56073b 386 * @brief Function for retrieving the capture/compare value for a specified channel.
AnnaBridge 143:86740a56073b 387 *
AnnaBridge 143:86740a56073b 388 * @param[in] p_timer Timer instance.
AnnaBridge 143:86740a56073b 389 * @param[in] cc_channel Requested capture/compare channel.
AnnaBridge 143:86740a56073b 390 *
AnnaBridge 143:86740a56073b 391 * @return Value from the requested capture/compare register.
AnnaBridge 143:86740a56073b 392 */
AnnaBridge 143:86740a56073b 393 __STATIC_INLINE uint32_t nrf_timer_cc_read(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 394 nrf_timer_cc_channel_t cc_channel);
AnnaBridge 143:86740a56073b 395
AnnaBridge 143:86740a56073b 396 /**
AnnaBridge 143:86740a56073b 397 * @brief Function for getting a specific timer capture task.
AnnaBridge 143:86740a56073b 398 *
AnnaBridge 143:86740a56073b 399 * @param[in] channel Capture channel.
AnnaBridge 143:86740a56073b 400 *
AnnaBridge 143:86740a56073b 401 * @return Capture task.
AnnaBridge 143:86740a56073b 402 */
AnnaBridge 143:86740a56073b 403 __STATIC_INLINE nrf_timer_task_t nrf_timer_capture_task_get(uint32_t channel);
AnnaBridge 143:86740a56073b 404
AnnaBridge 143:86740a56073b 405 /**
AnnaBridge 143:86740a56073b 406 * @brief Function for getting a specific timer compare event.
AnnaBridge 143:86740a56073b 407 *
AnnaBridge 143:86740a56073b 408 * @param[in] channel Compare channel.
AnnaBridge 143:86740a56073b 409 *
AnnaBridge 143:86740a56073b 410 * @return Compare event.
AnnaBridge 143:86740a56073b 411 */
AnnaBridge 143:86740a56073b 412 __STATIC_INLINE nrf_timer_event_t nrf_timer_compare_event_get(uint32_t channel);
AnnaBridge 143:86740a56073b 413
AnnaBridge 143:86740a56073b 414 /**
AnnaBridge 143:86740a56073b 415 * @brief Function for getting a specific timer compare interrupt.
AnnaBridge 143:86740a56073b 416 *
AnnaBridge 143:86740a56073b 417 * @param[in] channel Compare channel.
AnnaBridge 143:86740a56073b 418 *
AnnaBridge 143:86740a56073b 419 * @return Compare interrupt.
AnnaBridge 143:86740a56073b 420 */
AnnaBridge 143:86740a56073b 421 __STATIC_INLINE nrf_timer_int_mask_t nrf_timer_compare_int_get(uint32_t channel);
AnnaBridge 143:86740a56073b 422
AnnaBridge 143:86740a56073b 423 /**
AnnaBridge 143:86740a56073b 424 * @brief Function for calculating the number of timer ticks for a given time
AnnaBridge 143:86740a56073b 425 * (in microseconds) and timer frequency.
AnnaBridge 143:86740a56073b 426 *
AnnaBridge 143:86740a56073b 427 * @param[in] time_us Time in microseconds.
AnnaBridge 143:86740a56073b 428 * @param[in] frequency Timer frequency.
AnnaBridge 143:86740a56073b 429 *
AnnaBridge 143:86740a56073b 430 * @return Number of timer ticks.
AnnaBridge 143:86740a56073b 431 */
AnnaBridge 143:86740a56073b 432 __STATIC_INLINE uint32_t nrf_timer_us_to_ticks(uint32_t time_us,
AnnaBridge 143:86740a56073b 433 nrf_timer_frequency_t frequency);
AnnaBridge 143:86740a56073b 434
AnnaBridge 143:86740a56073b 435 /**
AnnaBridge 143:86740a56073b 436 * @brief Function for calculating the number of timer ticks for a given time
AnnaBridge 143:86740a56073b 437 * (in milliseconds) and timer frequency.
AnnaBridge 143:86740a56073b 438 *
AnnaBridge 143:86740a56073b 439 * @param[in] time_ms Time in milliseconds.
AnnaBridge 143:86740a56073b 440 * @param[in] frequency Timer frequency.
AnnaBridge 143:86740a56073b 441 *
AnnaBridge 143:86740a56073b 442 * @return Number of timer ticks.
AnnaBridge 143:86740a56073b 443 */
AnnaBridge 143:86740a56073b 444 __STATIC_INLINE uint32_t nrf_timer_ms_to_ticks(uint32_t time_ms,
AnnaBridge 143:86740a56073b 445 nrf_timer_frequency_t frequency);
AnnaBridge 143:86740a56073b 446
AnnaBridge 143:86740a56073b 447
AnnaBridge 143:86740a56073b 448 #ifndef SUPPRESS_INLINE_IMPLEMENTATION
AnnaBridge 143:86740a56073b 449
AnnaBridge 143:86740a56073b 450 __STATIC_INLINE void nrf_timer_task_trigger(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 451 nrf_timer_task_t task)
AnnaBridge 143:86740a56073b 452 {
AnnaBridge 143:86740a56073b 453 *((volatile uint32_t *)((uint8_t *)p_timer + (uint32_t)task)) = 0x1UL;
AnnaBridge 143:86740a56073b 454 }
AnnaBridge 143:86740a56073b 455
AnnaBridge 143:86740a56073b 456 __STATIC_INLINE uint32_t * nrf_timer_task_address_get(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 457 nrf_timer_task_t task)
AnnaBridge 143:86740a56073b 458 {
AnnaBridge 143:86740a56073b 459 return (uint32_t *)((uint8_t *)p_timer + (uint32_t)task);
AnnaBridge 143:86740a56073b 460 }
AnnaBridge 143:86740a56073b 461
AnnaBridge 143:86740a56073b 462 __STATIC_INLINE void nrf_timer_event_clear(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 463 nrf_timer_event_t event)
AnnaBridge 143:86740a56073b 464 {
AnnaBridge 143:86740a56073b 465 *((volatile uint32_t *)((uint8_t *)p_timer + (uint32_t)event)) = 0x0UL;
AnnaBridge 143:86740a56073b 466 }
AnnaBridge 143:86740a56073b 467
AnnaBridge 143:86740a56073b 468 __STATIC_INLINE bool nrf_timer_event_check(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 469 nrf_timer_event_t event)
AnnaBridge 143:86740a56073b 470 {
AnnaBridge 143:86740a56073b 471 return (bool)*(volatile uint32_t *)((uint8_t *)p_timer + (uint32_t)event);
AnnaBridge 143:86740a56073b 472 }
AnnaBridge 143:86740a56073b 473
AnnaBridge 143:86740a56073b 474 __STATIC_INLINE uint32_t * nrf_timer_event_address_get(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 475 nrf_timer_event_t event)
AnnaBridge 143:86740a56073b 476 {
AnnaBridge 143:86740a56073b 477 return (uint32_t *)((uint8_t *)p_timer + (uint32_t)event);
AnnaBridge 143:86740a56073b 478 }
AnnaBridge 143:86740a56073b 479
AnnaBridge 143:86740a56073b 480 __STATIC_INLINE void nrf_timer_shorts_enable(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 481 uint32_t timer_shorts_mask)
AnnaBridge 143:86740a56073b 482 {
AnnaBridge 143:86740a56073b 483 p_timer->SHORTS |= timer_shorts_mask;
AnnaBridge 143:86740a56073b 484 }
AnnaBridge 143:86740a56073b 485
AnnaBridge 143:86740a56073b 486 __STATIC_INLINE void nrf_timer_shorts_disable(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 487 uint32_t timer_shorts_mask)
AnnaBridge 143:86740a56073b 488 {
AnnaBridge 143:86740a56073b 489 p_timer->SHORTS &= ~(timer_shorts_mask);
AnnaBridge 143:86740a56073b 490 }
AnnaBridge 143:86740a56073b 491
AnnaBridge 143:86740a56073b 492 __STATIC_INLINE void nrf_timer_int_enable(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 493 uint32_t timer_int_mask)
AnnaBridge 143:86740a56073b 494 {
AnnaBridge 143:86740a56073b 495 p_timer->INTENSET = timer_int_mask;
AnnaBridge 143:86740a56073b 496 }
AnnaBridge 143:86740a56073b 497
AnnaBridge 143:86740a56073b 498 __STATIC_INLINE void nrf_timer_int_disable(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 499 uint32_t timer_int_mask)
AnnaBridge 143:86740a56073b 500 {
AnnaBridge 143:86740a56073b 501 p_timer->INTENCLR = timer_int_mask;
AnnaBridge 143:86740a56073b 502 }
AnnaBridge 143:86740a56073b 503
AnnaBridge 143:86740a56073b 504 __STATIC_INLINE bool nrf_timer_int_enable_check(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 505 uint32_t timer_int)
AnnaBridge 143:86740a56073b 506 {
AnnaBridge 143:86740a56073b 507 return (bool)(p_timer->INTENSET & timer_int);
AnnaBridge 143:86740a56073b 508 }
AnnaBridge 143:86740a56073b 509
AnnaBridge 143:86740a56073b 510 __STATIC_INLINE void nrf_timer_mode_set(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 511 nrf_timer_mode_t mode)
AnnaBridge 143:86740a56073b 512 {
AnnaBridge 143:86740a56073b 513 p_timer->MODE = (p_timer->MODE & ~TIMER_MODE_MODE_Msk) |
AnnaBridge 143:86740a56073b 514 ((mode << TIMER_MODE_MODE_Pos) & TIMER_MODE_MODE_Msk);
AnnaBridge 143:86740a56073b 515 }
AnnaBridge 143:86740a56073b 516
AnnaBridge 143:86740a56073b 517 __STATIC_INLINE nrf_timer_mode_t nrf_timer_mode_get(NRF_TIMER_Type * p_timer)
AnnaBridge 143:86740a56073b 518 {
AnnaBridge 143:86740a56073b 519 return (nrf_timer_mode_t)(p_timer->MODE);
AnnaBridge 143:86740a56073b 520 }
AnnaBridge 143:86740a56073b 521
AnnaBridge 143:86740a56073b 522 __STATIC_INLINE void nrf_timer_bit_width_set(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 523 nrf_timer_bit_width_t bit_width)
AnnaBridge 143:86740a56073b 524 {
AnnaBridge 143:86740a56073b 525 p_timer->BITMODE = (p_timer->BITMODE & ~TIMER_BITMODE_BITMODE_Msk) |
AnnaBridge 143:86740a56073b 526 ((bit_width << TIMER_BITMODE_BITMODE_Pos) &
AnnaBridge 143:86740a56073b 527 TIMER_BITMODE_BITMODE_Msk);
AnnaBridge 143:86740a56073b 528 }
AnnaBridge 143:86740a56073b 529
AnnaBridge 143:86740a56073b 530 __STATIC_INLINE nrf_timer_bit_width_t nrf_timer_bit_width_get(NRF_TIMER_Type * p_timer)
AnnaBridge 143:86740a56073b 531 {
AnnaBridge 143:86740a56073b 532 return (nrf_timer_bit_width_t)(p_timer->BITMODE);
AnnaBridge 143:86740a56073b 533 }
AnnaBridge 143:86740a56073b 534
AnnaBridge 143:86740a56073b 535 __STATIC_INLINE void nrf_timer_frequency_set(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 536 nrf_timer_frequency_t frequency)
AnnaBridge 143:86740a56073b 537 {
AnnaBridge 143:86740a56073b 538 p_timer->PRESCALER = (p_timer->PRESCALER & ~TIMER_PRESCALER_PRESCALER_Msk) |
AnnaBridge 143:86740a56073b 539 ((frequency << TIMER_PRESCALER_PRESCALER_Pos) &
AnnaBridge 143:86740a56073b 540 TIMER_PRESCALER_PRESCALER_Msk);
AnnaBridge 143:86740a56073b 541 }
AnnaBridge 143:86740a56073b 542
AnnaBridge 143:86740a56073b 543 __STATIC_INLINE nrf_timer_frequency_t nrf_timer_frequency_get(NRF_TIMER_Type * p_timer)
AnnaBridge 143:86740a56073b 544 {
AnnaBridge 143:86740a56073b 545 return (nrf_timer_frequency_t)(p_timer->PRESCALER);
AnnaBridge 143:86740a56073b 546 }
AnnaBridge 143:86740a56073b 547
AnnaBridge 143:86740a56073b 548 __STATIC_INLINE void nrf_timer_cc_write(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 549 nrf_timer_cc_channel_t cc_channel,
AnnaBridge 143:86740a56073b 550 uint32_t cc_value)
AnnaBridge 143:86740a56073b 551 {
AnnaBridge 143:86740a56073b 552 p_timer->CC[cc_channel] = cc_value;
AnnaBridge 143:86740a56073b 553 }
AnnaBridge 143:86740a56073b 554
AnnaBridge 143:86740a56073b 555 __STATIC_INLINE uint32_t nrf_timer_cc_read(NRF_TIMER_Type * p_timer,
AnnaBridge 143:86740a56073b 556 nrf_timer_cc_channel_t cc_channel)
AnnaBridge 143:86740a56073b 557 {
AnnaBridge 143:86740a56073b 558 return (uint32_t)p_timer->CC[cc_channel];
AnnaBridge 143:86740a56073b 559 }
AnnaBridge 143:86740a56073b 560
AnnaBridge 143:86740a56073b 561 __STATIC_INLINE nrf_timer_task_t nrf_timer_capture_task_get(uint32_t channel)
AnnaBridge 143:86740a56073b 562 {
AnnaBridge 143:86740a56073b 563 return (nrf_timer_task_t)
AnnaBridge 143:86740a56073b 564 ((uint32_t)NRF_TIMER_TASK_CAPTURE0 + (channel * sizeof(uint32_t)));
AnnaBridge 143:86740a56073b 565 }
AnnaBridge 143:86740a56073b 566
AnnaBridge 143:86740a56073b 567 __STATIC_INLINE nrf_timer_event_t nrf_timer_compare_event_get(uint32_t channel)
AnnaBridge 143:86740a56073b 568 {
AnnaBridge 143:86740a56073b 569 return (nrf_timer_event_t)
AnnaBridge 143:86740a56073b 570 ((uint32_t)NRF_TIMER_EVENT_COMPARE0 + (channel * sizeof(uint32_t)));
AnnaBridge 143:86740a56073b 571 }
AnnaBridge 143:86740a56073b 572
AnnaBridge 143:86740a56073b 573 __STATIC_INLINE nrf_timer_int_mask_t nrf_timer_compare_int_get(uint32_t channel)
AnnaBridge 143:86740a56073b 574 {
AnnaBridge 143:86740a56073b 575 return (nrf_timer_int_mask_t)
AnnaBridge 143:86740a56073b 576 ((uint32_t)NRF_TIMER_INT_COMPARE0_MASK << channel);
AnnaBridge 143:86740a56073b 577 }
AnnaBridge 143:86740a56073b 578
AnnaBridge 143:86740a56073b 579 __STATIC_INLINE uint32_t nrf_timer_us_to_ticks(uint32_t time_us,
AnnaBridge 143:86740a56073b 580 nrf_timer_frequency_t frequency)
AnnaBridge 143:86740a56073b 581 {
AnnaBridge 143:86740a56073b 582 // The "frequency" parameter here is actually the prescaler value, and the
AnnaBridge 143:86740a56073b 583 // timer runs at the following frequency: f = 16 MHz / 2^prescaler.
AnnaBridge 143:86740a56073b 584 uint32_t prescaler = (uint32_t)frequency;
AnnaBridge 143:86740a56073b 585 ASSERT(time_us <= (UINT32_MAX / 16UL));
AnnaBridge 143:86740a56073b 586 return ((time_us * 16UL) >> prescaler);
AnnaBridge 143:86740a56073b 587 }
AnnaBridge 143:86740a56073b 588
AnnaBridge 143:86740a56073b 589 __STATIC_INLINE uint32_t nrf_timer_ms_to_ticks(uint32_t time_ms,
AnnaBridge 143:86740a56073b 590 nrf_timer_frequency_t frequency)
AnnaBridge 143:86740a56073b 591 {
AnnaBridge 143:86740a56073b 592 // The "frequency" parameter here is actually the prescaler value, and the
AnnaBridge 143:86740a56073b 593 // timer runs at the following frequency: f = 16000 kHz / 2^prescaler.
AnnaBridge 143:86740a56073b 594 uint32_t prescaler = (uint32_t)frequency;
AnnaBridge 143:86740a56073b 595 ASSERT(time_ms <= (UINT32_MAX / 16000UL));
AnnaBridge 143:86740a56073b 596 return ((time_ms * 16000UL) >> prescaler);
AnnaBridge 143:86740a56073b 597 }
AnnaBridge 143:86740a56073b 598
AnnaBridge 143:86740a56073b 599 #endif // SUPPRESS_INLINE_IMPLEMENTATION
AnnaBridge 143:86740a56073b 600
AnnaBridge 143:86740a56073b 601 #endif // NRF_TIMER_H__
AnnaBridge 143:86740a56073b 602
AnnaBridge 143:86740a56073b 603 /** @} */