1*150812a8SEvalZero /* 2*150812a8SEvalZero * Copyright (c) 2016 - 2018, Nordic Semiconductor ASA 3*150812a8SEvalZero * All rights reserved. 4*150812a8SEvalZero * 5*150812a8SEvalZero * Redistribution and use in source and binary forms, with or without 6*150812a8SEvalZero * modification, are permitted provided that the following conditions are met: 7*150812a8SEvalZero * 8*150812a8SEvalZero * 1. Redistributions of source code must retain the above copyright notice, this 9*150812a8SEvalZero * list of conditions and the following disclaimer. 10*150812a8SEvalZero * 11*150812a8SEvalZero * 2. Redistributions in binary form must reproduce the above copyright 12*150812a8SEvalZero * notice, this list of conditions and the following disclaimer in the 13*150812a8SEvalZero * documentation and/or other materials provided with the distribution. 14*150812a8SEvalZero * 15*150812a8SEvalZero * 3. Neither the name of the copyright holder nor the names of its 16*150812a8SEvalZero * contributors may be used to endorse or promote products derived from this 17*150812a8SEvalZero * software without specific prior written permission. 18*150812a8SEvalZero * 19*150812a8SEvalZero * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20*150812a8SEvalZero * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21*150812a8SEvalZero * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22*150812a8SEvalZero * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23*150812a8SEvalZero * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24*150812a8SEvalZero * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25*150812a8SEvalZero * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26*150812a8SEvalZero * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27*150812a8SEvalZero * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28*150812a8SEvalZero * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29*150812a8SEvalZero * POSSIBILITY OF SUCH DAMAGE. 30*150812a8SEvalZero */ 31*150812a8SEvalZero 32*150812a8SEvalZero #ifndef NRFX_SYSTICK_H__ 33*150812a8SEvalZero #define NRFX_SYSTICK_H__ 34*150812a8SEvalZero 35*150812a8SEvalZero #include <nrfx.h> 36*150812a8SEvalZero #include <hal/nrf_systick.h> 37*150812a8SEvalZero 38*150812a8SEvalZero #ifdef __cplusplus 39*150812a8SEvalZero extern "C" { 40*150812a8SEvalZero #endif 41*150812a8SEvalZero 42*150812a8SEvalZero /** 43*150812a8SEvalZero * @defgroup nrfx_systick ARM(R) SysTick driver 44*150812a8SEvalZero * @{ 45*150812a8SEvalZero * @ingroup nrf_systick 46*150812a8SEvalZero * 47*150812a8SEvalZero * @brief ARM(R) SysTick driver. 48*150812a8SEvalZero * 49*150812a8SEvalZero * This driver configures ARM(R) SysTick as a free-running timer. 50*150812a8SEvalZero * This timer is used to generate delays and pool for timeouts. 51*150812a8SEvalZero * Only relatively short timeouts are supported. 52*150812a8SEvalZero * The SysTick works on 64MHz and is 24-bits wide. 53*150812a8SEvalZero * It means that it overflows around 4 times per second and around 250 ms 54*150812a8SEvalZero * would be the highest supported time in the library. 55*150812a8SEvalZero * But it would be really hard to detect if overflow was generated without 56*150812a8SEvalZero * using interrupts. For safety we would limit the maximum delay range by half. 57*150812a8SEvalZero */ 58*150812a8SEvalZero 59*150812a8SEvalZero /** 60*150812a8SEvalZero * @brief The value type that holds the SysTick state 61*150812a8SEvalZero * 62*150812a8SEvalZero * This variable is used to count the requested timeout. 63*150812a8SEvalZero * @sa nrfx_systick_get 64*150812a8SEvalZero */ 65*150812a8SEvalZero typedef struct { 66*150812a8SEvalZero uint32_t time; //!< Registered time value 67*150812a8SEvalZero } nrfx_systick_state_t; 68*150812a8SEvalZero 69*150812a8SEvalZero /** 70*150812a8SEvalZero * @brief Configure and start the timer 71*150812a8SEvalZero * 72*150812a8SEvalZero * Function configures SysTick as a free-running timer without interrupt. 73*150812a8SEvalZero */ 74*150812a8SEvalZero void nrfx_systick_init(void); 75*150812a8SEvalZero 76*150812a8SEvalZero /** 77*150812a8SEvalZero * @brief Get current SysTick state 78*150812a8SEvalZero * 79*150812a8SEvalZero * Function gets current state of the SysTick timer. 80*150812a8SEvalZero * It can be used to check time-out by @ref nrfx_systick_test. 81*150812a8SEvalZero * 82*150812a8SEvalZero * @param[out] p_state The pointer to the state variable to be filled 83*150812a8SEvalZero */ 84*150812a8SEvalZero void nrfx_systick_get(nrfx_systick_state_t * p_state); 85*150812a8SEvalZero 86*150812a8SEvalZero /** 87*150812a8SEvalZero * @brief Test if specified time is up in relation to remembered state 88*150812a8SEvalZero * 89*150812a8SEvalZero * @param[in] p_state Remembered state set by @ref nrfx_systick_get 90*150812a8SEvalZero * @param[in] us Required time-out. 91*150812a8SEvalZero * 92*150812a8SEvalZero * @retval true If current time is higher than specified state plus given time-out. 93*150812a8SEvalZero * @retval false If current time is lower than specified state plus given time-out 94*150812a8SEvalZero */ 95*150812a8SEvalZero bool nrfx_systick_test(nrfx_systick_state_t const * p_state, uint32_t us); 96*150812a8SEvalZero 97*150812a8SEvalZero /** 98*150812a8SEvalZero * @brief Blocking delay in CPU ticks 99*150812a8SEvalZero * 100*150812a8SEvalZero * @param[in] ticks Number of CPU ticks to delay. 101*150812a8SEvalZero */ 102*150812a8SEvalZero void nrfx_systick_delay_ticks(uint32_t ticks); 103*150812a8SEvalZero 104*150812a8SEvalZero /** 105*150812a8SEvalZero * @brief Blocking delay in us 106*150812a8SEvalZero * 107*150812a8SEvalZero * @param[in] us Number of microseconds to delay. 108*150812a8SEvalZero */ 109*150812a8SEvalZero void nrfx_systick_delay_us(uint32_t us); 110*150812a8SEvalZero 111*150812a8SEvalZero /** 112*150812a8SEvalZero * @brief Blocking delay in ms 113*150812a8SEvalZero * 114*150812a8SEvalZero * This delay function removes the limits of the highest possible delay value. 115*150812a8SEvalZero * 116*150812a8SEvalZero * @param[in] ms Number of milliseconds to delay. 117*150812a8SEvalZero */ 118*150812a8SEvalZero void nrfx_systick_delay_ms(uint32_t ms); 119*150812a8SEvalZero 120*150812a8SEvalZero /** @} */ 121*150812a8SEvalZero 122*150812a8SEvalZero #ifdef __cplusplus 123*150812a8SEvalZero } 124*150812a8SEvalZero #endif 125*150812a8SEvalZero 126*150812a8SEvalZero #endif /* NRFX_SYSTICK_H__ */ 127