2 ******************************************************************************
\r
3 * @file FreeRTOS/FreeRTOS_AMP_Dual_RTOS/CM7/Src/stm32h7xx_hal_timebase_tim.c
\r
4 * @author MCD Application Team
\r
5 * @brief HAL time base based on the hardware TIM.
\r
7 * This file overrides the native HAL time base functions (defined as weak)
\r
9 * + Intializes the TIM peripheral generate a Period elapsed Event each 1ms
\r
10 * + HAL_IncTick is called inside HAL_TIM_PeriodElapsedCallback ie each 1ms
\r
12 ******************************************************************************
\r
15 * <h2><center>© Copyright (c) 2019 STMicroelectronics.
\r
16 * All rights reserved.</center></h2>
\r
18 * This software component is licensed by ST under BSD 3-Clause license,
\r
19 * the "License"; You may not use this file except in compliance with the
\r
20 * License. You may obtain a copy of the License at:
\r
21 * opensource.org/licenses/BSD-3-Clause
\r
23 ******************************************************************************
\r
26 /* Includes ------------------------------------------------------------------*/
\r
27 #include "stm32h7xx_hal.h"
\r
29 /* Private typedef -----------------------------------------------------------*/
\r
30 /* Private define ------------------------------------------------------------*/
\r
31 /* Private macro -------------------------------------------------------------*/
\r
32 /* Private variables ---------------------------------------------------------*/
\r
33 TIM_HandleTypeDef TimHandle;
\r
34 /* Private function prototypes -----------------------------------------------*/
\r
35 void TIM6_DAC_IRQHandler(void);
\r
36 /* Private functions ---------------------------------------------------------*/
\r
39 * @brief This function configures the TIM6 as a time base source.
\r
40 * The time source is configured to have 1ms time base with a dedicated
\r
41 * Tick interrupt priority.
\r
42 * @note This function is called automatically at the beginning of program after
\r
43 * reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig().
\r
44 * @param TickPriority: Tick interrupt priority.
\r
45 * @retval HAL status
\r
47 HAL_StatusTypeDef HAL_InitTick (uint32_t TickPriority)
\r
49 RCC_ClkInitTypeDef clkconfig;
\r
50 uint32_t uwTimclock, uwAPB1Prescaler = 0U;
\r
51 uint32_t uwPrescalerValue = 0U;
\r
54 /*Configure the TIM6 IRQ priority */
\r
55 HAL_NVIC_SetPriority(TIM6_DAC_IRQn, TickPriority ,0U);
\r
57 /* Enable the TIM6 global Interrupt */
\r
58 HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn);
\r
60 /* Enable TIM6 clock */
\r
61 __HAL_RCC_TIM6_CLK_ENABLE();
\r
63 /* Get clock configuration */
\r
64 HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
\r
66 /* Get APB1 prescaler */
\r
67 uwAPB1Prescaler = clkconfig.APB1CLKDivider;
\r
69 /* Compute TIM6 clock */
\r
70 if (uwAPB1Prescaler == RCC_HCLK_DIV1)
\r
72 uwTimclock = HAL_RCC_GetPCLK1Freq();
\r
76 uwTimclock = 2*HAL_RCC_GetPCLK1Freq();
\r
79 /* Compute the prescaler value to have TIM6 counter clock equal to 1MHz */
\r
80 uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);
\r
82 /* Initialize TIM6 */
\r
83 TimHandle.Instance = TIM6;
\r
85 /* Initialize TIMx peripheral as follow:
\r
86 + Period = [(TIM6CLK/1000) - 1]. to have a (1/1000) s time base.
\r
87 + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
\r
89 + Counter direction = Up
\r
91 TimHandle.Init.Period = (1000000U / 1000U) - 1U;
\r
92 TimHandle.Init.Prescaler = uwPrescalerValue;
\r
93 TimHandle.Init.ClockDivision = 0;
\r
94 TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
\r
95 if(HAL_TIM_Base_Init(&TimHandle) == HAL_OK)
\r
97 /* Start the TIM time Base generation in interrupt mode */
\r
98 return HAL_TIM_Base_Start_IT(&TimHandle);
\r
101 /* Return function status */
\r
106 * @brief Suspend Tick increment.
\r
107 * @note Disable the tick increment by disabling TIM6 update interrupt.
\r
111 void HAL_SuspendTick(void)
\r
113 /* Disable TIM6 update Interrupt */
\r
114 __HAL_TIM_DISABLE_IT(&TimHandle, TIM_IT_UPDATE);
\r
118 * @brief Resume Tick increment.
\r
119 * @note Enable the tick increment by Enabling TIM6 update interrupt.
\r
123 void HAL_ResumeTick(void)
\r
125 /* Enable TIM6 Update interrupt */
\r
126 __HAL_TIM_ENABLE_IT(&TimHandle, TIM_IT_UPDATE);
\r
130 * @brief Period elapsed callback in non blocking mode
\r
131 * @note This function is called when TIM6 interrupt took place, inside
\r
132 * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
\r
133 * a global variable "uwTick" used as application time base.
\r
134 * @param htim : TIM handle
\r
137 void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
\r
143 * @brief This function handles TIM interrupt request.
\r
147 void TIM6_DAC_IRQHandler(void)
\r
149 HAL_TIM_IRQHandler(&TimHandle);
\r
152 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r