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/] [test/] [support_suite/] [linux/] [os_linux_demo.c] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
/*
2
 * Copyright (c) 2010, Mentor Graphics Corporation
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 * 1. Redistributions of source code must retain the above copyright notice,
9
 *    this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
11
 *    this list of conditions and the following disclaimer in the documentation
12
 *    and/or other materials provided with the distribution.
13
 * 3. Neither the name of the <ORGANIZATION> nor the names of its contributors
14
 *    may be used to endorse or promote products derived from this software
15
 *    without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
 * POSSIBILITY OF SUCH DAMAGE.
28
 */
29
 
30
/************************************************************************
31
*
32
*   FILENAME
33
*
34
*       os_linux_demo.c
35
*
36
*
37
*************************************************************************/
38
#include <pthread.h>
39
#include <signal.h>
40
#include <time.h>
41
#include <stdlib.h>
42
#include <unistd.h>
43
#include "mcapid.h"
44
#include "support_suite/mcapid_support.h"
45
 
46
extern int mcapi_test_start(int argc, char *argv[]);
47
 
48
static struct sigaction oldactions[32];
49
 
50
static void cleanup(void)
51
{
52
        mcapi_status_t status;
53
 
54
        mcapi_finalize(&status);
55
}
56
 
57
static void signalled(int signal, siginfo_t *info, void *context)
58
{
59
        struct sigaction *action;
60
 
61
        action = &oldactions[signal];
62
 
63
        if ((action->sa_flags & SA_SIGINFO) && action->sa_sigaction)
64
                action->sa_sigaction(signal, info, context);
65
        else if (action->sa_handler)
66
                action->sa_handler(signal);
67
 
68
        exit(signal);
69
}
70
 
71
struct sigaction action = {
72
        .sa_sigaction = signalled,
73
        .sa_flags = SA_SIGINFO,
74
};
75
 
76
int main(int argc, char *argv[])
77
{
78
        atexit(cleanup);
79
        sigaction(SIGQUIT, &action, &oldactions[SIGQUIT]);
80
        sigaction(SIGABRT, &action, &oldactions[SIGABRT]);
81
        sigaction(SIGTERM, &action, &oldactions[SIGTERM]);
82
        sigaction(SIGINT,  &action, &oldactions[SIGINT]);
83
 
84
    return mcapi_test_start(argc, argv);
85
}
86
 
87
mcapi_status_t MCAPID_Create_Thread(MCAPI_THREAD_PTR_ENTRY(thread_entry),
88
                                    MCAPID_STRUCT *mcapi_struct)
89
{
90
    mcapi_status_t status = MCAPI_SUCCESS;
91
    int rc;
92
 
93
    /* Initialize the state. */
94
    mcapi_struct->state = -1;
95
 
96
    rc = pthread_create(&mcapi_struct->task_ptr, NULL,
97
                        thread_entry, (void*)mcapi_struct);
98
 
99
    if (rc)
100
        status = MCAPI_ERR_GENERAL;
101
 
102
    mcapi_struct->status = status;
103
 
104
    return status;
105
}
106
 
107
/************************************************************************
108
*
109
*   FUNCTION
110
*
111
*       MCAPID_Cleanup
112
*
113
*   DESCRIPTION
114
*
115
*       This routine destroys a Linux thread.  Since Linux threads
116
*       are destroyed upon completion, there is no work required
117
*       of this routine.
118
*
119
*************************************************************************/
120
void MCAPID_Cleanup(MCAPID_STRUCT *mcapi_struct)
121
{
122
    /* Delete the local endpoint. */
123
    mcapi_delete_endpoint(mcapi_struct->local_endp, &mcapi_struct->status);
124
 
125
} /* MCAPID_Cleanup */
126
 
127
void MCAPID_Sleep(unsigned ms)
128
{
129
    usleep(ms * 1000);
130
}
131
 
132
/* Number of seconds since a fixed time. */
133
unsigned long MCAPID_Time(void)
134
{
135
    return (unsigned long)time(NULL);
136
}

powered by: WebSVN 2.1.0

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