hc32f4a0_ots.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /**
  2. *******************************************************************************
  3. * @file hc32f4a0_ots.h
  4. * @brief This file contains all the functions prototypes of the OTS driver
  5. * library.
  6. @verbatim
  7. Change Logs:
  8. Date Author Notes
  9. 2020-06-12 Wuze First version
  10. @endverbatim
  11. *******************************************************************************
  12. * Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
  13. *
  14. * This software component is licensed by HDSC under BSD 3-Clause license
  15. * (the "License"); You may not use this file except in compliance with the
  16. * License. You may obtain a copy of the License at:
  17. * opensource.org/licenses/BSD-3-Clause
  18. *
  19. *******************************************************************************
  20. */
  21. #ifndef __HC32F4A0_OTS_H__
  22. #define __HC32F4A0_OTS_H__
  23. /* C binding of definitions if building with C++ compiler */
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #endif
  28. /*******************************************************************************
  29. * Include files
  30. ******************************************************************************/
  31. #include "hc32_common.h"
  32. #include "ddl_config.h"
  33. /**
  34. * @addtogroup HC32F4A0_DDL_Driver
  35. * @{
  36. */
  37. /**
  38. * @addtogroup DDL_OTS
  39. * @{
  40. */
  41. #if (DDL_OTS_ENABLE == DDL_ON)
  42. /*******************************************************************************
  43. * Global type definitions ('typedef')
  44. ******************************************************************************/
  45. /**
  46. * @defgroup OTS_Global_Types OTS Global Types
  47. * @{
  48. */
  49. /**
  50. * @brief Conditions for default parameters(slope K and offset M).
  51. * @note 'u8T1' CANNOT equal 'u8T2'.
  52. */
  53. typedef struct
  54. {
  55. uint16_t u16ClkFreq; /*!< Frequency(MHz) of clock sources that OTS is going to use. */
  56. uint8_t u8T1; /*!< Temperature value T1 for the default parameter.
  57. This parameter can be a value of @ref OTS_Temp_Condition */
  58. uint8_t u8T2; /*!< Temperature value T2 for the default parameter.
  59. This parameter can be a value of @ref OTS_Temp_Condition */
  60. } stc_para_cond_t;
  61. /**
  62. * @brief OTS initialization structure.
  63. */
  64. typedef struct
  65. {
  66. uint16_t u16ClkSrc; /*!< Specifies clock source for OTS.
  67. This parameter can be a value of @ref OTS_Clock_Source */
  68. float32_t f32SlopeK; /*!< K: Temperature slope (calculated by calibration experiment). \
  69. When you want to use the default parameters(slope K and offset M), specify it as ZERO. */
  70. float32_t f32OffsetM; /*!< M: Temperature offset (calculated by calibration experiment). \
  71. When you want to use the default parameters(slope K and offset M), specify it as ZERO. */
  72. uint16_t u16AutoOffEn; /*!< OTS automatic-off function control.
  73. This parameter can be a value of @ref OTS_Automatic_Off_Ctrl */
  74. stc_para_cond_t stcParaCond; /*!< Specify the conditions when you want to use the default parameters(slope K and offset M). */
  75. } stc_ots_init_t;
  76. /**
  77. * @}
  78. */
  79. /*******************************************************************************
  80. * Global pre-processor symbols/macros ('#define')
  81. ******************************************************************************/
  82. /**
  83. * @defgroup OTS_Global_Macros OTS Global Macros
  84. * @{
  85. */
  86. /**
  87. * @defgroup OTS_Clock_Source OTS Clock Source
  88. * @{
  89. */
  90. #define OTS_CLK_XTAL (0x0U) /*!< Select XTAL as OTS clock. */
  91. #define OTS_CLK_HRC (OTS_CTL_OTSCK) /*!< Select HRC as OTS clock */
  92. /**
  93. * @}
  94. */
  95. /**
  96. * @defgroup OTS_Automatic_Off_Ctrl OTS Automatic Off Control
  97. * @{
  98. */
  99. #define OTS_AUTO_OFF_DISABLE (0x0U)
  100. #define OTS_AUTO_OFF_ENABLE (OTS_CTL_TSSTP)
  101. /**
  102. * @}
  103. */
  104. /**
  105. * @defgroup OTS_Temp_Condition OTS Temperature Condition For Default Parameters(slope K and offset M)
  106. * @{
  107. */
  108. #define OTS_COND_TN40 (0U) /*!< -40 degrees Celsius. */
  109. #define OTS_COND_T25 (1U) /*!< 25 degrees Celsius. */
  110. #define OTS_COND_T125 (2U) /*!< 125 degrees Celsius. */
  111. /**
  112. * @}
  113. */
  114. /**
  115. * @defgroup OTS_Common_Trigger_Sel OTS Common Trigger Source Select
  116. * @{
  117. */
  118. #define OTS_COM_TRIG1 (AOS_OTS_TRG_COMTRG_EN_0)
  119. #define OTS_COM_TRIG2 (AOS_OTS_TRG_COMTRG_EN_1)
  120. /**
  121. * @}
  122. */
  123. /**
  124. * @}
  125. */
  126. /*******************************************************************************
  127. * Global variable definitions ('extern')
  128. ******************************************************************************/
  129. /*******************************************************************************
  130. Global function prototypes (definition in C source)
  131. ******************************************************************************/
  132. /**
  133. * @addtogroup OTS_Global_Functions
  134. * @{
  135. */
  136. /**
  137. * @brief Start OTS.
  138. * @param None
  139. * @retval None
  140. */
  141. __STATIC_INLINE void OTS_Start(void)
  142. {
  143. bM4_OTS->CTL_b.OTSST = (uint32_t)1U;
  144. }
  145. /**
  146. * @brief Stop OTS.
  147. * @param None
  148. * @retval None
  149. */
  150. __STATIC_INLINE void OTS_Stop(void)
  151. {
  152. bM4_OTS->CTL_b.OTSST = (uint32_t)0U;
  153. }
  154. en_result_t OTS_Init(const stc_ots_init_t *pstcInit);
  155. en_result_t OTS_StructInit(stc_ots_init_t *pstcInit);
  156. void OTS_DeInit(void);
  157. en_result_t OTS_Polling(float32_t *pf32Temp, uint32_t u32Timeout);
  158. void OTS_IntCmd(en_functional_state_t enNewState);
  159. void OTS_SetTriggerSrc(en_event_src_t enEvent);
  160. void OTS_ComTriggerCmd(uint32_t u32ComTrig, en_functional_state_t enNewState);
  161. en_result_t OTS_ScalingExperiment(uint16_t *pu16Dr1, uint16_t *pu16Dr2, \
  162. uint16_t *pu16Ecr, float32_t *pf32A, \
  163. uint32_t u32Timeout);
  164. float OTS_CalculateTemp(void);
  165. /**
  166. * @}
  167. */
  168. #endif /* DDL_OTS_ENABLE */
  169. /**
  170. * @}
  171. */
  172. /**
  173. * @}
  174. */
  175. #ifdef __cplusplus
  176. }
  177. #endif
  178. #endif /* __HC32F4A0_OTS_H__ */
  179. /*******************************************************************************
  180. * EOF (not truncated)
  181. ******************************************************************************/