wkt_8xx.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * @brief LPC8xx Self Wakeup Timer (WKT) chip driver
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2012
  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 __WKT_8XX_H_
  32. #define __WKT_8XX_H_
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /** @defgroup WKT_8XX CHIP: LPC8xx Self Wakeup Timer driver
  37. * @ingroup CHIP_8XX_Drivers
  38. * @{
  39. */
  40. /**
  41. * @brief Self wake-up timer register block structure
  42. */
  43. typedef struct {
  44. __IO uint32_t CTRL; /*!< Offset: 0x000 Alarm/Wakeup Timer Control register */
  45. uint32_t Reserved[2];
  46. __IO uint32_t COUNT; /*!< Offset: 0x000C Alarm/Wakeup Timer Counter register */
  47. } LPC_WKT_T;
  48. #define WKT_CTRL_RESERVED (~7)
  49. /**
  50. * WKT Control register bit fields & masks
  51. */
  52. #define WKT_CTRL_CLKSEL ((uint32_t) (1 << 0)) /*!< Select the self wake-up timer clock source */
  53. #define WKT_CTRL_ALARMFLAG ((uint32_t) (1 << 1)) /*!< Wake-up or alarm timer flag */
  54. #define WKT_CTRL_CLEARCTR ((uint32_t) (1 << 2)) /*!< Clears the self wake-up timer */
  55. /**
  56. * WKT Clock source values enum
  57. */
  58. typedef enum {
  59. WKT_CLKSRC_DIVIRC = 0, /*!< Divided IRC clock - runs at 750kHz */
  60. WKT_CLKSRC_10KHZ = 1 /*!< Low power clock - runs at 10kHz */
  61. } WKT_CLKSRC_T;
  62. /**
  63. * @brief Get clock source for WKT
  64. * @param pWKT : Pointer to WKT register block
  65. * @return Clock source for the WKT
  66. */
  67. STATIC INLINE WKT_CLKSRC_T Chip_WKT_GetClockSource(LPC_WKT_T *pWKT)
  68. {
  69. return (WKT_CLKSRC_T) (pWKT->CTRL & WKT_CTRL_CLKSEL);
  70. }
  71. /**
  72. * @brief Set clock source for WKT
  73. * @param pWKT : Pointer to WKT register block
  74. * @param clkSrc : Clock source for the WKT
  75. * @return Nothing
  76. */
  77. void Chip_WKT_SetClockSource(LPC_WKT_T *pWKT, WKT_CLKSRC_T clkSrc);
  78. /**
  79. * @brief Return approximate rate for the selected clock source
  80. * @param pWKT : Pointer to WKT register block
  81. * @return Clock rate of the selected clock source for WKT
  82. */
  83. uint32_t Chip_WKT_GetClockRate(LPC_WKT_T *pWKT);
  84. /**
  85. * @brief Get WKT interrupt pending status (ALARMFLAG)
  86. * @param pWKT : Pointer to WKT register block
  87. * @return True if the interrupt is pending, otherwise false
  88. */
  89. STATIC INLINE bool Chip_WKT_GetIntStatus(LPC_WKT_T *pWKT)
  90. {
  91. return (bool) ((pWKT->CTRL & WKT_CTRL_ALARMFLAG) != 0);
  92. }
  93. /**
  94. * @brief Clear WKT interrupt status (ALARMFLAG)
  95. * @param pWKT : Pointer to WKT register block
  96. * @return Nothing
  97. */
  98. STATIC INLINE void Chip_WKT_ClearIntStatus(LPC_WKT_T *pWKT)
  99. {
  100. pWKT->CTRL = WKT_CTRL_ALARMFLAG | (pWKT->CTRL & ~WKT_CTRL_RESERVED);
  101. }
  102. /**
  103. * @brief Clear and stop WKT counter
  104. * @param pWKT : Pointer to WKT register block
  105. * @return Nothing
  106. */
  107. STATIC INLINE void Chip_WKT_Stop(LPC_WKT_T *pWKT)
  108. {
  109. pWKT->CTRL = WKT_CTRL_CLEARCTR | (pWKT->CTRL & ~WKT_CTRL_RESERVED);
  110. }
  111. /**
  112. * @brief Load count register and start count-down sequence
  113. * @param pWKT : Pointer to WKT register block
  114. * @param count : Count to load in the WKT
  115. * @return Nothing
  116. * @note This function should not be called if the WKT is already counting.
  117. */
  118. STATIC INLINE void Chip_WKT_LoadCount(LPC_WKT_T *pWKT, uint32_t count)
  119. {
  120. pWKT->COUNT = count;
  121. }
  122. /**
  123. * @brief Start wake-up timer interrupt, set clock source, set timer interval
  124. * @param pWKT : Pointer to WKT register block
  125. * @param clkSrc : Clock source
  126. * @param cntVal : Timer interval
  127. * @return None
  128. * @note This function should not be called if the WKT is already counting.
  129. */
  130. void Chip_WKT_Start(LPC_WKT_T *pWKT, WKT_CLKSRC_T clkSrc, uint32_t cntVal);
  131. /**
  132. * @}
  133. */
  134. #ifdef __cplusplus
  135. }
  136. #endif
  137. #endif /* __WKT_8XX_H_ */