Ejemplo n.º 1
0
void us_ticker_set_interrupt(timestamp_t timestamp) 
{
    uint32_t tick_cnt;
    uint32_t cur_tick_cnt;
    uint32_t time_def;

    tick_cnt = (uint32_t)timestamp/TIMER_TICK_US;
    cur_tick_cnt = 0xffffffff - HalTimerOp.HalTimerReadCount(SYS_TIM_ID);
    if (tick_cnt > cur_tick_cnt) {
        time_def = tick_cnt - cur_tick_cnt;
    }
    else {
        time_def = 0xffffffff - cur_tick_cnt + tick_cnt;
    }

    TimerAdapter.IrqDis = 0;    // Enable Irq
    TimerAdapter.TimerLoadValueUs = time_def * TIMER_TICK_US;
    TimerAdapter.TimerMode = USER_DEFINED; // Countdown Free Run

    HalTimerOp.HalTimerInit((VOID*) &TimerAdapter);
}
Ejemplo n.º 2
0
uint32_t us_ticker_read() 
{
    uint32_t tick_cnt;
    uint64_t us_tick;

    //1 Our G-timer  resolution is ~31 us (1/32K), and is a countdown timer
    if (!us_ticker_inited) 
        us_ticker_init();
    tick_cnt =  HalTimerOp.HalTimerReadCount(SYS_TIM_ID);
    us_tick = TIMER_TICK_US*(0xffffffff - tick_cnt);
    // TODO: handle overflow
    return ((uint32_t)us_tick);
}
Ejemplo n.º 3
0
uint32_t us_ticker_read() 
{
    uint32_t tick_cnt;
    uint32_t ticks_125ms;
    uint32_t ticks_remain;
    uint64_t us_tick;

    //1 Our G-timer  resolution is ~31 us (1/32K), and is a countdown timer
//    if (!us_ticker_inited) {
//        us_ticker_init();
//    }
    tick_cnt = HalTimerOp.HalTimerReadCount(SYS_TIM_ID);
    tick_cnt = 0xffffffff - tick_cnt;   // it's a down counter
    ticks_125ms = tick_cnt/(GTIMER_CLK_HZ/8);
    ticks_remain = tick_cnt - (ticks_125ms*(GTIMER_CLK_HZ/8));
    us_tick = ticks_125ms * 125000;
    us_tick += (ticks_remain * 1000000)/GTIMER_CLK_HZ;
    return ((uint32_t)us_tick);
}
Ejemplo n.º 4
0
uint32_t us_ticker_read() 
{
    uint32_t tick_cnt;
    uint32_t tick_cnt_div_4;
    uint32_t tick_cnt_mod_4;
    uint64_t us_tick;

    //1 Our G-timer  resolution is ~31 us (1/32K), and is a countdown timer
//    if (!us_ticker_inited) {
//        us_ticker_init();
//    }
    tick_cnt = HalTimerOp.HalTimerReadCount(SYS_TIM_ID);
    tick_cnt = 0xffffffff - tick_cnt;   // it's a down counter
    tick_cnt_div_4 = tick_cnt >> 2;
    tick_cnt_mod_4 = tick_cnt  - (tick_cnt_div_4 << 2);
    us_tick = (TIMER_TICK_US_X4*tick_cnt_div_4) + (TIMER_TICK_US*tick_cnt_mod_4);
    
    // TODO: handle overflow
    return ((uint32_t)us_tick);
}
Ejemplo n.º 5
0
void us_ticker_init(void) 
{
    
    if (us_ticker_inited) return;
    us_ticker_inited = 1;

    // Initial a G-Timer
    TimerAdapter.IrqDis = 1;    // Disable Irq
    TimerAdapter.IrqHandle.IrqFun = (IRQ_FUN) _us_ticker_irq_handler;
    TimerAdapter.IrqHandle.IrqNum = TIMER2_7_IRQ;
    TimerAdapter.IrqHandle.Priority = 0x20;
    TimerAdapter.IrqHandle.Data = (u32)NULL;
    TimerAdapter.TimerId = APP_TIM_ID;
    TimerAdapter.TimerIrqPriority = 0;
    TimerAdapter.TimerLoadValueUs = 1;
    TimerAdapter.TimerMode = FREE_RUN_MODE; // Countdown Free Run

    HalTimerOp.HalTimerInit((VOID*) &TimerAdapter);

    DBG_TIMER_INFO("%s: Timer_Id=%d\n", __FUNCTION__, APP_TIM_ID);
}
Ejemplo n.º 6
0
void us_ticker_set_interrupt(timestamp_t timestamp) 
{
    uint32_t cur_time_us;
    uint32_t time_def;

    cur_time_us = us_ticker_read();
    if ((uint32_t)timestamp >= cur_time_us) {
        time_def = (uint32_t)timestamp - cur_time_us;
    }
    else {
        time_def = 0xffffffff - cur_time_us + (uint32_t)timestamp;
    }    

    if (time_def < TIMER_TICK_US) {
        time_def = TIMER_TICK_US;       // at least 1 tick
    }
    
    TimerAdapter.IrqDis = 0;    // Enable Irq
    TimerAdapter.TimerLoadValueUs = time_def;
    TimerAdapter.TimerMode = USER_DEFINED; // Countdown Free Run

    HalTimerOp.HalTimerInit((VOID*) &TimerAdapter);
}
Ejemplo n.º 7
0
void us_ticker_clear_interrupt(void) 
{
    HalTimerOp.HalTimerIrqClear((u32)TimerAdapter.TimerId);
}
Ejemplo n.º 8
0
void us_ticker_disable_interrupt(void) 
{
    HalTimerOp.HalTimerDis((u32)TimerAdapter.TimerId);
}
Ejemplo n.º 9
0
uint32_t gtimer_read_tick (gtimer_t *obj)
{
    PTIMER_ADAPTER pTimerAdapter = &obj->hal_gtimer_adp;
    
    return (HalTimerOp.HalTimerReadCount(pTimerAdapter->TimerId));
}