art_pi_fw/src/bsp/rtos.c
/**
  * @brief  This function configures the TIM6 as a time base source.
  *         The time source is configured to have 1ms time base with a dedicated
  *         Tick interrupt priority.
  * @note   This function is called  automatically at the beginning of program after
  *         reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig().
  * @param  TickPriority Tick interrupt priority.
  * @retval HAL status
  */
@brief  This function configures the TIM6 as a time base source.
The time source is configured to have 1ms time base with a dedicated
Tick interrupt priority.
@note   This function is called  automatically at the beginning of program after
reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig().
@param  TickPriority Tick interrupt priority.
@retval HAL status
@brief This function configures the TIM6 as a time base source . The time source is configured to have 1ms time base with a dedicated Tick interrupt priority . @note This function is called automatically at the beginning of program after reset by HAL_Init () or at any time when clock is configured by HAL_RCC_ClockConfig () . @param TickPriority Tick interrupt priority . @retval HAL status
HAL_StatusTypeDef HAL_InitTick (uint32_t TickPriority)
{
  RCC_ClkInitTypeDef    clkconfig;
  uint32_t              uwTimclock, uwAPB1Prescaler;
  uint32_t              uwPrescalerValue;
  uint32_t              pFLatency;
  if (TickPriority < (1UL << __NVIC_PRIO_BITS))
  {
    HAL_NVIC_SetPriority(TIM6_DAC_IRQn, TickPriority ,0U);
    HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn);
    uwTickPrio = TickPriority;
  }
  else
  {
    return HAL_ERROR;
  }
  __HAL_RCC_TIM6_CLK_ENABLE();
  HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
  uwAPB1Prescaler = clkconfig.APB1CLKDivider;
  if (uwAPB1Prescaler == RCC_HCLK_DIV1)
  {
    uwTimclock = HAL_RCC_GetPCLK1Freq();
  }
  else
  {
    uwTimclock = 2UL * HAL_RCC_GetPCLK1Freq();
  }
  uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);
  TimHandle.Instance = TIM6;
  TimHandle.Init.Period = (1000000U / configTICK_RATE_HZ) - 1U;
  TimHandle.Init.Prescaler = uwPrescalerValue;
  TimHandle.Init.ClockDivision = 0;
  TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
  if(HAL_TIM_Base_Init(&TimHandle) == HAL_OK)
  {
    return HAL_TIM_Base_Start_IT(&TimHandle);
  }
  return HAL_ERROR;
}
HAL_StatusTypeDef HAL_InitTick ( uint32_t TickPriority ) { RCC_ClkInitTypeDef clkconfig ; uint32_t uwTimclock , uwAPB1Prescaler ; uint32_t uwPrescalerValue ; uint32_t pFLatency ; if ( TickPriority < ( 1UL << __NVIC_PRIO_BITS ) ) { HAL_NVIC_SetPriority ( TIM6_DAC_IRQn , TickPriority , 0U ) ; HAL_NVIC_EnableIRQ ( TIM6_DAC_IRQn ) ; uwTickPrio = TickPriority ; } else { return HAL_ERROR ; } __HAL_RCC_TIM6_CLK_ENABLE ( ) ; HAL_RCC_GetClockConfig ( & clkconfig , & pFLatency ) ; uwAPB1Prescaler = clkconfig . APB1CLKDivider ; if ( uwAPB1Prescaler == RCC_HCLK_DIV1 ) { uwTimclock = HAL_RCC_GetPCLK1Freq ( ) ; } else { uwTimclock = 2UL * HAL_RCC_GetPCLK1Freq ( ) ; } uwPrescalerValue = ( uint32_t ) ( ( uwTimclock / 1000000U ) - 1U ) ; TimHandle . Instance = TIM6 ; TimHandle . Init . Period = ( 1000000U / configTICK_RATE_HZ ) - 1U ; TimHandle . Init . Prescaler = uwPrescalerValue ; TimHandle . Init . ClockDivision = 0 ; TimHandle . Init . CounterMode = TIM_COUNTERMODE_UP ; if ( HAL_TIM_Base_Init ( & TimHandle ) == HAL_OK ) { return HAL_TIM_Base_Start_IT ( & TimHandle ) ; } return HAL_ERROR ; }
@brief  This function configures the TIM6 as a time base source.
@brief This function configures the TIM6 as a time base source .
/*Configure the TIM6 IRQ priority */ /* Enable the TIM6 global Interrupt */ /* Enable TIM6 clock */ /* Get clock configuration */ /* Get APB1 prescaler */ /* Compute TIM6 clock */ /* Compute the prescaler value to have TIM6 counter clock equal to 1MHz */ /* Initialize TIM6 */ /* Initialize TIMx peripheral as follow:
  + Period = [(TIM6CLK/1000) - 1]. to have a (1/1000) s time base.
  + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
  + ClockDivision = 0
  + Counter direction = Up
  */ /* Start the TIM time Base generation in interrupt mode */ /* Return function status */