runtime/plc_Win32_main.c
author greg
Tue, 29 Jan 2008 11:17:26 +0100
changeset 92 b4e25e5030d4
parent 79 ae06c2da83f7
child 110 a05e8b30c024
permissions -rw-r--r--
remove deb_dist in debian/rules
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
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
     6
void timer_notify()
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
     7
{
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
     8
   struct _timeb timebuffer;
75
9ad18a387a96 Windows related enhancements
etisserant
parents: 57
diff changeset
     9
   printf(".");
49
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    10
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    11
   _ftime( &timebuffer );
75
9ad18a387a96 Windows related enhancements
etisserant
parents: 57
diff changeset
    12
   __CURRENT_TIME.tv_sec = timebuffer.time;
9ad18a387a96 Windows related enhancements
etisserant
parents: 57
diff changeset
    13
   __CURRENT_TIME.tv_nsec = timebuffer.millitm * 1000000;
49
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    14
   __run();
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
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    17
int main(int argc,char **argv)
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    18
{
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    19
    HANDLE hTimer = NULL;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    20
    LARGE_INTEGER liDueTime;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    21
75
9ad18a387a96 Windows related enhancements
etisserant
parents: 57
diff changeset
    22
    liDueTime.QuadPart = -10000 * maxval(common_ticktime__,1);
49
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
    // Create a waitable timer.
75
9ad18a387a96 Windows related enhancements
etisserant
parents: 57
diff changeset
    25
    hTimer = CreateWaitableTimer(NULL, FALSE, "WaitableTimer");
49
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    26
    if (NULL == hTimer)
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    27
    {
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    28
        printf("CreateWaitableTimer failed (%d)\n", GetLastError());
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    29
        return 1;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    30
    }
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    31
57
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    32
    if( __init(argc,argv) == 0 ){
49
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    33
75
9ad18a387a96 Windows related enhancements
etisserant
parents: 57
diff changeset
    34
    	printf("Tick Time : %d ms\n", common_ticktime__);
57
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    35
        // Set a timer
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    36
        if (!SetWaitableTimer(hTimer, &liDueTime, common_ticktime__, NULL, NULL, 0))
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    37
        {
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    38
            printf("SetWaitableTimer failed (%d)\n", GetLastError());
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    39
            return 2;
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    40
        }
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    41
    
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    42
        while(1){
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    43
        // Wait for the timer.
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    44
            if (WaitForSingleObject(hTimer, INFINITE) != WAIT_OBJECT_0)
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
                printf("WaitForSingleObject failed (%d)\n", GetLastError());
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    47
                break;
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    48
            }
79
ae06c2da83f7 Some window related enhancements
etisserant
parents: 75
diff changeset
    49
            if (kbhit())
ae06c2da83f7 Some window related enhancements
etisserant
parents: 75
diff changeset
    50
            {
ae06c2da83f7 Some window related enhancements
etisserant
parents: 75
diff changeset
    51
                printf("Finishing\n");
ae06c2da83f7 Some window related enhancements
etisserant
parents: 75
diff changeset
    52
                break;
ae06c2da83f7 Some window related enhancements
etisserant
parents: 75
diff changeset
    53
            }
57
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    54
            timer_notify();
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    55
        }
49
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    56
    }
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    57
    __cleanup();
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    58
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    59
    return 0;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    60
}