utils.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 = 0x0,
  43. ERROR = 0x1,
  44. BUSY = 0x2,
  45. TIMEOUT = 0x3
  46. } ald_status_t;
  47. /**
  48. * @brief SysTick interval definition
  49. */
  50. typedef enum {
  51. SYSTICK_INTERVAL_1MS = 1000, /**< Interval is 1ms */
  52. SYSTICK_INTERVAL_10MS = 100, /**< Interval is 10ms */
  53. SYSTICK_INTERVAL_100MS = 10, /**< Interval is 100ms */
  54. SYSTICK_INTERVAL_1000MS = 1, /**< Interval is 1s */
  55. } systick_interval_t;
  56. /**
  57. * @}
  58. */
  59. /** @defgroup ALD_Public_Macros Public Macros
  60. * @{
  61. */
  62. #define ALD_MAX_DELAY 0xFFFFFFFF
  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 IS_PRIO(x) ((x) < 4)
  86. #define IS_SYSTICK_INTERVAL(x) (((x) == SYSTICK_INTERVAL_1MS) || \
  87. ((x) == SYSTICK_INTERVAL_10MS) || \
  88. ((x) == SYSTICK_INTERVAL_100MS) || \
  89. ((x) == SYSTICK_INTERVAL_1000MS))
  90. /**
  91. * @}
  92. */
  93. /** @addtogroup ALD_Public_Functions
  94. * @{
  95. */
  96. /** @addtogroup ALD_Public_Functions_Group1
  97. * @{
  98. */
  99. /* Initialization functions */
  100. void mcu_ald_init(void);
  101. void __init_tick(uint32_t prio);
  102. void systick_interval_select(systick_interval_t value);
  103. /**
  104. * @}
  105. */
  106. /** @addtogroup ALD_Public_Functions_Group2
  107. * @{
  108. */
  109. /* Peripheral Control functions */
  110. void __inc_tick(void);
  111. void __delay_ms(__IO uint32_t delay);
  112. uint32_t __get_tick(void);
  113. void __suspend_tick(void);
  114. void __resume_tick(void);
  115. void systick_irq_cbk(void);
  116. uint32_t get_ald_version(void);
  117. ald_status_t __wait_flag(uint32_t *reg, uint32_t bit, flag_status_t status, uint32_t timeout);
  118. void mcu_irq_config(IRQn_Type irq, uint8_t prio, type_func_t status);
  119. uint32_t mcu_get_tick(void);
  120. uint32_t mcu_get_cpu_id(void);
  121. /**
  122. * @}
  123. */
  124. /**
  125. * @}
  126. */
  127. /**
  128. * @}
  129. */
  130. /**
  131. * @}
  132. */
  133. #ifdef __cplusplus
  134. }
  135. #endif
  136. #endif /* __UTILS_H__ */