Subversion Repositories FuelGauge

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 6
Line 55... Line 55...
55
{
55
{
56
  RCC_ClkInitTypeDef    clkconfig;
56
  RCC_ClkInitTypeDef    clkconfig;
57
  uint32_t              uwTimclock, uwAPB1Prescaler = 0U;
57
  uint32_t              uwTimclock, uwAPB1Prescaler = 0U;
58
  uint32_t              uwPrescalerValue = 0U;
58
  uint32_t              uwPrescalerValue = 0U;
59
  uint32_t              pFLatency;
59
  uint32_t              pFLatency;
60
 
-
 
61
    /*Configure the TIM6 IRQ priority */
-
 
62
  HAL_NVIC_SetPriority(TIM6_DAC_IRQn, TickPriority ,0U);
-
 
63
 
-
 
64
  /* Enable the TIM6 global Interrupt */
-
 
65
  HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn);
60
  HAL_StatusTypeDef     status;
66
 
61
 
67
  /* Enable TIM6 clock */
62
  /* Enable TIM6 clock */
68
  __HAL_RCC_TIM6_CLK_ENABLE();
63
  __HAL_RCC_TIM6_CLK_ENABLE();
69
 
64
 
70
  /* Get clock configuration */
65
  /* Get clock configuration */
71
  HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
66
  HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
72
 
67
 
73
  /* Get APB1 prescaler */
68
  /* Get APB1 prescaler */
74
  uwAPB1Prescaler = clkconfig.APB1CLKDivider;
69
  uwAPB1Prescaler = clkconfig.APB1CLKDivider;
75
 
70
 
76
  /* Compute TIM6 clock */
71
  /* Compute TIM6 clock */
77
  if (uwAPB1Prescaler == RCC_HCLK_DIV1)
72
  if (uwAPB1Prescaler == RCC_HCLK_DIV1)
78
  {
73
  {
79
    uwTimclock = HAL_RCC_GetPCLK1Freq();
74
    uwTimclock = HAL_RCC_GetPCLK1Freq();
80
  }
75
  }
81
  else
76
  else
82
  {
77
  {
83
    uwTimclock = 2*HAL_RCC_GetPCLK1Freq();
78
    uwTimclock = 2 * HAL_RCC_GetPCLK1Freq();
84
  }
79
  }
85
 
80
 
86
  /* Compute the prescaler value to have TIM6 counter clock equal to 1MHz */
81
  /* Compute the prescaler value to have TIM6 counter clock equal to 1MHz */
87
  uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);
82
  uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);
88
 
83
 
89
  /* Initialize TIM6 */
84
  /* Initialize TIM6 */
90
  TimHandle.Instance = TIM6;
85
  TimHandle.Instance = TIM6;
91
 
86
 
92
  /* Initialize TIMx peripheral as follow:
87
  /* Initialize TIMx peripheral as follow:
93
  + Period = [(TIM6CLK/1000) - 1]. to have a (1/1000) s time base.
88
  + Period = [(TIM6CLK/1000) - 1]. to have a (1/1000) s time base.
94
  + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
89
  + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
95
  + ClockDivision = 0
90
  + ClockDivision = 0
96
  + Counter direction = Up
91
  + Counter direction = Up
Line 98... Line 93...
98
  TimHandle.Init.Period = (1000000U / 1000U) - 1U;
93
  TimHandle.Init.Period = (1000000U / 1000U) - 1U;
99
  TimHandle.Init.Prescaler = uwPrescalerValue;
94
  TimHandle.Init.Prescaler = uwPrescalerValue;
100
  TimHandle.Init.ClockDivision = 0U;
95
  TimHandle.Init.ClockDivision = 0U;
101
  TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
96
  TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
102
  TimHandle.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
97
  TimHandle.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
103
  if(HAL_TIM_Base_Init(&TimHandle) == HAL_OK)
98
  status = HAL_TIM_Base_Init(&TimHandle);
-
 
99
  if (status == HAL_OK)
104
  {
100
  {
105
    /* Start the TIM time Base generation in interrupt mode */
101
    /* Start the TIM time Base generation in interrupt mode */
106
    return HAL_TIM_Base_Start_IT(&TimHandle);
102
    status = HAL_TIM_Base_Start_IT(&TimHandle);
-
 
103
    if (status == HAL_OK)
-
 
104
    {
-
 
105
      /* Enable the TIM6 global Interrupt */
-
 
106
      HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn);
-
 
107
 
-
 
108
      if (TickPriority < (1UL << __NVIC_PRIO_BITS))
-
 
109
      {
-
 
110
        /* Enable the TIM6 global Interrupt */
-
 
111
        HAL_NVIC_SetPriority(TIM6_DAC_IRQn, TickPriority, 0);
-
 
112
        uwTickPrio = TickPriority;
-
 
113
      }
-
 
114
      else
-
 
115
      {
-
 
116
        status = HAL_ERROR;
-
 
117
      }
-
 
118
    }
107
  }
119
  }
108
 
-
 
109
  /* Return function status */
120
  /* Return function status */
110
  return HAL_ERROR;
121
  return status;
111
}
122
}
112
 
123
 
113
/**
124
/**
114
  * @brief  Suspend Tick increment.
125
  * @brief  Suspend Tick increment.
115
  * @note   Disable the tick increment by disabling TIM6 update interrupt.
126
  * @note   Disable the tick increment by disabling TIM6 update interrupt.