📄 timemng.c
字号:
////////////////////////////////////////////////////////////////////////////////
// File Name : Timemng.c
// Create Date : 2001-6-27 pm 02:32:16
// 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
//
// 2001/11/19 by longn_qi Revise structure "TIMER". "ptim" pointer to a local
// variable in the other function, it is very dangerous.
// So change "ptim" from pointer to structure.
// 2001/10/31 by longn_qi Add functions "def_cyc", "act_cyc", "loc_cpu" and
// "unl_cpu". Add structure "TIMER". Add static variable
// "timerQueue". And revise.
//
////////////////////////////////////////////////////////////////////////////////
/* System and Standard Header */
#include <sys\sysdebug.h>
#include <kernel\ros33\itron.h>
#include <kernel\ros33\ros33.h>
#define _SIZE_T_DEFINED
#include <windows.h>
/* Application Header */
#include "internal.h"
/* Local Structure Definition */
typedef struct
{
UB flag;
FP fp;
UINT act;
SYSTIME ptim;
}TIMER;
/* Local Macro Definition */
#define MAX_TIMER 6
#define IN_USE 1
#define NOT_DEF 0
/* Static Variable Definition */
static TIMER timerQueue[ MAX_TIMER ];
//--- external variables -------------------------------------------------------
//--- shared variables ---------------------------------------------------------
//--- static functions ---------------------------------------------------------
//--- external functions -------------------------------------------------------
/* Function Definition */
//------------------------------------------------------------------------------
// Function name : get_tim
// Description :
// Return type : ER
// Argument : SYSTIME *pk_tim
// Remarks :
// So also :
//------------------------------------------------------------------------------
ER get_tim( SYSTIME *pk_tim )
{
if( !pk_tim )
return E_PAR;
ENTER_CS
pk_tim->utime = 0;
pk_tim->ltime = GetTickCount( );
LEAVE_CS
return E_OK;
}
//------------------------------------------------------------------------------
// Function name : dly_tsk
// Description :
// Return type : ER
// Argument : DLYTIME dlytim
// Remarks :
// So also :
//------------------------------------------------------------------------------
ER dly_tsk( DLYTIME dlytim )
{
if( g_ubSysStat&TSS_DDSP )
return E_CTX;
if( dlytim<=0 )
return E_PAR;
ENTER_CS
aTcb[idCurTask].ubStatus |= TTS_WAI;
aTcb[idCurTask].ubWaitStat |= TTW_DLY;
RemoveTaskFromReadyQueue( aTcb[idCurTask].bPriority, idCurTask );
//AddPollingTimer( dlytim );
SetTimer( hwndClient, idCurTask, dlytim, ( TIMERPROC )PollingTimerHandler );
LEAVE_CS
ContextSwitch( );
return aTcb[idCurTask].vwWaitRet;
}
//------------------------------------------------------------------------------
// Function name : def_cyc
// Description :
// Return type : ER
// Argument : HNO cycno
// Argument : FP cychdr
// Argument : UINT cycact
// Argument : SYSTIME *pk_cyctim
// Remarks :
// So also :
//------------------------------------------------------------------------------
ER def_cyc( HNO cycno,
FP cychdr,
UINT cycact,
SYSTIME *pk_cyctim )
{
#if ENABLE_SYSCALL_STATISTIC
gSyscallSta[35].sta++;
#endif
if( cycno >= MAX_TIMER || timerQueue[cycno].flag == IN_USE )
return E_PAR;
ENTER_CS
timerQueue[cycno].flag = IN_USE;
timerQueue[cycno].act = cycact;
timerQueue[cycno].fp = cychdr;
timerQueue[cycno].ptim.utime = pk_cyctim->utime;
timerQueue[cycno].ptim.ltime = pk_cyctim->ltime;
LEAVE_CS
return E_OK;
}
//------------------------------------------------------------------------------
// Function name : act_cyc
// Description :
// Return type : ER
// Argument : HNO cycno
// Argument : UINT cycact
// Remarks :
// So also :
//------------------------------------------------------------------------------
ER act_cyc( HNO cycno,
UINT cycact )
{
HWND hwnd = hwndClient;
#if ENABLE_SYSCALL_STATISTIC
gSyscallSta[36].sta++;
#endif
if( cycno >= MAX_TIMER || timerQueue[cycno].flag == NOT_DEF )
return E_PAR;
ENTER_CS
if( cycact == TCY_OFF )
{
if( timerQueue[cycno].act == TCY_OFF )
{
LEAVE_CS
return E_OK;
}
timerQueue[cycno].act = TCY_OFF;
KillTimer( hwnd, TSK_NUM+1+cycno );
}
if( cycact == TCY_ON )
{
if( timerQueue[cycno].act == TCY_ON )
{
LEAVE_CS
return E_OK;
}
timerQueue[cycno].act = TCY_ON;
SetTimer( hwnd, TSK_NUM+1+cycno, timerQueue[cycno].ptim.ltime, 0);
}
LEAVE_CS
return E_OK;
}
//------------------------------------------------------------------------------
// Function name : loc_cpu
// Description :
// Return type : ER
// No Argument
// Remarks :
// So also :
//------------------------------------------------------------------------------
ER loc_cpu( )
{
#if ENABLE_SYSCALL_STATISTIC
gSyscallSta[30].sta++;
#endif
g_ubSysStat = TSS_LOC;
return E_OK;
}
//------------------------------------------------------------------------------
// Function name : unl_cpu
// Description :
// Return type : ER
// No Argument
// Remarks :
// So also :
//------------------------------------------------------------------------------
ER unl_cpu( )
{
#if ENABLE_SYSCALL_STATISTIC
gSyscallSta[31].sta++;
#endif
g_ubSysStat = TSS_TSK;
// return ena_dsp( );
return ContextSwitch( );
}
//----------------------------- The End of the File ----------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -