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