mxc_delay.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /**
  2. * @file
  3. * @brief Asynchronous delay routines based on the SysTick Timer.
  4. */
  5. /* ****************************************************************************
  6. * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a
  9. * copy of this software and associated documentation files (the "Software"),
  10. * to deal in the Software without restriction, including without limitation
  11. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  12. * and/or sell copies of the Software, and to permit persons to whom the
  13. * Software is furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included
  16. * in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  21. * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
  22. * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  23. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  24. * OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. * Except as contained in this notice, the name of Maxim Integrated
  27. * Products, Inc. shall not be used except as stated in the Maxim Integrated
  28. * Products, Inc. Branding Policy.
  29. *
  30. * The mere transfer of this software does not imply any licenses
  31. * of trade secrets, proprietary technology, copyrights, patents,
  32. * trademarks, maskwork rights, or any other form of intellectual
  33. * property whatsoever. Maxim Integrated Products, Inc. retains all
  34. * ownership rights.
  35. *
  36. * $Date: 2018-11-05 09:52:05 -0600 (Mon, 05 Nov 2018) $
  37. * $Revision: 38934 $
  38. *
  39. *************************************************************************** */
  40. /* Define to prevent redundant inclusion */
  41. #ifndef _DELAY_H_
  42. #define _DELAY_H_
  43. /**
  44. * @defgroup MXC_delay Delay Utility Functions
  45. * @ingroup devicelibs
  46. * @brief Asynchronous delay routines based on the SysTick Timer
  47. * @{
  48. */
  49. /***** Definitions *****/
  50. /**
  51. * Macro used to specify a microsecond timing parameter in seconds.
  52. * \code
  53. * x = SEC(3) // 3 seconds -> x = 3,000,000
  54. * \endcode
  55. */
  56. #define MXC_DELAY_SEC(s) (((unsigned long)s) * 1000000UL)
  57. /**
  58. * Macro used to specify a microsecond timing parameter in milliseconds.
  59. * \code
  60. * x = MSEC(3) // 3ms -> x = 3,000
  61. * \endcode
  62. */
  63. #define MXC_DELAY_MSEC(ms) (ms * 1000UL)
  64. /**
  65. * Macro used to specify a microsecond timing parameter.
  66. * \code
  67. * x = USEC(3) // 3us -> x = 3
  68. * \endcode
  69. */
  70. #define MXC_DELAY_USEC(us) (us)
  71. /***** Function Prototypes *****/
  72. /**
  73. * @brief Blocks and delays for the specified number of microseconds.
  74. * @details Uses the SysTick to create the requested delay. If the SysTick is
  75. * running, the current settings will be used. If the SysTick is not
  76. * running, it will be started.
  77. * @param us microseconds to delay
  78. * @return #E_NO_ERROR if no errors, @ref MXC_Error_Codes "error" if unsuccessful.
  79. */
  80. int mxc_delay(unsigned long us);
  81. /**
  82. * @brief Starts a non-blocking delay for the specified number of
  83. * microseconds.
  84. * @details Uses the SysTick to time the requested delay. If the SysTick is
  85. * running, the current settings will be used. If the SysTick is not
  86. * running, it will be started.
  87. * @note mxc_delay_handler() must be called from the SysTick interrupt service
  88. * routine or at a rate greater than the SysTick overflow rate.
  89. * @param us microseconds to delay
  90. * @return #E_NO_ERROR if no errors, #E_BUSY if currently servicing another
  91. * delay request.
  92. */
  93. int mxc_delay_start(unsigned long us);
  94. /**
  95. * @brief Returns the status of a non-blocking delay request
  96. * @pre Start the asynchronous delay by calling mxc_delay_start().
  97. * @return #E_BUSY until the requested delay time has expired.
  98. */
  99. int mxc_delay_check(void);
  100. /**
  101. * @brief Stops an asynchronous delay previously started.
  102. * @pre Start the asynchronous delay by calling mxc_delay_start().
  103. */
  104. void mxc_delay_stop(void);
  105. /**
  106. * @brief Processes the delay interrupt.
  107. * @details This function must be called from the SysTick IRQ or polled at a
  108. * rate greater than the SysTick overflow rate.
  109. */
  110. void mxc_delay_handler(void);
  111. /**@} end of group MXC_delay */
  112. #endif /* _DELAY_H_ */