runtime/plc_Win32_main.c
author lbessard
Tue, 02 Oct 2007 18:05:36 +0200
changeset 60 e9667bec7f00
parent 57 3b53f9a509d9
child 75 9ad18a387a96
permissions -rw-r--r--
Test on wx version changed to test on platform
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;
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
   _ftime( &timebuffer );
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    11
   CURRENT_TIME.tv_sec = timebuffer.time;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    12
   CURRENT_TIME.tv_nsec = timebuffer.millitm * 1000000
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    13
   __run();
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    14
}
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
int main(int argc,char **argv)
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    17
{
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    18
    HANDLE hTimer = NULL;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    19
    LARGE_INTEGER liDueTime;
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
    liDueTime.QuadPart = -10000 * maxval(common_ticktime__,1);;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    22
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    23
    // Create a waitable timer.
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    24
    hTimer = CreateWaitableTimer(NULL, TRUE, "WaitableTimer");
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    25
    if (NULL == hTimer)
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    26
    {
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    27
        printf("CreateWaitableTimer failed (%d)\n", GetLastError());
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    28
        return 1;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    29
    }
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    30
57
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    31
    if( __init(argc,argv) == 0 ){
49
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    32
57
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    33
        // Set a timer
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    34
        if (!SetWaitableTimer(hTimer, &liDueTime, common_ticktime__, NULL, NULL, 0))
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    35
        {
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    36
            printf("SetWaitableTimer failed (%d)\n", GetLastError());
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    37
            return 2;
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    38
        }
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    39
    
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    40
        while(1){
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    41
        // Wait for the timer.
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    42
            if (WaitForSingleObject(hTimer, INFINITE) != WAIT_OBJECT_0)
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    43
            {
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    44
                printf("WaitForSingleObject failed (%d)\n", GetLastError());
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    45
                break;
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
            timer_notify();
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 49
diff changeset
    48
        }
49
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    49
    }
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    50
    __cleanup();
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    51
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    52
    return 0;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    53
}