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

📄 ssp_tmr.c

📁 abstract rtos
💻 C
📖 第 1 页 / 共 2 页
字号:
#endif        result = FALSE;    }    else    {        AOS_ASSERT(0);    }    AOS_ASSERT(tmr->msg_out);            tmr->msg_out--;            if( TIMER_IS_WAITING != tmr->status )    {        if( !tmr->msg_out )        {                        aos_list_delete( (struct aos_list*)&tmr->prev );                        if( NULL != tmr->pTmr )            {                if( *(tmr->pTmr) == tmr )                {                    *(tmr->pTmr) = NULL;                }                else                {                     aos_printf( MPE_TIMER, "Timer:timeout msg check point to invalid handle=0x%x mpe=%d,"                    "name=%d,para=%d",tmr->pTmr, tmr->mpe,tmr->name,tmr->para );                }            }            TIMER_RETURN_ONE(tmr);        }    }    aos_int_unlock(lockKey);                    return result;}#if( CONFIG_OS_VXWORKS == TRUE )#define OS_INLINE inline#else#define OS_INLINE #endifOS_INLINE static  void  ssp_timer_out( TMR tmr, U32 *lockKey ){        TIMER_CALLBACK    tmp_callback;        SSP_TIMER_MSG_S   *timeout_msg_p;        SSP_TIMER_MSG_S   stTmrMsg;        MSG_S             msg;        U32               tmp_name = 0;        U32               tmp_para = 0;        U32               noMemFlag = 0;            tmp_callback = (TIMER_CALLBACK)NULL;                if( !(AOS_TIMEOUT_BY_CALLBACK&tmr->mode) )        {                        if( tmr->msg_out < TIMER_MAX_MSG_IN_QUEUE )            {                timeout_msg_p = (SSP_TIMER_MSG_S*)aos_msg_alloc(MPE_TIMER, sizeof(SSP_TIMER_MSG_S));                if( NULL == timeout_msg_p )                {                    g_ulTimerQueueFailCnt++;                    noMemFlag = 1;                    timeout_msg_p = &stTmrMsg;                }                timeout_msg_p->app.ulTimerName = tmr->name;                timeout_msg_p->app.ulPara      = tmr->para;                timeout_msg_p->src_tmr         = !noMemFlag ? tmr : NULL;                                msg.srcProcessorId = LOCAL_PROCESSOR_ID;                msg.srcMpe = MPE_TIMER;                msg.dstProcessorId= LOCAL_PROCESSOR_ID;                msg.dstMpe = tmr->mpe;                msg.msgPrio = MSG_PRIO_HIGH;                msg.ulSize = sizeof( TIMER_MSG_S );                msg.pvMsgBuf = (VOID*)timeout_msg_p;                if( !noMemFlag && AOS_SUCC == aos_msg_send(&msg) )                {                    tmr->msg_out++;                }                else                {                     aos_printf( MPE_TIMER, "Timer:send timeout message fail,mpe=%d,"                    "name=%d,para=%d",tmr->mpe,tmr->name,tmr->para );                }            }            else            {                g_ulTimerQueueFailCnt++;                 aos_printf( MPE_TIMER, "Timer:too many timeout message in queue,mpe=%d,"                "name=%d,para=%d,msg_cnt=%u",tmr->mpe,tmr->name,tmr->para, tmr->msg_out );            }        }        else        {             if(  NULL != tmr->callback )            {                tmp_callback = tmr->callback;                tmp_name = tmr->name;                tmp_para = tmr->para;            }        }        if( AOS_TIMER_LOOP & tmr->mode )        {                         tmr->ticks = tmr->init_ticks;             TIMER_LOOP_ENQUEUE(tmr);        }        else        {            if( tmr->msg_out )            {                 	             tmr->status = TIMER_IS_MSGOUT;	             ssp_timer_out_add(tmr);            }  	        else  	        {	            	            if( NULL != tmr->pTmr )	            {	                if( *(tmr->pTmr) == tmr )	                {	                    *(tmr->pTmr) = NULL;	                }	                else	                {	                     aos_printf( MPE_TIMER, "Timer:time out, point to invalid handle=0x%x mpe=%d,"	                    "name=%d,para=%d",tmr->pTmr, tmr->mpe,tmr->name,tmr->para );	                }	            }	            TIMER_RETURN_ONE(tmr);  	        }        }                aos_int_unlock(*lockKey);                if( NULL != tmp_callback )        {            tmp_callback( tmp_name, tmp_para );        }        else if( noMemFlag )        {                                    if( (msg.dstMpe < MPE_BUTT) &&                (TRUE == g_pstMpe[msg.dstMpe].status) )            {                if( g_pstMpe[msg.dstMpe].run )                {                    g_pstMpe[msg.dstMpe].msg_handling = 1;                    g_pstMpe[msg.dstMpe].message_cnt++;                    g_pstMpe[msg.dstMpe].run( &msg, msg.pvMsgBuf );                    g_pstMpe[msg.dstMpe].msg_handling = 0;                }            }                    }        *lockKey = aos_int_lock();}VOID ssp_timer_ticking( U32 ticks ){    TMR tmr;    U32 lockKey;    U32 slot_num;    struct aos_list *node;            if( FALSE == m_ulMsgEnable )    {        return;    }    lockKey = aos_int_lock();            for( slot_num = (ticks < TIMER_QUICK_SLOT_NUM ? ticks : TIMER_QUICK_SLOT_NUM) ; slot_num; slot_num-- )    {        g_ulQuickTimerTs++;        if( TIMER_QUICK_SLOT_NUM == g_ulQuickTimerTs )        {            g_ulQuickTimerTs = 0;        }        for( node = aos_list_fetch( &g_pstQuickTmrList[g_ulQuickTimerTs] );             NULL != node;             node = aos_list_fetch( &g_pstQuickTmrList[g_ulQuickTimerTs] ) )        {            tmr = aos_list_entry(node, struct timer_s, prev);            tmr->prev = tmr->next = NULL;            ssp_timer_out(tmr, &lockKey);        }    }    if( NULL != g_pstWaitTmrList )    {        tmr = g_pstWaitTmrList;        tmr->ticks -= (S32)ticks;        while( (NULL != tmr) && (tmr->ticks <= 0) )        {                        if( NULL != tmr->next )            {                tmr->next->prev = NULL;                tmr->next->ticks += tmr->ticks;            }            g_pstWaitTmrList = tmr->next;            tmr->prev = tmr->next = NULL;            ssp_timer_out(tmr,&lockKey);            tmr = g_pstWaitTmrList;        }        tmr = g_pstWaitTmrList;                while( (NULL != tmr) && (tmr->ticks <TIMER_QUICK_SLOT_NUM) )        {                        if( NULL != tmr->next )            {                tmr->next->prev = NULL;                tmr->next->ticks += tmr->ticks;            }            g_pstWaitTmrList = tmr->next;            tmr->prev = tmr->next = NULL;            ssp_quick_timer_wait_add( tmr );            tmr = g_pstWaitTmrList;        }    }        for( node = aos_list_fetch( &g_pstLoopTmrList );         NULL != node;         node = aos_list_fetch( &g_pstLoopTmrList ) )    {        tmr = aos_list_entry(node, struct timer_s, prev);        TIMER_WAIT_ENQUEUE( tmr );    }    aos_int_unlock(lockKey);}U32 ssp_timer_start( TMR* pTmr,                     MPE mpe,                     U32 ulTimeOut,                     U32 ulTimerName,                     U32 ulPara,                     TIMER_CALLBACK callback,                     U32 ulMode ){    TMR tmr;     if( ulTimeOut < TIMER_MILLISECOND_PER_TICK )    {    	aos_printf( MPE_TIMER, "Timer:start timer, timeout too small,mpe=%d,"    		"time name=%d len=%d, para=%d, callback=0x%x",    		mpe,ulTimerName,ulTimeOut,ulPara,callback );    	ulTimeOut = TIMER_MILLISECOND_PER_TICK;    }            if( (NULL != pTmr) && (NULL != *pTmr) )    {        aos_timer_stop( pTmr );    }    TIMER_GET_ONE( tmr );    if( NULL == tmr )    {        aos_printf( MPE_TIMER, "Timer:memory insufficient,mpe=%d, name=%d"                               ",para=%d,callback=0x%x",mpe,ulTimerName,ulPara,callback );                                       return TIMER_NO_MEM;    }    if( TIMER_IS_NULL != tmr->status )    {        aos_printf( MPE_TIMER, "Timer:start a 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 );    }    if( NULL != pTmr )    {        *pTmr = tmr;    }    tmr->status = TIMER_IS_WAITING;    tmr->mode   = ulMode;    tmr->mpe    = mpe;    tmr->ticks  = (S32)(ulTimeOut/TIMER_MILLISECOND_PER_TICK);    tmr->init_ticks = tmr->ticks;    tmr->name   = ulTimerName;    tmr->para   = ulPara;    tmr->callback=callback;        tmr->msg_out= 0;        tmr->pTmr = pTmr;    TIMER_WAIT_ENQUEUE( tmr );        return AOS_SUCC;    }AOS_INLINE U32 ssp_timer_verify( TMR tmr ){    AOS_ASSERT( NULL !=tmr  );    if(tmr == NULL)    {        return TIMER_ADDR_INVALID;    }    if( (tmr < g_pstTimer) ||(tmr>&g_pstTimer[CONFIG_TIMER_NUMBER-1]) )    {        return TIMER_ADDR_INVALID;    }    return AOS_SUCC;}AOS_INLINE VOID ssp_timer_wait_add( TMR tmr ){    TMR tmr_n, tmr_p;     AOS_ASSERT( NULL !=tmr  );    if(tmr == NULL)    {        return;    }    tmr->mode &= ~AOS_IS_QUICK_TIMER;    if( NULL == g_pstWaitTmrList )    {        tmr->prev = NULL;        tmr->next = NULL;        g_pstWaitTmrList = tmr;        return;    }        tmr_n = g_pstWaitTmrList;    tmr_p = tmr_n;    while( NULL != tmr_n )    {        if( tmr->ticks < tmr_n->ticks )        {            break;        }                tmr->ticks -= tmr_n->ticks;        tmr_p = tmr_n;        tmr_n = tmr_n->next;    }    if( NULL == tmr_n )    {        tmr_p->next = tmr;        tmr->prev   = tmr_p;        tmr->next   = NULL;    }    else     {        tmr->prev   = tmr_n->prev;        tmr->next   = tmr_n;                if( tmr_n == g_pstWaitTmrList )        {            g_pstWaitTmrList = tmr;        }        else        {            tmr_n->prev->next = tmr;        }        tmr_n->prev = tmr;        tmr_n->ticks -= tmr->ticks;    }}AOS_INLINE VOID ssp_timer_out_add( TMR tmr ){    AOS_ASSERT( NULL !=tmr  );    if(tmr == NULL)    {        return;    }        aos_list_add_tail( &g_pstMsgTmrList, (struct aos_list*)&tmr->prev );}AOS_INLINE VOID ssp_quick_timer_wait_add( TMR tmr ){    S32 slot;    tmr->mode |= AOS_IS_QUICK_TIMER;    slot = ( tmr->ticks + (S32)g_ulQuickTimerTs ) % TIMER_QUICK_SLOT_NUM;    tmr->quick_timer_slot = slot;    aos_list_add_tail( &g_pstQuickTmrList[slot], (struct aos_list*)&tmr->prev );}#ifdef __cplusplus#if __cplusplus}#endif #endif 

⌨️ 快捷键说明

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