runtime/plc_Linux_main.c
author etisserant
Sat, 24 May 2008 15:55:19 +0200
changeset 154 f3134b2c6d92
parent 100 24b504f67c72
child 178 2390b409eb93
permissions -rw-r--r--
Fixed killing app on Linux in wxPopen. Do not use shell anymore. Command line is splitted into args, taking care of double and simple cotes. To be tested on win32.
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 <string.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 <signal.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
53
805abb954de2 removed timer_notify conflict with CanFestival
etisserant
parents: 49
diff changeset
     7
void PLC_timer_notify(sigval_t val)
49
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
     8
{
100
24b504f67c72 Fixed current time struct in linux runtime
etisserant
parents: 57
diff changeset
     9
    clock_gettime(CLOCK_REALTIME, &__CURRENT_TIME);
49
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    10
    __run();
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    11
}
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    12
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    13
void catch_signal(int sig)
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
  signal(SIGTERM, catch_signal);
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    16
  signal(SIGINT, catch_signal);
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    17
  printf("Got Signal %d\n",sig);
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
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    20
int main(int argc,char **argv)
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    21
{
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    22
    timer_t timer;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    23
    struct sigevent sigev;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    24
    long tv_nsec = 1000000 * (maxval(common_ticktime__,1)%1000);
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    25
    time_t tv_sec = common_ticktime__/1000;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    26
    struct itimerspec timerValues;
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
    memset (&sigev, 0, sizeof (struct sigevent));
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    29
    memset (&timerValues, 0, sizeof (struct itimerspec));
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    30
    sigev.sigev_value.sival_int = 0;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    31
    sigev.sigev_notify = SIGEV_THREAD;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    32
    sigev.sigev_notify_attributes = NULL;
53
805abb954de2 removed timer_notify conflict with CanFestival
etisserant
parents: 49
diff changeset
    33
    sigev.sigev_notify_function = PLC_timer_notify;
49
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    34
    timerValues.it_value.tv_sec = tv_sec;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    35
    timerValues.it_value.tv_nsec = tv_nsec;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    36
    timerValues.it_interval.tv_sec = tv_sec;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    37
    timerValues.it_interval.tv_nsec = tv_nsec;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    38
57
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 53
diff changeset
    39
    if(  __init(argc,argv) == 0 ){
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 53
diff changeset
    40
        timer_create (CLOCK_REALTIME, &sigev, &timer);
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 53
diff changeset
    41
        timer_settime (timer, 0, &timerValues, NULL);
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 53
diff changeset
    42
        
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 53
diff changeset
    43
        /* install signal handler for manual break */
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 53
diff changeset
    44
        signal(SIGTERM, catch_signal);
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 53
diff changeset
    45
        signal(SIGINT, catch_signal);
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 53
diff changeset
    46
        
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 53
diff changeset
    47
        pause();
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 53
diff changeset
    48
        
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 53
diff changeset
    49
        timer_delete (timer);
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 53
diff changeset
    50
    }
49
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    51
    __cleanup();
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    52
    
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    53
    return 0;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    54
}