runtime/plc_Win32_main.c
author etisserant
Fri, 21 Sep 2007 17:48:34 +0200
changeset 49 45dc6a944ab6
child 57 3b53f9a509d9
permissions -rw-r--r--
On the long wat towards generated code comilation...
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
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    31
    __init();
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
    // Set a timer to wait for 10 seconds.
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    34
    if (!SetWaitableTimer(hTimer, &liDueTime, common_ticktime__, NULL, NULL, 0))
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
        printf("SetWaitableTimer failed (%d)\n", GetLastError());
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    37
        return 2;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    38
    }
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    39
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    40
    while(1){
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    41
    // Wait for the timer.
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    42
        if (WaitForSingleObject(hTimer, INFINITE) != WAIT_OBJECT_0)
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    43
        {
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    44
            printf("WaitForSingleObject failed (%d)\n", GetLastError());
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    45
            break;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    46
        }
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    47
        timer_notify();
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    48
    }
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
}