RTEMS 6.1-rc6
|
TIM HAL module driver. This file provides firmware functions to manage the following functionalities of the High Resolution Timer (HRTIM) peripheral: More...
#include "stm32h7xx_hal.h"
TIM HAL module driver. This file provides firmware functions to manage the following functionalities of the High Resolution Timer (HRTIM) peripheral:
Copyright (c) 2017 STMicroelectronics. All rights reserved.
This software is licensed under terms that can be found in the LICENSE file in the root directory of this software component. If no LICENSE file comes with this software, it is provided AS-IS.
============================================================================== ##### Simple mode v.s. waveform mode ##### ============================================================================== [..] The HRTIM HAL API is split into 2 categories: (#)Simple functions: these functions allow for using a HRTIM timer as a general purpose timer with high resolution capabilities. HRTIM simple modes are managed through the set of functions named HAL_HRTIM_Simple<Function>. These functions are similar in name and usage to the one defined for the TIM peripheral. When a HRTIM timer operates in simple mode, only a very limited set of HRTIM features are used. Following simple modes are proposed: (++)Output compare mode, (++)PWM output mode, (++)Input capture mode, (++)One pulse mode. (#)Waveform functions: These functions allow taking advantage of the HRTIM flexibility to produce numerous types of control signal. When a HRTIM timer operates in waveform mode, all the HRTIM features are accessible without any restriction. HRTIM waveform modes are managed through the set of functions named HAL_HRTIM_Waveform<Function> ============================================================================== ##### How to use this driver ##### ============================================================================== [..] (#)Initialize the HRTIM low level resources by implementing the HAL_HRTIM_MspInit() function: (##)Enable the HRTIM clock source using __HRTIMx_CLK_ENABLE() (##)Connect HRTIM pins to MCU I/Os (+++) Enable the clock for the HRTIM GPIOs using the following function: __HAL_RCC_GPIOx_CLK_ENABLE() (+++) Configure these GPIO pins in Alternate Function mode using HAL_GPIO_Init() (##)When using DMA to control data transfer (e.g HAL_HRTIM_SimpleBaseStart_DMA()) (+++)Enable the DMAx interface clock using __DMAx_CLK_ENABLE() (+++)Initialize the DMA handle (+++)Associate the initialized DMA handle to the appropriate DMA handle of the HRTIM handle using __HAL_LINKDMA() (+++)Initialize the DMA channel using HAL_DMA_Init() (+++)Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA channel using HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ() (##)In case of using interrupt mode (e.g HAL_HRTIM_SimpleBaseStart_IT()) (+++)Configure the priority and enable the NVIC for the concerned HRTIM interrupt using HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ() (#)Initialize the HRTIM HAL using HAL_HRTIM_Init(). The HRTIM configuration structure (field of the HRTIM handle) specifies which global interrupt of whole HRTIM must be enabled (Burst mode period, System fault, Faults). It also contains the HRTIM external synchronization configuration. HRTIM can act as a master (generating a synchronization signal) or as a slave (waiting for a trigger to be synchronized). (#) Configure HRTIM resources shared by all HRTIM timers (##)Burst Mode Controller: (+++)HAL_HRTIM_BurstModeConfig(): configures the HRTIM burst mode controller: operating mode (continuous or one-shot mode), clock (source, prescaler) , trigger(s), period, idle duration. (##)External Events Conditioning: (+++)HAL_HRTIM_EventConfig(): configures the conditioning of an external event channel: source, polarity, edge-sensitivity. External event can be used as triggers (timer reset, input capture, burst mode, ADC triggers, delayed protection) They can also be used to set or reset timer outputs. Up to 10 event channels are available. (+++)HAL_HRTIM_EventPrescalerConfig(): configures the external event sampling clock (used for digital filtering). (##)Fault Conditioning: (+++)HAL_HRTIM_FaultConfig(): configures the conditioning of a fault channel: source, polarity, edge-sensitivity. Fault channels are used to disable the outputs in case of an abnormal operation. Up to 5 fault channels are available. (+++)HAL_HRTIM_FaultPrescalerConfig(): configures the fault sampling clock (used for digital filtering). (+++)HAL_HRTIM_FaultModeCtl(): Enables or disables fault input(s) circuitry. By default all fault inputs are disabled. (##)ADC trigger: (+++)HAL_HRTIM_ADCTriggerConfig(): configures the source triggering the update of the ADC trigger register and the ADC trigger. 4 independent triggers are available to start both the regular and the injected sequencers of the 2 ADCs (#) Configure HRTIM timer time base using HAL_HRTIM_TimeBaseConfig(). This function must be called whatever the HRTIM timer operating mode is (simple v.s. waveform). It configures mainly: (##)The HRTIM timer counter operating mode (continuous v.s. one shot) (##)The HRTIM timer clock prescaler (##)The HRTIM timer period (##)The HRTIM timer repetition counter *** If the HRTIM timer operates in simple mode *** =================================================== [..] (#) Start or Stop simple timers (++)Simple time base: HAL_HRTIM_SimpleBaseStart(),HAL_HRTIM_SimpleBaseStop(), HAL_HRTIM_SimpleBaseStart_IT(),HAL_HRTIM_SimpleBaseStop_IT(), HAL_HRTIM_SimpleBaseStart_DMA(),HAL_HRTIM_SimpleBaseStop_DMA(). (++)Simple output compare: HAL_HRTIM_SimpleOCChannelConfig(), HAL_HRTIM_SimpleOCStart(),HAL_HRTIM_SimpleOCStop(), HAL_HRTIM_SimpleOCStart_IT(),HAL_HRTIM_SimpleOCStop_IT(), HAL_HRTIM_SimpleOCStart_DMA(),HAL_HRTIM_SimpleOCStop_DMA(), (++)Simple PWM output: HAL_HRTIM_SimplePWMChannelConfig(), HAL_HRTIM_SimplePWMStart(),HAL_HRTIM_SimplePWMStop(), HAL_HRTIM_SimplePWMStart_IT(),HAL_HRTIM_SimplePWMStop_IT(), HAL_HRTIM_SimplePWMStart_DMA(),HAL_HRTIM_SimplePWMStop_DMA(), (++)Simple input capture: HAL_HRTIM_SimpleCaptureChannelConfig(), HAL_HRTIM_SimpleCaptureStart(),HAL_HRTIM_SimpleCaptureStop(), HAL_HRTIM_SimpleCaptureStart_IT(),HAL_HRTIM_SimpleCaptureStop_IT(), HAL_HRTIM_SimpleCaptureStart_DMA(),HAL_HRTIM_SimpleCaptureStop_DMA(). (++)Simple one pulse: HAL_HRTIM_SimpleOnePulseChannelConfig(), HAL_HRTIM_SimpleOnePulseStart(),HAL_HRTIM_SimpleOnePulseStop(), HAL_HRTIM_SimpleOnePulseStart_IT(),HAL_HRTIM_SimpleOnePulseStop_It(). *** If the HRTIM timer operates in waveform mode *** ==================================================== [..] (#) Completes waveform timer configuration (++)HAL_HRTIM_WaveformTimerConfig(): configuration of a HRTIM timer operating in wave form mode mainly consists in: (+++)Enabling the HRTIM timer interrupts and DMA requests. (+++)Enabling the half mode for the HRTIM timer. (+++)Defining how the HRTIM timer reacts to external synchronization input. (+++)Enabling the push-pull mode for the HRTIM timer. (+++)Enabling the fault channels for the HRTIM timer. (+++)Enabling the dead-time insertion for the HRTIM timer. (+++)Setting the delayed protection mode for the HRTIM timer (source and outputs on which the delayed protection are applied). (+++)Specifying the HRTIM timer update and reset triggers. (+++)Specifying the HRTIM timer registers update policy (e.g. pre-load enabling). (++)HAL_HRTIM_TimerEventFilteringConfig(): configures external event blanking and windowing circuitry of a HRTIM timer: (+++)Blanking: to mask external events during a defined time period a defined time period (+++)Windowing, to enable external events only during a defined time period (++)HAL_HRTIM_DeadTimeConfig(): configures the dead-time insertion unit for a HRTIM timer. Allows to generate a couple of complementary signals from a single reference waveform, with programmable delays between active state. (++)HAL_HRTIM_ChopperModeConfig(): configures the parameters of the high-frequency carrier signal added on top of the timing unit output. Chopper mode can be enabled or disabled for each timer output separately (see HAL_HRTIM_WaveformOutputConfig()). (++)HAL_HRTIM_BurstDMAConfig(): configures the burst DMA burst controller. Allows having multiple HRTIM registers updated with a single DMA request. The burst DMA operation is started by calling HAL_HRTIM_BurstDMATransfer(). (++)HAL_HRTIM_WaveformCompareConfig():configures the compare unit of a HRTIM timer. This operation consists in setting the compare value and possibly specifying the auto delayed mode for compare units 2 and 4 (allows to have compare events generated relatively to capture events). Note that when auto delayed mode is needed, the capture unit associated to the compare unit must be configured separately. (++)HAL_HRTIM_WaveformCaptureConfig(): configures the capture unit of a HRTIM timer. This operation consists in specifying the source(s) triggering the capture (timer register update event, external event, timer output set/reset event, other HRTIM timer related events). (++)HAL_HRTIM_WaveformOutputConfig(): configuration of a HRTIM timer output mainly consists in: (+++)Setting the output polarity (active high or active low), (+++)Defining the set/reset crossbar for the output, (+++)Specifying the fault level (active or inactive) in IDLE and FAULT states., (#) Set waveform timer output(s) level (++)HAL_HRTIM_WaveformSetOutputLevel(): forces the output to its active or inactive level. For example, when deadtime insertion is enabled it is necessary to force the output level by software to have the outputs in a complementary state as soon as the RUN mode is entered. (#) Enable or Disable waveform timer output(s) (++)HAL_HRTIM_WaveformOutputStart(),HAL_HRTIM_WaveformOutputStop(). (#) Start or Stop waveform HRTIM timer(s). (++)HAL_HRTIM_WaveformCountStart(),HAL_HRTIM_WaveformCountStop(), (++)HAL_HRTIM_WaveformCountStart_IT(),HAL_HRTIM_WaveformCountStop_IT(), (++)HAL_HRTIM_WaveformCountStart_DMA(),HAL_HRTIM_WaveformCountStop_DMA(), (#) Burst mode controller enabling: (++)HAL_HRTIM_BurstModeCtl(): activates or de-activates the burst mode controller. (#) Some HRTIM operations can be triggered by software: (++)HAL_HRTIM_BurstModeSoftwareTrigger(): calling this function trigs the burst operation. (++)HAL_HRTIM_SoftwareCapture(): calling this function trigs the capture of the HRTIM timer counter. (++)HAL_HRTIM_SoftwareUpdate(): calling this function trigs the update of the pre-loadable registers of the HRTIM timer (++)HAL_HRTIM_SoftwareReset():calling this function resets the HRTIM timer counter. (#) Some functions can be used any time to retrieve HRTIM timer related information (++)HAL_HRTIM_GetCapturedValue(): returns actual value of the capture register of the designated capture unit. (++)HAL_HRTIM_WaveformGetOutputLevel(): returns actual level (ACTIVE/INACTIVE) of the designated timer output. (++)HAL_HRTIM_WaveformGetOutputState():returns actual state (IDLE/RUN/FAULT) of the designated timer output. (++)HAL_HRTIM_GetDelayedProtectionStatus():returns actual level (ACTIVE/INACTIVE) of the designated output when the delayed protection was triggered. (++)HAL_HRTIM_GetBurstStatus(): returns the actual status (ACTIVE/INACTIVE) of the burst mode controller. (++)HAL_HRTIM_GetCurrentPushPullStatus(): when the push-pull mode is enabled for the HRTIM timer (see HAL_HRTIM_WaveformTimerConfig()), the push-pull status indicates on which output the signal is currently active (e.g signal applied on output 1 and output 2 forced inactive or vice versa). (++)HAL_HRTIM_GetIdlePushPullStatus(): when the push-pull mode is enabled for the HRTIM timer (see HAL_HRTIM_WaveformTimerConfig()), the idle push-pull status indicates during which period the delayed protection request occurred (e.g. protection occurred when the output 1 was active and output 2 forced inactive or vice versa). (#) Some functions can be used any time to retrieve actual HRTIM status (++)HAL_HRTIM_GetState(): returns actual HRTIM instance HAL state. *** Callback registration *** ============================= [..] The compilation flag USE_HAL_HRTIM_REGISTER_CALLBACKS when set to 1 allows the user to configure dynamically the driver callbacks. Use Functions HAL_HRTIM_RegisterCallback() or HAL_HRTIM_TIMxRegisterCallback() to register an interrupt callback. [..] Function HAL_HRTIM_RegisterCallback() allows to register following callbacks: (+) Fault1Callback : Fault 1 interrupt callback function (+) Fault2Callback : Fault 2 interrupt callback function (+) Fault3Callback : Fault 3 interrupt callback function (+) Fault4Callback : Fault 4 interrupt callback function (+) Fault5Callback : Fault 5 interrupt callback function (+) SystemFaultCallback : System fault interrupt callback function (+) BurstModePeriodCallback : Burst mode period interrupt callback function (+) SynchronizationEventCallback : Sync Input interrupt callback function (+) ErrorCallback : DMA error callback function (+) MspInitCallback : HRTIM MspInit callback function (+) MspDeInitCallback : HRTIM MspInit callback function [..] Function HAL_HRTIM_TIMxRegisterCallback() allows to register following callbacks: (+) RegistersUpdateCallback : Timer x Update interrupt callback function (+) RepetitionEventCallback : Timer x Repetition interrupt callback function (+) Compare1EventCallback : Timer x Compare 1 match interrupt callback function (+) Compare2EventCallback : Timer x Compare 2 match interrupt callback function (+) Compare3EventCallback : Timer x Compare 3 match interrupt callback function (+) Compare4EventCallback : Timer x Compare 4 match interrupt callback function (+) Capture1EventCallback : Timer x Capture 1 interrupts callback function (+) Capture2EventCallback : Timer x Capture 2 interrupts callback function (+) DelayedProtectionCallback : Timer x Delayed protection interrupt callback function (+) CounterResetCallback : Timer x counter reset/roll-over interrupt callback function (+) Output1SetCallback : Timer x output 1 set interrupt callback function (+) Output1ResetCallback : Timer x output 1 reset interrupt callback function (+) Output2SetCallback : Timer x output 2 set interrupt callback function (+) Output2ResetCallback : Timer x output 2 reset interrupt callback function (+) BurstDMATransferCallback : Timer x Burst DMA completed interrupt callback function [..] Both functions take as parameters the HAL peripheral handle, the Callback ID and a pointer to the user callback function. [..] Use function HAL_HRTIM_UnRegisterCallback or HAL_HRTIM_TIMxUnRegisterCallback to reset a callback to the default weak function. Both functions take as parameters the HAL peripheral handle and the Callback ID. [..] By default, after the HAL_HRTIM_Init() and when the state is HAL_HRTIM_STATE_RESET all callbacks are set to the corresponding weak functions (e.g HAL_HRTIM_Fault1Callback) Exception done for MspInit and MspDeInit functions that are reset to the legacy weak functions in the HAL_HRTIM_Init()/ HAL_HRTIM_DeInit() only when these callbacks are null (not registered beforehand). If MspInit or MspDeInit are not null, the HAL_HRTIM_Init()/ HAL_HRTIM_DeInit() keep and use the user MspInit/MspDeInit callbacks (registered beforehand) whatever the state. [..] Callbacks can be registered/unregistered in HAL_HRTIM_STATE_READY state only. Exception done MspInit/MspDeInit functions that can be registered/unregistered in HAL_HRTIM_STATE_READY or HAL_HRTIM_STATE_RESET states, thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit. Then, the user first registers the MspInit/MspDeInit user callbacks using HAL_HRTIM_RegisterCallback() before calling HAL_HRTIM_DeInit() or HAL_HRTIM_Init() function. [..] When the compilation flag USE_HAL_HRTIM_REGISTER_CALLBACKS is set to 0 or not defined, the callback registration feature is not available and all callbacks are set to the corresponding weak functions.