📄 os_timer.c
字号:
/**************** os_timer.c**************/
/* MacroStar 1.0a */
/* Zhengyuquan,2003.7,Beijing */
/* All rights reserved */
/****************************************/
#include "mStar.h"
volatile uint_16 os_timerState=0XFFFF;
const uint_16 os_timerMask=0XFFFF;
TIMER os_timers[MAX_TIMER_NUM]; // 16*8=128
volatile uint_16 os_sysTime;
/*
************************************************************
*
*
*
************************************************************
*/
void STDCALL _FAR os_OnTimerIn( )
{
register uint_16 timerMask = 0x8000;
uint_16 timerflag = os_timerState^os_timerMask;
PTIMER pTimer = os_timers;
PTCB pTCB;
os_sysTime++;
while( timerflag )
{
if(timerMask&timerflag)
{
if( !(--pTimer->elapse) )
{
pTCB = &os_tcbs[ pTimer->taskId ];
if( pTimer->lpTimerFunc)(*pTimer->lpTimerFunc)(pTimer->taskId,pTimer->timerId);
pTimer->elapse = pTimer->backTime;
switch( pTimer->timerId&0xF0 )
{
case SLEEP_ID:
os_slpState |= os_maskTable[ pTCB->priority ];
os_timerState |= timerMask;
os_SetSwitchFlag( );
break;
case 0x00:
pTCB->msg[0] |= os_maskTable[ pTimer->timerId ];
os_rdyhState |= os_maskTable[ pTCB->priority ];
os_SetSwitchFlag( );
break;
case 0x10:
pTCB->msg[1] |= os_maskTable[pTimer->timerId&0x0f];
os_rdyState |= os_maskTable[ pTCB->priority];
os_SetSwitchFlag( );
/*default*/
}
}
timerflag ^= timerMask;
}
pTimer++;
timerMask >>= 1;
}
}
/*
************************************************************
*
*
*
************************************************************
*/
HTIMER STDCALL _FAR os_SetTimerIn(uchar timerId, uint_16 elapse, TIMERPROC lpTimerFunc)
{
HTIMER hTimer = NULL_TIMER;
PTIMER pTimer;
uint_16 temp ;
ENTER_CRITICAL_SEG( );
if( temp = os_timerState )
{
if(HIGHBYTE(temp))
hTimer = os_fastTable[ HIGHBYTE(temp) ];
else
hTimer = os_fastTable[ LOWBYTE(temp) ] | 8;
pTimer = &os_timers[hTimer];
pTimer->backTime = elapse;
pTimer->timerId = timerId;
pTimer->taskId = os_GetCurrentTaskId( );
pTimer->lpTimerFunc = lpTimerFunc;
LOCK_INT( );
os_timerState ^= os_maskTable[ hTimer];
pTimer->elapse = elapse;
UNLOCK_INT( );
}
LEAVE_CRITICAL_SEG( );
return hTimer;
}
/*
************************************************************
*
*
*
************************************************************
*/
void STDCALL _FAR os_KillTimer(HTIMER hTimer)
{
os_ASSERT( !(hTimer&0xF0),KILL_INVALID_HTIMER );
os_WARNING( !(os_timerState&os_maskTable[hTimer]),KILL_UNUSED_TIMER);
os_timerState |= os_maskTable[ hTimer ];
}
/*
************************************************************
*
*
*
************************************************************
*/
void STDCALL _FAR os_Sleep(uint_16 elapse)
{
LOCK_SCHEDULE( );
if( os_timerState )
{
os_slpState ^= os_curPrioMask;
os_SetTimerIn(SLEEP_ID,elapse,0);
}
UNLOCK_SCHEDULE( );
os_Schedule( );
}
#ifdef _DEBUG
/*
************************************************************
*
*
*
************************************************************
*/
HTIMER STDCALL _FAR os_SetTimer(uchar timerId, uint_16 elapse, TIMERPROC lpTimerFunc)
{
os_ASSERT( !(timerId&0xC0),SET_INVALID_TIMERID);
return os_SetTimerIn(timerId,elapse,lpTimerFunc);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -