ald_temp.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /**
  2. *********************************************************************************
  3. *
  4. * @file ald_temp.h
  5. * @brief Header file of TEMP module driver.
  6. *
  7. * @version V1.0
  8. * @date 15 Dec 2017
  9. * @author AE Team
  10. * @note
  11. *
  12. * Copyright (C) Shanghai Eastsoft Microelectronics Co. Ltd. All rights reserved.
  13. *
  14. ********************************************************************************
  15. */
  16. #ifndef __ALD_TEMP_H__
  17. #define __ALD_TEMP_H__
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. #include "utils.h"
  22. /** @addtogroup ES32FXXX_ALD
  23. * @{
  24. */
  25. /** @addtogroup TEMP
  26. * @{
  27. */
  28. /** @defgroup TEMP_Public_Macros TEMP Public Macros
  29. * @{
  30. */
  31. #define TEMP_LOCK() (WRITE_REG(TEMP->WPR, 0x0))
  32. #define TEMP_UNLOCK() (WRITE_REG(TEMP->WPR, 0xA55A9669))
  33. #define TEMP_ENABLE() \
  34. do { \
  35. TEMP_UNLOCK(); \
  36. SET_BIT(TEMP->CR, TEMP_CR_EN_MSK); \
  37. TEMP_LOCK(); \
  38. } while (0)
  39. #define TEMP_DISABLE() \
  40. do { \
  41. TEMP_UNLOCK(); \
  42. CLEAR_BIT(TEMP->CR, TEMP_CR_EN_MSK); \
  43. TEMP_LOCK(); \
  44. } while (0)
  45. #define TEMP_REQ_ENABLE() \
  46. do { \
  47. TEMP_UNLOCK(); \
  48. SET_BIT(TEMP->CR, TEMP_CR_REQEN_MSK); \
  49. TEMP_LOCK(); \
  50. } while (0)
  51. #define TEMP_REQ_DISABLE() \
  52. do { \
  53. TEMP_UNLOCK(); \
  54. CLEAR_BIT(TEMP->CR, TEMP_CR_REQEN_MSK); \
  55. TEMP_LOCK(); \
  56. } while (0)
  57. #define TEMP_CTN_ENABLE() \
  58. do { \
  59. TEMP_UNLOCK(); \
  60. SET_BIT(TEMP->CR, TEMP_CR_CTN_MSK); \
  61. TEMP_LOCK(); \
  62. } while (0)
  63. #define TEMP_CTN_DISABLE() \
  64. do { \
  65. TEMP_UNLOCK(); \
  66. CLEAR_BIT(TEMP->CR, TEMP_CR_CTN_MSK); \
  67. TEMP_LOCK(); \
  68. } while (0)
  69. #define TEMP_RESET() \
  70. do { \
  71. TEMP_UNLOCK(); \
  72. SET_BIT(TEMP->CR, TEMP_CR_RST_MSK); \
  73. TEMP_LOCK(); \
  74. } while (0)
  75. /**
  76. * @}
  77. */
  78. /** @defgroup TEMP_Public_Types TEMP Public Types
  79. * @{
  80. */
  81. /**
  82. * @brief Temperature update time
  83. */
  84. typedef enum {
  85. TEMP_UPDATE_CYCLE_3 = 0x3, /**< 3 Cycles */
  86. TEMP_UPDATE_CYCLE_4 = 0x4, /**< 4 Cycles */
  87. TEMP_UPDATE_CYCLE_5 = 0x5, /**< 5 Cycles */
  88. TEMP_UPDATE_CYCLE_6 = 0x6, /**< 6 Cycles */
  89. TEMP_UPDATE_CYCLE_7 = 0x7, /**< 7 Cycles */
  90. } temp_update_cycle_t;
  91. /**
  92. * @brief Temperature output mode
  93. */
  94. typedef enum {
  95. TEMP_OUTPUT_MODE_200 = 0x0, /**< 200 cycles update one temperature */
  96. TEMP_OUTPUT_MODE_400 = 0x1, /**< 400 cycles update one temperature */
  97. TEMP_OUTPUT_MODE_800 = 0x2, /**< 800 cycles update one temperature */
  98. TEMP_OUTPUT_MODE_1600 = 0x3, /**< 1600 cycles update one temperature */
  99. TEMP_OUTPUT_MODE_3200 = 0x4, /**< 3200 cycles update one temperature */
  100. } temp_output_mode_t;
  101. /**
  102. * @brief Source select
  103. */
  104. typedef enum {
  105. TEMP_SOURCE_LOSC = 0x0, /**< LOSC */
  106. TEMP_SOURCE_LRC = 0x1, /**< LRC */
  107. TEMP_SOURCE_HRC_DIV_1M = 0x2, /**< HRC divide to 1MHz */
  108. TEMP_SOURCE_HOSC_DIV_1M = 0x3, /**< HOSC divide to 1MHz */
  109. } temp_source_sel_t;
  110. /**
  111. * @brief TEMP init structure definition
  112. */
  113. typedef struct {
  114. temp_update_cycle_t cycle; /**< Temperature update time */
  115. temp_output_mode_t mode; /**< Temperature output mode */
  116. uint8_t ctn; /**< Continue mode */
  117. uint8_t psc; /**< Perscaler */
  118. } temp_init_t;
  119. /**
  120. * @brief Define callback function type
  121. */
  122. typedef void (*temp_cbk)(uint16_t value, ald_status_t status);
  123. /**
  124. * @}
  125. */
  126. /**
  127. * @defgroup TEMP_Private_Macros TEMP Private Macros
  128. * @{
  129. */
  130. #define IS_TEMP_UPDATE_CYCLE(x) (((x) == TEMP_UPDATE_CYCLE_3) || \
  131. ((x) == TEMP_UPDATE_CYCLE_4) || \
  132. ((x) == TEMP_UPDATE_CYCLE_5) || \
  133. ((x) == TEMP_UPDATE_CYCLE_6) || \
  134. ((x) == TEMP_UPDATE_CYCLE_7))
  135. #define IS_TEMP_OUTPUT_MODE(x) (((x) == TEMP_OUTPUT_MODE_200) || \
  136. ((x) == TEMP_OUTPUT_MODE_400) || \
  137. ((x) == TEMP_OUTPUT_MODE_800) || \
  138. ((x) == TEMP_OUTPUT_MODE_1600) || \
  139. ((x) == TEMP_OUTPUT_MODE_3200))
  140. #define IS_TEMP_SOURCE_SEL(x) (((x) == TEMP_SOURCE_LOSC) || \
  141. ((x) == TEMP_SOURCE_LRC) || \
  142. ((x) == TEMP_SOURCE_HRC_DIV_1M ) || \
  143. ((x) == TEMP_SOURCE_HOSC_DIV_1M))
  144. /**
  145. * @}
  146. */
  147. /** @addtogroup TEMP_Public_Functions
  148. * @{
  149. */
  150. /** @addtogroup TEMP_Public_Functions_Group1
  151. * @{
  152. */
  153. /* Initialization functions */
  154. extern void temp_init(temp_init_t *init);
  155. extern void temp_source_selcet(temp_source_sel_t sel);
  156. /**
  157. * @}
  158. */
  159. /** @addtogroup TEMP_Public_Functions_Group2
  160. * @{
  161. */
  162. /* Control functions */
  163. extern ald_status_t temp_get_value(uint16_t *temp);
  164. extern void temp_get_value_by_it(temp_cbk cbk);
  165. void temp_irq_handle(void);
  166. /**
  167. * @}
  168. */
  169. /**
  170. * @}
  171. */
  172. /**
  173. * @}
  174. */
  175. /**
  176. * @}
  177. */
  178. #ifdef __cplusplus
  179. }
  180. #endif
  181. #endif /* __ALD_TEMP_H__ */