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