utick_5410x.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * @brief LPC5410X Micro Tick chip driver
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2014
  6. * All rights reserved.
  7. *
  8. * @par
  9. * Software that is described herein is for illustrative purposes only
  10. * which provides customers with programming information regarding the
  11. * LPC products. This software is supplied "AS IS" without any warranties of
  12. * any kind, and NXP Semiconductors and its licensor disclaim any and
  13. * all warranties, express or implied, including all implied warranties of
  14. * merchantability, fitness for a particular purpose and non-infringement of
  15. * intellectual property rights. NXP Semiconductors assumes no responsibility
  16. * or liability for the use of the software, conveys no license or rights under any
  17. * patent, copyright, mask work right, or any other intellectual property rights in
  18. * or to any products. NXP Semiconductors reserves the right to make changes
  19. * in the software without notification. NXP Semiconductors also makes no
  20. * representation or warranty that such application will be suitable for the
  21. * specified use without further testing or modification.
  22. *
  23. * @par
  24. * Permission to use, copy, modify, and distribute this software and its
  25. * documentation is hereby granted, under NXP Semiconductors' and its
  26. * licensor's relevant copyrights in the software, without fee, provided that it
  27. * is used in conjunction with NXP Semiconductors microcontrollers. This
  28. * copyright, permission, and disclaimer notice must appear in all copies of
  29. * this code.
  30. */
  31. #ifndef __UTICK_5410X_H_
  32. #define __UTICK_5410X_H_
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /** @defgroup UTICK_5410X CHIP: LPC5410X Micro Tick driver
  37. * @ingroup CHIP_5410X_DRIVERS
  38. * @{
  39. */
  40. /**
  41. * @brief Micro Tick register block structure
  42. */
  43. typedef struct {
  44. __IO uint32_t CTRL; /*!< UTick Control register */
  45. __IO uint32_t STATUS; /*!< UTick Status register */
  46. } LPC_UTICK_T;
  47. /**
  48. * @brief UTick register definitions
  49. */
  50. /** UTick repeat delay bit */
  51. #define UTICK_CTRL_REPEAT ((uint32_t) 1UL << 31)
  52. /** UTick Delay Value Mask */
  53. #define UTICK_CTRL_DELAY_MASK ((uint32_t) 0x7FFFFFFF)
  54. /** UTick Interrupt Status bit */
  55. #define UTICK_STATUS_INTR ((uint32_t) 1 << 0)
  56. /** UTick Active Status bit */
  57. #define UTICK_STATUS_ACTIVE ((uint32_t) 1 << 1)
  58. /** UTick Status Register Mask */
  59. #define UTICK_STATUS_MASK ((uint32_t) 0x03)
  60. /**
  61. * @brief Initialize the UTICK peripheral
  62. * @param pUTICK : UTICK peripheral selected
  63. * @return Nothing
  64. */
  65. STATIC INLINE void Chip_UTICK_Init(LPC_UTICK_T *pUTICK)
  66. {
  67. Chip_Clock_EnablePeriphClock(SYSCON_CLOCK_UTICK);
  68. Chip_SYSCON_PeriphReset(RESET_UTICK);
  69. }
  70. /**
  71. * @brief De-initialize the UTICK peripheral
  72. * @param pUTICK : UTICK peripheral selected
  73. * @return Nothing
  74. */
  75. STATIC INLINE void Chip_UTICK_DeInit(LPC_UTICK_T *pUTICK)
  76. {
  77. Chip_Clock_DisablePeriphClock(SYSCON_CLOCK_UTICK);
  78. }
  79. /**
  80. * @brief Setup UTICK
  81. * @param pUTICK : The base address of UTICK block
  82. * @param tick_value : Tick value, should not exceed UTICK_CTRL_DELAY_MASK
  83. * @param repeat : If true then delay repeats continuously else it is one time
  84. * @return Nothing
  85. */
  86. void Chip_UTICK_SetTick(LPC_UTICK_T *pUTICK, uint32_t tick_value, bool repeat);
  87. /**
  88. * @brief Setup UTICK for the passed delay (in mS)
  89. * @param pUTICK : The base address of UTICK block
  90. * @param delayMs : Delay value in mS (Maximum is 1000mS)
  91. * @param repeat : If true then delay repeats continuously else it is one time
  92. * @return Nothing
  93. * @note The WDT oscillator runs at about 500KHz, so delays in uS won't be
  94. * too accurate.
  95. */
  96. void Chip_UTICK_SetDelayMs(LPC_UTICK_T *pUTICK, uint32_t delayMs, bool repeat);
  97. /**
  98. * @brief Read UTICK Value
  99. * @param pUTICK : The base address of UTICK block
  100. * @return Current tick value
  101. */
  102. STATIC INLINE uint32_t Chip_UTICK_GetTick(LPC_UTICK_T *pUTICK)
  103. {
  104. return pUTICK->CTRL & UTICK_CTRL_DELAY_MASK;
  105. }
  106. /**
  107. * @brief Halt UTICK timer
  108. * @param pUTICK : The base address of UTICK block
  109. * @return Nothing
  110. */
  111. STATIC INLINE void Chip_UTICK_Halt(LPC_UTICK_T *pUTICK)
  112. {
  113. pUTICK->CTRL = 0;
  114. }
  115. /**
  116. * @brief Returns the status of UTICK
  117. * @param pUTICK : The base address of UTICK block
  118. * @return Micro tick timer status register value
  119. */
  120. STATIC INLINE uint32_t Chip_UTICK_GetStatus(LPC_UTICK_T *pUTICK)
  121. {
  122. return pUTICK->STATUS;
  123. }
  124. /**
  125. * @brief Clears UTICK Interrupt flag
  126. * @param pUTICK : The base address of UTICK block
  127. * @return Nothing
  128. */
  129. STATIC INLINE void Chip_UTICK_ClearInterrupt(LPC_UTICK_T *pUTICK)
  130. {
  131. pUTICK->STATUS = UTICK_STATUS_INTR;
  132. }
  133. /**
  134. * @}
  135. */
  136. #ifdef __cplusplus
  137. }
  138. #endif
  139. #endif /* __UTICK_5410X_H_ */