runtime/plc_Linux_main.c
author etisserant
Mon, 24 Sep 2007 17:08:35 +0200
changeset 53 805abb954de2
parent 49 45dc6a944ab6
child 57 3b53f9a509d9
permissions -rw-r--r--
removed timer_notify conflict with CanFestival
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
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    40
    __init();
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    41
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    42
    timer_create (CLOCK_REALTIME, &sigev, &timer);
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    43
    timer_settime (timer, 0, &timerValues, NULL);
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    44
    
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    45
    /* install signal handler for manual break */
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    46
    signal(SIGTERM, catch_signal);
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    47
    signal(SIGINT, catch_signal);
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
    pause();
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    50
    
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    51
    timer_delete (timer);
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
    __cleanup();
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    54
    
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    55
    return 0;
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents:
diff changeset
    56
}