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