hc32f460_ots.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*******************************************************************************
  2. * Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
  3. *
  4. * This software component is licensed by HDSC under BSD 3-Clause license
  5. * (the "License"); You may not use this file except in compliance with the
  6. * License. You may obtain a copy of the License at:
  7. * opensource.org/licenses/BSD-3-Clause
  8. */
  9. /******************************************************************************/
  10. /** \file hc32f460_ots.h
  11. **
  12. ** A detailed description is available at
  13. ** @link OtsGroup Ots description @endlink
  14. **
  15. ** - 2018-10-26 CDT First version for Device Driver Library of Ots.
  16. **
  17. ******************************************************************************/
  18. #ifndef __HC32F460_OTS_H__
  19. #define __HC32F460_OTS_H__
  20. /*******************************************************************************
  21. * Include files
  22. ******************************************************************************/
  23. #include "hc32_common.h"
  24. #include "ddl_config.h"
  25. #if (DDL_OTS_ENABLE == DDL_ON)
  26. /* C binding of definitions if building with C++ compiler */
  27. #ifdef __cplusplus
  28. extern "C"
  29. {
  30. #endif
  31. /**
  32. *******************************************************************************
  33. ** \defgroup OtsGroup On-chip Temperature Sensor(OTS)
  34. **
  35. ******************************************************************************/
  36. //@{
  37. /*******************************************************************************
  38. * Global type definitions ('typedef')
  39. ******************************************************************************/
  40. /* Automatically turn off the analog temperature sensor after the temperature
  41. measurement is over. */
  42. typedef enum en_ots_auto_off
  43. {
  44. OtsAutoOff_Disable = 0x0, ///< Disable automatically turn off OTS.
  45. OtsAutoOff_Enable = 0x1, ///< Enable automatically turn off OTS.
  46. } en_ots_auto_off_t;
  47. /* Temperature measurement end interrupt request. */
  48. typedef enum en_ots_ie
  49. {
  50. OtsInt_Disable = 0x0, ///< Disable OTS interrupt.
  51. OtsInt_Enable = 0x1, ///< Enable OTS interrupt.
  52. } en_ots_ie_t;
  53. /* OTS clock selection. */
  54. typedef enum en_ots_clk_sel
  55. {
  56. OtsClkSel_Xtal = 0x0, ///< Select XTAL as OTS clock.
  57. OtsClkSel_Hrc = 0x1, ///< Select HRC as OTS clock.
  58. } en_ots_clk_sel_t;
  59. /* OTS OTS initialization structure definition. */
  60. typedef struct stc_ots_init
  61. {
  62. en_ots_auto_off_t enAutoOff; ///< @ref en_ots_auto_off_t.
  63. en_ots_clk_sel_t enClkSel; ///< @ref en_ots_clk_sel_t.
  64. float32_t f32SlopeK; ///< K: Temperature slope (calculated by calibration experiment). */
  65. float32_t f32OffsetM; ///< M: Temperature offset (calculated by calibration experiment). */
  66. } stc_ots_init_t;
  67. /* OTS common trigger source select */
  68. typedef enum en_ots_com_trigger
  69. {
  70. OtsComTrigger_1 = 0x1, ///< Select common trigger 1.
  71. OtsComTrigger_2 = 0x2, ///< Select common trigger 2.
  72. OtsComTrigger_1_2 = 0x3, ///< Select common trigger 1 and 2.
  73. } en_ots_com_trigger_t;
  74. /*******************************************************************************
  75. * Global variable definitions ('extern')
  76. ******************************************************************************/
  77. /*******************************************************************************
  78. * Global function prototypes (definition in C source)
  79. ******************************************************************************/
  80. /**
  81. * @brief Start OTS.
  82. * @param None
  83. * @retval None
  84. */
  85. __STATIC_INLINE void OTS_Start(void)
  86. {
  87. bM4_OTS_CTL_OTSST = (uint32_t)1u;
  88. }
  89. /**
  90. * @brief Stop OTS.
  91. * @param None
  92. * @retval None
  93. */
  94. __STATIC_INLINE void OTS_Stop(void)
  95. {
  96. bM4_OTS_CTL_OTSST = (uint32_t)0u;
  97. }
  98. en_result_t OTS_Init(const stc_ots_init_t *pstcInit);
  99. void OTS_DeInit(void);
  100. en_result_t OTS_Polling(float32_t *pf32Temp, uint32_t u32Timeout);
  101. void OTS_IntCmd(en_functional_state_t enNewState);
  102. void OTS_SetTriggerSrc(en_event_src_t enEvent);
  103. void OTS_ComTriggerCmd(en_ots_com_trigger_t enComTrigger, en_functional_state_t enState);
  104. en_result_t OTS_ScalingExperiment(uint16_t *pu16Dr1, uint16_t *pu16Dr2, \
  105. uint16_t *pu16Ecr, float32_t *pf32A, \
  106. uint32_t u32Timeout);
  107. float OTS_CalculateTemp(void);
  108. //@} // OtsGroup
  109. #ifdef __cplusplus
  110. }
  111. #endif
  112. #endif /* DDL_OTS_ENABLE */
  113. #endif /* __HC32F460_OTS_H__ */
  114. /*******************************************************************************
  115. * EOF (not truncated)
  116. ******************************************************************************/