You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

9278 lines
315 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_hal_hrtim.c
  4. * @author MCD Application Team
  5. * @brief TIM HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the High Resolution Timer (HRTIM) peripheral:
  8. * + HRTIM Initialization
  9. * + Timer Time Base Unit Configuration
  10. * + Simple Time Base Start/Stop
  11. * + Simple Time Base Start/Stop Interrupt
  12. * + Simple Time Base Start/Stop DMA Request
  13. * + Simple Output Compare/PWM Channel Configuration
  14. * + Simple Output Compare/PWM Channel Start/Stop Interrupt
  15. * + Simple Output Compare/PWM Channel Start/Stop DMA Request
  16. * + Simple Input Capture Channel Configuration
  17. * + Simple Input Capture Channel Start/Stop Interrupt
  18. * + Simple Input Capture Channel Start/Stop DMA Request
  19. * + Simple One Pulse Channel Configuration
  20. * + Simple One Pulse Channel Start/Stop Interrupt
  21. * + HRTIM External Synchronization Configuration
  22. * + HRTIM Burst Mode Controller Configuration
  23. * + HRTIM Burst Mode Controller Enabling
  24. * + HRTIM External Events Conditioning Configuration
  25. * + HRTIM Faults Conditioning Configuration
  26. * + HRTIM Faults Enabling
  27. * + HRTIM ADC trigger Configuration
  28. * + Waveform Timer Configuration
  29. * + Waveform Event Filtering Configuration
  30. * + Waveform Dead Time Insertion Configuration
  31. * + Waveform Chopper Mode Configuration
  32. * + Waveform Compare Unit Configuration
  33. * + Waveform Capture Unit Configuration
  34. * + Waveform Output Configuration
  35. * + Waveform Counter Start/Stop
  36. * + Waveform Counter Start/Stop Interrupt
  37. * + Waveform Counter Start/Stop DMA Request
  38. * + Waveform Output Enabling
  39. * + Waveform Output Level Set/Get
  40. * + Waveform Output State Get
  41. * + Waveform Burst DMA Operation Configuration
  42. * + Waveform Burst DMA Operation Start
  43. * + Waveform Timer Counter Software Reset
  44. * + Waveform Capture Software Trigger
  45. * + Waveform Burst Mode Controller Software Trigger
  46. * + Waveform Timer Pre-loadable Registers Update Enabling
  47. * + Waveform Timer Pre-loadable Registers Software Update
  48. * + Waveform Timer Delayed Protection Status Get
  49. * + Waveform Timer Burst Status Get
  50. * + Waveform Timer Push-Pull Status Get
  51. * + Peripheral State Get
  52. @verbatim
  53. ==============================================================================
  54. ##### Simple mode v.s. waveform mode #####
  55. ==============================================================================
  56. [..] The HRTIM HAL API is split into 2 categories:
  57. (#)Simple functions: these functions allow for using a HRTIM timer as a
  58. general purpose timer with high resolution capabilities.
  59. HRTIM simple modes are managed through the set of functions named
  60. HAL_HRTIM_Simple<Function>. These functions are similar in name and usage
  61. to the one defined for the TIM peripheral. When a HRTIM timer operates in
  62. simple mode, only a very limited set of HRTIM features are used.
  63. Following simple modes are proposed:
  64. (++)Output compare mode,
  65. (++)PWM output mode,
  66. (++)Input capture mode,
  67. (++)One pulse mode.
  68. (#)Waveform functions: These functions allow taking advantage of the HRTIM
  69. flexibility to produce numerous types of control signal. When a HRTIM timer
  70. operates in waveform mode, all the HRTIM features are accessible without
  71. any restriction. HRTIM waveform modes are managed through the set of
  72. functions named HAL_HRTIM_Waveform<Function>
  73. ##### How to use this driver #####
  74. ==============================================================================
  75. [..]
  76. (#)Initialize the HRTIM low level resources by implementing the
  77. HAL_HRTIM_MspInit() function:
  78. (##)Enable the HRTIM clock source using __HRTIMx_CLK_ENABLE()
  79. (##)Connect HRTIM pins to MCU I/Os
  80. (+++) Enable the clock for the HRTIM GPIOs using the following
  81. function: __HAL_RCC_GPIOx_CLK_ENABLE()
  82. (+++) Configure these GPIO pins in Alternate Function mode using
  83. HAL_GPIO_Init()
  84. (##)When using DMA to control data transfer (e.g HAL_HRTIM_SimpleBaseStart_DMA())
  85. (+++)Enable the DMAx interface clock using __DMAx_CLK_ENABLE()
  86. (+++)Initialize the DMA handle
  87. (+++)Associate the initialized DMA handle to the appropriate DMA
  88. handle of the HRTIM handle using __HAL_LINKDMA()
  89. (+++)Initialize the DMA channel using HAL_DMA_Init()
  90. (+++)Configure the priority and enable the NVIC for the transfer
  91. complete interrupt on the DMA channel using HAL_NVIC_SetPriority()
  92. and HAL_NVIC_EnableIRQ()
  93. (##)In case of using interrupt mode (e.g HAL_HRTIM_SimpleBaseStart_IT())
  94. (+++)Configure the priority and enable the NVIC for the concerned
  95. HRTIM interrupt using HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ()
  96. (#)Initialize the HRTIM HAL using HAL_HRTIM_Init(). The HRTIM configuration
  97. structure (field of the HRTIM handle) specifies which global interrupt of
  98. whole HRTIM must be enabled (Burst mode period, System fault, Faults).
  99. It also contains the HRTIM external synchronization configuration. HRTIM
  100. can act as a master (generating a synchronization signal) or as a slave
  101. (waiting for a trigger to be synchronized).
  102. (#) Configure HRTIM resources shared by all HRTIM timers
  103. (##)Burst Mode Controller:
  104. (+++)HAL_HRTIM_BurstModeConfig(): configures the HRTIM burst mode
  105. controller: operating mode (continuous or one-shot mode), clock
  106. (source, prescaler) , trigger(s), period, idle duration.
  107. (##)External Events Conditioning:
  108. (+++)HAL_HRTIM_EventConfig(): configures the conditioning of an
  109. external event channel: source, polarity, edge-sensitivity.
  110. External event can be used as triggers (timer reset, input
  111. capture, burst mode, ADC triggers, delayed protection)
  112. They can also be used to set or reset timer outputs. Up to
  113. 10 event channels are available.
  114. (+++)HAL_HRTIM_EventPrescalerConfig(): configures the external
  115. event sampling clock (used for digital filtering).
  116. (##)Fault Conditioning:
  117. (+++)HAL_HRTIM_FaultConfig(): configures the conditioning of a
  118. fault channel: source, polarity, edge-sensitivity. Fault
  119. channels are used to disable the outputs in case of an
  120. abnormal operation. Up to 5 fault channels are available.
  121. (+++)HAL_HRTIM_FaultPrescalerConfig(): configures the fault
  122. sampling clock (used for digital filtering).
  123. (+++)HAL_HRTIM_FaultModeCtl(): Enables or disables fault input(s)
  124. circuitry. By default all fault inputs are disabled.
  125. (##)ADC trigger:
  126. (+++)HAL_HRTIM_ADCTriggerConfig(): configures the source triggering
  127. the update of the ADC trigger register and the ADC trigger.
  128. 4 independent triggers are available to start both the regular
  129. and the injected sequencers of the 2 ADCs
  130. (#) Configure HRTIM timer time base using HAL_HRTIM_TimeBaseConfig(). This
  131. function must be called whatever the HRTIM timer operating mode is
  132. (simple v.s. waveform). It configures mainly:
  133. (##)The HRTIM timer counter operating mode (continuous v.s. one shot)
  134. (##)The HRTIM timer clock prescaler
  135. (##)The HRTIM timer period
  136. (##)The HRTIM timer repetition counter
  137. *** If the HRTIM timer operates in simple mode ***
  138. ===================================================
  139. [..]
  140. (#) Start or Stop simple timers
  141. (++)Simple time base: HAL_HRTIM_SimpleBaseStart(),HAL_HRTIM_SimpleBaseStop(),
  142. HAL_HRTIM_SimpleBaseStart_IT(),HAL_HRTIM_SimpleBaseStop_IT(),
  143. HAL_HRTIM_SimpleBaseStart_DMA(),HAL_HRTIM_SimpleBaseStop_DMA().
  144. (++)Simple output compare: HAL_HRTIM_SimpleOCChannelConfig(),
  145. HAL_HRTIM_SimpleOCStart(),HAL_HRTIM_SimpleOCStop(),
  146. HAL_HRTIM_SimpleOCStart_IT(),HAL_HRTIM_SimpleOCStop_IT(),
  147. HAL_HRTIM_SimpleOCStart_DMA(),HAL_HRTIM_SimpleOCStop_DMA(),
  148. (++)Simple PWM output: HAL_HRTIM_SimplePWMChannelConfig(),
  149. HAL_HRTIM_SimplePWMStart(),HAL_HRTIM_SimplePWMStop(),
  150. HAL_HRTIM_SimplePWMStart_IT(),HAL_HRTIM_SimplePWMStop_IT(),
  151. HAL_HRTIM_SimplePWMStart_DMA(),HAL_HRTIM_SimplePWMStop_DMA(),
  152. (++)Simple input capture: HAL_HRTIM_SimpleCaptureChannelConfig(),
  153. HAL_HRTIM_SimpleCaptureStart(),HAL_HRTIM_SimpleCaptureStop(),
  154. HAL_HRTIM_SimpleCaptureStart_IT(),HAL_HRTIM_SimpleCaptureStop_IT(),
  155. HAL_HRTIM_SimpleCaptureStart_DMA(),HAL_HRTIM_SimpleCaptureStop_DMA().
  156. (++)Simple one pulse: HAL_HRTIM_SimpleOnePulseChannelConfig(),
  157. HAL_HRTIM_SimpleOnePulseStart(),HAL_HRTIM_SimpleOnePulseStop(),
  158. HAL_HRTIM_SimpleOnePulseStart_IT(),HAL_HRTIM_SimpleOnePulseStop_It().
  159. *** If the HRTIM timer operates in waveform mode ***
  160. ====================================================
  161. [..]
  162. (#) Completes waveform timer configuration
  163. (++)HAL_HRTIM_WaveformTimerConfig(): configuration of a HRTIM timer
  164. operating in wave form mode mainly consists in:
  165. (+++)Enabling the HRTIM timer interrupts and DMA requests.
  166. (+++)Enabling the half mode for the HRTIM timer.
  167. (+++)Defining how the HRTIM timer reacts to external synchronization input.
  168. (+++)Enabling the push-pull mode for the HRTIM timer.
  169. (+++)Enabling the fault channels for the HRTIM timer.
  170. (+++)Enabling the dead-time insertion for the HRTIM timer.
  171. (+++)Setting the delayed protection mode for the HRTIM timer (source and outputs
  172. on which the delayed protection are applied).
  173. (+++)Specifying the HRTIM timer update and reset triggers.
  174. (+++)Specifying the HRTIM timer registers update policy (e.g. pre-load enabling).
  175. (++)HAL_HRTIM_TimerEventFilteringConfig(): configures external
  176. event blanking and windowing circuitry of a HRTIM timer:
  177. (+++)Blanking: to mask external events during a defined time period a defined time period
  178. (+++)Windowing, to enable external events only during a defined time period
  179. (++)HAL_HRTIM_DeadTimeConfig(): configures the dead-time insertion
  180. unit for a HRTIM timer. Allows to generate a couple of
  181. complementary signals from a single reference waveform,
  182. with programmable delays between active state.
  183. (++)HAL_HRTIM_ChopperModeConfig(): configures the parameters of
  184. the high-frequency carrier signal added on top of the timing
  185. unit output. Chopper mode can be enabled or disabled for each
  186. timer output separately (see HAL_HRTIM_WaveformOutputConfig()).
  187. (++)HAL_HRTIM_BurstDMAConfig(): configures the burst DMA burst
  188. controller. Allows having multiple HRTIM registers updated
  189. with a single DMA request. The burst DMA operation is started
  190. by calling HAL_HRTIM_BurstDMATransfer().
  191. (++)HAL_HRTIM_WaveformCompareConfig():configures the compare unit
  192. of a HRTIM timer. This operation consists in setting the
  193. compare value and possibly specifying the auto delayed mode
  194. for compare units 2 and 4 (allows to have compare events
  195. generated relatively to capture events). Note that when auto
  196. delayed mode is needed, the capture unit associated to the
  197. compare unit must be configured separately.
  198. (++)HAL_HRTIM_WaveformCaptureConfig(): configures the capture unit
  199. of a HRTIM timer. This operation consists in specifying the
  200. source(s) triggering the capture (timer register update event,
  201. external event, timer output set/reset event, other HRTIM
  202. timer related events).
  203. (++)HAL_HRTIM_WaveformOutputConfig(): configuration of a HRTIM timer
  204. output mainly consists in:
  205. (+++)Setting the output polarity (active high or active low),
  206. (+++)Defining the set/reset crossbar for the output,
  207. (+++)Specifying the fault level (active or inactive) in IDLE and FAULT states.,
  208. (#) Set waveform timer output(s) level
  209. (++)HAL_HRTIM_WaveformSetOutputLevel(): forces the output to its
  210. active or inactive level. For example, when deadtime insertion
  211. is enabled it is necessary to force the output level by software
  212. to have the outputs in a complementary state as soon as the RUN mode is entered.
  213. (#) Enable or Disable waveform timer output(s)
  214. (++)HAL_HRTIM_WaveformOutputStart(),HAL_HRTIM_WaveformOutputStop().
  215. (#) Start or Stop waveform HRTIM timer(s).
  216. (++)HAL_HRTIM_WaveformCountStart(),HAL_HRTIM_WaveformCountStop(),
  217. (++)HAL_HRTIM_WaveformCountStart_IT(),HAL_HRTIM_WaveformCountStop_IT(),
  218. (++)HAL_HRTIM_WaveformCountStart_DMA(),HAL_HRTIM_WaveformCountStop_DMA(),
  219. (#) Burst mode controller enabling:
  220. (++)HAL_HRTIM_BurstModeCtl(): activates or de-activates the
  221. burst mode controller.
  222. (#) Some HRTIM operations can be triggered by software:
  223. (++)HAL_HRTIM_BurstModeSoftwareTrigger(): calling this function
  224. trigs the burst operation.
  225. (++)HAL_HRTIM_SoftwareCapture(): calling this function trigs the
  226. capture of the HRTIM timer counter.
  227. (++)HAL_HRTIM_SoftwareUpdate(): calling this function trigs the
  228. update of the pre-loadable registers of the HRTIM timer
  229. (++)HAL_HRTIM_SoftwareReset():calling this function resets the
  230. HRTIM timer counter.
  231. (#) Some functions can be used any time to retrieve HRTIM timer related
  232. information
  233. (++)HAL_HRTIM_GetCapturedValue(): returns actual value of the
  234. capture register of the designated capture unit.
  235. (++)HAL_HRTIM_WaveformGetOutputLevel(): returns actual level
  236. (ACTIVE/INACTIVE) of the designated timer output.
  237. (++)HAL_HRTIM_WaveformGetOutputState():returns actual state
  238. (IDLE/RUN/FAULT) of the designated timer output.
  239. (++)HAL_HRTIM_GetDelayedProtectionStatus():returns actual level
  240. (ACTIVE/INACTIVE) of the designated output when the delayed
  241. protection was triggered.
  242. (++)HAL_HRTIM_GetBurstStatus(): returns the actual status
  243. (ACTIVE/INACTIVE) of the burst mode controller.
  244. (++)HAL_HRTIM_GetCurrentPushPullStatus(): when the push-pull mode
  245. is enabled for the HRTIM timer (see HAL_HRTIM_WaveformTimerConfig()),
  246. the push-pull status indicates on which output the signal is currently
  247. active (e.g signal applied on output 1 and output 2 forced
  248. inactive or vice versa).
  249. (++)HAL_HRTIM_GetIdlePushPullStatus(): when the push-pull mode
  250. is enabled for the HRTIM timer (see HAL_HRTIM_WaveformTimerConfig()),
  251. the idle push-pull status indicates during which period the
  252. delayed protection request occurred (e.g. protection occurred
  253. when the output 1 was active and output 2 forced inactive or
  254. vice versa).
  255. (#) Some functions can be used any time to retrieve actual HRTIM status
  256. (++)HAL_HRTIM_GetState(): returns actual HRTIM instance HAL state.
  257. *** Callback registration ***
  258. =============================
  259. [..]
  260. The compilation flag USE_HAL_HRTIM_REGISTER_CALLBACKS when set to 1
  261. allows the user to configure dynamically the driver callbacks.
  262. Use Functions HAL_HRTIM_RegisterCallback() or HAL_HRTIM_TIMxRegisterCallback()
  263. to register an interrupt callback.
  264. [..]
  265. Function HAL_HRTIM_RegisterCallback() allows to register following callbacks:
  266. (+) Fault1Callback : Fault 1 interrupt callback function
  267. (+) Fault2Callback : Fault 2 interrupt callback function
  268. (+) Fault3Callback : Fault 3 interrupt callback function
  269. (+) Fault4Callback : Fault 4 interrupt callback function
  270. (+) Fault5Callback : Fault 5 interrupt callback function
  271. (+) SystemFaultCallback : System fault interrupt callback function
  272. (+) BurstModePeriodCallback : Burst mode period interrupt callback function
  273. (+) SynchronizationEventCallback : Sync Input interrupt callback function
  274. (+) ErrorCallback : DMA error callback function
  275. (+) MspInitCallback : HRTIM MspInit callback function
  276. (+) MspDeInitCallback : HRTIM MspInit callback function
  277. [..]
  278. Function HAL_HRTIM_TIMxRegisterCallback() allows to register following callbacks:
  279. (+) RegistersUpdateCallback : Timer x Update interrupt callback function
  280. (+) RepetitionEventCallback : Timer x Repetition interrupt callback function
  281. (+) Compare1EventCallback : Timer x Compare 1 match interrupt callback function
  282. (+) Compare2EventCallback : Timer x Compare 2 match interrupt callback function
  283. (+) Compare3EventCallback : Timer x Compare 3 match interrupt callback function
  284. (+) Compare4EventCallback : Timer x Compare 4 match interrupt callback function
  285. (+) Capture1EventCallback : Timer x Capture 1 interrupts callback function
  286. (+) Capture2EventCallback : Timer x Capture 2 interrupts callback function
  287. (+) DelayedProtectionCallback : Timer x Delayed protection interrupt callback function
  288. (+) CounterResetCallback : Timer x counter reset/roll-over interrupt callback function
  289. (+) Output1SetCallback : Timer x output 1 set interrupt callback function
  290. (+) Output1ResetCallback : Timer x output 1 reset interrupt callback function
  291. (+) Output2SetCallback : Timer x output 2 set interrupt callback function
  292. (+) Output2ResetCallback : Timer x output 2 reset interrupt callback function
  293. (+) BurstDMATransferCallback : Timer x Burst DMA completed interrupt callback function
  294. [..]
  295. Both functions take as parameters the HAL peripheral handle, the Callback ID
  296. and a pointer to the user callback function.
  297. [..]
  298. Use function HAL_HRTIM_UnRegisterCallback or HAL_HRTIM_TIMxUnRegisterCallback
  299. to reset a callback to the default weak function. Both functions take as parameters
  300. the HAL peripheral handle and the Callback ID.
  301. [..]
  302. By default, after the HAL_HRTIM_Init() and when the state is HAL_HRTIM_STATE_RESET
  303. all callbacks are set to the corresponding weak functions (e.g HAL_HRTIM_Fault1Callback)
  304. Exception done for MspInit and MspDeInit functions that are reset to the legacy
  305. weak functions in the HAL_HRTIM_Init()/ HAL_HRTIM_DeInit() only when these
  306. callbacks are null (not registered beforehand). If MspInit or MspDeInit are
  307. not null, the HAL_HRTIM_Init()/ HAL_HRTIM_DeInit() keep and use the user
  308. MspInit/MspDeInit callbacks (registered beforehand) whatever the state.
  309. [..]
  310. Callbacks can be registered/unregistered in HAL_HRTIM_STATE_READY state only.
  311. Exception done MspInit/MspDeInit functions that can be registered/unregistered
  312. in HAL_HRTIM_STATE_READY or HAL_HRTIM_STATE_RESET states, thus registered
  313. (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
  314. Then, the user first registers the MspInit/MspDeInit user callbacks
  315. using HAL_HRTIM_RegisterCallback() before calling HAL_HRTIM_DeInit()
  316. or HAL_HRTIM_Init() function.
  317. [..]
  318. When the compilation flag USE_HAL_HRTIM_REGISTER_CALLBACKS is set to 0 or
  319. not defined, the callback registration feature is not available and all
  320. callbacks are set to the corresponding weak functions.
  321. @endverbatim
  322. ******************************************************************************
  323. * @attention
  324. *
  325. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  326. * All rights reserved.</center></h2>
  327. *
  328. * This software component is licensed by ST under BSD 3-Clause license,
  329. * the "License"; You may not use this file except in compliance with the
  330. * License. You may obtain a copy of the License at:
  331. * opensource.org/licenses/BSD-3-Clause
  332. *
  333. ******************************************************************************
  334. */
  335. /* Includes ------------------------------------------------------------------*/
  336. #include "stm32h7xx_hal.h"
  337. /** @addtogroup STM32H7xx_HAL_Driver
  338. * @{
  339. */
  340. #ifdef HAL_HRTIM_MODULE_ENABLED
  341. #if defined(HRTIM1)
  342. /** @defgroup HRTIM HRTIM
  343. * @brief HRTIM HAL module driver
  344. * @{
  345. */
  346. /* Private typedef -----------------------------------------------------------*/
  347. /* Private define ------------------------------------------------------------*/
  348. /** @defgroup HRTIM_Private_Defines HRTIM Private Define
  349. * @{
  350. */
  351. #define HRTIM_FLTR_FLTxEN (HRTIM_FLTR_FLT1EN |\
  352. HRTIM_FLTR_FLT2EN |\
  353. HRTIM_FLTR_FLT3EN |\
  354. HRTIM_FLTR_FLT4EN | \
  355. HRTIM_FLTR_FLT5EN)
  356. #define HRTIM_TIMCR_TIMUPDATETRIGGER (HRTIM_TIMUPDATETRIGGER_MASTER |\
  357. HRTIM_TIMUPDATETRIGGER_TIMER_A |\
  358. HRTIM_TIMUPDATETRIGGER_TIMER_B |\
  359. HRTIM_TIMUPDATETRIGGER_TIMER_C |\
  360. HRTIM_TIMUPDATETRIGGER_TIMER_D |\
  361. HRTIM_TIMUPDATETRIGGER_TIMER_E)
  362. #define HRTIM_FLTINR1_FLTxLCK ((HRTIM_FAULTLOCK_READONLY) | \
  363. (HRTIM_FAULTLOCK_READONLY << 8U) | \
  364. (HRTIM_FAULTLOCK_READONLY << 16U) | \
  365. (HRTIM_FAULTLOCK_READONLY << 24U))
  366. #define HRTIM_FLTINR2_FLTxLCK ((HRTIM_FAULTLOCK_READONLY) | \
  367. (HRTIM_FAULTLOCK_READONLY << 8U))
  368. /**
  369. * @}
  370. */
  371. /* Private macro -------------------------------------------------------------*/
  372. /* Private variables ---------------------------------------------------------*/
  373. /** @defgroup HRTIM_Private_Variables HRTIM Private Variables
  374. * @{
  375. */
  376. static uint32_t TimerIdxToTimerId[] =
  377. {
  378. HRTIM_TIMERID_TIMER_A,
  379. HRTIM_TIMERID_TIMER_B,
  380. HRTIM_TIMERID_TIMER_C,
  381. HRTIM_TIMERID_TIMER_D,
  382. HRTIM_TIMERID_TIMER_E,
  383. HRTIM_TIMERID_MASTER,
  384. };
  385. /**
  386. * @}
  387. */
  388. /* Private function prototypes -----------------------------------------------*/
  389. /** @defgroup HRTIM_Private_Functions HRTIM Private Functions
  390. * @{
  391. */
  392. static void HRTIM_MasterBase_Config(HRTIM_HandleTypeDef * hhrtim,
  393. HRTIM_TimeBaseCfgTypeDef * pTimeBaseCfg);
  394. static void HRTIM_TimingUnitBase_Config(HRTIM_HandleTypeDef * hhrtim,
  395. uint32_t TimerIdx,
  396. HRTIM_TimeBaseCfgTypeDef * pTimeBaseCfg);
  397. static void HRTIM_MasterWaveform_Config(HRTIM_HandleTypeDef * hhrtim,
  398. HRTIM_TimerCfgTypeDef * pTimerCfg);
  399. static void HRTIM_TimingUnitWaveform_Config(HRTIM_HandleTypeDef * hhrtim,
  400. uint32_t TimerIdx,
  401. HRTIM_TimerCfgTypeDef * pTimerCfg);
  402. static void HRTIM_CaptureUnitConfig(HRTIM_HandleTypeDef * hhrtim,
  403. uint32_t TimerIdx,
  404. uint32_t CaptureUnit,
  405. uint32_t Event);
  406. static void HRTIM_OutputConfig(HRTIM_HandleTypeDef * hhrtim,
  407. uint32_t TimerIdx,
  408. uint32_t Output,
  409. HRTIM_OutputCfgTypeDef * pOutputCfg);
  410. static void HRTIM_EventConfig(HRTIM_HandleTypeDef * hhrtim,
  411. uint32_t Event,
  412. HRTIM_EventCfgTypeDef * pEventCfg);
  413. static void HRTIM_TIM_ResetConfig(HRTIM_HandleTypeDef * hhrtim,
  414. uint32_t TimerIdx,
  415. uint32_t Event);
  416. static uint32_t HRTIM_GetITFromOCMode(HRTIM_HandleTypeDef * hhrtim,
  417. uint32_t TimerIdx,
  418. uint32_t OCChannel);
  419. static uint32_t HRTIM_GetDMAFromOCMode(HRTIM_HandleTypeDef * hhrtim,
  420. uint32_t TimerIdx,
  421. uint32_t OCChannel);
  422. static DMA_HandleTypeDef * HRTIM_GetDMAHandleFromTimerIdx(HRTIM_HandleTypeDef * hhrtim,
  423. uint32_t TimerIdx);
  424. static uint32_t GetTimerIdxFromDMAHandle(HRTIM_HandleTypeDef * hhrtim,
  425. DMA_HandleTypeDef * hdma);
  426. static void HRTIM_ForceRegistersUpdate(HRTIM_HandleTypeDef * hhrtim,
  427. uint32_t TimerIdx);
  428. static void HRTIM_HRTIM_ISR(HRTIM_HandleTypeDef * hhrtim);
  429. static void HRTIM_Master_ISR(HRTIM_HandleTypeDef * hhrtim);
  430. static void HRTIM_Timer_ISR(HRTIM_HandleTypeDef * hhrtim,
  431. uint32_t TimerIdx);
  432. static void HRTIM_DMAMasterCplt(DMA_HandleTypeDef *hdma);
  433. static void HRTIM_DMATimerxCplt(DMA_HandleTypeDef *hdma);
  434. static void HRTIM_DMAError(DMA_HandleTypeDef *hdma);
  435. static void HRTIM_BurstDMACplt(DMA_HandleTypeDef *hdma);
  436. /**
  437. * @}
  438. */
  439. /* Exported functions ---------------------------------------------------------*/
  440. /** @defgroup HRTIM_Exported_Functions HRTIM Exported Functions
  441. * @{
  442. */
  443. /** @defgroup HRTIM_Exported_Functions_Group1 Initialization and de-initialization functions
  444. * @brief Initialization and Configuration functions
  445. @verbatim
  446. ===============================================================================
  447. ##### Initialization and Time Base Configuration functions #####
  448. ===============================================================================
  449. [..] This section provides functions allowing to:
  450. (+) Initialize a HRTIM instance
  451. (+) De-initialize a HRTIM instance
  452. (+) Initialize the HRTIM MSP
  453. (+) De-initialize the HRTIM MSP
  454. (+) Configure the time base unit of a HRTIM timer
  455. @endverbatim
  456. * @{
  457. */
  458. /**
  459. * @brief Initialize a HRTIM instance
  460. * @param hhrtim pointer to HAL HRTIM handle
  461. * @retval HAL status
  462. */
  463. HAL_StatusTypeDef HAL_HRTIM_Init(HRTIM_HandleTypeDef * hhrtim)
  464. {
  465. uint8_t timer_idx;
  466. uint32_t hrtim_mcr;
  467. /* Check the HRTIM handle allocation */
  468. if(hhrtim == NULL)
  469. {
  470. return HAL_ERROR;
  471. }
  472. /* Check the parameters */
  473. assert_param(IS_HRTIM_ALL_INSTANCE(hhrtim->Instance));
  474. assert_param(IS_HRTIM_IT(hhrtim->Init.HRTIMInterruptResquests));
  475. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  476. if (hhrtim->State == HAL_HRTIM_STATE_RESET)
  477. {
  478. /* Initialize callback function pointers to their default values */
  479. hhrtim->Fault1Callback = HAL_HRTIM_Fault1Callback;
  480. hhrtim->Fault2Callback = HAL_HRTIM_Fault2Callback;
  481. hhrtim->Fault3Callback = HAL_HRTIM_Fault3Callback;
  482. hhrtim->Fault4Callback = HAL_HRTIM_Fault4Callback;
  483. hhrtim->Fault5Callback = HAL_HRTIM_Fault5Callback;
  484. hhrtim->SystemFaultCallback = HAL_HRTIM_SystemFaultCallback;
  485. hhrtim->BurstModePeriodCallback = HAL_HRTIM_BurstModePeriodCallback;
  486. hhrtim->SynchronizationEventCallback = HAL_HRTIM_SynchronizationEventCallback;
  487. hhrtim->ErrorCallback = HAL_HRTIM_ErrorCallback;
  488. hhrtim->RegistersUpdateCallback = HAL_HRTIM_RegistersUpdateCallback;
  489. hhrtim->RepetitionEventCallback = HAL_HRTIM_RepetitionEventCallback;
  490. hhrtim->Compare1EventCallback = HAL_HRTIM_Compare1EventCallback;
  491. hhrtim->Compare2EventCallback = HAL_HRTIM_Compare2EventCallback;
  492. hhrtim->Compare3EventCallback = HAL_HRTIM_Compare3EventCallback;
  493. hhrtim->Compare4EventCallback = HAL_HRTIM_Compare4EventCallback;
  494. hhrtim->Capture1EventCallback = HAL_HRTIM_Capture1EventCallback;
  495. hhrtim->Capture2EventCallback = HAL_HRTIM_Capture2EventCallback;
  496. hhrtim->DelayedProtectionCallback = HAL_HRTIM_DelayedProtectionCallback;
  497. hhrtim->CounterResetCallback = HAL_HRTIM_CounterResetCallback;
  498. hhrtim->Output1SetCallback = HAL_HRTIM_Output1SetCallback;
  499. hhrtim->Output1ResetCallback = HAL_HRTIM_Output1ResetCallback;
  500. hhrtim->Output2SetCallback = HAL_HRTIM_Output2SetCallback;
  501. hhrtim->Output2ResetCallback = HAL_HRTIM_Output2ResetCallback;
  502. hhrtim->BurstDMATransferCallback = HAL_HRTIM_BurstDMATransferCallback;
  503. if (hhrtim->MspInitCallback == NULL)
  504. {
  505. hhrtim->MspInitCallback = HAL_HRTIM_MspInit;
  506. }
  507. }
  508. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  509. /* Set the HRTIM state */
  510. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  511. /* Initialize the DMA handles */
  512. hhrtim->hdmaMaster = (DMA_HandleTypeDef *)NULL;
  513. hhrtim->hdmaTimerA = (DMA_HandleTypeDef *)NULL;
  514. hhrtim->hdmaTimerB = (DMA_HandleTypeDef *)NULL;
  515. hhrtim->hdmaTimerC = (DMA_HandleTypeDef *)NULL;
  516. hhrtim->hdmaTimerD = (DMA_HandleTypeDef *)NULL;
  517. hhrtim->hdmaTimerE = (DMA_HandleTypeDef *)NULL;
  518. /* HRTIM output synchronization configuration (if required) */
  519. if ((hhrtim->Init.SyncOptions & HRTIM_SYNCOPTION_MASTER) != (uint32_t)RESET)
  520. {
  521. /* Check parameters */
  522. assert_param(IS_HRTIM_SYNCOUTPUTSOURCE(hhrtim->Init.SyncOutputSource));
  523. assert_param(IS_HRTIM_SYNCOUTPUTPOLARITY(hhrtim->Init.SyncOutputPolarity));
  524. /* The synchronization output initialization procedure must be done prior
  525. to the configuration of the MCU outputs (done within HAL_HRTIM_MspInit)
  526. */
  527. if (hhrtim->Instance == HRTIM1)
  528. {
  529. /* Enable the HRTIM peripheral clock */
  530. __HAL_RCC_HRTIM1_CLK_ENABLE();
  531. }
  532. hrtim_mcr = hhrtim->Instance->sMasterRegs.MCR;
  533. /* Set the event to be sent on the synchronization output */
  534. hrtim_mcr &= ~(HRTIM_MCR_SYNC_SRC);
  535. hrtim_mcr |= (hhrtim->Init.SyncOutputSource & HRTIM_MCR_SYNC_SRC);
  536. /* Set the polarity of the synchronization output */
  537. hrtim_mcr &= ~(HRTIM_MCR_SYNC_OUT);
  538. hrtim_mcr |= (hhrtim->Init.SyncOutputPolarity & HRTIM_MCR_SYNC_OUT);
  539. /* Update the HRTIM registers */
  540. hhrtim->Instance->sMasterRegs.MCR = hrtim_mcr;
  541. }
  542. /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
  543. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  544. hhrtim->MspInitCallback(hhrtim);
  545. #else
  546. HAL_HRTIM_MspInit(hhrtim);
  547. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  548. /* HRTIM input synchronization configuration (if required) */
  549. if ((hhrtim->Init.SyncOptions & HRTIM_SYNCOPTION_SLAVE) != (uint32_t)RESET)
  550. {
  551. /* Check parameters */
  552. assert_param(IS_HRTIM_SYNCINPUTSOURCE(hhrtim->Init.SyncInputSource));
  553. hrtim_mcr = hhrtim->Instance->sMasterRegs.MCR;
  554. /* Set the synchronization input source */
  555. hrtim_mcr &= ~(HRTIM_MCR_SYNC_IN);
  556. hrtim_mcr |= (hhrtim->Init.SyncInputSource & HRTIM_MCR_SYNC_IN);
  557. /* Update the HRTIM registers */
  558. hhrtim->Instance->sMasterRegs.MCR = hrtim_mcr;
  559. }
  560. /* Initialize the HRTIM state*/
  561. hhrtim->State = HAL_HRTIM_STATE_READY;
  562. /* Initialize the lock status of the HRTIM HAL API */
  563. __HAL_UNLOCK(hhrtim);
  564. /* Initialize timer related parameters */
  565. for (timer_idx = HRTIM_TIMERINDEX_TIMER_A ;
  566. timer_idx <= HRTIM_TIMERINDEX_MASTER ;
  567. timer_idx++)
  568. {
  569. hhrtim->TimerParam[timer_idx].CaptureTrigger1 = HRTIM_CAPTURETRIGGER_NONE;
  570. hhrtim->TimerParam[timer_idx].CaptureTrigger2 = HRTIM_CAPTURETRIGGER_NONE;
  571. hhrtim->TimerParam[timer_idx].InterruptRequests = HRTIM_IT_NONE;
  572. hhrtim->TimerParam[timer_idx].DMARequests = HRTIM_IT_NONE;
  573. hhrtim->TimerParam[timer_idx].DMASrcAddress = 0U;
  574. hhrtim->TimerParam[timer_idx].DMASize = 0U;
  575. }
  576. return HAL_OK;
  577. }
  578. /**
  579. * @brief De-initialize a HRTIM instance
  580. * @param hhrtim pointer to HAL HRTIM handle
  581. * @retval HAL status
  582. */
  583. HAL_StatusTypeDef HAL_HRTIM_DeInit (HRTIM_HandleTypeDef * hhrtim)
  584. {
  585. /* Check the HRTIM handle allocation */
  586. if(hhrtim == NULL)
  587. {
  588. return HAL_ERROR;
  589. }
  590. /* Check the parameters */
  591. assert_param(IS_HRTIM_ALL_INSTANCE(hhrtim->Instance));
  592. /* Set the HRTIM state */
  593. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  594. /* DeInit the low level hardware */
  595. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  596. if (hhrtim->MspDeInitCallback == NULL)
  597. {
  598. hhrtim->MspDeInitCallback = HAL_HRTIM_MspDeInit;
  599. }
  600. hhrtim->MspDeInitCallback(hhrtim);
  601. #else
  602. HAL_HRTIM_MspDeInit(hhrtim);
  603. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  604. hhrtim->State = HAL_HRTIM_STATE_READY;
  605. return HAL_OK;
  606. }
  607. /**
  608. * @brief MSP initialization for a HRTIM instance
  609. * @param hhrtim pointer to HAL HRTIM handle
  610. * @retval None
  611. */
  612. __weak void HAL_HRTIM_MspInit(HRTIM_HandleTypeDef * hhrtim)
  613. {
  614. /* Prevent unused argument(s) compilation warning */
  615. UNUSED(hhrtim);
  616. /* NOTE: This function should not be modified, when the callback is needed,
  617. the HAL_HRTIM_MspInit could be implemented in the user file
  618. */
  619. }
  620. /**
  621. * @brief MSP de-initialization of a HRTIM instance
  622. * @param hhrtim pointer to HAL HRTIM handle
  623. * @retval None
  624. */
  625. __weak void HAL_HRTIM_MspDeInit(HRTIM_HandleTypeDef * hhrtim)
  626. {
  627. /* Prevent unused argument(s) compilation warning */
  628. UNUSED(hhrtim);
  629. /* NOTE: This function should not be modified, when the callback is needed,
  630. the HAL_HRTIM_MspDeInit could be implemented in the user file
  631. */
  632. }
  633. /**
  634. * @brief Configure the time base unit of a timer
  635. * @param hhrtim pointer to HAL HRTIM handle
  636. * @param TimerIdx Timer index
  637. * This parameter can be one of the following values:
  638. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  639. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  640. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  641. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  642. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  643. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  644. * @param pTimeBaseCfg pointer to the time base configuration structure
  645. * @note This function must be called prior starting the timer
  646. * @note The time-base unit initialization parameters specify:
  647. * The timer counter operating mode (continuous, one shot),
  648. * The timer clock prescaler,
  649. * The timer period,
  650. * The timer repetition counter.
  651. * @retval HAL status
  652. */
  653. HAL_StatusTypeDef HAL_HRTIM_TimeBaseConfig(HRTIM_HandleTypeDef *hhrtim,
  654. uint32_t TimerIdx,
  655. HRTIM_TimeBaseCfgTypeDef * pTimeBaseCfg)
  656. {
  657. /* Check the parameters */
  658. assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
  659. assert_param(IS_HRTIM_PRESCALERRATIO(pTimeBaseCfg->PrescalerRatio));
  660. assert_param(IS_HRTIM_MODE(pTimeBaseCfg->Mode));
  661. if(hhrtim->State == HAL_HRTIM_STATE_BUSY)
  662. {
  663. return HAL_BUSY;
  664. }
  665. /* Set the HRTIM state */
  666. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  667. if (TimerIdx == HRTIM_TIMERINDEX_MASTER)
  668. {
  669. /* Configure master timer time base unit */
  670. HRTIM_MasterBase_Config(hhrtim, pTimeBaseCfg);
  671. }
  672. else
  673. {
  674. /* Configure timing unit time base unit */
  675. HRTIM_TimingUnitBase_Config(hhrtim, TimerIdx, pTimeBaseCfg);
  676. }
  677. /* Set HRTIM state */
  678. hhrtim->State = HAL_HRTIM_STATE_READY;
  679. return HAL_OK;
  680. }
  681. /**
  682. * @}
  683. */
  684. /** @defgroup HRTIM_Exported_Functions_Group2 Simple time base mode functions
  685. * @brief Simple time base mode functions.
  686. @verbatim
  687. ===============================================================================
  688. ##### Simple time base mode functions #####
  689. ===============================================================================
  690. [..] This section provides functions allowing to:
  691. (+) Start simple time base
  692. (+) Stop simple time base
  693. (+) Start simple time base and enable interrupt
  694. (+) Stop simple time base and disable interrupt
  695. (+) Start simple time base and enable DMA transfer
  696. (+) Stop simple time base and disable DMA transfer
  697. -@- When a HRTIM timer operates in simple time base mode, the timer
  698. counter counts from 0 to the period value.
  699. @endverbatim
  700. * @{
  701. */
  702. /**
  703. * @brief Start the counter of a timer operating in simple time base mode.
  704. * @param hhrtim pointer to HAL HRTIM handle
  705. * @param TimerIdx Timer index.
  706. * This parameter can be one of the following values:
  707. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  708. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  709. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  710. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  711. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  712. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  713. * @retval HAL status
  714. */
  715. HAL_StatusTypeDef HAL_HRTIM_SimpleBaseStart(HRTIM_HandleTypeDef * hhrtim,
  716. uint32_t TimerIdx)
  717. {
  718. /* Check the parameters */
  719. assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
  720. /* Process Locked */
  721. __HAL_LOCK(hhrtim);
  722. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  723. /* Enable the timer counter */
  724. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  725. hhrtim->State = HAL_HRTIM_STATE_READY;
  726. /* Process Unlocked */
  727. __HAL_UNLOCK(hhrtim);
  728. return HAL_OK;
  729. }
  730. /**
  731. * @brief Stop the counter of a timer operating in simple time base mode.
  732. * @param hhrtim pointer to HAL HRTIM handle
  733. * @param TimerIdx Timer index.
  734. * This parameter can be one of the following values:
  735. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  736. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  737. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  738. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  739. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  740. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  741. * @retval HAL status
  742. */
  743. HAL_StatusTypeDef HAL_HRTIM_SimpleBaseStop(HRTIM_HandleTypeDef * hhrtim,
  744. uint32_t TimerIdx)
  745. {
  746. /* Check the parameters */
  747. assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
  748. /* Process Locked */
  749. __HAL_LOCK(hhrtim);
  750. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  751. /* Disable the timer counter */
  752. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  753. hhrtim->State = HAL_HRTIM_STATE_READY;
  754. /* Process Unlocked */
  755. __HAL_UNLOCK(hhrtim);
  756. return HAL_OK;
  757. }
  758. /**
  759. * @brief Start the counter of a timer operating in simple time base mode
  760. * (Timer repetition interrupt is enabled).
  761. * @param hhrtim pointer to HAL HRTIM handle
  762. * @param TimerIdx Timer index.
  763. * This parameter can be one of the following values:
  764. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  765. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  766. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  767. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  768. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  769. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  770. * @retval HAL status
  771. */
  772. HAL_StatusTypeDef HAL_HRTIM_SimpleBaseStart_IT(HRTIM_HandleTypeDef * hhrtim,
  773. uint32_t TimerIdx)
  774. {
  775. /* Check the parameters */
  776. assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
  777. /* Process Locked */
  778. __HAL_LOCK(hhrtim);
  779. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  780. /* Enable the repetition interrupt */
  781. if (TimerIdx == HRTIM_TIMERINDEX_MASTER)
  782. {
  783. __HAL_HRTIM_MASTER_ENABLE_IT(hhrtim, HRTIM_MASTER_IT_MREP);
  784. }
  785. else
  786. {
  787. __HAL_HRTIM_TIMER_ENABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_REP);
  788. }
  789. /* Enable the timer counter */
  790. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  791. hhrtim->State = HAL_HRTIM_STATE_READY;
  792. /* Process Unlocked */
  793. __HAL_UNLOCK(hhrtim);
  794. return HAL_OK;
  795. }
  796. /**
  797. * @brief Stop the counter of a timer operating in simple time base mode
  798. * (Timer repetition interrupt is disabled).
  799. * @param hhrtim pointer to HAL HRTIM handle
  800. * @param TimerIdx Timer index.
  801. * This parameter can be one of the following values:
  802. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  803. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  804. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  805. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  806. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  807. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  808. * @retval HAL status
  809. */
  810. HAL_StatusTypeDef HAL_HRTIM_SimpleBaseStop_IT(HRTIM_HandleTypeDef * hhrtim,
  811. uint32_t TimerIdx)
  812. {
  813. /* Check the parameters */
  814. assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
  815. /* Process Locked */
  816. __HAL_LOCK(hhrtim);
  817. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  818. /* Disable the repetition interrupt */
  819. if (TimerIdx == HRTIM_TIMERINDEX_MASTER)
  820. {
  821. __HAL_HRTIM_MASTER_DISABLE_IT(hhrtim, HRTIM_MASTER_IT_MREP);
  822. }
  823. else
  824. {
  825. __HAL_HRTIM_TIMER_DISABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_REP);
  826. }
  827. /* Disable the timer counter */
  828. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  829. hhrtim->State = HAL_HRTIM_STATE_READY;
  830. /* Process Unlocked */
  831. __HAL_UNLOCK(hhrtim);
  832. return HAL_OK;
  833. }
  834. /**
  835. * @brief Start the counter of a timer operating in simple time base mode
  836. * (Timer repetition DMA request is enabled).
  837. * @param hhrtim pointer to HAL HRTIM handle
  838. * @param TimerIdx Timer index.
  839. * This parameter can be one of the following values:
  840. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  841. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  842. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  843. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  844. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  845. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  846. * @param SrcAddr DMA transfer source address
  847. * @param DestAddr DMA transfer destination address
  848. * @param Length The length of data items (data size) to be transferred
  849. * from source to destination
  850. */
  851. HAL_StatusTypeDef HAL_HRTIM_SimpleBaseStart_DMA(HRTIM_HandleTypeDef * hhrtim,
  852. uint32_t TimerIdx,
  853. uint32_t SrcAddr,
  854. uint32_t DestAddr,
  855. uint32_t Length)
  856. {
  857. DMA_HandleTypeDef * hdma;
  858. /* Check the parameters */
  859. assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
  860. if(hhrtim->State == HAL_HRTIM_STATE_BUSY)
  861. {
  862. return HAL_BUSY;
  863. }
  864. if(hhrtim->State == HAL_HRTIM_STATE_READY)
  865. {
  866. if((SrcAddr == 0U ) || (DestAddr == 0U ) || (Length == 0U))
  867. {
  868. return HAL_ERROR;
  869. }
  870. else
  871. {
  872. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  873. }
  874. }
  875. /* Process Locked */
  876. __HAL_LOCK(hhrtim);
  877. /* Get the timer DMA handler */
  878. hdma = HRTIM_GetDMAHandleFromTimerIdx(hhrtim, TimerIdx);
  879. if (hdma == NULL)
  880. {
  881. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  882. /* Process Unlocked */
  883. __HAL_UNLOCK(hhrtim);
  884. return HAL_ERROR;
  885. }
  886. /* Set the DMA transfer completed callback */
  887. if (TimerIdx == HRTIM_TIMERINDEX_MASTER)
  888. {
  889. hdma->XferCpltCallback = HRTIM_DMAMasterCplt;
  890. }
  891. else
  892. {
  893. hdma->XferCpltCallback = HRTIM_DMATimerxCplt;
  894. }
  895. /* Set the DMA error callback */
  896. hdma->XferErrorCallback = HRTIM_DMAError ;
  897. /* Enable the DMA channel */
  898. if (HAL_DMA_Start_IT(hdma, SrcAddr, DestAddr, Length) != HAL_OK)
  899. {
  900. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  901. /* Process Unlocked */
  902. __HAL_UNLOCK(hhrtim);
  903. return HAL_ERROR;
  904. }
  905. /* Enable the timer repetition DMA request */
  906. if (TimerIdx == HRTIM_TIMERINDEX_MASTER)
  907. {
  908. __HAL_HRTIM_MASTER_ENABLE_DMA(hhrtim, HRTIM_MASTER_DMA_MREP);
  909. }
  910. else
  911. {
  912. __HAL_HRTIM_TIMER_ENABLE_DMA(hhrtim, TimerIdx, HRTIM_TIM_DMA_REP);
  913. }
  914. /* Enable the timer counter */
  915. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  916. hhrtim->State = HAL_HRTIM_STATE_READY;
  917. /* Process Unlocked */
  918. __HAL_UNLOCK(hhrtim);
  919. return HAL_OK;
  920. }
  921. /**
  922. * @brief Stop the counter of a timer operating in simple time base mode
  923. * (Timer repetition DMA request is disabled).
  924. * @param hhrtim pointer to HAL HRTIM handle
  925. * @param TimerIdx Timer index.
  926. * This parameter can be one of the following values:
  927. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  928. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  929. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  930. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  931. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  932. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  933. * @retval HAL status
  934. */
  935. HAL_StatusTypeDef HAL_HRTIM_SimpleBaseStop_DMA(HRTIM_HandleTypeDef * hhrtim,
  936. uint32_t TimerIdx)
  937. {
  938. DMA_HandleTypeDef * hdma;
  939. /* Check the parameters */
  940. assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
  941. /* Process Locked */
  942. __HAL_LOCK(hhrtim);
  943. if (TimerIdx == HRTIM_TIMERINDEX_MASTER)
  944. {
  945. hhrtim->State = HAL_HRTIM_STATE_READY;
  946. /* Disable the DMA */
  947. if (HAL_DMA_Abort(hhrtim->hdmaMaster) != HAL_OK)
  948. {
  949. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  950. }
  951. /* Disable the timer repetition DMA request */
  952. __HAL_HRTIM_MASTER_DISABLE_DMA(hhrtim, HRTIM_MASTER_DMA_MREP);
  953. }
  954. else
  955. {
  956. /* Get the timer DMA handler */
  957. hdma = HRTIM_GetDMAHandleFromTimerIdx(hhrtim, TimerIdx);
  958. if (hdma == NULL)
  959. {
  960. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  961. }
  962. else
  963. {
  964. hhrtim->State = HAL_HRTIM_STATE_READY;
  965. /* Disable the DMA */
  966. if (HAL_DMA_Abort(hdma) != HAL_OK)
  967. {
  968. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  969. }
  970. /* Disable the timer repetition DMA request */
  971. __HAL_HRTIM_TIMER_DISABLE_DMA(hhrtim, TimerIdx, HRTIM_TIM_DMA_REP);
  972. }
  973. }
  974. /* Disable the timer counter */
  975. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  976. /* Process Unlocked */
  977. __HAL_UNLOCK(hhrtim);
  978. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  979. {
  980. return HAL_ERROR;
  981. }
  982. else
  983. {
  984. return HAL_OK;
  985. }
  986. }
  987. /**
  988. * @}
  989. */
  990. /** @defgroup HRTIM_Exported_Functions_Group3 Simple output compare mode functions
  991. * @brief Simple output compare functions
  992. @verbatim
  993. ===============================================================================
  994. ##### Simple output compare functions #####
  995. ===============================================================================
  996. [..] This section provides functions allowing to:
  997. (+) Configure simple output channel
  998. (+) Start simple output compare
  999. (+) Stop simple output compare
  1000. (+) Start simple output compare and enable interrupt
  1001. (+) Stop simple output compare and disable interrupt
  1002. (+) Start simple output compare and enable DMA transfer
  1003. (+) Stop simple output compare and disable DMA transfer
  1004. -@- When a HRTIM timer operates in simple output compare mode
  1005. the output level is set to a programmable value when a match
  1006. is found between the compare register and the counter.
  1007. Compare unit 1 is automatically associated to output 1
  1008. Compare unit 2 is automatically associated to output 2
  1009. @endverbatim
  1010. * @{
  1011. */
  1012. /**
  1013. * @brief Configure an output in simple output compare mode
  1014. * @param hhrtim pointer to HAL HRTIM handle
  1015. * @param TimerIdx Timer index
  1016. * This parameter can be one of the following values:
  1017. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  1018. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  1019. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  1020. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  1021. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  1022. * @param OCChannel Timer output
  1023. * This parameter can be one of the following values:
  1024. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  1025. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  1026. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  1027. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  1028. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  1029. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  1030. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  1031. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  1032. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  1033. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  1034. * @param pSimpleOCChannelCfg pointer to the simple output compare output configuration structure
  1035. * @note When the timer operates in simple output compare mode:
  1036. * Output 1 is implicitly controlled by the compare unit 1
  1037. * Output 2 is implicitly controlled by the compare unit 2
  1038. * Output Set/Reset crossbar is set according to the selected output compare mode:
  1039. * Toggle: SETxyR = RSTxyR = CMPy
  1040. * Active: SETxyR = CMPy, RSTxyR = 0
  1041. * Inactive: SETxy =0, RSTxy = CMPy
  1042. * @retval HAL status
  1043. */
  1044. HAL_StatusTypeDef HAL_HRTIM_SimpleOCChannelConfig(HRTIM_HandleTypeDef * hhrtim,
  1045. uint32_t TimerIdx,
  1046. uint32_t OCChannel,
  1047. HRTIM_SimpleOCChannelCfgTypeDef* pSimpleOCChannelCfg)
  1048. {
  1049. uint32_t CompareUnit = (uint32_t)RESET;
  1050. HRTIM_OutputCfgTypeDef OutputCfg;
  1051. /* Check parameters */
  1052. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OCChannel));
  1053. assert_param(IS_HRTIM_BASICOCMODE(pSimpleOCChannelCfg->Mode));
  1054. assert_param(IS_HRTIM_OUTPUTPULSE(pSimpleOCChannelCfg->Pulse));
  1055. assert_param(IS_HRTIM_OUTPUTPOLARITY(pSimpleOCChannelCfg->Polarity));
  1056. assert_param(IS_HRTIM_OUTPUTIDLELEVEL(pSimpleOCChannelCfg->IdleLevel));
  1057. if(hhrtim->State == HAL_HRTIM_STATE_BUSY)
  1058. {
  1059. return HAL_BUSY;
  1060. }
  1061. /* Set HRTIM state */
  1062. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  1063. /* Configure timer compare unit */
  1064. switch (OCChannel)
  1065. {
  1066. case HRTIM_OUTPUT_TA1:
  1067. case HRTIM_OUTPUT_TB1:
  1068. case HRTIM_OUTPUT_TC1:
  1069. case HRTIM_OUTPUT_TD1:
  1070. case HRTIM_OUTPUT_TE1:
  1071. {
  1072. CompareUnit = HRTIM_COMPAREUNIT_1;
  1073. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP1xR = pSimpleOCChannelCfg->Pulse;
  1074. break;
  1075. }
  1076. case HRTIM_OUTPUT_TA2:
  1077. case HRTIM_OUTPUT_TB2:
  1078. case HRTIM_OUTPUT_TC2:
  1079. case HRTIM_OUTPUT_TD2:
  1080. case HRTIM_OUTPUT_TE2:
  1081. {
  1082. CompareUnit = HRTIM_COMPAREUNIT_2;
  1083. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP2xR = pSimpleOCChannelCfg->Pulse;
  1084. break;
  1085. }
  1086. default:
  1087. {
  1088. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  1089. /* Process Unlocked */
  1090. __HAL_UNLOCK(hhrtim);
  1091. break;
  1092. }
  1093. }
  1094. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  1095. {
  1096. return HAL_ERROR;
  1097. }
  1098. /* Configure timer output */
  1099. OutputCfg.Polarity = (pSimpleOCChannelCfg->Polarity & HRTIM_OUTR_POL1);
  1100. OutputCfg.IdleLevel = (pSimpleOCChannelCfg->IdleLevel & HRTIM_OUTR_IDLES1);
  1101. OutputCfg.FaultLevel = HRTIM_OUTPUTFAULTLEVEL_NONE;
  1102. OutputCfg.IdleMode = HRTIM_OUTPUTIDLEMODE_NONE;
  1103. OutputCfg.ChopperModeEnable = HRTIM_OUTPUTCHOPPERMODE_DISABLED;
  1104. OutputCfg.BurstModeEntryDelayed = HRTIM_OUTPUTBURSTMODEENTRY_REGULAR;
  1105. switch (pSimpleOCChannelCfg->Mode)
  1106. {
  1107. case HRTIM_BASICOCMODE_TOGGLE:
  1108. {
  1109. if (CompareUnit == HRTIM_COMPAREUNIT_1)
  1110. {
  1111. OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP1;
  1112. }
  1113. else
  1114. {
  1115. OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP2;
  1116. }
  1117. OutputCfg.ResetSource = OutputCfg.SetSource;
  1118. break;
  1119. }
  1120. case HRTIM_BASICOCMODE_ACTIVE:
  1121. {
  1122. if (CompareUnit == HRTIM_COMPAREUNIT_1)
  1123. {
  1124. OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP1;
  1125. }
  1126. else
  1127. {
  1128. OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP2;
  1129. }
  1130. OutputCfg.ResetSource = HRTIM_OUTPUTRESET_NONE;
  1131. break;
  1132. }
  1133. case HRTIM_BASICOCMODE_INACTIVE:
  1134. {
  1135. if (CompareUnit == HRTIM_COMPAREUNIT_1)
  1136. {
  1137. OutputCfg.ResetSource = HRTIM_OUTPUTRESET_TIMCMP1;
  1138. }
  1139. else
  1140. {
  1141. OutputCfg.ResetSource = HRTIM_OUTPUTRESET_TIMCMP2;
  1142. }
  1143. OutputCfg.SetSource = HRTIM_OUTPUTSET_NONE;
  1144. break;
  1145. }
  1146. default:
  1147. {
  1148. OutputCfg.SetSource = HRTIM_OUTPUTSET_NONE;
  1149. OutputCfg.ResetSource = HRTIM_OUTPUTRESET_NONE;
  1150. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  1151. /* Process Unlocked */
  1152. __HAL_UNLOCK(hhrtim);
  1153. break;
  1154. }
  1155. }
  1156. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  1157. {
  1158. return HAL_ERROR;
  1159. }
  1160. HRTIM_OutputConfig(hhrtim,
  1161. TimerIdx,
  1162. OCChannel,
  1163. &OutputCfg);
  1164. /* Set HRTIM state */
  1165. hhrtim->State = HAL_HRTIM_STATE_READY;
  1166. return HAL_OK;
  1167. }
  1168. /**
  1169. * @brief Start the output compare signal generation on the designed timer output
  1170. * @param hhrtim pointer to HAL HRTIM handle
  1171. * @param TimerIdx Timer index
  1172. * This parameter can be one of the following values:
  1173. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  1174. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  1175. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  1176. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  1177. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  1178. * @param OCChannel Timer output
  1179. * This parameter can be one of the following values:
  1180. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  1181. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  1182. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  1183. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  1184. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  1185. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  1186. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  1187. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  1188. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  1189. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  1190. * @retval HAL status
  1191. */
  1192. HAL_StatusTypeDef HAL_HRTIM_SimpleOCStart(HRTIM_HandleTypeDef * hhrtim,
  1193. uint32_t TimerIdx,
  1194. uint32_t OCChannel)
  1195. {
  1196. /* Check the parameters */
  1197. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OCChannel));
  1198. /* Process Locked */
  1199. __HAL_LOCK(hhrtim);
  1200. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  1201. /* Enable the timer output */
  1202. hhrtim->Instance->sCommonRegs.OENR |= OCChannel;
  1203. /* Enable the timer counter */
  1204. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  1205. hhrtim->State = HAL_HRTIM_STATE_READY;
  1206. /* Process Unlocked */
  1207. __HAL_UNLOCK(hhrtim);
  1208. return HAL_OK;
  1209. }
  1210. /**
  1211. * @brief Stop the output compare signal generation on the designed timer output
  1212. * @param hhrtim pointer to HAL HRTIM handle
  1213. * @param TimerIdx Timer index
  1214. * This parameter can be one of the following values:
  1215. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  1216. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  1217. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  1218. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  1219. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  1220. * @param OCChannel Timer output
  1221. * This parameter can be one of the following values:
  1222. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  1223. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  1224. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  1225. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  1226. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  1227. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  1228. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  1229. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  1230. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  1231. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  1232. * @retval HAL status
  1233. */
  1234. HAL_StatusTypeDef HAL_HRTIM_SimpleOCStop(HRTIM_HandleTypeDef * hhrtim,
  1235. uint32_t TimerIdx,
  1236. uint32_t OCChannel)
  1237. {
  1238. /* Check the parameters */
  1239. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OCChannel));
  1240. /* Process Locked */
  1241. __HAL_LOCK(hhrtim);
  1242. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  1243. /* Disable the timer output */
  1244. hhrtim->Instance->sCommonRegs.ODISR |= OCChannel;
  1245. /* Disable the timer counter */
  1246. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  1247. hhrtim->State = HAL_HRTIM_STATE_READY;
  1248. /* Process Unlocked */
  1249. __HAL_UNLOCK(hhrtim);
  1250. return HAL_OK;
  1251. }
  1252. /**
  1253. * @brief Start the output compare signal generation on the designed timer output
  1254. * (Interrupt is enabled (see note note below)).
  1255. * @param hhrtim pointer to HAL HRTIM handle
  1256. * @param TimerIdx Timer index
  1257. * This parameter can be one of the following values:
  1258. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  1259. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  1260. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  1261. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  1262. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  1263. * @param OCChannel Timer output
  1264. * This parameter can be one of the following values:
  1265. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  1266. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  1267. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  1268. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  1269. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  1270. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  1271. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  1272. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  1273. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  1274. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  1275. * @note Interrupt enabling depends on the chosen output compare mode
  1276. * Output toggle: compare match interrupt is enabled
  1277. * Output set active: output set interrupt is enabled
  1278. * Output set inactive: output reset interrupt is enabled
  1279. * @retval HAL status
  1280. */
  1281. HAL_StatusTypeDef HAL_HRTIM_SimpleOCStart_IT(HRTIM_HandleTypeDef * hhrtim,
  1282. uint32_t TimerIdx,
  1283. uint32_t OCChannel)
  1284. {
  1285. uint32_t interrupt;
  1286. /* Check the parameters */
  1287. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OCChannel));
  1288. /* Process Locked */
  1289. __HAL_LOCK(hhrtim);
  1290. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  1291. /* Get the interrupt to enable (depends on the output compare mode) */
  1292. interrupt = HRTIM_GetITFromOCMode(hhrtim, TimerIdx, OCChannel);
  1293. /* Enable the timer output */
  1294. hhrtim->Instance->sCommonRegs.OENR |= OCChannel;
  1295. /* Enable the timer interrupt (depends on the output compare mode) */
  1296. __HAL_HRTIM_TIMER_ENABLE_IT(hhrtim, TimerIdx, interrupt);
  1297. /* Enable the timer counter */
  1298. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  1299. hhrtim->State = HAL_HRTIM_STATE_READY;
  1300. /* Process Unlocked */
  1301. __HAL_UNLOCK(hhrtim);
  1302. return HAL_OK;
  1303. }
  1304. /**
  1305. * @brief Stop the output compare signal generation on the designed timer output
  1306. * (Interrupt is disabled).
  1307. * @param hhrtim pointer to HAL HRTIM handle
  1308. * @param TimerIdx Timer index
  1309. * This parameter can be one of the following values:
  1310. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  1311. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  1312. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  1313. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  1314. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  1315. * @param OCChannel Timer output
  1316. * This parameter can be one of the following values:
  1317. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  1318. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  1319. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  1320. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  1321. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  1322. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  1323. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  1324. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  1325. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  1326. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  1327. * @retval HAL status
  1328. */
  1329. HAL_StatusTypeDef HAL_HRTIM_SimpleOCStop_IT(HRTIM_HandleTypeDef * hhrtim,
  1330. uint32_t TimerIdx,
  1331. uint32_t OCChannel)
  1332. {
  1333. uint32_t interrupt;
  1334. /* Check the parameters */
  1335. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OCChannel));
  1336. /* Process Locked */
  1337. __HAL_LOCK(hhrtim);
  1338. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  1339. /* Disable the timer output */
  1340. hhrtim->Instance->sCommonRegs.ODISR |= OCChannel;
  1341. /* Get the interrupt to disable (depends on the output compare mode) */
  1342. interrupt = HRTIM_GetITFromOCMode(hhrtim, TimerIdx, OCChannel);
  1343. /* Disable the timer interrupt */
  1344. __HAL_HRTIM_TIMER_DISABLE_IT(hhrtim, TimerIdx, interrupt);
  1345. /* Disable the timer counter */
  1346. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  1347. hhrtim->State = HAL_HRTIM_STATE_READY;
  1348. /* Process Unlocked */
  1349. __HAL_UNLOCK(hhrtim);
  1350. return HAL_OK;
  1351. }
  1352. /**
  1353. * @brief Start the output compare signal generation on the designed timer output
  1354. * (DMA request is enabled (see note below)).
  1355. * @param hhrtim pointer to HAL HRTIM handle
  1356. * @param TimerIdx Timer index
  1357. * This parameter can be one of the following values:
  1358. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  1359. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  1360. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  1361. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  1362. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  1363. * @param OCChannel Timer output
  1364. * This parameter can be one of the following values:
  1365. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  1366. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  1367. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  1368. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  1369. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  1370. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  1371. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  1372. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  1373. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  1374. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  1375. * @param SrcAddr DMA transfer source address
  1376. * @param DestAddr DMA transfer destination address
  1377. * @param Length The length of data items (data size) to be transferred
  1378. * from source to destination
  1379. * @note DMA request enabling depends on the chosen output compare mode
  1380. * Output toggle: compare match DMA request is enabled
  1381. * Output set active: output set DMA request is enabled
  1382. * Output set inactive: output reset DMA request is enabled
  1383. * @retval HAL status
  1384. */
  1385. HAL_StatusTypeDef HAL_HRTIM_SimpleOCStart_DMA(HRTIM_HandleTypeDef * hhrtim,
  1386. uint32_t TimerIdx,
  1387. uint32_t OCChannel,
  1388. uint32_t SrcAddr,
  1389. uint32_t DestAddr,
  1390. uint32_t Length)
  1391. {
  1392. DMA_HandleTypeDef * hdma;
  1393. uint32_t dma_request;
  1394. /* Check the parameters */
  1395. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OCChannel));
  1396. if((hhrtim->State == HAL_HRTIM_STATE_BUSY))
  1397. {
  1398. return HAL_BUSY;
  1399. }
  1400. if((hhrtim->State == HAL_HRTIM_STATE_READY))
  1401. {
  1402. if((SrcAddr == 0U ) || (DestAddr == 0U ) || (Length == 0U))
  1403. {
  1404. return HAL_ERROR;
  1405. }
  1406. else
  1407. {
  1408. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  1409. }
  1410. }
  1411. /* Process Locked */
  1412. __HAL_LOCK(hhrtim);
  1413. /* Enable the timer output */
  1414. hhrtim->Instance->sCommonRegs.OENR |= OCChannel;
  1415. /* Get the DMA request to enable */
  1416. dma_request = HRTIM_GetDMAFromOCMode(hhrtim, TimerIdx, OCChannel);
  1417. /* Get the timer DMA handler */
  1418. hdma = HRTIM_GetDMAHandleFromTimerIdx(hhrtim, TimerIdx);
  1419. if (hdma == NULL)
  1420. {
  1421. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  1422. /* Process Unlocked */
  1423. __HAL_UNLOCK(hhrtim);
  1424. return HAL_ERROR;
  1425. }
  1426. /* Set the DMA error callback */
  1427. hdma->XferErrorCallback = HRTIM_DMAError ;
  1428. /* Set the DMA transfer completed callback */
  1429. hdma->XferCpltCallback = HRTIM_DMATimerxCplt;
  1430. /* Enable the DMA channel */
  1431. if (HAL_DMA_Start_IT(hdma, SrcAddr, DestAddr, Length) != HAL_OK)
  1432. {
  1433. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  1434. /* Process Unlocked */
  1435. __HAL_UNLOCK(hhrtim);
  1436. return HAL_ERROR;
  1437. }
  1438. /* Enable the timer DMA request */
  1439. __HAL_HRTIM_TIMER_ENABLE_DMA(hhrtim, TimerIdx, dma_request);
  1440. /* Enable the timer counter */
  1441. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  1442. hhrtim->State = HAL_HRTIM_STATE_READY;
  1443. /* Process Unlocked */
  1444. __HAL_UNLOCK(hhrtim);
  1445. return HAL_OK;
  1446. }
  1447. /**
  1448. * @brief Stop the output compare signal generation on the designed timer output
  1449. * (DMA request is disabled).
  1450. * @param hhrtim pointer to HAL HRTIM handle
  1451. * @param TimerIdx Timer index
  1452. * This parameter can be one of the following values:
  1453. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  1454. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  1455. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  1456. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  1457. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  1458. * @param OCChannel Timer output
  1459. * This parameter can be one of the following values:
  1460. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  1461. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  1462. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  1463. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  1464. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  1465. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  1466. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  1467. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  1468. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  1469. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  1470. * @retval HAL status
  1471. */
  1472. HAL_StatusTypeDef HAL_HRTIM_SimpleOCStop_DMA(HRTIM_HandleTypeDef * hhrtim,
  1473. uint32_t TimerIdx,
  1474. uint32_t OCChannel)
  1475. {
  1476. uint32_t dma_request;
  1477. /* Check the parameters */
  1478. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OCChannel));
  1479. /* Process Locked */
  1480. __HAL_LOCK(hhrtim);
  1481. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  1482. /* Disable the timer output */
  1483. hhrtim->Instance->sCommonRegs.ODISR |= OCChannel;
  1484. /* Get the timer DMA handler */
  1485. /* Disable the DMA */
  1486. if (HAL_DMA_Abort(HRTIM_GetDMAHandleFromTimerIdx(hhrtim, TimerIdx)) != HAL_OK)
  1487. {
  1488. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  1489. /* Process Unlocked */
  1490. __HAL_UNLOCK(hhrtim);
  1491. return HAL_ERROR;
  1492. }
  1493. /* Get the DMA request to disable */
  1494. dma_request = HRTIM_GetDMAFromOCMode(hhrtim, TimerIdx, OCChannel);
  1495. /* Disable the timer DMA request */
  1496. __HAL_HRTIM_TIMER_DISABLE_DMA(hhrtim, TimerIdx, dma_request);
  1497. /* Disable the timer counter */
  1498. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  1499. hhrtim->State = HAL_HRTIM_STATE_READY;
  1500. /* Process Unlocked */
  1501. __HAL_UNLOCK(hhrtim);
  1502. return HAL_OK;
  1503. }
  1504. /**
  1505. * @}
  1506. */
  1507. /** @defgroup HRTIM_Exported_Functions_Group4 Simple PWM output mode functions
  1508. * @brief Simple PWM output functions
  1509. @verbatim
  1510. ===============================================================================
  1511. ##### Simple PWM output functions #####
  1512. ===============================================================================
  1513. [..] This section provides functions allowing to:
  1514. (+) Configure simple PWM output channel
  1515. (+) Start simple PWM output
  1516. (+) Stop simple PWM output
  1517. (+) Start simple PWM output and enable interrupt
  1518. (+) Stop simple PWM output and disable interrupt
  1519. (+) Start simple PWM output and enable DMA transfer
  1520. (+) Stop simple PWM output and disable DMA transfer
  1521. -@- When a HRTIM timer operates in simple PWM output mode
  1522. the output level is set to a programmable value when a match is
  1523. found between the compare register and the counter and reset when
  1524. the timer period is reached. Duty cycle is determined by the
  1525. comparison value.
  1526. Compare unit 1 is automatically associated to output 1
  1527. Compare unit 2 is automatically associated to output 2
  1528. @endverbatim
  1529. * @{
  1530. */
  1531. /**
  1532. * @brief Configure an output in simple PWM mode
  1533. * @param hhrtim pointer to HAL HRTIM handle
  1534. * @param TimerIdx Timer index
  1535. * This parameter can be one of the following values:
  1536. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  1537. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  1538. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  1539. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  1540. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  1541. * @param PWMChannel Timer output
  1542. * This parameter can be one of the following values:
  1543. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  1544. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  1545. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  1546. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  1547. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  1548. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  1549. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  1550. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  1551. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  1552. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  1553. * @param pSimplePWMChannelCfg pointer to the simple PWM output configuration structure
  1554. * @note When the timer operates in simple PWM output mode:
  1555. * Output 1 is implicitly controlled by the compare unit 1
  1556. * Output 2 is implicitly controlled by the compare unit 2
  1557. * Output Set/Reset crossbar is set as follows:
  1558. * Output 1: SETx1R = CMP1, RSTx1R = PER
  1559. * Output 2: SETx2R = CMP2, RST2R = PER
  1560. * @note When Simple PWM mode is used the registers preload mechanism is
  1561. * enabled (otherwise the behavior is not guaranteed).
  1562. * @retval HAL status
  1563. */
  1564. HAL_StatusTypeDef HAL_HRTIM_SimplePWMChannelConfig(HRTIM_HandleTypeDef * hhrtim,
  1565. uint32_t TimerIdx,
  1566. uint32_t PWMChannel,
  1567. HRTIM_SimplePWMChannelCfgTypeDef* pSimplePWMChannelCfg)
  1568. {
  1569. HRTIM_OutputCfgTypeDef OutputCfg;
  1570. uint32_t hrtim_timcr;
  1571. /* Check parameters */
  1572. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, PWMChannel));
  1573. assert_param(IS_HRTIM_OUTPUTPOLARITY(pSimplePWMChannelCfg->Polarity));
  1574. assert_param(IS_HRTIM_OUTPUTPULSE(pSimplePWMChannelCfg->Pulse));
  1575. assert_param(IS_HRTIM_OUTPUTIDLELEVEL(pSimplePWMChannelCfg->IdleLevel));
  1576. if(hhrtim->State == HAL_HRTIM_STATE_BUSY)
  1577. {
  1578. return HAL_BUSY;
  1579. }
  1580. /* Process Locked */
  1581. __HAL_LOCK(hhrtim);
  1582. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  1583. /* Configure timer compare unit */
  1584. switch (PWMChannel)
  1585. {
  1586. case HRTIM_OUTPUT_TA1:
  1587. case HRTIM_OUTPUT_TB1:
  1588. case HRTIM_OUTPUT_TC1:
  1589. case HRTIM_OUTPUT_TD1:
  1590. case HRTIM_OUTPUT_TE1:
  1591. {
  1592. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP1xR = pSimplePWMChannelCfg->Pulse;
  1593. OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP1;
  1594. break;
  1595. }
  1596. case HRTIM_OUTPUT_TA2:
  1597. case HRTIM_OUTPUT_TB2:
  1598. case HRTIM_OUTPUT_TC2:
  1599. case HRTIM_OUTPUT_TD2:
  1600. case HRTIM_OUTPUT_TE2:
  1601. {
  1602. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP2xR = pSimplePWMChannelCfg->Pulse;
  1603. OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP2;
  1604. break;
  1605. }
  1606. default:
  1607. {
  1608. OutputCfg.SetSource = HRTIM_OUTPUTSET_NONE;
  1609. OutputCfg.ResetSource = HRTIM_OUTPUTRESET_NONE;
  1610. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  1611. /* Process Unlocked */
  1612. __HAL_UNLOCK(hhrtim);
  1613. break;
  1614. }
  1615. }
  1616. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  1617. {
  1618. return HAL_ERROR;
  1619. }
  1620. /* Configure timer output */
  1621. OutputCfg.Polarity = (pSimplePWMChannelCfg->Polarity & HRTIM_OUTR_POL1);
  1622. OutputCfg.IdleLevel = (pSimplePWMChannelCfg->IdleLevel& HRTIM_OUTR_IDLES1);
  1623. OutputCfg.FaultLevel = HRTIM_OUTPUTFAULTLEVEL_NONE;
  1624. OutputCfg.IdleMode = HRTIM_OUTPUTIDLEMODE_NONE;
  1625. OutputCfg.ChopperModeEnable = HRTIM_OUTPUTCHOPPERMODE_DISABLED;
  1626. OutputCfg.BurstModeEntryDelayed = HRTIM_OUTPUTBURSTMODEENTRY_REGULAR;
  1627. OutputCfg.ResetSource = HRTIM_OUTPUTRESET_TIMPER;
  1628. HRTIM_OutputConfig(hhrtim,
  1629. TimerIdx,
  1630. PWMChannel,
  1631. &OutputCfg);
  1632. /* Enable the registers preload mechanism */
  1633. hrtim_timcr = hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR;
  1634. hrtim_timcr |= HRTIM_TIMCR_PREEN;
  1635. hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR = hrtim_timcr;
  1636. hhrtim->State = HAL_HRTIM_STATE_READY;
  1637. /* Process Unlocked */
  1638. __HAL_UNLOCK(hhrtim);
  1639. return HAL_OK;
  1640. }
  1641. /**
  1642. * @brief Start the PWM output signal generation on the designed timer output
  1643. * @param hhrtim pointer to HAL HRTIM handle
  1644. * @param TimerIdx Timer index
  1645. * This parameter can be one of the following values:
  1646. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  1647. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  1648. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  1649. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  1650. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  1651. * @param PWMChannel Timer output
  1652. * This parameter can be one of the following values:
  1653. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  1654. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  1655. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  1656. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  1657. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  1658. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  1659. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  1660. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  1661. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  1662. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  1663. * @retval HAL status
  1664. */
  1665. HAL_StatusTypeDef HAL_HRTIM_SimplePWMStart(HRTIM_HandleTypeDef * hhrtim,
  1666. uint32_t TimerIdx,
  1667. uint32_t PWMChannel)
  1668. {
  1669. /* Check the parameters */
  1670. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, PWMChannel));
  1671. /* Process Locked */
  1672. __HAL_LOCK(hhrtim);
  1673. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  1674. /* Enable the timer output */
  1675. hhrtim->Instance->sCommonRegs.OENR |= PWMChannel;
  1676. /* Enable the timer counter */
  1677. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  1678. hhrtim->State = HAL_HRTIM_STATE_READY;
  1679. /* Process Unlocked */
  1680. __HAL_UNLOCK(hhrtim);
  1681. return HAL_OK;
  1682. }
  1683. /**
  1684. * @brief Stop the PWM output signal generation on the designed timer output
  1685. * @param hhrtim pointer to HAL HRTIM handle
  1686. * @param TimerIdx Timer index
  1687. * This parameter can be one of the following values:
  1688. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  1689. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  1690. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  1691. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  1692. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  1693. * @param PWMChannel Timer output
  1694. * This parameter can be one of the following values:
  1695. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  1696. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  1697. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  1698. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  1699. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  1700. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  1701. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  1702. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  1703. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  1704. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  1705. * @retval HAL status
  1706. */
  1707. HAL_StatusTypeDef HAL_HRTIM_SimplePWMStop(HRTIM_HandleTypeDef * hhrtim,
  1708. uint32_t TimerIdx,
  1709. uint32_t PWMChannel)
  1710. {
  1711. /* Check the parameters */
  1712. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, PWMChannel));
  1713. /* Process Locked */
  1714. __HAL_LOCK(hhrtim);
  1715. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  1716. /* Disable the timer output */
  1717. hhrtim->Instance->sCommonRegs.ODISR |= PWMChannel;
  1718. /* Disable the timer counter */
  1719. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  1720. hhrtim->State = HAL_HRTIM_STATE_READY;
  1721. /* Process Unlocked */
  1722. __HAL_UNLOCK(hhrtim);
  1723. return HAL_OK;
  1724. }
  1725. /**
  1726. * @brief Start the PWM output signal generation on the designed timer output
  1727. * (The compare interrupt is enabled).
  1728. * @param hhrtim pointer to HAL HRTIM handle
  1729. * @param TimerIdx Timer index
  1730. * This parameter can be one of the following values:
  1731. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  1732. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  1733. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  1734. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  1735. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  1736. * @param PWMChannel Timer output
  1737. * This parameter can be one of the following values:
  1738. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  1739. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  1740. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  1741. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  1742. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  1743. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  1744. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  1745. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  1746. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  1747. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  1748. * @retval HAL status
  1749. */
  1750. HAL_StatusTypeDef HAL_HRTIM_SimplePWMStart_IT(HRTIM_HandleTypeDef * hhrtim,
  1751. uint32_t TimerIdx,
  1752. uint32_t PWMChannel)
  1753. {
  1754. /* Check the parameters */
  1755. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, PWMChannel));
  1756. /* Process Locked */
  1757. __HAL_LOCK(hhrtim);
  1758. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  1759. /* Enable the timer output */
  1760. hhrtim->Instance->sCommonRegs.OENR |= PWMChannel;
  1761. /* Enable the timer interrupt (depends on the PWM output) */
  1762. switch (PWMChannel)
  1763. {
  1764. case HRTIM_OUTPUT_TA1:
  1765. case HRTIM_OUTPUT_TB1:
  1766. case HRTIM_OUTPUT_TC1:
  1767. case HRTIM_OUTPUT_TD1:
  1768. case HRTIM_OUTPUT_TE1:
  1769. {
  1770. __HAL_HRTIM_TIMER_ENABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP1);
  1771. break;
  1772. }
  1773. case HRTIM_OUTPUT_TA2:
  1774. case HRTIM_OUTPUT_TB2:
  1775. case HRTIM_OUTPUT_TC2:
  1776. case HRTIM_OUTPUT_TD2:
  1777. case HRTIM_OUTPUT_TE2:
  1778. {
  1779. __HAL_HRTIM_TIMER_ENABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP2);
  1780. break;
  1781. }
  1782. default:
  1783. {
  1784. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  1785. /* Process Unlocked */
  1786. __HAL_UNLOCK(hhrtim);
  1787. break;
  1788. }
  1789. }
  1790. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  1791. {
  1792. return HAL_ERROR;
  1793. }
  1794. /* Enable the timer counter */
  1795. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  1796. hhrtim->State = HAL_HRTIM_STATE_READY;
  1797. /* Process Unlocked */
  1798. __HAL_UNLOCK(hhrtim);
  1799. return HAL_OK;
  1800. }
  1801. /**
  1802. * @brief Stop the PWM output signal generation on the designed timer output
  1803. * (The compare interrupt is disabled).
  1804. * @param hhrtim pointer to HAL HRTIM handle
  1805. * @param TimerIdx Timer index
  1806. * This parameter can be one of the following values:
  1807. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  1808. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  1809. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  1810. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  1811. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  1812. * @param PWMChannel Timer output
  1813. * This parameter can be one of the following values:
  1814. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  1815. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  1816. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  1817. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  1818. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  1819. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  1820. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  1821. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  1822. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  1823. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  1824. * @retval HAL status
  1825. */
  1826. HAL_StatusTypeDef HAL_HRTIM_SimplePWMStop_IT(HRTIM_HandleTypeDef * hhrtim,
  1827. uint32_t TimerIdx,
  1828. uint32_t PWMChannel)
  1829. {
  1830. /* Check the parameters */
  1831. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, PWMChannel));
  1832. /* Process Locked */
  1833. __HAL_LOCK(hhrtim);
  1834. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  1835. /* Disable the timer output */
  1836. hhrtim->Instance->sCommonRegs.ODISR |= PWMChannel;
  1837. /* Disable the timer interrupt (depends on the PWM output) */
  1838. switch (PWMChannel)
  1839. {
  1840. case HRTIM_OUTPUT_TA1:
  1841. case HRTIM_OUTPUT_TB1:
  1842. case HRTIM_OUTPUT_TC1:
  1843. case HRTIM_OUTPUT_TD1:
  1844. case HRTIM_OUTPUT_TE1:
  1845. {
  1846. __HAL_HRTIM_TIMER_DISABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP1);
  1847. break;
  1848. }
  1849. case HRTIM_OUTPUT_TA2:
  1850. case HRTIM_OUTPUT_TB2:
  1851. case HRTIM_OUTPUT_TC2:
  1852. case HRTIM_OUTPUT_TD2:
  1853. case HRTIM_OUTPUT_TE2:
  1854. {
  1855. __HAL_HRTIM_TIMER_DISABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP2);
  1856. break;
  1857. }
  1858. default:
  1859. {
  1860. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  1861. /* Process Unlocked */
  1862. __HAL_UNLOCK(hhrtim);
  1863. break;
  1864. }
  1865. }
  1866. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  1867. {
  1868. return HAL_ERROR;
  1869. }
  1870. /* Disable the timer counter */
  1871. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  1872. hhrtim->State = HAL_HRTIM_STATE_READY;
  1873. /* Process Unlocked */
  1874. __HAL_UNLOCK(hhrtim);
  1875. return HAL_OK;
  1876. }
  1877. /**
  1878. * @brief Start the PWM output signal generation on the designed timer output
  1879. * (The compare DMA request is enabled).
  1880. * @param hhrtim pointer to HAL HRTIM handle
  1881. * @param TimerIdx Timer index
  1882. * This parameter can be one of the following values:
  1883. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  1884. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  1885. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  1886. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  1887. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  1888. * @param PWMChannel Timer output
  1889. * This parameter can be one of the following values:
  1890. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  1891. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  1892. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  1893. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  1894. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  1895. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  1896. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  1897. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  1898. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  1899. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  1900. * @param SrcAddr DMA transfer source address
  1901. * @param DestAddr DMA transfer destination address
  1902. * @param Length The length of data items (data size) to be transferred
  1903. * from source to destination
  1904. * @retval HAL status
  1905. */
  1906. HAL_StatusTypeDef HAL_HRTIM_SimplePWMStart_DMA(HRTIM_HandleTypeDef * hhrtim,
  1907. uint32_t TimerIdx,
  1908. uint32_t PWMChannel,
  1909. uint32_t SrcAddr,
  1910. uint32_t DestAddr,
  1911. uint32_t Length)
  1912. {
  1913. DMA_HandleTypeDef * hdma;
  1914. /* Check the parameters */
  1915. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, PWMChannel));
  1916. if((hhrtim->State == HAL_HRTIM_STATE_BUSY))
  1917. {
  1918. return HAL_BUSY;
  1919. }
  1920. if((hhrtim->State == HAL_HRTIM_STATE_READY))
  1921. {
  1922. if((SrcAddr == 0U ) || (DestAddr == 0U ) || (Length == 0U))
  1923. {
  1924. return HAL_ERROR;
  1925. }
  1926. else
  1927. {
  1928. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  1929. }
  1930. }
  1931. /* Process Locked */
  1932. __HAL_LOCK(hhrtim);
  1933. /* Enable the timer output */
  1934. hhrtim->Instance->sCommonRegs.OENR |= PWMChannel;
  1935. /* Get the timer DMA handler */
  1936. hdma = HRTIM_GetDMAHandleFromTimerIdx(hhrtim, TimerIdx);
  1937. if (hdma == NULL)
  1938. {
  1939. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  1940. /* Process Unlocked */
  1941. __HAL_UNLOCK(hhrtim);
  1942. return HAL_ERROR;
  1943. }
  1944. /* Set the DMA error callback */
  1945. hdma->XferErrorCallback = HRTIM_DMAError ;
  1946. /* Set the DMA transfer completed callback */
  1947. hdma->XferCpltCallback = HRTIM_DMATimerxCplt;
  1948. /* Enable the DMA channel */
  1949. if (HAL_DMA_Start_IT(hdma, SrcAddr, DestAddr, Length) != HAL_OK)
  1950. {
  1951. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  1952. /* Process Unlocked */
  1953. __HAL_UNLOCK(hhrtim);
  1954. return HAL_ERROR;
  1955. }
  1956. /* Enable the timer DMA request */
  1957. switch (PWMChannel)
  1958. {
  1959. case HRTIM_OUTPUT_TA1:
  1960. case HRTIM_OUTPUT_TB1:
  1961. case HRTIM_OUTPUT_TC1:
  1962. case HRTIM_OUTPUT_TD1:
  1963. case HRTIM_OUTPUT_TE1:
  1964. {
  1965. __HAL_HRTIM_TIMER_ENABLE_DMA(hhrtim, TimerIdx, HRTIM_TIM_DMA_CMP1);
  1966. break;
  1967. }
  1968. case HRTIM_OUTPUT_TA2:
  1969. case HRTIM_OUTPUT_TB2:
  1970. case HRTIM_OUTPUT_TC2:
  1971. case HRTIM_OUTPUT_TD2:
  1972. case HRTIM_OUTPUT_TE2:
  1973. {
  1974. __HAL_HRTIM_TIMER_ENABLE_DMA(hhrtim, TimerIdx, HRTIM_TIM_DMA_CMP2);
  1975. break;
  1976. }
  1977. default:
  1978. {
  1979. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  1980. /* Process Unlocked */
  1981. __HAL_UNLOCK(hhrtim);
  1982. break;
  1983. }
  1984. }
  1985. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  1986. {
  1987. return HAL_ERROR;
  1988. }
  1989. /* Enable the timer counter */
  1990. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  1991. hhrtim->State = HAL_HRTIM_STATE_READY;
  1992. /* Process Unlocked */
  1993. __HAL_UNLOCK(hhrtim);
  1994. return HAL_OK;
  1995. }
  1996. /**
  1997. * @brief Stop the PWM output signal generation on the designed timer output
  1998. * (The compare DMA request is disabled).
  1999. * @param hhrtim pointer to HAL HRTIM handle
  2000. * @param TimerIdx Timer index
  2001. * This parameter can be one of the following values:
  2002. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  2003. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  2004. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  2005. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  2006. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  2007. * @param PWMChannel Timer output
  2008. * This parameter can be one of the following values:
  2009. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  2010. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  2011. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  2012. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  2013. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  2014. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  2015. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  2016. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  2017. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  2018. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  2019. * @retval HAL status
  2020. */
  2021. HAL_StatusTypeDef HAL_HRTIM_SimplePWMStop_DMA(HRTIM_HandleTypeDef * hhrtim,
  2022. uint32_t TimerIdx,
  2023. uint32_t PWMChannel)
  2024. {
  2025. /* Check the parameters */
  2026. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, PWMChannel));
  2027. /* Process Locked */
  2028. __HAL_LOCK(hhrtim);
  2029. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  2030. /* Disable the timer output */
  2031. hhrtim->Instance->sCommonRegs.ODISR |= PWMChannel;
  2032. /* Get the timer DMA handler */
  2033. /* Disable the DMA */
  2034. if (HAL_DMA_Abort(HRTIM_GetDMAHandleFromTimerIdx(hhrtim, TimerIdx)) != HAL_OK)
  2035. {
  2036. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2037. /* Process Unlocked */
  2038. __HAL_UNLOCK(hhrtim);
  2039. return HAL_ERROR;
  2040. }
  2041. /* Disable the timer DMA request */
  2042. switch (PWMChannel)
  2043. {
  2044. case HRTIM_OUTPUT_TA1:
  2045. case HRTIM_OUTPUT_TB1:
  2046. case HRTIM_OUTPUT_TC1:
  2047. case HRTIM_OUTPUT_TD1:
  2048. case HRTIM_OUTPUT_TE1:
  2049. {
  2050. __HAL_HRTIM_TIMER_DISABLE_DMA(hhrtim, TimerIdx, HRTIM_TIM_DMA_CMP1);
  2051. break;
  2052. }
  2053. case HRTIM_OUTPUT_TA2:
  2054. case HRTIM_OUTPUT_TB2:
  2055. case HRTIM_OUTPUT_TC2:
  2056. case HRTIM_OUTPUT_TD2:
  2057. case HRTIM_OUTPUT_TE2:
  2058. {
  2059. __HAL_HRTIM_TIMER_DISABLE_DMA(hhrtim, TimerIdx, HRTIM_TIM_DMA_CMP2);
  2060. break;
  2061. }
  2062. default:
  2063. {
  2064. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2065. /* Process Unlocked */
  2066. __HAL_UNLOCK(hhrtim);
  2067. break;
  2068. }
  2069. }
  2070. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  2071. {
  2072. return HAL_ERROR;
  2073. }
  2074. /* Disable the timer counter */
  2075. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  2076. hhrtim->State = HAL_HRTIM_STATE_READY;
  2077. /* Process Unlocked */
  2078. __HAL_UNLOCK(hhrtim);
  2079. return HAL_OK;
  2080. }
  2081. /**
  2082. * @}
  2083. */
  2084. /** @defgroup HRTIM_Exported_Functions_Group5 Simple input capture functions
  2085. * @brief Simple input capture functions
  2086. @verbatim
  2087. ===============================================================================
  2088. ##### Simple input capture functions #####
  2089. ===============================================================================
  2090. [..] This section provides functions allowing to:
  2091. (+) Configure simple input capture channel
  2092. (+) Start simple input capture
  2093. (+) Stop simple input capture
  2094. (+) Start simple input capture and enable interrupt
  2095. (+) Stop simple input capture and disable interrupt
  2096. (+) Start simple input capture and enable DMA transfer
  2097. (+) Stop simple input capture and disable DMA transfer
  2098. -@- When a HRTIM timer operates in simple input capture mode
  2099. the Capture Register (HRTIM_CPT1/2xR) is used to latch the
  2100. value of the timer counter counter after a transition detected
  2101. on a given external event input.
  2102. @endverbatim
  2103. * @{
  2104. */
  2105. /**
  2106. * @brief Configure a simple capture
  2107. * @param hhrtim pointer to HAL HRTIM handle
  2108. * @param TimerIdx Timer index
  2109. * This parameter can be one of the following values:
  2110. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  2111. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  2112. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  2113. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  2114. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  2115. * @param CaptureChannel Capture unit
  2116. * This parameter can be one of the following values:
  2117. * @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  2118. * @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  2119. * @param pSimpleCaptureChannelCfg pointer to the simple capture configuration structure
  2120. * @note When the timer operates in simple capture mode the capture is trigerred
  2121. * by the designated external event and GPIO input is implicitly used as event source.
  2122. * The cature can be triggered by a rising edge, a falling edge or both
  2123. * edges on event channel.
  2124. * @retval HAL status
  2125. */
  2126. HAL_StatusTypeDef HAL_HRTIM_SimpleCaptureChannelConfig(HRTIM_HandleTypeDef * hhrtim,
  2127. uint32_t TimerIdx,
  2128. uint32_t CaptureChannel,
  2129. HRTIM_SimpleCaptureChannelCfgTypeDef* pSimpleCaptureChannelCfg)
  2130. {
  2131. HRTIM_EventCfgTypeDef EventCfg;
  2132. /* Check parameters */
  2133. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  2134. assert_param(IS_HRTIM_CAPTUREUNIT(CaptureChannel));
  2135. assert_param(IS_HRTIM_EVENT(pSimpleCaptureChannelCfg->Event));
  2136. assert_param(IS_HRTIM_EVENTPOLARITY(pSimpleCaptureChannelCfg->EventSensitivity,
  2137. pSimpleCaptureChannelCfg->EventPolarity));
  2138. assert_param(IS_HRTIM_EVENTSENSITIVITY(pSimpleCaptureChannelCfg->EventSensitivity));
  2139. assert_param(IS_HRTIM_EVENTFILTER(pSimpleCaptureChannelCfg->Event,
  2140. pSimpleCaptureChannelCfg->EventFilter));
  2141. if(hhrtim->State == HAL_HRTIM_STATE_BUSY)
  2142. {
  2143. return HAL_BUSY;
  2144. }
  2145. /* Process Locked */
  2146. __HAL_LOCK(hhrtim);
  2147. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  2148. /* Configure external event channel */
  2149. EventCfg.FastMode = HRTIM_EVENTFASTMODE_DISABLE;
  2150. EventCfg.Filter = (pSimpleCaptureChannelCfg->EventFilter & HRTIM_EECR3_EE6F);
  2151. EventCfg.Polarity = (pSimpleCaptureChannelCfg->EventPolarity & HRTIM_EECR1_EE1POL);
  2152. EventCfg.Sensitivity = (pSimpleCaptureChannelCfg->EventSensitivity & HRTIM_EECR1_EE1SNS);
  2153. EventCfg.Source = HRTIM_EVENTSRC_1;
  2154. HRTIM_EventConfig(hhrtim,
  2155. pSimpleCaptureChannelCfg->Event,
  2156. &EventCfg);
  2157. /* Memorize capture trigger (will be configured when the capture is started */
  2158. HRTIM_CaptureUnitConfig(hhrtim,
  2159. TimerIdx,
  2160. CaptureChannel,
  2161. pSimpleCaptureChannelCfg->Event);
  2162. hhrtim->State = HAL_HRTIM_STATE_READY;
  2163. /* Process Unlocked */
  2164. __HAL_UNLOCK(hhrtim);
  2165. return HAL_OK;
  2166. }
  2167. /**
  2168. * @brief Enable a simple capture on the designed capture unit
  2169. * @param hhrtim pointer to HAL HRTIM handle
  2170. * @param TimerIdx Timer index
  2171. * This parameter can be one of the following values:
  2172. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  2173. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  2174. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  2175. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  2176. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  2177. * @param CaptureChannel Timer output
  2178. * This parameter can be one of the following values:
  2179. * @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  2180. * @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  2181. * @retval HAL status
  2182. * @note The external event triggering the capture is available for all timing
  2183. * units. It can be used directly and is active as soon as the timing
  2184. * unit counter is enabled.
  2185. */
  2186. HAL_StatusTypeDef HAL_HRTIM_SimpleCaptureStart(HRTIM_HandleTypeDef * hhrtim,
  2187. uint32_t TimerIdx,
  2188. uint32_t CaptureChannel)
  2189. {
  2190. /* Check the parameters */
  2191. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  2192. assert_param(IS_HRTIM_CAPTUREUNIT(CaptureChannel));
  2193. /* Process Locked */
  2194. __HAL_LOCK(hhrtim);
  2195. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  2196. /* Set the capture unit trigger */
  2197. switch (CaptureChannel)
  2198. {
  2199. case HRTIM_CAPTUREUNIT_1:
  2200. {
  2201. hhrtim->Instance->sTimerxRegs[TimerIdx].CPT1xCR = hhrtim->TimerParam[TimerIdx].CaptureTrigger1;
  2202. break;
  2203. }
  2204. case HRTIM_CAPTUREUNIT_2:
  2205. {
  2206. hhrtim->Instance->sTimerxRegs[TimerIdx].CPT2xCR = hhrtim->TimerParam[TimerIdx].CaptureTrigger2;
  2207. break;
  2208. }
  2209. default:
  2210. {
  2211. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2212. /* Process Unlocked */
  2213. __HAL_UNLOCK(hhrtim);
  2214. break;
  2215. }
  2216. }
  2217. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  2218. {
  2219. return HAL_ERROR;
  2220. }
  2221. /* Enable the timer counter */
  2222. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  2223. hhrtim->State = HAL_HRTIM_STATE_READY;
  2224. /* Process Unlocked */
  2225. __HAL_UNLOCK(hhrtim);
  2226. return HAL_OK;
  2227. }
  2228. /**
  2229. * @brief Disable a simple capture on the designed capture unit
  2230. * @param hhrtim pointer to HAL HRTIM handle
  2231. * @param TimerIdx Timer index
  2232. * This parameter can be one of the following values:
  2233. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  2234. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  2235. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  2236. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  2237. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  2238. * @param CaptureChannel Timer output
  2239. * This parameter can be one of the following values:
  2240. * @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  2241. * @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  2242. * @retval HAL status
  2243. */
  2244. HAL_StatusTypeDef HAL_HRTIM_SimpleCaptureStop(HRTIM_HandleTypeDef * hhrtim,
  2245. uint32_t TimerIdx,
  2246. uint32_t CaptureChannel)
  2247. {
  2248. uint32_t hrtim_cpt1cr;
  2249. uint32_t hrtim_cpt2cr;
  2250. /* Check the parameters */
  2251. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  2252. assert_param(IS_HRTIM_CAPTUREUNIT(CaptureChannel));
  2253. /* Process Locked */
  2254. __HAL_LOCK(hhrtim);
  2255. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  2256. /* Set the capture unit trigger */
  2257. switch (CaptureChannel)
  2258. {
  2259. case HRTIM_CAPTUREUNIT_1:
  2260. {
  2261. hhrtim->Instance->sTimerxRegs[TimerIdx].CPT1xCR = HRTIM_CAPTURETRIGGER_NONE;
  2262. break;
  2263. }
  2264. case HRTIM_CAPTUREUNIT_2:
  2265. {
  2266. hhrtim->Instance->sTimerxRegs[TimerIdx].CPT2xCR = HRTIM_CAPTURETRIGGER_NONE;
  2267. break;
  2268. }
  2269. default:
  2270. {
  2271. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2272. /* Process Unlocked */
  2273. __HAL_UNLOCK(hhrtim);
  2274. break;
  2275. }
  2276. }
  2277. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  2278. {
  2279. return HAL_ERROR;
  2280. }
  2281. hrtim_cpt1cr = hhrtim->Instance->sTimerxRegs[TimerIdx].CPT1xCR;
  2282. hrtim_cpt2cr = hhrtim->Instance->sTimerxRegs[TimerIdx].CPT2xCR;
  2283. /* Disable the timer counter */
  2284. if ((hrtim_cpt1cr == HRTIM_CAPTURETRIGGER_NONE) &&
  2285. (hrtim_cpt2cr == HRTIM_CAPTURETRIGGER_NONE))
  2286. {
  2287. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  2288. }
  2289. hhrtim->State = HAL_HRTIM_STATE_READY;
  2290. /* Process Unlocked */
  2291. __HAL_UNLOCK(hhrtim);
  2292. return HAL_OK;
  2293. }
  2294. /**
  2295. * @brief Enable a simple capture on the designed capture unit
  2296. * (Capture interrupt is enabled).
  2297. * @param hhrtim pointer to HAL HRTIM handle
  2298. * @param TimerIdx Timer index
  2299. * This parameter can be one of the following values:
  2300. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  2301. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  2302. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  2303. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  2304. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  2305. * @param CaptureChannel Timer output
  2306. * This parameter can be one of the following values:
  2307. * @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  2308. * @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  2309. * @retval HAL status
  2310. */
  2311. HAL_StatusTypeDef HAL_HRTIM_SimpleCaptureStart_IT(HRTIM_HandleTypeDef * hhrtim,
  2312. uint32_t TimerIdx,
  2313. uint32_t CaptureChannel)
  2314. {
  2315. /* Check the parameters */
  2316. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  2317. assert_param(IS_HRTIM_CAPTUREUNIT(CaptureChannel));
  2318. /* Process Locked */
  2319. __HAL_LOCK(hhrtim);
  2320. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  2321. /* Set the capture unit trigger */
  2322. switch (CaptureChannel)
  2323. {
  2324. case HRTIM_CAPTUREUNIT_1:
  2325. {
  2326. hhrtim->Instance->sTimerxRegs[TimerIdx].CPT1xCR = hhrtim->TimerParam[TimerIdx].CaptureTrigger1;
  2327. /* Enable the capture unit 1 interrupt */
  2328. __HAL_HRTIM_TIMER_ENABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CPT1);
  2329. break;
  2330. }
  2331. case HRTIM_CAPTUREUNIT_2:
  2332. {
  2333. hhrtim->Instance->sTimerxRegs[TimerIdx].CPT2xCR = hhrtim->TimerParam[TimerIdx].CaptureTrigger2;
  2334. /* Enable the capture unit 2 interrupt */
  2335. __HAL_HRTIM_TIMER_ENABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CPT2);
  2336. break;
  2337. }
  2338. default:
  2339. {
  2340. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2341. /* Process Unlocked */
  2342. __HAL_UNLOCK(hhrtim);
  2343. break;
  2344. }
  2345. }
  2346. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  2347. {
  2348. return HAL_ERROR;
  2349. }
  2350. /* Enable the timer counter */
  2351. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  2352. hhrtim->State = HAL_HRTIM_STATE_READY;
  2353. /* Process Unlocked */
  2354. __HAL_UNLOCK(hhrtim);
  2355. return HAL_OK;
  2356. }
  2357. /**
  2358. * @brief Disable a simple capture on the designed capture unit
  2359. * (Capture interrupt is disabled).
  2360. * @param hhrtim pointer to HAL HRTIM handle
  2361. * @param TimerIdx Timer index
  2362. * This parameter can be one of the following values:
  2363. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  2364. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  2365. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  2366. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  2367. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  2368. * @param CaptureChannel Timer output
  2369. * This parameter can be one of the following values:
  2370. * @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  2371. * @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  2372. * @retval HAL status
  2373. */
  2374. HAL_StatusTypeDef HAL_HRTIM_SimpleCaptureStop_IT(HRTIM_HandleTypeDef * hhrtim,
  2375. uint32_t TimerIdx,
  2376. uint32_t CaptureChannel)
  2377. {
  2378. uint32_t hrtim_cpt1cr;
  2379. uint32_t hrtim_cpt2cr;
  2380. /* Check the parameters */
  2381. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  2382. assert_param(IS_HRTIM_CAPTUREUNIT(CaptureChannel));
  2383. /* Process Locked */
  2384. __HAL_LOCK(hhrtim);
  2385. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  2386. /* Set the capture unit trigger */
  2387. switch (CaptureChannel)
  2388. {
  2389. case HRTIM_CAPTUREUNIT_1:
  2390. {
  2391. hhrtim->Instance->sTimerxRegs[TimerIdx].CPT1xCR = HRTIM_CAPTURETRIGGER_NONE;
  2392. /* Disable the capture unit 1 interrupt */
  2393. __HAL_HRTIM_TIMER_DISABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CPT1);
  2394. break;
  2395. }
  2396. case HRTIM_CAPTUREUNIT_2:
  2397. {
  2398. hhrtim->Instance->sTimerxRegs[TimerIdx].CPT2xCR = HRTIM_CAPTURETRIGGER_NONE;
  2399. /* Disable the capture unit 2 interrupt */
  2400. __HAL_HRTIM_TIMER_DISABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CPT2);
  2401. break;
  2402. }
  2403. default:
  2404. {
  2405. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2406. /* Process Unlocked */
  2407. __HAL_UNLOCK(hhrtim);
  2408. break;
  2409. }
  2410. }
  2411. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  2412. {
  2413. return HAL_ERROR;
  2414. }
  2415. hrtim_cpt1cr = hhrtim->Instance->sTimerxRegs[TimerIdx].CPT1xCR;
  2416. hrtim_cpt2cr = hhrtim->Instance->sTimerxRegs[TimerIdx].CPT2xCR;
  2417. /* Disable the timer counter */
  2418. if ((hrtim_cpt1cr == HRTIM_CAPTURETRIGGER_NONE) &&
  2419. (hrtim_cpt2cr == HRTIM_CAPTURETRIGGER_NONE))
  2420. {
  2421. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  2422. }
  2423. hhrtim->State = HAL_HRTIM_STATE_READY;
  2424. /* Process Unlocked */
  2425. __HAL_UNLOCK(hhrtim);
  2426. return HAL_OK;
  2427. }
  2428. /**
  2429. * @brief Enable a simple capture on the designed capture unit
  2430. * (Capture DMA request is enabled).
  2431. * @param hhrtim pointer to HAL HRTIM handle
  2432. * @param TimerIdx Timer index
  2433. * This parameter can be one of the following values:
  2434. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  2435. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  2436. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  2437. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  2438. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  2439. * @param CaptureChannel Timer output
  2440. * This parameter can be one of the following values:
  2441. * @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  2442. * @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  2443. * @param SrcAddr DMA transfer source address
  2444. * @param DestAddr DMA transfer destination address
  2445. * @param Length The length of data items (data size) to be transferred
  2446. * from source to destination
  2447. * @retval HAL status
  2448. */
  2449. HAL_StatusTypeDef HAL_HRTIM_SimpleCaptureStart_DMA(HRTIM_HandleTypeDef * hhrtim,
  2450. uint32_t TimerIdx,
  2451. uint32_t CaptureChannel,
  2452. uint32_t SrcAddr,
  2453. uint32_t DestAddr,
  2454. uint32_t Length)
  2455. {
  2456. DMA_HandleTypeDef * hdma;
  2457. /* Check the parameters */
  2458. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  2459. assert_param(IS_HRTIM_CAPTUREUNIT(CaptureChannel));
  2460. /* Process Locked */
  2461. __HAL_LOCK(hhrtim);
  2462. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  2463. /* Get the timer DMA handler */
  2464. hdma = HRTIM_GetDMAHandleFromTimerIdx(hhrtim, TimerIdx);
  2465. if (hdma == NULL)
  2466. {
  2467. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2468. /* Process Unlocked */
  2469. __HAL_UNLOCK(hhrtim);
  2470. return HAL_ERROR;
  2471. }
  2472. /* Set the DMA error callback */
  2473. hdma->XferErrorCallback = HRTIM_DMAError ;
  2474. /* Set the DMA transfer completed callback */
  2475. hdma->XferCpltCallback = HRTIM_DMATimerxCplt;
  2476. /* Enable the DMA channel */
  2477. if (HAL_DMA_Start_IT(hdma, SrcAddr, DestAddr, Length) != HAL_OK)
  2478. {
  2479. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2480. /* Process Unlocked */
  2481. __HAL_UNLOCK(hhrtim);
  2482. return HAL_ERROR;
  2483. }
  2484. switch (CaptureChannel)
  2485. {
  2486. case HRTIM_CAPTUREUNIT_1:
  2487. {
  2488. /* Set the capture unit trigger */
  2489. hhrtim->Instance->sTimerxRegs[TimerIdx].CPT1xCR = hhrtim->TimerParam[TimerIdx].CaptureTrigger1;
  2490. __HAL_HRTIM_TIMER_ENABLE_DMA(hhrtim, TimerIdx, HRTIM_TIM_DMA_CPT1);
  2491. break;
  2492. }
  2493. case HRTIM_CAPTUREUNIT_2:
  2494. {
  2495. /* Set the capture unit trigger */
  2496. hhrtim->Instance->sTimerxRegs[TimerIdx].CPT2xCR = hhrtim->TimerParam[TimerIdx].CaptureTrigger2;
  2497. /* Enable the timer DMA request */
  2498. __HAL_HRTIM_TIMER_ENABLE_DMA(hhrtim, TimerIdx, HRTIM_TIM_DMA_CPT2);
  2499. break;
  2500. }
  2501. default:
  2502. {
  2503. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2504. /* Process Unlocked */
  2505. __HAL_UNLOCK(hhrtim);
  2506. break;
  2507. }
  2508. }
  2509. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  2510. {
  2511. return HAL_ERROR;
  2512. }
  2513. /* Enable the timer counter */
  2514. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  2515. hhrtim->State = HAL_HRTIM_STATE_READY;
  2516. /* Process Unlocked */
  2517. __HAL_UNLOCK(hhrtim);
  2518. return HAL_OK;
  2519. }
  2520. /**
  2521. * @brief Disable a simple capture on the designed capture unit
  2522. * (Capture DMA request is disabled).
  2523. * @param hhrtim pointer to HAL HRTIM handle
  2524. * @param TimerIdx Timer index
  2525. * This parameter can be one of the following values:
  2526. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  2527. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  2528. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  2529. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  2530. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  2531. * @param CaptureChannel Timer output
  2532. * This parameter can be one of the following values:
  2533. * @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  2534. * @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  2535. * @retval HAL status
  2536. */
  2537. HAL_StatusTypeDef HAL_HRTIM_SimpleCaptureStop_DMA(HRTIM_HandleTypeDef * hhrtim,
  2538. uint32_t TimerIdx,
  2539. uint32_t CaptureChannel)
  2540. {
  2541. uint32_t hrtim_cpt1cr;
  2542. uint32_t hrtim_cpt2cr;
  2543. /* Check the parameters */
  2544. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  2545. assert_param(IS_HRTIM_CAPTUREUNIT(CaptureChannel));
  2546. /* Process Locked */
  2547. __HAL_LOCK(hhrtim);
  2548. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  2549. /* Get the timer DMA handler */
  2550. /* Disable the DMA */
  2551. if (HAL_DMA_Abort(HRTIM_GetDMAHandleFromTimerIdx(hhrtim, TimerIdx)) != HAL_OK)
  2552. {
  2553. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2554. /* Process Unlocked */
  2555. __HAL_UNLOCK(hhrtim);
  2556. return HAL_ERROR;
  2557. }
  2558. switch (CaptureChannel)
  2559. {
  2560. case HRTIM_CAPTUREUNIT_1:
  2561. {
  2562. /* Reset the capture unit trigger */
  2563. hhrtim->Instance->sTimerxRegs[TimerIdx].CPT1xCR = HRTIM_CAPTURETRIGGER_NONE;
  2564. /* Disable the capture unit 1 DMA request */
  2565. __HAL_HRTIM_TIMER_DISABLE_DMA(hhrtim, TimerIdx, HRTIM_TIM_DMA_CPT1);
  2566. break;
  2567. }
  2568. case HRTIM_CAPTUREUNIT_2:
  2569. {
  2570. /* Reset the capture unit trigger */
  2571. hhrtim->Instance->sTimerxRegs[TimerIdx].CPT2xCR = HRTIM_CAPTURETRIGGER_NONE;
  2572. /* Disable the capture unit 2 DMA request */
  2573. __HAL_HRTIM_TIMER_DISABLE_DMA(hhrtim, TimerIdx, HRTIM_TIM_DMA_CPT2);
  2574. break;
  2575. }
  2576. default:
  2577. {
  2578. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2579. /* Process Unlocked */
  2580. __HAL_UNLOCK(hhrtim);
  2581. break;
  2582. }
  2583. }
  2584. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  2585. {
  2586. return HAL_ERROR;
  2587. }
  2588. hrtim_cpt1cr = hhrtim->Instance->sTimerxRegs[TimerIdx].CPT1xCR;
  2589. hrtim_cpt2cr = hhrtim->Instance->sTimerxRegs[TimerIdx].CPT2xCR;
  2590. /* Disable the timer counter */
  2591. if ((hrtim_cpt1cr == HRTIM_CAPTURETRIGGER_NONE) &&
  2592. (hrtim_cpt2cr == HRTIM_CAPTURETRIGGER_NONE))
  2593. {
  2594. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  2595. }
  2596. hhrtim->State = HAL_HRTIM_STATE_READY;
  2597. /* Process Unlocked */
  2598. __HAL_UNLOCK(hhrtim);
  2599. return HAL_OK;
  2600. }
  2601. /**
  2602. * @}
  2603. */
  2604. /** @defgroup HRTIM_Exported_Functions_Group6 Simple one pulse functions
  2605. * @brief Simple one pulse functions
  2606. @verbatim
  2607. ===============================================================================
  2608. ##### Simple one pulse functions #####
  2609. ===============================================================================
  2610. [..] This section provides functions allowing to:
  2611. (+) Configure one pulse channel
  2612. (+) Start one pulse generation
  2613. (+) Stop one pulse generation
  2614. (+) Start one pulse generation and enable interrupt
  2615. (+) Stop one pulse generation and disable interrupt
  2616. -@- When a HRTIM timer operates in simple one pulse mode
  2617. the timer counter is started in response to transition detected
  2618. on a given external event input to generate a pulse with a
  2619. programmable length after a programmable delay.
  2620. @endverbatim
  2621. * @{
  2622. */
  2623. /**
  2624. * @brief Configure an output simple one pulse mode
  2625. * @param hhrtim pointer to HAL HRTIM handle
  2626. * @param TimerIdx Timer index
  2627. * This parameter can be one of the following values:
  2628. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  2629. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  2630. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  2631. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  2632. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  2633. * @param OnePulseChannel Timer output
  2634. * This parameter can be one of the following values:
  2635. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  2636. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  2637. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  2638. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  2639. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  2640. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  2641. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  2642. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  2643. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  2644. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  2645. * @param pSimpleOnePulseChannelCfg pointer to the simple one pulse output configuration structure
  2646. * @note When the timer operates in simple one pulse mode:
  2647. * the timer counter is implicitly started by the reset event,
  2648. * the reset of the timer counter is triggered by the designated external event
  2649. * GPIO input is implicitly used as event source,
  2650. * Output 1 is implicitly controlled by the compare unit 1,
  2651. * Output 2 is implicitly controlled by the compare unit 2.
  2652. * Output Set/Reset crossbar is set as follows:
  2653. * Output 1: SETx1R = CMP1, RSTx1R = PER
  2654. * Output 2: SETx2R = CMP2, RST2R = PER
  2655. * @retval HAL status
  2656. * @note If HAL_HRTIM_SimpleOnePulseChannelConfig is called for both timer
  2657. * outputs, the reset event related configuration data provided in the
  2658. * second call will override the reset event related configuration data
  2659. * provided in the first call.
  2660. */
  2661. HAL_StatusTypeDef HAL_HRTIM_SimpleOnePulseChannelConfig(HRTIM_HandleTypeDef * hhrtim,
  2662. uint32_t TimerIdx,
  2663. uint32_t OnePulseChannel,
  2664. HRTIM_SimpleOnePulseChannelCfgTypeDef* pSimpleOnePulseChannelCfg)
  2665. {
  2666. HRTIM_OutputCfgTypeDef OutputCfg;
  2667. HRTIM_EventCfgTypeDef EventCfg;
  2668. /* Check parameters */
  2669. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OnePulseChannel));
  2670. assert_param(IS_HRTIM_OUTPUTPULSE(pSimpleOnePulseChannelCfg->Pulse));
  2671. assert_param(IS_HRTIM_OUTPUTPOLARITY(pSimpleOnePulseChannelCfg->OutputPolarity));
  2672. assert_param(IS_HRTIM_OUTPUTIDLELEVEL(pSimpleOnePulseChannelCfg->OutputIdleLevel));
  2673. assert_param(IS_HRTIM_EVENT(pSimpleOnePulseChannelCfg->Event));
  2674. assert_param(IS_HRTIM_EVENTPOLARITY(pSimpleOnePulseChannelCfg->EventSensitivity,
  2675. pSimpleOnePulseChannelCfg->EventPolarity));
  2676. assert_param(IS_HRTIM_EVENTSENSITIVITY(pSimpleOnePulseChannelCfg->EventSensitivity));
  2677. assert_param(IS_HRTIM_EVENTFILTER(pSimpleOnePulseChannelCfg->Event,
  2678. pSimpleOnePulseChannelCfg->EventFilter));
  2679. if(hhrtim->State == HAL_HRTIM_STATE_BUSY)
  2680. {
  2681. return HAL_BUSY;
  2682. }
  2683. /* Process Locked */
  2684. __HAL_LOCK(hhrtim);
  2685. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  2686. /* Configure timer compare unit */
  2687. switch (OnePulseChannel)
  2688. {
  2689. case HRTIM_OUTPUT_TA1:
  2690. case HRTIM_OUTPUT_TB1:
  2691. case HRTIM_OUTPUT_TC1:
  2692. case HRTIM_OUTPUT_TD1:
  2693. case HRTIM_OUTPUT_TE1:
  2694. {
  2695. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP1xR = pSimpleOnePulseChannelCfg->Pulse;
  2696. OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP1;
  2697. break;
  2698. }
  2699. case HRTIM_OUTPUT_TA2:
  2700. case HRTIM_OUTPUT_TB2:
  2701. case HRTIM_OUTPUT_TC2:
  2702. case HRTIM_OUTPUT_TD2:
  2703. case HRTIM_OUTPUT_TE2:
  2704. {
  2705. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP2xR = pSimpleOnePulseChannelCfg->Pulse;
  2706. OutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP2;
  2707. break;
  2708. }
  2709. default:
  2710. {
  2711. OutputCfg.SetSource = HRTIM_OUTPUTSET_NONE;
  2712. OutputCfg.ResetSource = HRTIM_OUTPUTRESET_NONE;
  2713. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2714. /* Process Unlocked */
  2715. __HAL_UNLOCK(hhrtim);
  2716. break;
  2717. }
  2718. }
  2719. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  2720. {
  2721. return HAL_ERROR;
  2722. }
  2723. /* Configure timer output */
  2724. OutputCfg.Polarity = (pSimpleOnePulseChannelCfg->OutputPolarity & HRTIM_OUTR_POL1);
  2725. OutputCfg.IdleLevel = (pSimpleOnePulseChannelCfg->OutputIdleLevel & HRTIM_OUTR_IDLES1);
  2726. OutputCfg.FaultLevel = HRTIM_OUTPUTFAULTLEVEL_NONE;
  2727. OutputCfg.IdleMode = HRTIM_OUTPUTIDLEMODE_NONE;
  2728. OutputCfg.ChopperModeEnable = HRTIM_OUTPUTCHOPPERMODE_DISABLED;
  2729. OutputCfg.BurstModeEntryDelayed = HRTIM_OUTPUTBURSTMODEENTRY_REGULAR;
  2730. OutputCfg.ResetSource = HRTIM_OUTPUTRESET_TIMPER;
  2731. HRTIM_OutputConfig(hhrtim,
  2732. TimerIdx,
  2733. OnePulseChannel,
  2734. &OutputCfg);
  2735. /* Configure external event channel */
  2736. EventCfg.FastMode = HRTIM_EVENTFASTMODE_DISABLE;
  2737. EventCfg.Filter = (pSimpleOnePulseChannelCfg->EventFilter & HRTIM_EECR3_EE6F);
  2738. EventCfg.Polarity = (pSimpleOnePulseChannelCfg->EventPolarity & HRTIM_OUTR_POL1);
  2739. EventCfg.Sensitivity = (pSimpleOnePulseChannelCfg->EventSensitivity &HRTIM_EECR1_EE1SNS);
  2740. EventCfg.Source = HRTIM_EVENTSRC_1;
  2741. HRTIM_EventConfig(hhrtim,
  2742. pSimpleOnePulseChannelCfg->Event,
  2743. &EventCfg);
  2744. /* Configure the timer reset register */
  2745. HRTIM_TIM_ResetConfig(hhrtim,
  2746. TimerIdx,
  2747. pSimpleOnePulseChannelCfg->Event);
  2748. hhrtim->State = HAL_HRTIM_STATE_READY;
  2749. /* Process Unlocked */
  2750. __HAL_UNLOCK(hhrtim);
  2751. return HAL_OK;
  2752. }
  2753. /**
  2754. * @brief Enable the simple one pulse signal generation on the designed output
  2755. * @param hhrtim pointer to HAL HRTIM handle
  2756. * @param TimerIdx Timer index
  2757. * This parameter can be one of the following values:
  2758. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  2759. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  2760. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  2761. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  2762. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  2763. * @param OnePulseChannel Timer output
  2764. * This parameter can be one of the following values:
  2765. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  2766. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  2767. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  2768. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  2769. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  2770. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  2771. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  2772. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  2773. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  2774. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  2775. * @retval HAL status
  2776. */
  2777. HAL_StatusTypeDef HAL_HRTIM_SimpleOnePulseStart(HRTIM_HandleTypeDef * hhrtim,
  2778. uint32_t TimerIdx,
  2779. uint32_t OnePulseChannel)
  2780. {
  2781. /* Check the parameters */
  2782. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OnePulseChannel));
  2783. /* Process Locked */
  2784. __HAL_LOCK(hhrtim);
  2785. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  2786. /* Enable the timer output */
  2787. hhrtim->Instance->sCommonRegs.OENR |= OnePulseChannel;
  2788. /* Enable the timer counter */
  2789. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  2790. hhrtim->State = HAL_HRTIM_STATE_READY;
  2791. /* Process Unlocked */
  2792. __HAL_UNLOCK(hhrtim);
  2793. return HAL_OK;
  2794. }
  2795. /**
  2796. * @brief Disable the simple one pulse signal generation on the designed output
  2797. * @param hhrtim pointer to HAL HRTIM handle
  2798. * @param TimerIdx Timer index
  2799. * This parameter can be one of the following values:
  2800. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  2801. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  2802. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  2803. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  2804. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  2805. * @param OnePulseChannel Timer output
  2806. * This parameter can be one of the following values:
  2807. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  2808. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  2809. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  2810. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  2811. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  2812. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  2813. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  2814. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  2815. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  2816. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  2817. * @retval HAL status
  2818. */
  2819. HAL_StatusTypeDef HAL_HRTIM_SimpleOnePulseStop(HRTIM_HandleTypeDef * hhrtim,
  2820. uint32_t TimerIdx,
  2821. uint32_t OnePulseChannel)
  2822. {
  2823. /* Check the parameters */
  2824. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OnePulseChannel));
  2825. /* Process Locked */
  2826. __HAL_LOCK(hhrtim);
  2827. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  2828. /* Disable the timer output */
  2829. hhrtim->Instance->sCommonRegs.ODISR |= OnePulseChannel;
  2830. /* Disable the timer counter */
  2831. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  2832. hhrtim->State = HAL_HRTIM_STATE_READY;
  2833. /* Process Unlocked */
  2834. __HAL_UNLOCK(hhrtim);
  2835. return HAL_OK;
  2836. }
  2837. /**
  2838. * @brief Enable the simple one pulse signal generation on the designed output
  2839. * (The compare interrupt is enabled (pulse start)).
  2840. * @param hhrtim pointer to HAL HRTIM handle
  2841. * @param TimerIdx Timer index
  2842. * This parameter can be one of the following values:
  2843. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  2844. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  2845. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  2846. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  2847. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  2848. * @param OnePulseChannel Timer output
  2849. * This parameter can be one of the following values:
  2850. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  2851. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  2852. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  2853. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  2854. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  2855. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  2856. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  2857. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  2858. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  2859. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  2860. * @retval HAL status
  2861. */
  2862. HAL_StatusTypeDef HAL_HRTIM_SimpleOnePulseStart_IT(HRTIM_HandleTypeDef * hhrtim,
  2863. uint32_t TimerIdx,
  2864. uint32_t OnePulseChannel)
  2865. {
  2866. /* Check the parameters */
  2867. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OnePulseChannel));
  2868. /* Process Locked */
  2869. __HAL_LOCK(hhrtim);
  2870. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  2871. /* Enable the timer output */
  2872. hhrtim->Instance->sCommonRegs.OENR |= OnePulseChannel;
  2873. /* Enable the timer interrupt (depends on the OnePulse output) */
  2874. switch (OnePulseChannel)
  2875. {
  2876. case HRTIM_OUTPUT_TA1:
  2877. case HRTIM_OUTPUT_TB1:
  2878. case HRTIM_OUTPUT_TC1:
  2879. case HRTIM_OUTPUT_TD1:
  2880. case HRTIM_OUTPUT_TE1:
  2881. {
  2882. __HAL_HRTIM_TIMER_ENABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP1);
  2883. break;
  2884. }
  2885. case HRTIM_OUTPUT_TA2:
  2886. case HRTIM_OUTPUT_TB2:
  2887. case HRTIM_OUTPUT_TC2:
  2888. case HRTIM_OUTPUT_TD2:
  2889. case HRTIM_OUTPUT_TE2:
  2890. {
  2891. __HAL_HRTIM_TIMER_ENABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP2);
  2892. break;
  2893. }
  2894. default:
  2895. {
  2896. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2897. /* Process Unlocked */
  2898. __HAL_UNLOCK(hhrtim);
  2899. break;
  2900. }
  2901. }
  2902. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  2903. {
  2904. return HAL_ERROR;
  2905. }
  2906. /* Enable the timer counter */
  2907. __HAL_HRTIM_ENABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  2908. hhrtim->State = HAL_HRTIM_STATE_READY;
  2909. /* Process Unlocked */
  2910. __HAL_UNLOCK(hhrtim);
  2911. return HAL_OK;
  2912. }
  2913. /**
  2914. * @brief Disable the simple one pulse signal generation on the designed output
  2915. * (The compare interrupt is disabled).
  2916. * @param hhrtim pointer to HAL HRTIM handle
  2917. * @param TimerIdx Timer index
  2918. * This parameter can be one of the following values:
  2919. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  2920. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  2921. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  2922. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  2923. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  2924. * @param OnePulseChannel Timer output
  2925. * This parameter can be one of the following values:
  2926. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  2927. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  2928. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  2929. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  2930. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  2931. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  2932. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  2933. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  2934. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  2935. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  2936. * @retval HAL status
  2937. */
  2938. HAL_StatusTypeDef HAL_HRTIM_SimpleOnePulseStop_IT(HRTIM_HandleTypeDef * hhrtim,
  2939. uint32_t TimerIdx,
  2940. uint32_t OnePulseChannel)
  2941. {
  2942. /* Check the parameters */
  2943. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, OnePulseChannel));
  2944. /* Process Locked */
  2945. __HAL_LOCK(hhrtim);
  2946. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  2947. /* Disable the timer output */
  2948. hhrtim->Instance->sCommonRegs.ODISR |= OnePulseChannel;
  2949. /* Disable the timer interrupt (depends on the OnePulse output) */
  2950. switch (OnePulseChannel)
  2951. {
  2952. case HRTIM_OUTPUT_TA1:
  2953. case HRTIM_OUTPUT_TB1:
  2954. case HRTIM_OUTPUT_TC1:
  2955. case HRTIM_OUTPUT_TD1:
  2956. case HRTIM_OUTPUT_TE1:
  2957. {
  2958. __HAL_HRTIM_TIMER_DISABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP1);
  2959. break;
  2960. }
  2961. case HRTIM_OUTPUT_TA2:
  2962. case HRTIM_OUTPUT_TB2:
  2963. case HRTIM_OUTPUT_TC2:
  2964. case HRTIM_OUTPUT_TD2:
  2965. case HRTIM_OUTPUT_TE2:
  2966. {
  2967. __HAL_HRTIM_TIMER_DISABLE_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP2);
  2968. break;
  2969. }
  2970. default:
  2971. {
  2972. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  2973. /* Process Unlocked */
  2974. __HAL_UNLOCK(hhrtim);
  2975. break;
  2976. }
  2977. }
  2978. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  2979. {
  2980. return HAL_ERROR;
  2981. }
  2982. /* Disable the timer counter */
  2983. __HAL_HRTIM_DISABLE(hhrtim, TimerIdxToTimerId[TimerIdx]);
  2984. hhrtim->State = HAL_HRTIM_STATE_READY;
  2985. /* Process Unlocked */
  2986. __HAL_UNLOCK(hhrtim);
  2987. return HAL_OK;
  2988. }
  2989. /**
  2990. * @}
  2991. */
  2992. /** @defgroup HRTIM_Exported_Functions_Group7 Configuration functions
  2993. * @brief HRTIM configuration functions
  2994. @verbatim
  2995. ===============================================================================
  2996. ##### HRTIM configuration functions #####
  2997. ===============================================================================
  2998. [..] This section provides functions allowing to configure the HRTIM
  2999. resources shared by all the HRTIM timers operating in waveform mode:
  3000. (+) Configure the burst mode controller
  3001. (+) Configure an external event conditioning
  3002. (+) Configure the external events sampling clock
  3003. (+) Configure a fault conditioning
  3004. (+) Enable or disable fault inputs
  3005. (+) Configure the faults sampling clock
  3006. (+) Configure an ADC trigger
  3007. @endverbatim
  3008. * @{
  3009. */
  3010. /**
  3011. * @brief Configure the burst mode feature of the HRTIM
  3012. * @param hhrtim pointer to HAL HRTIM handle
  3013. * @param pBurstModeCfg pointer to the burst mode configuration structure
  3014. * @retval HAL status
  3015. * @note This function must be called before starting the burst mode
  3016. * controller
  3017. */
  3018. HAL_StatusTypeDef HAL_HRTIM_BurstModeConfig(HRTIM_HandleTypeDef * hhrtim,
  3019. HRTIM_BurstModeCfgTypeDef* pBurstModeCfg)
  3020. {
  3021. uint32_t hrtim_bmcr;
  3022. /* Check parameters */
  3023. assert_param(IS_HRTIM_BURSTMODE(pBurstModeCfg->Mode));
  3024. assert_param(IS_HRTIM_BURSTMODECLOCKSOURCE(pBurstModeCfg->ClockSource));
  3025. assert_param(IS_HRTIM_HRTIM_BURSTMODEPRESCALER(pBurstModeCfg->Prescaler));
  3026. assert_param(IS_HRTIM_BURSTMODEPRELOAD(pBurstModeCfg->PreloadEnable));
  3027. assert_param(IS_HRTIM_BURSTMODETRIGGER(pBurstModeCfg->Trigger));
  3028. if(hhrtim->State == HAL_HRTIM_STATE_BUSY)
  3029. {
  3030. return HAL_BUSY;
  3031. }
  3032. /* Process Locked */
  3033. __HAL_LOCK(hhrtim);
  3034. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  3035. hrtim_bmcr = hhrtim->Instance->sCommonRegs.BMCR;
  3036. /* Set the burst mode operating mode */
  3037. hrtim_bmcr &= ~(HRTIM_BMCR_BMOM);
  3038. hrtim_bmcr |= (pBurstModeCfg->Mode & HRTIM_BMCR_BMOM);
  3039. /* Set the burst mode clock source */
  3040. hrtim_bmcr &= ~(HRTIM_BMCR_BMCLK);
  3041. hrtim_bmcr |= (pBurstModeCfg->ClockSource & HRTIM_BMCR_BMCLK);
  3042. /* Set the burst mode prescaler */
  3043. hrtim_bmcr &= ~(HRTIM_BMCR_BMPRSC);
  3044. hrtim_bmcr |= pBurstModeCfg->Prescaler;
  3045. /* Enable/disable burst mode registers preload */
  3046. hrtim_bmcr &= ~(HRTIM_BMCR_BMPREN);
  3047. hrtim_bmcr |= (pBurstModeCfg->PreloadEnable & HRTIM_BMCR_BMPREN);
  3048. /* Set the burst mode trigger */
  3049. hhrtim->Instance->sCommonRegs.BMTRGR = pBurstModeCfg->Trigger;
  3050. /* Set the burst mode compare value */
  3051. hhrtim->Instance->sCommonRegs.BMCMPR = pBurstModeCfg->IdleDuration;
  3052. /* Set the burst mode period */
  3053. hhrtim->Instance->sCommonRegs.BMPER = pBurstModeCfg->Period;
  3054. /* Update the HRTIM registers */
  3055. hhrtim->Instance->sCommonRegs.BMCR = hrtim_bmcr;
  3056. hhrtim->State = HAL_HRTIM_STATE_READY;
  3057. /* Process Unlocked */
  3058. __HAL_UNLOCK(hhrtim);
  3059. return HAL_OK;
  3060. }
  3061. /**
  3062. * @brief Configure the conditioning of an external event
  3063. * @param hhrtim pointer to HAL HRTIM handle
  3064. * @param Event external event to configure
  3065. * This parameter can be one of the following values:
  3066. * @arg HRTIM_EVENT_NONE: no external Event
  3067. * @arg HRTIM_EVENT_1: External event 1
  3068. * @arg HRTIM_EVENT_2: External event 2
  3069. * @arg HRTIM_EVENT_3: External event 3
  3070. * @arg HRTIM_EVENT_4: External event 4
  3071. * @arg HRTIM_EVENT_5: External event 5
  3072. * @arg HRTIM_EVENT_6: External event 6
  3073. * @arg HRTIM_EVENT_7: External event 7
  3074. * @arg HRTIM_EVENT_8: External event 8
  3075. * @arg HRTIM_EVENT_9: External event 9
  3076. * @arg HRTIM_EVENT_10: External event 10
  3077. * @param pEventCfg pointer to the event conditioning configuration structure
  3078. * @note This function must be called before starting the timer
  3079. * @retval HAL status
  3080. */
  3081. HAL_StatusTypeDef HAL_HRTIM_EventConfig(HRTIM_HandleTypeDef * hhrtim,
  3082. uint32_t Event,
  3083. HRTIM_EventCfgTypeDef* pEventCfg)
  3084. {
  3085. /* Check parameters */
  3086. assert_param(IS_HRTIM_EVENT(Event));
  3087. assert_param(IS_HRTIM_EVENTSRC(pEventCfg->Source));
  3088. assert_param(IS_HRTIM_EVENTPOLARITY(pEventCfg->Sensitivity, pEventCfg->Polarity));
  3089. assert_param(IS_HRTIM_EVENTSENSITIVITY(pEventCfg->Sensitivity));
  3090. assert_param(IS_HRTIM_EVENTFASTMODE(Event, pEventCfg->FastMode));
  3091. assert_param(IS_HRTIM_EVENTFILTER(Event, pEventCfg->Filter));
  3092. if(hhrtim->State == HAL_HRTIM_STATE_BUSY)
  3093. {
  3094. return HAL_BUSY;
  3095. }
  3096. /* Process Locked */
  3097. __HAL_LOCK(hhrtim);
  3098. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  3099. /* Configure the event channel */
  3100. HRTIM_EventConfig(hhrtim, Event, pEventCfg);
  3101. hhrtim->State = HAL_HRTIM_STATE_READY;
  3102. /* Process Unlocked */
  3103. __HAL_UNLOCK(hhrtim);
  3104. return HAL_OK;
  3105. }
  3106. /**
  3107. * @brief Configure the external event conditioning block prescaler
  3108. * @param hhrtim pointer to HAL HRTIM handle
  3109. * @param Prescaler Prescaler value
  3110. * This parameter can be one of the following values:
  3111. * @arg HRTIM_EVENTPRESCALER_DIV1: fEEVS=fHRTIM
  3112. * @arg HRTIM_EVENTPRESCALER_DIV2: fEEVS=fHRTIM / 2
  3113. * @arg HRTIM_EVENTPRESCALER_DIV4: fEEVS=fHRTIM / 4
  3114. * @arg HRTIM_EVENTPRESCALER_DIV8: fEEVS=fHRTIM / 8
  3115. * @note This function must be called before starting the timer
  3116. * @retval HAL status
  3117. */
  3118. HAL_StatusTypeDef HAL_HRTIM_EventPrescalerConfig(HRTIM_HandleTypeDef * hhrtim,
  3119. uint32_t Prescaler)
  3120. {
  3121. /* Check parameters */
  3122. assert_param(IS_HRTIM_EVENTPRESCALER(Prescaler));
  3123. if(hhrtim->State == HAL_HRTIM_STATE_BUSY)
  3124. {
  3125. return HAL_BUSY;
  3126. }
  3127. /* Process Locked */
  3128. __HAL_LOCK(hhrtim);
  3129. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  3130. /* Set the external event prescaler */
  3131. MODIFY_REG(hhrtim->Instance->sCommonRegs.EECR3, HRTIM_EECR3_EEVSD, (Prescaler & HRTIM_EECR3_EEVSD));
  3132. hhrtim->State = HAL_HRTIM_STATE_READY;
  3133. /* Process Unlocked */
  3134. __HAL_UNLOCK(hhrtim);
  3135. return HAL_OK;
  3136. }
  3137. /**
  3138. * @brief Configure the conditioning of fault input
  3139. * @param hhrtim pointer to HAL HRTIM handle
  3140. * @param Fault fault input to configure
  3141. * This parameter can be one of the following values:
  3142. * @arg HRTIM_FAULT_1: Fault input 1
  3143. * @arg HRTIM_FAULT_2: Fault input 2
  3144. * @arg HRTIM_FAULT_3: Fault input 3
  3145. * @arg HRTIM_FAULT_4: Fault input 4
  3146. * @arg HRTIM_FAULT_5: Fault input 5
  3147. * @param pFaultCfg pointer to the fault conditioning configuration structure
  3148. * @note This function must be called before starting the timer and before
  3149. * enabling faults inputs
  3150. * @retval HAL status
  3151. */
  3152. HAL_StatusTypeDef HAL_HRTIM_FaultConfig(HRTIM_HandleTypeDef * hhrtim,
  3153. uint32_t Fault,
  3154. HRTIM_FaultCfgTypeDef* pFaultCfg)
  3155. {
  3156. uint32_t hrtim_fltinr1;
  3157. uint32_t hrtim_fltinr2;
  3158. /* Check parameters */
  3159. assert_param(IS_HRTIM_FAULT(Fault));
  3160. assert_param(IS_HRTIM_FAULTSOURCE(pFaultCfg->Source));
  3161. assert_param(IS_HRTIM_FAULTPOLARITY(pFaultCfg->Polarity));
  3162. assert_param(IS_HRTIM_FAULTFILTER(pFaultCfg->Filter));
  3163. assert_param(IS_HRTIM_FAULTLOCK(pFaultCfg->Lock));
  3164. if(hhrtim->State == HAL_HRTIM_STATE_BUSY)
  3165. {
  3166. return HAL_BUSY;
  3167. }
  3168. /* Process Locked */
  3169. __HAL_LOCK(hhrtim);
  3170. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  3171. /* Configure fault channel */
  3172. hrtim_fltinr1 = hhrtim->Instance->sCommonRegs.FLTINR1;
  3173. hrtim_fltinr2 = hhrtim->Instance->sCommonRegs.FLTINR2;
  3174. switch (Fault)
  3175. {
  3176. case HRTIM_FAULT_1:
  3177. {
  3178. hrtim_fltinr1 &= ~(HRTIM_FLTINR1_FLT1P | HRTIM_FLTINR1_FLT1SRC | HRTIM_FLTINR1_FLT1F | HRTIM_FLTINR1_FLT1LCK);
  3179. hrtim_fltinr1 |= (pFaultCfg->Polarity & HRTIM_FLTINR1_FLT1P);
  3180. hrtim_fltinr1 |= (pFaultCfg->Source & HRTIM_FLTINR1_FLT1SRC);
  3181. hrtim_fltinr1 |= (pFaultCfg->Filter & HRTIM_FLTINR1_FLT1F);
  3182. hrtim_fltinr1 |= (pFaultCfg->Lock & HRTIM_FLTINR1_FLT1LCK);
  3183. break;
  3184. }
  3185. case HRTIM_FAULT_2:
  3186. {
  3187. hrtim_fltinr1 &= ~(HRTIM_FLTINR1_FLT2P | HRTIM_FLTINR1_FLT2SRC | HRTIM_FLTINR1_FLT2F | HRTIM_FLTINR1_FLT2LCK);
  3188. hrtim_fltinr1 |= ((pFaultCfg->Polarity << 8U) & HRTIM_FLTINR1_FLT2P);
  3189. hrtim_fltinr1 |= ((pFaultCfg->Source << 8U) & HRTIM_FLTINR1_FLT2SRC);
  3190. hrtim_fltinr1 |= ((pFaultCfg->Filter << 8U) & HRTIM_FLTINR1_FLT2F);
  3191. hrtim_fltinr1 |= ((pFaultCfg->Lock << 8U) & HRTIM_FLTINR1_FLT2LCK);
  3192. break;
  3193. }
  3194. case HRTIM_FAULT_3:
  3195. {
  3196. hrtim_fltinr1 &= ~(HRTIM_FLTINR1_FLT3P | HRTIM_FLTINR1_FLT3SRC | HRTIM_FLTINR1_FLT3F | HRTIM_FLTINR1_FLT3LCK);
  3197. hrtim_fltinr1 |= ((pFaultCfg->Polarity << 16U) & HRTIM_FLTINR1_FLT3P);
  3198. hrtim_fltinr1 |= ((pFaultCfg->Source << 16U) & HRTIM_FLTINR1_FLT3SRC);
  3199. hrtim_fltinr1 |= ((pFaultCfg->Filter << 16U) & HRTIM_FLTINR1_FLT3F);
  3200. hrtim_fltinr1 |= ((pFaultCfg->Lock << 16U) & HRTIM_FLTINR1_FLT3LCK);
  3201. break;
  3202. }
  3203. case HRTIM_FAULT_4:
  3204. {
  3205. hrtim_fltinr1 &= ~(HRTIM_FLTINR1_FLT4P | HRTIM_FLTINR1_FLT4SRC | HRTIM_FLTINR1_FLT4F | HRTIM_FLTINR1_FLT4LCK);
  3206. hrtim_fltinr1 |= ((pFaultCfg->Polarity << 24U) & HRTIM_FLTINR1_FLT4P);
  3207. hrtim_fltinr1 |= ((pFaultCfg->Source << 24U) & HRTIM_FLTINR1_FLT4SRC);
  3208. hrtim_fltinr1 |= ((pFaultCfg->Filter << 24U) & HRTIM_FLTINR1_FLT4F);
  3209. hrtim_fltinr1 |= ((pFaultCfg->Lock << 24U) & HRTIM_FLTINR1_FLT4LCK);
  3210. break;
  3211. }
  3212. case HRTIM_FAULT_5:
  3213. {
  3214. hrtim_fltinr2 &= ~(HRTIM_FLTINR2_FLT5P | HRTIM_FLTINR2_FLT5SRC | HRTIM_FLTINR2_FLT5F | HRTIM_FLTINR2_FLT5LCK);
  3215. hrtim_fltinr2 |= (pFaultCfg->Polarity & HRTIM_FLTINR2_FLT5P);
  3216. hrtim_fltinr2 |= (pFaultCfg->Source & HRTIM_FLTINR2_FLT5SRC);
  3217. hrtim_fltinr2 |= (pFaultCfg->Filter & HRTIM_FLTINR2_FLT5F);
  3218. hrtim_fltinr2 |= (pFaultCfg->Lock & HRTIM_FLTINR2_FLT5LCK);
  3219. break;
  3220. }
  3221. default:
  3222. {
  3223. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  3224. /* Process Unlocked */
  3225. __HAL_UNLOCK(hhrtim);
  3226. break;
  3227. }
  3228. }
  3229. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  3230. {
  3231. return HAL_ERROR;
  3232. }
  3233. /* Update the HRTIM registers except LOCK bit */
  3234. hhrtim->Instance->sCommonRegs.FLTINR1 = (hrtim_fltinr1 & (~(HRTIM_FLTINR1_FLTxLCK)));
  3235. hhrtim->Instance->sCommonRegs.FLTINR2 = (hrtim_fltinr2 & (~(HRTIM_FLTINR2_FLTxLCK)));
  3236. /* Update the HRTIM registers LOCK bit */
  3237. SET_BIT(hhrtim->Instance->sCommonRegs.FLTINR1,(hrtim_fltinr1 & HRTIM_FLTINR1_FLTxLCK));
  3238. SET_BIT(hhrtim->Instance->sCommonRegs.FLTINR2,(hrtim_fltinr2 & HRTIM_FLTINR2_FLTxLCK));
  3239. hhrtim->State = HAL_HRTIM_STATE_READY;
  3240. /* Process Unlocked */
  3241. __HAL_UNLOCK(hhrtim);
  3242. return HAL_OK;
  3243. }
  3244. /**
  3245. * @brief Configure the fault conditioning block prescaler
  3246. * @param hhrtim pointer to HAL HRTIM handle
  3247. * @param Prescaler Prescaler value
  3248. * This parameter can be one of the following values:
  3249. * @arg HRTIM_FAULTPRESCALER_DIV1: fFLTS=fHRTIM
  3250. * @arg HRTIM_FAULTPRESCALER_DIV2: fFLTS=fHRTIM / 2
  3251. * @arg HRTIM_FAULTPRESCALER_DIV4: fFLTS=fHRTIM / 4
  3252. * @arg HRTIM_FAULTPRESCALER_DIV8: fFLTS=fHRTIM / 8
  3253. * @retval HAL status
  3254. * @note This function must be called before starting the timer and before
  3255. * enabling faults inputs
  3256. */
  3257. HAL_StatusTypeDef HAL_HRTIM_FaultPrescalerConfig(HRTIM_HandleTypeDef * hhrtim,
  3258. uint32_t Prescaler)
  3259. {
  3260. /* Check parameters */
  3261. assert_param(IS_HRTIM_FAULTPRESCALER(Prescaler));
  3262. if(hhrtim->State == HAL_HRTIM_STATE_BUSY)
  3263. {
  3264. return HAL_BUSY;
  3265. }
  3266. /* Process Locked */
  3267. __HAL_LOCK(hhrtim);
  3268. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  3269. /* Set the external event prescaler */
  3270. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR2, HRTIM_FLTINR2_FLTSD, (Prescaler & HRTIM_FLTINR2_FLTSD));
  3271. hhrtim->State = HAL_HRTIM_STATE_READY;
  3272. /* Process Unlocked */
  3273. __HAL_UNLOCK(hhrtim);
  3274. return HAL_OK;
  3275. }
  3276. /**
  3277. * @brief Enable or disables the HRTIMx Fault mode.
  3278. * @param hhrtim pointer to HAL HRTIM handle
  3279. * @param Faults fault input(s) to enable or disable
  3280. * This parameter can be any combination of the following values:
  3281. * @arg HRTIM_FAULT_1: Fault input 1
  3282. * @arg HRTIM_FAULT_2: Fault input 2
  3283. * @arg HRTIM_FAULT_3: Fault input 3
  3284. * @arg HRTIM_FAULT_4: Fault input 4
  3285. * @arg HRTIM_FAULT_5: Fault input 5
  3286. * @param Enable Fault(s) enabling
  3287. * This parameter can be one of the following values:
  3288. * @arg HRTIM_FAULTMODECTL_ENABLED: Fault(s) enabled
  3289. * @arg HRTIM_FAULTMODECTL_DISABLED: Fault(s) disabled
  3290. * @retval None
  3291. */
  3292. void HAL_HRTIM_FaultModeCtl(HRTIM_HandleTypeDef * hhrtim,
  3293. uint32_t Faults,
  3294. uint32_t Enable)
  3295. {
  3296. /* Check parameters */
  3297. assert_param(IS_HRTIM_FAULT(Faults));
  3298. assert_param(IS_HRTIM_FAULTMODECTL(Enable));
  3299. if ((Faults & HRTIM_FAULT_1) != (uint32_t)RESET)
  3300. {
  3301. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR1, HRTIM_FLTINR1_FLT1E, (Enable & HRTIM_FLTINR1_FLT1E));
  3302. }
  3303. if ((Faults & HRTIM_FAULT_2) != (uint32_t)RESET)
  3304. {
  3305. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR1, HRTIM_FLTINR1_FLT2E, ((Enable << 8U) & HRTIM_FLTINR1_FLT2E));
  3306. }
  3307. if ((Faults & HRTIM_FAULT_3) != (uint32_t)RESET)
  3308. {
  3309. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR1, HRTIM_FLTINR1_FLT3E, ((Enable << 16U) & HRTIM_FLTINR1_FLT3E));
  3310. }
  3311. if ((Faults & HRTIM_FAULT_4) != (uint32_t)RESET)
  3312. {
  3313. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR1, HRTIM_FLTINR1_FLT4E, ((Enable << 24U) & HRTIM_FLTINR1_FLT4E));
  3314. }
  3315. if ((Faults & HRTIM_FAULT_5) != (uint32_t)RESET)
  3316. {
  3317. MODIFY_REG(hhrtim->Instance->sCommonRegs.FLTINR2, HRTIM_FLTINR2_FLT5E, ((Enable) & HRTIM_FLTINR2_FLT5E));
  3318. }
  3319. }
  3320. /**
  3321. * @brief Configure both the ADC trigger register update source and the ADC
  3322. * trigger source.
  3323. * @param hhrtim pointer to HAL HRTIM handle
  3324. * @param ADCTrigger ADC trigger to configure
  3325. * This parameter can be one of the following values:
  3326. * @arg HRTIM_ADCTRIGGER_1: ADC trigger 1
  3327. * @arg HRTIM_ADCTRIGGER_2: ADC trigger 2
  3328. * @arg HRTIM_ADCTRIGGER_3: ADC trigger 3
  3329. * @arg HRTIM_ADCTRIGGER_4: ADC trigger 4
  3330. * @param pADCTriggerCfg pointer to the ADC trigger configuration structure
  3331. * @retval HAL status
  3332. * @note This function must be called before starting the timer
  3333. */
  3334. HAL_StatusTypeDef HAL_HRTIM_ADCTriggerConfig(HRTIM_HandleTypeDef * hhrtim,
  3335. uint32_t ADCTrigger,
  3336. HRTIM_ADCTriggerCfgTypeDef* pADCTriggerCfg)
  3337. {
  3338. uint32_t hrtim_cr1;
  3339. /* Check parameters */
  3340. assert_param(IS_HRTIM_ADCTRIGGER(ADCTrigger));
  3341. assert_param(IS_HRTIM_ADCTRIGGERUPDATE(pADCTriggerCfg->UpdateSource));
  3342. if(hhrtim->State == HAL_HRTIM_STATE_BUSY)
  3343. {
  3344. return HAL_BUSY;
  3345. }
  3346. /* Process Locked */
  3347. __HAL_LOCK(hhrtim);
  3348. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  3349. /* Set the ADC trigger update source */
  3350. hrtim_cr1 = hhrtim->Instance->sCommonRegs.CR1;
  3351. switch (ADCTrigger)
  3352. {
  3353. case HRTIM_ADCTRIGGER_1:
  3354. {
  3355. hrtim_cr1 &= ~(HRTIM_CR1_ADC1USRC);
  3356. hrtim_cr1 |= (pADCTriggerCfg->UpdateSource & HRTIM_CR1_ADC1USRC);
  3357. /* Set the ADC trigger 1 source */
  3358. hhrtim->Instance->sCommonRegs.ADC1R = pADCTriggerCfg->Trigger;
  3359. break;
  3360. }
  3361. case HRTIM_ADCTRIGGER_2:
  3362. {
  3363. hrtim_cr1 &= ~(HRTIM_CR1_ADC2USRC);
  3364. hrtim_cr1 |= ((pADCTriggerCfg->UpdateSource << 3U) & HRTIM_CR1_ADC2USRC);
  3365. /* Set the ADC trigger 2 source */
  3366. hhrtim->Instance->sCommonRegs.ADC2R = pADCTriggerCfg->Trigger;
  3367. break;
  3368. }
  3369. case HRTIM_ADCTRIGGER_3:
  3370. {
  3371. hrtim_cr1 &= ~(HRTIM_CR1_ADC3USRC);
  3372. hrtim_cr1 |= ((pADCTriggerCfg->UpdateSource << 6U) & HRTIM_CR1_ADC3USRC);
  3373. /* Set the ADC trigger 3 source */
  3374. hhrtim->Instance->sCommonRegs.ADC3R = pADCTriggerCfg->Trigger;
  3375. break;
  3376. }
  3377. case HRTIM_ADCTRIGGER_4:
  3378. {
  3379. hrtim_cr1 &= ~(HRTIM_CR1_ADC4USRC);
  3380. hrtim_cr1 |= ((pADCTriggerCfg->UpdateSource << 9U) & HRTIM_CR1_ADC4USRC);
  3381. /* Set the ADC trigger 4 source */
  3382. hhrtim->Instance->sCommonRegs.ADC4R = pADCTriggerCfg->Trigger;
  3383. break;
  3384. }
  3385. default:
  3386. {
  3387. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  3388. /* Process Unlocked */
  3389. __HAL_UNLOCK(hhrtim);
  3390. break;
  3391. }
  3392. }
  3393. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  3394. {
  3395. return HAL_ERROR;
  3396. }
  3397. /* Update the HRTIM registers */
  3398. hhrtim->Instance->sCommonRegs.CR1 = hrtim_cr1;
  3399. hhrtim->State = HAL_HRTIM_STATE_READY;
  3400. /* Process Unlocked */
  3401. __HAL_UNLOCK(hhrtim);
  3402. return HAL_OK;
  3403. }
  3404. /**
  3405. * @}
  3406. */
  3407. /** @defgroup HRTIM_Exported_Functions_Group8 Timer waveform configuration and functions
  3408. * @brief HRTIM timer configuration and control functions
  3409. @verbatim
  3410. ===============================================================================
  3411. ##### HRTIM timer configuration and control functions #####
  3412. ===============================================================================
  3413. [..] This section provides functions used to configure and control a
  3414. HRTIM timer operating in waveform mode:
  3415. (+) Configure HRTIM timer general behavior
  3416. (+) Configure HRTIM timer event filtering
  3417. (+) Configure HRTIM timer deadtime insertion
  3418. (+) Configure HRTIM timer chopper mode
  3419. (+) Configure HRTIM timer burst DMA
  3420. (+) Configure HRTIM timer compare unit
  3421. (+) Configure HRTIM timer capture unit
  3422. (+) Configure HRTIM timer output
  3423. (+) Set HRTIM timer output level
  3424. (+) Enable HRTIM timer output
  3425. (+) Disable HRTIM timer output
  3426. (+) Start HRTIM timer
  3427. (+) Stop HRTIM timer
  3428. (+) Start HRTIM timer and enable interrupt
  3429. (+) Stop HRTIM timer and disable interrupt
  3430. (+) Start HRTIM timer and enable DMA transfer
  3431. (+) Stop HRTIM timer and disable DMA transfer
  3432. (+) Enable or disable the burst mode controller
  3433. (+) Start the burst mode controller (by software)
  3434. (+) Trigger a Capture (by software)
  3435. (+) Update the HRTIM timer preloadable registers (by software)
  3436. (+) Reset the HRTIM timer counter (by software)
  3437. (+) Start a burst DMA transfer
  3438. (+) Enable timer register update
  3439. (+) Disable timer register update
  3440. @endverbatim
  3441. * @{
  3442. */
  3443. /**
  3444. * @brief Configure the general behavior of a timer operating in waveform mode
  3445. * @param hhrtim pointer to HAL HRTIM handle
  3446. * @param TimerIdx Timer index
  3447. * This parameter can be one of the following values:
  3448. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  3449. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  3450. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  3451. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  3452. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  3453. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  3454. * @param pTimerCfg pointer to the timer configuration structure
  3455. * @note When the timer operates in waveform mode, all the features supported by
  3456. * the HRTIM are available without any limitation.
  3457. * @retval HAL status
  3458. * @note This function must be called before starting the timer
  3459. */
  3460. HAL_StatusTypeDef HAL_HRTIM_WaveformTimerConfig(HRTIM_HandleTypeDef * hhrtim,
  3461. uint32_t TimerIdx,
  3462. HRTIM_TimerCfgTypeDef * pTimerCfg)
  3463. {
  3464. /* Check parameters */
  3465. assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
  3466. /* Relevant for all HRTIM timers, including the master */
  3467. assert_param(IS_HRTIM_HALFMODE(pTimerCfg->HalfModeEnable));
  3468. assert_param(IS_HRTIM_SYNCSTART(pTimerCfg->StartOnSync));
  3469. assert_param(IS_HRTIM_SYNCRESET(pTimerCfg->ResetOnSync));
  3470. assert_param(IS_HRTIM_DACSYNC(pTimerCfg->DACSynchro));
  3471. assert_param(IS_HRTIM_PRELOAD(pTimerCfg->PreloadEnable));
  3472. assert_param(IS_HRTIM_TIMERBURSTMODE(pTimerCfg->BurstMode));
  3473. assert_param(IS_HRTIM_UPDATEONREPETITION(pTimerCfg->RepetitionUpdate));
  3474. if(hhrtim->State == HAL_HRTIM_STATE_BUSY)
  3475. {
  3476. return HAL_BUSY;
  3477. }
  3478. /* Process Locked */
  3479. __HAL_LOCK(hhrtim);
  3480. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  3481. if (TimerIdx == HRTIM_TIMERINDEX_MASTER)
  3482. {
  3483. /* Check parameters */
  3484. assert_param(IS_HRTIM_UPDATEGATING_MASTER(pTimerCfg->UpdateGating));
  3485. assert_param(IS_HRTIM_MASTER_IT(pTimerCfg->InterruptRequests));
  3486. assert_param(IS_HRTIM_MASTER_DMA(pTimerCfg->DMARequests));
  3487. /* Configure master timer */
  3488. HRTIM_MasterWaveform_Config(hhrtim, pTimerCfg);
  3489. }
  3490. else
  3491. {
  3492. /* Check parameters */
  3493. assert_param(IS_HRTIM_UPDATEGATING_TIM(pTimerCfg->UpdateGating));
  3494. assert_param(IS_HRTIM_TIM_IT(pTimerCfg->InterruptRequests));
  3495. assert_param(IS_HRTIM_TIM_DMA(pTimerCfg->DMARequests));
  3496. assert_param(IS_HRTIM_TIMPUSHPULLMODE(pTimerCfg->PushPull));
  3497. assert_param(IS_HRTIM_TIMFAULTENABLE(pTimerCfg->FaultEnable));
  3498. assert_param(IS_HRTIM_TIMFAULTLOCK(pTimerCfg->FaultLock));
  3499. assert_param(IS_HRTIM_TIMDEADTIMEINSERTION(pTimerCfg->PushPull,
  3500. pTimerCfg->DeadTimeInsertion));
  3501. assert_param(IS_HRTIM_TIMDELAYEDPROTECTION(pTimerCfg->PushPull,
  3502. pTimerCfg->DelayedProtectionMode));
  3503. assert_param(IS_HRTIM_TIMUPDATETRIGGER(pTimerCfg->UpdateTrigger));
  3504. assert_param(IS_HRTIM_TIMRESETTRIGGER(pTimerCfg->ResetTrigger));
  3505. assert_param(IS_HRTIM_TIMUPDATEONRESET(pTimerCfg->ResetUpdate));
  3506. /* Configure timing unit */
  3507. HRTIM_TimingUnitWaveform_Config(hhrtim, TimerIdx, pTimerCfg);
  3508. }
  3509. /* Update timer parameters */
  3510. hhrtim->TimerParam[TimerIdx].InterruptRequests = pTimerCfg->InterruptRequests;
  3511. hhrtim->TimerParam[TimerIdx].DMARequests = pTimerCfg->DMARequests;
  3512. hhrtim->TimerParam[TimerIdx].DMASrcAddress = pTimerCfg->DMASrcAddress;
  3513. hhrtim->TimerParam[TimerIdx].DMADstAddress = pTimerCfg->DMADstAddress;
  3514. hhrtim->TimerParam[TimerIdx].DMASize = pTimerCfg->DMASize;
  3515. /* Force a software update */
  3516. HRTIM_ForceRegistersUpdate(hhrtim, TimerIdx);
  3517. hhrtim->State = HAL_HRTIM_STATE_READY;
  3518. /* Process Unlocked */
  3519. __HAL_UNLOCK(hhrtim);
  3520. return HAL_OK;
  3521. }
  3522. /**
  3523. * @brief Configure the event filtering capabilities of a timer (blanking, windowing)
  3524. * @param hhrtim pointer to HAL HRTIM handle
  3525. * @param TimerIdx Timer index
  3526. * This parameter can be one of the following values:
  3527. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  3528. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  3529. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  3530. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  3531. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  3532. * @param Event external event for which timer event filtering must be configured
  3533. * This parameter can be one of the following values:
  3534. * @arg HRTIM_EVENT_1: External event 1
  3535. * @arg HRTIM_EVENT_2: External event 2
  3536. * @arg HRTIM_EVENT_3: External event 3
  3537. * @arg HRTIM_EVENT_4: External event 4
  3538. * @arg HRTIM_EVENT_5: External event 5
  3539. * @arg HRTIM_EVENT_6: External event 6
  3540. * @arg HRTIM_EVENT_7: External event 7
  3541. * @arg HRTIM_EVENT_8: External event 8
  3542. * @arg HRTIM_EVENT_9: External event 9
  3543. * @arg HRTIM_EVENT_10: External event 10
  3544. * @param pTimerEventFilteringCfg pointer to the timer event filtering configuration structure
  3545. * @note This function must be called before starting the timer
  3546. * @retval HAL status
  3547. */
  3548. HAL_StatusTypeDef HAL_HRTIM_TimerEventFilteringConfig(HRTIM_HandleTypeDef * hhrtim,
  3549. uint32_t TimerIdx,
  3550. uint32_t Event,
  3551. HRTIM_TimerEventFilteringCfgTypeDef* pTimerEventFilteringCfg)
  3552. {
  3553. /* Check parameters */
  3554. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  3555. assert_param(IS_HRTIM_EVENT(Event));
  3556. assert_param(IS_HRTIM_TIMEVENTFILTER(pTimerEventFilteringCfg->Filter));
  3557. assert_param(IS_HRTIM_TIMEVENTLATCH(pTimerEventFilteringCfg->Latch));
  3558. if(hhrtim->State == HAL_HRTIM_STATE_BUSY)
  3559. {
  3560. return HAL_BUSY;
  3561. }
  3562. /* Process Locked */
  3563. __HAL_LOCK(hhrtim);
  3564. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  3565. /* Configure timer event filtering capabilities */
  3566. switch (Event)
  3567. {
  3568. case HRTIM_EVENT_NONE:
  3569. {
  3570. CLEAR_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR1);
  3571. CLEAR_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR2);
  3572. break;
  3573. }
  3574. case HRTIM_EVENT_1:
  3575. {
  3576. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR1, (HRTIM_EEFR1_EE1FLTR | HRTIM_EEFR1_EE1LTCH), (pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch));
  3577. break;
  3578. }
  3579. case HRTIM_EVENT_2:
  3580. {
  3581. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR1, (HRTIM_EEFR1_EE2FLTR | HRTIM_EEFR1_EE2LTCH), ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 6U) );
  3582. break;
  3583. }
  3584. case HRTIM_EVENT_3:
  3585. {
  3586. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR1, (HRTIM_EEFR1_EE3FLTR | HRTIM_EEFR1_EE3LTCH), ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 12U) );
  3587. break;
  3588. }
  3589. case HRTIM_EVENT_4:
  3590. {
  3591. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR1, (HRTIM_EEFR1_EE4FLTR | HRTIM_EEFR1_EE4LTCH), ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 18U) );
  3592. break;
  3593. }
  3594. case HRTIM_EVENT_5:
  3595. {
  3596. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR1, (HRTIM_EEFR1_EE5FLTR | HRTIM_EEFR1_EE5LTCH), ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 24U) );
  3597. break;
  3598. }
  3599. case HRTIM_EVENT_6:
  3600. {
  3601. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR2, (HRTIM_EEFR2_EE6FLTR | HRTIM_EEFR2_EE6LTCH), (pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) );
  3602. break;
  3603. }
  3604. case HRTIM_EVENT_7:
  3605. {
  3606. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR2, (HRTIM_EEFR2_EE7FLTR | HRTIM_EEFR2_EE7LTCH), ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 6U) );
  3607. break;
  3608. }
  3609. case HRTIM_EVENT_8:
  3610. {
  3611. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR2, (HRTIM_EEFR2_EE8FLTR | HRTIM_EEFR2_EE8LTCH), ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 12U) );
  3612. break;
  3613. }
  3614. case HRTIM_EVENT_9:
  3615. {
  3616. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR2, (HRTIM_EEFR2_EE9FLTR | HRTIM_EEFR2_EE9LTCH), ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 18U) );
  3617. break;
  3618. }
  3619. case HRTIM_EVENT_10:
  3620. {
  3621. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].EEFxR2, (HRTIM_EEFR2_EE10FLTR | HRTIM_EEFR2_EE10LTCH), ((pTimerEventFilteringCfg->Filter | pTimerEventFilteringCfg->Latch) << 24U) );
  3622. break;
  3623. }
  3624. default:
  3625. {
  3626. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  3627. /* Process Unlocked */
  3628. __HAL_UNLOCK(hhrtim);
  3629. break;
  3630. }
  3631. }
  3632. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  3633. {
  3634. return HAL_ERROR;
  3635. }
  3636. hhrtim->State = HAL_HRTIM_STATE_READY;
  3637. /* Process Unlocked */
  3638. __HAL_UNLOCK(hhrtim);
  3639. return HAL_OK;
  3640. }
  3641. /**
  3642. * @brief Configure the dead-time insertion feature for a timer
  3643. * @param hhrtim pointer to HAL HRTIM handle
  3644. * @param TimerIdx Timer index
  3645. * This parameter can be one of the following values:
  3646. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  3647. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  3648. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  3649. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  3650. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  3651. * @param pDeadTimeCfg pointer to the deadtime insertion configuration structure
  3652. * @retval HAL status
  3653. * @note This function must be called before starting the timer
  3654. */
  3655. HAL_StatusTypeDef HAL_HRTIM_DeadTimeConfig(HRTIM_HandleTypeDef * hhrtim,
  3656. uint32_t TimerIdx,
  3657. HRTIM_DeadTimeCfgTypeDef* pDeadTimeCfg)
  3658. {
  3659. uint32_t hrtim_dtr;
  3660. /* Check parameters */
  3661. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  3662. assert_param(IS_HRTIM_TIMDEADTIME_PRESCALERRATIO(pDeadTimeCfg->Prescaler));
  3663. assert_param(IS_HRTIM_TIMDEADTIME_RISINGSIGN(pDeadTimeCfg->RisingSign));
  3664. assert_param(IS_HRTIM_TIMDEADTIME_RISINGLOCK(pDeadTimeCfg->RisingLock));
  3665. assert_param(IS_HRTIM_TIMDEADTIME_RISINGSIGNLOCK(pDeadTimeCfg->RisingSignLock));
  3666. assert_param(IS_HRTIM_TIMDEADTIME_FALLINGSIGN(pDeadTimeCfg->FallingSign));
  3667. assert_param(IS_HRTIM_TIMDEADTIME_FALLINGLOCK(pDeadTimeCfg->FallingLock));
  3668. assert_param(IS_HRTIM_TIMDEADTIME_FALLINGSIGNLOCK(pDeadTimeCfg->FallingSignLock));
  3669. if(hhrtim->State == HAL_HRTIM_STATE_BUSY)
  3670. {
  3671. return HAL_BUSY;
  3672. }
  3673. /* Process Locked */
  3674. __HAL_LOCK(hhrtim);
  3675. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  3676. /* Set timer deadtime configuration */
  3677. hrtim_dtr = (pDeadTimeCfg->Prescaler & HRTIM_DTR_DTPRSC);
  3678. hrtim_dtr |= (pDeadTimeCfg->RisingValue & HRTIM_DTR_DTR);
  3679. hrtim_dtr |= (pDeadTimeCfg->RisingSign & HRTIM_DTR_SDTR);
  3680. hrtim_dtr |= (pDeadTimeCfg->RisingSignLock & HRTIM_DTR_DTRSLK);
  3681. hrtim_dtr |= (pDeadTimeCfg->RisingLock & HRTIM_DTR_DTRLK);
  3682. hrtim_dtr |= ((pDeadTimeCfg->FallingValue << 16U) & HRTIM_DTR_DTF);
  3683. hrtim_dtr |= (pDeadTimeCfg->FallingSign & HRTIM_DTR_SDTF);
  3684. hrtim_dtr |= (pDeadTimeCfg->FallingSignLock & HRTIM_DTR_DTFSLK);
  3685. hrtim_dtr |= (pDeadTimeCfg->FallingLock & HRTIM_DTR_DTFLK);
  3686. /* Update the HRTIM registers */
  3687. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].DTxR, (
  3688. HRTIM_DTR_DTR | HRTIM_DTR_SDTR | HRTIM_DTR_DTPRSC |
  3689. HRTIM_DTR_DTRSLK | HRTIM_DTR_DTRLK | HRTIM_DTR_DTF |
  3690. HRTIM_DTR_SDTF | HRTIM_DTR_DTFSLK | HRTIM_DTR_DTFLK), hrtim_dtr);
  3691. hhrtim->State = HAL_HRTIM_STATE_READY;
  3692. /* Process Unlocked */
  3693. __HAL_UNLOCK(hhrtim);
  3694. return HAL_OK;
  3695. }
  3696. /**
  3697. * @brief Configure the chopper mode feature for a timer
  3698. * @param hhrtim pointer to HAL HRTIM handle
  3699. * @param TimerIdx Timer index
  3700. * This parameter can be one of the following values:
  3701. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  3702. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  3703. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  3704. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  3705. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  3706. * @param pChopperModeCfg pointer to the chopper mode configuration structure
  3707. * @retval HAL status
  3708. * @note This function must be called before configuring the timer output(s)
  3709. */
  3710. HAL_StatusTypeDef HAL_HRTIM_ChopperModeConfig(HRTIM_HandleTypeDef * hhrtim,
  3711. uint32_t TimerIdx,
  3712. HRTIM_ChopperModeCfgTypeDef* pChopperModeCfg)
  3713. {
  3714. uint32_t hrtim_chpr;
  3715. /* Check parameters */
  3716. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  3717. assert_param(IS_HRTIM_CHOPPER_PRESCALERRATIO(pChopperModeCfg->CarrierFreq));
  3718. assert_param(IS_HRTIM_CHOPPER_DUTYCYCLE(pChopperModeCfg->DutyCycle));
  3719. assert_param(IS_HRTIM_CHOPPER_PULSEWIDTH(pChopperModeCfg->StartPulse));
  3720. if(hhrtim->State == HAL_HRTIM_STATE_BUSY)
  3721. {
  3722. return HAL_BUSY;
  3723. }
  3724. /* Process Locked */
  3725. __HAL_LOCK(hhrtim);
  3726. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  3727. /* Set timer choppe mode configuration */
  3728. hrtim_chpr = (pChopperModeCfg->CarrierFreq & HRTIM_CHPR_CARFRQ);
  3729. hrtim_chpr |= (pChopperModeCfg->DutyCycle & HRTIM_CHPR_CARDTY);
  3730. hrtim_chpr |= (pChopperModeCfg->StartPulse & HRTIM_CHPR_STRPW);
  3731. /* Update the HRTIM registers */
  3732. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].CHPxR, (HRTIM_CHPR_CARFRQ | HRTIM_CHPR_CARDTY |
  3733. HRTIM_CHPR_STRPW) ,
  3734. hrtim_chpr);
  3735. hhrtim->State = HAL_HRTIM_STATE_READY;
  3736. /* Process Unlocked */
  3737. __HAL_UNLOCK(hhrtim);
  3738. return HAL_OK;
  3739. }
  3740. /**
  3741. * @brief Configure the burst DMA controller for a timer
  3742. * @param hhrtim pointer to HAL HRTIM handle
  3743. * @param TimerIdx Timer index
  3744. * This parameter can be one of the following values:
  3745. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  3746. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  3747. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  3748. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  3749. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  3750. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  3751. * @param RegistersToUpdate registers to be written by DMA
  3752. * This parameter can be any combination of the following values:
  3753. * @arg HRTIM_BURSTDMA_CR: HRTIM_MCR or HRTIM_TIMxCR
  3754. * @arg HRTIM_BURSTDMA_ICR: HRTIM_MICR or HRTIM_TIMxICR
  3755. * @arg HRTIM_BURSTDMA_DIER: HRTIM_MDIER or HRTIM_TIMxDIER
  3756. * @arg HRTIM_BURSTDMA_CNT: HRTIM_MCNT or HRTIM_TIMxCNT
  3757. * @arg HRTIM_BURSTDMA_PER: HRTIM_MPER or HRTIM_TIMxPER
  3758. * @arg HRTIM_BURSTDMA_REP: HRTIM_MREP or HRTIM_TIMxREP
  3759. * @arg HRTIM_BURSTDMA_CMP1: HRTIM_MCMP1 or HRTIM_TIMxCMP1
  3760. * @arg HRTIM_BURSTDMA_CMP2: HRTIM_MCMP2 or HRTIM_TIMxCMP2
  3761. * @arg HRTIM_BURSTDMA_CMP3: HRTIM_MCMP3 or HRTIM_TIMxCMP3
  3762. * @arg HRTIM_BURSTDMA_CMP4: HRTIM_MCMP4 or HRTIM_TIMxCMP4
  3763. * @arg HRTIM_BURSTDMA_DTR: HRTIM_TIMxDTR
  3764. * @arg HRTIM_BURSTDMA_SET1R: HRTIM_TIMxSET1R
  3765. * @arg HRTIM_BURSTDMA_RST1R: HRTIM_TIMxRST1R
  3766. * @arg HRTIM_BURSTDMA_SET2R: HRTIM_TIMxSET2R
  3767. * @arg HRTIM_BURSTDMA_RST2R: HRTIM_TIMxRST2R
  3768. * @arg HRTIM_BURSTDMA_EEFR1: HRTIM_TIMxEEFR1
  3769. * @arg HRTIM_BURSTDMA_EEFR2: HRTIM_TIMxEEFR2
  3770. * @arg HRTIM_BURSTDMA_RSTR: HRTIM_TIMxRSTR
  3771. * @arg HRTIM_BURSTDMA_CHPR: HRTIM_TIMxCHPR
  3772. * @arg HRTIM_BURSTDMA_OUTR: HRTIM_TIMxOUTR
  3773. * @arg HRTIM_BURSTDMA_FLTR: HRTIM_TIMxFLTR
  3774. * @retval HAL status
  3775. * @note This function must be called before starting the timer
  3776. */
  3777. HAL_StatusTypeDef HAL_HRTIM_BurstDMAConfig(HRTIM_HandleTypeDef * hhrtim,
  3778. uint32_t TimerIdx,
  3779. uint32_t RegistersToUpdate)
  3780. {
  3781. /* Check parameters */
  3782. assert_param(IS_HRTIM_TIMER_BURSTDMA(TimerIdx, RegistersToUpdate));
  3783. if(hhrtim->State == HAL_HRTIM_STATE_BUSY)
  3784. {
  3785. return HAL_BUSY;
  3786. }
  3787. /* Process Locked */
  3788. __HAL_LOCK(hhrtim);
  3789. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  3790. /* Set the burst DMA timer update register */
  3791. switch (TimerIdx)
  3792. {
  3793. case HRTIM_TIMERINDEX_TIMER_A:
  3794. {
  3795. hhrtim->Instance->sCommonRegs.BDTAUPR = RegistersToUpdate;
  3796. break;
  3797. }
  3798. case HRTIM_TIMERINDEX_TIMER_B:
  3799. {
  3800. hhrtim->Instance->sCommonRegs.BDTBUPR = RegistersToUpdate;
  3801. break;
  3802. }
  3803. case HRTIM_TIMERINDEX_TIMER_C:
  3804. {
  3805. hhrtim->Instance->sCommonRegs.BDTCUPR = RegistersToUpdate;
  3806. break;
  3807. }
  3808. case HRTIM_TIMERINDEX_TIMER_D:
  3809. {
  3810. hhrtim->Instance->sCommonRegs.BDTDUPR = RegistersToUpdate;
  3811. break;
  3812. }
  3813. case HRTIM_TIMERINDEX_TIMER_E:
  3814. {
  3815. hhrtim->Instance->sCommonRegs.BDTEUPR = RegistersToUpdate;
  3816. break;
  3817. }
  3818. case HRTIM_TIMERINDEX_MASTER:
  3819. {
  3820. hhrtim->Instance->sCommonRegs.BDMUPR = RegistersToUpdate;
  3821. break;
  3822. }
  3823. default:
  3824. {
  3825. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  3826. /* Process Unlocked */
  3827. __HAL_UNLOCK(hhrtim);
  3828. break;
  3829. }
  3830. }
  3831. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  3832. {
  3833. return HAL_ERROR;
  3834. }
  3835. hhrtim->State = HAL_HRTIM_STATE_READY;
  3836. /* Process Unlocked */
  3837. __HAL_UNLOCK(hhrtim);
  3838. return HAL_OK;
  3839. }
  3840. /**
  3841. * @brief Configure the compare unit of a timer operating in waveform mode
  3842. * @param hhrtim pointer to HAL HRTIM handle
  3843. * @param TimerIdx Timer index
  3844. * This parameter can be one of the following values:
  3845. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  3846. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  3847. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  3848. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  3849. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  3850. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  3851. * @param CompareUnit Compare unit to configure
  3852. * This parameter can be one of the following values:
  3853. * @arg HRTIM_COMPAREUNIT_1: Compare unit 1
  3854. * @arg HRTIM_COMPAREUNIT_2: Compare unit 2
  3855. * @arg HRTIM_COMPAREUNIT_3: Compare unit 3
  3856. * @arg HRTIM_COMPAREUNIT_4: Compare unit 4
  3857. * @param pCompareCfg pointer to the compare unit configuration structure
  3858. * @note When auto delayed mode is required for compare unit 2 or compare unit 4,
  3859. * application has to configure separately the capture unit. Capture unit
  3860. * to configure in that case depends on the compare unit auto delayed mode
  3861. * is applied to (see below):
  3862. * Auto delayed on output compare 2: capture unit 1 must be configured
  3863. * Auto delayed on output compare 4: capture unit 2 must be configured
  3864. * @retval HAL status
  3865. * @note This function must be called before starting the timer
  3866. */
  3867. HAL_StatusTypeDef HAL_HRTIM_WaveformCompareConfig(HRTIM_HandleTypeDef * hhrtim,
  3868. uint32_t TimerIdx,
  3869. uint32_t CompareUnit,
  3870. HRTIM_CompareCfgTypeDef* pCompareCfg)
  3871. {
  3872. /* Check parameters */
  3873. assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
  3874. if(hhrtim->State == HAL_HRTIM_STATE_BUSY)
  3875. {
  3876. return HAL_BUSY;
  3877. }
  3878. /* Process Locked */
  3879. __HAL_LOCK(hhrtim);
  3880. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  3881. /* Configure the compare unit */
  3882. if (TimerIdx == HRTIM_TIMERINDEX_MASTER)
  3883. {
  3884. switch (CompareUnit)
  3885. {
  3886. case HRTIM_COMPAREUNIT_1:
  3887. {
  3888. hhrtim->Instance->sMasterRegs.MCMP1R = pCompareCfg->CompareValue;
  3889. break;
  3890. }
  3891. case HRTIM_COMPAREUNIT_2:
  3892. {
  3893. hhrtim->Instance->sMasterRegs.MCMP2R = pCompareCfg->CompareValue;
  3894. break;
  3895. }
  3896. case HRTIM_COMPAREUNIT_3:
  3897. {
  3898. hhrtim->Instance->sMasterRegs.MCMP3R = pCompareCfg->CompareValue;
  3899. break;
  3900. }
  3901. case HRTIM_COMPAREUNIT_4:
  3902. {
  3903. hhrtim->Instance->sMasterRegs.MCMP4R = pCompareCfg->CompareValue;
  3904. break;
  3905. }
  3906. default:
  3907. {
  3908. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  3909. /* Process Unlocked */
  3910. __HAL_UNLOCK(hhrtim);
  3911. break;
  3912. }
  3913. }
  3914. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  3915. {
  3916. return HAL_ERROR;
  3917. }
  3918. }
  3919. else
  3920. {
  3921. switch (CompareUnit)
  3922. {
  3923. case HRTIM_COMPAREUNIT_1:
  3924. {
  3925. /* Set the compare value */
  3926. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP1xR = pCompareCfg->CompareValue;
  3927. break;
  3928. }
  3929. case HRTIM_COMPAREUNIT_2:
  3930. {
  3931. /* Check parameters */
  3932. assert_param(IS_HRTIM_COMPAREUNIT_AUTODELAYEDMODE(CompareUnit, pCompareCfg->AutoDelayedMode));
  3933. /* Set the compare value */
  3934. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP2xR = pCompareCfg->CompareValue;
  3935. if (pCompareCfg->AutoDelayedMode != HRTIM_AUTODELAYEDMODE_REGULAR)
  3936. {
  3937. /* Configure auto-delayed mode */
  3938. /* DELCMP2 bitfield must be reset when reprogrammed from one value */
  3939. /* to the other to reinitialize properly the auto-delayed mechanism */
  3940. hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR &= ~HRTIM_TIMCR_DELCMP2;
  3941. hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR |= pCompareCfg->AutoDelayedMode;
  3942. /* Set the compare value for timeout compare unit (if any) */
  3943. if (pCompareCfg->AutoDelayedMode == HRTIM_AUTODELAYEDMODE_AUTODELAYED_TIMEOUTCMP1)
  3944. {
  3945. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP1xR = pCompareCfg->AutoDelayedTimeout;
  3946. }
  3947. else if (pCompareCfg->AutoDelayedMode == HRTIM_AUTODELAYEDMODE_AUTODELAYED_TIMEOUTCMP3)
  3948. {
  3949. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP3xR = pCompareCfg->AutoDelayedTimeout;
  3950. }
  3951. else
  3952. {
  3953. /* nothing to do */
  3954. }
  3955. }
  3956. else
  3957. {
  3958. /* Clear HRTIM_TIMxCR.DELCMP2 bitfield */
  3959. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR, HRTIM_TIMCR_DELCMP2, 0U);
  3960. }
  3961. break;
  3962. }
  3963. case HRTIM_COMPAREUNIT_3:
  3964. {
  3965. /* Set the compare value */
  3966. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP3xR = pCompareCfg->CompareValue;
  3967. break;
  3968. }
  3969. case HRTIM_COMPAREUNIT_4:
  3970. {
  3971. /* Check parameters */
  3972. assert_param(IS_HRTIM_COMPAREUNIT_AUTODELAYEDMODE(CompareUnit, pCompareCfg->AutoDelayedMode));
  3973. /* Set the compare value */
  3974. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP4xR = pCompareCfg->CompareValue;
  3975. if (pCompareCfg->AutoDelayedMode != HRTIM_AUTODELAYEDMODE_REGULAR)
  3976. {
  3977. /* Configure auto-delayed mode */
  3978. /* DELCMP4 bitfield must be reset when reprogrammed from one value */
  3979. /* to the other to reinitialize properly the auto-delayed mechanism */
  3980. hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR &= ~HRTIM_TIMCR_DELCMP4;
  3981. hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR |= (pCompareCfg->AutoDelayedMode << 2U);
  3982. /* Set the compare value for timeout compare unit (if any) */
  3983. if (pCompareCfg->AutoDelayedMode == HRTIM_AUTODELAYEDMODE_AUTODELAYED_TIMEOUTCMP1)
  3984. {
  3985. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP1xR = pCompareCfg->AutoDelayedTimeout;
  3986. }
  3987. else if (pCompareCfg->AutoDelayedMode == HRTIM_AUTODELAYEDMODE_AUTODELAYED_TIMEOUTCMP3)
  3988. {
  3989. hhrtim->Instance->sTimerxRegs[TimerIdx].CMP3xR = pCompareCfg->AutoDelayedTimeout;
  3990. }
  3991. else
  3992. {
  3993. /* nothing to do */
  3994. }
  3995. }
  3996. else
  3997. {
  3998. /* Clear HRTIM_TIMxCR.DELCMP4 bitfield */
  3999. MODIFY_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR, HRTIM_TIMCR_DELCMP4, 0U);
  4000. }
  4001. break;
  4002. }
  4003. default:
  4004. {
  4005. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  4006. /* Process Unlocked */
  4007. __HAL_UNLOCK(hhrtim);
  4008. break;
  4009. }
  4010. }
  4011. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  4012. {
  4013. return HAL_ERROR;
  4014. }
  4015. }
  4016. hhrtim->State = HAL_HRTIM_STATE_READY;
  4017. /* Process Unlocked */
  4018. __HAL_UNLOCK(hhrtim);
  4019. return HAL_OK;
  4020. }
  4021. /**
  4022. * @brief Configure the capture unit of a timer operating in waveform mode
  4023. * @param hhrtim pointer to HAL HRTIM handle
  4024. * @param TimerIdx Timer index
  4025. * This parameter can be one of the following values:
  4026. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  4027. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  4028. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  4029. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  4030. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  4031. * @param CaptureUnit Capture unit to configure
  4032. * This parameter can be one of the following values:
  4033. * @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  4034. * @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  4035. * @param pCaptureCfg pointer to the compare unit configuration structure
  4036. * @retval HAL status
  4037. * @note This function must be called before starting the timer
  4038. */
  4039. HAL_StatusTypeDef HAL_HRTIM_WaveformCaptureConfig(HRTIM_HandleTypeDef * hhrtim,
  4040. uint32_t TimerIdx,
  4041. uint32_t CaptureUnit,
  4042. HRTIM_CaptureCfgTypeDef* pCaptureCfg)
  4043. {
  4044. /* Check parameters */
  4045. assert_param(IS_HRTIM_TIMER_CAPTURETRIGGER(TimerIdx, pCaptureCfg->Trigger));
  4046. if(hhrtim->State == HAL_HRTIM_STATE_BUSY)
  4047. {
  4048. return HAL_BUSY;
  4049. }
  4050. /* Process Locked */
  4051. __HAL_LOCK(hhrtim);
  4052. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4053. /* Configure the capture unit */
  4054. switch (CaptureUnit)
  4055. {
  4056. case HRTIM_CAPTUREUNIT_1:
  4057. {
  4058. WRITE_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].CPT1xCR, pCaptureCfg->Trigger);
  4059. break;
  4060. }
  4061. case HRTIM_CAPTUREUNIT_2:
  4062. {
  4063. WRITE_REG(hhrtim->Instance->sTimerxRegs[TimerIdx].CPT2xCR, pCaptureCfg->Trigger);
  4064. break;
  4065. }
  4066. default:
  4067. {
  4068. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  4069. /* Process Unlocked */
  4070. __HAL_UNLOCK(hhrtim);
  4071. break;
  4072. }
  4073. }
  4074. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  4075. {
  4076. return HAL_ERROR;
  4077. }
  4078. hhrtim->State = HAL_HRTIM_STATE_READY;
  4079. /* Process Unlocked */
  4080. __HAL_UNLOCK(hhrtim);
  4081. return HAL_OK;
  4082. }
  4083. /**
  4084. * @brief Configure the output of a timer operating in waveform mode
  4085. * @param hhrtim pointer to HAL HRTIM handle
  4086. * @param TimerIdx Timer index
  4087. * This parameter can be one of the following values:
  4088. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  4089. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  4090. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  4091. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  4092. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  4093. * @param Output Timer output
  4094. * This parameter can be one of the following values:
  4095. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  4096. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  4097. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  4098. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  4099. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  4100. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  4101. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  4102. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  4103. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  4104. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  4105. * @param pOutputCfg pointer to the timer output configuration structure
  4106. * @retval HAL status
  4107. * @note This function must be called before configuring the timer and after
  4108. * configuring the deadtime insertion feature (if required).
  4109. */
  4110. HAL_StatusTypeDef HAL_HRTIM_WaveformOutputConfig(HRTIM_HandleTypeDef * hhrtim,
  4111. uint32_t TimerIdx,
  4112. uint32_t Output,
  4113. HRTIM_OutputCfgTypeDef * pOutputCfg)
  4114. {
  4115. /* Check parameters */
  4116. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, Output));
  4117. assert_param(IS_HRTIM_OUTPUTPOLARITY(pOutputCfg->Polarity));
  4118. assert_param(IS_HRTIM_OUTPUTIDLELEVEL(pOutputCfg->IdleLevel));
  4119. assert_param(IS_HRTIM_OUTPUTIDLEMODE(pOutputCfg->IdleMode));
  4120. assert_param(IS_HRTIM_OUTPUTFAULTLEVEL(pOutputCfg->FaultLevel));
  4121. assert_param(IS_HRTIM_OUTPUTCHOPPERMODE(pOutputCfg->ChopperModeEnable));
  4122. assert_param(IS_HRTIM_OUTPUTBURSTMODEENTRY(pOutputCfg->BurstModeEntryDelayed));
  4123. if(hhrtim->State == HAL_HRTIM_STATE_BUSY)
  4124. {
  4125. return HAL_BUSY;
  4126. }
  4127. /* Process Locked */
  4128. __HAL_LOCK(hhrtim);
  4129. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4130. /* Configure the timer output */
  4131. HRTIM_OutputConfig(hhrtim,
  4132. TimerIdx,
  4133. Output,
  4134. pOutputCfg);
  4135. hhrtim->State = HAL_HRTIM_STATE_READY;
  4136. /* Process Unlocked */
  4137. __HAL_UNLOCK(hhrtim);
  4138. return HAL_OK;
  4139. }
  4140. /**
  4141. * @brief Force the timer output to its active or inactive state
  4142. * @param hhrtim pointer to HAL HRTIM handle
  4143. * @param TimerIdx Timer index
  4144. * This parameter can be one of the following values:
  4145. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  4146. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  4147. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  4148. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  4149. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  4150. * @param Output Timer output
  4151. * This parameter can be one of the following values:
  4152. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  4153. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  4154. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  4155. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  4156. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  4157. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  4158. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  4159. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  4160. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  4161. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  4162. * @param OutputLevel indicates whether the output is forced to its active or inactive level
  4163. * This parameter can be one of the following values:
  4164. * @arg HRTIM_OUTPUTLEVEL_ACTIVE: output is forced to its active level
  4165. * @arg HRTIM_OUTPUTLEVEL_INACTIVE: output is forced to its inactive level
  4166. * @retval HAL status
  4167. * @note The 'software set/reset trigger' bit in the output set/reset registers
  4168. * is automatically reset by hardware
  4169. */
  4170. HAL_StatusTypeDef HAL_HRTIM_WaveformSetOutputLevel(HRTIM_HandleTypeDef * hhrtim,
  4171. uint32_t TimerIdx,
  4172. uint32_t Output,
  4173. uint32_t OutputLevel)
  4174. {
  4175. /* Check parameters */
  4176. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, Output));
  4177. assert_param(IS_HRTIM_OUTPUTLEVEL(OutputLevel));
  4178. if(hhrtim->State == HAL_HRTIM_STATE_BUSY)
  4179. {
  4180. return HAL_BUSY;
  4181. }
  4182. /* Process Locked */
  4183. __HAL_LOCK(hhrtim);
  4184. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4185. /* Force timer output level */
  4186. switch (Output)
  4187. {
  4188. case HRTIM_OUTPUT_TA1:
  4189. case HRTIM_OUTPUT_TB1:
  4190. case HRTIM_OUTPUT_TC1:
  4191. case HRTIM_OUTPUT_TD1:
  4192. case HRTIM_OUTPUT_TE1:
  4193. {
  4194. if (OutputLevel == HRTIM_OUTPUTLEVEL_ACTIVE)
  4195. {
  4196. /* Force output to its active state */
  4197. SET_BIT(hhrtim->Instance->sTimerxRegs[TimerIdx].SETx1R,HRTIM_SET1R_SST);
  4198. }
  4199. else
  4200. {
  4201. /* Force output to its inactive state */
  4202. SET_BIT(hhrtim->Instance->sTimerxRegs[TimerIdx].RSTx1R, HRTIM_RST1R_SRT);
  4203. }
  4204. break;
  4205. }
  4206. case HRTIM_OUTPUT_TA2:
  4207. case HRTIM_OUTPUT_TB2:
  4208. case HRTIM_OUTPUT_TC2:
  4209. case HRTIM_OUTPUT_TD2:
  4210. case HRTIM_OUTPUT_TE2:
  4211. {
  4212. if (OutputLevel == HRTIM_OUTPUTLEVEL_ACTIVE)
  4213. {
  4214. /* Force output to its active state */
  4215. SET_BIT(hhrtim->Instance->sTimerxRegs[TimerIdx].SETx2R, HRTIM_SET2R_SST);
  4216. }
  4217. else
  4218. {
  4219. /* Force output to its inactive state */
  4220. SET_BIT(hhrtim->Instance->sTimerxRegs[TimerIdx].RSTx2R, HRTIM_RST2R_SRT);
  4221. }
  4222. break;
  4223. }
  4224. default:
  4225. {
  4226. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  4227. /* Process Unlocked */
  4228. __HAL_UNLOCK(hhrtim);
  4229. break;
  4230. }
  4231. }
  4232. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  4233. {
  4234. return HAL_ERROR;
  4235. }
  4236. hhrtim->State = HAL_HRTIM_STATE_READY;
  4237. /* Process Unlocked */
  4238. __HAL_UNLOCK(hhrtim);
  4239. return HAL_OK;
  4240. }
  4241. /**
  4242. * @brief Enable the generation of the waveform signal on the designated output(s)
  4243. * Outputs can be combined (ORed) to allow for simultaneous output enabling.
  4244. * @param hhrtim pointer to HAL HRTIM handle
  4245. * @param OutputsToStart Timer output(s) to enable
  4246. * This parameter can be any combination of the following values:
  4247. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  4248. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  4249. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  4250. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  4251. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  4252. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  4253. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  4254. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  4255. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  4256. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  4257. * @retval HAL status
  4258. */
  4259. HAL_StatusTypeDef HAL_HRTIM_WaveformOutputStart(HRTIM_HandleTypeDef * hhrtim,
  4260. uint32_t OutputsToStart)
  4261. {
  4262. /* Check the parameters */
  4263. assert_param(IS_HRTIM_OUTPUT(OutputsToStart));
  4264. /* Process Locked */
  4265. __HAL_LOCK(hhrtim);
  4266. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4267. /* Enable the HRTIM outputs */
  4268. hhrtim->Instance->sCommonRegs.OENR |= (OutputsToStart);
  4269. hhrtim->State = HAL_HRTIM_STATE_READY;
  4270. /* Process Unlocked */
  4271. __HAL_UNLOCK(hhrtim);
  4272. return HAL_OK;
  4273. }
  4274. /**
  4275. * @brief Disable the generation of the waveform signal on the designated output(s)
  4276. * Outputs can be combined (ORed) to allow for simultaneous output disabling.
  4277. * @param hhrtim pointer to HAL HRTIM handle
  4278. * @param OutputsToStop Timer output(s) to disable
  4279. * This parameter can be any combination of the following values:
  4280. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  4281. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  4282. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  4283. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  4284. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  4285. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  4286. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  4287. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  4288. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  4289. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  4290. * @retval HAL status
  4291. */
  4292. HAL_StatusTypeDef HAL_HRTIM_WaveformOutputStop(HRTIM_HandleTypeDef * hhrtim,
  4293. uint32_t OutputsToStop)
  4294. {
  4295. /* Check the parameters */
  4296. assert_param(IS_HRTIM_OUTPUT(OutputsToStop));
  4297. /* Process Locked */
  4298. __HAL_LOCK(hhrtim);
  4299. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4300. /* Enable the HRTIM outputs */
  4301. hhrtim->Instance->sCommonRegs.ODISR |= (OutputsToStop);
  4302. hhrtim->State = HAL_HRTIM_STATE_READY;
  4303. /* Process Unlocked */
  4304. __HAL_UNLOCK(hhrtim);
  4305. return HAL_OK;
  4306. }
  4307. /**
  4308. * @brief Start the counter of the designated timer(s) operating in waveform mode
  4309. * Timers can be combined (ORed) to allow for simultaneous counter start.
  4310. * @param hhrtim pointer to HAL HRTIM handle
  4311. * @param Timers Timer counter(s) to start
  4312. * This parameter can be any combination of the following values:
  4313. * @arg HRTIM_TIMERID_MASTER
  4314. * @arg HRTIM_TIMERID_TIMER_A
  4315. * @arg HRTIM_TIMERID_TIMER_B
  4316. * @arg HRTIM_TIMERID_TIMER_C
  4317. * @arg HRTIM_TIMERID_TIMER_D
  4318. * @arg HRTIM_TIMERID_TIMER_E
  4319. * @retval HAL status
  4320. */
  4321. HAL_StatusTypeDef HAL_HRTIM_WaveformCountStart(HRTIM_HandleTypeDef * hhrtim,
  4322. uint32_t Timers)
  4323. {
  4324. /* Check the parameters */
  4325. assert_param(IS_HRTIM_TIMERID(Timers));
  4326. /* Process Locked */
  4327. __HAL_LOCK(hhrtim);
  4328. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4329. /* Enable timer(s) counter */
  4330. hhrtim->Instance->sMasterRegs.MCR |= (Timers);
  4331. hhrtim->State = HAL_HRTIM_STATE_READY;
  4332. /* Process Unlocked */
  4333. __HAL_UNLOCK(hhrtim);
  4334. return HAL_OK;
  4335. }
  4336. /**
  4337. * @brief Stop the counter of the designated timer(s) operating in waveform mode
  4338. * Timers can be combined (ORed) to allow for simultaneous counter stop.
  4339. * @param hhrtim pointer to HAL HRTIM handle
  4340. * @param Timers Timer counter(s) to stop
  4341. * This parameter can be any combination of the following values:
  4342. * @arg HRTIM_TIMERID_MASTER
  4343. * @arg HRTIM_TIMERID_A
  4344. * @arg HRTIM_TIMERID_B
  4345. * @arg HRTIM_TIMERID_C
  4346. * @arg HRTIM_TIMERID_D
  4347. * @arg HRTIM_TIMERID_E
  4348. * @retval HAL status
  4349. * @note The counter of a timer is stopped only if all timer outputs are disabled
  4350. */
  4351. HAL_StatusTypeDef HAL_HRTIM_WaveformCountStop(HRTIM_HandleTypeDef * hhrtim,
  4352. uint32_t Timers)
  4353. {
  4354. /* Check the parameters */
  4355. assert_param(IS_HRTIM_TIMERID(Timers));
  4356. /* Process Locked */
  4357. __HAL_LOCK(hhrtim);
  4358. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4359. /* Disable timer(s) counter */
  4360. hhrtim->Instance->sMasterRegs.MCR &= ~(Timers);
  4361. hhrtim->State = HAL_HRTIM_STATE_READY;
  4362. /* Process Unlocked */
  4363. __HAL_UNLOCK(hhrtim);
  4364. return HAL_OK;
  4365. }
  4366. /**
  4367. * @brief Start the counter of the designated timer(s) operating in waveform mode
  4368. * Timers can be combined (ORed) to allow for simultaneous counter start.
  4369. * @param hhrtim pointer to HAL HRTIM handle
  4370. * @param Timers Timer counter(s) to start
  4371. * This parameter can be any combination of the following values:
  4372. * @arg HRTIM_TIMERID_MASTER
  4373. * @arg HRTIM_TIMERID_A
  4374. * @arg HRTIM_TIMERID_B
  4375. * @arg HRTIM_TIMERID_C
  4376. * @arg HRTIM_TIMERID_D
  4377. * @arg HRTIM_TIMERID_E
  4378. * @note HRTIM interrupts (e.g. faults interrupts) and interrupts related
  4379. * to the timers to start are enabled within this function.
  4380. * Interrupts to enable are selected through HAL_HRTIM_WaveformTimerConfig
  4381. * function.
  4382. * @retval HAL status
  4383. */
  4384. HAL_StatusTypeDef HAL_HRTIM_WaveformCountStart_IT(HRTIM_HandleTypeDef * hhrtim,
  4385. uint32_t Timers)
  4386. {
  4387. uint8_t timer_idx;
  4388. /* Check the parameters */
  4389. assert_param(IS_HRTIM_TIMERID(Timers));
  4390. /* Process Locked */
  4391. __HAL_LOCK(hhrtim);
  4392. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4393. /* Enable HRTIM interrupts (if required) */
  4394. __HAL_HRTIM_ENABLE_IT(hhrtim, hhrtim->Init.HRTIMInterruptResquests);
  4395. /* Enable master timer related interrupts (if required) */
  4396. if ((Timers & HRTIM_TIMERID_MASTER) != 0U)
  4397. {
  4398. __HAL_HRTIM_MASTER_ENABLE_IT(hhrtim,
  4399. hhrtim->TimerParam[HRTIM_TIMERINDEX_MASTER].InterruptRequests);
  4400. }
  4401. /* Enable timing unit related interrupts (if required) */
  4402. for (timer_idx = HRTIM_TIMERINDEX_TIMER_A ;
  4403. timer_idx < HRTIM_TIMERINDEX_MASTER ;
  4404. timer_idx++)
  4405. {
  4406. if ((Timers & TimerIdxToTimerId[timer_idx]) != 0U)
  4407. {
  4408. __HAL_HRTIM_TIMER_ENABLE_IT(hhrtim,
  4409. timer_idx,
  4410. hhrtim->TimerParam[timer_idx].InterruptRequests);
  4411. }
  4412. }
  4413. /* Enable timer(s) counter */
  4414. hhrtim->Instance->sMasterRegs.MCR |= (Timers);
  4415. hhrtim->State = HAL_HRTIM_STATE_READY;
  4416. /* Process Unlocked */
  4417. __HAL_UNLOCK(hhrtim);
  4418. return HAL_OK;}
  4419. /**
  4420. * @brief Stop the counter of the designated timer(s) operating in waveform mode
  4421. * Timers can be combined (ORed) to allow for simultaneous counter stop.
  4422. * @param hhrtim pointer to HAL HRTIM handle
  4423. * @param Timers Timer counter(s) to stop
  4424. * This parameter can be any combination of the following values:
  4425. * @arg HRTIM_TIMERID_MASTER
  4426. * @arg HRTIM_TIMERID_A
  4427. * @arg HRTIM_TIMERID_B
  4428. * @arg HRTIM_TIMERID_C
  4429. * @arg HRTIM_TIMERID_D
  4430. * @arg HRTIM_TIMERID_E
  4431. * @retval HAL status
  4432. * @note The counter of a timer is stopped only if all timer outputs are disabled
  4433. * @note All enabled timer related interrupts are disabled.
  4434. */
  4435. HAL_StatusTypeDef HAL_HRTIM_WaveformCountStop_IT(HRTIM_HandleTypeDef * hhrtim,
  4436. uint32_t Timers)
  4437. {
  4438. /* ++ WA */
  4439. __IO uint32_t delai = (uint32_t)(0x17FU);
  4440. /* -- WA */
  4441. uint8_t timer_idx;
  4442. /* Check the parameters */
  4443. assert_param(IS_HRTIM_TIMERID(Timers));
  4444. /* Process Locked */
  4445. __HAL_LOCK(hhrtim);
  4446. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4447. /* Disable HRTIM interrupts (if required) */
  4448. __HAL_HRTIM_DISABLE_IT(hhrtim, hhrtim->Init.HRTIMInterruptResquests);
  4449. /* Disable master timer related interrupts (if required) */
  4450. if ((Timers & HRTIM_TIMERID_MASTER) != 0U)
  4451. {
  4452. /* Interrupts enable flag must be cleared one by one */
  4453. __HAL_HRTIM_MASTER_DISABLE_IT(hhrtim, hhrtim->TimerParam[HRTIM_TIMERINDEX_MASTER].InterruptRequests);
  4454. }
  4455. /* Disable timing unit related interrupts (if required) */
  4456. for (timer_idx = HRTIM_TIMERINDEX_TIMER_A ;
  4457. timer_idx < HRTIM_TIMERINDEX_MASTER ;
  4458. timer_idx++)
  4459. {
  4460. if ((Timers & TimerIdxToTimerId[timer_idx]) != 0U)
  4461. {
  4462. __HAL_HRTIM_TIMER_DISABLE_IT(hhrtim, timer_idx, hhrtim->TimerParam[timer_idx].InterruptRequests);
  4463. }
  4464. }
  4465. /* ++ WA */
  4466. do { delai--; } while (delai != 0U);
  4467. /* -- WA */
  4468. /* Disable timer(s) counter */
  4469. hhrtim->Instance->sMasterRegs.MCR &= ~(Timers);
  4470. hhrtim->State = HAL_HRTIM_STATE_READY;
  4471. /* Process Unlocked */
  4472. __HAL_UNLOCK(hhrtim);
  4473. return HAL_OK;
  4474. }
  4475. /**
  4476. * @brief Start the counter of the designated timer(s) operating in waveform mode
  4477. * Timers can be combined (ORed) to allow for simultaneous counter start.
  4478. * @param hhrtim pointer to HAL HRTIM handle
  4479. * @param Timers Timer counter(s) to start
  4480. * This parameter can be any combination of the following values:
  4481. * @arg HRTIM_TIMERID_MASTER
  4482. * @arg HRTIM_TIMERID_TIMER_A
  4483. * @arg HRTIM_TIMERID_TIMER_B
  4484. * @arg HRTIM_TIMERID_TIMER_C
  4485. * @arg HRTIM_TIMERID_TIMER_D
  4486. * @arg HRTIM_TIMERID_TIMER_E
  4487. * @retval HAL status
  4488. * @note This function enables the dma request(s) mentionned in the timer
  4489. * configuration data structure for every timers to start.
  4490. * @note The source memory address, the destination memory address and the
  4491. * size of each DMA transfer are specified at timer configuration time
  4492. * (see HAL_HRTIM_WaveformTimerConfig)
  4493. */
  4494. HAL_StatusTypeDef HAL_HRTIM_WaveformCountStart_DMA(HRTIM_HandleTypeDef * hhrtim,
  4495. uint32_t Timers)
  4496. {
  4497. uint8_t timer_idx;
  4498. DMA_HandleTypeDef * hdma;
  4499. /* Check the parameters */
  4500. assert_param(IS_HRTIM_TIMERID(Timers));
  4501. if((hhrtim->State == HAL_HRTIM_STATE_BUSY))
  4502. {
  4503. return HAL_BUSY;
  4504. }
  4505. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4506. /* Process Locked */
  4507. __HAL_LOCK(hhrtim);
  4508. if (((Timers & HRTIM_TIMERID_MASTER) != (uint32_t)RESET) &&
  4509. (hhrtim->TimerParam[HRTIM_TIMERINDEX_MASTER].DMARequests != 0U))
  4510. {
  4511. /* Set the DMA error callback */
  4512. hhrtim->hdmaMaster->XferErrorCallback = HRTIM_DMAError ;
  4513. /* Set the DMA transfer completed callback */
  4514. hhrtim->hdmaMaster->XferCpltCallback = HRTIM_DMAMasterCplt;
  4515. /* Enable the DMA channel */
  4516. if (HAL_DMA_Start_IT(hhrtim->hdmaMaster,
  4517. hhrtim->TimerParam[HRTIM_TIMERINDEX_MASTER].DMASrcAddress,
  4518. hhrtim->TimerParam[HRTIM_TIMERINDEX_MASTER].DMADstAddress,
  4519. hhrtim->TimerParam[HRTIM_TIMERINDEX_MASTER].DMASize) != HAL_OK)
  4520. {
  4521. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  4522. /* Process Unlocked */
  4523. __HAL_UNLOCK(hhrtim);
  4524. return HAL_ERROR;
  4525. }
  4526. /* Enable the timer DMA request */
  4527. __HAL_HRTIM_MASTER_ENABLE_DMA(hhrtim,
  4528. hhrtim->TimerParam[HRTIM_TIMERINDEX_MASTER].DMARequests);
  4529. }
  4530. for (timer_idx = HRTIM_TIMERINDEX_TIMER_A ;
  4531. timer_idx < HRTIM_TIMERINDEX_MASTER ;
  4532. timer_idx++)
  4533. {
  4534. if (((Timers & TimerIdxToTimerId[timer_idx]) != (uint32_t)RESET) &&
  4535. (hhrtim->TimerParam[timer_idx].DMARequests != 0U))
  4536. {
  4537. /* Get the timer DMA handler */
  4538. hdma = HRTIM_GetDMAHandleFromTimerIdx(hhrtim, timer_idx);
  4539. if (hdma == NULL)
  4540. {
  4541. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  4542. /* Process Unlocked */
  4543. __HAL_UNLOCK(hhrtim);
  4544. return HAL_ERROR;
  4545. }
  4546. /* Set the DMA error callback */
  4547. hdma->XferErrorCallback = HRTIM_DMAError ;
  4548. /* Set the DMA transfer completed callback */
  4549. hdma->XferCpltCallback = HRTIM_DMATimerxCplt;
  4550. /* Enable the DMA channel */
  4551. if (HAL_DMA_Start_IT(hdma,
  4552. hhrtim->TimerParam[timer_idx].DMASrcAddress,
  4553. hhrtim->TimerParam[timer_idx].DMADstAddress,
  4554. hhrtim->TimerParam[timer_idx].DMASize) != HAL_OK)
  4555. {
  4556. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  4557. /* Process Unlocked */
  4558. __HAL_UNLOCK(hhrtim);
  4559. return HAL_ERROR;
  4560. }
  4561. /* Enable the timer DMA request */
  4562. __HAL_HRTIM_TIMER_ENABLE_DMA(hhrtim,
  4563. timer_idx,
  4564. hhrtim->TimerParam[timer_idx].DMARequests);
  4565. }
  4566. }
  4567. /* Enable the timer counter */
  4568. __HAL_HRTIM_ENABLE(hhrtim, Timers);
  4569. hhrtim->State = HAL_HRTIM_STATE_READY;
  4570. /* Process Unlocked */
  4571. __HAL_UNLOCK(hhrtim);
  4572. return HAL_OK;
  4573. }
  4574. /**
  4575. * @brief Stop the counter of the designated timer(s) operating in waveform mode
  4576. * Timers can be combined (ORed) to allow for simultaneous counter stop.
  4577. * @param hhrtim pointer to HAL HRTIM handle
  4578. * @param Timers Timer counter(s) to stop
  4579. * This parameter can be any combination of the following values:
  4580. * @arg HRTIM_TIMERID_MASTER
  4581. * @arg HRTIM_TIMERID_TIMER_A
  4582. * @arg HRTIM_TIMERID_TIMER_B
  4583. * @arg HRTIM_TIMERID_TIMER_C
  4584. * @arg HRTIM_TIMERID_TIMER_D
  4585. * @arg HRTIM_TIMERID_TIMER_E
  4586. * @retval HAL status
  4587. * @note The counter of a timer is stopped only if all timer outputs are disabled
  4588. * @note All enabled timer related DMA requests are disabled.
  4589. */
  4590. HAL_StatusTypeDef HAL_HRTIM_WaveformCountStop_DMA(HRTIM_HandleTypeDef * hhrtim,
  4591. uint32_t Timers)
  4592. {
  4593. uint8_t timer_idx;
  4594. /* Check the parameters */
  4595. assert_param(IS_HRTIM_TIMERID(Timers));
  4596. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4597. if (((Timers & HRTIM_TIMERID_MASTER) != 0U) &&
  4598. (hhrtim->TimerParam[HRTIM_TIMERINDEX_MASTER].DMARequests != 0U))
  4599. {
  4600. /* Disable the DMA */
  4601. if (HAL_DMA_Abort(hhrtim->hdmaMaster) != HAL_OK)
  4602. {
  4603. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  4604. }
  4605. else
  4606. {
  4607. hhrtim->State = HAL_HRTIM_STATE_READY;
  4608. /* Disable the DMA request(s) */
  4609. __HAL_HRTIM_MASTER_DISABLE_DMA(hhrtim,
  4610. hhrtim->TimerParam[HRTIM_TIMERINDEX_MASTER].DMARequests);
  4611. }
  4612. }
  4613. for (timer_idx = HRTIM_TIMERINDEX_TIMER_A ;
  4614. timer_idx < HRTIM_TIMERINDEX_MASTER ;
  4615. timer_idx++)
  4616. {
  4617. if (((Timers & TimerIdxToTimerId[timer_idx]) != 0U) &&
  4618. (hhrtim->TimerParam[timer_idx].DMARequests != 0U))
  4619. {
  4620. /* Get the timer DMA handler */
  4621. /* Disable the DMA */
  4622. if (HAL_DMA_Abort(HRTIM_GetDMAHandleFromTimerIdx(hhrtim, timer_idx)) != HAL_OK)
  4623. {
  4624. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  4625. }
  4626. else
  4627. {
  4628. hhrtim->State = HAL_HRTIM_STATE_READY;
  4629. /* Disable the DMA request(s) */
  4630. __HAL_HRTIM_TIMER_DISABLE_DMA(hhrtim,
  4631. timer_idx,
  4632. hhrtim->TimerParam[timer_idx].DMARequests);
  4633. }
  4634. }
  4635. }
  4636. /* Disable the timer counter */
  4637. __HAL_HRTIM_DISABLE(hhrtim, Timers);
  4638. if (hhrtim->State == HAL_HRTIM_STATE_ERROR)
  4639. {
  4640. return HAL_ERROR;
  4641. }
  4642. else
  4643. {
  4644. return HAL_OK;
  4645. }
  4646. }
  4647. /**
  4648. * @brief Enable or disables the HRTIM burst mode controller.
  4649. * @param hhrtim pointer to HAL HRTIM handle
  4650. * @param Enable Burst mode controller enabling
  4651. * This parameter can be one of the following values:
  4652. * @arg HRTIM_BURSTMODECTL_ENABLED: Burst mode enabled
  4653. * @arg HRTIM_BURSTMODECTL_DISABLED: Burst mode disabled
  4654. * @retval HAL status
  4655. * @note This function must be called after starting the timer(s)
  4656. */
  4657. HAL_StatusTypeDef HAL_HRTIM_BurstModeCtl(HRTIM_HandleTypeDef * hhrtim,
  4658. uint32_t Enable)
  4659. {
  4660. /* Check parameters */
  4661. assert_param(IS_HRTIM_BURSTMODECTL(Enable));
  4662. if(hhrtim->State == HAL_HRTIM_STATE_BUSY)
  4663. {
  4664. return HAL_BUSY;
  4665. }
  4666. /* Process Locked */
  4667. __HAL_LOCK(hhrtim);
  4668. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4669. /* Enable/Disable the burst mode controller */
  4670. MODIFY_REG(hhrtim->Instance->sCommonRegs.BMCR, HRTIM_BMCR_BME, Enable);
  4671. hhrtim->State = HAL_HRTIM_STATE_READY;
  4672. /* Process Unlocked */
  4673. __HAL_UNLOCK(hhrtim);
  4674. return HAL_OK;
  4675. }
  4676. /**
  4677. * @brief Trig the burst mode operation.
  4678. * @param hhrtim pointer to HAL HRTIM handle
  4679. * @retval HAL status
  4680. */
  4681. HAL_StatusTypeDef HAL_HRTIM_BurstModeSoftwareTrigger(HRTIM_HandleTypeDef *hhrtim)
  4682. {
  4683. if(hhrtim->State == HAL_HRTIM_STATE_BUSY)
  4684. {
  4685. return HAL_BUSY;
  4686. }
  4687. /* Process Locked */
  4688. __HAL_LOCK(hhrtim);
  4689. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4690. /* Software trigger of the burst mode controller */
  4691. SET_BIT(hhrtim->Instance->sCommonRegs.BMTRGR, HRTIM_BMTRGR_SW);
  4692. hhrtim->State = HAL_HRTIM_STATE_READY;
  4693. /* Process Unlocked */
  4694. __HAL_UNLOCK(hhrtim);
  4695. return HAL_OK;
  4696. }
  4697. /**
  4698. * @brief Trig a software capture on the designed capture unit
  4699. * @param hhrtim pointer to HAL HRTIM handle
  4700. * @param TimerIdx Timer index
  4701. * This parameter can be one of the following values:
  4702. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  4703. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  4704. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  4705. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  4706. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  4707. * @param CaptureUnit Capture unit to trig
  4708. * This parameter can be one of the following values:
  4709. * @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  4710. * @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  4711. * @retval HAL status
  4712. * @note The 'software capture' bit in the capure configuration register is
  4713. * automatically reset by hardware
  4714. */
  4715. HAL_StatusTypeDef HAL_HRTIM_SoftwareCapture(HRTIM_HandleTypeDef * hhrtim,
  4716. uint32_t TimerIdx,
  4717. uint32_t CaptureUnit)
  4718. {
  4719. /* Check parameters */
  4720. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  4721. assert_param(IS_HRTIM_CAPTUREUNIT(CaptureUnit));
  4722. if(hhrtim->State == HAL_HRTIM_STATE_BUSY)
  4723. {
  4724. return HAL_BUSY;
  4725. }
  4726. /* Process Locked */
  4727. __HAL_LOCK(hhrtim);
  4728. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4729. /* Force a software capture on concerned capture unit */
  4730. switch (CaptureUnit)
  4731. {
  4732. case HRTIM_CAPTUREUNIT_1:
  4733. {
  4734. SET_BIT(hhrtim->Instance->sTimerxRegs[TimerIdx].CPT1xCR, HRTIM_CPT1CR_SWCPT);
  4735. break;
  4736. }
  4737. case HRTIM_CAPTUREUNIT_2:
  4738. {
  4739. SET_BIT(hhrtim->Instance->sTimerxRegs[TimerIdx].CPT2xCR, HRTIM_CPT2CR_SWCPT);
  4740. break;
  4741. }
  4742. default:
  4743. {
  4744. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  4745. /* Process Unlocked */
  4746. __HAL_UNLOCK(hhrtim);
  4747. break;
  4748. }
  4749. }
  4750. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  4751. {
  4752. return HAL_ERROR;
  4753. }
  4754. hhrtim->State = HAL_HRTIM_STATE_READY;
  4755. /* Process Unlocked */
  4756. __HAL_UNLOCK(hhrtim);
  4757. return HAL_OK;
  4758. }
  4759. /**
  4760. * @brief Trig the update of the registers of one or several timers
  4761. * @param hhrtim pointer to HAL HRTIM handle
  4762. * @param Timers timers concerned with the software register update
  4763. * This parameter can be any combination of the following values:
  4764. * @arg HRTIM_TIMERUPDATE_MASTER
  4765. * @arg HRTIM_TIMERUPDATE_A
  4766. * @arg HRTIM_TIMERUPDATE_B
  4767. * @arg HRTIM_TIMERUPDATE_C
  4768. * @arg HRTIM_TIMERUPDATE_D
  4769. * @arg HRTIM_TIMERUPDATE_E
  4770. * @retval HAL status
  4771. * @note The 'software update' bits in the HRTIM conrol register 2 register are
  4772. * automatically reset by hardware
  4773. */
  4774. HAL_StatusTypeDef HAL_HRTIM_SoftwareUpdate(HRTIM_HandleTypeDef * hhrtim,
  4775. uint32_t Timers)
  4776. {
  4777. /* Check parameters */
  4778. assert_param(IS_HRTIM_TIMERUPDATE(Timers));
  4779. if(hhrtim->State == HAL_HRTIM_STATE_BUSY)
  4780. {
  4781. return HAL_BUSY;
  4782. }
  4783. /* Process Locked */
  4784. __HAL_LOCK(hhrtim);
  4785. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4786. /* Force timer(s) registers update */
  4787. hhrtim->Instance->sCommonRegs.CR2 |= Timers;
  4788. hhrtim->State = HAL_HRTIM_STATE_READY;
  4789. /* Process Unlocked */
  4790. __HAL_UNLOCK(hhrtim);
  4791. return HAL_OK;
  4792. }
  4793. /**
  4794. * @brief Trig the reset of one or several timers
  4795. * @param hhrtim pointer to HAL HRTIM handle
  4796. * @param Timers timers concerned with the software counter reset
  4797. * This parameter can be any combination of the following values:
  4798. * @arg HRTIM_TIMERRESET_MASTER
  4799. * @arg HRTIM_TIMERRESET_TIMER_A
  4800. * @arg HRTIM_TIMERRESET_TIMER_B
  4801. * @arg HRTIM_TIMERRESET_TIMER_C
  4802. * @arg HRTIM_TIMERRESET_TIMER_D
  4803. * @arg HRTIM_TIMERRESET_TIMER_E
  4804. * @retval HAL status
  4805. * @note The 'software reset' bits in the HRTIM conrol register 2 are
  4806. * automatically reset by hardware
  4807. */
  4808. HAL_StatusTypeDef HAL_HRTIM_SoftwareReset(HRTIM_HandleTypeDef * hhrtim,
  4809. uint32_t Timers)
  4810. {
  4811. /* Check parameters */
  4812. assert_param(IS_HRTIM_TIMERRESET(Timers));
  4813. if(hhrtim->State == HAL_HRTIM_STATE_BUSY)
  4814. {
  4815. return HAL_BUSY;
  4816. }
  4817. /* Process Locked */
  4818. __HAL_LOCK(hhrtim);
  4819. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4820. /* Force timer(s) registers reset */
  4821. hhrtim->Instance->sCommonRegs.CR2 = Timers;
  4822. hhrtim->State = HAL_HRTIM_STATE_READY;
  4823. /* Process Unlocked */
  4824. __HAL_UNLOCK(hhrtim);
  4825. return HAL_OK;
  4826. }
  4827. /**
  4828. * @brief Start a burst DMA operation to update HRTIM control registers content
  4829. * @param hhrtim pointer to HAL HRTIM handle
  4830. * @param TimerIdx Timer index
  4831. * This parameter can be one of the following values:
  4832. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  4833. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  4834. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  4835. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  4836. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  4837. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  4838. * @param BurstBufferAddress address of the buffer the HRTIM control registers
  4839. * content will be updated from.
  4840. * @param BurstBufferLength size (in WORDS) of the burst buffer.
  4841. * @retval HAL status
  4842. * @note The TimerIdx parameter determines the dma channel to be used by the
  4843. * DMA burst controller (see below)
  4844. * HRTIM_TIMERINDEX_MASTER: DMA channel 2 is used by the DMA burst controller
  4845. * HRTIM_TIMERINDEX_TIMER_A: DMA channel 3 is used by the DMA burst controller
  4846. * HRTIM_TIMERINDEX_TIMER_B: DMA channel 4 is used by the DMA burst controller
  4847. * HRTIM_TIMERINDEX_TIMER_C: DMA channel 5 is used by the DMA burst controller
  4848. * HRTIM_TIMERINDEX_TIMER_D: DMA channel 6 is used by the DMA burst controller
  4849. * HRTIM_TIMERINDEX_TIMER_E: DMA channel 7 is used by the DMA burst controller
  4850. */
  4851. HAL_StatusTypeDef HAL_HRTIM_BurstDMATransfer(HRTIM_HandleTypeDef *hhrtim,
  4852. uint32_t TimerIdx,
  4853. uint32_t BurstBufferAddress,
  4854. uint32_t BurstBufferLength)
  4855. {
  4856. DMA_HandleTypeDef * hdma;
  4857. /* Check the parameters */
  4858. assert_param(IS_HRTIM_TIMERINDEX(TimerIdx));
  4859. if((hhrtim->State == HAL_HRTIM_STATE_BUSY))
  4860. {
  4861. return HAL_BUSY;
  4862. }
  4863. if((hhrtim->State == HAL_HRTIM_STATE_READY))
  4864. {
  4865. if((BurstBufferAddress == 0U ) || (BurstBufferLength == 0U))
  4866. {
  4867. return HAL_ERROR;
  4868. }
  4869. else
  4870. {
  4871. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4872. }
  4873. }
  4874. /* Process Locked */
  4875. __HAL_LOCK(hhrtim);
  4876. /* Get the timer DMA handler */
  4877. hdma = HRTIM_GetDMAHandleFromTimerIdx(hhrtim, TimerIdx);
  4878. if (hdma == NULL)
  4879. {
  4880. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  4881. /* Process Unlocked */
  4882. __HAL_UNLOCK(hhrtim);
  4883. return HAL_ERROR;
  4884. }
  4885. /* Set the DMA transfer completed callback */
  4886. hdma->XferCpltCallback = HRTIM_BurstDMACplt;
  4887. /* Set the DMA error callback */
  4888. hdma->XferErrorCallback = HRTIM_DMAError ;
  4889. /* Enable the DMA channel */
  4890. if (HAL_DMA_Start_IT(hdma,
  4891. BurstBufferAddress,
  4892. (uint32_t)&(hhrtim->Instance->sCommonRegs.BDMADR),
  4893. BurstBufferLength) != HAL_OK)
  4894. {
  4895. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  4896. /* Process Unlocked */
  4897. __HAL_UNLOCK(hhrtim);
  4898. return HAL_ERROR;
  4899. }
  4900. hhrtim->State = HAL_HRTIM_STATE_READY;
  4901. /* Process Unlocked */
  4902. __HAL_UNLOCK(hhrtim);
  4903. return HAL_OK;
  4904. }
  4905. /**
  4906. * @brief Enable the transfer from preload to active registers for one
  4907. * or several timing units (including master timer).
  4908. * @param hhrtim pointer to HAL HRTIM handle
  4909. * @param Timers Timer(s) concerned by the register preload enabling command
  4910. * This parameter can be any combination of the following values:
  4911. * @arg HRTIM_TIMERUPDATE_MASTER
  4912. * @arg HRTIM_TIMERUPDATE_A
  4913. * @arg HRTIM_TIMERUPDATE_B
  4914. * @arg HRTIM_TIMERUPDATE_C
  4915. * @arg HRTIM_TIMERUPDATE_D
  4916. * @arg HRTIM_TIMERUPDATE_E
  4917. * @retval HAL status
  4918. */
  4919. HAL_StatusTypeDef HAL_HRTIM_UpdateEnable(HRTIM_HandleTypeDef *hhrtim,
  4920. uint32_t Timers)
  4921. {
  4922. /* Check the parameters */
  4923. assert_param(IS_HRTIM_TIMERUPDATE(Timers));
  4924. /* Process Locked */
  4925. __HAL_LOCK(hhrtim);
  4926. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4927. /* Enable timer(s) registers update */
  4928. hhrtim->Instance->sCommonRegs.CR1 &= ~(Timers);
  4929. hhrtim->State = HAL_HRTIM_STATE_READY;
  4930. /* Process Unlocked */
  4931. __HAL_UNLOCK(hhrtim);
  4932. return HAL_OK;
  4933. }
  4934. /**
  4935. * @brief Disable the transfer from preload to active registers for one
  4936. * or several timing units (including master timer).
  4937. * @param hhrtim pointer to HAL HRTIM handle
  4938. * @param Timers Timer(s) concerned by the register preload disabling command
  4939. * This parameter can be any combination of the following values:
  4940. * @arg HRTIM_TIMERUPDATE_MASTER
  4941. * @arg HRTIM_TIMERUPDATE_A
  4942. * @arg HRTIM_TIMERUPDATE_B
  4943. * @arg HRTIM_TIMERUPDATE_C
  4944. * @arg HRTIM_TIMERUPDATE_D
  4945. * @arg HRTIM_TIMERUPDATE_E
  4946. * @retval HAL status
  4947. */
  4948. HAL_StatusTypeDef HAL_HRTIM_UpdateDisable(HRTIM_HandleTypeDef *hhrtim,
  4949. uint32_t Timers)
  4950. {
  4951. /* Check the parameters */
  4952. assert_param(IS_HRTIM_TIMERUPDATE(Timers));
  4953. /* Process Locked */
  4954. __HAL_LOCK(hhrtim);
  4955. hhrtim->State = HAL_HRTIM_STATE_BUSY;
  4956. /* Enable timer(s) registers update */
  4957. hhrtim->Instance->sCommonRegs.CR1 |= (Timers);
  4958. hhrtim->State = HAL_HRTIM_STATE_READY;
  4959. /* Process Unlocked */
  4960. __HAL_UNLOCK(hhrtim);
  4961. return HAL_OK;
  4962. }
  4963. /**
  4964. * @}
  4965. */
  4966. /** @defgroup HRTIM_Exported_Functions_Group9 Peripheral state functions
  4967. * @brief Peripheral State functions
  4968. @verbatim
  4969. ===============================================================================
  4970. ##### Peripheral State functions #####
  4971. ===============================================================================
  4972. [..] This section provides functions used to get HRTIM or HRTIM timer
  4973. specific information:
  4974. (+) Get HRTIM HAL state
  4975. (+) Get captured value
  4976. (+) Get HRTIM timer output level
  4977. (+) Get HRTIM timer output state
  4978. (+) Get delayed protection status
  4979. (+) Get burst status
  4980. (+) Get current push-pull status
  4981. (+) Get idle push-pull status
  4982. @endverbatim
  4983. * @{
  4984. */
  4985. /**
  4986. * @brief Return the HRTIM HAL state
  4987. * @param hhrtim pointer to HAL HRTIM handle
  4988. * @retval HAL state
  4989. */
  4990. HAL_HRTIM_StateTypeDef HAL_HRTIM_GetState(HRTIM_HandleTypeDef* hhrtim)
  4991. {
  4992. /* Return HRTIM state */
  4993. return hhrtim->State;
  4994. }
  4995. /**
  4996. * @brief Return actual value of the capture register of the designated capture unit
  4997. * @param hhrtim pointer to HAL HRTIM handle
  4998. * @param TimerIdx Timer index
  4999. * This parameter can be one of the following values:
  5000. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  5001. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  5002. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  5003. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  5004. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  5005. * @param CaptureUnit Capture unit to trig
  5006. * This parameter can be one of the following values:
  5007. * @arg HRTIM_CAPTUREUNIT_1: Capture unit 1
  5008. * @arg HRTIM_CAPTUREUNIT_2: Capture unit 2
  5009. * @retval Captured value
  5010. */
  5011. uint32_t HAL_HRTIM_GetCapturedValue(HRTIM_HandleTypeDef * hhrtim,
  5012. uint32_t TimerIdx,
  5013. uint32_t CaptureUnit)
  5014. {
  5015. uint32_t captured_value;
  5016. /* Check parameters */
  5017. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  5018. assert_param(IS_HRTIM_CAPTUREUNIT(CaptureUnit));
  5019. /* Read captured value */
  5020. switch (CaptureUnit)
  5021. {
  5022. case HRTIM_CAPTUREUNIT_1:
  5023. {
  5024. captured_value = hhrtim->Instance->sTimerxRegs[TimerIdx].CPT1xR;
  5025. break;
  5026. }
  5027. case HRTIM_CAPTUREUNIT_2:
  5028. {
  5029. captured_value = hhrtim->Instance->sTimerxRegs[TimerIdx].CPT2xR;
  5030. break;
  5031. }
  5032. default:
  5033. {
  5034. captured_value = 0xFFFFFFFFUL;
  5035. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  5036. /* Process Unlocked */
  5037. __HAL_UNLOCK(hhrtim);
  5038. break;
  5039. }
  5040. }
  5041. return captured_value;
  5042. }
  5043. /**
  5044. * @brief Return actual level (active or inactive) of the designated output
  5045. * @param hhrtim pointer to HAL HRTIM handle
  5046. * @param TimerIdx Timer index
  5047. * This parameter can be one of the following values:
  5048. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  5049. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  5050. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  5051. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  5052. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  5053. * @param Output Timer output
  5054. * This parameter can be one of the following values:
  5055. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  5056. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  5057. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  5058. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  5059. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  5060. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  5061. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  5062. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  5063. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  5064. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  5065. * @retval Output level
  5066. * @note Returned output level is taken before the output stage (chopper,
  5067. * polarity).
  5068. */
  5069. uint32_t HAL_HRTIM_WaveformGetOutputLevel(HRTIM_HandleTypeDef * hhrtim,
  5070. uint32_t TimerIdx,
  5071. uint32_t Output)
  5072. {
  5073. uint32_t output_level = (uint32_t)RESET;
  5074. /* Check parameters */
  5075. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, Output));
  5076. /* Read the output level */
  5077. switch (Output)
  5078. {
  5079. case HRTIM_OUTPUT_TA1:
  5080. case HRTIM_OUTPUT_TB1:
  5081. case HRTIM_OUTPUT_TC1:
  5082. case HRTIM_OUTPUT_TD1:
  5083. case HRTIM_OUTPUT_TE1:
  5084. {
  5085. if ((hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxISR & HRTIM_TIMISR_O1CPY) != (uint32_t)RESET)
  5086. {
  5087. output_level = HRTIM_OUTPUTLEVEL_ACTIVE;
  5088. }
  5089. else
  5090. {
  5091. output_level = HRTIM_OUTPUTLEVEL_INACTIVE;
  5092. }
  5093. break;
  5094. }
  5095. case HRTIM_OUTPUT_TA2:
  5096. case HRTIM_OUTPUT_TB2:
  5097. case HRTIM_OUTPUT_TC2:
  5098. case HRTIM_OUTPUT_TD2:
  5099. case HRTIM_OUTPUT_TE2:
  5100. {
  5101. if ((hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxISR & HRTIM_TIMISR_O2CPY) != (uint32_t)RESET)
  5102. {
  5103. output_level = HRTIM_OUTPUTLEVEL_ACTIVE;
  5104. }
  5105. else
  5106. {
  5107. output_level = HRTIM_OUTPUTLEVEL_INACTIVE;
  5108. }
  5109. break;
  5110. }
  5111. default:
  5112. {
  5113. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  5114. /* Process Unlocked */
  5115. __HAL_UNLOCK(hhrtim);
  5116. break;
  5117. }
  5118. }
  5119. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  5120. {
  5121. return (uint32_t)HAL_ERROR;
  5122. }
  5123. return output_level;
  5124. }
  5125. /**
  5126. * @brief Return actual state (RUN, IDLE, FAULT) of the designated output
  5127. * @param hhrtim pointer to HAL HRTIM handle
  5128. * @param TimerIdx Timer index
  5129. * This parameter can be one of the following values:
  5130. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  5131. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  5132. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  5133. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  5134. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  5135. * @param Output Timer output
  5136. * This parameter can be one of the following values:
  5137. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  5138. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  5139. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  5140. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  5141. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  5142. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  5143. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  5144. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  5145. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  5146. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  5147. * @retval Output state
  5148. */
  5149. uint32_t HAL_HRTIM_WaveformGetOutputState(HRTIM_HandleTypeDef * hhrtim,
  5150. uint32_t TimerIdx,
  5151. uint32_t Output)
  5152. {
  5153. uint32_t output_bit = (uint32_t)RESET;
  5154. uint32_t output_state;
  5155. /* Check parameters */
  5156. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, Output));
  5157. /* Set output state according to output control status and output disable status */
  5158. switch (Output)
  5159. {
  5160. case HRTIM_OUTPUT_TA1:
  5161. {
  5162. output_bit = HRTIM_OENR_TA1OEN;
  5163. break;
  5164. }
  5165. case HRTIM_OUTPUT_TA2:
  5166. {
  5167. output_bit = HRTIM_OENR_TA2OEN;
  5168. break;
  5169. }
  5170. case HRTIM_OUTPUT_TB1:
  5171. {
  5172. output_bit = HRTIM_OENR_TB1OEN;
  5173. break;
  5174. }
  5175. case HRTIM_OUTPUT_TB2:
  5176. {
  5177. output_bit = HRTIM_OENR_TB2OEN;
  5178. break;
  5179. }
  5180. case HRTIM_OUTPUT_TC1:
  5181. {
  5182. output_bit = HRTIM_OENR_TC1OEN;
  5183. break;
  5184. }
  5185. case HRTIM_OUTPUT_TC2:
  5186. {
  5187. output_bit = HRTIM_OENR_TC2OEN;
  5188. break;
  5189. }
  5190. case HRTIM_OUTPUT_TD1:
  5191. {
  5192. output_bit = HRTIM_OENR_TD1OEN;
  5193. break;
  5194. }
  5195. case HRTIM_OUTPUT_TD2:
  5196. {
  5197. output_bit = HRTIM_OENR_TD2OEN;
  5198. break;
  5199. }
  5200. case HRTIM_OUTPUT_TE1:
  5201. {
  5202. output_bit = HRTIM_OENR_TE1OEN;
  5203. break;
  5204. }
  5205. case HRTIM_OUTPUT_TE2:
  5206. {
  5207. output_bit = HRTIM_OENR_TE2OEN;
  5208. break;
  5209. }
  5210. default:
  5211. {
  5212. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  5213. /* Process Unlocked */
  5214. __HAL_UNLOCK(hhrtim);
  5215. break;
  5216. }
  5217. }
  5218. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  5219. {
  5220. return (uint32_t)HAL_ERROR;
  5221. }
  5222. if ((hhrtim->Instance->sCommonRegs.OENR & output_bit) != (uint32_t)RESET)
  5223. {
  5224. /* Output is enabled: output in RUN state (whatever ouput disable status is)*/
  5225. output_state = HRTIM_OUTPUTSTATE_RUN;
  5226. }
  5227. else
  5228. {
  5229. if ((hhrtim->Instance->sCommonRegs.ODSR & output_bit) != (uint32_t)RESET)
  5230. {
  5231. /* Output is disabled: output in FAULT state */
  5232. output_state = HRTIM_OUTPUTSTATE_FAULT;
  5233. }
  5234. else
  5235. {
  5236. /* Output is disabled: output in IDLE state */
  5237. output_state = HRTIM_OUTPUTSTATE_IDLE;
  5238. }
  5239. }
  5240. return(output_state);
  5241. }
  5242. /**
  5243. * @brief Return the level (active or inactive) of the designated output
  5244. * when the delayed protection was triggered.
  5245. * @param hhrtim pointer to HAL HRTIM handle
  5246. * @param TimerIdx Timer index
  5247. * This parameter can be one of the following values:
  5248. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  5249. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  5250. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  5251. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  5252. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  5253. * @param Output Timer output
  5254. * This parameter can be one of the following values:
  5255. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  5256. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  5257. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  5258. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  5259. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  5260. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  5261. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  5262. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  5263. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  5264. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  5265. * @retval Delayed protection status
  5266. */
  5267. uint32_t HAL_HRTIM_GetDelayedProtectionStatus(HRTIM_HandleTypeDef * hhrtim,
  5268. uint32_t TimerIdx,
  5269. uint32_t Output)
  5270. {
  5271. uint32_t delayed_protection_status = (uint32_t)RESET;
  5272. /* Check parameters */
  5273. assert_param(IS_HRTIM_TIMER_OUTPUT(TimerIdx, Output));
  5274. /* Read the delayed protection status */
  5275. switch (Output)
  5276. {
  5277. case HRTIM_OUTPUT_TA1:
  5278. case HRTIM_OUTPUT_TB1:
  5279. case HRTIM_OUTPUT_TC1:
  5280. case HRTIM_OUTPUT_TD1:
  5281. case HRTIM_OUTPUT_TE1:
  5282. {
  5283. if ((hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxISR & HRTIM_TIMISR_O1STAT) != (uint32_t)RESET)
  5284. {
  5285. /* Output 1 was active when the delayed idle protection was triggered */
  5286. delayed_protection_status = HRTIM_OUTPUTLEVEL_ACTIVE;
  5287. }
  5288. else
  5289. {
  5290. /* Output 1 was inactive when the delayed idle protection was triggered */
  5291. delayed_protection_status = HRTIM_OUTPUTLEVEL_INACTIVE;
  5292. }
  5293. break;
  5294. }
  5295. case HRTIM_OUTPUT_TA2:
  5296. case HRTIM_OUTPUT_TB2:
  5297. case HRTIM_OUTPUT_TC2:
  5298. case HRTIM_OUTPUT_TD2:
  5299. case HRTIM_OUTPUT_TE2:
  5300. {
  5301. if ((hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxISR & HRTIM_TIMISR_O2STAT) != (uint32_t)RESET)
  5302. {
  5303. /* Output 2 was active when the delayed idle protection was triggered */
  5304. delayed_protection_status = HRTIM_OUTPUTLEVEL_ACTIVE;
  5305. }
  5306. else
  5307. {
  5308. /* Output 2 was inactive when the delayed idle protection was triggered */
  5309. delayed_protection_status = HRTIM_OUTPUTLEVEL_INACTIVE;
  5310. }
  5311. break;
  5312. }
  5313. default:
  5314. {
  5315. hhrtim->State = HAL_HRTIM_STATE_ERROR;
  5316. /* Process Unlocked */
  5317. __HAL_UNLOCK(hhrtim);
  5318. break;
  5319. }
  5320. }
  5321. if(hhrtim->State == HAL_HRTIM_STATE_ERROR)
  5322. {
  5323. return (uint32_t)HAL_ERROR;
  5324. }
  5325. return delayed_protection_status;
  5326. }
  5327. /**
  5328. * @brief Return the actual status (active or inactive) of the burst mode controller
  5329. * @param hhrtim pointer to HAL HRTIM handle
  5330. * @retval Burst mode controller status
  5331. */
  5332. uint32_t HAL_HRTIM_GetBurstStatus(HRTIM_HandleTypeDef * hhrtim)
  5333. {
  5334. uint32_t burst_mode_status;
  5335. /* Read burst mode status */
  5336. burst_mode_status = (hhrtim->Instance->sCommonRegs.BMCR & HRTIM_BMCR_BMSTAT);
  5337. return burst_mode_status;
  5338. }
  5339. /**
  5340. * @brief Indicate on which output the signal is currently active (when the
  5341. * push pull mode is enabled).
  5342. * @param hhrtim pointer to HAL HRTIM handle
  5343. * @param TimerIdx Timer index
  5344. * This parameter can be one of the following values:
  5345. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  5346. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  5347. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  5348. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  5349. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  5350. * @retval Burst mode controller status
  5351. */
  5352. uint32_t HAL_HRTIM_GetCurrentPushPullStatus(HRTIM_HandleTypeDef * hhrtim,
  5353. uint32_t TimerIdx)
  5354. {
  5355. uint32_t current_pushpull_status;
  5356. /* Check the parameters */
  5357. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  5358. /* Read current push pull status */
  5359. current_pushpull_status = (hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxISR & HRTIM_TIMISR_CPPSTAT);
  5360. return current_pushpull_status;
  5361. }
  5362. /**
  5363. * @brief Indicate on which output the signal was applied, in push-pull mode,
  5364. balanced fault mode or delayed idle mode, when the protection was triggered.
  5365. * @param hhrtim pointer to HAL HRTIM handle
  5366. * @param TimerIdx Timer index
  5367. * This parameter can be one of the following values:
  5368. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  5369. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  5370. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  5371. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  5372. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  5373. * @retval Idle Push Pull Status
  5374. */
  5375. uint32_t HAL_HRTIM_GetIdlePushPullStatus(HRTIM_HandleTypeDef * hhrtim,
  5376. uint32_t TimerIdx)
  5377. {
  5378. uint32_t idle_pushpull_status;
  5379. /* Check the parameters */
  5380. assert_param(IS_HRTIM_TIMING_UNIT(TimerIdx));
  5381. /* Read current push pull status */
  5382. idle_pushpull_status = (hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxISR & HRTIM_TIMISR_IPPSTAT);
  5383. return idle_pushpull_status;
  5384. }
  5385. /**
  5386. * @}
  5387. */
  5388. /** @defgroup HRTIM_Exported_Functions_Group10 Interrupts handling
  5389. * @brief Functions called when HRTIM generates an interrupt
  5390. * 7 interrupts can be generated by the master timer:
  5391. * - Master timer registers update
  5392. * - Synchronization event received
  5393. * - Master timer repetition event
  5394. * - Master Compare 1 to 4 event
  5395. * 14 interrupts can be generated by each timing unit:
  5396. * - Delayed protection triggered
  5397. * - Counter reset or roll-over event
  5398. * - Output 1 and output 2 reset (transition active to inactive)
  5399. * - Output 1 and output 2 set (transition inactive to active)
  5400. * - Capture 1 and 2 events
  5401. * - Timing unit registers update
  5402. * - Repetition event
  5403. * - Compare 1 to 4 event
  5404. * 7 global interrupts are generated for the whole HRTIM:
  5405. * - System fault and Fault 1 to 5 (regardless of the timing unit attribution)
  5406. * - Burst mode period completed
  5407. @verbatim
  5408. ===============================================================================
  5409. ##### HRTIM interrupts handling #####
  5410. ===============================================================================
  5411. [..]
  5412. This subsection provides a set of functions allowing to manage the HRTIM
  5413. interrupts:
  5414. (+) HRTIM interrupt handler
  5415. (+) Callback function called when Fault1 interrupt occurs
  5416. (+) Callback function called when Fault2 interrupt occurs
  5417. (+) Callback function called when Fault3 interrupt occurs
  5418. (+) Callback function called when Fault4 interrupt occurs
  5419. (+) Callback function called when Fault5 interrupt occurs
  5420. (+) Callback function called when system Fault interrupt occurs
  5421. (+) Callback function called when burst mode period interrupt occurs
  5422. (+) Callback function called when synchronization input interrupt occurs
  5423. (+) Callback function called when a timer register update interrupt occurs
  5424. (+) Callback function called when a timer repetition interrupt occurs
  5425. (+) Callback function called when a compare 1 match interrupt occurs
  5426. (+) Callback function called when a compare 2 match interrupt occurs
  5427. (+) Callback function called when a compare 3 match interrupt occurs
  5428. (+) Callback function called when a compare 4 match interrupt occurs
  5429. (+) Callback function called when a capture 1 interrupt occurs
  5430. (+) Callback function called when a capture 2 interrupt occurs
  5431. (+) Callback function called when a delayed protection interrupt occurs
  5432. (+) Callback function called when a timer counter reset interrupt occurs
  5433. (+) Callback function called when a timer output 1 set interrupt occurs
  5434. (+) Callback function called when a timer output 1 reset interrupt occurs
  5435. (+) Callback function called when a timer output 2 set interrupt occurs
  5436. (+) Callback function called when a timer output 2 reset interrupt occurs
  5437. (+) Callback function called when a timer output 2 reset interrupt occurs
  5438. (+) Callback function called upon completion of a burst DMA transfer
  5439. (+) HRTIM callback function registration
  5440. (+) HRTIM callback function unregistration
  5441. (+) HRTIM Timer x callback function registration
  5442. (+) HRTIM Timer x callback function unregistration
  5443. @endverbatim
  5444. * @{
  5445. */
  5446. /**
  5447. * @brief This function handles HRTIM interrupt request.
  5448. * @param hhrtim pointer to HAL HRTIM handle
  5449. * @param TimerIdx Timer index
  5450. * This parameter can be any value of HRTIM_Timer_Index
  5451. * @retval None
  5452. */
  5453. void HAL_HRTIM_IRQHandler(HRTIM_HandleTypeDef * hhrtim,
  5454. uint32_t TimerIdx)
  5455. {
  5456. /* HRTIM interrupts handling */
  5457. if (TimerIdx == HRTIM_TIMERINDEX_COMMON)
  5458. {
  5459. HRTIM_HRTIM_ISR(hhrtim);
  5460. }
  5461. else if (TimerIdx == HRTIM_TIMERINDEX_MASTER)
  5462. {
  5463. /* Master related interrupts handling */
  5464. HRTIM_Master_ISR(hhrtim);
  5465. }
  5466. else
  5467. {
  5468. /* Timing unit related interrupts handling */
  5469. HRTIM_Timer_ISR(hhrtim, TimerIdx);
  5470. }
  5471. }
  5472. /**
  5473. * @brief Callback function invoked when a fault 1 interrupt occurred
  5474. * @param hhrtim pointer to HAL HRTIM handle * @retval None
  5475. * @retval None
  5476. */
  5477. __weak void HAL_HRTIM_Fault1Callback(HRTIM_HandleTypeDef * hhrtim)
  5478. {
  5479. /* Prevent unused argument(s) compilation warning */
  5480. UNUSED(hhrtim);
  5481. /* NOTE : This function should not be modified, when the callback is needed,
  5482. the HAL_HRTIM_Fault1Callback could be implemented in the user file
  5483. */
  5484. }
  5485. /**
  5486. * @brief Callback function invoked when a fault 2 interrupt occurred
  5487. * @param hhrtim pointer to HAL HRTIM handle
  5488. * @retval None
  5489. */
  5490. __weak void HAL_HRTIM_Fault2Callback(HRTIM_HandleTypeDef * hhrtim)
  5491. {
  5492. /* Prevent unused argument(s) compilation warning */
  5493. UNUSED(hhrtim);
  5494. /* NOTE : This function should not be modified, when the callback is needed,
  5495. the HAL_HRTIM_Fault2Callback could be implemented in the user file
  5496. */
  5497. }
  5498. /**
  5499. * @brief Callback function invoked when a fault 3 interrupt occurred
  5500. * @param hhrtim pointer to HAL HRTIM handle
  5501. * @retval None
  5502. */
  5503. __weak void HAL_HRTIM_Fault3Callback(HRTIM_HandleTypeDef * hhrtim)
  5504. {
  5505. /* Prevent unused argument(s) compilation warning */
  5506. UNUSED(hhrtim);
  5507. /* NOTE : This function should not be modified, when the callback is needed,
  5508. the HAL_HRTIM_Fault3Callback could be implemented in the user file
  5509. */
  5510. }
  5511. /**
  5512. * @brief Callback function invoked when a fault 4 interrupt occurred
  5513. * @param hhrtim pointer to HAL HRTIM handle
  5514. * @retval None
  5515. */
  5516. __weak void HAL_HRTIM_Fault4Callback(HRTIM_HandleTypeDef * hhrtim)
  5517. {
  5518. /* Prevent unused argument(s) compilation warning */
  5519. UNUSED(hhrtim);
  5520. /* NOTE : This function should not be modified, when the callback is needed,
  5521. the HAL_HRTIM_Fault4Callback could be implemented in the user file
  5522. */
  5523. }
  5524. /**
  5525. * @brief Callback function invoked when a fault 5 interrupt occurred
  5526. * @param hhrtim pointer to HAL HRTIM handle
  5527. * @retval None
  5528. */
  5529. __weak void HAL_HRTIM_Fault5Callback(HRTIM_HandleTypeDef * hhrtim)
  5530. {
  5531. /* Prevent unused argument(s) compilation warning */
  5532. UNUSED(hhrtim);
  5533. /* NOTE : This function should not be modified, when the callback is needed,
  5534. the HAL_HRTIM_Fault5Callback could be implemented in the user file
  5535. */
  5536. }
  5537. /**
  5538. * @brief Callback function invoked when a system fault interrupt occurred
  5539. * @param hhrtim pointer to HAL HRTIM handle
  5540. * @retval None
  5541. */
  5542. __weak void HAL_HRTIM_SystemFaultCallback(HRTIM_HandleTypeDef * hhrtim)
  5543. {
  5544. /* Prevent unused argument(s) compilation warning */
  5545. UNUSED(hhrtim);
  5546. /* NOTE : This function should not be modified, when the callback is needed,
  5547. the HAL_HRTIM_SystemFaultCallback could be implemented in the user file
  5548. */
  5549. }
  5550. /**
  5551. * @brief Callback function invoked when the end of the burst mode period is reached
  5552. * @param hhrtim pointer to HAL HRTIM handle
  5553. * @retval None
  5554. */
  5555. __weak void HAL_HRTIM_BurstModePeriodCallback(HRTIM_HandleTypeDef * hhrtim)
  5556. {
  5557. /* Prevent unused argument(s) compilation warning */
  5558. UNUSED(hhrtim);
  5559. /* NOTE : This function should not be modified, when the callback is needed,
  5560. the HAL_HRTIM_BurstModeCallback could be implemented in the user file
  5561. */
  5562. }
  5563. /**
  5564. * @brief Callback function invoked when a synchronization input event is received
  5565. * @param hhrtim pointer to HAL HRTIM handle
  5566. * @retval None
  5567. */
  5568. __weak void HAL_HRTIM_SynchronizationEventCallback(HRTIM_HandleTypeDef * hhrtim)
  5569. {
  5570. /* Prevent unused argument(s) compilation warning */
  5571. UNUSED(hhrtim);
  5572. /* NOTE : This function should not be modified, when the callback is needed,
  5573. the HAL_HRTIM_SynchronizationEventCallback could be implemented in the user file
  5574. */
  5575. }
  5576. /**
  5577. * @brief Callback function invoked when timer registers are updated
  5578. * @param hhrtim pointer to HAL HRTIM handle
  5579. * @param TimerIdx Timer index
  5580. * This parameter can be one of the following values:
  5581. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  5582. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  5583. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  5584. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  5585. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  5586. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  5587. * @retval None
  5588. */
  5589. __weak void HAL_HRTIM_RegistersUpdateCallback(HRTIM_HandleTypeDef * hhrtim,
  5590. uint32_t TimerIdx)
  5591. {
  5592. /* Prevent unused argument(s) compilation warning */
  5593. UNUSED(hhrtim);
  5594. UNUSED(TimerIdx);
  5595. /* NOTE : This function should not be modified, when the callback is needed,
  5596. the HAL_HRTIM_Master_RegistersUpdateCallback could be implemented in the user file
  5597. */
  5598. }
  5599. /**
  5600. * @brief Callback function invoked when timer repetition period has elapsed
  5601. * @param hhrtim pointer to HAL HRTIM handle
  5602. * @param TimerIdx Timer index
  5603. * This parameter can be one of the following values:
  5604. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  5605. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  5606. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  5607. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  5608. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  5609. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  5610. * @retval None
  5611. */
  5612. __weak void HAL_HRTIM_RepetitionEventCallback(HRTIM_HandleTypeDef * hhrtim,
  5613. uint32_t TimerIdx)
  5614. {
  5615. /* Prevent unused argument(s) compilation warning */
  5616. UNUSED(hhrtim);
  5617. UNUSED(TimerIdx);
  5618. /* NOTE : This function should not be modified, when the callback is needed,
  5619. the HAL_HRTIM_Master_RepetitionEventCallback could be implemented in the user file
  5620. */
  5621. }
  5622. /**
  5623. * @brief Callback function invoked when the timer counter matches the value
  5624. * programmed in the compare 1 register
  5625. * @param hhrtim pointer to HAL HRTIM handle
  5626. * @param TimerIdx Timer index
  5627. * This parameter can be one of the following values:
  5628. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  5629. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  5630. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  5631. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  5632. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  5633. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  5634. * @retval None
  5635. */
  5636. __weak void HAL_HRTIM_Compare1EventCallback(HRTIM_HandleTypeDef * hhrtim,
  5637. uint32_t TimerIdx)
  5638. {
  5639. /* Prevent unused argument(s) compilation warning */
  5640. UNUSED(hhrtim);
  5641. UNUSED(TimerIdx);
  5642. /* NOTE : This function should not be modified, when the callback is needed,
  5643. the HAL_HRTIM_Master_Compare1EventCallback could be implemented in the user file
  5644. */
  5645. }
  5646. /**
  5647. * @brief Callback function invoked when the timer counter matches the value
  5648. * programmed in the compare 2 register
  5649. * @param hhrtim pointer to HAL HRTIM handle
  5650. * @retval None
  5651. * @param TimerIdx Timer index
  5652. * This parameter can be one of the following values:
  5653. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  5654. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  5655. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  5656. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  5657. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  5658. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  5659. */
  5660. __weak void HAL_HRTIM_Compare2EventCallback(HRTIM_HandleTypeDef * hhrtim,
  5661. uint32_t TimerIdx)
  5662. {
  5663. /* Prevent unused argument(s) compilation warning */
  5664. UNUSED(hhrtim);
  5665. UNUSED(TimerIdx);
  5666. /* NOTE : This function should not be modified, when the callback is needed,
  5667. the HAL_HRTIM_Master_Compare2EventCallback could be implemented in the user file
  5668. */
  5669. }
  5670. /**
  5671. * @brief Callback function invoked when the timer counter matches the value
  5672. * programmed in the compare 3 register
  5673. * @param hhrtim pointer to HAL HRTIM handle
  5674. * @param TimerIdx Timer index
  5675. * This parameter can be one of the following values:
  5676. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  5677. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  5678. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  5679. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  5680. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  5681. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  5682. * @retval None
  5683. */
  5684. __weak void HAL_HRTIM_Compare3EventCallback(HRTIM_HandleTypeDef * hhrtim,
  5685. uint32_t TimerIdx)
  5686. {
  5687. /* Prevent unused argument(s) compilation warning */
  5688. UNUSED(hhrtim);
  5689. UNUSED(TimerIdx);
  5690. /* NOTE : This function should not be modified, when the callback is needed,
  5691. the HAL_HRTIM_Master_Compare3EventCallback could be implemented in the user file
  5692. */
  5693. }
  5694. /**
  5695. * @brief Callback function invoked when the timer counter matches the value
  5696. * programmed in the compare 4 register.
  5697. * @param hhrtim pointer to HAL HRTIM handle
  5698. * @param TimerIdx Timer index
  5699. * This parameter can be one of the following values:
  5700. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  5701. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  5702. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  5703. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  5704. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  5705. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  5706. * @retval None
  5707. */
  5708. __weak void HAL_HRTIM_Compare4EventCallback(HRTIM_HandleTypeDef * hhrtim,
  5709. uint32_t TimerIdx)
  5710. {
  5711. /* Prevent unused argument(s) compilation warning */
  5712. UNUSED(hhrtim);
  5713. UNUSED(TimerIdx);
  5714. /* NOTE : This function should not be modified, when the callback is needed,
  5715. the HAL_HRTIM_Master_Compare4EventCallback could be implemented in the user file
  5716. */
  5717. }
  5718. /**
  5719. * @brief Callback function invoked when the timer x capture 1 event occurs
  5720. * @param hhrtim pointer to HAL HRTIM handle
  5721. * @param TimerIdx Timer index
  5722. * This parameter can be one of the following values:
  5723. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  5724. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  5725. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  5726. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  5727. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  5728. * @retval None
  5729. */
  5730. __weak void HAL_HRTIM_Capture1EventCallback(HRTIM_HandleTypeDef * hhrtim,
  5731. uint32_t TimerIdx)
  5732. {
  5733. /* Prevent unused argument(s) compilation warning */
  5734. UNUSED(hhrtim);
  5735. UNUSED(TimerIdx);
  5736. /* NOTE : This function should not be modified, when the callback is needed,
  5737. the HAL_HRTIM_Timer_Capture1EventCallback could be implemented in the user file
  5738. */
  5739. }
  5740. /**
  5741. * @brief Callback function invoked when the timer x capture 2 event occurs
  5742. * @param hhrtim pointer to HAL HRTIM handle
  5743. * @param TimerIdx Timer index
  5744. * This parameter can be one of the following values:
  5745. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  5746. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  5747. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  5748. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  5749. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  5750. * @retval None
  5751. */
  5752. __weak void HAL_HRTIM_Capture2EventCallback(HRTIM_HandleTypeDef * hhrtim,
  5753. uint32_t TimerIdx)
  5754. {
  5755. /* Prevent unused argument(s) compilation warning */
  5756. UNUSED(hhrtim);
  5757. UNUSED(TimerIdx);
  5758. /* NOTE : This function should not be modified, when the callback is needed,
  5759. the HAL_HRTIM_Timer_Capture2EventCallback could be implemented in the user file
  5760. */
  5761. }
  5762. /**
  5763. * @brief Callback function invoked when the delayed idle or balanced idle mode is
  5764. * entered.
  5765. * @param hhrtim pointer to HAL HRTIM handle
  5766. * @param TimerIdx Timer index
  5767. * This parameter can be one of the following values:
  5768. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  5769. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  5770. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  5771. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  5772. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  5773. * @retval None
  5774. */
  5775. __weak void HAL_HRTIM_DelayedProtectionCallback(HRTIM_HandleTypeDef * hhrtim,
  5776. uint32_t TimerIdx)
  5777. {
  5778. /* Prevent unused argument(s) compilation warning */
  5779. UNUSED(hhrtim);
  5780. UNUSED(TimerIdx);
  5781. /* NOTE : This function should not be modified, when the callback is needed,
  5782. the HAL_HRTIM_Timer_DelayedProtectionCallback could be implemented in the user file
  5783. */
  5784. }
  5785. /**
  5786. * @brief Callback function invoked when the timer x counter reset/roll-over
  5787. * event occurs.
  5788. * @param hhrtim pointer to HAL HRTIM handle
  5789. * @param TimerIdx Timer index
  5790. * This parameter can be one of the following values:
  5791. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  5792. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  5793. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  5794. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  5795. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  5796. * @retval None
  5797. */
  5798. __weak void HAL_HRTIM_CounterResetCallback(HRTIM_HandleTypeDef * hhrtim,
  5799. uint32_t TimerIdx)
  5800. {
  5801. /* Prevent unused argument(s) compilation warning */
  5802. UNUSED(hhrtim);
  5803. UNUSED(TimerIdx);
  5804. /* NOTE : This function should not be modified, when the callback is needed,
  5805. the HAL_HRTIM_Timer_CounterResetCallback could be implemented in the user file
  5806. */
  5807. }
  5808. /**
  5809. * @brief Callback function invoked when the timer x output 1 is set
  5810. * @param hhrtim pointer to HAL HRTIM handle
  5811. * @param TimerIdx Timer index
  5812. * This parameter can be one of the following values:
  5813. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  5814. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  5815. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  5816. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  5817. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  5818. * @retval None
  5819. */
  5820. __weak void HAL_HRTIM_Output1SetCallback(HRTIM_HandleTypeDef * hhrtim,
  5821. uint32_t TimerIdx)
  5822. {
  5823. /* Prevent unused argument(s) compilation warning */
  5824. UNUSED(hhrtim);
  5825. UNUSED(TimerIdx);
  5826. /* NOTE : This function should not be modified, when the callback is needed,
  5827. the HAL_HRTIM_Timer_Output1SetCallback could be implemented in the user file
  5828. */
  5829. }
  5830. /**
  5831. * @brief Callback function invoked when the timer x output 1 is reset
  5832. * @param hhrtim pointer to HAL HRTIM handle
  5833. * @param TimerIdx Timer index
  5834. * This parameter can be one of the following values:
  5835. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  5836. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  5837. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  5838. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  5839. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  5840. * @retval None
  5841. */
  5842. __weak void HAL_HRTIM_Output1ResetCallback(HRTIM_HandleTypeDef * hhrtim,
  5843. uint32_t TimerIdx)
  5844. {
  5845. /* Prevent unused argument(s) compilation warning */
  5846. UNUSED(hhrtim);
  5847. UNUSED(TimerIdx);
  5848. /* NOTE : This function should not be modified, when the callback is needed,
  5849. the HAL_HRTIM_Timer_Output1ResetCallback could be implemented in the user file
  5850. */
  5851. }
  5852. /**
  5853. * @brief Callback function invoked when the timer x output 2 is set
  5854. * @param hhrtim pointer to HAL HRTIM handle
  5855. * @param TimerIdx Timer index
  5856. * This parameter can be one of the following values:
  5857. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  5858. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  5859. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  5860. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  5861. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  5862. * @retval None
  5863. */
  5864. __weak void HAL_HRTIM_Output2SetCallback(HRTIM_HandleTypeDef * hhrtim,
  5865. uint32_t TimerIdx)
  5866. {
  5867. /* Prevent unused argument(s) compilation warning */
  5868. UNUSED(hhrtim);
  5869. UNUSED(TimerIdx);
  5870. /* NOTE : This function should not be modified, when the callback is needed,
  5871. the HAL_HRTIM_Timer_Output2SetCallback could be implemented in the user file
  5872. */
  5873. }
  5874. /**
  5875. * @brief Callback function invoked when the timer x output 2 is reset
  5876. * @param hhrtim pointer to HAL HRTIM handle
  5877. * @param TimerIdx Timer index
  5878. * This parameter can be one of the following values:
  5879. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  5880. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  5881. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  5882. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  5883. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  5884. * @retval None
  5885. */
  5886. __weak void HAL_HRTIM_Output2ResetCallback(HRTIM_HandleTypeDef * hhrtim,
  5887. uint32_t TimerIdx)
  5888. {
  5889. /* Prevent unused argument(s) compilation warning */
  5890. UNUSED(hhrtim);
  5891. UNUSED(TimerIdx);
  5892. /* NOTE : This function should not be modified, when the callback is needed,
  5893. the HAL_HRTIM_Timer_Output2ResetCallback could be implemented in the user file
  5894. */
  5895. }
  5896. /**
  5897. * @brief Callback function invoked when a DMA burst transfer is completed
  5898. * @param hhrtim pointer to HAL HRTIM handle
  5899. * @param TimerIdx Timer index
  5900. * This parameter can be one of the following values:
  5901. * @arg HRTIM_TIMERINDEX_MASTER for master timer
  5902. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  5903. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  5904. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  5905. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  5906. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  5907. * @retval None
  5908. */
  5909. __weak void HAL_HRTIM_BurstDMATransferCallback(HRTIM_HandleTypeDef * hhrtim,
  5910. uint32_t TimerIdx)
  5911. {
  5912. /* Prevent unused argument(s) compilation warning */
  5913. UNUSED(hhrtim);
  5914. UNUSED(TimerIdx);
  5915. /* NOTE : This function should not be modified, when the callback is needed,
  5916. the HAL_HRTIM_BurstDMATransferCallback could be implemented in the user file
  5917. */
  5918. }
  5919. /**
  5920. * @brief Callback function invoked when a DMA error occurs
  5921. * @param hhrtim pointer to HAL HRTIM handle
  5922. * @retval None
  5923. */
  5924. __weak void HAL_HRTIM_ErrorCallback(HRTIM_HandleTypeDef *hhrtim)
  5925. {
  5926. /* Prevent unused argument(s) compilation warning */
  5927. UNUSED(hhrtim);
  5928. /* NOTE : This function should not be modified, when the callback is needed,
  5929. the HAL_HRTIM_ErrorCallback could be implemented in the user file
  5930. */
  5931. }
  5932. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  5933. /**
  5934. * @brief HRTIM callback function registration
  5935. * @param hhrtim pointer to HAL HRTIM handle
  5936. * @param CallbackID ID of the HRTIM callback function to register
  5937. * This parameter can be one of the following values:
  5938. * @arg HAL_HRTIM_FAULT1CALLBACK_CB_ID
  5939. * @arg HAL_HRTIM_FAULT2CALLBACK_CB_ID
  5940. * @arg HAL_HRTIM_FAULT3CALLBACK_CB_ID
  5941. * @arg HAL_HRTIM_FAULT4CALLBACK_CB_ID
  5942. * @arg HAL_HRTIM_FAULT5CALLBACK_CB_ID
  5943. * @arg HAL_HRTIM_SYSTEMFAULTCALLBACK_CB_ID
  5944. * @arg HAL_HRTIM_BURSTMODEPERIODCALLBACK_CB_ID
  5945. * @arg HAL_HRTIM_SYNCHRONIZATIONEVENTCALLBACK_CB_ID
  5946. * @arg HAL_HRTIM_ERRORCALLBACK_CB_ID
  5947. * @arg HAL_HRTIM_MSPINIT_CB_ID
  5948. * @arg HAL_HRTIM_MSPDEINIT_CB_ID
  5949. * @param pCallback Callback function pointer
  5950. * @retval HAL status
  5951. */
  5952. HAL_StatusTypeDef HAL_HRTIM_RegisterCallback(HRTIM_HandleTypeDef * hhrtim,
  5953. HAL_HRTIM_CallbackIDTypeDef CallbackID,
  5954. pHRTIM_CallbackTypeDef pCallback)
  5955. {
  5956. HAL_StatusTypeDef status = HAL_OK;
  5957. if (pCallback == NULL)
  5958. {
  5959. /* Update the state */
  5960. hhrtim->State = HAL_HRTIM_STATE_INVALID_CALLBACK;
  5961. return HAL_ERROR;
  5962. }
  5963. /* Process locked */
  5964. __HAL_LOCK(hhrtim);
  5965. if (HAL_HRTIM_STATE_READY == hhrtim->State)
  5966. {
  5967. switch (CallbackID)
  5968. {
  5969. case HAL_HRTIM_FAULT1CALLBACK_CB_ID :
  5970. hhrtim->Fault1Callback = pCallback;
  5971. break;
  5972. case HAL_HRTIM_FAULT2CALLBACK_CB_ID :
  5973. hhrtim->Fault2Callback = pCallback;
  5974. break;
  5975. case HAL_HRTIM_FAULT3CALLBACK_CB_ID :
  5976. hhrtim->Fault3Callback = pCallback;
  5977. break;
  5978. case HAL_HRTIM_FAULT4CALLBACK_CB_ID :
  5979. hhrtim->Fault4Callback = pCallback;
  5980. break;
  5981. case HAL_HRTIM_FAULT5CALLBACK_CB_ID :
  5982. hhrtim->Fault5Callback = pCallback;
  5983. break;
  5984. case HAL_HRTIM_SYSTEMFAULTCALLBACK_CB_ID :
  5985. hhrtim->SystemFaultCallback = pCallback;
  5986. break;
  5987. case HAL_HRTIM_BURSTMODEPERIODCALLBACK_CB_ID :
  5988. hhrtim->BurstModePeriodCallback = pCallback;
  5989. break;
  5990. case HAL_HRTIM_SYNCHRONIZATIONEVENTCALLBACK_CB_ID :
  5991. hhrtim->SynchronizationEventCallback = pCallback;
  5992. break;
  5993. case HAL_HRTIM_ERRORCALLBACK_CB_ID :
  5994. hhrtim->ErrorCallback = pCallback;
  5995. break;
  5996. case HAL_HRTIM_MSPINIT_CB_ID :
  5997. hhrtim->MspInitCallback = pCallback;
  5998. break;
  5999. case HAL_HRTIM_MSPDEINIT_CB_ID :
  6000. hhrtim->MspDeInitCallback = pCallback;
  6001. break;
  6002. default :
  6003. /* Update the state */
  6004. hhrtim->State = HAL_HRTIM_STATE_INVALID_CALLBACK;
  6005. /* Return error status */
  6006. status = HAL_ERROR;
  6007. break;
  6008. }
  6009. }
  6010. else if (HAL_HRTIM_STATE_RESET == hhrtim->State)
  6011. {
  6012. switch (CallbackID)
  6013. {
  6014. case HAL_HRTIM_MSPINIT_CB_ID :
  6015. hhrtim->MspInitCallback = pCallback;
  6016. break;
  6017. case HAL_HRTIM_MSPDEINIT_CB_ID :
  6018. hhrtim->MspDeInitCallback = pCallback;
  6019. break;
  6020. default :
  6021. /* Update the state */
  6022. hhrtim->State = HAL_HRTIM_STATE_INVALID_CALLBACK;
  6023. /* Return error status */
  6024. status = HAL_ERROR;
  6025. break;
  6026. }
  6027. }
  6028. else
  6029. {
  6030. /* Update the state */
  6031. hhrtim->State = HAL_HRTIM_STATE_INVALID_CALLBACK;
  6032. /* Return error status */
  6033. status = HAL_ERROR;
  6034. }
  6035. /* Release Lock */
  6036. __HAL_UNLOCK(hhrtim);
  6037. return status;
  6038. }
  6039. /**
  6040. * @brief HRTIM callback function un-registration
  6041. * @param hhrtim pointer to HAL HRTIM handle
  6042. * @param CallbackID ID of the HRTIM callback function to unregister
  6043. * This parameter can be one of the following values:
  6044. * @arg HAL_HRTIM_FAULT1CALLBACK_CB_ID
  6045. * @arg HAL_HRTIM_FAULT2CALLBACK_CB_ID
  6046. * @arg HAL_HRTIM_FAULT3CALLBACK_CB_ID
  6047. * @arg HAL_HRTIM_FAULT4CALLBACK_CB_ID
  6048. * @arg HAL_HRTIM_FAULT5CALLBACK_CB_ID
  6049. * @arg HAL_HRTIM_SYSTEMFAULTCALLBACK_CB_ID
  6050. * @arg HAL_HRTIM_BURSTMODEPERIODCALLBACK_CB_ID
  6051. * @arg HAL_HRTIM_SYNCHRONIZATIONEVENTCALLBACK_CB_ID
  6052. * @arg HAL_HRTIM_ERRORCALLBACK_CB_ID
  6053. * @arg HAL_HRTIM_MSPINIT_CB_ID
  6054. * @arg HAL_HRTIM_MSPDEINIT_CB_ID
  6055. * @retval HAL status
  6056. */
  6057. HAL_StatusTypeDef HAL_HRTIM_UnRegisterCallback(HRTIM_HandleTypeDef * hhrtim,
  6058. HAL_HRTIM_CallbackIDTypeDef CallbackID)
  6059. {
  6060. HAL_StatusTypeDef status = HAL_OK;
  6061. /* Process locked */
  6062. __HAL_LOCK(hhrtim);
  6063. if (HAL_HRTIM_STATE_READY == hhrtim->State)
  6064. {
  6065. switch (CallbackID)
  6066. {
  6067. case HAL_HRTIM_FAULT1CALLBACK_CB_ID :
  6068. hhrtim->Fault1Callback = HAL_HRTIM_Fault1Callback;
  6069. break;
  6070. case HAL_HRTIM_FAULT2CALLBACK_CB_ID :
  6071. hhrtim->Fault2Callback = HAL_HRTIM_Fault2Callback;
  6072. break;
  6073. case HAL_HRTIM_FAULT3CALLBACK_CB_ID :
  6074. hhrtim->Fault3Callback = HAL_HRTIM_Fault3Callback;
  6075. break;
  6076. case HAL_HRTIM_FAULT4CALLBACK_CB_ID :
  6077. hhrtim->Fault4Callback = HAL_HRTIM_Fault4Callback;
  6078. break;
  6079. case HAL_HRTIM_FAULT5CALLBACK_CB_ID :
  6080. hhrtim->Fault5Callback = HAL_HRTIM_Fault5Callback;
  6081. break;
  6082. case HAL_HRTIM_SYSTEMFAULTCALLBACK_CB_ID :
  6083. hhrtim->SystemFaultCallback = HAL_HRTIM_SystemFaultCallback;
  6084. break;
  6085. case HAL_HRTIM_BURSTMODEPERIODCALLBACK_CB_ID :
  6086. hhrtim->BurstModePeriodCallback = HAL_HRTIM_BurstModePeriodCallback;
  6087. break;
  6088. case HAL_HRTIM_SYNCHRONIZATIONEVENTCALLBACK_CB_ID :
  6089. hhrtim->SynchronizationEventCallback = HAL_HRTIM_SynchronizationEventCallback;
  6090. break;
  6091. case HAL_HRTIM_ERRORCALLBACK_CB_ID :
  6092. hhrtim->ErrorCallback = HAL_HRTIM_ErrorCallback;
  6093. break;
  6094. case HAL_HRTIM_MSPINIT_CB_ID :
  6095. hhrtim->MspInitCallback = HAL_HRTIM_MspInit;
  6096. break;
  6097. case HAL_HRTIM_MSPDEINIT_CB_ID :
  6098. hhrtim->MspDeInitCallback = HAL_HRTIM_MspDeInit;
  6099. break;
  6100. default :
  6101. /* Update the state */
  6102. hhrtim->State = HAL_HRTIM_STATE_INVALID_CALLBACK;
  6103. /* Return error status */
  6104. status = HAL_ERROR;
  6105. break;
  6106. }
  6107. }
  6108. else if (HAL_HRTIM_STATE_RESET == hhrtim->State)
  6109. {
  6110. switch (CallbackID)
  6111. {
  6112. case HAL_HRTIM_MSPINIT_CB_ID :
  6113. hhrtim->MspInitCallback = HAL_HRTIM_MspInit;
  6114. break;
  6115. case HAL_HRTIM_MSPDEINIT_CB_ID :
  6116. hhrtim->MspDeInitCallback = HAL_HRTIM_MspDeInit;
  6117. break;
  6118. default :
  6119. /* Update the state */
  6120. hhrtim->State = HAL_HRTIM_STATE_INVALID_CALLBACK;
  6121. /* Return error status */
  6122. status = HAL_ERROR;
  6123. break;
  6124. }
  6125. }
  6126. else
  6127. {
  6128. /* Update the state */
  6129. hhrtim->State = HAL_HRTIM_STATE_INVALID_CALLBACK;
  6130. /* Return error status */
  6131. status = HAL_ERROR;
  6132. }
  6133. /* Release Lock */
  6134. __HAL_UNLOCK(hhrtim);
  6135. return status;
  6136. }
  6137. /**
  6138. * @brief HRTIM Timer x callback function registration
  6139. * @param hhrtim pointer to HAL HRTIM handle
  6140. * @param CallbackID ID of the HRTIM Timer x callback function to register
  6141. * This parameter can be one of the following values:
  6142. * @arg HAL_HRTIM_REGISTERSUPDATECALLBACK_CB_ID
  6143. * @arg HAL_HRTIM_REPETITIONEVENTCALLBACK_CB_ID
  6144. * @arg HAL_HRTIM_COMPARE1EVENTCALLBACK_CB_ID
  6145. * @arg HAL_HRTIM_COMPARE2EVENTCALLBACK_CB_ID
  6146. * @arg HAL_HRTIM_COMPARE3EVENTCALLBACK_CB_ID
  6147. * @arg HAL_HRTIM_COMPARE4EVENTCALLBACK_CB_ID
  6148. * @arg HAL_HRTIM_CAPTURE1EVENTCALLBACK_CB_ID
  6149. * @arg HAL_HRTIM_CAPTURE2EVENTCALLBACK_CB_ID
  6150. * @arg HAL_HRTIM_DELAYEDPROTECTIONCALLBACK_CB_ID
  6151. * @arg HAL_HRTIM_COUNTERRESETCALLBACK_CB_ID
  6152. * @arg HAL_HRTIM_OUTPUT1SETCALLBACK_CB_ID
  6153. * @arg HAL_HRTIM_OUTPUT1RESETCALLBACK_CB_ID
  6154. * @arg HAL_HRTIM_OUTPUT2SETCALLBACK_CB_ID
  6155. * @arg HAL_HRTIM_OUTPUT2RESETCALLBACK_CB_ID
  6156. * @arg HAL_HRTIM_BURSTDMATRANSFERCALLBACK_CB_ID
  6157. * @param pCallback Callback function pointer
  6158. * @retval HAL status
  6159. */
  6160. HAL_StatusTypeDef HAL_HRTIM_TIMxRegisterCallback(HRTIM_HandleTypeDef * hhrtim,
  6161. HAL_HRTIM_CallbackIDTypeDef CallbackID,
  6162. pHRTIM_TIMxCallbackTypeDef pCallback)
  6163. {
  6164. HAL_StatusTypeDef status = HAL_OK;
  6165. if (pCallback == NULL)
  6166. {
  6167. /* Update the state */
  6168. hhrtim->State = HAL_HRTIM_STATE_INVALID_CALLBACK;
  6169. return HAL_ERROR;
  6170. }
  6171. /* Process locked */
  6172. __HAL_LOCK(hhrtim);
  6173. if (HAL_HRTIM_STATE_READY == hhrtim->State)
  6174. {
  6175. switch (CallbackID)
  6176. {
  6177. case HAL_HRTIM_REGISTERSUPDATECALLBACK_CB_ID :
  6178. hhrtim->RegistersUpdateCallback = pCallback;
  6179. break;
  6180. case HAL_HRTIM_REPETITIONEVENTCALLBACK_CB_ID :
  6181. hhrtim->RepetitionEventCallback = pCallback;
  6182. break;
  6183. case HAL_HRTIM_COMPARE1EVENTCALLBACK_CB_ID :
  6184. hhrtim->Compare1EventCallback = pCallback;
  6185. break;
  6186. case HAL_HRTIM_COMPARE2EVENTCALLBACK_CB_ID :
  6187. hhrtim->Compare2EventCallback = pCallback;
  6188. break;
  6189. case HAL_HRTIM_COMPARE3EVENTCALLBACK_CB_ID :
  6190. hhrtim->Compare3EventCallback = pCallback;
  6191. break;
  6192. case HAL_HRTIM_COMPARE4EVENTCALLBACK_CB_ID :
  6193. hhrtim->Compare4EventCallback = pCallback;
  6194. break;
  6195. case HAL_HRTIM_CAPTURE1EVENTCALLBACK_CB_ID :
  6196. hhrtim->Capture1EventCallback = pCallback;
  6197. break;
  6198. case HAL_HRTIM_CAPTURE2EVENTCALLBACK_CB_ID :
  6199. hhrtim->Capture2EventCallback = pCallback;
  6200. break;
  6201. case HAL_HRTIM_DELAYEDPROTECTIONCALLBACK_CB_ID :
  6202. hhrtim->DelayedProtectionCallback = pCallback;
  6203. break;
  6204. case HAL_HRTIM_COUNTERRESETCALLBACK_CB_ID :
  6205. hhrtim->CounterResetCallback = pCallback;
  6206. break;
  6207. case HAL_HRTIM_OUTPUT1SETCALLBACK_CB_ID :
  6208. hhrtim->Output1SetCallback = pCallback;
  6209. break;
  6210. case HAL_HRTIM_OUTPUT1RESETCALLBACK_CB_ID :
  6211. hhrtim->Output1ResetCallback = pCallback;
  6212. break;
  6213. case HAL_HRTIM_OUTPUT2SETCALLBACK_CB_ID :
  6214. hhrtim->Output2SetCallback = pCallback;
  6215. break;
  6216. case HAL_HRTIM_OUTPUT2RESETCALLBACK_CB_ID :
  6217. hhrtim->Output2ResetCallback = pCallback;
  6218. break;
  6219. case HAL_HRTIM_BURSTDMATRANSFERCALLBACK_CB_ID :
  6220. hhrtim->BurstDMATransferCallback = pCallback;
  6221. break;
  6222. default :
  6223. /* Update the state */
  6224. hhrtim->State = HAL_HRTIM_STATE_INVALID_CALLBACK;
  6225. /* Return error status */
  6226. status = HAL_ERROR;
  6227. break;
  6228. }
  6229. }
  6230. else
  6231. {
  6232. /* Update the state */
  6233. hhrtim->State = HAL_HRTIM_STATE_INVALID_CALLBACK;
  6234. /* Return error status */
  6235. status = HAL_ERROR;
  6236. }
  6237. /* Release Lock */
  6238. __HAL_UNLOCK(hhrtim);
  6239. return status;
  6240. }
  6241. /**
  6242. * @brief HRTIM Timer x callback function un-registration
  6243. * @param hhrtim pointer to HAL HRTIM handle
  6244. * @param CallbackID ID of the HRTIM callback Timer x function to unregister
  6245. * This parameter can be one of the following values:
  6246. * @arg HAL_HRTIM_REGISTERSUPDATECALLBACK_CB_ID
  6247. * @arg HAL_HRTIM_REPETITIONEVENTCALLBACK_CB_ID
  6248. * @arg HAL_HRTIM_COMPARE1EVENTCALLBACK_CB_ID
  6249. * @arg HAL_HRTIM_COMPARE2EVENTCALLBACK_CB_ID
  6250. * @arg HAL_HRTIM_COMPARE3EVENTCALLBACK_CB_ID
  6251. * @arg HAL_HRTIM_COMPARE4EVENTCALLBACK_CB_ID
  6252. * @arg HAL_HRTIM_CAPTURE1EVENTCALLBACK_CB_ID
  6253. * @arg HAL_HRTIM_CAPTURE2EVENTCALLBACK_CB_ID
  6254. * @arg HAL_HRTIM_DELAYEDPROTECTIONCALLBACK_CB_ID
  6255. * @arg HAL_HRTIM_COUNTERRESETCALLBACK_CB_ID
  6256. * @arg HAL_HRTIM_OUTPUT1SETCALLBACK_CB_ID
  6257. * @arg HAL_HRTIM_OUTPUT1RESETCALLBACK_CB_ID
  6258. * @arg HAL_HRTIM_OUTPUT2SETCALLBACK_CB_ID
  6259. * @arg HAL_HRTIM_OUTPUT2RESETCALLBACK_CB_ID
  6260. * @arg HAL_HRTIM_BURSTDMATRANSFERCALLBACK_CB_ID
  6261. * @retval HAL status
  6262. */
  6263. HAL_StatusTypeDef HAL_HRTIM_TIMxUnRegisterCallback(HRTIM_HandleTypeDef * hhrtim,
  6264. HAL_HRTIM_CallbackIDTypeDef CallbackID)
  6265. {
  6266. HAL_StatusTypeDef status = HAL_OK;
  6267. /* Process locked */
  6268. __HAL_LOCK(hhrtim);
  6269. if (HAL_HRTIM_STATE_READY == hhrtim->State)
  6270. {
  6271. switch (CallbackID)
  6272. {
  6273. case HAL_HRTIM_REGISTERSUPDATECALLBACK_CB_ID :
  6274. hhrtim->RegistersUpdateCallback = HAL_HRTIM_RegistersUpdateCallback;
  6275. break;
  6276. case HAL_HRTIM_REPETITIONEVENTCALLBACK_CB_ID :
  6277. hhrtim->RepetitionEventCallback = HAL_HRTIM_RepetitionEventCallback;
  6278. break;
  6279. case HAL_HRTIM_COMPARE1EVENTCALLBACK_CB_ID :
  6280. hhrtim->Compare1EventCallback = HAL_HRTIM_Compare1EventCallback;
  6281. break;
  6282. case HAL_HRTIM_COMPARE2EVENTCALLBACK_CB_ID :
  6283. hhrtim->Compare2EventCallback = HAL_HRTIM_Compare2EventCallback;
  6284. break;
  6285. case HAL_HRTIM_COMPARE3EVENTCALLBACK_CB_ID :
  6286. hhrtim->Compare3EventCallback = HAL_HRTIM_Compare3EventCallback;
  6287. break;
  6288. case HAL_HRTIM_COMPARE4EVENTCALLBACK_CB_ID :
  6289. hhrtim->Compare4EventCallback = HAL_HRTIM_Compare4EventCallback;
  6290. break;
  6291. case HAL_HRTIM_CAPTURE1EVENTCALLBACK_CB_ID :
  6292. hhrtim->Capture1EventCallback = HAL_HRTIM_Capture1EventCallback;
  6293. break;
  6294. case HAL_HRTIM_CAPTURE2EVENTCALLBACK_CB_ID :
  6295. hhrtim->Capture2EventCallback = HAL_HRTIM_Capture2EventCallback;
  6296. break;
  6297. case HAL_HRTIM_DELAYEDPROTECTIONCALLBACK_CB_ID :
  6298. hhrtim->DelayedProtectionCallback = HAL_HRTIM_DelayedProtectionCallback;
  6299. break;
  6300. case HAL_HRTIM_COUNTERRESETCALLBACK_CB_ID :
  6301. hhrtim->CounterResetCallback = HAL_HRTIM_CounterResetCallback;
  6302. break;
  6303. case HAL_HRTIM_OUTPUT1SETCALLBACK_CB_ID :
  6304. hhrtim->Output1SetCallback = HAL_HRTIM_Output1SetCallback;
  6305. break;
  6306. case HAL_HRTIM_OUTPUT1RESETCALLBACK_CB_ID :
  6307. hhrtim->Output1ResetCallback = HAL_HRTIM_Output1ResetCallback;
  6308. break;
  6309. case HAL_HRTIM_OUTPUT2SETCALLBACK_CB_ID :
  6310. hhrtim->Output2SetCallback = HAL_HRTIM_Output2SetCallback;
  6311. break;
  6312. case HAL_HRTIM_OUTPUT2RESETCALLBACK_CB_ID :
  6313. hhrtim->Output2ResetCallback = HAL_HRTIM_Output2ResetCallback;
  6314. break;
  6315. case HAL_HRTIM_BURSTDMATRANSFERCALLBACK_CB_ID :
  6316. hhrtim->BurstDMATransferCallback = HAL_HRTIM_BurstDMATransferCallback;
  6317. break;
  6318. default :
  6319. /* Update the state */
  6320. hhrtim->State = HAL_HRTIM_STATE_INVALID_CALLBACK;
  6321. /* Return error status */
  6322. status = HAL_ERROR;
  6323. break;
  6324. }
  6325. }
  6326. else
  6327. {
  6328. /* Update the state */
  6329. hhrtim->State = HAL_HRTIM_STATE_INVALID_CALLBACK;
  6330. /* Return error status */
  6331. status = HAL_ERROR;
  6332. }
  6333. /* Release Lock */
  6334. __HAL_UNLOCK(hhrtim);
  6335. return status;
  6336. }
  6337. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  6338. /**
  6339. * @}
  6340. */
  6341. /**
  6342. * @}
  6343. */
  6344. /** @addtogroup HRTIM_Private_Functions
  6345. * @{
  6346. */
  6347. /**
  6348. * @brief Configure the master timer time base
  6349. * @param hhrtim pointer to HAL HRTIM handle
  6350. * @param pTimeBaseCfg pointer to the time base configuration structure
  6351. * @retval None
  6352. */
  6353. static void HRTIM_MasterBase_Config(HRTIM_HandleTypeDef * hhrtim,
  6354. HRTIM_TimeBaseCfgTypeDef * pTimeBaseCfg)
  6355. {
  6356. uint32_t hrtim_mcr;
  6357. /* Configure master timer */
  6358. hrtim_mcr = hhrtim->Instance->sMasterRegs.MCR;
  6359. /* Set the prescaler ratio */
  6360. hrtim_mcr &= (uint32_t) ~(HRTIM_MCR_CK_PSC);
  6361. hrtim_mcr |= (uint32_t)pTimeBaseCfg->PrescalerRatio;
  6362. /* Set the operating mode */
  6363. hrtim_mcr &= (uint32_t) ~(HRTIM_MCR_CONT | HRTIM_MCR_RETRIG);
  6364. hrtim_mcr |= (uint32_t)pTimeBaseCfg->Mode;
  6365. /* Update the HRTIM registers */
  6366. hhrtim->Instance->sMasterRegs.MCR = hrtim_mcr;
  6367. hhrtim->Instance->sMasterRegs.MPER = pTimeBaseCfg->Period;
  6368. hhrtim->Instance->sMasterRegs.MREP = pTimeBaseCfg->RepetitionCounter;
  6369. }
  6370. /**
  6371. * @brief Configure timing unit (Timer A to Timer E) time base
  6372. * @param hhrtim pointer to HAL HRTIM handle
  6373. * @param TimerIdx Timer index
  6374. * @param pTimeBaseCfg pointer to the time base configuration structure
  6375. * @retval None
  6376. */
  6377. static void HRTIM_TimingUnitBase_Config(HRTIM_HandleTypeDef * hhrtim,
  6378. uint32_t TimerIdx ,
  6379. HRTIM_TimeBaseCfgTypeDef * pTimeBaseCfg)
  6380. {
  6381. uint32_t hrtim_timcr;
  6382. /* Configure master timing unit */
  6383. hrtim_timcr = hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR;
  6384. /* Set the prescaler ratio */
  6385. hrtim_timcr &= (uint32_t) ~(HRTIM_TIMCR_CK_PSC);
  6386. hrtim_timcr |= (uint32_t)pTimeBaseCfg->PrescalerRatio;
  6387. /* Set the operating mode */
  6388. hrtim_timcr &= (uint32_t) ~(HRTIM_TIMCR_CONT | HRTIM_TIMCR_RETRIG);
  6389. hrtim_timcr |= (uint32_t)pTimeBaseCfg->Mode;
  6390. /* Update the HRTIM registers */
  6391. hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR = hrtim_timcr;
  6392. hhrtim->Instance->sTimerxRegs[TimerIdx].PERxR = pTimeBaseCfg->Period;
  6393. hhrtim->Instance->sTimerxRegs[TimerIdx].REPxR = pTimeBaseCfg->RepetitionCounter;
  6394. }
  6395. /**
  6396. * @brief Configure the master timer in waveform mode
  6397. * @param hhrtim pointer to HAL HRTIM handle
  6398. * @param pTimerCfg pointer to the timer configuration data structure
  6399. * @retval None
  6400. */
  6401. static void HRTIM_MasterWaveform_Config(HRTIM_HandleTypeDef * hhrtim,
  6402. HRTIM_TimerCfgTypeDef * pTimerCfg)
  6403. {
  6404. uint32_t hrtim_mcr;
  6405. uint32_t hrtim_bmcr;
  6406. /* Configure master timer */
  6407. hrtim_mcr = hhrtim->Instance->sMasterRegs.MCR;
  6408. hrtim_bmcr = hhrtim->Instance->sCommonRegs.BMCR;
  6409. /* Enable/Disable the half mode */
  6410. hrtim_mcr &= ~(HRTIM_MCR_HALF);
  6411. hrtim_mcr |= pTimerCfg->HalfModeEnable;
  6412. /* Enable/Disable the timer start upon synchronization event reception */
  6413. hrtim_mcr &= ~(HRTIM_MCR_SYNCSTRTM);
  6414. hrtim_mcr |= pTimerCfg->StartOnSync;
  6415. /* Enable/Disable the timer reset upon synchronization event reception */
  6416. hrtim_mcr &= ~(HRTIM_MCR_SYNCRSTM);
  6417. hrtim_mcr |= pTimerCfg->ResetOnSync;
  6418. /* Enable/Disable the DAC synchronization event generation */
  6419. hrtim_mcr &= ~(HRTIM_MCR_DACSYNC);
  6420. hrtim_mcr |= pTimerCfg->DACSynchro;
  6421. /* Enable/Disable preload meachanism for timer registers */
  6422. hrtim_mcr &= ~(HRTIM_MCR_PREEN);
  6423. hrtim_mcr |= pTimerCfg->PreloadEnable;
  6424. /* Master timer registers update handling */
  6425. hrtim_mcr &= ~(HRTIM_MCR_BRSTDMA);
  6426. hrtim_mcr |= (pTimerCfg->UpdateGating << 2U);
  6427. /* Enable/Disable registers update on repetition */
  6428. hrtim_mcr &= ~(HRTIM_MCR_MREPU);
  6429. hrtim_mcr |= pTimerCfg->RepetitionUpdate;
  6430. /* Set the timer burst mode */
  6431. hrtim_bmcr &= ~(HRTIM_BMCR_MTBM);
  6432. hrtim_bmcr |= pTimerCfg->BurstMode;
  6433. /* Update the HRTIM registers */
  6434. hhrtim->Instance->sMasterRegs.MCR = hrtim_mcr;
  6435. hhrtim->Instance->sCommonRegs.BMCR = hrtim_bmcr;
  6436. }
  6437. /**
  6438. * @brief Configure timing unit (Timer A to Timer E) in waveform mode
  6439. * @param hhrtim pointer to HAL HRTIM handle
  6440. * @param TimerIdx Timer index
  6441. * @param pTimerCfg pointer to the timer configuration data structure
  6442. * @retval None
  6443. */
  6444. static void HRTIM_TimingUnitWaveform_Config(HRTIM_HandleTypeDef * hhrtim,
  6445. uint32_t TimerIdx,
  6446. HRTIM_TimerCfgTypeDef * pTimerCfg)
  6447. {
  6448. uint32_t hrtim_timcr;
  6449. uint32_t hrtim_timfltr;
  6450. uint32_t hrtim_timoutr;
  6451. uint32_t hrtim_timrstr;
  6452. uint32_t hrtim_bmcr;
  6453. /* UPDGAT bitfield must be reset before programming a new value */
  6454. hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR &= ~(HRTIM_TIMCR_UPDGAT);
  6455. /* Configure timing unit (Timer A to Timer E) */
  6456. hrtim_timcr = hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR;
  6457. hrtim_timfltr = hhrtim->Instance->sTimerxRegs[TimerIdx].FLTxR;
  6458. hrtim_timoutr = hhrtim->Instance->sTimerxRegs[TimerIdx].OUTxR;
  6459. hrtim_bmcr = hhrtim->Instance->sCommonRegs.BMCR;
  6460. /* Enable/Disable the half mode */
  6461. hrtim_timcr &= ~(HRTIM_TIMCR_HALF);
  6462. hrtim_timcr |= pTimerCfg->HalfModeEnable;
  6463. /* Enable/Disable the timer start upon synchronization event reception */
  6464. hrtim_timcr &= ~(HRTIM_TIMCR_SYNCSTRT);
  6465. hrtim_timcr |= pTimerCfg->StartOnSync;
  6466. /* Enable/Disable the timer reset upon synchronization event reception */
  6467. hrtim_timcr &= ~(HRTIM_TIMCR_SYNCRST);
  6468. hrtim_timcr |= pTimerCfg->ResetOnSync;
  6469. /* Enable/Disable the DAC synchronization event generation */
  6470. hrtim_timcr &= ~(HRTIM_TIMCR_DACSYNC);
  6471. hrtim_timcr |= pTimerCfg->DACSynchro;
  6472. /* Enable/Disable preload meachanism for timer registers */
  6473. hrtim_timcr &= ~(HRTIM_TIMCR_PREEN);
  6474. hrtim_timcr |= pTimerCfg->PreloadEnable;
  6475. /* Timing unit registers update handling */
  6476. hrtim_timcr &= ~(HRTIM_TIMCR_UPDGAT);
  6477. hrtim_timcr |= pTimerCfg->UpdateGating;
  6478. /* Enable/Disable registers update on repetition */
  6479. hrtim_timcr &= ~(HRTIM_TIMCR_TREPU);
  6480. if (pTimerCfg->RepetitionUpdate == HRTIM_UPDATEONREPETITION_ENABLED)
  6481. {
  6482. hrtim_timcr |= HRTIM_TIMCR_TREPU;
  6483. }
  6484. /* Set the push-pull mode */
  6485. hrtim_timcr &= ~(HRTIM_TIMCR_PSHPLL);
  6486. hrtim_timcr |= pTimerCfg->PushPull;
  6487. /* Enable/Disable registers update on timer counter reset */
  6488. hrtim_timcr &= ~(HRTIM_TIMCR_TRSTU);
  6489. hrtim_timcr |= pTimerCfg->ResetUpdate;
  6490. /* Set the timer update trigger */
  6491. hrtim_timcr &= ~(HRTIM_TIMCR_TIMUPDATETRIGGER);
  6492. hrtim_timcr |= pTimerCfg->UpdateTrigger;
  6493. /* Enable/Disable the fault channel at timer level */
  6494. hrtim_timfltr &= ~(HRTIM_FLTR_FLTxEN);
  6495. hrtim_timfltr |= (pTimerCfg->FaultEnable & HRTIM_FLTR_FLTxEN);
  6496. /* Lock/Unlock fault sources at timer level */
  6497. hrtim_timfltr &= ~(HRTIM_FLTR_FLTLCK);
  6498. hrtim_timfltr |= pTimerCfg->FaultLock;
  6499. /* The deadtime cannot be used simultaneously with the push-pull mode */
  6500. if (pTimerCfg->PushPull == HRTIM_TIMPUSHPULLMODE_DISABLED)
  6501. {
  6502. /* Enable/Disable dead time insertion at timer level */
  6503. hrtim_timoutr &= ~(HRTIM_OUTR_DTEN);
  6504. hrtim_timoutr |= pTimerCfg->DeadTimeInsertion;
  6505. }
  6506. /* Enable/Disable delayed protection at timer level
  6507. Delayed Idle is available whatever the timer operating mode (regular, push-pull)
  6508. Balanced Idle is only available in push-pull mode
  6509. */
  6510. if ( ((pTimerCfg->DelayedProtectionMode != HRTIM_TIMER_A_B_C_DELAYEDPROTECTION_BALANCED_EEV6)
  6511. && (pTimerCfg->DelayedProtectionMode != HRTIM_TIMER_A_B_C_DELAYEDPROTECTION_BALANCED_EEV7))
  6512. || (pTimerCfg->PushPull == HRTIM_TIMPUSHPULLMODE_ENABLED))
  6513. {
  6514. hrtim_timoutr &= ~(HRTIM_OUTR_DLYPRT| HRTIM_OUTR_DLYPRTEN);
  6515. hrtim_timoutr |= pTimerCfg->DelayedProtectionMode;
  6516. }
  6517. /* Set the timer counter reset trigger */
  6518. hrtim_timrstr = pTimerCfg->ResetTrigger;
  6519. /* Set the timer burst mode */
  6520. switch (TimerIdx)
  6521. {
  6522. case HRTIM_TIMERINDEX_TIMER_A:
  6523. {
  6524. hrtim_bmcr &= ~(HRTIM_BMCR_TABM);
  6525. hrtim_bmcr |= ( pTimerCfg->BurstMode << 1U);
  6526. break;
  6527. }
  6528. case HRTIM_TIMERINDEX_TIMER_B:
  6529. {
  6530. hrtim_bmcr &= ~(HRTIM_BMCR_TBBM);
  6531. hrtim_bmcr |= ( pTimerCfg->BurstMode << 2U);
  6532. break;
  6533. }
  6534. case HRTIM_TIMERINDEX_TIMER_C:
  6535. {
  6536. hrtim_bmcr &= ~(HRTIM_BMCR_TCBM);
  6537. hrtim_bmcr |= ( pTimerCfg->BurstMode << 3U);
  6538. break;
  6539. }
  6540. case HRTIM_TIMERINDEX_TIMER_D:
  6541. {
  6542. hrtim_bmcr &= ~(HRTIM_BMCR_TDBM);
  6543. hrtim_bmcr |= ( pTimerCfg->BurstMode << 4U);
  6544. break;
  6545. }
  6546. case HRTIM_TIMERINDEX_TIMER_E:
  6547. {
  6548. hrtim_bmcr &= ~(HRTIM_BMCR_TEBM);
  6549. hrtim_bmcr |= ( pTimerCfg->BurstMode << 5U);
  6550. break;
  6551. }
  6552. default:
  6553. break;
  6554. }
  6555. /* Update the HRTIM registers */
  6556. hhrtim->Instance->sTimerxRegs[TimerIdx].TIMxCR = hrtim_timcr;
  6557. hhrtim->Instance->sTimerxRegs[TimerIdx].FLTxR = hrtim_timfltr;
  6558. hhrtim->Instance->sTimerxRegs[TimerIdx].OUTxR = hrtim_timoutr;
  6559. hhrtim->Instance->sTimerxRegs[TimerIdx].RSTxR = hrtim_timrstr;
  6560. hhrtim->Instance->sCommonRegs.BMCR = hrtim_bmcr;
  6561. }
  6562. /**
  6563. * @brief Configure a capture unit
  6564. * @param hhrtim pointer to HAL HRTIM handle
  6565. * @param TimerIdx Timer index
  6566. * @param CaptureUnit Capture unit identifier
  6567. * @param Event Event reference
  6568. * @retval None
  6569. */
  6570. static void HRTIM_CaptureUnitConfig(HRTIM_HandleTypeDef * hhrtim,
  6571. uint32_t TimerIdx,
  6572. uint32_t CaptureUnit,
  6573. uint32_t Event)
  6574. {
  6575. uint32_t CaptureTrigger = 0xFFFFFFFFU;
  6576. switch (Event)
  6577. {
  6578. case HRTIM_EVENT_1:
  6579. {
  6580. CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_1;
  6581. break;
  6582. }
  6583. case HRTIM_EVENT_2:
  6584. {
  6585. CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_2;
  6586. break;
  6587. }
  6588. case HRTIM_EVENT_3:
  6589. {
  6590. CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_3;
  6591. break;
  6592. }
  6593. case HRTIM_EVENT_4:
  6594. {
  6595. CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_4;
  6596. break;
  6597. }
  6598. case HRTIM_EVENT_5:
  6599. {
  6600. CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_5;
  6601. break;
  6602. }
  6603. case HRTIM_EVENT_6:
  6604. {
  6605. CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_6;
  6606. break;
  6607. }
  6608. case HRTIM_EVENT_7:
  6609. {
  6610. CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_7;
  6611. break;
  6612. }
  6613. case HRTIM_EVENT_8:
  6614. {
  6615. CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_8;
  6616. break;
  6617. }
  6618. case HRTIM_EVENT_9:
  6619. {
  6620. CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_9;
  6621. break;
  6622. }
  6623. case HRTIM_EVENT_10:
  6624. {
  6625. CaptureTrigger = HRTIM_CAPTURETRIGGER_EEV_10;
  6626. break;
  6627. }
  6628. default:
  6629. break;
  6630. }
  6631. switch (CaptureUnit)
  6632. {
  6633. case HRTIM_CAPTUREUNIT_1:
  6634. {
  6635. hhrtim->TimerParam[TimerIdx].CaptureTrigger1 = CaptureTrigger;
  6636. break;
  6637. }
  6638. case HRTIM_CAPTUREUNIT_2:
  6639. {
  6640. hhrtim->TimerParam[TimerIdx].CaptureTrigger2 = CaptureTrigger;
  6641. break;
  6642. }
  6643. default:
  6644. break;
  6645. }
  6646. }
  6647. /**
  6648. * @brief Configure the output of a timing unit
  6649. * @param hhrtim pointer to HAL HRTIM handle
  6650. * @param TimerIdx Timer index
  6651. * @param Output timing unit output identifier
  6652. * @param pOutputCfg pointer to the output configuration data structure
  6653. * @retval None
  6654. */
  6655. static void HRTIM_OutputConfig(HRTIM_HandleTypeDef * hhrtim,
  6656. uint32_t TimerIdx,
  6657. uint32_t Output,
  6658. HRTIM_OutputCfgTypeDef * pOutputCfg)
  6659. {
  6660. uint32_t hrtim_outr;
  6661. uint32_t hrtim_dtr;
  6662. uint32_t shift = 0U;
  6663. hrtim_outr = hhrtim->Instance->sTimerxRegs[TimerIdx].OUTxR;
  6664. hrtim_dtr = hhrtim->Instance->sTimerxRegs[TimerIdx].DTxR;
  6665. switch (Output)
  6666. {
  6667. case HRTIM_OUTPUT_TA1:
  6668. case HRTIM_OUTPUT_TB1:
  6669. case HRTIM_OUTPUT_TC1:
  6670. case HRTIM_OUTPUT_TD1:
  6671. case HRTIM_OUTPUT_TE1:
  6672. {
  6673. /* Set the output set/reset crossbar */
  6674. hhrtim->Instance->sTimerxRegs[TimerIdx].SETx1R = pOutputCfg->SetSource;
  6675. hhrtim->Instance->sTimerxRegs[TimerIdx].RSTx1R = pOutputCfg->ResetSource;
  6676. break;
  6677. }
  6678. case HRTIM_OUTPUT_TA2:
  6679. case HRTIM_OUTPUT_TB2:
  6680. case HRTIM_OUTPUT_TC2:
  6681. case HRTIM_OUTPUT_TD2:
  6682. case HRTIM_OUTPUT_TE2:
  6683. {
  6684. /* Set the output set/reset crossbar */
  6685. hhrtim->Instance->sTimerxRegs[TimerIdx].SETx2R = pOutputCfg->SetSource;
  6686. hhrtim->Instance->sTimerxRegs[TimerIdx].RSTx2R = pOutputCfg->ResetSource;
  6687. shift = 16U;
  6688. break;
  6689. }
  6690. default:
  6691. break;
  6692. }
  6693. /* Clear output config */
  6694. hrtim_outr &= ~((HRTIM_OUTR_POL1 |
  6695. HRTIM_OUTR_IDLM1 |
  6696. HRTIM_OUTR_IDLES1|
  6697. HRTIM_OUTR_FAULT1|
  6698. HRTIM_OUTR_CHP1 |
  6699. HRTIM_OUTR_DIDL1) << shift);
  6700. /* Set the polarity */
  6701. hrtim_outr |= (pOutputCfg->Polarity << shift);
  6702. /* Set the IDLE mode */
  6703. hrtim_outr |= (pOutputCfg->IdleMode << shift);
  6704. /* Set the IDLE state */
  6705. hrtim_outr |= (pOutputCfg->IdleLevel << shift);
  6706. /* Set the FAULT state */
  6707. hrtim_outr |= (pOutputCfg->FaultLevel << shift);
  6708. /* Set the chopper mode */
  6709. hrtim_outr |= (pOutputCfg->ChopperModeEnable << shift);
  6710. /* Set the burst mode entry mode : deadtime insertion when entering the idle
  6711. state during a burst mode operation is allowed only under the following
  6712. conditions:
  6713. - the outputs is active during the burst mode (IDLES=1U)
  6714. - positive deadtimes (SDTR/SDTF set to 0U)
  6715. */
  6716. if ((pOutputCfg->IdleLevel == HRTIM_OUTPUTIDLELEVEL_ACTIVE) &&
  6717. ((hrtim_dtr & HRTIM_DTR_SDTR) == (uint32_t)RESET) &&
  6718. ((hrtim_dtr & HRTIM_DTR_SDTF) == (uint32_t)RESET))
  6719. {
  6720. hrtim_outr |= (pOutputCfg->BurstModeEntryDelayed << shift);
  6721. }
  6722. /* Update HRTIM register */
  6723. hhrtim->Instance->sTimerxRegs[TimerIdx].OUTxR = hrtim_outr;
  6724. }
  6725. /**
  6726. * @brief Configure an external event channel
  6727. * @param hhrtim pointer to HAL HRTIM handle
  6728. * @param Event Event channel identifier
  6729. * @param pEventCfg pointer to the event channel configuration data structure
  6730. * @retval None
  6731. */
  6732. static void HRTIM_EventConfig(HRTIM_HandleTypeDef * hhrtim,
  6733. uint32_t Event,
  6734. HRTIM_EventCfgTypeDef *pEventCfg)
  6735. {
  6736. uint32_t hrtim_eecr1;
  6737. uint32_t hrtim_eecr2;
  6738. uint32_t hrtim_eecr3;
  6739. /* Configure external event channel */
  6740. hrtim_eecr1 = hhrtim->Instance->sCommonRegs.EECR1;
  6741. hrtim_eecr2 = hhrtim->Instance->sCommonRegs.EECR2;
  6742. hrtim_eecr3 = hhrtim->Instance->sCommonRegs.EECR3;
  6743. switch (Event)
  6744. {
  6745. case HRTIM_EVENT_NONE:
  6746. {
  6747. /* Update the HRTIM registers */
  6748. hhrtim->Instance->sCommonRegs.EECR1 = 0U;
  6749. hhrtim->Instance->sCommonRegs.EECR2 = 0U;
  6750. hhrtim->Instance->sCommonRegs.EECR3 = 0U;
  6751. break;
  6752. }
  6753. case HRTIM_EVENT_1:
  6754. {
  6755. hrtim_eecr1 &= ~(HRTIM_EECR1_EE1SRC | HRTIM_EECR1_EE1POL | HRTIM_EECR1_EE1SNS | HRTIM_EECR1_EE1FAST);
  6756. hrtim_eecr1 |= (pEventCfg->Source & HRTIM_EECR1_EE1SRC);
  6757. hrtim_eecr1 |= (pEventCfg->Polarity & HRTIM_EECR1_EE1POL);
  6758. hrtim_eecr1 |= (pEventCfg->Sensitivity & HRTIM_EECR1_EE1SNS);
  6759. /* Update the HRTIM registers (all bitfields but EE1FAST bit) */
  6760. hhrtim->Instance->sCommonRegs.EECR1 = hrtim_eecr1;
  6761. /* Update the HRTIM registers (EE1FAST bit) */
  6762. hrtim_eecr1 |= (pEventCfg->FastMode & HRTIM_EECR1_EE1FAST);
  6763. hhrtim->Instance->sCommonRegs.EECR1 = hrtim_eecr1;
  6764. break;
  6765. }
  6766. case HRTIM_EVENT_2:
  6767. {
  6768. hrtim_eecr1 &= ~(HRTIM_EECR1_EE2SRC | HRTIM_EECR1_EE2POL | HRTIM_EECR1_EE2SNS | HRTIM_EECR1_EE2FAST);
  6769. hrtim_eecr1 |= ((pEventCfg->Source << 6U) & HRTIM_EECR1_EE2SRC);
  6770. hrtim_eecr1 |= ((pEventCfg->Polarity << 6U) & HRTIM_EECR1_EE2POL);
  6771. hrtim_eecr1 |= ((pEventCfg->Sensitivity << 6U) & HRTIM_EECR1_EE2SNS);
  6772. /* Update the HRTIM registers (all bitfields but EE2FAST bit) */
  6773. hhrtim->Instance->sCommonRegs.EECR1 = hrtim_eecr1;
  6774. /* Update the HRTIM registers (EE2FAST bit) */
  6775. hrtim_eecr1 |= ((pEventCfg->FastMode << 6U) & HRTIM_EECR1_EE2FAST);
  6776. hhrtim->Instance->sCommonRegs.EECR1 = hrtim_eecr1;
  6777. break;
  6778. }
  6779. case HRTIM_EVENT_3:
  6780. {
  6781. hrtim_eecr1 &= ~(HRTIM_EECR1_EE3SRC | HRTIM_EECR1_EE3POL | HRTIM_EECR1_EE3SNS | HRTIM_EECR1_EE3FAST);
  6782. hrtim_eecr1 |= ((pEventCfg->Source << 12U) & HRTIM_EECR1_EE3SRC);
  6783. hrtim_eecr1 |= ((pEventCfg->Polarity << 12U) & HRTIM_EECR1_EE3POL);
  6784. hrtim_eecr1 |= ((pEventCfg->Sensitivity << 12U) & HRTIM_EECR1_EE3SNS);
  6785. /* Update the HRTIM registers (all bitfields but EE3FAST bit) */
  6786. hhrtim->Instance->sCommonRegs.EECR1 = hrtim_eecr1;
  6787. /* Update the HRTIM registers (EE3FAST bit) */
  6788. hrtim_eecr1 |= ((pEventCfg->FastMode << 12U) & HRTIM_EECR1_EE3FAST);
  6789. hhrtim->Instance->sCommonRegs.EECR1 = hrtim_eecr1;
  6790. break;
  6791. }
  6792. case HRTIM_EVENT_4:
  6793. {
  6794. hrtim_eecr1 &= ~(HRTIM_EECR1_EE4SRC | HRTIM_EECR1_EE4POL | HRTIM_EECR1_EE4SNS | HRTIM_EECR1_EE4FAST);
  6795. hrtim_eecr1 |= ((pEventCfg->Source << 18U) & HRTIM_EECR1_EE4SRC);
  6796. hrtim_eecr1 |= ((pEventCfg->Polarity << 18U) & HRTIM_EECR1_EE4POL);
  6797. hrtim_eecr1 |= ((pEventCfg->Sensitivity << 18U) & HRTIM_EECR1_EE4SNS);
  6798. /* Update the HRTIM registers (all bitfields but EE4FAST bit) */
  6799. hhrtim->Instance->sCommonRegs.EECR1 = hrtim_eecr1;
  6800. /* Update the HRTIM registers (EE4FAST bit) */
  6801. hrtim_eecr1 |= ((pEventCfg->FastMode << 18U) & HRTIM_EECR1_EE4FAST);
  6802. hhrtim->Instance->sCommonRegs.EECR1 = hrtim_eecr1;
  6803. break;
  6804. }
  6805. case HRTIM_EVENT_5:
  6806. {
  6807. hrtim_eecr1 &= ~(HRTIM_EECR1_EE5SRC | HRTIM_EECR1_EE5POL | HRTIM_EECR1_EE5SNS | HRTIM_EECR1_EE5FAST);
  6808. hrtim_eecr1 |= ((pEventCfg->Source << 24U) & HRTIM_EECR1_EE5SRC);
  6809. hrtim_eecr1 |= ((pEventCfg->Polarity << 24U) & HRTIM_EECR1_EE5POL);
  6810. hrtim_eecr1 |= ((pEventCfg->Sensitivity << 24U) & HRTIM_EECR1_EE5SNS);
  6811. /* Update the HRTIM registers (all bitfields but EE5FAST bit) */
  6812. hhrtim->Instance->sCommonRegs.EECR1 = hrtim_eecr1;
  6813. /* Update the HRTIM registers (EE5FAST bit) */
  6814. hrtim_eecr1 |= ((pEventCfg->FastMode << 24U) & HRTIM_EECR1_EE5FAST);
  6815. hhrtim->Instance->sCommonRegs.EECR1 = hrtim_eecr1;
  6816. break;
  6817. }
  6818. case HRTIM_EVENT_6:
  6819. {
  6820. hrtim_eecr2 &= ~(HRTIM_EECR2_EE6SRC | HRTIM_EECR2_EE6POL | HRTIM_EECR2_EE6SNS);
  6821. hrtim_eecr2 |= (pEventCfg->Source & HRTIM_EECR2_EE6SRC);
  6822. hrtim_eecr2 |= (pEventCfg->Polarity & HRTIM_EECR2_EE6POL);
  6823. hrtim_eecr2 |= (pEventCfg->Sensitivity & HRTIM_EECR2_EE6SNS);
  6824. hrtim_eecr3 &= ~(HRTIM_EECR3_EE6F);
  6825. hrtim_eecr3 |= (pEventCfg->Filter & HRTIM_EECR3_EE6F);
  6826. /* Update the HRTIM registers */
  6827. hhrtim->Instance->sCommonRegs.EECR2 = hrtim_eecr2;
  6828. hhrtim->Instance->sCommonRegs.EECR3 = hrtim_eecr3;
  6829. break;
  6830. }
  6831. case HRTIM_EVENT_7:
  6832. {
  6833. hrtim_eecr2 &= ~(HRTIM_EECR2_EE7SRC | HRTIM_EECR2_EE7POL | HRTIM_EECR2_EE7SNS);
  6834. hrtim_eecr2 |= ((pEventCfg->Source << 6U) & HRTIM_EECR2_EE7SRC);
  6835. hrtim_eecr2 |= ((pEventCfg->Polarity << 6U) & HRTIM_EECR2_EE7POL);
  6836. hrtim_eecr2 |= ((pEventCfg->Sensitivity << 6U) & HRTIM_EECR2_EE7SNS);
  6837. hrtim_eecr3 &= ~(HRTIM_EECR3_EE7F);
  6838. hrtim_eecr3 |= ((pEventCfg->Filter << 6U) & HRTIM_EECR3_EE7F);
  6839. /* Update the HRTIM registers */
  6840. hhrtim->Instance->sCommonRegs.EECR2 = hrtim_eecr2;
  6841. hhrtim->Instance->sCommonRegs.EECR3 = hrtim_eecr3;
  6842. break;
  6843. }
  6844. case HRTIM_EVENT_8:
  6845. {
  6846. hrtim_eecr2 &= ~(HRTIM_EECR2_EE8SRC | HRTIM_EECR2_EE8POL | HRTIM_EECR2_EE8SNS);
  6847. hrtim_eecr2 |= ((pEventCfg->Source << 12U) & HRTIM_EECR2_EE8SRC);
  6848. hrtim_eecr2 |= ((pEventCfg->Polarity << 12U) & HRTIM_EECR2_EE8POL);
  6849. hrtim_eecr2 |= ((pEventCfg->Sensitivity << 12U) & HRTIM_EECR2_EE8SNS);
  6850. hrtim_eecr3 &= ~(HRTIM_EECR3_EE8F);
  6851. hrtim_eecr3 |= ((pEventCfg->Filter << 12U) & HRTIM_EECR3_EE8F );
  6852. /* Update the HRTIM registers */
  6853. hhrtim->Instance->sCommonRegs.EECR2 = hrtim_eecr2;
  6854. hhrtim->Instance->sCommonRegs.EECR3 = hrtim_eecr3;
  6855. break;
  6856. }
  6857. case HRTIM_EVENT_9:
  6858. {
  6859. hrtim_eecr2 &= ~(HRTIM_EECR2_EE9SRC | HRTIM_EECR2_EE9POL | HRTIM_EECR2_EE9SNS);
  6860. hrtim_eecr2 |= ((pEventCfg->Source << 18U) & HRTIM_EECR2_EE9SRC);
  6861. hrtim_eecr2 |= ((pEventCfg->Polarity << 18U) & HRTIM_EECR2_EE9POL);
  6862. hrtim_eecr2 |= ((pEventCfg->Sensitivity << 18U) & HRTIM_EECR2_EE9SNS);
  6863. hrtim_eecr3 &= ~(HRTIM_EECR3_EE9F);
  6864. hrtim_eecr3 |= ((pEventCfg->Filter << 18U) & HRTIM_EECR3_EE9F);
  6865. /* Update the HRTIM registers */
  6866. hhrtim->Instance->sCommonRegs.EECR2 = hrtim_eecr2;
  6867. hhrtim->Instance->sCommonRegs.EECR3 = hrtim_eecr3;
  6868. break;
  6869. }
  6870. case HRTIM_EVENT_10:
  6871. {
  6872. hrtim_eecr2 &= ~(HRTIM_EECR2_EE10SRC | HRTIM_EECR2_EE10POL | HRTIM_EECR2_EE10SNS);
  6873. hrtim_eecr2 |= ((pEventCfg->Source << 24U) & HRTIM_EECR2_EE10SRC);
  6874. hrtim_eecr2 |= ((pEventCfg->Polarity << 24U) & HRTIM_EECR2_EE10POL);
  6875. hrtim_eecr2 |= ((pEventCfg->Sensitivity << 24U) & HRTIM_EECR2_EE10SNS);
  6876. hrtim_eecr3 &= ~(HRTIM_EECR3_EE10F);
  6877. hrtim_eecr3 |= ((pEventCfg->Filter << 24U) & HRTIM_EECR3_EE10F);
  6878. /* Update the HRTIM registers */
  6879. hhrtim->Instance->sCommonRegs.EECR2 = hrtim_eecr2;
  6880. hhrtim->Instance->sCommonRegs.EECR3 = hrtim_eecr3;
  6881. break;
  6882. }
  6883. default:
  6884. break;
  6885. }
  6886. }
  6887. /**
  6888. * @brief Configure the timer counter reset
  6889. * @param hhrtim pointer to HAL HRTIM handle
  6890. * @param TimerIdx Timer index
  6891. * @param Event Event channel identifier
  6892. * @retval None
  6893. */
  6894. static void HRTIM_TIM_ResetConfig(HRTIM_HandleTypeDef * hhrtim,
  6895. uint32_t TimerIdx,
  6896. uint32_t Event)
  6897. {
  6898. switch (Event)
  6899. {
  6900. case HRTIM_EVENT_1:
  6901. {
  6902. hhrtim->Instance->sTimerxRegs[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_1;
  6903. break;
  6904. }
  6905. case HRTIM_EVENT_2:
  6906. {
  6907. hhrtim->Instance->sTimerxRegs[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_2;
  6908. break;
  6909. }
  6910. case HRTIM_EVENT_3:
  6911. {
  6912. hhrtim->Instance->sTimerxRegs[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_3;
  6913. break;
  6914. }
  6915. case HRTIM_EVENT_4:
  6916. {
  6917. hhrtim->Instance->sTimerxRegs[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_4;
  6918. break;
  6919. }
  6920. case HRTIM_EVENT_5:
  6921. {
  6922. hhrtim->Instance->sTimerxRegs[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_5;
  6923. break;
  6924. }
  6925. case HRTIM_EVENT_6:
  6926. {
  6927. hhrtim->Instance->sTimerxRegs[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_6;
  6928. break;
  6929. }
  6930. case HRTIM_EVENT_7:
  6931. {
  6932. hhrtim->Instance->sTimerxRegs[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_7;
  6933. break;
  6934. }
  6935. case HRTIM_EVENT_8:
  6936. {
  6937. hhrtim->Instance->sTimerxRegs[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_8;
  6938. break;
  6939. }
  6940. case HRTIM_EVENT_9:
  6941. {
  6942. hhrtim->Instance->sTimerxRegs[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_9;
  6943. break;
  6944. }
  6945. case HRTIM_EVENT_10:
  6946. {
  6947. hhrtim->Instance->sTimerxRegs[TimerIdx].RSTxR = HRTIM_TIMRESETTRIGGER_EEV_10;
  6948. break;
  6949. }
  6950. default:
  6951. break;
  6952. }
  6953. }
  6954. /**
  6955. * @brief Return the interrupt to enable or disable according to the
  6956. * OC mode.
  6957. * @param hhrtim pointer to HAL HRTIM handle
  6958. * @param TimerIdx Timer index
  6959. * @param OCChannel Timer output
  6960. * This parameter can be one of the following values:
  6961. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  6962. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  6963. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  6964. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  6965. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  6966. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  6967. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  6968. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  6969. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  6970. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  6971. * @retval Interrupt to enable or disable
  6972. */
  6973. static uint32_t HRTIM_GetITFromOCMode(HRTIM_HandleTypeDef * hhrtim,
  6974. uint32_t TimerIdx,
  6975. uint32_t OCChannel)
  6976. {
  6977. uint32_t hrtim_set;
  6978. uint32_t hrtim_reset;
  6979. uint32_t interrupt = 0U;
  6980. switch (OCChannel)
  6981. {
  6982. case HRTIM_OUTPUT_TA1:
  6983. case HRTIM_OUTPUT_TB1:
  6984. case HRTIM_OUTPUT_TC1:
  6985. case HRTIM_OUTPUT_TD1:
  6986. case HRTIM_OUTPUT_TE1:
  6987. {
  6988. /* Retreives actual OC mode and set interrupt accordingly */
  6989. hrtim_set = hhrtim->Instance->sTimerxRegs[TimerIdx].SETx1R;
  6990. hrtim_reset = hhrtim->Instance->sTimerxRegs[TimerIdx].RSTx1R;
  6991. if (((hrtim_set & HRTIM_OUTPUTSET_TIMCMP1) == HRTIM_OUTPUTSET_TIMCMP1) &&
  6992. ((hrtim_reset & HRTIM_OUTPUTRESET_TIMCMP1) == HRTIM_OUTPUTRESET_TIMCMP1))
  6993. {
  6994. /* OC mode: HRTIM_BASICOCMODE_TOGGLE */
  6995. interrupt = HRTIM_TIM_IT_CMP1;
  6996. }
  6997. else if (((hrtim_set & HRTIM_OUTPUTSET_TIMCMP1) == HRTIM_OUTPUTSET_TIMCMP1) &&
  6998. (hrtim_reset == 0U))
  6999. {
  7000. /* OC mode: HRTIM_BASICOCMODE_ACTIVE */
  7001. interrupt = HRTIM_TIM_IT_SET1;
  7002. }
  7003. else if ((hrtim_set == 0U) &&
  7004. ((hrtim_reset & HRTIM_OUTPUTRESET_TIMCMP1) == HRTIM_OUTPUTRESET_TIMCMP1))
  7005. {
  7006. /* OC mode: HRTIM_BASICOCMODE_INACTIVE */
  7007. interrupt = HRTIM_TIM_IT_RST1;
  7008. }
  7009. else
  7010. {
  7011. /* nothing to do */
  7012. }
  7013. break;
  7014. }
  7015. case HRTIM_OUTPUT_TA2:
  7016. case HRTIM_OUTPUT_TB2:
  7017. case HRTIM_OUTPUT_TC2:
  7018. case HRTIM_OUTPUT_TD2:
  7019. case HRTIM_OUTPUT_TE2:
  7020. {
  7021. /* Retreives actual OC mode and set interrupt accordingly */
  7022. hrtim_set = hhrtim->Instance->sTimerxRegs[TimerIdx].SETx2R;
  7023. hrtim_reset = hhrtim->Instance->sTimerxRegs[TimerIdx].RSTx2R;
  7024. if (((hrtim_set & HRTIM_OUTPUTSET_TIMCMP2) == HRTIM_OUTPUTSET_TIMCMP2) &&
  7025. ((hrtim_reset & HRTIM_OUTPUTRESET_TIMCMP2) == HRTIM_OUTPUTRESET_TIMCMP2))
  7026. {
  7027. /* OC mode: HRTIM_BASICOCMODE_TOGGLE */
  7028. interrupt = HRTIM_TIM_IT_CMP2;
  7029. }
  7030. else if (((hrtim_set & HRTIM_OUTPUTSET_TIMCMP2) == HRTIM_OUTPUTSET_TIMCMP2) &&
  7031. (hrtim_reset == 0U))
  7032. {
  7033. /* OC mode: HRTIM_BASICOCMODE_ACTIVE */
  7034. interrupt = HRTIM_TIM_IT_SET2;
  7035. }
  7036. else if ((hrtim_set == 0U) &&
  7037. ((hrtim_reset & HRTIM_OUTPUTRESET_TIMCMP2) == HRTIM_OUTPUTRESET_TIMCMP2))
  7038. {
  7039. /* OC mode: HRTIM_BASICOCMODE_INACTIVE */
  7040. interrupt = HRTIM_TIM_IT_RST2;
  7041. }
  7042. else
  7043. {
  7044. /* nothing to do */
  7045. }
  7046. break;
  7047. }
  7048. default:
  7049. break;
  7050. }
  7051. return interrupt;
  7052. }
  7053. /**
  7054. * @brief Return the DMA request to enable or disable according to the
  7055. * OC mode.
  7056. * @param hhrtim pointer to HAL HRTIM handle
  7057. * @param TimerIdx Timer index
  7058. * @param OCChannel Timer output
  7059. * This parameter can be one of the following values:
  7060. * @arg HRTIM_OUTPUT_TA1: Timer A - Output 1
  7061. * @arg HRTIM_OUTPUT_TA2: Timer A - Output 2
  7062. * @arg HRTIM_OUTPUT_TB1: Timer B - Output 1
  7063. * @arg HRTIM_OUTPUT_TB2: Timer B - Output 2
  7064. * @arg HRTIM_OUTPUT_TC1: Timer C - Output 1
  7065. * @arg HRTIM_OUTPUT_TC2: Timer C - Output 2
  7066. * @arg HRTIM_OUTPUT_TD1: Timer D - Output 1
  7067. * @arg HRTIM_OUTPUT_TD2: Timer D - Output 2
  7068. * @arg HRTIM_OUTPUT_TE1: Timer E - Output 1
  7069. * @arg HRTIM_OUTPUT_TE2: Timer E - Output 2
  7070. * @retval DMA request to enable or disable
  7071. */
  7072. static uint32_t HRTIM_GetDMAFromOCMode(HRTIM_HandleTypeDef * hhrtim,
  7073. uint32_t TimerIdx,
  7074. uint32_t OCChannel)
  7075. {
  7076. uint32_t hrtim_set;
  7077. uint32_t hrtim_reset;
  7078. uint32_t dma_request = 0U;
  7079. switch (OCChannel)
  7080. {
  7081. case HRTIM_OUTPUT_TA1:
  7082. case HRTIM_OUTPUT_TB1:
  7083. case HRTIM_OUTPUT_TC1:
  7084. case HRTIM_OUTPUT_TD1:
  7085. case HRTIM_OUTPUT_TE1:
  7086. {
  7087. /* Retreives actual OC mode and set dma_request accordingly */
  7088. hrtim_set = hhrtim->Instance->sTimerxRegs[TimerIdx].SETx1R;
  7089. hrtim_reset = hhrtim->Instance->sTimerxRegs[TimerIdx].RSTx1R;
  7090. if (((hrtim_set & HRTIM_OUTPUTSET_TIMCMP1) == HRTIM_OUTPUTSET_TIMCMP1) &&
  7091. ((hrtim_reset & HRTIM_OUTPUTRESET_TIMCMP1) == HRTIM_OUTPUTRESET_TIMCMP1))
  7092. {
  7093. /* OC mode: HRTIM_BASICOCMODE_TOGGLE */
  7094. dma_request = HRTIM_TIM_DMA_CMP1;
  7095. }
  7096. else if (((hrtim_set & HRTIM_OUTPUTSET_TIMCMP1) == HRTIM_OUTPUTSET_TIMCMP1) &&
  7097. (hrtim_reset == 0U))
  7098. {
  7099. /* OC mode: HRTIM_BASICOCMODE_ACTIVE */
  7100. dma_request = HRTIM_TIM_DMA_SET1;
  7101. }
  7102. else if ((hrtim_set == 0U) &&
  7103. ((hrtim_reset & HRTIM_OUTPUTRESET_TIMCMP1) == HRTIM_OUTPUTRESET_TIMCMP1))
  7104. {
  7105. /* OC mode: HRTIM_BASICOCMODE_INACTIVE */
  7106. dma_request = HRTIM_TIM_DMA_RST1;
  7107. }
  7108. else
  7109. {
  7110. /* nothing to do */
  7111. }
  7112. break;
  7113. }
  7114. case HRTIM_OUTPUT_TA2:
  7115. case HRTIM_OUTPUT_TB2:
  7116. case HRTIM_OUTPUT_TC2:
  7117. case HRTIM_OUTPUT_TD2:
  7118. case HRTIM_OUTPUT_TE2:
  7119. {
  7120. /* Retreives actual OC mode and set dma_request accordingly */
  7121. hrtim_set = hhrtim->Instance->sTimerxRegs[TimerIdx].SETx2R;
  7122. hrtim_reset = hhrtim->Instance->sTimerxRegs[TimerIdx].RSTx2R;
  7123. if (((hrtim_set & HRTIM_OUTPUTSET_TIMCMP2) == HRTIM_OUTPUTSET_TIMCMP2) &&
  7124. ((hrtim_reset & HRTIM_OUTPUTRESET_TIMCMP2) == HRTIM_OUTPUTRESET_TIMCMP2))
  7125. {
  7126. /* OC mode: HRTIM_BASICOCMODE_TOGGLE */
  7127. dma_request = HRTIM_TIM_DMA_CMP2;
  7128. }
  7129. else if (((hrtim_set & HRTIM_OUTPUTSET_TIMCMP2) == HRTIM_OUTPUTSET_TIMCMP2) &&
  7130. (hrtim_reset == 0U))
  7131. {
  7132. /* OC mode: HRTIM_BASICOCMODE_ACTIVE */
  7133. dma_request = HRTIM_TIM_DMA_SET2;
  7134. }
  7135. else if ((hrtim_set == 0U) &&
  7136. ((hrtim_reset & HRTIM_OUTPUTRESET_TIMCMP2) == HRTIM_OUTPUTRESET_TIMCMP2))
  7137. {
  7138. /* OC mode: HRTIM_BASICOCMODE_INACTIVE */
  7139. dma_request = HRTIM_TIM_DMA_RST2;
  7140. }
  7141. else
  7142. {
  7143. /* nothing to do */
  7144. }
  7145. break;
  7146. }
  7147. default:
  7148. break;
  7149. }
  7150. return dma_request;
  7151. }
  7152. static DMA_HandleTypeDef * HRTIM_GetDMAHandleFromTimerIdx(HRTIM_HandleTypeDef * hhrtim,
  7153. uint32_t TimerIdx)
  7154. {
  7155. DMA_HandleTypeDef * hdma = (DMA_HandleTypeDef *)NULL;
  7156. switch (TimerIdx)
  7157. {
  7158. case HRTIM_TIMERINDEX_MASTER:
  7159. {
  7160. hdma = hhrtim->hdmaMaster;
  7161. break;
  7162. }
  7163. case HRTIM_TIMERINDEX_TIMER_A:
  7164. {
  7165. hdma = hhrtim->hdmaTimerA;
  7166. break;
  7167. }
  7168. case HRTIM_TIMERINDEX_TIMER_B:
  7169. {
  7170. hdma = hhrtim->hdmaTimerB;
  7171. break;
  7172. }
  7173. case HRTIM_TIMERINDEX_TIMER_C:
  7174. {
  7175. hdma = hhrtim->hdmaTimerC;
  7176. break;
  7177. }
  7178. case HRTIM_TIMERINDEX_TIMER_D:
  7179. {
  7180. hdma = hhrtim->hdmaTimerD;
  7181. break;
  7182. }
  7183. case HRTIM_TIMERINDEX_TIMER_E:
  7184. {
  7185. hdma = hhrtim->hdmaTimerE;
  7186. break;
  7187. }
  7188. default:
  7189. break;
  7190. }
  7191. return hdma;
  7192. }
  7193. static uint32_t GetTimerIdxFromDMAHandle(HRTIM_HandleTypeDef * hhrtim,
  7194. DMA_HandleTypeDef * hdma)
  7195. {
  7196. uint32_t timed_idx = 0xFFFFFFFFU;
  7197. if (hdma == hhrtim->hdmaMaster)
  7198. {
  7199. timed_idx = HRTIM_TIMERINDEX_MASTER;
  7200. }
  7201. else if (hdma == hhrtim->hdmaTimerA)
  7202. {
  7203. timed_idx = HRTIM_TIMERINDEX_TIMER_A;
  7204. }
  7205. else if (hdma == hhrtim->hdmaTimerB)
  7206. {
  7207. timed_idx = HRTIM_TIMERINDEX_TIMER_B;
  7208. }
  7209. else if (hdma == hhrtim->hdmaTimerC)
  7210. {
  7211. timed_idx = HRTIM_TIMERINDEX_TIMER_C;
  7212. }
  7213. else if (hdma == hhrtim->hdmaTimerD)
  7214. {
  7215. timed_idx = HRTIM_TIMERINDEX_TIMER_D;
  7216. }
  7217. else if (hdma == hhrtim->hdmaTimerE)
  7218. {
  7219. timed_idx = HRTIM_TIMERINDEX_TIMER_E;
  7220. }
  7221. else
  7222. {
  7223. /* nothing to do */
  7224. }
  7225. return timed_idx;
  7226. }
  7227. /**
  7228. * @brief Force an immediate transfer from the preload to the active
  7229. * registers.
  7230. * @param hhrtim pointer to HAL HRTIM handle
  7231. * @param TimerIdx Timer index
  7232. * @retval None
  7233. */
  7234. static void HRTIM_ForceRegistersUpdate(HRTIM_HandleTypeDef * hhrtim,
  7235. uint32_t TimerIdx)
  7236. {
  7237. switch (TimerIdx)
  7238. {
  7239. case HRTIM_TIMERINDEX_MASTER:
  7240. {
  7241. hhrtim->Instance->sCommonRegs.CR2 |= HRTIM_CR2_MSWU;
  7242. break;
  7243. }
  7244. case HRTIM_TIMERINDEX_TIMER_A:
  7245. {
  7246. hhrtim->Instance->sCommonRegs.CR2 |= HRTIM_CR2_TASWU;
  7247. break;
  7248. }
  7249. case HRTIM_TIMERINDEX_TIMER_B:
  7250. {
  7251. hhrtim->Instance->sCommonRegs.CR2 |= HRTIM_CR2_TBSWU;
  7252. break;
  7253. }
  7254. case HRTIM_TIMERINDEX_TIMER_C:
  7255. {
  7256. hhrtim->Instance->sCommonRegs.CR2 |= HRTIM_CR2_TCSWU;
  7257. break;
  7258. }
  7259. case HRTIM_TIMERINDEX_TIMER_D:
  7260. {
  7261. hhrtim->Instance->sCommonRegs.CR2 |= HRTIM_CR2_TDSWU;
  7262. break;
  7263. }
  7264. case HRTIM_TIMERINDEX_TIMER_E:
  7265. {
  7266. hhrtim->Instance->sCommonRegs.CR2 |= HRTIM_CR2_TESWU;
  7267. break;
  7268. }
  7269. default:
  7270. break;
  7271. }
  7272. }
  7273. /**
  7274. * @brief HRTIM interrupts service routine
  7275. * @param hhrtim pointer to HAL HRTIM handle
  7276. * @retval None
  7277. */
  7278. static void HRTIM_HRTIM_ISR(HRTIM_HandleTypeDef * hhrtim)
  7279. {
  7280. /* Fault 1 event */
  7281. if(__HAL_HRTIM_GET_FLAG(hhrtim, HRTIM_FLAG_FLT1) != (uint32_t)RESET)
  7282. {
  7283. if(__HAL_HRTIM_GET_ITSTATUS(hhrtim, HRTIM_IT_FLT1) != RESET)
  7284. {
  7285. __HAL_HRTIM_CLEAR_IT(hhrtim, HRTIM_IT_FLT1);
  7286. /* Invoke Fault 1 event callback */
  7287. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7288. hhrtim->Fault1Callback(hhrtim);
  7289. #else
  7290. HAL_HRTIM_Fault1Callback(hhrtim);
  7291. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7292. }
  7293. }
  7294. /* Fault 2 event */
  7295. if(__HAL_HRTIM_GET_FLAG(hhrtim, HRTIM_FLAG_FLT2) != (uint32_t)RESET)
  7296. {
  7297. if(__HAL_HRTIM_GET_ITSTATUS(hhrtim, HRTIM_IT_FLT2) != RESET)
  7298. {
  7299. __HAL_HRTIM_CLEAR_IT(hhrtim, HRTIM_IT_FLT2);
  7300. /* Invoke Fault 2 event callback */
  7301. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7302. hhrtim->Fault2Callback(hhrtim);
  7303. #else
  7304. HAL_HRTIM_Fault2Callback(hhrtim);
  7305. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7306. }
  7307. }
  7308. /* Fault 3 event */
  7309. if(__HAL_HRTIM_GET_FLAG(hhrtim, HRTIM_FLAG_FLT3) != (uint32_t)RESET)
  7310. {
  7311. if(__HAL_HRTIM_GET_ITSTATUS(hhrtim, HRTIM_IT_FLT3) != RESET)
  7312. {
  7313. __HAL_HRTIM_CLEAR_IT(hhrtim, HRTIM_IT_FLT3);
  7314. /* Invoke Fault 3 event callback */
  7315. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7316. hhrtim->Fault3Callback(hhrtim);
  7317. #else
  7318. HAL_HRTIM_Fault3Callback(hhrtim);
  7319. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7320. }
  7321. }
  7322. /* Fault 4 event */
  7323. if(__HAL_HRTIM_GET_FLAG(hhrtim, HRTIM_FLAG_FLT4) != (uint32_t)RESET)
  7324. {
  7325. if(__HAL_HRTIM_GET_ITSTATUS(hhrtim, HRTIM_IT_FLT4) != RESET)
  7326. {
  7327. __HAL_HRTIM_CLEAR_IT(hhrtim, HRTIM_IT_FLT4);
  7328. /* Invoke Fault 4 event callback */
  7329. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7330. hhrtim->Fault4Callback(hhrtim);
  7331. #else
  7332. HAL_HRTIM_Fault4Callback(hhrtim);
  7333. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7334. }
  7335. }
  7336. /* Fault 5 event */
  7337. if(__HAL_HRTIM_GET_FLAG(hhrtim, HRTIM_FLAG_FLT5) != (uint32_t)RESET)
  7338. {
  7339. if(__HAL_HRTIM_GET_ITSTATUS(hhrtim, HRTIM_IT_FLT5) != RESET)
  7340. {
  7341. __HAL_HRTIM_CLEAR_IT(hhrtim, HRTIM_IT_FLT5);
  7342. /* Invoke Fault 5 event callback */
  7343. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7344. hhrtim->Fault5Callback(hhrtim);
  7345. #else
  7346. HAL_HRTIM_Fault5Callback(hhrtim);
  7347. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7348. }
  7349. }
  7350. /* System fault event */
  7351. if(__HAL_HRTIM_GET_FLAG(hhrtim, HRTIM_FLAG_SYSFLT) != (uint32_t)RESET)
  7352. {
  7353. if(__HAL_HRTIM_GET_ITSTATUS(hhrtim, HRTIM_IT_SYSFLT) != RESET)
  7354. {
  7355. __HAL_HRTIM_CLEAR_IT(hhrtim, HRTIM_IT_SYSFLT);
  7356. /* Invoke System fault event callback */
  7357. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7358. hhrtim->SystemFaultCallback(hhrtim);
  7359. #else
  7360. HAL_HRTIM_SystemFaultCallback(hhrtim);
  7361. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7362. }
  7363. }
  7364. }
  7365. /**
  7366. * @brief Master timer interrupts service routine
  7367. * @param hhrtim pointer to HAL HRTIM handle
  7368. * @retval None
  7369. */
  7370. static void HRTIM_Master_ISR(HRTIM_HandleTypeDef * hhrtim)
  7371. {
  7372. /* Burst mode period event */
  7373. if(__HAL_HRTIM_GET_FLAG(hhrtim, HRTIM_FLAG_BMPER) != (uint32_t)RESET)
  7374. {
  7375. if(__HAL_HRTIM_GET_ITSTATUS(hhrtim, HRTIM_IT_BMPER) != RESET)
  7376. {
  7377. __HAL_HRTIM_CLEAR_IT(hhrtim, HRTIM_IT_BMPER);
  7378. /* Invoke Burst mode period event callback */
  7379. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7380. hhrtim->BurstModePeriodCallback(hhrtim);
  7381. #else
  7382. HAL_HRTIM_BurstModePeriodCallback(hhrtim);
  7383. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7384. }
  7385. }
  7386. /* Master timer compare 1 event */
  7387. if(__HAL_HRTIM_MASTER_GET_FLAG(hhrtim, HRTIM_MASTER_FLAG_MCMP1) != (uint32_t)RESET)
  7388. {
  7389. if(__HAL_HRTIM_MASTER_GET_ITSTATUS(hhrtim, HRTIM_MASTER_IT_MCMP1) != RESET)
  7390. {
  7391. __HAL_HRTIM_MASTER_CLEAR_IT(hhrtim, HRTIM_MASTER_IT_MCMP1);
  7392. /* Invoke compare 1 event callback */
  7393. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7394. hhrtim->Compare1EventCallback(hhrtim, HRTIM_TIMERINDEX_MASTER);
  7395. #else
  7396. HAL_HRTIM_Compare1EventCallback(hhrtim, HRTIM_TIMERINDEX_MASTER);
  7397. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7398. }
  7399. }
  7400. /* Master timer compare 2 event */
  7401. if(__HAL_HRTIM_MASTER_GET_FLAG(hhrtim, HRTIM_MASTER_FLAG_MCMP2) != (uint32_t)RESET)
  7402. {
  7403. if(__HAL_HRTIM_MASTER_GET_ITSTATUS(hhrtim, HRTIM_MASTER_IT_MCMP2) != RESET)
  7404. {
  7405. __HAL_HRTIM_MASTER_CLEAR_IT(hhrtim, HRTIM_MASTER_IT_MCMP2);
  7406. /* Invoke compare 2 event callback */
  7407. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7408. hhrtim->Compare2EventCallback(hhrtim, HRTIM_TIMERINDEX_MASTER);
  7409. #else
  7410. HAL_HRTIM_Compare2EventCallback(hhrtim, HRTIM_TIMERINDEX_MASTER);
  7411. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7412. }
  7413. }
  7414. /* Master timer compare 3 event */
  7415. if(__HAL_HRTIM_MASTER_GET_FLAG(hhrtim, HRTIM_MASTER_FLAG_MCMP3) != (uint32_t)RESET)
  7416. {
  7417. if(__HAL_HRTIM_MASTER_GET_ITSTATUS(hhrtim, HRTIM_MASTER_IT_MCMP3) != RESET)
  7418. {
  7419. __HAL_HRTIM_MASTER_CLEAR_IT(hhrtim, HRTIM_MASTER_IT_MCMP3);
  7420. /* Invoke compare 3 event callback */
  7421. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7422. hhrtim->Compare3EventCallback(hhrtim, HRTIM_TIMERINDEX_MASTER);
  7423. #else
  7424. HAL_HRTIM_Compare3EventCallback(hhrtim, HRTIM_TIMERINDEX_MASTER);
  7425. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7426. }
  7427. }
  7428. /* Master timer compare 4 event */
  7429. if(__HAL_HRTIM_MASTER_GET_FLAG(hhrtim, HRTIM_MASTER_FLAG_MCMP4) != (uint32_t)RESET)
  7430. {
  7431. if(__HAL_HRTIM_MASTER_GET_ITSTATUS(hhrtim, HRTIM_MASTER_IT_MCMP4) != RESET)
  7432. {
  7433. __HAL_HRTIM_MASTER_CLEAR_IT(hhrtim, HRTIM_MASTER_IT_MCMP4);
  7434. /* Invoke compare 4 event callback */
  7435. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7436. hhrtim->Compare4EventCallback(hhrtim, HRTIM_TIMERINDEX_MASTER);
  7437. #else
  7438. HAL_HRTIM_Compare4EventCallback(hhrtim, HRTIM_TIMERINDEX_MASTER);
  7439. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7440. }
  7441. }
  7442. /* Master timer repetition event */
  7443. if(__HAL_HRTIM_MASTER_GET_FLAG(hhrtim, HRTIM_MASTER_FLAG_MREP) != (uint32_t)RESET)
  7444. {
  7445. if(__HAL_HRTIM_MASTER_GET_ITSTATUS(hhrtim, HRTIM_MASTER_IT_MREP) != RESET)
  7446. {
  7447. __HAL_HRTIM_MASTER_CLEAR_IT(hhrtim, HRTIM_MASTER_IT_MREP);
  7448. /* Invoke repetition event callback */
  7449. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7450. hhrtim->RepetitionEventCallback(hhrtim, HRTIM_TIMERINDEX_MASTER);
  7451. #else
  7452. HAL_HRTIM_RepetitionEventCallback(hhrtim, HRTIM_TIMERINDEX_MASTER);
  7453. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7454. }
  7455. }
  7456. /* Synchronization input event */
  7457. if(__HAL_HRTIM_MASTER_GET_FLAG(hhrtim, HRTIM_MASTER_FLAG_SYNC) != (uint32_t)RESET)
  7458. {
  7459. if(__HAL_HRTIM_MASTER_GET_ITSTATUS(hhrtim, HRTIM_MASTER_IT_SYNC) != RESET)
  7460. {
  7461. __HAL_HRTIM_MASTER_CLEAR_IT(hhrtim, HRTIM_MASTER_IT_SYNC);
  7462. /* Invoke synchronization event callback */
  7463. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7464. hhrtim->SynchronizationEventCallback(hhrtim);
  7465. #else
  7466. HAL_HRTIM_SynchronizationEventCallback(hhrtim);
  7467. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7468. }
  7469. }
  7470. /* Master timer registers update event */
  7471. if(__HAL_HRTIM_MASTER_GET_FLAG(hhrtim, HRTIM_MASTER_FLAG_MUPD) != (uint32_t)RESET)
  7472. {
  7473. if(__HAL_HRTIM_MASTER_GET_ITSTATUS(hhrtim, HRTIM_MASTER_IT_MUPD) != RESET)
  7474. {
  7475. __HAL_HRTIM_MASTER_CLEAR_IT(hhrtim, HRTIM_MASTER_IT_MUPD);
  7476. /* Invoke registers update event callback */
  7477. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7478. hhrtim->RegistersUpdateCallback(hhrtim, HRTIM_TIMERINDEX_MASTER);
  7479. #else
  7480. HAL_HRTIM_RegistersUpdateCallback(hhrtim, HRTIM_TIMERINDEX_MASTER);
  7481. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7482. }
  7483. }
  7484. }
  7485. /**
  7486. * @brief Timer interrupts service routine
  7487. * @param hhrtim pointer to HAL HRTIM handle
  7488. * @param TimerIdx Timer index
  7489. * This parameter can be one of the following values:
  7490. * @arg HRTIM_TIMERINDEX_TIMER_A for timer A
  7491. * @arg HRTIM_TIMERINDEX_TIMER_B for timer B
  7492. * @arg HRTIM_TIMERINDEX_TIMER_C for timer C
  7493. * @arg HRTIM_TIMERINDEX_TIMER_D for timer D
  7494. * @arg HRTIM_TIMERINDEX_TIMER_E for timer E
  7495. * @retval None
  7496. */
  7497. static void HRTIM_Timer_ISR(HRTIM_HandleTypeDef * hhrtim,
  7498. uint32_t TimerIdx)
  7499. {
  7500. /* Timer compare 1 event */
  7501. if(__HAL_HRTIM_TIMER_GET_FLAG(hhrtim, TimerIdx, HRTIM_TIM_FLAG_CMP1) != (uint32_t)RESET)
  7502. {
  7503. if(__HAL_HRTIM_TIMER_GET_ITSTATUS(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP1) != RESET)
  7504. {
  7505. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP1);
  7506. /* Invoke compare 1 event callback */
  7507. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7508. hhrtim->Compare1EventCallback(hhrtim, TimerIdx);
  7509. #else
  7510. HAL_HRTIM_Compare1EventCallback(hhrtim, TimerIdx);
  7511. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7512. }
  7513. }
  7514. /* Timer compare 2 event */
  7515. if(__HAL_HRTIM_TIMER_GET_FLAG(hhrtim, TimerIdx, HRTIM_TIM_FLAG_CMP2) != (uint32_t)RESET)
  7516. {
  7517. if(__HAL_HRTIM_TIMER_GET_ITSTATUS(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP2) != RESET)
  7518. {
  7519. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP2);
  7520. /* Invoke compare 2 event callback */
  7521. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7522. hhrtim->Compare2EventCallback(hhrtim, TimerIdx);
  7523. #else
  7524. HAL_HRTIM_Compare2EventCallback(hhrtim, TimerIdx);
  7525. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7526. }
  7527. }
  7528. /* Timer compare 3 event */
  7529. if(__HAL_HRTIM_TIMER_GET_FLAG(hhrtim, TimerIdx, HRTIM_TIM_FLAG_CMP3) != (uint32_t)RESET)
  7530. {
  7531. if(__HAL_HRTIM_TIMER_GET_ITSTATUS(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP3) != RESET)
  7532. {
  7533. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP3);
  7534. /* Invoke compare 3 event callback */
  7535. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7536. hhrtim->Compare3EventCallback(hhrtim, TimerIdx);
  7537. #else
  7538. HAL_HRTIM_Compare3EventCallback(hhrtim, TimerIdx);
  7539. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7540. }
  7541. }
  7542. /* Timer compare 4 event */
  7543. if(__HAL_HRTIM_TIMER_GET_FLAG(hhrtim, TimerIdx, HRTIM_TIM_FLAG_CMP4) != (uint32_t)RESET)
  7544. {
  7545. if(__HAL_HRTIM_TIMER_GET_ITSTATUS(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP4) != RESET)
  7546. {
  7547. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CMP4);
  7548. /* Invoke compare 4 event callback */
  7549. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7550. hhrtim->Compare4EventCallback(hhrtim, TimerIdx);
  7551. #else
  7552. HAL_HRTIM_Compare4EventCallback(hhrtim, TimerIdx);
  7553. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7554. }
  7555. }
  7556. /* Timer repetition event */
  7557. if(__HAL_HRTIM_TIMER_GET_FLAG(hhrtim, TimerIdx, HRTIM_TIM_FLAG_REP) != (uint32_t)RESET)
  7558. {
  7559. if(__HAL_HRTIM_TIMER_GET_ITSTATUS(hhrtim, TimerIdx, HRTIM_TIM_IT_REP) != RESET)
  7560. {
  7561. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_REP);
  7562. /* Invoke repetition event callback */
  7563. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7564. hhrtim->RepetitionEventCallback(hhrtim, TimerIdx);
  7565. #else
  7566. HAL_HRTIM_RepetitionEventCallback(hhrtim, TimerIdx);
  7567. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7568. }
  7569. }
  7570. /* Timer registers update event */
  7571. if(__HAL_HRTIM_TIMER_GET_FLAG(hhrtim, TimerIdx, HRTIM_TIM_FLAG_UPD) != (uint32_t)RESET)
  7572. {
  7573. if(__HAL_HRTIM_TIMER_GET_ITSTATUS(hhrtim, TimerIdx, HRTIM_TIM_IT_UPD) != RESET)
  7574. {
  7575. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_UPD);
  7576. /* Invoke registers update event callback */
  7577. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7578. hhrtim->RegistersUpdateCallback(hhrtim, TimerIdx);
  7579. #else
  7580. HAL_HRTIM_RegistersUpdateCallback(hhrtim, TimerIdx);
  7581. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7582. }
  7583. }
  7584. /* Timer capture 1 event */
  7585. if(__HAL_HRTIM_TIMER_GET_FLAG(hhrtim, TimerIdx, HRTIM_TIM_FLAG_CPT1) != (uint32_t)RESET)
  7586. {
  7587. if(__HAL_HRTIM_TIMER_GET_ITSTATUS(hhrtim, TimerIdx, HRTIM_TIM_IT_CPT1) != RESET)
  7588. {
  7589. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CPT1);
  7590. /* Invoke capture 1 event callback */
  7591. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7592. hhrtim->Capture1EventCallback(hhrtim, TimerIdx);
  7593. #else
  7594. HAL_HRTIM_Capture1EventCallback(hhrtim, TimerIdx);
  7595. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7596. }
  7597. }
  7598. /* Timer capture 2 event */
  7599. if(__HAL_HRTIM_TIMER_GET_FLAG(hhrtim, TimerIdx, HRTIM_TIM_FLAG_CPT2) != (uint32_t)RESET)
  7600. {
  7601. if(__HAL_HRTIM_TIMER_GET_ITSTATUS(hhrtim, TimerIdx, HRTIM_TIM_IT_CPT2) != RESET)
  7602. {
  7603. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_CPT2);
  7604. /* Invoke capture 2 event callback */
  7605. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7606. hhrtim->Capture2EventCallback(hhrtim, TimerIdx);
  7607. #else
  7608. HAL_HRTIM_Capture2EventCallback(hhrtim, TimerIdx);
  7609. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7610. }
  7611. }
  7612. /* Timer output 1 set event */
  7613. if(__HAL_HRTIM_TIMER_GET_FLAG(hhrtim, TimerIdx, HRTIM_TIM_FLAG_SET1) != (uint32_t)RESET)
  7614. {
  7615. if(__HAL_HRTIM_TIMER_GET_ITSTATUS(hhrtim, TimerIdx, HRTIM_TIM_IT_SET1) != RESET)
  7616. {
  7617. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_SET1);
  7618. /* Invoke output 1 set event callback */
  7619. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7620. hhrtim->Output1SetCallback(hhrtim, TimerIdx);
  7621. #else
  7622. HAL_HRTIM_Output1SetCallback(hhrtim, TimerIdx);
  7623. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7624. }
  7625. }
  7626. /* Timer output 1 reset event */
  7627. if(__HAL_HRTIM_TIMER_GET_FLAG(hhrtim, TimerIdx, HRTIM_TIM_FLAG_RST1) != (uint32_t)RESET)
  7628. {
  7629. if(__HAL_HRTIM_TIMER_GET_ITSTATUS(hhrtim, TimerIdx, HRTIM_TIM_IT_RST1) != RESET)
  7630. {
  7631. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_RST1);
  7632. /* Invoke output 1 reset event callback */
  7633. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7634. hhrtim->Output1ResetCallback(hhrtim, TimerIdx);
  7635. #else
  7636. HAL_HRTIM_Output1ResetCallback(hhrtim, TimerIdx);
  7637. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7638. }
  7639. }
  7640. /* Timer output 2 set event */
  7641. if(__HAL_HRTIM_TIMER_GET_FLAG(hhrtim, TimerIdx, HRTIM_TIM_FLAG_SET2) != (uint32_t)RESET)
  7642. {
  7643. if(__HAL_HRTIM_TIMER_GET_ITSTATUS(hhrtim, TimerIdx, HRTIM_TIM_IT_SET2) != RESET)
  7644. {
  7645. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_SET2);
  7646. /* Invoke output 2 set event callback */
  7647. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7648. hhrtim->Output2SetCallback(hhrtim, TimerIdx);
  7649. #else
  7650. HAL_HRTIM_Output2SetCallback(hhrtim, TimerIdx);
  7651. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7652. }
  7653. }
  7654. /* Timer output 2 reset event */
  7655. if(__HAL_HRTIM_TIMER_GET_FLAG(hhrtim, TimerIdx, HRTIM_TIM_FLAG_RST2) != (uint32_t)RESET)
  7656. {
  7657. if(__HAL_HRTIM_TIMER_GET_ITSTATUS(hhrtim, TimerIdx, HRTIM_TIM_IT_RST2) != RESET)
  7658. {
  7659. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_RST2);
  7660. /* Invoke output 2 reset event callback */
  7661. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7662. hhrtim->Output2ResetCallback(hhrtim, TimerIdx);
  7663. #else
  7664. HAL_HRTIM_Output2ResetCallback(hhrtim, TimerIdx);
  7665. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7666. }
  7667. }
  7668. /* Timer reset event */
  7669. if(__HAL_HRTIM_TIMER_GET_FLAG(hhrtim, TimerIdx, HRTIM_TIM_FLAG_RST) != (uint32_t)RESET)
  7670. {
  7671. if(__HAL_HRTIM_TIMER_GET_ITSTATUS(hhrtim, TimerIdx, HRTIM_TIM_IT_RST) != RESET)
  7672. {
  7673. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_RST);
  7674. /* Invoke timer reset callback */
  7675. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7676. hhrtim->CounterResetCallback(hhrtim, TimerIdx);
  7677. #else
  7678. HAL_HRTIM_CounterResetCallback(hhrtim, TimerIdx);
  7679. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7680. }
  7681. }
  7682. /* Delayed protection event */
  7683. if(__HAL_HRTIM_TIMER_GET_FLAG(hhrtim, TimerIdx, HRTIM_TIM_FLAG_DLYPRT) != (uint32_t)RESET)
  7684. {
  7685. if(__HAL_HRTIM_TIMER_GET_ITSTATUS(hhrtim, TimerIdx, HRTIM_TIM_IT_DLYPRT) != RESET)
  7686. {
  7687. __HAL_HRTIM_TIMER_CLEAR_IT(hhrtim, TimerIdx, HRTIM_TIM_IT_DLYPRT);
  7688. /* Invoke delayed protection callback */
  7689. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7690. hhrtim->DelayedProtectionCallback(hhrtim, TimerIdx);
  7691. #else
  7692. HAL_HRTIM_DelayedProtectionCallback(hhrtim, TimerIdx);
  7693. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7694. }
  7695. }
  7696. }
  7697. /**
  7698. * @brief DMA callback invoked upon master timer related DMA request completion
  7699. * @param hdma pointer to DMA handle.
  7700. * @retval None
  7701. */
  7702. static void HRTIM_DMAMasterCplt(DMA_HandleTypeDef *hdma)
  7703. {
  7704. HRTIM_HandleTypeDef * hrtim = (HRTIM_HandleTypeDef *)((DMA_HandleTypeDef* )hdma)->Parent;
  7705. if ((hrtim->Instance->sMasterRegs.MDIER & HRTIM_MASTER_DMA_MCMP1) != (uint32_t)RESET)
  7706. {
  7707. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7708. hrtim->Compare1EventCallback(hrtim, HRTIM_TIMERINDEX_MASTER);
  7709. #else
  7710. HAL_HRTIM_Compare1EventCallback(hrtim, HRTIM_TIMERINDEX_MASTER);
  7711. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7712. }
  7713. else if ((hrtim->Instance->sMasterRegs.MDIER & HRTIM_MASTER_DMA_MCMP2) != (uint32_t)RESET)
  7714. {
  7715. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7716. hrtim->Compare2EventCallback(hrtim, HRTIM_TIMERINDEX_MASTER);
  7717. #else
  7718. HAL_HRTIM_Compare2EventCallback(hrtim, HRTIM_TIMERINDEX_MASTER);
  7719. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7720. }
  7721. else if ((hrtim->Instance->sMasterRegs.MDIER & HRTIM_MASTER_DMA_MCMP3) != (uint32_t)RESET)
  7722. {
  7723. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7724. hrtim->Compare3EventCallback(hrtim, HRTIM_TIMERINDEX_MASTER);
  7725. #else
  7726. HAL_HRTIM_Compare3EventCallback(hrtim, HRTIM_TIMERINDEX_MASTER);
  7727. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7728. }
  7729. else if ((hrtim->Instance->sMasterRegs.MDIER & HRTIM_MASTER_DMA_MCMP4) != (uint32_t)RESET)
  7730. {
  7731. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7732. hrtim->Compare4EventCallback(hrtim, HRTIM_TIMERINDEX_MASTER);
  7733. #else
  7734. HAL_HRTIM_Compare4EventCallback(hrtim, HRTIM_TIMERINDEX_MASTER);
  7735. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7736. }
  7737. else if ((hrtim->Instance->sMasterRegs.MDIER & HRTIM_MASTER_DMA_SYNC) != (uint32_t)RESET)
  7738. {
  7739. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7740. hrtim->SynchronizationEventCallback(hrtim);
  7741. #else
  7742. HAL_HRTIM_SynchronizationEventCallback(hrtim);
  7743. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7744. }
  7745. else if ((hrtim->Instance->sMasterRegs.MDIER & HRTIM_MASTER_DMA_MUPD) != (uint32_t)RESET)
  7746. {
  7747. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7748. hrtim->RegistersUpdateCallback(hrtim, HRTIM_TIMERINDEX_MASTER);
  7749. #else
  7750. HAL_HRTIM_RegistersUpdateCallback(hrtim, HRTIM_TIMERINDEX_MASTER);
  7751. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7752. }
  7753. else if ((hrtim->Instance->sMasterRegs.MDIER & HRTIM_MASTER_DMA_MREP) != (uint32_t)RESET)
  7754. {
  7755. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7756. hrtim->RepetitionEventCallback(hrtim, HRTIM_TIMERINDEX_MASTER);
  7757. #else
  7758. HAL_HRTIM_RepetitionEventCallback(hrtim, HRTIM_TIMERINDEX_MASTER);
  7759. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7760. }
  7761. else
  7762. {
  7763. /* nothing to do */
  7764. }
  7765. }
  7766. /**
  7767. * @brief DMA callback invoked upon timer A..E related DMA request completion
  7768. * @param hdma pointer to DMA handle.
  7769. * @retval None
  7770. */
  7771. static void HRTIM_DMATimerxCplt(DMA_HandleTypeDef *hdma)
  7772. {
  7773. uint8_t timer_idx;
  7774. HRTIM_HandleTypeDef * hrtim = (HRTIM_HandleTypeDef *)((DMA_HandleTypeDef* )hdma)->Parent;
  7775. timer_idx = (uint8_t)GetTimerIdxFromDMAHandle(hrtim, hdma);
  7776. if ( !IS_HRTIM_TIMING_UNIT(timer_idx) ) {return;}
  7777. if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_CMP1) != (uint32_t)RESET)
  7778. {
  7779. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7780. hrtim->Compare1EventCallback(hrtim, timer_idx);
  7781. #else
  7782. HAL_HRTIM_Compare1EventCallback(hrtim, timer_idx);
  7783. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7784. }
  7785. else if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_CMP2) != (uint32_t)RESET)
  7786. {
  7787. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7788. hrtim->Compare2EventCallback(hrtim, timer_idx);
  7789. #else
  7790. HAL_HRTIM_Compare2EventCallback(hrtim, timer_idx);
  7791. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7792. }
  7793. else if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_CMP3) != (uint32_t)RESET)
  7794. {
  7795. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7796. hrtim->Compare3EventCallback(hrtim, timer_idx);
  7797. #else
  7798. HAL_HRTIM_Compare3EventCallback(hrtim, timer_idx);
  7799. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7800. }
  7801. else if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_CMP4) != (uint32_t)RESET)
  7802. {
  7803. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7804. hrtim->Compare4EventCallback(hrtim, timer_idx);
  7805. #else
  7806. HAL_HRTIM_Compare4EventCallback(hrtim, timer_idx);
  7807. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7808. }
  7809. else if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_UPD) != (uint32_t)RESET)
  7810. {
  7811. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7812. hrtim->RegistersUpdateCallback(hrtim, timer_idx);
  7813. #else
  7814. HAL_HRTIM_RegistersUpdateCallback(hrtim, timer_idx);
  7815. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7816. }
  7817. else if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_CPT1) != (uint32_t)RESET)
  7818. {
  7819. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7820. hrtim->Capture1EventCallback(hrtim, timer_idx);
  7821. #else
  7822. HAL_HRTIM_Capture1EventCallback(hrtim, timer_idx);
  7823. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7824. }
  7825. else if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_CPT2) != (uint32_t)RESET)
  7826. {
  7827. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7828. hrtim->Capture2EventCallback(hrtim, timer_idx);
  7829. #else
  7830. HAL_HRTIM_Capture2EventCallback(hrtim, timer_idx);
  7831. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7832. }
  7833. else if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_SET1) != (uint32_t)RESET)
  7834. {
  7835. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7836. hrtim->Output1SetCallback(hrtim, timer_idx);
  7837. #else
  7838. HAL_HRTIM_Output1SetCallback(hrtim, timer_idx);
  7839. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7840. }
  7841. else if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_RST1) != (uint32_t)RESET)
  7842. {
  7843. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7844. hrtim->Output1ResetCallback(hrtim, timer_idx);
  7845. #else
  7846. HAL_HRTIM_Output1ResetCallback(hrtim, timer_idx);
  7847. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7848. }
  7849. else if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_SET2) != (uint32_t)RESET)
  7850. {
  7851. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7852. hrtim->Output2SetCallback(hrtim, timer_idx);
  7853. #else
  7854. HAL_HRTIM_Output2SetCallback(hrtim, timer_idx);
  7855. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7856. }
  7857. else if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_RST2) != (uint32_t)RESET)
  7858. {
  7859. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7860. hrtim->Output2ResetCallback(hrtim, timer_idx);
  7861. #else
  7862. HAL_HRTIM_Output2ResetCallback(hrtim, timer_idx);
  7863. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7864. }
  7865. else if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_RST) != (uint32_t)RESET)
  7866. {
  7867. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7868. hrtim->CounterResetCallback(hrtim, timer_idx);
  7869. #else
  7870. HAL_HRTIM_CounterResetCallback(hrtim, timer_idx);
  7871. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7872. }
  7873. else if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_DLYPRT) != (uint32_t)RESET)
  7874. {
  7875. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7876. hrtim->DelayedProtectionCallback(hrtim, timer_idx);
  7877. #else
  7878. HAL_HRTIM_DelayedProtectionCallback(hrtim, timer_idx);
  7879. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7880. }
  7881. else if ((hrtim->Instance->sTimerxRegs[timer_idx].TIMxDIER & HRTIM_TIM_DMA_REP) != (uint32_t)RESET)
  7882. {
  7883. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7884. hrtim->RepetitionEventCallback(hrtim, timer_idx);
  7885. #else
  7886. HAL_HRTIM_RepetitionEventCallback(hrtim, timer_idx);
  7887. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7888. }
  7889. else
  7890. {
  7891. /* nothing to do */
  7892. }
  7893. }
  7894. /**
  7895. * @brief DMA error callback
  7896. * @param hdma pointer to DMA handle.
  7897. * @retval None
  7898. */
  7899. static void HRTIM_DMAError(DMA_HandleTypeDef *hdma)
  7900. {
  7901. HRTIM_HandleTypeDef * hrtim = (HRTIM_HandleTypeDef *)((DMA_HandleTypeDef* )hdma)->Parent;
  7902. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7903. hrtim->ErrorCallback(hrtim);
  7904. #else
  7905. HAL_HRTIM_ErrorCallback(hrtim);
  7906. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7907. }
  7908. /**
  7909. * @brief DMA callback invoked upon burst DMA transfer completion
  7910. * @param hdma pointer to DMA handle.
  7911. * @retval None
  7912. */
  7913. static void HRTIM_BurstDMACplt(DMA_HandleTypeDef *hdma)
  7914. {
  7915. HRTIM_HandleTypeDef * hrtim = (HRTIM_HandleTypeDef *)((DMA_HandleTypeDef* )hdma)->Parent;
  7916. #if (USE_HAL_HRTIM_REGISTER_CALLBACKS == 1)
  7917. hrtim->BurstDMATransferCallback(hrtim, GetTimerIdxFromDMAHandle(hrtim, hdma));
  7918. #else
  7919. HAL_HRTIM_BurstDMATransferCallback(hrtim, GetTimerIdxFromDMAHandle(hrtim, hdma));
  7920. #endif /* USE_HAL_HRTIM_REGISTER_CALLBACKS */
  7921. }
  7922. /**
  7923. * @}
  7924. */
  7925. /**
  7926. * @}
  7927. */
  7928. #endif /* HRTIM1 */
  7929. #endif /* HAL_HRTIM_MODULE_ENABLED */
  7930. /**
  7931. * @}
  7932. */
  7933. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/