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