+ All Categories

RTMwin7

Date post: 27-Nov-2015
Category:
Upload: hamsaxyz
View: 10 times
Download: 0 times
Share this document with a friend
Description:
rt win
Popular Tags:
26
Hadcon Real time module Microsystems for Windows Vista ,XP/2000 - 1 - Real time module for Windows Vista,Xp/2000 Reference Manual _________________________________________________________ January, 2008
Transcript
Page 1: RTMwin7

Hadcon Real time module Microsystems for Windows Vista ,XP/2000

- 1 -

Real time module for Windows Vista,Xp/2000

Reference Manual _________________________________________________________ January, 2008

Page 2: RTMwin7

Hadcon Real time module Microsystems for Windows Vista ,XP/2000

- 2 -

Overview The Hadcon’s real time module (RTM) has been developed to bring “hard “ real time capabilities (such as creation of timers, system thread,of management by resources – memory, ports,interrupts ) to Windows , excepting necessity of a creating of the driver . RTM enables application components that require deterministic and high-speed response times, along with other non-real-time application components, to work together on a common Windows system. Creating an RTMDLL Visual Studio 6.0 Project

Use the procedures that follow to create an RTMDLL Project with Visual Studio 6.0.

To create an RTMDLL Project

Create a new project workspace

1. From the File menu, choose New and then choose the Projects tab.

2. Select Win32 Dynamic-Link Library, and enter the name of the project in the Project name text box.

3. Click OK. The Win32 Dynamic-Link Library dialog appears.

4. Select Win32 Dynamic-Link Library, enter a name, and then click OK.

Page 3: RTMwin7

Hadcon Real time module Microsystems for Windows Vista ,XP/2000

- 3 -

Specify the project settings

1. From the Project menu, choose Settings to open the Project Settings dialog box.

2. In the Settings For box, select either Win32 Release or Win32 Debug, based on the version you are building.

3. From the Link tab, delete all Project Options and replace them with one of the following option sets.

6. Click OK to save the settings.

RTM Architecture Precise execution of events is critical in a real-time system. RTM provides complete flexibility to the developer to determine the appropriate timer resolution for their system. Timer interval values can be set between 100 microsecond and 1 millisecond (100,200,500,1000). The timer interval is default inside of [AddNewInst] section rtmdrv.inf file’s HKR,,TimerQuantum,,500

Page 4: RTMwin7

Hadcon Real time module Microsystems for Windows Vista ,XP/2000

- 4 -

RTM uses the “mixed” code i.e timer’s , interrupt’s routines (working in Ring 0 ) and user routines (working in Ring 3 ) are incorporated in one DLL module. Real-time components (timer ,system thread and interrupt routines) must be locked in memory to avoid latencies due to page faults. Therefore RTM defines own sections for location of a code , a data and a stack using the data_seg, code_seg, and bss_seg pragmas. #pragma code_seg( “RTMCODE “) Specifies a code section where functions are to be allocated. For example: #pragma code_seg( “RTMCODE “) void timer1(unsigned dwmess ) { /* code */ .................. } #pragma code_seg() #pragma data_seg( “RTMDATA “)

Win 32 Process

Windows kernel Device drivers

RTM driver

Windows HAL

Rtm timer

System thread

Win 32 DLL RTM calls

Page 5: RTMwin7

Hadcon Real time module Microsystems for Windows Vista ,XP/2000

- 5 -

Specifies a code section where initialized data are to be allocated. For example: #pragma data_seg( “RTMDATA “) char buff[10] = {0}; int k1 = 0; #pragma data_seg() #pragma data_seg( “RTMBSS “) Specifies a code section where uninitialized data are to be allocated. For example: #pragma bss_seg( “RTMBSS “) char buff1[10] ; int a1 ; #pragma bss_seg()

List of Real-time Calls BOOL RtmInit(HINSTANCE hinst ,int kmode); The RtmInit function creates new RTM driver’s session.

Parameters hinst

