OpenCores
URL https://opencores.org/ocsvn/funbase_ip_library/funbase_ip_library/trunk

Subversion Repositories funbase_ip_library

[/] [funbase_ip_library/] [trunk/] [TUT/] [ip.application/] [vopd/] [1.0/] [src/] [12_timer.c] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
/**
2
 *
3
 * @file   12_timer.c
4
 * @author Lasse Lehtonen
5
 *
6
 * @brief VOPD - timer node.
7
 *
8
 */
9
 
10
 
11
#include "common.h"
12
 
13
#include <mcapi.h>
14
 
15
#include <stdlib.h>
16
#include <stdio.h>
17
#include <signal.h>
18
#include <getopt.h>
19
 
20
const int LOCAL    = 12;
21
 
22
const int REMOTE1  = 0;
23
const int TX_PORT1 = 28;
24
const int RX_PORT1 = 29;
25
const int TX_DATA1 = 8;
26
 
27
const int REMOTE2  = 6;
28
const int TX_PORT2 = 30;
29
const int RX_PORT2 = 31;
30
const int TX_DATA2 = 8;
31
 
32
 
33
 
34
 
35
 
36
mcapi_pktchan_recv_hndl_t       send_handle1;
37
mcapi_pktchan_recv_hndl_t       send_handle2;
38
 
39
 
40
static struct sigaction oldactions[32];
41
 
42
static void signalled(int signal, siginfo_t *info, void *context)
43
{
44
        struct sigaction *action;
45
 
46
        action = &oldactions[signal];
47
 
48
        if ((action->sa_flags & SA_SIGINFO) && action->sa_sigaction)
49
                action->sa_sigaction(signal, info, context);
50
        else if (action->sa_handler)
51
                action->sa_handler(signal);
52
 
53
        exit(signal);
54
}
55
 
56
struct sigaction action = {
57
        .sa_sigaction = signalled,
58
        .sa_flags = SA_SIGINFO,
59
};
60
 
61
 
62
int main(int argc, char* argv[])
63
{
64
 
65
   mcapi_status_t status;
66
   mcapi_version_t version;
67
 
68
   char   outgoing1[TX_DATA1];
69
   char   outgoing2[TX_DATA2];
70
   int count = 0;
71
 
72
 
73
   mcapi_initialize(LOCAL, &version, &status);
74
   mcapi_assert_success(status);
75
   printf("Node %d: MCAPI Initialized\n", LOCAL);
76
 
77
 
78
   connect_fwd(LOCAL, TX_PORT2, &send_handle2, REMOTE2, RX_PORT2);
79
   connect_fwd(LOCAL, TX_PORT1, &send_handle1, REMOTE1, RX_PORT1);
80
 
81
 
82
   atexit(cleanup);
83
   sigaction(SIGQUIT, &action, &oldactions[SIGQUIT]);
84
   sigaction(SIGABRT, &action, &oldactions[SIGABRT]);
85
   sigaction(SIGTERM, &action, &oldactions[SIGTERM]);
86
   sigaction(SIGINT,  &action, &oldactions[SIGINT]);
87
 
88
   while(1) {
89
 
90
 
91
      count = (count+1) % 10;
92
      memset(outgoing1, 0, TX_DATA1);
93
      sprintf(outgoing1, "Node %d: timer (%d)", LOCAL, count);
94
 
95
      mcapi_pktchan_send(send_handle1, outgoing1, TX_DATA1,
96
                         &status);
97
      mcapi_assert_success(status);
98
 
99
 
100
      memset(outgoing2, 0, TX_DATA2);
101
      sprintf(outgoing2, "Node %d: timer (%d)", LOCAL, count);
102
 
103
      mcapi_pktchan_send(send_handle2, outgoing2, TX_DATA2,
104
                         &status);
105
      mcapi_assert_success(status);
106
 
107
      sleep(1);
108
 
109
   }
110
 
111
   return 0;
112
}
113
 
114
// Local Variables:
115
// mode: c++
116
// c-file-style: "ellemtel"
117
// c-basic-offset: 3
118
// End:
119
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.