nrfx_systick.h 4.4 KB

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