📄 tsksync.c
字号:
///////////////////////////////////////////////////////////////////////////////
// File: Tsksync.c
// Date: 2001-6-20 pm 04:47:44
// Written by: CYu
// Decription:
//------------------------------------------------------------------------------
// Copyright: CNASIC Proprietary Material
// Copyright (c) 2001, All Rights Reserved By:
// National ASIC System Engineering Research Center (CNASIC)
// SouthEast University
//
// DISTRIBUTION PROHIBITED without written authorization from CNASIC
//------------------------------------------------------------------------------
// Modification History
//
///////////////////////////////////////////////////////////////////////////////
/* System and Standard Header */
#include <kernel\ros33\itron.h>
#include <kernel\ros33\ros33.h>
#define _SIZE_T_DEFINED
#include <windows.h>
/* Application Header */
#include "internal.h"
//--- macro and definition -----------------------------------------------------
//--- static variables ---------------------------------------------------------
//--- external variables -------------------------------------------------------
//--- shared variables ---------------------------------------------------------
//--- static functions ---------------------------------------------------------
//--- external functions -------------------------------------------------------
//------------------------------------------------------------------------------
// Function name : tslp_tsk
// Description :
// Return type : ER
// Argument : TMO tmout - not implemented yet
// Remarks :
// So also :
//------------------------------------------------------------------------------
ER tslp_tsk( TMO tmout )
{
#if ENABLE_SYSCALL_STATISTIC
gSyscallSta[12].sta++;
#endif
if( g_ubSysStat & TSS_DDSP ) // task in dispatch disabled state
return E_CTX;
if( tmout <= -2 )
return E_PAR;
ENTER_CS
if( aTcb[idCurTask].uhWupcnt <= 0)
{
if( tmout == TMO_POL )
{
LEAVE_CS
return E_TMOUT;
}
aTcb[idCurTask].ubStatus |= TTS_WAI;
aTcb[idCurTask].ubWaitStat |= TTW_SLP;
RemoveTaskFromReadyQueue( aTcb[idCurTask].bPriority, idCurTask );
if( tmout!=TMO_FEVR )
SetTimer( hwndClient, idCurTask, tmout, ( TIMERPROC )PollingTimerHandler );
LEAVE_CS
ContextSwitch( );
return aTcb[idCurTask].vwWaitRet;// return value is E_OK or E_RLWAI
}
else
aTcb[idCurTask].uhWupcnt--;
LEAVE_CS
return E_OK;
}
//------------------------------------------------------------------------------
// Function name : rel_wai
// Description :
// Return type : ER
// Argument : ID tskid
// Remarks :
// So also :
//------------------------------------------------------------------------------
ER rel_wai( ID tskid )
{
#if ENABLE_SYSCALL_STATISTIC
gSyscallSta[7].sta++;
#endif
if( tskid<=0 )
return E_ID;
if( tskid>TSK_NUM )
return E_NOEXS;
ENTER_CS
if( !aTcb[tskid].fpPC )
{
LEAVE_CS
return E_NOEXS;
}
if( tskid==idCurTask || aTcb[tskid].ubStatus & TTS_DMT )
{
LEAVE_CS
return E_OBJ;
}
// Is status TTS_RUN or TTS_RDY? ie., in the ready queue
if( !(aTcb[tskid].ubStatus & ( ~( TTS_RUN | TTS_RDY ) ) ) )
{
LEAVE_CS
return E_OBJ;
}
aTcb[tskid].ubStatus &= ~TTS_WAI;
aTcb[tskid].ubWaitStat = 0;
aTcb[tskid].vwWaitRet = E_RLWAI;
AppendTaskToReadyQueue( tskid );
LEAVE_CS
ContextSwitch( );
return E_OK;
}
//------------------------------------------------------------------------------
// Function name : wup_tsk
// Description :
// Return type : ER
// Argument : ID tskid
// Remarks :
// So also :
//------------------------------------------------------------------------------
ER wup_tsk( ID tskid )
{
#if ENABLE_SYSCALL_STATISTIC
gSyscallSta[13].sta++;
#endif
if( tskid<=0 )
return E_ID;
if( tskid>TSK_NUM )
return E_NOEXS;
ENTER_CS
if( !aTcb[idCurTask].fpPC )
{
LEAVE_CS
return E_NOEXS;
}
if( tskid == idCurTask || aTcb[tskid].ubStatus & TTS_DMT )
{
LEAVE_CS
return E_OBJ;
}
if( aTcb[tskid].uhWupcnt>=WUP_CNT )
{
LEAVE_CS
return E_QOVR;
}
if( !( aTcb[tskid].ubStatus & TTS_WAI ) )
{
aTcb[tskid].uhWupcnt++;
LEAVE_CS
return E_OK;
}
if( aTcb[tskid].ubStatus & TTS_WAI && aTcb[tskid].ubWaitStat & TTW_SLP )
{
aTcb[tskid].ubStatus &= ~TTS_WAI;
aTcb[tskid].ubWaitStat &= ~TTW_SLP;
aTcb[tskid].vwWaitRet = E_TMOUT;
AppendTaskToReadyQueue( tskid );
LEAVE_CS
ContextSwitch( );
}
else
{
LEAVE_CS
}
return E_OK;
}
//------------------------------------------------------------------------------
// Function name : can_wup
// Description :
// Return type : ER
// Argument : INT *p_wupcnt
// Argument : ID tskid
// Remarks :
// So also :
//------------------------------------------------------------------------------
ER can_wup( INT *p_wupcnt,
ID tskid )
{
#if ENABLE_SYSCALL_STATISTIC
gSyscallSta[14].sta++;
#endif
if( tskid<0 )
return E_ID;
if( tskid>TSK_NUM )
return E_NOEXS;
if( tskid == TSK_SELF)
tskid = idCurTask;
ENTER_CS
if( !aTcb[tskid].fpPC )
{
LEAVE_CS
return E_NOEXS;
}
if( aTcb[tskid].ubStatus & TTS_DMT )
{
LEAVE_CS
return E_OBJ;
}
*p_wupcnt = aTcb[tskid].uhWupcnt;
aTcb[tskid].uhWupcnt = 0;
LEAVE_CS
return E_OK;
}
//------------------------------------------------------------------------------
// Function name : sus_tsk
// Description :
// Return type : ER
// Argument : ID tskid
// Remarks :
// So also :
//------------------------------------------------------------------------------
ER sus_tsk( ID tskid )
{
#if ENABLE_SYSCALL_STATISTIC
gSyscallSta[9].sta++;
#endif
if( tskid<=0 )
return E_ID;
if( tskid>TSK_NUM )
return E_NOEXS;
ENTER_CS
if( !aTcb[tskid].fpPC )
{
LEAVE_CS
return E_NOEXS;
}
if( tskid==idCurTask || aTcb[tskid].ubStatus&TTS_DMT )
{
LEAVE_CS
return E_OBJ;
}
if( aTcb[tskid].ubStatus & TTS_SUS )
{
LEAVE_CS
return E_QOVR;
}
aTcb[tskid].ubStatus |= TTS_SUS;
RemoveTaskFromReadyQueue( aTcb[tskid].bPriority, tskid );
LEAVE_CS
ContextSwitch( );
return E_OK;
}
//------------------------------------------------------------------------------
// Function name : rsm_tsk
// Description :
// Return type : ER
// Argument : ID tskid
// Remarks :
// So also :
//------------------------------------------------------------------------------
ER rsm_tsk( ID tskid )
{
#if ENABLE_SYSCALL_STATISTIC
gSyscallSta[10].sta++;
#endif
if( tskid<=0 )
return E_ID;
if( tskid>TSK_NUM )
return E_NOEXS;
ENTER_CS
if( !aTcb[tskid].fpPC )
{
LEAVE_CS
return E_NOEXS;
}
if( idCurTask==tskid || !(aTcb[tskid].ubStatus & TTS_SUS) || aTcb[tskid].ubStatus & TTS_DMT )
{
LEAVE_CS
return E_OBJ;
}
aTcb[tskid].ubStatus &= ~TTS_SUS;
AppendTaskToReadyQueue( tskid );
LEAVE_CS
ContextSwitch( );
return E_OK;
}
//----------------------------- The End of the File ----------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -