s32 bsp_hardtimer_free_k3(u32 timer_id)
{
	u32 intLev = 0;
	(void)bsp_hardtimer_disable_k3(timer_id);
	intLev = hard_timer_control[timer_id].interrupt_num;/* [false alarm]:误报 */
	osl_free_irq(intLev,hard_timer_control[timer_id].routine,(int)hard_timer_control[timer_id].arg);
	hard_timer_control[timer_id].routine = NULL;
	hard_timer_control[timer_id].arg = 0;
	return OK;
}
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;
}
Пример #3
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;
}