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

📄 mfw_tim.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
+--------------------------------------------------------------------+
| PROJECT: MMI-Framework (8417)         $Workfile:: mfw_tim.c       $|
| $Author: jhxu $ CONDAT GmbH           $Revision: 1.2 $|
| CREATED: 21.09.98                     $Modtime:: 2.03.00 11:49    $|
| STATE  : code                                                      |
+--------------------------------------------------------------------+

   MODULE  : MFW_TIM

   PURPOSE : timer handling functions

   EXPORT  :

   TO DO   :

   $History:: mfw_tim.c                                             $
 * 
 * *****************  Version 12  *****************
 * User: Es           Date: 3.03.00    Time: 12:10
 * Updated in $/GSM/Condat/MS/SRC/MFW
 * timStart(), timSignal() etc.: safer handling of simultaneous
 * timeouts; additional chain in timer control block.
 *
 * *****************  Version 11  *****************
 * User: Nm           Date: 18.02.00   Time: 13:57
 * Updated in $/GSM/Condat/MS/SRC/MFW
 *
 * *****************  Version 10  *****************
 * User: Nm           Date: 18.02.00   Time: 12:34
 * Updated in $/GSM/Condat/MS/SRC/MFW
 * change the name timSetup to
 * timSetTime
 *
 * *****************  Version 9  *****************
 * User: Nm           Date: 18.02.00   Time: 12:21
 * Updated in $/GSM/Condat/MS/SRC/MFW
 * add the function timSetup()
 *
 * *****************  Version 8  *****************
 * User: Es           Date: 14.06.99   Time: 12:14
 * Updated in $/GSM/DEV/MS/SRC/MFW
 *
 * *****************  Version 7  *****************
 * User: Es           Date: 1.04.99    Time: 17:07
 * Updated in $/GSM/DEV/MS/SRC/MFW
 * removed lots of traces
 *
 * *****************  Version 6  *****************
 * User: Es           Date: 18.02.99   Time: 17:01
 * Updated in $/GSM/DEV/MS/SRC/MFW
 *
 * *****************  Version 5  *****************
 * User: Es           Date: 17.02.99   Time: 19:11
 * Updated in $/GSM/DEV/MS/SRC/MFW
 *
 * *****************  Version 4  *****************
 * User: Es           Date: 27.01.99   Time: 15:06
 * Updated in $/GSM/DEV/MS/SRC/MFW
 *
 * *****************  Version 3  *****************
 * User: Es           Date: 14.01.99   Time: 17:19
 * Updated in $/GSM/DEV/MS/SRC/MFW
 *
 * *****************  Version 2  *****************
 * User: Es           Date: 23.12.98   Time: 16:19
 * Updated in $/GSM/DEV/MS/SRC/MFW
*/


#define ENTITY_MFW

#if defined (NEW_FRAME)

#include "typedefs.h"
#include "vsi.h"
#include "custom.h"
#include "gsm.h"

#else

#include "stddefs.h"
#include "custom.h"
#include "gsm.h"
#include "vsi.h"

#endif

#include "mfw_mfw.h"
#include "mfw_sys.h"
#include "drv_tmr.h"
#include "mfw_tim.h"


static MfwTim *timRoot = 0;             /* list of running clocks   */
static int timTimeoutCount;             /* overrun counter          */
static int timTimeoutBusy;              /* overrun marker           */
static int timTimerPrecMs;              /* minimum timer intervall  */

static MfwTim *ActiveTOut = 0;          /* list of timeouts to be processed on this cycle*/
/* PATCH PMC 000721: use another pointer /
         NDH 16/4/2003 : Make it static for use with timDelete also */
static MfwTim *timSavedNext = 0;
/* END PATCH PMC 000721: use another pointer */

static void timInsert (MfwTim *t);
static void timRemove (MfwTim *t);
static void timAdjust (S32 t);
static int timFind (MfwTim *t);
static int timCommand (U32 cmd, void *h);
int timFindOut (MfwHnd h);

MfwHdr * current_mfw_elem;

/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417)        MODULE  : MFW_TIM            |
| STATE   : code                        ROUTINE : timInit            |
+--------------------------------------------------------------------+

  PURPOSE : initialize timer handler

*/

MfwRes timInit (void)
{
    void timTimeout (void);

    timTimeoutCount = 0;
    timTimeoutBusy = 0;
    timRoot = 0;
    mfwCommand[MfwTypTim] = (MfwCb) timCommand;
    tmrInit(timTimeout);
    tmrStart(1);
    timTimerPrecMs = tmrStop();

    return MfwResOk;
}


/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417)        MODULE  : MFW_TIM            |
| STATE   : code                        ROUTINE : timExit            |
+--------------------------------------------------------------------+

  PURPOSE : finalize timer handler

*/

MfwRes timExit (void)
{
    tmrExit();
    mfwCommand[MfwTypTim] = 0;

    return MfwResOk;
}


