hw_if.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file hw_if.h
  5. * @author MCD Application Team
  6. * @brief Hardware Interface
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
  11. * All rights reserved.</center></h2>
  12. *
  13. * This software component is licensed by ST under Ultimate Liberty license
  14. * SLA0044, the "License"; You may not use this file except in compliance with
  15. * the License. You may obtain a copy of the License at:
  16. * www.st.com/SLA0044
  17. *
  18. ******************************************************************************
  19. */
  20. /* USER CODE END Header */
  21. /* Define to prevent recursive inclusion -------------------------------------*/
  22. #ifndef HW_IF_H
  23. #define HW_IF_H
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. /* Includes ------------------------------------------------------------------*/
  28. #include "stm32wbxx.h"
  29. #include "stm32wbxx_ll_exti.h"
  30. #include "stm32wbxx_ll_system.h"
  31. #include "stm32wbxx_ll_rcc.h"
  32. #include "stm32wbxx_ll_ipcc.h"
  33. #include "stm32wbxx_ll_bus.h"
  34. #include "stm32wbxx_ll_pwr.h"
  35. #include "stm32wbxx_ll_cortex.h"
  36. #include "stm32wbxx_ll_utils.h"
  37. #include "stm32wbxx_ll_hsem.h"
  38. #include "stm32wbxx_ll_gpio.h"
  39. #include "stm32wbxx_ll_rtc.h"
  40. #ifdef USE_STM32WBXX_USB_DONGLE
  41. #include "stm32wbxx_usb_dongle.h"
  42. #endif
  43. #ifdef USE_STM32WBXX_NUCLEO
  44. #include "stm32wbxx_nucleo.h"
  45. #endif
  46. #ifdef USE_X_NUCLEO_EPD
  47. #include "x_nucleo_epd.h"
  48. #endif
  49. /* Private includes ----------------------------------------------------------*/
  50. /* USER CODE BEGIN Includes */
  51. /* USER CODE END Includes */
  52. /******************************************************************************
  53. * HW UART
  54. ******************************************************************************/
  55. typedef enum
  56. {
  57. hw_uart1,
  58. hw_uart2,
  59. hw_lpuart1,
  60. } hw_uart_id_t;
  61. typedef enum
  62. {
  63. hw_uart_ok,
  64. hw_uart_error,
  65. hw_uart_busy,
  66. hw_uart_to,
  67. } hw_status_t;
  68. void HW_UART_Init(hw_uart_id_t hw_uart_id);
  69. void HW_UART_Receive_IT(hw_uart_id_t hw_uart_id, uint8_t *pData, uint16_t Size, void (*Callback)(void));
  70. void HW_UART_Transmit_IT(hw_uart_id_t hw_uart_id, uint8_t *pData, uint16_t Size, void (*Callback)(void));
  71. hw_status_t HW_UART_Transmit(hw_uart_id_t hw_uart_id, uint8_t *p_data, uint16_t size, uint32_t timeout);
  72. hw_status_t HW_UART_Transmit_DMA(hw_uart_id_t hw_uart_id, uint8_t *p_data, uint16_t size, void (*Callback)(void));
  73. void HW_UART_Interrupt_Handler(hw_uart_id_t hw_uart_id);
  74. void HW_UART_DMA_Interrupt_Handler(hw_uart_id_t hw_uart_id);
  75. /******************************************************************************
  76. * HW TimerServer
  77. ******************************************************************************/
  78. /* Exported types ------------------------------------------------------------*/
  79. /**
  80. * This setting is used when standby mode is supported.
  81. * hw_ts_InitMode_Limited should be used when the device restarts from Standby Mode. In that case, the Timer Server does
  82. * not re-initialized its context. Only the Hardware register which content has been lost is reconfigured
  83. * Otherwise, hw_ts_InitMode_Full should be requested (Start from Power ON) and everything is re-initialized.
  84. */
  85. typedef enum
  86. {
  87. hw_ts_InitMode_Full,
  88. hw_ts_InitMode_Limited,
  89. } HW_TS_InitMode_t;
  90. /**
  91. * When a Timer is created as a SingleShot timer, it is not automatically restarted when the timeout occurs. However,
  92. * the timer is kept reserved in the list and could be restarted at anytime with HW_TS_Start()
  93. *
  94. * When a Timer is created as a Repeated timer, it is automatically restarted when the timeout occurs.
  95. */
  96. typedef enum
  97. {
  98. hw_ts_SingleShot,
  99. hw_ts_Repeated
  100. } HW_TS_Mode_t;
  101. /**
  102. * hw_ts_Successful is returned when a Timer has been successfully created with HW_TS_Create(). Otherwise, hw_ts_Failed
  103. * is returned. When hw_ts_Failed is returned, that means there are not enough free slots in the list to create a
  104. * Timer. In that case, CFG_HW_TS_MAX_NBR_CONCURRENT_TIMER should be increased
  105. */
  106. typedef enum
  107. {
  108. hw_ts_Successful,
  109. hw_ts_Failed,
  110. }HW_TS_ReturnStatus_t;
  111. typedef void (*HW_TS_pTimerCb_t)(void);
  112. /**
  113. * @brief Initialize the timer server
  114. * This API shall be called by the application before any timer is requested to the timer server. It
  115. * configures the RTC module to be connected to the LSI input clock.
  116. *
  117. * @param TimerInitMode: When the device restarts from Standby, it should request hw_ts_InitMode_Limited so that the
  118. * Timer context is not re-initialized. Otherwise, hw_ts_InitMode_Full should be requested
  119. * @param hrtc: RTC Handle
  120. * @retval None
  121. */
  122. void HW_TS_Init(HW_TS_InitMode_t TimerInitMode, RTC_HandleTypeDef *hrtc);
  123. /**
  124. * @brief Interface to create a virtual timer
  125. * The user shall call this API to create a timer. Once created, the timer is reserved to the module until it
  126. * has been deleted. When creating a timer, the user shall specify the mode (single shot or repeated), the
  127. * callback to be notified when the timer expires and a module ID to identify in the timer interrupt handler
  128. * which module is concerned. In return, the user gets a timer ID to handle it.
  129. *
  130. * @param TimerProcessID: This is an identifier provided by the user and returned in the callback to allow
  131. * identification of the requester
  132. * @param pTimerId: Timer Id returned to the user to request operation (start, stop, delete)
  133. * @param TimerMode: Mode of the virtual timer (Single shot or repeated)
  134. * @param pTimerCallBack: Callback when the virtual timer expires
  135. * @retval HW_TS_ReturnStatus_t: Return whether the creation is sucessfull or not
  136. */
  137. HW_TS_ReturnStatus_t HW_TS_Create(uint32_t TimerProcessID, uint8_t *pTimerId, HW_TS_Mode_t TimerMode, HW_TS_pTimerCb_t pTimerCallBack);
  138. /**
  139. * @brief Stop a virtual timer
  140. * This API may be used to stop a running timer. A timer which is stopped is move to the pending state.
  141. * A pending timer may be restarted at any time with a different timeout value but the mode cannot be changed.
  142. * Nothing is done when it is called to stop a timer which has been already stopped
  143. *
  144. * @param TimerID: Id of the timer to stop
  145. * @retval None
  146. */
  147. void HW_TS_Stop(uint8_t TimerID);
  148. /**
  149. * @brief Start a virtual timer
  150. * This API shall be used to start a timer. The timeout value is specified and may be different each time.
  151. * When the timer is in the single shot mode, it will move to the pending state when it expires. The user may
  152. * restart it at any time with a different timeout value. When the timer is in the repeated mode, it always
  153. * stay in the running state. When the timer expires, it will be restarted with the same timeout value.
  154. * This API shall not be called on a running timer.
  155. *
  156. * @param TimerID: The ID Id of the timer to start
  157. * @param timeout_ticks: Number of ticks of the virtual timer (Maximum value is (0xFFFFFFFF-0xFFFF = 0xFFFF0000)
  158. * @retval None
  159. */
  160. void HW_TS_Start(uint8_t TimerID, uint32_t timeout_ticks);
  161. /**
  162. * @brief Delete a virtual timer from the list
  163. * This API should be used when a timer is not needed anymore by the user. A deleted timer is removed from
  164. * the timer list managed by the timer server. It cannot be restarted again. The user has to go with the
  165. * creation of a new timer if required and may get a different timer id
  166. *
  167. * @param TimerID: The ID of the timer to remove from the list
  168. * @retval None
  169. */
  170. void HW_TS_Delete(uint8_t TimerID);
  171. /**
  172. * @brief Schedule the timer list on the timer interrupt handler
  173. * This interrupt handler shall be called by the application in the RTC interrupt handler. This handler takes
  174. * care of clearing all status flag required in the RTC and EXTI peripherals
  175. *
  176. * @param None
  177. * @retval None
  178. */
  179. void HW_TS_RTC_Wakeup_Handler(void);
  180. /**
  181. * @brief Return the number of ticks to count before the interrupt
  182. * This API returns the number of ticks left to be counted before an interrupt is generated by the
  183. * Timer Server. This API may be used by the application for power management optimization. When the system
  184. * enters low power mode, the mode selection is a tradeoff between the wakeup time where the CPU is running
  185. * and the time while the CPU will be kept in low power mode before next wakeup. The deeper is the
  186. * low power mode used, the longer is the wakeup time. The low power mode management considering wakeup time
  187. * versus time in low power mode is implementation specific
  188. * When the timer is disabled (No timer in the list), it returns 0xFFFF
  189. *
  190. * @param None
  191. * @retval The number of ticks left to count
  192. */
  193. uint16_t HW_TS_RTC_ReadLeftTicksToCount(void);
  194. /**
  195. * @brief Notify the application that a registered timer has expired
  196. * This API shall be implemented by the user application.
  197. * This API notifies the application that a timer expires. This API is running in the RTC Wakeup interrupt
  198. * context. The application may implement an Operating System to change the context priority where the timer
  199. * callback may be handled. This API provides the module ID to identify which module is concerned and to allow
  200. * sending the information to the correct task
  201. *
  202. * @param TimerProcessID: The TimerProcessId associated with the timer when it has been created
  203. * @param TimerID: The TimerID of the expired timer
  204. * @param pTimerCallBack: The Callback associated with the timer when it has been created
  205. * @retval None
  206. */
  207. void HW_TS_RTC_Int_AppNot(uint32_t TimerProcessID, uint8_t TimerID, HW_TS_pTimerCb_t pTimerCallBack);
  208. /**
  209. * @brief Notify the application that the wakeupcounter has been updated
  210. * This API should be implemented by the user application
  211. * This API notifies the application that the counter has been updated. This is expected to be used along
  212. * with the HW_TS_RTC_ReadLeftTicksToCount () API. It could be that the counter has been updated since the
  213. * last call of HW_TS_RTC_ReadLeftTicksToCount () and before entering low power mode. This notification
  214. * provides a way to the application to solve that race condition to reevaluate the counter value before
  215. * entering low power mode
  216. *
  217. * @param None
  218. * @retval None
  219. */
  220. void HW_TS_RTC_CountUpdated_AppNot(void);
  221. #ifdef __cplusplus
  222. }
  223. #endif
  224. #endif /*HW_IF_H */
  225. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/