utils.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /**
  2. *********************************************************************************
  3. *
  4. * @file utils.h
  5. * @brief This file contains the Utilities functions/types for the driver.
  6. *
  7. * @version V1.0
  8. * @date 07 Nov 2017
  9. * @author AE Team
  10. * @note
  11. *
  12. * Copyright (C) Shanghai Eastsoft Microelectronics Co. Ltd. All rights reserved.
  13. *
  14. *********************************************************************************
  15. */
  16. #ifndef __UTILS_H__
  17. #define __UTILS_H__
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. #include <stdlib.h>
  22. #include "ald_conf.h"
  23. #include "type.h"
  24. #include "es32f033x.h"
  25. /** @addtogroup ES32FXXX_ALD
  26. * @{
  27. */
  28. /** @addtogroup UTILS
  29. * @{
  30. */
  31. /** @defgroup ALD_Public_Types Public Types
  32. * @{
  33. */
  34. /**
  35. * @brief SysTick interval
  36. */
  37. extern uint32_t __systick_interval;
  38. /**
  39. * @brief ALD Status structures definition
  40. */
  41. typedef enum {
  42. OK = 0x0U, /**< Status: OK */
  43. ERROR = 0x1U, /**< Status: ERROR */
  44. BUSY = 0x2U, /**< Status: BUSY */
  45. TIMEOUT = 0x3U, /**< Status: TIMEOUT */
  46. } ald_status_t;
  47. /**
  48. * @brief SysTick interval definition
  49. */
  50. typedef enum {
  51. SYSTICK_INTERVAL_1MS = 1000U, /**< Interval is 1ms */
  52. SYSTICK_INTERVAL_10MS = 100U, /**< Interval is 10ms */
  53. SYSTICK_INTERVAL_100MS = 10U, /**< Interval is 100ms */
  54. SYSTICK_INTERVAL_1000MS = 1U, /**< Interval is 1s */
  55. } systick_interval_t;
  56. /**
  57. * @}
  58. */
  59. /** @defgroup ALD_Public_Macros Public Macros
  60. * @{
  61. */
  62. #define ALD_MAX_DELAY 0xFFFFFFFFU
  63. #define IS_BIT_SET(reg, bit) (((reg) & (bit)) != RESET)
  64. #define IS_BIT_CLR(reg, bit) (((reg) & (bit)) == RESET)
  65. #define RESET_HANDLE_STATE(x) ((x)->state = 0)
  66. #define __LOCK(x) \
  67. do { \
  68. if ((x)->lock == LOCK) { \
  69. return BUSY; \
  70. } \
  71. else { \
  72. (x)->lock = LOCK; \
  73. } \
  74. } while (0)
  75. #define __UNLOCK(x) \
  76. do { \
  77. (x)->lock = UNLOCK; \
  78. } while (0)
  79. /**
  80. * @}
  81. */
  82. /** @defgroup ALD_Private_Macros Private Macros
  83. * @{
  84. */
  85. #define MCU_UID0_ADDR 0x000403E0U
  86. #define MCU_UID1_ADDR 0x000403E8U
  87. #define MCU_UID2_ADDR 0x000403F0U
  88. #define MCU_CHIPID_ADDR 0x000403F8U
  89. #define IS_PRIO(x) ((x) < 4)
  90. #define IS_SYSTICK_INTERVAL(x) (((x) == SYSTICK_INTERVAL_1MS) || \
  91. ((x) == SYSTICK_INTERVAL_10MS) || \
  92. ((x) == SYSTICK_INTERVAL_100MS) || \
  93. ((x) == SYSTICK_INTERVAL_1000MS))
  94. /**
  95. * @}
  96. */
  97. /** @addtogroup ALD_Public_Functions
  98. * @{
  99. */
  100. /** @addtogroup ALD_Public_Functions_Group1
  101. * @{
  102. */
  103. /* Initialization functions */
  104. void ald_cmu_init(void);
  105. void ald_tick_init(uint32_t prio);
  106. void ald_systick_interval_select(systick_interval_t value);
  107. /**
  108. * @}
  109. */
  110. /** @addtogroup ALD_Public_Functions_Group2
  111. * @{
  112. */
  113. /* Peripheral Control functions */
  114. void ald_inc_tick_weak(void);
  115. void ald_delay_ms(__IO uint32_t delay);
  116. uint32_t ald_get_tick(void);
  117. void ald_suspend_tick(void);
  118. void ald_resume_tick(void);
  119. void ald_systick_irq_cbk(void);
  120. void ald_inc_tick(void);
  121. uint32_t ald_get_ald_version(void);
  122. ald_status_t ald_wait_flag(uint32_t *reg, uint32_t bit, flag_status_t status, uint32_t timeout);
  123. void ald_mcu_irq_config(IRQn_Type irq, uint8_t prio, type_func_t status);
  124. uint32_t ald_mcu_get_tick(void);
  125. uint32_t ald_mcu_get_cpu_id(void);
  126. void ald_mcu_get_uid(uint8_t *buf);
  127. uint32_t ald_mcu_get_chipid(void);
  128. /**
  129. * @}
  130. */
  131. /**
  132. * @}
  133. */
  134. /**
  135. * @}
  136. */
  137. /**
  138. * @}
  139. */
  140. #ifdef __cplusplus
  141. }
  142. #endif
  143. #endif /* __UTILS_H__ */