fsl_utick.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Copyright (c) 2016, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2017 NXP
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * o Redistributions of source code must retain the above copyright notice, this list
  9. * of conditions and the following disclaimer.
  10. *
  11. * o Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * o 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" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef _FSL_UTICK_H_
  31. #define _FSL_UTICK_H_
  32. #include "fsl_common.h"
  33. /*!
  34. * @addtogroup utick
  35. * @{
  36. */
  37. /*! @file*/
  38. /*******************************************************************************
  39. * Definitions
  40. ******************************************************************************/
  41. /*! @name Driver version */
  42. /*@{*/
  43. /*! @brief UTICK driver version 2.0.0. */
  44. #define FSL_UTICK_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
  45. /*@}*/
  46. /*! @brief UTICK timer operational mode. */
  47. typedef enum _utick_mode
  48. {
  49. kUTICK_Onetime = 0x0U, /*!< Trigger once*/
  50. kUTICK_Repeat = 0x1U, /*!< Trigger repeatedly */
  51. } utick_mode_t;
  52. /*! @brief UTICK callback function. */
  53. typedef void (*utick_callback_t)(void);
  54. /*******************************************************************************
  55. * API
  56. ******************************************************************************/
  57. #if defined(__cplusplus)
  58. extern "C" {
  59. #endif /* _cplusplus */
  60. /*!
  61. * @name Initialization and deinitialization
  62. * @{
  63. */
  64. /*!
  65. * @brief Initializes an UTICK by turning its bus clock on
  66. *
  67. */
  68. void UTICK_Init(UTICK_Type *base);
  69. /*!
  70. * @brief Deinitializes a UTICK instance.
  71. *
  72. * This function shuts down Utick bus clock
  73. *
  74. * @param base UTICK peripheral base address.
  75. */
  76. void UTICK_Deinit(UTICK_Type *base);
  77. /*!
  78. * @brief Get Status Flags.
  79. *
  80. * This returns the status flag
  81. *
  82. * @param base UTICK peripheral base address.
  83. * @return status register value
  84. */
  85. uint32_t UTICK_GetStatusFlags(UTICK_Type *base);
  86. /*!
  87. * @brief Clear Status Interrupt Flags.
  88. *
  89. * This clears intr status flag
  90. *
  91. * @param base UTICK peripheral base address.
  92. * @return none
  93. */
  94. void UTICK_ClearStatusFlags(UTICK_Type *base);
  95. /*!
  96. * @brief Starts UTICK.
  97. *
  98. * This function starts a repeat/onetime countdown with an optional callback
  99. *
  100. * @param base UTICK peripheral base address.
  101. * @param mode UTICK timer mode (ie kUTICK_onetime or kUTICK_repeat)
  102. * @param count UTICK timer mode (ie kUTICK_onetime or kUTICK_repeat)
  103. * @param cb UTICK callback (can be left as NULL if none, otherwise should be a void func(void))
  104. * @return none
  105. */
  106. void UTICK_SetTick(UTICK_Type *base, utick_mode_t mode, uint32_t count, utick_callback_t cb);
  107. /*!
  108. * @brief UTICK Interrupt Service Handler.
  109. *
  110. * This function handles the interrupt and refers to the callback array in the driver to callback user (as per request
  111. * in UTICK_SetTick()).
  112. * if no user callback is scheduled, the interrupt will simply be cleared.
  113. *
  114. * @param base UTICK peripheral base address.
  115. * @param cb callback scheduled for this instance of UTICK
  116. * @return none
  117. */
  118. void UTICK_HandleIRQ(UTICK_Type *base, utick_callback_t cb);
  119. /* @} */
  120. #if defined(__cplusplus)
  121. }
  122. #endif
  123. /*! @}*/
  124. #endif /* _FSL_UTICK_H_ */