--- a/runtime/plc_Win32_main.c Mon Jul 07 11:34:12 2008 +0200
+++ b/runtime/plc_Win32_main.c Mon Jul 07 13:37:23 2008 +0200
@@ -5,61 +5,73 @@
+void PLC_GetTime(IEC_TIME *CURRENT_TIME) + (*CURRENT_TIME).tv_sec = timetmp.time; + (*CURRENT_TIME).tv_nsec = timetmp.millitm * 1000000; + PLC_GetTime(&__CURRENT_TIME); +HANDLE PLC_timer = NULL; +void PLC_SetTimer(long long next, long long period) - struct _timeb timebuffer;
- if(++localcount % 50 == 0){
- printf("PLC tick : %d\n",localcount);
- __CURRENT_TIME.tv_sec = timebuffer.time;
- __CURRENT_TIME.tv_nsec = timebuffer.millitm * 1000000;
+ LARGE_INTEGER liDueTime; + /* arg 2 of SetWaitableTimer take 100 ns interval*/ + liDueTime.QuadPart = next / (-100); + printf("SetTimer(%lld,%lld)\n",next, period); + if (!SetWaitableTimer(PLC_timer, &liDueTime, common_ticktime__, NULL, NULL, 0)) + printf("SetWaitableTimer failed (%d)\n", GetLastError()); + if (WaitForSingleObject(PLC_timer, INFINITE) != WAIT_OBJECT_0) + printf("WaitForSingleObject failed (%d)\n", GetLastError()); int main(int argc,char **argv)
- LARGE_INTEGER liDueTime;
+ /* Translate PLC's microseconds to Ttick nanoseconds */ + Ttick = 1000000 * maxval(common_ticktime__,1); - liDueTime.QuadPart = -10000 * maxval(common_ticktime__,1);
- // Create a waitable timer.
- hTimer = CreateWaitableTimer(NULL, FALSE, "WaitableTimer");
+ /* Create a waitable timer */ + PLC_timer = CreateWaitableTimer(NULL, FALSE, "WaitableTimer"); printf("CreateWaitableTimer failed (%d)\n", GetLastError());
- if( __init(argc,argv) == 0 ){
+ if( __init(argc,argv) == 0 ) printf("Tick Time : %d ms\n", common_ticktime__);
- if (!SetWaitableTimer(hTimer, &liDueTime, common_ticktime__, NULL, NULL, 0))
- printf("SetWaitableTimer failed (%d)\n", GetLastError());
- if (WaitForSingleObject(hTimer, INFINITE) != WAIT_OBJECT_0)
- printf("WaitForSingleObject failed (%d)\n", GetLastError());
+ PLC_SetTimer(Ttick,Ttick);
+ CloseHandle(PLC_timer);