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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
/**
2
 *
3
 * @file   11_vop_mem.c
4
 * @author Lasse Lehtonen
5
 *
6
 * @brief VOPD - vop_mem 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    = 11;
21
 
22
const int REMOTE1  = 10;
23
const int TX_PORT1 = 24;
24
const int RX_PORT1 = 25;
25
const int TX_DATA1 = 512;//000;
26
 
27
const int REMOTE2  = 9;
28
const int TX_PORT2 = 26;
29
const int RX_PORT2 = 27;
30
const int TX_DATA2 = 512;//000;
31
 
32
const int IN_PORT  = 23;
33
 
34
 
35
 
36
mcapi_pktchan_recv_hndl_t       send_handle1;
37
mcapi_pktchan_recv_hndl_t       send_handle2;
38
mcapi_pktchan_recv_hndl_t       recv_handle;
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
   char*  incoming;
71
   size_t bytes;
72
   int count = 0;
73
 
74
 
75
   mcapi_initialize(LOCAL, &version, &status);
76
   mcapi_assert_success(status);
77
   printf("Node %d: MCAPI Initialized\n", LOCAL);
78
 
79
 
80
   connect_rev(LOCAL, IN_PORT, &recv_handle);
81
   connect_fwd(LOCAL, TX_PORT1, &send_handle1, REMOTE1, RX_PORT1);
82
   connect_fwd(LOCAL, TX_PORT2, &send_handle2, REMOTE2, RX_PORT2);
83
 
84
 
85
 
86
   atexit(cleanup);
87
   sigaction(SIGQUIT, &action, &oldactions[SIGQUIT]);
88
   sigaction(SIGABRT, &action, &oldactions[SIGABRT]);
89
   sigaction(SIGTERM, &action, &oldactions[SIGTERM]);
90
   sigaction(SIGINT,  &action, &oldactions[SIGINT]);
91
 
92
   while(1) {
93
 
94
      // Send 1
95
      count = (count+1) % 10;
96
      memset(outgoing1, 0, TX_DATA1);
97
      sprintf(outgoing1, "Node %d: vop_mem (%d)", LOCAL, count);
98
 
99
      mcapi_pktchan_send(send_handle1, outgoing1, TX_DATA1,
100
                         &status);
101
      mcapi_assert_success(status);
102
 
103
      // Send 2
104
      memset(outgoing2, 0, TX_DATA2);
105
      sprintf(outgoing2, "Node %d: vop_mem (%d)", LOCAL, count);
106
 
107
      mcapi_pktchan_send(send_handle2, outgoing2, TX_DATA2,
108
                         &status);
109
      mcapi_assert_success(status);
110
 
111
      // Receive
112
      mcapi_pktchan_recv(recv_handle, (void *)&incoming, &bytes,
113
                        &status);
114
      printf("Node %d: received %d bytes :%s\n", LOCAL, bytes, incoming);
115
 
116
      mcapi_pktchan_free(incoming, &status);
117
      mcapi_assert_success(status);
118
 
119
   }
120
 
121
   return 0;
122
}
123
 
124
// Local Variables:
125
// mode: c++
126
// c-file-style: "ellemtel"
127
// c-basic-offset: 3
128
// End:
129
 

powered by: WebSVN 2.1.0

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