⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ssp_tmr.c

📁 abstract rtos
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "syscfg.h"#ifdef __cplusplus#if __cplusplusextern "C"{#endif #endif #include "sys/sys_pub.h"#include "aos.h"#include "ssp_msg.h"#include "ssp_tmr.h"TMR g_pstFreeTmrList = NULL;TMR g_pstWaitTmrList = NULL;struct aos_list g_pstMsgTmrList;struct aos_list g_pstLoopTmrList;struct aos_list *g_pstQuickTmrList;TMR g_pstTimer = NULL;U32 g_ulQuickTimerTs;U32 g_ulTimerQueueFailCnt;    extern U32    m_ulMsgEnable;U32 ssp_timer_start( TMR* pTmr,                     MPE mpe,                     U32 ulTimeOut,                     U32 ulTimerName,                     U32 ulPara,                     TIMER_CALLBACK callback,                     U32 ulMode );AOS_INLINE U32 ssp_timer_verify( TMR tmr );AOS_INLINE VOID ssp_timer_wait_add( TMR tmr );AOS_INLINE VOID ssp_timer_out_add( TMR tmr );AOS_INLINE VOID ssp_quick_timer_wait_add( TMR tmr );#define TIMER_WAIT_ENQUEUE(t)\ \do\{\    if( (t)->ticks < TIMER_QUICK_SLOT_NUM )\    {\        ssp_quick_timer_wait_add(t);\    }\    else\    {\        ssp_timer_wait_add(t);\    }\}while(0)#define TIMER_LOOP_ENQUEUE(t)\ \do\{\    aos_list_add_tail( &g_pstLoopTmrList, (struct aos_list*)&(t)->prev );\}while(0)                     U32 m_timer_init(){        U32 index;            g_pstFreeTmrList = NULL;    g_pstWaitTmrList = NULL;    g_ulQuickTimerTs = 0;    g_ulTimerQueueFailCnt = 0;    aos_list_init( &g_pstMsgTmrList );    aos_list_init( &g_pstLoopTmrList );    g_pstQuickTmrList = (struct aos_list*)aos_smem_alloc(MPE_TIMER, SID_TIMER_QUE, sizeof(struct aos_list)*(TIMER_QUICK_SLOT_NUM) );    if( NULL == g_pstQuickTmrList )    {        return TIMER_MOD_INIT_NO_MEM;    }        for( index = 0; index < TIMER_QUICK_SLOT_NUM; index++ )    {        aos_list_init( &g_pstQuickTmrList[index] );    }    g_pstTimer = (TMR)aos_smem_alloc(MPE_TIMER, SID_TIMER, sizeof(TIMER_S)*CONFIG_TIMER_NUMBER );    if( NULL == g_pstTimer )    {        return TIMER_MOD_INIT_NO_MEM;    }    for( index=0; index < CONFIG_TIMER_NUMBER; index++)    {        TIMER_RETURN_ONE( (&g_pstTimer[index]) );    }    return AOS_SUCC;}U32 aos_timer_start( TMR* pTmr,                     MPE mpe,                     U32 ulTimeOut,                     U32 ulTimerName,                     U32 ulPara,                     U32 ulMode ){    U32 result,lockKey;        result = ssp_mpe_msg_verify( mpe );    if( AOS_SUCC != result )    {         return result;    }    if( (AOS_TIMER_LOOP != ulMode) && (AOS_TIMER_NO_LOOP != ulMode) )    {        return TIMER_HANDLE_NULL;    }    lockKey = aos_int_lock();    result = ssp_timer_start(pTmr, mpe, ulTimeOut, ulTimerName, ulPara, (TIMER_CALLBACK)NULL, ulMode );    aos_int_unlock(lockKey);    return result;}U32 aos_callbacktimer_start( TMR* pTmr,                             MPE mpe,                             U32 ulTimeOut,                             U32 ulTimerName,                             U32 ulPara,                             TIMER_CALLBACK callback,                             U32 ulMode ){    U32 result, lockKey;        result = ssp_mpe_verify( mpe );    if( AOS_SUCC != result )    {         return result;    }    if( (AOS_TIMER_LOOP != ulMode) && (AOS_TIMER_NO_LOOP != ulMode) )    {        return TIMER_MODE_INVALID;    }    if( NULL == callback )    {        return TIMER_CALLBACK_INVALID;    }    ulMode |= AOS_TIMEOUT_BY_CALLBACK;    lockKey = aos_int_lock();    result = ssp_timer_start(pTmr, mpe, ulTimeOut, ulTimerName, ulPara, callback, ulMode );    aos_int_unlock(lockKey);        return result;}U32 aos_timer_stop( TMR *pTmr){    TMR tmr;    U32 lockKey;        if( NULL == pTmr )    {        return TIMER_HANDLE_NULL;    }    tmr = *pTmr;    if( NULL == tmr )    {        return AOS_SUCC;    }    if( AOS_SUCC != ssp_timer_verify(tmr) )    {        aos_printf( MPE_TIMER, "Timer:This handler points to an invalid timer"                                            " addres,handle =0x%x, tmr=0x%x",pTmr, tmr);        return TIMER_HANDLE_INVALID;    }    if( tmr->pTmr != pTmr )    {        aos_printf( MPE_TIMER, "Timer:Invalid timer handle,handle =0x%x, tmr=0x%x\r\n",pTmr, tmr);        aos_printf( MPE_TIMER, "Timer:status=0x%x,mpe=%d,name=%d,para=%d,callback=0x%x",                                            tmr->status,tmr->mpe,tmr->name,tmr->para,tmr->callback);    }    lockKey = aos_int_lock();    *pTmr = NULL;    switch (tmr->status)    {        case TIMER_IS_WAITING:            if( tmr->mode & AOS_IS_QUICK_TIMER )            {                aos_list_delete( (struct aos_list*)&tmr->prev );            }            else            {                if( NULL != tmr->prev )                {                    tmr->prev->next  = tmr->next;                }                if( NULL != tmr->next )                {                    tmr->next->prev = tmr->prev;                    tmr->next->ticks += tmr->ticks;                }                if( tmr == g_pstWaitTmrList )                {                    g_pstWaitTmrList  = tmr->next;                }            }            tmr->status = TIMER_IS_DELETED;            tmr->pTmr   = NULL;            break;        case TIMER_IS_MSGOUT:            if( tmr->msg_out )            {                tmr->status = TIMER_IS_DELETED;                tmr->pTmr   = NULL;                #if CONFIG_DEBUG_TIMER                aos_printf( MPE_TIMER, "Timer:stop a timeout timer,handle =0x%x, tmr=0x%x",pTmr, tmr );                          aos_printf( MPE_TIMER, "Timer:mpe=%d,name=%d,para=%d,callback=0x%x",                                            tmr->mpe,tmr->name,tmr->para,tmr->callback);#endif            }            else            {                aos_printf( MPE_TIMER, "Timer:stop a timeout timer,handle =0x%x, tmr=0x%x\r\n",pTmr, tmr );                          aos_printf( MPE_TIMER, "Timer:in invalid status mpe=%d,name=%d,para=%d,callback=0x%x",                                            tmr->mpe,tmr->name,tmr->para,tmr->callback );                                                            TIMER_RETURN_ONE(tmr);            }            aos_int_unlock(lockKey);                        return AOS_SUCC;        case TIMER_IS_NULL:                    aos_int_unlock(lockKey);            aos_printf( MPE_TIMER, "Timer:stop a null timer,handle =0x%x, tmr=0x%x\r\n",pTmr, tmr);                        return TIMER_ERROR_STATE;                case TIMER_IS_DELETED:            aos_int_unlock(lockKey);                    aos_printf( MPE_TIMER, "Timer:stop a stopped timer,handle =0x%x, tmr=0x%x\r\n",pTmr, tmr);            return TIMER_ERROR_STATE;        default:            aos_int_unlock(lockKey);        	            aos_printf( MPE_TIMER, "Timer:timer in invalid status,handle =0x%x, tmr=0x%x\r\n",pTmr, tmr);            return TIMER_ERROR_STATE;    }        if( !(AOS_TIMER_LOOP & tmr->mode) )    {                if( !tmr->msg_out )        {                        TIMER_RETURN_ONE(tmr);        }        else        {            aos_printf( MPE_TIMER, "Timer:stop a timeout timer,handle =0x%x, tmr=0x%x\r\n",pTmr, tmr );                      aos_printf( MPE_TIMER, "Timer:in invalid status mpe=%d,name=%d,para=%d,callback=0x%x",                                            tmr->mpe,tmr->name,tmr->para,tmr->callback );            aos_int_unlock(lockKey);            return TIMER_ERROR_STATE;        }        aos_int_unlock(lockKey);        return AOS_SUCC;    }    if( tmr->msg_out )    {          tmr->pTmr = NULL;        ssp_timer_out_add( tmr );    }    else    {                TIMER_RETURN_ONE(tmr);    }        aos_int_unlock(lockKey);    return AOS_SUCC;}U32 aos_timer_pass_msec( TMR *pTmr){    TMR tmr,next;    U32 lockKey,res_ticks,pass_ticks;        if( NULL == pTmr )    {        return 0;    }    tmr = *pTmr;    if( NULL == tmr )    {        return 0;    }    if( AOS_SUCC != ssp_timer_verify(tmr) )    {        aos_printf( MPE_TIMER, "Timerp:This handler points to an invalid timer"                                            " addres,handle =0x%x, tmr=0x%x",pTmr, tmr);        return 0;    }    if( tmr->pTmr != pTmr )    {        aos_printf( MPE_TIMER, "Timerp:Invalid timer handle,handle =0x%x, tmr=0x%x\r\n",pTmr, tmr);        aos_printf( MPE_TIMER, "Timerp:status=0x%x,mpe=%d,name=%d,para=%d,callback=0x%x",                                            tmr->status,tmr->mpe,tmr->name,tmr->para,tmr->callback);    }    switch (tmr->status)    {        case TIMER_IS_WAITING:            lockKey = aos_int_lock();            if( tmr->mode & AOS_IS_QUICK_TIMER )            {                if( tmr->quick_timer_slot < g_ulQuickTimerTs )                {                    res_ticks = tmr->quick_timer_slot + TIMER_QUICK_SLOT_NUM - g_ulQuickTimerTs;                }                else                {                    res_ticks = tmr->quick_timer_slot - g_ulQuickTimerTs;                }            }            else            {                res_ticks = 0;                next = g_pstWaitTmrList;                while( NULL != next )                {                    res_ticks += next->ticks;                    if( tmr == next)                    {                        break;                    }                    next = next->next;                }                if( tmr != next )                {                    AOS_ASSERT(0);                }            }            pass_ticks = tmr->init_ticks - res_ticks;            aos_int_unlock(lockKey);            return pass_ticks * TIMER_MILLISECOND_PER_TICK;        case TIMER_IS_MSGOUT:            return tmr->init_ticks * TIMER_MILLISECOND_PER_TICK;        default:            aos_printf( MPE_TIMER, "Timerp:timer in invalid status,handle =0x%x, tmr=0x%x\r\n",pTmr, tmr);            return 0;    }}BOOL_T ssp_timeout_msg_check( VOID *timeout_msg_p ){    TMR tmr;	U32 result = TRUE, lockKey;        AOS_ASSERT( NULL != timeout_msg_p );    if(timeout_msg_p == NULL)    {        return FALSE;    }    tmr = ((SSP_TIMER_MSG_S*)timeout_msg_p)->src_tmr;    if( AOS_SUCC != ssp_timer_verify(tmr) )    {        aos_printf( MPE_TIMER, "Timer:ssp_timeout_msg_check error,msg=0x%x,tmr=0x%x", timeout_msg_p, tmr );        return FALSE;    }    lockKey = aos_int_lock();    if( (TIMER_IS_MSGOUT == tmr->status) ||        (TIMER_IS_WAITING == tmr->status) )    {        result = TRUE;    }    else if( TIMER_IS_DELETED == tmr->status )    {#if CONFIG_DEBUG_TIMER        aos_printf( MPE_TIMER, "Timer:timer has been stopped!,this timeout msg to be discarded");        aos_printf( MPE_TIMER, "Timer:mpe=%d,name=%d,para=%d",tmr->mpe,tmr->name,tmr->para );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -