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