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

Subversion Repositories funbase_ip_library

[/] [funbase_ip_library/] [trunk/] [TUT/] [ip.swp.api/] [openmcapi/] [1.0/] [demo/] [linux_init.c] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
#include <stdlib.h>
2
#include <stdio.h>
3
#include <signal.h>
4
#include <getopt.h>
5
 
6
#include <mcapi.h>
7
 
8
extern void startup(unsigned int local, unsigned int remote);
9
extern void demo(unsigned int local, int listen);
10
 
11
static struct sigaction oldactions[32];
12
 
13
static void usage(const char *name)
14
{
15
        printf("Usage: %s [options] <local node id> <remote node id>\n"
16
                        "Options:\n"
17
                        "  -l, --loop      send and receive messages until killed.\n",
18
                        name);
19
        exit(1);
20
}
21
 
22
static void cleanup(void)
23
{
24
        mcapi_status_t status;
25
 
26
        printf("%s\n", __func__);
27
        mcapi_finalize(&status);
28
}
29
 
30
static void signalled(int signal, siginfo_t *info, void *context)
31
{
32
        struct sigaction *action;
33
 
34
        action = &oldactions[signal];
35
 
36
        if ((action->sa_flags & SA_SIGINFO) && action->sa_sigaction)
37
                action->sa_sigaction(signal, info, context);
38
        else if (action->sa_handler)
39
                action->sa_handler(signal);
40
 
41
        exit(signal);
42
}
43
 
44
struct sigaction action = {
45
        .sa_sigaction = signalled,
46
        .sa_flags = SA_SIGINFO,
47
};
48
 
49
int main(int argc, char *argv[])
50
{
51
        unsigned long local;
52
        unsigned long remote;
53
        int c;
54
        int loop = 0;
55
 
56
        while (1) {
57
                static struct option long_options[] = {
58
                        {"loop", 0, 0, 'l'},
59
                        {NULL, 0, 0, 0},
60
                };
61
                int option_index = 0;
62
 
63
                c = getopt_long(argc, argv, "l", long_options, &option_index);
64
 
65
                if (c == -1)
66
                        break;
67
 
68
                switch (c) {
69
                case 'l':
70
                        loop = 1;
71
                        break;
72
                default:
73
                        usage(argv[0]);
74
                        break;
75
                }
76
        }
77
 
78
        if (optind == argc - 2) {
79
                local = strtoul(argv[optind], NULL, 0);
80
                remote = strtoul(argv[optind + 1], NULL, 0);
81
        } else
82
                usage(argv[0]);
83
 
84
        atexit(cleanup);
85
        sigaction(SIGQUIT, &action, &oldactions[SIGQUIT]);
86
        sigaction(SIGABRT, &action, &oldactions[SIGABRT]);
87
        sigaction(SIGTERM, &action, &oldactions[SIGTERM]);
88
        sigaction(SIGINT,  &action, &oldactions[SIGINT]);
89
 
90
        startup(local, remote);
91
 
92
        demo(local, loop);
93
 
94
        return 0;
95
}

powered by: WebSVN 2.1.0

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