lvd.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /******************************************************************************
  2. * Copyright (C) 2021, Xiaohua Semiconductor Co., Ltd. All rights reserved.
  3. *
  4. * This software component is licensed by XHSC 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. /******************************************************************************
  11. * @file lvd.h
  12. *
  13. * @brief Header file for Low Voltage Detector functions
  14. *
  15. * @author MADS Team
  16. *
  17. ******************************************************************************/
  18. #ifndef __LVD_H__
  19. #define __LVD_H__
  20. /******************************************************************************
  21. * Include files
  22. ******************************************************************************/
  23. #include "ddl.h"
  24. /* C binding of definitions if building with C++ compiler */
  25. #ifdef __cplusplus
  26. extern "C"
  27. {
  28. #endif
  29. /**
  30. ******************************************************************************
  31. ** \defgroup LvdGroup Low Voltage Detector (LVD)
  32. **
  33. ******************************************************************************/
  34. //@{
  35. /******************************************************************************
  36. * Global type definitions
  37. ******************************************************************************/
  38. /**
  39. ******************************************************************************
  40. ** \brief LVD监测电压源选择
  41. **
  42. ** \note
  43. ******************************************************************************/
  44. typedef enum en_lvd_input_src
  45. {
  46. LvdInputSrcMskVCC = 0u<<2, ///< Vcc
  47. LvdInputSrcMskPC13 = 1u<<2, ///< PC13
  48. LvdInputSrcMskPB08 = 2u<<2, ///< PB08
  49. LvdInputSrcMskPB07 = 3u<<2, ///< PB07
  50. }en_lvd_input_src_t;
  51. /**
  52. ******************************************************************************
  53. ** \brief LVD阈值电压选择
  54. **
  55. ** \note
  56. ******************************************************************************/
  57. typedef enum en_lvd_threshold
  58. {
  59. LvdMskTH1_8V = 0u<<4, ///< 1.8V
  60. LvdMskTH1_9V = 1u<<4, ///< 1.9V
  61. LvdMskTH2_0V = 2u<<4, ///< 2.0V
  62. LvdMskTH2_1V = 3u<<4, ///< 2.1V
  63. LvdMskTH2_2V = 4u<<4, ///< 2.2V
  64. LvdMskTH2_3V = 5u<<4, ///< 2.3V
  65. LvdMskTH2_4V = 6u<<4, ///< 2.4V
  66. LvdMskTH2_5V = 7u<<4, ///< 2.5V
  67. LvdMskTH2_6V = 8u<<4, ///< 2.6V
  68. LvdMskTH2_7V = 9u<<4, ///< 2.7V
  69. LvdMskTH2_8V = 10u<<4, ///< 2.8V
  70. LvdMskTH2_9V = 11u<<4, ///< 2.9V
  71. LvdMskTH3_0V = 12u<<4, ///< 3.0V
  72. LvdMskTH3_1V = 13u<<4, ///< 3.1V
  73. LvdMskTH3_2V = 14u<<4, ///< 3.2V
  74. LvdMskTH3_3V = 15u<<4, ///< 3.3V
  75. }en_lvd_threshold_t;
  76. /**
  77. ******************************************************************************
  78. ** \brief LVD输出滤波时间
  79. **
  80. ** \note
  81. ******************************************************************************/
  82. typedef enum en_lvd_filter_time
  83. {
  84. LvdFilterMsk7us = 0u<<9, ///< 7us
  85. LvdFilterMsk14us = 1u<<9, ///< 14us
  86. LvdFilterMsk28us = 2u<<9, ///< 28us
  87. LvdFilterMsk112us = 3u<<9, ///< 112us
  88. LvdFilterMsk450us = 4u<<9, ///< 450us
  89. LvdFilterMsk1_8ms = 5u<<9, ///< 1.8ms
  90. LvdFilterMsk7_2ms = 6u<<9, ///< 7.3ms
  91. LvdFilterMsk28_8ms = 7u<<9, ///< 28.8ms
  92. }en_lvd_filter_time_t;
  93. /**
  94. ******************************************************************************
  95. ** \brief LVD中断触发方式
  96. **
  97. ** \note
  98. ******************************************************************************/
  99. typedef enum en_lvd_irq_type
  100. {
  101. LvdIrqMskRiseFall = 3u<<12, ///< 上升/下降沿触发
  102. LvdIrqMskHigh = 1u<<14, ///< 高电平触发
  103. LvdIrqMskRise = 1u<<13, ///< 上升沿触发
  104. LvdIrqMskFall = 1u<<12, ///< 下降沿触发
  105. }en_lvd_irq_type_t;
  106. /**
  107. ******************************************************************************
  108. ** \brief LVD触发动作选择
  109. **
  110. ** \note
  111. ******************************************************************************/
  112. typedef enum en_lvd_act
  113. {
  114. LvdActMskReset = 1u<<1, ///< 系统复位
  115. LvdActMskInt = 0u, ///< NVIC中断
  116. }en_lvd_act_t;
  117. /**
  118. ******************************************************************************
  119. ** \brief LVD数字滤波使能配置
  120. **
  121. ** \note
  122. ******************************************************************************/
  123. typedef enum en_lvd_filter
  124. {
  125. LvdFilterMskEnable = 1u<<8, ///< 数字滤波使能
  126. LvdFilterMskDisable = 0u, ///< 数字滤波禁止
  127. }en_lvd_filter_t;
  128. /**
  129. ******************************************************************************
  130. ** \brief LVD配置
  131. ** \note
  132. ******************************************************************************/
  133. typedef struct stc_lvd_cfg
  134. {
  135. en_lvd_act_t enAct; ///< LVD触发动作
  136. en_lvd_input_src_t enInputSrc; ///< LVD输入电压源
  137. en_lvd_threshold_t enThreshold; ///< LVD监测电压
  138. en_lvd_filter_t enFilter; ///< 是否使用输出滤波
  139. en_lvd_filter_time_t enFilterTime; ///< 输出滤波时间
  140. en_lvd_irq_type_t enIrqType; ///< 中断触发方式
  141. }stc_lvd_cfg_t;
  142. /******************************************************************************
  143. * Global definitions
  144. ******************************************************************************/
  145. /******************************************************************************
  146. * Local type definitions ('typedef')
  147. ******************************************************************************/
  148. /******************************************************************************
  149. * Global variable definitions ('extern')
  150. ******************************************************************************/
  151. /******************************************************************************
  152. * Global function prototypes (definition in C source)
  153. ******************************************************************************/
  154. //irq enable/disable
  155. void Lvd_EnableIrq(void);
  156. void Lvd_DisableIrq(void);
  157. // irq function
  158. void Lvd_ClearIrq(void);
  159. boolean_t Lvd_GetIrqStat(void);
  160. // fliter function
  161. boolean_t Lvd_GetFilterResult(void);
  162. //init/deinit function
  163. void Lvd_Init(stc_lvd_cfg_t *pstcCfg);
  164. //LVD function enable/disable
  165. void Lvd_Enable(void);
  166. void Lvd_Disable(void);
  167. //@} // LvdGroup
  168. #ifdef __cplusplus
  169. }
  170. #endif
  171. #endif /* __LVD_H__ */
  172. /******************************************************************************
  173. * EOF (not truncated)
  174. ******************************************************************************/