/*测试函数接口操作timer0*/
s32 hardtimer_test_case01(void)
{
   u32 i=0; 
   s32 ret = 0;
   my_timer.func =(timer_func) for_timer_test;
   my_timer.mode = TIMER_PERIOD_COUNT;
   my_timer.timeout = 32768;
   my_timer.timerId = i;
   my_timer.para = i;
   osl_sem_init(SEM_EMPTY,&sem);
   ret = bsp_hardtimer_alloc(&my_timer);
   if (OK != ret)
   	return ERROR;
   ret = bsp_hardtimer_enable(my_timer.timerId);
   if (OK != ret)
   	return ERROR;
   osl_sem_down(&sem);
   ret = bsp_hardtimer_free(i);
   if (OK != ret)
   {
	osl_sem_up(&sem);
	osl_sema_delete(&sem);
	return ERROR;
    }
   osl_sem_up(&sem);
   osl_sema_delete(&sem);
   return OK;
}
OSL_IRQ_FUNC(static return_type,for_test_unit,irq,para)
{
   s32 ret;
   ret = bsp_hardtimer_disable(my_timer.timerId);
   if (ret == OK)
   	cnt++;
 	bsp_hardtimer_enable(my_timer.timerId);
   return IRQ_HANDLED;
}
int DRV_TIMER_START(unsigned int usrClkId,FUNCPTR_1 routine,int argument,unsigned int timerValue,unsigned int mode,unsigned int unitType)
{
    s32 ret = 0;
    struct bsp_hardtimer_control my_hardtimer;
    u32 intLev = adp_timer_ctrl[usrClkId].int_num;/* [false alarm]:误报 从不使用指定的初始值*/
    if(usrClkId==TIMER_CCPU_CPUVIEW_ID)
    {
        if(adp_timer_ctrl[usrClkId].routine)/* [false alarm]:误报 */
        {
            osl_free_irq(intLev,(VOIDFUNCPTR)adp_timer_handler,(int)usrClkId);/*lint !e64*/
            adp_timer_ctrl[usrClkId].routine = NULL;
        }
   }
    my_hardtimer.func = NULL;
    my_hardtimer.para = 0;
    my_hardtimer.mode = mode;
    my_hardtimer.timerId = usrClkId;
    adp_timer_ctrl[usrClkId].routine = routine;
    adp_timer_ctrl[usrClkId].args = argument;
    adp_timer_ctrl[usrClkId].mode = mode;
    if (TIMER_UNIT_MS==unitType)/*ms*/
    {
        if(HI_TCXO_CLK == adp_timer_ctrl[usrClkId].clk)
        {
            my_hardtimer.timeout = adp_timer_ctrl[usrClkId].clk*timerValue/Second_To_Millisecond;
        }
        else
        {
            my_hardtimer.timeout = adp_timer_ctrl[usrClkId].clk/Second_To_Millisecond*timerValue;	
        }
    }
    else if (TIMER_UNIT_US==unitType)/*us*/
    {
        if(HI_TIMER_CLK == adp_timer_ctrl[usrClkId].clk)/* [false alarm]:误报 dead code*/
        {
            my_hardtimer.timeout = adp_timer_ctrl[usrClkId].clk/Second_To_Millisecond*timerValue/Second_To_Millisecond;
        }
        else
        {
        if (timerValue > TIMER_32K_US_BOUNDARY)
            {
                 my_hardtimer.timeout = (timerValue * adp_timer_ctrl[usrClkId].clk) / Second_To_Millisecond / Second_To_Millisecond;/* [false alarm]:误报 dead code*/
            }
            else
            {
                /* 对于不大于31us的定时,直接往load寄存器写1 */
                 my_hardtimer.timeout = 1;
            }
        }
    }
    else if(TIMER_UNIT_NONE == unitType)/*直接操作寄存器*/
    {
        my_hardtimer.timeout = timerValue;/* [false alarm]:误报 dead code*/
    }
    #ifdef K3_TIMER_FEATURE
    if(usrClkId >= 8)
        ret = bsp_hardtimer_alloc_k3(&my_hardtimer);/* [false alarm]:误报 */
    else
        ret = bsp_hardtimer_alloc(&my_hardtimer);
    #else
        ret = bsp_hardtimer_alloc(&my_hardtimer);
    #endif
    if(ret)
    {
         return ERROR;
    }
    if(usrClkId==TIMER_CCPU_CPUVIEW_ID)
    {
        ret = request_irq( adp_timer_ctrl[usrClkId].int_num,(irq_handler_t)adp_timer_handler,0,"timer callback",(void*)usrClkId);/* [false alarm]:误报 */
        if(ret)
        {
            return ERROR;
        }
    }
    timer_enable_stamp_dbg(usrClkId,my_hardtimer.timeout);
    #ifdef K3_TIMER_FEATURE
    if(usrClkId >= 8)
        (void)bsp_hardtimer_enable_k3(usrClkId);
    else
    (void)bsp_hardtimer_enable(usrClkId);
    #else
    (void)bsp_hardtimer_enable(usrClkId);
    #endif
    return 0;
}
Пример #4
0
int DRV_TIMER_START(unsigned int usrClkId,FUNCPTR_1 routine,int arg,unsigned int timerValue,unsigned int mode,unsigned int unitType)
{
    s32 ret = 0;
    struct bsp_hardtimer_control my_hardtimer;
    u32 intLev = adp_timer_ctrl[usrClkId].int_num;
    if(TIMER_ACPU_CPUVIEW_ID==usrClkId)
    {
        if(adp_timer_ctrl[usrClkId].routine)
        {
            osl_free_irq(intLev,adp_timer_handler,usrClkId);
            adp_timer_ctrl[usrClkId].routine = NULL;
        }
    }
    my_hardtimer.func = NULL;
    my_hardtimer.para = 0;
    my_hardtimer.mode = mode;
    my_hardtimer.timerId = usrClkId;
    adp_timer_ctrl[usrClkId].routine = routine;
    adp_timer_ctrl[usrClkId].args = arg;
    adp_timer_ctrl[usrClkId].mode = mode;
    if (TIMER_UNIT_MS==unitType)/*ms*/
    {
        if(HI_TCXO_CLK == adp_timer_ctrl[usrClkId].clk)
        {
            my_hardtimer.timeout = adp_timer_ctrl[usrClkId].clk*timerValue/Second_To_Millisecond;
        }
        else
        {
            my_hardtimer.timeout = adp_timer_ctrl[usrClkId].clk/Second_To_Millisecond*timerValue;
        }
    }
    else if (TIMER_UNIT_US==unitType)/*us*/
    {
        if(HI_TIMER_CLK == adp_timer_ctrl[usrClkId].clk)
        {
            my_hardtimer.timeout = adp_timer_ctrl[usrClkId].clk/Second_To_Millisecond*timerValue/Second_To_Millisecond;
        }
        else
        {
            if (timerValue > TIMER_32K_US_BOUNDARY)
            {
                my_hardtimer.timeout = (timerValue * adp_timer_ctrl[usrClkId].clk) / Second_To_Millisecond / Second_To_Millisecond;
            }
            else
            {
                my_hardtimer.timeout = 1;
            }
        }
    }
    else if(TIMER_UNIT_NONE == unitType)/*直接操作寄存器*/
    {
        my_hardtimer.timeout = timerValue;
    }
    ret = bsp_hardtimer_alloc(&my_hardtimer);
    if(ret)
    {
        return ERROR;
    }
    if(TIMER_ACPU_CPUVIEW_ID==usrClkId)
    {
        ret = request_irq( adp_timer_ctrl[usrClkId].int_num,(irq_handler_t)adp_timer_handler,0,"timer callback",(void*)usrClkId);
        if(ret)
        {
            return ERROR;
        }
    }
    timer_enable_stamp_dbg(usrClkId,my_hardtimer.timeout);
    (void)bsp_hardtimer_enable(usrClkId);
    return 0;
}