mbed library sources
Dependents: frdm_kl05z_gpio_test
Fork of mbed-src by
Diff: targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/us_ticker.c
- Revision:
- 216:577900467c9e
- Parent:
- 96:c359415e941f
- Child:
- 304:89b9c3a9a045
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/us_ticker.c Tue May 27 08:30:06 2014 +0100 +++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/us_ticker.c Tue May 27 10:00:08 2014 +0100 @@ -58,7 +58,7 @@ // Used by interrupt system static void tim_oc_irq_handler(void) { uint16_t cval = TIM_MST->CNT; - + // Clear interrupt flag if (TIM_GetITStatus(TIM_MST, TIM_IT_CC1) == SET) { TIM_ClearITPendingBit(TIM_MST, TIM_IT_CC1); @@ -67,14 +67,12 @@ if (oc_rem_part > 0) { set_compare(oc_rem_part); // Finish the remaining time left oc_rem_part = 0; - } - else { + } else { if (oc_int_part > 0) { set_compare(0xFFFF); oc_rem_part = cval; // To finish the counter loop the next time oc_int_part--; - } - else { + } else { us_ticker_irq_handler(); } } @@ -82,13 +80,13 @@ void us_ticker_init(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; - + if (us_ticker_inited) return; us_ticker_inited = 1; - + // Enable Timer clock TIM_MST_RCC; - + // Configure time base TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Period = 0xFFFF; @@ -96,18 +94,18 @@ TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM_MST, &TIM_TimeBaseStructure); - + // Configure interrupts TIM_ITConfig(TIM_MST, TIM_IT_Update, ENABLE); - + // Update interrupt used for 32-bit counter NVIC_SetVector(TIM_MST_UP_IRQ, (uint32_t)tim_update_irq_handler); NVIC_EnableIRQ(TIM_MST_UP_IRQ); - + // Output compare interrupt used for timeout feature NVIC_SetVector(TIM_MST_OC_IRQ, (uint32_t)tim_oc_irq_handler); NVIC_EnableIRQ(TIM_MST_OC_IRQ); - + // Enable timer TIM_Cmd(TIM_MST, ENABLE); } @@ -139,8 +137,7 @@ if (delta <= 0) { // This event was in the past us_ticker_irq_handler(); - } - else { + } else { oc_int_part = (uint32_t)(delta >> 16); oc_rem_part = (uint16_t)(delta & 0xFFFF); if (oc_rem_part <= (0xFFFF - cval)) {