runtime/plc_Win32_main.c
author etisserant
Tue, 26 Feb 2008 15:04:12 +0100
changeset 112 fa0eaeaa9012
parent 110 a05e8b30c024
child 196 93d06827e31b
permissions -rw-r--r--
Re-enabled stderr
49
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
     1
#include <stdio.h>
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
     2
#include <sys/timeb.h>
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
     3
#include <time.h>
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
     4
#include <windows.h>
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
     5
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 79
diff changeset
     6
int localcount = 0;
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 79
diff changeset
     7
49
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
     8
void timer_notify()
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
     9
{
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    10
   struct _timeb timebuffer;
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 79
diff changeset
    11
   if(++localcount % 50 == 0){
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 79
diff changeset
    12
	   printf("PLC tick : %d\n",localcount);
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 79
diff changeset
    13
	   fflush(stdout);
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 79
diff changeset
    14
	   }
49
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    15
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    16
   _ftime( &timebuffer );
75
9ad18a387a96 Windows related enhancements
etisserant
parents: 57
diff changeset
    17
   __CURRENT_TIME.tv_sec = timebuffer.time;
9ad18a387a96 Windows related enhancements
etisserant
parents: 57
diff changeset
    18
   __CURRENT_TIME.tv_nsec = timebuffer.millitm * 1000000;
49
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    19
   __run();
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    20
}
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    21
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    22
int main(int argc,char **argv)
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    23
{
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    24
    HANDLE hTimer = NULL;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    25
    LARGE_INTEGER liDueTime;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    26
75
9ad18a387a96 Windows related enhancements
etisserant
parents: 57
diff changeset
    27
    liDueTime.QuadPart = -10000 * maxval(common_ticktime__,1);
49
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    28
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    29
    // Create a waitable timer.
75
9ad18a387a96 Windows related enhancements
etisserant
parents: 57
diff changeset
    30
    hTimer = CreateWaitableTimer(NULL, FALSE, "WaitableTimer");
49
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    31
    if (NULL == hTimer)
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    32
    {
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    33
        printf("CreateWaitableTimer failed (%d)\n", GetLastError());
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    34
        return 1;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    35
    }
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    36
57
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    37
    if( __init(argc,argv) == 0 ){
49
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    38
75
9ad18a387a96 Windows related enhancements
etisserant
parents: 57
diff changeset
    39
    	printf("Tick Time : %d ms\n", common_ticktime__);
57
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    40
        // Set a timer
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    41
        if (!SetWaitableTimer(hTimer, &liDueTime, common_ticktime__, NULL, NULL, 0))
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    42
        {
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    43
            printf("SetWaitableTimer failed (%d)\n", GetLastError());
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    44
            return 2;
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    45
        }
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    46
    
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    47
        while(1){
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    48
        // Wait for the timer.
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    49
            if (WaitForSingleObject(hTimer, INFINITE) != WAIT_OBJECT_0)
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    50
            {
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    51
                printf("WaitForSingleObject failed (%d)\n", GetLastError());
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    52
                break;
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    53
            }
79
ae06c2da83f7 Some window related enhancements
etisserant
parents: 75
diff changeset
    54
            if (kbhit())
ae06c2da83f7 Some window related enhancements
etisserant
parents: 75
diff changeset
    55
            {
ae06c2da83f7 Some window related enhancements
etisserant
parents: 75
diff changeset
    56
                printf("Finishing\n");
ae06c2da83f7 Some window related enhancements
etisserant
parents: 75
diff changeset
    57
                break;
ae06c2da83f7 Some window related enhancements
etisserant
parents: 75
diff changeset
    58
            }
57
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    59
            timer_notify();
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    60
        }
49
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    61
    }
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    62
    __cleanup();
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    63
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    64
    return 0;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    65
}