📄 tsksync.c
字号:
//*************************************************************************
//
// Copyright (C) SEIKO EPSON CORP. 1997
// All Rights Reserved
//
// Filename : tsksync.c
// Function : Task-Dependent Synchronization Functions for C33 itron
// Revision :
// 1997/08/01 H.Matsuoka start
// 1999/08/27 H.Matsuoka BUG FIX(critical section)
// 1999/11/25 H.Matsuoka Add iwup_tsk
// 2000/02/23 H.Matsuoka Fix suspend status problem
// 2000/11/29 Y.Taka Add Enter/Return_critical_section
// 2001/01/22 Y.Taka Add tslp_tsk()
// 2001/03/08 Y.Taka Change critical section
//
//*************************************************************************
#include "ros33.h"
#include "internal.h"
//****************************************************************************
//*** 3.2 Task-Dependent Synchronization Functions ***
//****************************************************************************
//********************************************************************
// Suspend Other Task
// [Parameters]
// ID tskid TaskID
// [Return Parameters]
// ER ercd ErrorCode
//********************************************************************
ER sus_tsk(ID tskid)
{
T_TSKCB* pTskcb;
UW psr;
#ifndef NO_ERROR_CHECK
if(tskid <= 0) // 0 is tskid = TSK_SELF
{
return E_ID;
}
if(tskid > TSK_NUM)
{
return E_NOEXS;
}
#endif
psr = ent_cri();
pTskcb = &g_sTskcb[tskid-1];
#ifndef NO_ERROR_CHECK
if(pTskcb->fpPC == 0)
{
ret_cri(psr);
return E_NOEXS;
}
if((pTskcb == g_pCurTsk)
|| (pTskcb->ubStatus & TTS_DMT))
{
ret_cri(psr);
return E_OBJ;
}
if(pTskcb->ubStatus & TTS_SUS)
{
ret_cri(psr);
return E_QOVR;
}
#endif
pTskcb->ubStatus |= TTS_SUS;
ret_cri(psr);
#ifndef NO_RETURN_VALUE
return E_OK;
#endif
}
//********************************************************************
// Resume Suspended Task
// [Parameters]
// ID tskid TaskID
// [Return Parameters]
// ER ercd ErrorCode
//********************************************************************
ER rsm_tsk(ID tskid)
{
T_TSKCB* pTskcb;
UW psr;
#ifndef NO_ERROR_CHECK
if(tskid <= 0) // 0 is tskid = TSK_SELF
{
return E_ID;
}
if(tskid > TSK_NUM)
{
return E_NOEXS;
}
#endif
psr = ent_cri();
pTskcb = &g_sTskcb[tskid-1];
#ifndef NO_ERROR_CHECK
if(pTskcb->fpPC == 0)
{
ret_cri(psr);
return E_NOEXS;
}
if((pTskcb == g_pCurTsk)
|| (!(pTskcb->ubStatus & TTS_SUS))
|| (pTskcb->ubStatus & TTS_DMT))
{
ret_cri(psr);
return E_OBJ;
}
#endif
pTskcb->ubStatus &= ~TTS_SUS;
int_dispatch(); // dispatch & disable interrupt
ret_cri(psr);
#ifndef NO_RETURN_VALUE
return E_OK;
#endif
}
//********************************************************************
// Sleep Task
// [Parameters]
// TMO tmout Timeout
// [Return Parameters]
// ER ercd ErrorCode
//********************************************************************
ER tslp_tsk(TMO tmout)
{
UW psr;
#ifndef NO_ERROR_CHECK
if((g_ubIntNestCnt != 0) // issued from task-independent portions
|| (g_ubSysStat & TSS_DDSP)) // task in dispatch disabled state
{
return E_CTX;
}
if(tmout <= -2)
{
return E_PAR;
}
#endif
psr = ent_cri();
if(g_pCurTsk->uhWupcnt == 0)
{
if (tmout == TMO_POL)
{
ret_cri(psr);
return E_TMOUT;
}
g_pCurTsk->ubStatus |= TTS_WAI;
g_pCurTsk->ubWaitStat |= TTW_SLP;
vfnDelInitMember((T_NODE*)g_pCurTsk);
/* set time out */
if(tmout != TMO_FEVR) {
g_pCurTsk->utime = g_sSysTime.utime;
if (g_sSysTime.ltime > g_sSysTime.ltime + tmout)
g_pCurTsk->utime += 1;
g_pCurTsk->ltime = g_sSysTime.ltime + tmout;
vfnAddTimer((T_NODE*)&(g_pCurTsk->pNxtTmoTsk));
}
int_dispatch(); // dispatch & disable interrupt
ret_cri(psr);
MOV_R1TOR0; // mov r1(from the returnvalue in the stack) to ro (in asm)
return; // return value is E_OK or E_RLWAI
} else {
g_pCurTsk->uhWupcnt--;
}
ret_cri(psr);
#ifndef NO_RETURN_VALUE
return E_OK;
#endif
}
//********************************************************************
// Wakeup Other Task
// [Parameters]
// ID tskid TaskID
// [Return Parameters]
// ER ercd ErrorCode
// [implementation dependent]
// Allowable number for the wakeup request queuing
// count (wupcnt) is 1.
//********************************************************************
ER wup_tsk(ID tskid)
{
T_TSKCB* pTskcb;
UW psr;
#ifndef NO_ERROR_CHECK
if(tskid <= 0) // 0 is tskid = TSK_SELF
{
return E_ID;
}
if(tskid > TSK_NUM)
{
return E_NOEXS;
}
#endif
psr = ent_cri();
pTskcb = &g_sTskcb[tskid-1];
#ifndef NO_ERROR_CHECK
if(pTskcb->fpPC == 0)
{
ret_cri(psr);
return E_NOEXS;
}
if((pTskcb == g_pCurTsk)
|| (pTskcb->ubStatus & TTS_DMT))
{
ret_cri(psr);
return E_OBJ;
}
if(pTskcb->uhWupcnt >= WUP_CNT)
{
ret_cri(psr);
return E_QOVR;
}
#endif
if(!(pTskcb->ubStatus & TTS_WAI))
{
pTskcb->uhWupcnt++;
ret_cri(psr);
return E_OK;
}
if((pTskcb->ubStatus & TTS_WAI) && (pTskcb->ubWaitStat & TTW_SLP))
{
pTskcb->ubStatus &= ~TTS_WAI;
pTskcb->ubWaitStat &= ~TTW_SLP;
if(pTskcb->ubIntinfo == 0) /* interrupt information */
{
((T_SAVEDREG_MIN*)(pTskcb->uwSP))->returnvalue = E_OK; //gfd
}
/* clear time out task link */
vfnDelInitMember((T_NODE*)&(pTskcb->pNxtTmoTsk));
vfnDelAddMember((T_NODE*)&g_sReadyQueue[pTskcb->bPriority],
(T_NODE*)pTskcb);
int_dispatch(); // dispatch & disable interrupt
}
ret_cri(psr);
#ifndef NO_RETURN_VALUE
return E_OK;
#endif
}
//********************************************************************
// Cancel Wakeup Request
// [Parameters]
// ID tskid TaskID
// [Return Parameters]
// ER ercd ErrorCode
// INT wupcnt WakeupCount
//********************************************************************
ER can_wup(INT *p_wupcnt,ID tskid)
{
T_TSKCB* pTskcb;
UW psr;
#ifndef NO_ERROR_CHECK
if((tskid < 0) // 0 is tskid = TSK_SELF
||((g_ubIntNestCnt != 0) & (tskid == TSK_SELF)))
{
return E_ID;
}
if(tskid > TSK_NUM)
{
return E_NOEXS;
}
#endif
psr = ent_cri();
if(tskid == TSK_SELF)
{
pTskcb = g_pCurTsk;
} else {
pTskcb = &g_sTskcb[tskid-1];
}
#ifndef NO_ERROR_CHECK
if(pTskcb->fpPC == 0)
{
ret_cri(psr);
return E_NOEXS;
}
if (pTskcb->ubStatus & TTS_DMT)
{
ret_cri(psr);
return E_OBJ;
}
#endif
*p_wupcnt = pTskcb->uhWupcnt;
pTskcb->uhWupcnt = 0;
ret_cri(psr);
#ifndef NO_RETURN_VALUE
return E_OK;
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -