Add initialization of timer instance in all functions

pull/3213/head
bcostm 2016-10-27 16:47:32 +02:00
parent 6baec10d29
commit cc24e5b7f9
2 changed files with 9 additions and 5 deletions

View File

@ -44,6 +44,7 @@ volatile uint32_t tim_it_counter = 0; // Time stamp to be updated by timer_irq_h
void set_compare(uint16_t count) void set_compare(uint16_t count)
{ {
TimMasterHandle.Instance = TIM_MST;
// Set new output compare value // Set new output compare value
__HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, count); __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, count);
// Enable IT // Enable IT
@ -64,6 +65,8 @@ uint32_t us_ticker_read()
{ {
uint32_t counter; uint32_t counter;
TimMasterHandle.Instance = TIM_MST;
if (!us_ticker_inited) us_ticker_init(); if (!us_ticker_inited) us_ticker_init();
tim_it_update = 0; // Clear TIM_IT_UPDATE event flag tim_it_update = 0; // Clear TIM_IT_UPDATE event flag
@ -106,6 +109,7 @@ uint32_t us_ticker_read()
void us_ticker_set_interrupt(timestamp_t timestamp) void us_ticker_set_interrupt(timestamp_t timestamp)
{ {
int delta = (int)((uint32_t)timestamp - us_ticker_read()); int delta = (int)((uint32_t)timestamp - us_ticker_read());
uint16_t cval = TIM_MST->CNT; uint16_t cval = TIM_MST->CNT;
if (delta <= 0) { // This event was in the past if (delta <= 0) { // This event was in the past
@ -125,11 +129,13 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
void us_ticker_disable_interrupt(void) void us_ticker_disable_interrupt(void)
{ {
TimMasterHandle.Instance = TIM_MST;
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1); __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
} }
void us_ticker_clear_interrupt(void) void us_ticker_clear_interrupt(void)
{ {
TimMasterHandle.Instance = TIM_MST;
if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) {
__HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1); __HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1);
} }

View File

@ -51,22 +51,20 @@ uint32_t us_ticker_read() {
} }
void us_ticker_set_interrupt(timestamp_t timestamp) { void us_ticker_set_interrupt(timestamp_t timestamp) {
TimMasterHandle.Instance = TIM_MST;
// Set new output compare value // Set new output compare value
// TODO: Check if still true
#if defined(TARGET_L4)
__HAL_TIM_SET_COMPARE(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp); __HAL_TIM_SET_COMPARE(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp);
#else
__HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp);
#endif
// Enable IT // Enable IT
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1); __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
} }
void us_ticker_disable_interrupt(void) { void us_ticker_disable_interrupt(void) {
TimMasterHandle.Instance = TIM_MST;
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1); __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
} }
void us_ticker_clear_interrupt(void) { void us_ticker_clear_interrupt(void) {
TimMasterHandle.Instance = TIM_MST;
__HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1);
} }