rtl8195am - fix us_ticker interrupt handling

TIMER2_7_IRQ is shared among several timer sources, including
us_ticker. Raising TIMER2_7_IRQ pending bit will trigger the timer
interrupt, but the timer interrupt handler will not know which timer
source this interrupt is for. This patch sets timer load value to one
tick and force us_ticker to fire almost "immediately".

TIMER2_7_IRQ is handled through a common interrupt handler, and
is automatically cleared. Therefore, there is no need to clear IRQ.

The underlying timer HAL treats load value as micro-seconds and does
conversion internally. Therefore, simply pass micro-seconds to timer
HAL without converting to tick first.

Signed-off-by: Tony Wu <tung7970@gmail.com>
pull/5464/head
Tony Wu 2017-10-26 06:33:30 +08:00 committed by Yuguo Zou
parent 863b3fdcc1
commit 07646db24c
1 changed files with 8 additions and 15 deletions

View File

@ -19,7 +19,6 @@
#include "us_ticker_api.h"
#include "PeripheralNames.h"
#define TICK_READ_FROM_CPU 0 // 1: read tick from CPU, 0: read tick from G-Timer
#define SYS_TIM_ID 1 // the G-Timer ID for System
#define APP_TIM_ID 2 // the G-Timer ID for Application
@ -33,8 +32,6 @@
*
* Define the following macros to convert between TICK and US.
*/
#define MS_TO_TICK(x) (uint64_t)(((x)*327) / 10)
#define US_TO_TICK(x) (uint64_t)(((x)*32) / 1000)
#define TICK_TO_US(x) (uint64_t)(((x)/2) * 61 + ((x)%2) * TIMER_TICK_US)
static int us_ticker_inited = 0;
@ -73,8 +70,6 @@ void us_ticker_init(void)
TimerAdapter.TimerMode = USER_DEFINED;
HalTimerOp.HalTimerInit((void *) &TimerAdapter);
DBG_TIMER_INFO("%s: Timer_Id=%d\n", __FUNCTION__, APP_TIM_ID);
}
uint32_t us_ticker_read(void)
@ -95,27 +90,26 @@ uint32_t us_ticker_read(void)
void us_ticker_set_interrupt(timestamp_t timestamp)
{
uint32_t time_cur;
uint32_t time_cnt;
HalTimerOp.HalTimerDis((u32)TimerAdapter.TimerId);
time_cur = us_ticker_read();
if (timestamp > time_cur + TIMER_TICK_US) {
time_cnt = timestamp - time_cur;
TimerAdapter.TimerLoadValueUs = timestamp - time_cur;
} else {
HalTimerOpExt.HalTimerReLoad((u32)TimerAdapter.TimerId, 0xffffffff);
HalTimerOp.HalTimerEn((u32)TimerAdapter.TimerId);
us_ticker_fire_interrupt();
return;
TimerAdapter.TimerLoadValueUs = TIMER_TICK_US;
}
TimerAdapter.TimerLoadValueUs = MAX(MS_TO_TICK(time_cnt/1000) + US_TO_TICK(time_cnt%1000), 1);
HalTimerOp.HalTimerDis((u32)TimerAdapter.TimerId);
HalTimerOpExt.HalTimerReLoad((u32)TimerAdapter.TimerId, TimerAdapter.TimerLoadValueUs);
HalTimerOp.HalTimerEn((u32)TimerAdapter.TimerId);
}
void us_ticker_fire_interrupt(void)
{
NVIC_SetPendingIRQ(TIMER2_7_IRQ);
TimerAdapter.TimerLoadValueUs = TIMER_TICK_US;
HalTimerOp.HalTimerDis((u32)TimerAdapter.TimerId);
HalTimerOpExt.HalTimerReLoad((u32)TimerAdapter.TimerId, TimerAdapter.TimerLoadValueUs);
HalTimerOp.HalTimerEn((u32)TimerAdapter.TimerId);
}
void us_ticker_disable_interrupt(void)
@ -125,5 +119,4 @@ void us_ticker_disable_interrupt(void)
void us_ticker_clear_interrupt(void)
{
HalTimerOp.HalTimerIrqClear((u32)TimerAdapter.TimerId);
}