Handle to the DLL. The value is the base address of the DLL. kmode

If kmode is defined as KERNEL_MODE ,functions is located in the RTMCODE section it will be placed in the system memory space. It protects real time code from user application.

Return Values

if successful, returns TRUE. Otherwise the function returns 0. BOOL RtmClose(HANDLE s_handle);

Page 6: RTMwin7

Hadcon Real time module Microsystems for Windows Vista ,XP/2000

- 6 -

The RtmClose function close RTM driver’s session. s_handle

Handle to the open RTM driver’s session.

Return Values

returns 0 if the driver’s session was successfully closed. A return value of –1 indicates an error HANDLE RtmCreateTimer(HANDLE s_handle ,TIMER_START_ROUTINE lpStartTmAddress,unsigned int dwStackSize,unsigned int dwTime ); The RtmCreateTimer function creates new timer. Parameters s_handle

Handle to the RTM driver’s session. lpStartTmAddress

Pointer to the application-defined function of type TIMER_START_ROUTINE to be executed by the timer and represents the starting address of the timer.

dwStackSize Specifies the initial commit size of the stack, in bytes. The system rounds this value to the nearest page. If this value is zero, or is smaller than the default commit size, the default is to use the same size as the calling thread.

dwTime Specifies the repeat interval, measured in microseconds, required for the timer to run. If 0 (zero) or there is less than value timer resolution is specified AddNewInst section rtmdrv.inf file’s , function will set the interval equal to the RTM timer period resolution. The highest RTM timer resolution is 100 us (microseconds).

Return Values

if successful, returns a handle to the created timer. Otherwise the function returns –1

The RtmDeleteTimer function deletes a timer. BOOL RtmDeleteTimer (int s_handle , HANDLE tmhandle );

Parameters s_handle

Handle to the RTM driver’s session. tmhandle

Handle to the timer to delete.

Page 7: RTMwin7

Hadcon Real time module Microsystems for Windows Vista ,XP/2000

- 7 -

Return Values

The function returns TRUE if it completes successfully, or it returns FALSE if invalid parameters are specified. BOOL RtmStartTimer(HANDLE s_handle , HANDLE tmhandle ); The RtmStartTimer function starts the timer.

Parameters s_handle

Handle to the RTM driver’s session. tmhandle

Handle referring to create timer. The RtmCreateTimer function returns this handle.

Return Value

The function returns TRUE if it completes successfully, or it returns FALSE if invalid parameters are specified. BOOL RtmStopTimer(HANDLE s_handle , HANDLE tmhandle); The RtmStopTimer function stops the timer. Parameters s_handle

Handle to the RTM driver’s session. tmhandle

Handle referring to create timer. The RtmCreateTimer function returns this handle.

Return Value

The function returns TRUE if it completes successfully, or it returns FALSE if invalid parameters are specified. BOOL RtmSetTimerInterval(HANDLE s_handle , HANDLE tmhandle , int dwTime ); The RtmSetTimerInterval function sets the repeat interval on the specified timer.

Page 8: RTMwin7

Hadcon Real time module Microsystems for Windows Vista ,XP/2000

- 8 -

Parameters s_handle

Handle to the RTM driver’s session. tmhandle

Handle referring to create timer. The RtmCreateTimer function returns this handle dwTime Specifies the repeat interval, measured in microseconds, required for the timer to run. If 0 (zero) or there is less than value timer resolution is specified AddNewInst section rtmdrv.inf file’s , function will set the interval equal to the RTM timer period resolution. The highest RTM timer resolution is 100 us (microseconds). Return Value

If the function succeeds, the return value is the previous repeat interval , else 0. BOOL RtmTimerPostMessage(HANDLE s_handle , HANDLE tmhandle , unsigned tdwmess ); The RtmTimerPostMessage function posts message to the timer. Parameters s_handle

Handle to the RTM driver’s session. tmhandle

Handle referring to create timer.

dwmess

Specifies the message to be posted .

