hc32f460_dcu.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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_dcu.h
  11. **
  12. ** A detailed description is available at
  13. ** @link DcuGroup DCU description @endlink
  14. **
  15. ** - 2018-10-15 CDT First version for Device Driver Library of DCU.
  16. **
  17. ******************************************************************************/
  18. #ifndef __HC32F460_DCU_H__
  19. #define __HC32F460_DCU_H__
  20. /*******************************************************************************
  21. * Include files
  22. ******************************************************************************/
  23. #include "hc32_common.h"
  24. #include "ddl_config.h"
  25. #if (DDL_DCU_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 DcuGroup Data Computing Unit(DCU)
  34. **
  35. ******************************************************************************/
  36. //@{
  37. /*******************************************************************************
  38. * Global type definitions ('typedef')
  39. ******************************************************************************/
  40. /**
  41. *******************************************************************************
  42. ** \brief DCU register data enumeration
  43. **
  44. ******************************************************************************/
  45. typedef enum en_dcu_data_register
  46. {
  47. DcuRegisterData0 = 0u, ///< DCU DATA0
  48. DcuRegisterData1 = 1u, ///< DCU DATA1
  49. DcuRegisterData2 = 2u, ///< DCU DATA2
  50. } en_dcu_data_register_t;
  51. /**
  52. *******************************************************************************
  53. ** \brief DCU operation enumeration
  54. **
  55. ******************************************************************************/
  56. typedef enum en_dcu_operation_mode
  57. {
  58. DcuInvalid = 0u, ///< DCU Invalid
  59. DcuOpAdd = 1u, ///< DCU operation: Add
  60. DcuOpSub = 2u, ///< DCU operation: Sub
  61. DcuHwTrigOpAdd = 3u, ///< DCU operation: Hardware trigger Add
  62. DcuHwTrigOpSub = 4u, ///< DCU operation: Hardware trigger Sub
  63. DcuOpCompare = 5u, ///< DCU operation: Compare
  64. } en_dcu_operation_mode_t;
  65. /**
  66. *******************************************************************************
  67. ** \brief DCU data size enumeration
  68. **
  69. ******************************************************************************/
  70. typedef enum en_dcu_data_size
  71. {
  72. DcuDataBit8 = 0u, ///< DCU data size: 8 bit
  73. DcuDataBit16 = 1u, ///< DCU data size: 16 bit
  74. DcuDataBit32 = 2u, ///< DCU data size: 32 bit
  75. } en_dcu_data_size_t;
  76. /**
  77. *******************************************************************************
  78. ** \brief DCU compare operation trigger mode enumeration
  79. **
  80. ******************************************************************************/
  81. typedef enum en_dcu_cmp_trigger_mode
  82. {
  83. DcuCmpTrigbyData0 = 0u, ///< DCU compare triggered by DATA0
  84. DcuCmpTrigbyData012 = 1u, ///< DCU compare triggered by DATA0 or DATA1 or DATA2
  85. } en_dcu_cmp_trigger_mode_t;
  86. /**
  87. *******************************************************************************
  88. ** \brief DCU interrupt selection enumeration
  89. **
  90. ******************************************************************************/
  91. typedef enum en_dcu_int_sel
  92. {
  93. DcuIntOp = (1ul << 0), ///< DCU overflow or underflow interrupt
  94. DcuIntLs2 = (1ul << 1), ///< DCU DATA0 < DATA2 interrupt
  95. DcuIntEq2 = (1ul << 2), ///< DCU DATA0 = DATA2 interrupt
  96. DcuIntGt2 = (1ul << 3), ///< DCU DATA0 > DATA2 interrupt
  97. DcuIntLs1 = (1ul << 4), ///< DCU DATA0 < DATA1 interrupt
  98. DcuIntEq1 = (1ul << 5), ///< DCU DATA0 = DATA1 interrupt
  99. DcuIntGt1 = (1ul << 6), ///< DCU DATA0 > DATA1 interrupt
  100. } en_dcu_int_sel_t, en_dcu_flag_t;
  101. /**
  102. *******************************************************************************
  103. ** \brief DCU window interrupt mode enumeration
  104. **
  105. ******************************************************************************/
  106. typedef enum en_dcu_int_win_mode
  107. {
  108. DcuIntInvalid = 0u, ///< DCU don't occur interrupt
  109. DcuWinIntInvalid = 1u, ///< DCU window interrupt is invalid.
  110. DcuInsideWinCmpInt = 2u, ///< DCU occur interrupt when DATA2 ≤ DATA0 ≤ DATA2
  111. DcuOutsideWinCmpInt = 3u, ///< DCU occur interrupt when DATA0 > DATA1 or DATA0 < DATA2
  112. } en_dcu_int_win_mode_t;
  113. /* DCU common trigger source select */
  114. typedef enum en_dcu_com_trigger
  115. {
  116. DcuComTrigger_1 = 1u, ///< Select common trigger 1.
  117. DcuComTrigger_2 = 2u, ///< Select common trigger 2.
  118. DcuComTrigger_1_2 = 3u, ///< Select common trigger 1 and 2.
  119. } en_dcu_com_trigger_t;
  120. /**
  121. *******************************************************************************
  122. ** \brief DCU initialization configuration
  123. **
  124. ******************************************************************************/
  125. typedef struct stc_dcu_init
  126. {
  127. uint32_t u32IntSel; ///< Specifies interrupt selection and This parameter can be a value of @ref en_dcu_int_sel_t
  128. en_functional_state_t enIntCmd; ///< Select DCU interrupt function. Enable:Enable DCU interrupt function; Disable:Disable DCU interrupt function
  129. en_dcu_int_win_mode_t enIntWinMode; ///< Specifies interrupt window mode and This parameter can be a value of @ref en_dcu_int_win_mode_t
  130. en_dcu_data_size_t enDataSize; ///< Specifies DCU data size and This parameter can be a value of @ref en_dcu_data_size_t
  131. en_dcu_operation_mode_t enOperation; ///< Specifies DCU operation and This parameter can be a value of @ref en_dcu_operation_mode_t
  132. en_dcu_cmp_trigger_mode_t enCmpTriggerMode; ///< Specifies DCU compare operation trigger mode size and This parameter can be a value of @ref en_dcu_cmp_trigger_mode_t
  133. } stc_dcu_init_t;
  134. /*******************************************************************************
  135. * Global pre-processor symbols/macros ('#define')
  136. ******************************************************************************/
  137. /*******************************************************************************
  138. * Global variable definitions ('extern')
  139. ******************************************************************************/
  140. /*******************************************************************************
  141. * Global function prototypes (definition in C source)
  142. ******************************************************************************/
  143. en_result_t DCU_Init(M4_DCU_TypeDef *DCUx, const stc_dcu_init_t *pstcInitCfg);
  144. en_result_t DCU_DeInit(M4_DCU_TypeDef *DCUx);
  145. en_result_t DCU_SetOperationMode(M4_DCU_TypeDef *DCUx,
  146. en_dcu_operation_mode_t enMode);
  147. en_dcu_operation_mode_t DCU_GetOperationMode(M4_DCU_TypeDef *DCUx);
  148. en_result_t DCU_SetDataSize(M4_DCU_TypeDef *DCUx, en_dcu_data_size_t enSize);
  149. en_dcu_data_size_t DCU_GetDataSize(M4_DCU_TypeDef *DCUx);
  150. en_result_t DCU_SetIntWinMode(M4_DCU_TypeDef *DCUx,
  151. en_dcu_int_win_mode_t enIntWinMode);
  152. en_dcu_int_win_mode_t DCU_GetIntWinMode(M4_DCU_TypeDef *DCUx);
  153. en_result_t DCU_SetCmpTriggerMode(M4_DCU_TypeDef *DCUx,
  154. en_dcu_cmp_trigger_mode_t enTriggerMode);
  155. en_dcu_cmp_trigger_mode_t DCU_GetCmpTriggerMode(M4_DCU_TypeDef *DCUx);
  156. en_result_t DCU_EnableInterrupt(M4_DCU_TypeDef *DCUx);
  157. en_result_t DCU_DisableInterrupt(M4_DCU_TypeDef *DCUx);
  158. en_flag_status_t DCU_GetIrqFlag(M4_DCU_TypeDef *DCUx, en_dcu_flag_t enFlag);
  159. en_result_t DCU_ClearIrqFlag(M4_DCU_TypeDef *DCUx, en_dcu_flag_t enFlag);
  160. en_result_t DCU_IrqSelCmd(M4_DCU_TypeDef *DCUx,
  161. en_dcu_int_sel_t enIntSel,
  162. en_functional_state_t enCmd);
  163. uint8_t DCU_ReadDataByte(M4_DCU_TypeDef *DCUx,
  164. en_dcu_data_register_t enDataReg);
  165. en_result_t DCU_WriteDataByte(M4_DCU_TypeDef *DCUx,
  166. en_dcu_data_register_t enDataReg, uint8_t u8Data);
  167. uint16_t DCU_ReadDataHalfWord(M4_DCU_TypeDef *DCUx,
  168. en_dcu_data_register_t enDataReg);
  169. en_result_t DCU_WriteDataHalfWord(M4_DCU_TypeDef *DCUx,
  170. en_dcu_data_register_t enDataReg,
  171. uint16_t u16Data);
  172. uint32_t DCU_ReadDataWord(M4_DCU_TypeDef *DCUx,
  173. en_dcu_data_register_t enDataReg);
  174. en_result_t DCU_WriteDataWord(M4_DCU_TypeDef *DCUx,
  175. en_dcu_data_register_t enDataReg,
  176. uint32_t u32Data);
  177. en_result_t DCU_SetTriggerSrc(M4_DCU_TypeDef *DCUx,
  178. en_event_src_t enTriggerSrc);
  179. void DCU_ComTriggerCmd(M4_DCU_TypeDef *DCUx,
  180. en_dcu_com_trigger_t enComTrigger,
  181. en_functional_state_t enState);
  182. //@} // DcuGroup
  183. #ifdef __cplusplus
  184. }
  185. #endif
  186. #endif /* DDL_DCU_ENABLE */
  187. #endif /* __HC32F460_DCU_H__ */
  188. /*******************************************************************************
  189. * EOF (not truncated)
  190. ******************************************************************************/