/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417)        MODULE  : MFW_TIM            |
| STATE   : code                        ROUTINE : timCreate          |
+--------------------------------------------------------------------+

  PURPOSE : create timer control

*/

MfwHnd timCreate (MfwHnd w, S32 t, MfwCb f)
{
    MfwHdr *hdr = (MfwHdr *) mfwAlloc(sizeof(MfwHdr));
    MfwTim *tim = (MfwTim *) mfwAlloc(sizeof(MfwTim));
    MfwHdr *insert_status =0;

    if (!hdr || !tim)
   	 {
    	TRACE_ERROR("ERROR: timCreate() Mem Alloc Failed.");
			
	   	if(hdr)
   			mfwFree((U8*)hdr,sizeof(MfwHdr));

   		if(tim)
   			mfwFree((U8*)tim,sizeof(MfwTim));
   		
	   	return 0;
     }

    tim->time = t;
    tim->left = 0;
    tim->handler = f;
    tim->next = 0;
    // PATCH LE 06.06.00
    // store mfw header address
    tim->mfwHeader = hdr;	/* SPR#1597 - SH - Change mfw_header to mfwHeader */
    // END PATCH LE 06.06.00

    hdr->data = tim;
    hdr->type = MfwTypTim;

    insert_status= mfwInsert(w,hdr);
    if(!insert_status)
	{
  		TRACE_ERROR("ERROR: timCreate() Failed to Install Handler. ");
   		mfwFree((U8*)hdr,sizeof(MfwHdr));
   		mfwFree((U8*)tim,sizeof(MfwTim));
		return 0;
  	}
    return insert_status;
  	
    
}


/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417)        MODULE  : MFW_TIM            |
| STATE   : code                        ROUTINE : timDelete          |
+--------------------------------------------------------------------+

  PURPOSE : delete timer control block

*/

MfwRes timDelete (MfwHnd h)
{
    MfwRes res;

    if (!h)
        return MfwResIllHnd;

    if (((MfwHdr *) h)->type != MfwTypTim)
        return MfwResIllHnd;

    res = (mfwRemove(h)) ? MfwResOk : MfwResIllHnd;

    timStop(h);

    mfwFree(((MfwHdr *) h)->data,sizeof(MfwTim));
    mfwFree(h,sizeof(MfwHdr));

    return res;
}


/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417)        MODULE  : MFW_TIM            |
| STATE   : code                        ROUTINE : timStart           |
+--------------------------------------------------------------------+

  PURPOSE : start timer

*/

MfwRes timStart (MfwHnd h)
{
    MfwTim *tc;
    S32 left, diff;

    if (!h)
        return MfwResIllHnd;

    if (((MfwHdr *) h)->type != MfwTypTim)
        return MfwResIllHnd;

    tc = ((MfwHdr *) h)->data;

    if (tc->time <= 0)
        return MfwResErr;

    if (tc->time < timTimerPrecMs)
        tc->time = timTimerPrecMs;

    tc->left = tc->time;
    left = tmrStop();                   /* get systimer left time   */
    timRemove(tc);                      /* remove, if running       */
    if (left <= tc->left)
        tc->left -= left;               /* adjust for next timer    */
    else
    {
        diff = left - tc->left;         /* correction value         */
        left = tc->left;                /* new timeout              */
        tc->left = 0;                   /* this is the first        */
        timAdjust(diff);                /* correct other timers     */
    }
    timInsert(tc);
    if (!left)                          /* no timer was running     */
    {
        left = timRoot->left;
        tc = timRoot;
        while (tc)
        {
            tc->left -= left;           /* adjust time left entry   */
            tc = tc->next;
        }
    }
    tmrStart(left);                     /* restart timer            */

    return MfwResOk;
}


/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417)        MODULE  : MFW_TIM            |
| STATE   : code                        ROUTINE : timSetup           |
+--------------------------------------------------------------------+

  PURPOSE : Stop the current timer and reload it with the new timeout.


*/

MfwRes timSetTime (MfwHnd h,S32 t)
{
    MfwTim *tc;

    if (!h)
        return MfwResIllHnd;

    if (((MfwHdr *) h)->type != MfwTypTim)
        return MfwResIllHnd;

    timStop (h);                        /* stop the current timer */

    tc = ((MfwHdr *) h)->data;
    tc->time = t;                        /* load with new timeout */
    tc->left = 0;


    return MfwResOk;
}


/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417)        MODULE  : MFW_TIM            |
| STATE   : code                        ROUTINE : timStop            |
+--------------------------------------------------------------------+

  PURPOSE : stop timer

*/

MfwRes timStop (MfwHnd h)
{
    MfwTim *tc;

    if (!h)
        return MfwResIllHnd;

    if (((MfwHdr *) h)->type != MfwTypTim)
        return MfwResIllHnd;

    tc = ((MfwHdr *) h)->data;
    tc->left = 0;

    timRemove(tc);

    return MfwResOk;

⌨️ 快捷键说明

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