Return Value

The function returns TRUE if it completes successfully, or it returns FALSE if invalid parameters are specified. Example Code : void timer1(unsigned dwmess ) { /*......... code ....*/ if(dwmess == 0x100) /*......... code ....*/

Page 9: RTMwin7

Hadcon Real time module Microsystems for Windows Vista ,XP/2000

- 9 -

} void func() { int error; int tm; if(RtmInit(hRTMDLL,KERNEL_MODE) == -1) return 0; RtmDebug((int)hRTMDLL ,TRUE); tm = RtmCreateTimer((int)hRTMDLL ,timer_anl,0x2000,stanl.quantum); RtmStartTimer((int)hRTMDLL ,tm); error = RtmTimerPostMessage((int)hRTMDLL ,tm,0x100); }

BOOL RtmDebug(HANDLE s_handle ,BOOL bmode ); The RtmDebug function sets the debug mode. Parameters s_handle

Handle to the RTM driver’s session. bmode

if bmode is TRUE setting debug mode.

Return Value

Returns the previous value. BOOL RtmTimerStepover (HANDLE s_handle , HANDLE tmhandle ); The RtmTimerStepover function allows to continue performance code following for rtmbreakpoint function.

Parameters s_handle

Handle to the RTM driver’s session. tmhandle

Handle referring to create timer.

Return Value

The function returns TRUE if it completes successfully, or it returns FALSE if invalid parameters are specified.

Page 10: RTMwin7

Hadcon Real time module Microsystems for Windows Vista ,XP/2000

- 10 -

Example Code : void timer1(unsigned dwmess ) { /*......... code ....*/ rtmbreakpoint(TRUE); /*......... code ....*/ } int func1() { int tm; if(RtmInit(hRTMDLL,KERNEL_MODE) == -1) return 0; RtmDebug((int)hRTMDLL ,TRUE); tm = RtmCreateTimer((int)hRTMDLL ,timer_anl,0x2000,stanl.quantum); RtmStartTimer((int)hRTMDLL ,tm); RtmTimerStepover((int)hRTMDLL ,tm); }

RtmCreateThread creates a system thread that executes in kernel mode . HANDLE RtmCreateThread(HANDLE s_handle , THREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter ); Parameters s_handle

Handle to the RTM driver’s session. lpStartAddress A pointer to the application-supplied function to be executed by the thread and represents the starting address of the thread. The function accepts a single 32-bit argument and returns a 32- bit exit value. lpParameter A single 32-bit parameter value passed to the thread. Return Value If the function succeeds, the return value is a handle to the new thread. If the function fails, the return value is NULL. Example Code : void writetofile(PWSTR pfl,UINT addr,int nsize) {

Page 11: RTMwin7

Hadcon Real time module Microsystems for Windows Vista ,XP/2000

- 11 -

IO_STATUS_BLOCK IoStatus; OBJECT_ATTRIBUTES objectAttributes; HANDLE FileHandle = NULL; UNICODE_STRING fileName1; NTSTATUS status; fileName1.Buffer = NULL; fileName1.Length = 0; fileName1.MaximumLength = 256; DbgPrint("start"); fileName1.Buffer = (unsigned short *)ExAllocatePool(PagedPool, fileName1.MaximumLength); DbgPrint("111"); RtlZeroMemory(fileName1.Buffer, fileName1.MaximumLength); status = RtlAppendUnicodeToString(&fileName1, pfl); InitializeObjectAttributes (&objectAttributes, (PUNICODE_STRING)&fileName1, OBJ_CASE_INSENSITIVE, NULL, NULL ); status = ZwCreateFile(&FileHandle, FILE_APPEND_DATA, &objectAttributes, &IoStatus, 0, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_WRITE, FILE_OPEN_IF, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0 ); if(NT_SUCCESS(status)) { ZwWriteFile(FileHandle, NULL, NULL, NULL, &IoStatus, (void *)addr, nsize, NULL, NULL ); ZwClose(FileHandle); DbgPrint ("Close file"); } if(fileName1.Buffer) ExFreePool(fileName1.Buffer); } int systhread(void *param) { unsigned int _cr3 = 0; PVOID pv;

Page 12: RTMwin7

Hadcon Real time module Microsystems for Windows Vista ,XP/2000

- 12 -

PHYSICAL_ADDRESS pf; n_count_task++; if(n_count_task == 10) { _asm mov eax,cr3 _asm mov _cr3,eax pf.HighPart = 0; pf.LowPart = _cr3; pv = MmGetVirtualForPhysical (pf); writetofile(L"\\??\\C:\\tmp\\qqq1",(UINT)pv ,0x1000); } return 0; }

void func() { int error; int tm; DWORD th; if(RtmInit(hRTMDLL,KERNEL_MODE) == -1) return 0; th = RtmCreateThread((int)hRTMDLL ,(THREAD_START_ROUTINE)systhread,NULL); }

The RtmDeleteThread function deletes a system thread . BOOL RtmDeleteThread (int s_handle , HANDLE thhandle );

Parameters s_handle

Handle to the RTM driver’s session. thhandle

Handle to the system thread to delete. Return Values

If the function succeeds, the return value is nonzero.

RtmTerminateThread terminates a thread.

BOOL RtmTerminateThread(HANDLE s_handle , HANDLE thrhandle);

Parameters s_handle

Page 13: RTMwin7

Hadcon Real time module Microsystems for Windows Vista ,XP/2000

- 13 -

Handle to the RTM driver’s session. thrhandle

The handle system thread to terminate.

Return Values

If the function succeeds, the return value is nonzero. HANDLE RtmConnectInterrupt (HANDLE s_handle , RTMCONNINTERRUPT *interrupt);

The RtmConnectInterrupt registers a newintr routine (ISR), so that it will be called when a device interrupts on any of a specified set of processors. The routine uses the DDK HAL routines for getting the system-wide interrupt vector based on the bus-specific interrupt level and vector

Parameters s_handle

Handle to the RTM driver’s session.

interrupt Pointer to the RTMCONNINTERRUPT structure.

typedef struct _tagRTMCONNINTERRUPT { INTERFACE_TYPE itype; ULONG nVector ; ULONG BusNumber ; ULONG VenID ; ULONG DevID; unsigned char bShared; void *lpParameter; INTERRUPT_ROUTINE newintr; ) RTMCONNINTERRUPT;

itype Specifies the type of interface (PCIBus or ISA) nVector Specifies the number interrupt vector (for PCI zero) BusNumber Specifies the bus number for the device (for ISA zero) VenID

Page 14: RTMwin7

Hadcon Real time module Microsystems for Windows Vista ,XP/2000

- 14 -

Identifies the manufacturer of the device. (for ISA zero)

DevID Identifies the particular device. This value is assigned by the manufacturer. (for ISA zero) bShared

Specifies whether the interrupt vector is sharable. lpParameter

Specifies a single 32-bit parameter value passed to the interrupt function. Value should be certain inside of the RTM_DATA section.

newintr Pointer to the interrupt function .

Return Value

If successful, returns handle to the interrupt object. Otherwise the function returns –1 Example Code : void newintr(void *pv) { /* ------------------------- */

}

int func1() { int tm; RTMCONNINTERRUPT cinter; void *pi; if(RtmInit(hRTMDLL,KERNEL_MODE) == -1) return 0; cinter.BusNumber = 1; cinter.DevID = 0x2f00; cinter.nVector =0; cinter.VenID = 0x14f1; cinter.itype = PCIBus; cinter.lpParameter = NULL; cinter.newintr = newintr; pi = RtmConnectInterrupt((int)hRTMDLL ,&cinter); }

BOOL RtmDisconnectInterrupt (HANDLE s_handle , HANDLE introbject); Parameters s_handle

Handle to the RTM driver’s session.

