Da Vinci Firmware 1
Firmware for the DaVinci-M rocket avionics board.
Loading...
Searching...
No Matches
stm32h7xx_hal_timebase_tim.c
Go to the documentation of this file.
1/* USER CODE BEGIN Header */
18/* USER CODE END Header */
19
20/* Includes ------------------------------------------------------------------*/
21#include "stm32h7xx_hal.h"
22#include "stm32h7xx_hal_tim.h"
23
24/* Private typedef -----------------------------------------------------------*/
25/* Private define ------------------------------------------------------------*/
26/* Private macro -------------------------------------------------------------*/
27/* Private variables ---------------------------------------------------------*/
28TIM_HandleTypeDef htim4;
29/* Private function prototypes -----------------------------------------------*/
30/* Private functions ---------------------------------------------------------*/
31
41HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
42{
43 RCC_ClkInitTypeDef clkconfig;
44 uint32_t uwTimclock, uwAPB1Prescaler;
45 uint32_t uwPrescalerValue;
46 uint32_t pFLatency;
47
48 /*Configure the TIM4 IRQ priority */
49 if (TickPriority < (1UL << __NVIC_PRIO_BITS))
50 {
51 HAL_NVIC_SetPriority(TIM4_IRQn, TickPriority ,0);
52
53 /* Enable the TIM4 global Interrupt */
54 HAL_NVIC_EnableIRQ(TIM4_IRQn);
55 uwTickPrio = TickPriority;
56 }
57 else
58 {
59 return HAL_ERROR;
60 }
61
62 /* Enable TIM4 clock */
63 __HAL_RCC_TIM4_CLK_ENABLE();
64
65 /* Get clock configuration */
66 HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
67
68 /* Get APB1 prescaler */
69 uwAPB1Prescaler = clkconfig.APB1CLKDivider;
70 /* Compute TIM4 clock */
71 if (uwAPB1Prescaler == RCC_HCLK_DIV1)
72 {
73 uwTimclock = HAL_RCC_GetPCLK1Freq();
74 }
75 else
76 {
77 uwTimclock = 2UL * HAL_RCC_GetPCLK1Freq();
78 }
79
80 /* Compute the prescaler value to have TIM4 counter clock equal to 1MHz */
81 uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);
82
83 /* Initialize TIM4 */
84 htim4.Instance = TIM4;
85
86 /* Initialize TIMx peripheral as follow:
87 * Period = [(TIM4CLK/1000) - 1]. to have a (1/1000) s time base.
88 * Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
89 * ClockDivision = 0
90 * Counter direction = Up
91 */
92 htim4.Init.Period = (1000000U / 1000U) - 1U;
93 htim4.Init.Prescaler = uwPrescalerValue;
94 htim4.Init.ClockDivision = 0;
95 htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
96
97 if(HAL_TIM_Base_Init(&htim4) == HAL_OK)
98 {
99 /* Start the TIM time Base generation in interrupt mode */
100 return HAL_TIM_Base_Start_IT(&htim4);
101 }
102
103 /* Return function status */
104 return HAL_ERROR;
105}
106
114{
115 /* Disable TIM4 update Interrupt */
116 __HAL_TIM_DISABLE_IT(&htim4, TIM_IT_UPDATE);
117}
118
126{
127 /* Enable TIM4 Update interrupt */
128 __HAL_TIM_ENABLE_IT(&htim4, TIM_IT_UPDATE);
129}
130
void HAL_ResumeTick(void)
Resume Tick increment.
TIM_HandleTypeDef htim4
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
This function configures the TIM4 as a time base source. The time source is configured to have 1ms ti...
void HAL_SuspendTick(void)
Suspend Tick increment.
HAL_StatusTypeDef
HAL Status structures definition.
@ HAL_ERROR
@ HAL_OK