ddl.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 ddl.h
  12. *
  13. * @brief Header file for DDL functions
  14. *
  15. * @author MADS Team
  16. *
  17. ******************************************************************************/
  18. #ifndef __DDL_H__
  19. #define __DDL_H__
  20. /******************************************************************************/
  21. /* Include files */
  22. /******************************************************************************/
  23. #include "base_types.h"
  24. #include "board_stkhc32l19x.h"
  25. #include "hc32l19x.h"
  26. #include "system_hc32l19x.h"
  27. #include "sysctrl.h"
  28. #include "interrupts_hc32l19x.h"
  29. /* C binding of definitions if building with C++ compiler */
  30. #ifdef __cplusplus
  31. extern "C"
  32. {
  33. #endif
  34. /******************************************************************************/
  35. /* Global pre-processor symbols/macros ('#define') */
  36. /* Macro for initializing local structures to zero */
  37. /******************************************************************************/
  38. #define DDL_ZERO_STRUCT(x) ddl_memclr((uint8_t*)&(x), (uint32_t)(sizeof(x)))
  39. #define DEC2BCD(x) ((((x)/10)<<4) + ((x)%10))
  40. #define BCD2DEC(x) ((((x)>>4)*10) + ((x)&0x0F))
  41. #define SET_BIT(REG, BIT) ((REG) |= (BIT))
  42. #define CLEAR_BIT(REG, BIT) ((REG) &= ~(BIT))
  43. #define READ_BIT(REG, BIT) ((REG) & (BIT))
  44. #define CLEAR_REG(REG) ((REG) = (0x0))
  45. #define WRITE_REG(REG, VAL) ((REG) = (VAL))
  46. #define READ_REG(REG) ((REG))
  47. #define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK)))
  48. /**
  49. ******************************************************************************
  50. ** Global Device Series List
  51. ******************************************************************************/
  52. #define DDL_DEVICE_SERIES_HC32L17X (0u)
  53. /**
  54. ******************************************************************************
  55. ** Global Device Package List
  56. ******************************************************************************/
  57. // package definitions of HC device.
  58. #define DDL_DEVICE_PACKAGE_HC_C (0x00u)
  59. #define DDL_DEVICE_PACKAGE_HC_F (0x10u)
  60. #define DDL_DEVICE_PACKAGE_HC_J (0x20u)
  61. #define DDL_DEVICE_PACKAGE_HC_K (0x30u)
  62. /******************************************************************************/
  63. /* User Device Setting Include file */
  64. /******************************************************************************/
  65. #include "ddl_device.h" // MUST be included here!
  66. /******************************************************************************/
  67. /* Global type definitions ('typedef') */
  68. /******************************************************************************/
  69. /**
  70. ******************************************************************************
  71. ** \brief Level
  72. **
  73. ** Specifies levels.
  74. **
  75. ******************************************************************************/
  76. typedef enum en_level
  77. {
  78. DdlLow = 0u, ///< Low level '0'
  79. DdlHigh = 1u ///< High level '1'
  80. } en_level_t;
  81. /**
  82. ******************************************************************************
  83. ** \brief Generic Flag Code
  84. **
  85. ** Specifies flags.
  86. **
  87. ******************************************************************************/
  88. typedef enum en_flag
  89. {
  90. DdlClr = 0u, ///< Flag clr '0'
  91. DdlSet = 1u ///< Flag set '1'
  92. } en_stat_flag_t, en_irq_flag_t;
  93. /******************************************************************************/
  94. /* Global variable declarations ('extern', definition in C source) */
  95. /******************************************************************************/
  96. /******************************************************************************/
  97. /* Global function prototypes ('extern', definition in C source) */
  98. /******************************************************************************/
  99. /*******************************************************************************
  100. * Global function prototypes
  101. ******************************************************************************/
  102. extern void ddl_memclr(void* pu8Address, uint32_t u32Count);
  103. uint32_t Log2(uint32_t u32Val);
  104. /**
  105. *******************************************************************************
  106. ** This hook is part of wait loops.
  107. ******************************************************************************/
  108. void delay1ms(uint32_t u32Cnt);
  109. void delay100us(uint32_t u32Cnt);
  110. void delay10us(uint32_t u32Cnt);
  111. void SetBit(uint32_t addr, uint32_t offset, boolean_t bFlag);
  112. void ClrBit(uint32_t addr, uint32_t offset);
  113. boolean_t GetBit(uint32_t addr, uint32_t offset);
  114. #ifdef __cplusplus
  115. }
  116. #endif
  117. #endif /* __DDL_H__ */
  118. /******************************************************************************/
  119. /* EOF (not truncated) */
  120. /******************************************************************************/