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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
/**
2
 *
3
 * @file   01_run_len_dec.c
4
 * @author Lasse Lehtonen
5
 *
6
 * @brief VOPD - run_len_dec 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   = 1;
21
const int REMOTE  = 2;
22
const int TX_PORT = 2;
23
const int RX_PORT = 3;
24
const int IN_PORT = 1;
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
   mcapi_initialize(LOCAL, &version, &status);
64
   mcapi_assert_success(status);
65
   printf("Node %d: MCAPI Initialized\n", LOCAL);
66
 
67
   connect_rev(LOCAL, IN_PORT, &recv_handle);
68
   connect_fwd(LOCAL, TX_PORT, &send_handle, REMOTE, RX_PORT);
69
 
70
   atexit(cleanup);
71
   sigaction(SIGQUIT, &action, &oldactions[SIGQUIT]);
72
   sigaction(SIGABRT, &action, &oldactions[SIGABRT]);
73
   sigaction(SIGTERM, &action, &oldactions[SIGTERM]);
74
   sigaction(SIGINT,  &action, &oldactions[SIGINT]);
75
 
76
   while(1) {
77
 
78
      mcapi_pktchan_recv(recv_handle, (void *)&incoming, &bytes,
79
                        &status);
80
      printf("Node %d: received %d bytes :%s\n", LOCAL, bytes, incoming);
81
 
82
      mcapi_pktchan_free(incoming, &status);
83
      mcapi_assert_success(status);
84
 
85
      count = (count+1) % 10;
86
      memset(outgoing, 0, TX_DATA);
87
      sprintf(outgoing, "Node %d: run_len_dec (%d)", LOCAL, count);
88
 
89
      mcapi_pktchan_send(send_handle, outgoing, TX_DATA,
90
                         &status);
91
      mcapi_assert_success(status);
92
 
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.