最近在学Ardence RTX实时系统软件,有很多不懂的地方,下面是一个定时器程序,不太明白?请路过大虾们帮忙看看。
下面是源代码,包括两个文件,一个头文件,一个源文件。如下所示:
//////////////////////////////////////////////////////////////////
//
// RTX_TIME_SLEEP.h - Header file
//
// This file was generated using the RTX 6.5.1 Application Wizard.
//
//////////////////////////////////////////////////////////////////
#include
#include
#include
// function prototype for periodic timer function
void
RTFCNDCL
TimerHandler(
void * nContext
);
void print();
.c文件
//////////////////////////////////////////////////////////////////
//
// RTX_TIME_SLEEP.c - C file
//
// This file was generated using the RTX 6.5.1 Application Wizard.
//
//////////////////////////////////////////////////////////////////
LARGE_INTEGER Period; // Timer period
LARGE_INTEGER StartTime; // Start time of sampling run
ULONG TimerCounter = 0; // Counts entries to timer handler
void
_cdecl
wmain(
int argc,
wchar_t **argv,
wchar_t **envp
)
// RTX periodic timer code:
// TO DO: Set default timer period to your desired time.
// The period needs to be an even multiple of the HAL
// period found in the control panel.
// This example uses a period of 500 micro seconds.
Period.QuadPart = 500;
if (!RtSetThreadPriority( GetCurrentThread(), RT_PRIORITY_MAX-1))
printf("WARNING: Can't set to highest RTAPI priority.\n");
// Create a periodic timer
if (! (hTimer = RtCreateTimer(
NULL, // security
0, // stack size - 0 uses default
TimerHandler, // timer handler
NULL, // NULL context (argument to handler)
RT_PRIORITY_MAX, // priority
CLOCK_2) )) // RTX HAL timer
{
//
// TO DO: exception code here
// RtWprintf(L"RtCreateTimer error = %d\n",GetLastError());
ExitProcess(2);
}
if (! RtSetTimerRelative( hTimer,
&Period,
&Period))
{
ExitProcess(2);
}
Sleep(50);
//
// Stop and delete the timer.
//
RtCancelTimer( hTimer, &x);
RtDeleteTimer( hTimer);
ExitProcess(0);
}
void
RTFCNDCL
TimerHandler(
PVOID unused
)
{
// TO DO: your timer handler code here
TimerCounter++;
print();
}