void BSP_Tmr_TickInit(uint32_t tmrId, uint32_t period, uint32_t vecId, void *isr) { /* set tick period */ hal_timer_set_period(tmrId, period); /* enable timer1 interrupt */ hal_timer_irq_control(tmrId, 1); /****************************** * tick ISR init ******************************/ /* init trigger mode */ /* Set edge trigger, falling edge */ hal_intc_irq_config(vecId, 1, 0); /* clean pending */ hal_intc_irq_clean(vecId); /* enable timer interrupt */ hal_intc_irq_enable(vecId); if (isr) OS_CPU_Vector_Table[vecId] = isr; else DEBUG(1, 1, "Invalid tick handler!!\r\n"); /* start timer */ hal_timer_start(tmrId); }
extern hal_result_t hal_timer_countdown_set(hal_timer_t id, hal_reltime_t countdown, hal_reltime_t *error) { hal_timer_cfg_t *curcfg = NULL; hal_timer_cfg_t newcfg; uint8_t wasrunning = 0; if(hal_false == s_hal_timer_initted_is(id)) { return(hal_res_NOK_generic); } // if running stop. if(hal_timer_status_running == hal_timer_status_get(id)) { wasrunning = 1; } // computes the values to be put in registers curcfg = &s_hal_timer_theinternals.items[HAL_timer_id2index(id)]->config; memcpy(&newcfg, curcfg, sizeof(hal_timer_cfg_t)); newcfg.countdown = countdown; hal_timer_init(id, &newcfg, error); if(1 == wasrunning) { hal_timer_start(id); } return(hal_res_OK); }
extern hal_result_t hal_timer_countdown_set(hal_timer_t timer, hal_time_t countdown, hal_time_t *error) { hal_timer_cfg_t *curcfg = NULL; hal_timer_cfg_t newcfg; uint8_t wasrunning = 0; if(hal_false == s_hal_timer_initted_is(timer)) { return(hal_res_NOK_generic); } // if running stop. if(hal_timer_status_running == hal_timer_status_get(timer)) { wasrunning = 1; } // computes the values to be put in registers curcfg = &s_hal_timer_info[HAL_timer_t2index(timer)]->cfg; memcpy(&newcfg, curcfg, sizeof(hal_timer_cfg_t)); newcfg.countdown = countdown; hal_timer_init(timer, &newcfg, error); if(1 == wasrunning) { hal_timer_start(timer); } return(hal_res_OK); #if 0 if(hal_false == s_hal_timer_initted_is(timer)) { return(hal_res_NOK_generic); } if(hal_timer_status_running == s_hal_timer_info[timer]->status) { *(s_hal_timer_info[HAL_timer_t2index(timer)]->reg.confRegAddr) &=0x7FFF; //stop timer (reset TON bit) } *(s_hal_timer_info[HAL_timer_t2index(timer)]->reg.periodRegAddr) = (countdown*1000L)/s_hal_timer_info[timer]->period; *(s_hal_timer_info[HAL_timer_t2index(timer)]->reg.timerRegAddr) = 0; //reset counting register return(hal_res_OK); #endif }