py32f002b_hal_def.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /**
  2. ******************************************************************************
  3. * @file py32f002b_hal_def.h
  4. * @author MCU Application Team
  5. * @version V1.0.0
  6. * @date
  7. * @brief This file contains HAL common defines, enumeration, macros and
  8. * structures definitions.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * <h2><center>&copy; Copyright (c) 2023 Puya Semiconductor Co.
  13. * All rights reserved.</center></h2>
  14. *
  15. * This software component is licensed by Puya under BSD 3-Clause license,
  16. * the "License"; You may not use this file except in compliance with the
  17. * License. You may obtain a copy of the License at:
  18. * opensource.org/licenses/BSD-3-Clause
  19. *
  20. ******************************************************************************
  21. * @attention
  22. *
  23. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  24. * All rights reserved.</center></h2>
  25. *
  26. * This software component is licensed by ST under BSD 3-Clause license,
  27. * the "License"; You may not use this file except in compliance with the
  28. * License. You may obtain a copy of the License at:
  29. * opensource.org/licenses/BSD-3-Clause
  30. *
  31. ******************************************************************************
  32. */
  33. /* Define to prevent recursive inclusion -------------------------------------*/
  34. #ifndef __PY32F002B_HAL_DEF
  35. #define __PY32F002B_HAL_DEF
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. /* Includes ------------------------------------------------------------------*/
  40. #include "py32f0xx.h"
  41. #include <stdio.h>
  42. /* Exported types ------------------------------------------------------------*/
  43. /**
  44. * @brief HAL Status structures definition
  45. */
  46. typedef enum
  47. {
  48. HAL_OK = 0x00U,
  49. HAL_ERROR = 0x01U,
  50. HAL_BUSY = 0x02U,
  51. HAL_TIMEOUT = 0x03U
  52. } HAL_StatusTypeDef;
  53. /**
  54. * @brief HAL Lock structures definition
  55. */
  56. typedef enum
  57. {
  58. HAL_UNLOCKED = 0x00U,
  59. HAL_LOCKED = 0x01U
  60. } HAL_LockTypeDef;
  61. /* Exported macro ------------------------------------------------------------*/
  62. #define HAL_MAX_DELAY 0xFFFFFFFFU
  63. #define HAL_IS_BIT_SET(REG, BIT) (((REG) & (BIT)) != 0U)
  64. #define HAL_IS_BIT_CLR(REG, BIT) (((REG) & (BIT)) == 0U)
  65. #define UNUSED(X) (void)X /* To avoid gcc/g++ warnings */
  66. /** @brief Reset the Handle's State field.
  67. * @param __HANDLE__: specifies the Peripheral Handle.
  68. * @note This macro can be used for the following purpose:
  69. * - When the Handle is declared as local variable; before passing it as parameter
  70. * to HAL_PPP_Init() for the first time, it is mandatory to use this macro
  71. * to set to 0 the Handle's "State" field.
  72. * Otherwise, "State" field may have any random value and the first time the function
  73. * HAL_PPP_Init() is called, the low level hardware initialization will be missed
  74. * (i.e. HAL_PPP_MspInit() will not be executed).
  75. * - When there is a need to reconfigure the low level hardware: instead of calling
  76. * HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init().
  77. * In this later function, when the Handle's "State" field is set to 0, it will execute the function
  78. * HAL_PPP_MspInit() which will reconfigure the low level hardware.
  79. * @retval None
  80. */
  81. #define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0U)
  82. #if (USE_RTOS == 1U)
  83. /* Reserved for future use */
  84. #error "USE_RTOS should be 0 in the current HAL release"
  85. #else
  86. #define __HAL_LOCK(__HANDLE__) \
  87. do{ \
  88. if((__HANDLE__)->Lock == HAL_LOCKED) \
  89. { \
  90. return HAL_BUSY; \
  91. } \
  92. else \
  93. { \
  94. (__HANDLE__)->Lock = HAL_LOCKED; \
  95. } \
  96. }while (0U)
  97. #define __HAL_UNLOCK(__HANDLE__) \
  98. do{ \
  99. (__HANDLE__)->Lock = HAL_UNLOCKED; \
  100. }while (0U)
  101. #endif /* USE_RTOS */
  102. #if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
  103. #ifndef __weak
  104. #define __weak __attribute__((weak))
  105. #endif /* __weak */
  106. #ifndef __packed
  107. #define __packed __attribute__((__packed__))
  108. #endif /* __packed */
  109. #endif /* __GNUC__ */
  110. /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */
  111. #if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
  112. #ifndef __ALIGN_END
  113. #define __ALIGN_END __attribute__ ((aligned (4)))
  114. #endif /* __ALIGN_END */
  115. #ifndef __ALIGN_BEGIN
  116. #define __ALIGN_BEGIN
  117. #endif /* __ALIGN_BEGIN */
  118. #else
  119. #ifndef __ALIGN_END
  120. #define __ALIGN_END
  121. #endif /* __ALIGN_END */
  122. #ifndef __ALIGN_BEGIN
  123. #if defined (__CC_ARM) /* ARM Compiler */
  124. #define __ALIGN_BEGIN __align(4)
  125. #elif defined (__ICCARM__) /* IAR Compiler */
  126. #define __ALIGN_BEGIN
  127. #endif /* __CC_ARM */
  128. #endif /* __ALIGN_BEGIN */
  129. #endif /* __GNUC__ */
  130. /**
  131. * @brief __RAM_FUNC definition
  132. */
  133. #if defined ( __CC_ARM )
  134. /* ARM Compiler
  135. ------------
  136. RAM functions are defined using the toolchain options.
  137. Functions that are executed in RAM should reside in a separate source module.
  138. Using the 'Options for File' dialog you can simply change the 'Code / Const'
  139. area of a module to a memory space in physical RAM.
  140. Available memory areas are declared in the 'Target' tab of the 'Options for Target'
  141. dialog.
  142. */
  143. #define __RAM_FUNC
  144. #elif defined ( __ICCARM__ )
  145. /* ICCARM Compiler
  146. ---------------
  147. RAM functions are defined using a specific toolchain keyword "__ramfunc".
  148. */
  149. #define __RAM_FUNC __ramfunc
  150. #elif defined ( __GNUC__ )
  151. /* GNU Compiler
  152. ------------
  153. RAM functions are defined using a specific toolchain attribute
  154. "__attribute__((section(".RamFunc")))".
  155. */
  156. #define __RAM_FUNC __attribute__((section(".RamFunc")))
  157. #endif
  158. /**
  159. * @brief __NOINLINE definition
  160. */
  161. #if defined ( __CC_ARM ) || defined ( __GNUC__ )
  162. /* ARM & GNUCompiler
  163. ----------------
  164. */
  165. #define __NOINLINE __attribute__ ( (noinline) )
  166. #elif defined ( __ICCARM__ )
  167. /* ICCARM Compiler
  168. ---------------
  169. */
  170. #define __NOINLINE _Pragma("optimize = no_inline")
  171. #endif
  172. #if defined (USE_HAL_DRIVER)
  173. #include "py32f0xx_hal.h"
  174. #endif /* USE_HAL_DRIVER */
  175. #ifdef __cplusplus
  176. }
  177. #endif
  178. #endif /* ___PY32F002B_HAL_DEF */