📄 mtimer.c
字号:
/*
* Copyright (C) Obigo AB, 2002-2005.
* All rights reserved.
*
* This software is covered by the license agreement between
* the end user and Obigo AB, and may be
* used and copied only in accordance with the terms of the
* said agreement.
*
* Obigo AB assumes no responsibility or
* liability for any errors or inaccuracies in this software,
* or any consequential, incidental or indirect damage arising
* out of the use of the software.
*
*/
#include "cansilib.h"
#include "cmnconf.h"
#include "cmntypes.h"
#include "aapicmn.h"
#include "gmem.h"
#include "mmsconf.h"
#include "mmstypes.h"
#include "aapimms.h"
#include "msig.h"
#include "mtimer.h"
#include "mmem.h"
typedef struct m_timer_st
{
struct m_timer_st *next;
MmsStateMachine dst;
UINT32 expire_sec;
UINT32 expire_dsec;
long i_param;
UINT32 u_param1;
UINT32 u_param2;
} m_timer_t;
static m_timer_t *m_timer_list = NULL;
void mTimerInit(void)
{
m_timer_list = NULL;
MMS_LOG_I (("MTIMER: initialized\n"));
}
void mTimerTerminate(void)
{
MMSa_resetTimer();
while (m_timer_list)
{
m_timer_t *t = m_timer_list;
m_timer_list = t->next;
M_FREE(t);
}
MMS_LOG_I(("MTIMER: terminated\n"));
}
void mTimerExpired(void)
{
m_timer_t *t = m_timer_list;
unsigned long now = CMNa_upTime();
if (!t)
{
return;
}
while (t && ((t->expire_sec < now) || ((t->expire_sec == now) && (t->expire_dsec == 0))))
{
M_SIGNAL_SENDTO_IUU(t->dst, MMS_SIG_COMMON_TIMER_EXPIRED,
t->i_param, t->u_param1, t->u_param2);
m_timer_list = t->next;
M_FREE(t);
t = m_timer_list;
}
if (m_timer_list)
{
MMSa_resetTimer();
MMSa_setTimer((m_timer_list->expire_sec - now) * 10
+ m_timer_list->expire_dsec);
}
}
void mTimerSet(MmsStateMachine dst, UINT32 dsecs, long i_param,
UINT32 u_param1, UINT32 u_param2)
{
m_timer_t *prev = NULL;
m_timer_t *t = m_timer_list;
m_timer_t *timer;
int has_reset = 0;
while (t && ((t->dst != dst) || (t->i_param != i_param) ||
(t->u_param1 != u_param1) || (t->u_param2 != u_param2)))
{
prev = t;
t = t->next;
}
if (t)
{
if (prev)
{
prev->next = t->next;
}
else
{
m_timer_list = t->next;
MMSa_resetTimer();
has_reset = 1;
}
timer = t;
}
else
{
timer = (m_timer_t *)M_CALLOC(sizeof(m_timer_t));
timer->dst = dst;
timer->i_param = i_param;
timer->u_param1 = u_param1;
timer->u_param2 = u_param2;
}
timer->expire_sec = CMNa_upTime() + (dsecs / 10);
timer->expire_dsec = dsecs % 10;
for (prev = NULL, t = m_timer_list; t; prev = t, t = t->next)
{
if ((timer->expire_sec < t->expire_sec) ||
((timer->expire_sec == t->expire_sec)
&& (timer->expire_dsec < t->expire_dsec)))
{
break;
}
}
timer->next = t;
if (prev)
{
prev->next = timer;
}
else if (t)
{
if (!has_reset)
{
MMSa_resetTimer();
}
m_timer_list = timer;
MMSa_setTimer(dsecs);
}
else
{
m_timer_list = timer;
MMSa_setTimer(dsecs);
}
}
void mTimerReset(MmsStateMachine dst, long i_param, UINT32 u_param1, UINT32 u_param2)
{
m_timer_t *prev = NULL;
m_timer_t *t = m_timer_list;
while (t && ((t->dst != dst) || (t->i_param != i_param) ||
(t->u_param1 != u_param1) || (t->u_param2 != u_param2)))
{
prev = t;
t = t->next;
}
if (!t)
{
return;
}
if (prev)
{
prev->next = t->next;
}
else
{
m_timer_list = t->next;
MMSa_resetTimer();
mTimerExpired();
}
mSignalFlush( dst, MMS_SIG_COMMON_TIMER_EXPIRED, t->i_param, t->u_param1,
t->u_param2, NULL);
M_FREE(t);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -