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