Page 15: RTMwin7

Hadcon Real time module Microsystems for Windows Vista ,XP/2000

- 15 -

introbject Pointer to interrupt object . The RtmConnectInterrupt function returns this pointer.

Return Value

If successful, returns 0. Otherwise the function returns –1 HANDLE RtmHookInterrupt (HANDLE s_handle , RTMCONNINTERRUPT *interrupt);

The RtmHookInterrupt function enables you to intercept Windows vector interrupt’s . s_handle

Handle to the RTM driver’s session.

interrupt Pointer to the interrupt structure

Return Value

If successful, returns a pointer to interrupt object. Otherwise the function returns –1 BOOL RtmUnhookInterrupt (HANDLE s_handle , HANDLE introbject);

The RtmUnhookInterrupt function restores vector interrupt’s .

Parameters s_handle

Handle to the RTM driver’s session.

introbject Pointer to interrupt object . The RtmHookInterrupt function returns this pointer.

Return Value

If successful, returns 0. Otherwise the function returns –1 BOOL RtmAssignResources (int s_handle , ULONG BusNumber, ULONG VenID , ULONG DevID); The RtmAssignResources assigned resources by the RTM driver.

Parameters s_handle

Handle to the RTM driver’s session.

Page 16: RTMwin7

Hadcon Real time module Microsystems for Windows Vista ,XP/2000

- 16 -

BusNumber Specifies the bus number for the device . Slot Specifies the logical slot number of the device . VenID Identifies the manufacturer of the device.

DevID Identifies the particular device. Return Value

If successful, returns 0. Otherwise the function returns –1 BOOL RtmReleaseResources (HANDLE s_handle , ULONG BusNumber, ULONG Slot, ULONG VenID , ULONG DevID); The RtmReleaseResources release resources .

Parameters s_handle

Handle to the RTM driver’s session. BusNumber Specifies the bus number for the device . Slot Specifies the logical slot number of the device . VenID Identifies the manufacturer of the device.

DevID Identifies the particular device. Return Value

If successful, returns 0. Otherwise the function returns –1 Example Code : int PCIResource(BOOL bmode,PCIINFO *pci) { char *pDev = NULL; int rez = -1;

Page 17: RTMwin7

Hadcon Real time module Microsystems for Windows Vista ,XP/2000

- 17 -

rez = CheckPci(TRUE,pci->pcidata.VendorID,pci->pcidata.DeviceID,pDev); if(rez!= -1) { if(bmode == TRUE) rez = RtmAssignPCISlot(pci->bus,pci->slot.u.AsULONG,\ pci->pcidata.VendorID,pci->pcidata.DeviceID); else rez = RtmReleasePCISlot(pci->bus,pci->slot.u.AsULONG,\ pci->pcidata.VendorID,pci->pcidata.DeviceID); } return rez; }

void RtmCopyMemory(void *Destination,void *Source, int Length ); RtmCopyMemory copies the contents of one buffer to another.

Parameters Destination

Points to the destination of the move. Source

Points to the memory to be copied. Length

Specifies the number of bytes to be copied. MEMPAGEU* RtmAllocMem(int NumberOfBytes ) RtmAllocMem allocates pool memory and returns a pointer to the allocated block.

Parameters NumberOfBytes

Specifies the number of bytes to allocate.

Return Value

Returns NULL if there is insufficient memory in the free pool to satisfy the request. Otherwise the routine returns a pointer to the MEMPAGEU structure. typedef struct _tag MEMPAGEU { void *pmap; int NumberOfBytes ; void *pv; }; Parameters pmap Pointer to the allocated memory.

Page 18: RTMwin7

Hadcon Real time module Microsystems for Windows Vista ,XP/2000

- 18 -

NumberOfBytes Specifies the number of bytes to allocate.

void RtmFreeMem(MEMPAGEU* pm ) RtmFreeMem deallocates a block of pool memory.

Parameters pm Pointer to the to the MEMPAGEU structure. The RtmAllocMem function returns this pointer.

.

void RtmReadPhysicalAddress( int nIndex ,unsigned naddress ,void *Buffer ,int Count,int nsize)

RtmReadPhysicalAddress reads the Count items of data each of length nsize bytes from the specified physical address into a buffer.

Parameters nIndex

Specifies the zero-based index of the pciinfo struct item. naddress

Specifies physical address Buffer

Points to a buffer into which an array items is to be read. Count

Specifies the number of items to be read nsize

Item size in bytes

void RtmWritePhysicalAddress( int nIndex ,unsigned naddress ,void *Buffer ,int Count,int nsize)

RtmWritePhysicalAddress writes the Count items of data each of length nsize bytes number from a buffer to the specified physical address .

Parameters nIndex

Specifies the zero-based index of the pciinfo struct item. naddress

Specifies physical address Buffer

Points to a buffer form which an array items is to be written. Count

Specifies the number of items to be written

Page 19: RTMwin7

Hadcon Real time module Microsystems for Windows Vista ,XP/2000

- 19 -

nsize Item size in bytes

List of Real-time Calls inside of timer and interrupt functions VOID rtmbreakpoint (BOOL bm ); The rtmbreakpoint function sets breakpoint. This functions works only set debug mode Parameters

bm

if TRUE sets breakpoint. 0 – ignored.

Return Value

This function returns no value.

Example Code : void timer1(unsigned dwmess ) { /*......... code ....*/ rtmbreakpoint(TRUE); /*......... code ....*/ }

BOOL rtmsettimerinterval( int dwTime ); The rtmsettimerinterval function sets the repeat interval timer. Parameters dwTime Specifies the repeat interval, measured in microseconds, required for the timer to run. If 0 (zero) or there is less than value timer resolution is specified AddNewInst section rtmdrv.inf file’s , function will set the interval equal to the RTM timer period resolution. The highest RTM timer resolution is 100 us (microseconds). Return Value

If the function succeeds, the return value is the previous repeat interval , else 0. Example Code :

Page 20: RTMwin7

Hadcon Real time module Microsystems for Windows Vista ,XP/2000

- 20 -

void timer1(unsigned dwmess ) { /*......... code ....*/ rtmsettimerinterval(100); /*......... code ....*/ }

VOID rtmdeletetimer (void ); The rtmdeletetimer function deletes a timer.

Parameters

This function has no parameters.

Return Value

This function returns no value Example Code : void timer1(unsigned dwmess ) { /*......... code ....*/ rtmdeletetimer(); /*......... code ....*/

} /*memory.h - declarations for buffer (memory) manipulation routines/ void * __CLIB rtmmemcpy(void *,const void *,size_t); void * __CLIB rtmmemmove(void *,const void *,size_t); char * __CLIB rtmstrcpy(char *,const char *); char * __CLIB rtmstrncpy(char *,const char *,size_t); char * __CLIB rtmstrcat(char *,const char *); char * __CLIB rtmstrncat(char *,const char *,size_t); int __CLIB rtmmemcmp(const void *,const void *,size_t); int __CLIB rtmstrcmp(const char *,const char *); int __CLIB rtmstrcoll(const char *,const char *); int __CLIB rtmstrncmp(const char *,const char *,size_t); void * __CLIB rtmmemchr(const void *,int,size_t); char * __CLIB rtmstrchr(const char *,int); size_t __CLIB rtmstrcspn(const char *,const char *); char * __CLIB rtmstrpbrk(const char *,const char *); char * __CLIB rtmstrrchr(const char *,int); size_t __CLIB rtmstrspn(const char *,const char *); char * __CLIB rtmstrstr(const char *,const char *); char * __CLIB rtmstrtok(char *,const char *);

Page 21: RTMwin7

Hadcon Real time module Microsystems for Windows Vista ,XP/2000

- 21 -

void * __CLIB rtmmemset(void *,int,size_t); size_t __CLIB rtmstrlen(const char *); int __CLIB rtmsprintf(char *, const char *, ...); /*rtmmath.h - definitions and declarations for math library Function prototypes */ int __cdecl rtmabs(int); double __cdecl rtmacos(double); Calculates the arc cosine. acos returns the arc cosine of the input value. Return Value

The rtmacos function returns the arccosine of x in the range 0 to π radians. If x is less than –1 or greater than 1, rtmacos returns an indefinite (same as a quiet NaN). Example Code : void timer1(unsigned dwmess ) { char buff[32]; double result; double x = 0.5; result = rtmacos(x); rtmsprintf(buff ,"The arc cosine of %lf is %lf\n", x, result); }

double __cdecl rtmasin(double); Calculates the arcsine Return Value

The rtmasin function returns the arcsine of x in the range –π/2 to π/2 radians. If x is less than –1 or greater than 1, rtmasin returns an indefinite (same as a quiet NaN). Example Code : void timer1(unsigned dwmess ) { char buff[32]; double result; double x = 0.5; result = rtmasin(x); rtmsprintf(buff ,"The arc sin of %lf is %lf\n", x, result); }

double __cdecl rtmatan(double); double __cdecl rtmatan2(double, double); Calculates the arc tangent.

Page 22: RTMwin7

Hadcon Real time module Microsystems for Windows Vista ,XP/2000

- 22 -

atan calculates the arc tangent of the input value. Return Value

rtmatan returns the arctangent of x. rtmatan2 returns the arctangent of y/x. If x is 0, rtmatan returns 0. If both parameters of rtmatan2 are 0, the function returns 0. Example Code : void timer1(unsigned dwmess ) { char buff[32]; double result; double x = 0.5; double y= 45.0; result = rtmatan(x); rtmsprintf(buff ,"The arc tangent of %lf is %lf\n", x, result); x = 90.0; result = rtmatan2(y, x); rtmsprintf(buff ,"The arc tangent ratio of %lf is %lf\n", (y / x), result); }

double __cdecl rtmcos(double); double __cdecl rtmcosh(double); Calculates the cosine of a value. Return Value

The rtmcos and rtmcosh functions return the cosine and hyperbolic cosine, respectively, of x. If x is greater than or equal to 263, or less than or equal to –263, a loss of significance in the result of a call to rtmcos occurs, in which case the function generates a _TLOSS error and returns an indefinite (same as a quiet NaN).

If the result is too large in a rtmcosh call, the function returns HUGE_VAL . Example Code : void timer1(unsigned dwmess ) { double result; double x = 0.5; result = rtmcos(x); rtmsprintf(buff ,"The cosine of %lf is %lf\n", x, result); result = rtmcosh(x); rtmsprintf(buff ,"The hyperbolic cosine of %lf is %lf\n", x, result); }

double __cdecl rtmexp(double);

Page 23: RTMwin7

Hadcon Real time module Microsystems for Windows Vista ,XP/2000

- 23 -

Calculates the exponential

Return Value

The rtmexp function returns the exponential value of the floating-point parameter, x, if successful. On overflow, the function returns INF (infinite) and on underflow, rtmexp returns 0. Example Code : void timer1(unsigned dwmess ) { char buff[32]; double result; double x = 4.0; result = rtmexp(x); rtmsprintf(buff ,"'e' raised to the power of %lf (e ^ %lf) = %lf\n", x, x, result); return 0; }

double __cdecl rtmfabs(double); Calculates the absolute value of the floating-point argument.

Return Value

rtmfabs returns the absolute value of its argument. There is no error return. Example Code : void timer1(unsigned dwmess ) { char buff[32]; float number = -1234.0; rtmsprintf(buff ,"number: %f absolute value: %f\n", number, rtmfabs(number)); }

double __cdecl rtmfmod(double, double); Calculates the floating-point remainder.

Return Value

rtmfmod returns the floating-point remainder of x / y. If the value of y is 0.0, rtmfmod returns a quiet NaN. Example Code : void timer1(unsigned dwmess ) { char buff[32]; double x = 5.0, y = 2.0; double result; result = rtmfmod(x,y);

Page 24: RTMwin7

Hadcon Real time module Microsystems for Windows Vista ,XP/2000

- 24 -

rtmsprintf(buff ,"The remainder of (%lf / %lf) is %lf\n", x, y, result); }

long __cdecl rtmlabs(long); Calculates the absolute value of a long integer Return Value

The rtmlabs function returns the absolute value of its argument. There is no error return. Example Code : void timer1(unsigned dwmess ) { char buff[32]; long result; long x = -12345678L; result= rtmlabs(x); rtmsprintf(buff ,"number: %ld abs value: %ld\n", x, result); }

double __cdecl rtmlog(double); double __cdecl rtmlog10(double); Calculates logarithms.

Return Value

The rtmlog functions return the logarithm of x if successful. If x is negative, these functions return an indefinite (same as a quiet NaN). If x is 0, they return INF (infinite). Example Code : void timer1(unsigned dwmess ) { char buff[32]; double result; double x = 8.6872; result = rtmlog(x); rtmsprintf(buff ,"The natural log of %lf is %lf\n", x, result); x = 800.6872; result = rtmlog10(x); rtmsprintf(buff ,"The common log of %lf is %lf\n", x, result); return 0; }

double __cdecl rtmpow(double, double); Calculates x raised to the power of y.

Return Value

Page 25: RTMwin7

Hadcon Real time module Microsystems for Windows Vista ,XP/2000

- 25 -

rtmpow returns the value of xy. No error message is printed on overflow or underflow. Example Code : void timer1(unsigned dwmess ) { char buff[32]; double x = 2.0, y = 3.0; rtmsprintf(buff ,"%lf raised to %lf is %lf\n", x, y, rtmpow(x, y)); return 0; }

double __cdecl rtmsin(double); double __cdecl rtmsinh(double); Calculate sines and hyperbolic sines.

Return Value

rtmsin returns the sine of x. If x is greater than or equal to 263, or less than or equal to –263, a loss of significance in the result occurs, in which case the function generates a _TLOSS error and returns an indefinite (same as a quiet NaN).

rtmsinh returns the hyperbolic sine of x. If the result is too large, rtmsinh sets errno to ERANGE and returns ±HUGE_VAL. Example Code : void timer1(unsigned dwmess ) { char buff[32]; double result, x = 0.5; result = rtmsin(x); rtmsprintf(buff ,"The sin of %lf is %lf\n", x, result); result = rtmsinh(x); rtmsprintf(buff ,"The hyperbolic sin of %lf is %lf\n", x, result); }

double __cdecl rtmtan(double); double __cdecl rtmtanh(double); Calculate the tangent (tan) or hyperbolic tangent (tanh).

Return Value

rtmtan returns the tangent of x. If x is greater than or equal to 263, or less than or equal to –263, a loss of significance in the result occurs, in which case the function generates a _TLOSS error and returns an indefinite (same as a quiet NaN). Example Code : void timer1(unsigned dwmess ) { char buff[32]; double result, x;

Page 26: RTMwin7

Hadcon Real time module Microsystems for Windows Vista ,XP/2000

- 26 -

x = 0.5; result = rtmtan(x); rtmsprintf(buff ,"The tan of %lf is %lf\n", x, result); result = rtmtanh(x); rtmsprintf(buff ,"The hyperbolic tangent of %lf is %lf\n", x, result); }

double __cdecl rtmsqrt(double); Calculates the square root.

Return Value

The rtmsqrt function returns the square-root of x. If x is negative, rtmsqrt returns an indefinite (same as a quiet NaN). Example Code : void timer1(unsigned dwmess ) { char buff[32]; double x = 4.0, result; result = rtmsqrt(x); rtmsprintf(buff ,"The square root of %lf is %lf\n", x, result); }