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/] [02_inv_scan.c] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
/**
2
 *
3
 * @file   02_inv_scan.c
4
 * @author Lasse Lehtonen
5
 *
6
 * @brief VOPD - inv_scan 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   = 2;
21
const int REMOTE  = 3;
22
const int TX_PORT = 4;
23
const int RX_PORT = 5;
24
const int IN_PORT = 3;
25
const int TX_DATA = 370;//688;
26
 
27
mcapi_pktchan_recv_hndl_t       send_handle;
28
mcapi_pktchan_recv_hndl_t       recv_handle;
29
 
30
static struct sigaction oldactions[32];
31
 
32
static void signalled(int signal, siginfo_t *info, void *context)
33
{
34
        struct sigaction *action;
35
 
36
        action = &oldactions[signal];
37
 
38
        if ((action->sa_flags & SA_SIGINFO) && action->sa_sigaction)
39
                action->sa_sigaction(signal, info, context);
40
        else if (action->sa_handler)
41
                action->sa_handler(signal);
42
 
43
        exit(signal);
44
}
45
 
46
struct sigaction action = {
47
        .sa_sigaction = signalled,
48
        .sa_flags = SA_SIGINFO,
49
};
50
 
51
 
52
int main(int argc, char* argv[])
53
{
54
 
55
   mcapi_status_t status;
56
   mcapi_version_t version;
57
 
58
   char   outgoing[TX_DATA];
59
   char*  incoming;
60
   size_t bytes;
61
   int count = 0;
62
 
63
 
64
   mcapi_initialize(LOCAL, &version, &status);
65
   mcapi_assert_success(status);
66
   printf("Node %d: MCAPI Initialized\n", LOCAL);
67
 
68
   connect_fwd(LOCAL, TX_PORT, &send_handle, REMOTE, RX_PORT);
69
   connect_rev(LOCAL, IN_PORT, &recv_handle);
70
 
71
   atexit(cleanup);
72
   sigaction(SIGQUIT, &action, &oldactions[SIGQUIT]);
73
   sigaction(SIGABRT, &action, &oldactions[SIGABRT]);
74
   sigaction(SIGTERM, &action, &oldactions[SIGTERM]);
75
   sigaction(SIGINT,  &action, &oldactions[SIGINT]);
76
 
77
   while(1) {
78
 
79
      mcapi_pktchan_recv(recv_handle, (void *)&incoming, &bytes,
80
                        &status);
81
      printf("Node %d: received %d bytes :%s\n", LOCAL, bytes, incoming);
82
 
83
      mcapi_pktchan_free(incoming, &status);
84
      mcapi_assert_success(status);
85
 
86
      count = (count+1) % 10;
87
      memset(outgoing, 0, TX_DATA);
88
      sprintf(outgoing, "Node %d: inv_scan (%d)", LOCAL, count);
89
 
90
      mcapi_pktchan_send(send_handle, outgoing, TX_DATA,
91
                         &status);
92
      mcapi_assert_success(status);
93
   }
94
 
95
   return 0;
96
}
97
 
98
// Local Variables:
99
// mode: c++
100
// c-file-style: "ellemtel"
101
// c-basic-offset: 3
102
// End:
103
 

powered by: WebSVN 2.1.0

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