--- a/plugger.py Wed Aug 20 09:37:57 2008 +0200
+++ b/plugger.py Wed Aug 20 10:10:34 2008 +0200
@@ -1121,8 +1121,7 @@
}
target_name = self.BeremizRoot.getTargetType().getcontent()["name"]
- plc_main_code += runtime.code("plc_%s_main"%target_name)
-
+ plc_main_code += targets.code(target_name)
return plc_main_code
--- a/runtime/plc_Linux_main.c Wed Aug 20 09:37:57 2008 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,112 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <pthread.h>
-
-long AtomicCompareExchange(long* atomicvar,long exchange, long compared)
-{
- return __sync_val_compare_and_swap(atomicvar, compared, exchange);
-}
-
-//long AtomicExchange(long* atomicvar,long exchange)
-//{
-// return __sync_lock_test_and_set(atomicvar, exchange);
-//}
-
-void PLC_GetTime(IEC_TIME *CURRENT_TIME)
-{
- clock_gettime(CLOCK_REALTIME, CURRENT_TIME);
-}
-
-void PLC_timer_notify(sigval_t val)
-{
- PLC_GetTime(&__CURRENT_TIME);
- __run();
-}
-
-timer_t PLC_timer;
-
-void PLC_SetTimer(long long next, long long period)
-{
- struct itimerspec timerValues;
- /*
- printf("SetTimer(%lld,%lld)\n",next, period);
- */
- memset (&timerValues, 0, sizeof (struct itimerspec));
- {
-#ifdef __lldiv_t_defined
- lldiv_t nxt_div = lldiv(next, 1000000000);
- lldiv_t period_div = lldiv(period, 1000000000);
- timerValues.it_value.tv_sec = nxt_div.quot;
- timerValues.it_value.tv_nsec = nxt_div.rem;
- timerValues.it_interval.tv_sec = period_div.quot;
- timerValues.it_interval.tv_nsec = period_div.rem;
-#else
- timerValues.it_value.tv_sec = next / 1000000000;
- timerValues.it_value.tv_nsec = next % 1000000000;
- timerValues.it_interval.tv_sec = period / 1000000000;
- timerValues.it_interval.tv_nsec = period % 1000000000;
-#endif
- }
- timer_settime (PLC_timer, 0, &timerValues, NULL);
-}
-//
-void catch_signal(int sig)
-{
-// signal(SIGTERM, catch_signal);
- signal(SIGINT, catch_signal);
- printf("Got Signal %d\n",sig);
- exit(0);
-}
-
-int startPLC(int argc,char **argv)
-{
- struct sigevent sigev;
- /* Translate PLC's microseconds to Ttick nanoseconds */
- Ttick = 1000000 * maxval(common_ticktime__,1);
-
- memset (&sigev, 0, sizeof (struct sigevent));
- sigev.sigev_value.sival_int = 0;
- sigev.sigev_notify = SIGEV_THREAD;
- sigev.sigev_notify_attributes = NULL;
- sigev.sigev_notify_function = PLC_timer_notify;
-
- timer_create (CLOCK_REALTIME, &sigev, &PLC_timer);
- if( __init(argc,argv) == 0 ){
- PLC_SetTimer(Ttick,Ttick);
-
- /* install signal handler for manual break */
-// signal(SIGTERM, catch_signal);
- signal(SIGINT, catch_signal);
- }else{
- return 1;
- }
- return 0;
-}
-
-int stopPLC()
-{
- /* Stop the PLC */
- PLC_SetTimer(0,0);
- timer_delete (PLC_timer);
- __cleanup();
-}
-
-pthread_mutex_t DebugLock = PTHREAD_MUTEX_INITIALIZER;
-
-/* from plc_debugger.c */
-void WaitDebugData()
-{
- /* Wait signal from PLC thread */
- pthread_mutex_lock(&DebugLock);
-}
-
-/* Called by PLC thread when debug_publish finished
- * This is supposed to unlock debugger thread in WaitDebugData*/
-void InitiateDebugTransfer()
-{
- /* signal debugger thread to continue*/
- pthread_mutex_unlock(&DebugLock);
-}
--- a/runtime/plc_Win32_main.c Wed Aug 20 09:37:57 2008 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,85 +0,0 @@
-#include <stdio.h>
-#include <sys/timeb.h>
-#include <time.h>
-#include <windows.h>
-
-long AtomicCompareExchange(long* atomicvar,long exchange, long compared)
-{
- return InterlockedCompareExchange(atomicvar, exchange, compared);
-}
-
-//long AtomicExchange(long* atomicvar,long exchange)
-//{
-// return InterlockedExchange(atomicvar, exchange);
-//}
-
-struct _timeb timetmp;
-void PLC_GetTime(IEC_TIME *CURRENT_TIME)
-{
- _ftime(&timetmp);
-
- (*CURRENT_TIME).tv_sec = timetmp.time;
- (*CURRENT_TIME).tv_nsec = timetmp.millitm * 1000000;
-}
-
-void PLC_timer_notify()
-{
- PLC_GetTime(&__CURRENT_TIME);
- __run();
-}
-
-HANDLE PLC_timer = NULL;
-void PLC_SetTimer(long long next, long long period)
-{
- 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());
- }
- PLC_timer_notify();
-}
-
-int main(int argc,char **argv)
-{
- /* Translate PLC's microseconds to Ttick nanoseconds */
- Ttick = 1000000 * maxval(common_ticktime__,1);
-
- /* Create a waitable timer */
- PLC_timer = CreateWaitableTimer(NULL, FALSE, "WaitableTimer");
- if(NULL == PLC_timer)
- {
- printf("CreateWaitableTimer failed (%d)\n", GetLastError());
- return 1;
- }
-
- if( __init(argc,argv) == 0 )
- {
- printf("Tick Time : %d ms\n", common_ticktime__);
- while(1)
- {
- // Set a timer
- PLC_SetTimer(Ttick,Ttick);
- if (kbhit())
- {
- printf("Finishing\n");
- break;
- }
- }
- PLC_SetTimer(0,0);
- }
- __cleanup();
- CloseHandle(PLC_timer);
-
- return 0;
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/targets/Linux/plc_Linux_main.c Wed Aug 20 10:10:34 2008 +0200
@@ -0,0 +1,112 @@
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <pthread.h>
+
+long AtomicCompareExchange(long* atomicvar,long exchange, long compared)
+{
+ return __sync_val_compare_and_swap(atomicvar, compared, exchange);
+}
+
+//long AtomicExchange(long* atomicvar,long exchange)
+//{
+// return __sync_lock_test_and_set(atomicvar, exchange);
+//}
+
+void PLC_GetTime(IEC_TIME *CURRENT_TIME)
+{
+ clock_gettime(CLOCK_REALTIME, CURRENT_TIME);
+}
+
+void PLC_timer_notify(sigval_t val)
+{
+ PLC_GetTime(&__CURRENT_TIME);
+ __run();
+}
+
+timer_t PLC_timer;
+
+void PLC_SetTimer(long long next, long long period)
+{
+ struct itimerspec timerValues;
+ /*
+ printf("SetTimer(%lld,%lld)\n",next, period);
+ */
+ memset (&timerValues, 0, sizeof (struct itimerspec));
+ {
+#ifdef __lldiv_t_defined
+ lldiv_t nxt_div = lldiv(next, 1000000000);
+ lldiv_t period_div = lldiv(period, 1000000000);
+ timerValues.it_value.tv_sec = nxt_div.quot;
+ timerValues.it_value.tv_nsec = nxt_div.rem;
+ timerValues.it_interval.tv_sec = period_div.quot;
+ timerValues.it_interval.tv_nsec = period_div.rem;
+#else
+ timerValues.it_value.tv_sec = next / 1000000000;
+ timerValues.it_value.tv_nsec = next % 1000000000;
+ timerValues.it_interval.tv_sec = period / 1000000000;
+ timerValues.it_interval.tv_nsec = period % 1000000000;
+#endif
+ }
+ timer_settime (PLC_timer, 0, &timerValues, NULL);
+}
+//
+void catch_signal(int sig)
+{
+// signal(SIGTERM, catch_signal);
+ signal(SIGINT, catch_signal);
+ printf("Got Signal %d\n",sig);
+ exit(0);
+}
+
+int startPLC(int argc,char **argv)
+{
+ struct sigevent sigev;
+ /* Translate PLC's microseconds to Ttick nanoseconds */
+ Ttick = 1000000 * maxval(common_ticktime__,1);
+
+ memset (&sigev, 0, sizeof (struct sigevent));
+ sigev.sigev_value.sival_int = 0;
+ sigev.sigev_notify = SIGEV_THREAD;
+ sigev.sigev_notify_attributes = NULL;
+ sigev.sigev_notify_function = PLC_timer_notify;
+
+ timer_create (CLOCK_REALTIME, &sigev, &PLC_timer);
+ if( __init(argc,argv) == 0 ){
+ PLC_SetTimer(Ttick,Ttick);
+
+ /* install signal handler for manual break */
+// signal(SIGTERM, catch_signal);
+ signal(SIGINT, catch_signal);
+ }else{
+ return 1;
+ }
+ return 0;
+}
+
+int stopPLC()
+{
+ /* Stop the PLC */
+ PLC_SetTimer(0,0);
+ timer_delete (PLC_timer);
+ __cleanup();
+}
+
+pthread_mutex_t DebugLock = PTHREAD_MUTEX_INITIALIZER;
+
+/* from plc_debugger.c */
+void WaitDebugData()
+{
+ /* Wait signal from PLC thread */
+ pthread_mutex_lock(&DebugLock);
+}
+
+/* Called by PLC thread when debug_publish finished
+ * This is supposed to unlock debugger thread in WaitDebugData*/
+void InitiateDebugTransfer()
+{
+ /* signal debugger thread to continue*/
+ pthread_mutex_unlock(&DebugLock);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/targets/Win32/plc_Win32_main.c Wed Aug 20 10:10:34 2008 +0200
@@ -0,0 +1,85 @@
+#include <stdio.h>
+#include <sys/timeb.h>
+#include <time.h>
+#include <windows.h>
+
+long AtomicCompareExchange(long* atomicvar,long exchange, long compared)
+{
+ return InterlockedCompareExchange(atomicvar, exchange, compared);
+}
+
+//long AtomicExchange(long* atomicvar,long exchange)
+//{
+// return InterlockedExchange(atomicvar, exchange);
+//}
+
+struct _timeb timetmp;
+void PLC_GetTime(IEC_TIME *CURRENT_TIME)
+{
+ _ftime(&timetmp);
+
+ (*CURRENT_TIME).tv_sec = timetmp.time;
+ (*CURRENT_TIME).tv_nsec = timetmp.millitm * 1000000;
+}
+
+void PLC_timer_notify()
+{
+ PLC_GetTime(&__CURRENT_TIME);
+ __run();
+}
+
+HANDLE PLC_timer = NULL;
+void PLC_SetTimer(long long next, long long period)
+{
+ 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());
+ }
+ PLC_timer_notify();
+}
+
+int main(int argc,char **argv)
+{
+ /* Translate PLC's microseconds to Ttick nanoseconds */
+ Ttick = 1000000 * maxval(common_ticktime__,1);
+
+ /* Create a waitable timer */
+ PLC_timer = CreateWaitableTimer(NULL, FALSE, "WaitableTimer");
+ if(NULL == PLC_timer)
+ {
+ printf("CreateWaitableTimer failed (%d)\n", GetLastError());
+ return 1;
+ }
+
+ if( __init(argc,argv) == 0 )
+ {
+ printf("Tick Time : %d ms\n", common_ticktime__);
+ while(1)
+ {
+ // Set a timer
+ PLC_SetTimer(Ttick,Ttick);
+ if (kbhit())
+ {
+ printf("Finishing\n");
+ break;
+ }
+ }
+ PLC_SetTimer(0,0);
+ }
+ __cleanup();
+ CloseHandle(PLC_timer);
+
+ return 0;
+}
--- a/targets/__init__.py Wed Aug 20 09:37:57 2008 +0200
+++ b/targets/__init__.py Wed Aug 20 10:10:34 2008 +0200
@@ -64,4 +64,11 @@
for target in DictXSD_target.keys():
targetchoices += DictXSD_target[target]
+def code(target_name):
+ filename = path.join(path.split(__file__)[0], target_name, "plc_%s_main.c"%target_name)
+ if path.exists(filename):
+ return open(filename).read()
+ else:
+ return "#error %s target not implemented !!!\n"%target_name
+
from toolchain_gcc import toolchain_gcc
\ No newline at end of file