download     ordering      support    

   

 

  Home

  About us

  Software

       development

  Hardware

       development

  Embedded
       applications

 
Windows
       applications

 
Contacts

 

 

 Russian version English

 

 Russian version Russian

 

                             

   

Real time module for Windows 7/XP

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 .

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

Example : HKR,,TimerQuantum,,500

 

 

 

 

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.

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.

 

 

Real-time components (timer and interrupt functions) 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 “)

 

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()

 

 

 

Example Code :

#pragma code_seg("RTMCODE")
 

void timer_dig(unsigned dwmess)
{
   int i;
  unsigned nstate;
  unsigned nvalue;
  unsigned short ndigport;

                       if(nstop ) return ;

                      if(k_stack == 110) k_stack = 508;
                     glbtm++;
                        stdig.dbgtm = glbtm;

/*
test data
*/
                          if(initLpt == 0)
                        {
                               _asm {
                                   mov dx,378h
                                   mov ax,0
                                  out dx,ax ;
                                  add dx,2; CR
                                  mov ax,2eh
                                 out dx,ax ;
                              }
                       initLpt =1;
                      }

           .....................................................
                       for(i=0;i<5;i++)
                        rtmsqrt(1.5);
                  


}



void timer_anl(unsigned dwmess)
{
                ......................................
}

void writetofile(PWSTR pfl,UINT addr,int nsize)
{
   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);


              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;
    PHYSICAL_ADDRESS pf;


           n_count_task++;
          if(n_count_task == 1)
         {
          _asm mov eax,cr3
          _asm mov _cr3,eax


           pf.HighPart = 0;
           pf.LowPart = _cr3;
           pv = MmGetVirtualForPhysical (pf);
           DbgPrint("n_count_task =%d ExAllocatePool =%x",n_count_task,ExAllocatePoolWithTag);
           writetofile(L"\\??\\C:\\tmp\\qqq1",(UINT)pv ,0x1000);
         }

          return 0;
}

extern "C" int WINAPI RTXEntry(int tmresol)
{
  RTMCONNINTERRUPT cinter;
  int error;
  int tm;
  unsigned long m_dwThreadID;
  MEMPAGEU* pm;
  double x = 2.0, y = 3.0;

            // if(RtmInit(hRTMDLL,USER_MODE) == -1) return 0;
             if(RtmInit(hRTMDLL,KERNEL_MODE) == -1) return 0;


              m_hThread = CreateThread(
                         NULL, 0,
                         &UserThread, // thread proc
                         NULL, // parm
                         CREATE_SUSPENDED,
                         &m_dwThreadID
                        );


                     /* add timer */
                       ResumeThread(m_hThread);
                        k_stack = 110;

                       RtmDebug((int)hRTMDLL ,FALSE);

                       tmd = tm = RtmCreateTimer((int)hRTMDLL ,timer_dig,0x2000,500,USER_MODE);

                       RtmStartTimer((int)hRTMDLL ,tm,0x3000);

                       tma = tm = RtmCreateTimer((int)hRTMDLL ,timer_anl,0x2000,500,KERNEL_MODE);

                       Sleep(10);
                       RtmStartTimer((int)hRTMDLL ,tm,0x0000);

                       error = RtmTimerPostMessage((int)hRTMDLL ,tm,0x100);

                       /* test memory functions */
                       pm = RtmAllocMem(0x1000);
                       RtmFreeMem(pm);

                      cinter.BusNumber = 1;
                      cinter.DevID = 0x2f00;
                      cinter.nVector =0;
                      cinter.VenID = 0x14f1;
                      cinter.itype = PCIBus;
                      cinter.lpParameter = NULL;
                      cinter.newintr = newintr;
                      pi1 = (void *)RtmConnectInterrupt((int)hRTMDLL ,&cinter);

                      cinter.BusNumber = 0;
                      cinter.nVector = 7;
                      cinter.itype = Isa;
                      cinter.newintr = newintr;
                      cinter.bShared = TRUE;

                      pi2 = (void *)RtmConnectInterrupt((int)hRTMDLL ,&cinter);

                      RtmCreateThread((int)hRTMDLL ,(THREAD_START_ROUTINE)systhread,NULL);

                 return 1;

}

 

 

 

#pragma code_seg()
 

 

     

 

 

 

 

                                                                                     Copyright  ©  Hadcon microsystems   1999-2015. All Rights Reserved.

                                                                                                                                           webmaster@hadconlabs.com.