runtime/plc_Linux_main.c
author lbessard
Tue, 02 Oct 2007 18:05:36 +0200
changeset 60 e9667bec7f00
parent 57 3b53f9a509d9
child 100 24b504f67c72
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 <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
{
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
     9
    struct timespec CURRENT_TIME;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    10
    clock_gettime(CLOCK_REALTIME, &CURRENT_TIME);
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    11
    __run();
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
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    14
void catch_signal(int sig)
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
  signal(SIGTERM, catch_signal);
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    17
  signal(SIGINT, catch_signal);
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    18
  printf("Got Signal %d\n",sig);
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
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    21
int main(int argc,char **argv)
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
    timer_t timer;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    24
    struct sigevent sigev;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    25
    long tv_nsec = 1000000 * (maxval(common_ticktime__,1)%1000);
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    26
    time_t tv_sec = common_ticktime__/1000;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    27
    struct itimerspec timerValues;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    28
    
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    29
    memset (&sigev, 0, sizeof (struct sigevent));
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    30
    memset (&timerValues, 0, sizeof (struct itimerspec));
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    31
    sigev.sigev_value.sival_int = 0;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    32
    sigev.sigev_notify = SIGEV_THREAD;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    33
    sigev.sigev_notify_attributes = NULL;
53
805abb954de2 removed timer_notify conflict with CanFestival
etisserant
parents: 49
diff changeset
    34
    sigev.sigev_notify_function = PLC_timer_notify;
49
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    35
    timerValues.it_value.tv_sec = tv_sec;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    36
    timerValues.it_value.tv_nsec = tv_nsec;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    37
    timerValues.it_interval.tv_sec = tv_sec;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    38
    timerValues.it_interval.tv_nsec = tv_nsec;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    39
57
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 53
diff changeset
    40
    if(  __init(argc,argv) == 0 ){
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 53
diff changeset
    41
        timer_create (CLOCK_REALTIME, &sigev, &timer);
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 53
diff changeset
    42
        timer_settime (timer, 0, &timerValues, NULL);
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 53
diff changeset
    43
        
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 53
diff changeset
    44
        /* install signal handler for manual break */
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 53
diff changeset
    45
        signal(SIGTERM, catch_signal);
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 53
diff changeset
    46
        signal(SIGINT, catch_signal);
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 53
diff changeset
    47
        
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 53
diff changeset
    48
        pause();
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 53
diff changeset
    49
        
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 53
diff changeset
    50
        timer_delete (timer);
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 53
diff changeset
    51
    }
49
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    52
    __cleanup();
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    53
    
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    54
    return 0;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    55
}