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/] [libmcapi/] [mcapi/] [interface.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
#include <openmcapi.h>
33
 
34
MCAPI_INTERFACE MCAPI_Interface_List[MCAPI_INTERFACE_COUNT];
35
extern MCAPI_INT_INIT   MCAPI_Int_Init_List[];
36
 
37
/*************************************************************************
38
*
39
*   FUNCTION
40
*
41
*       mcapi_init_interfaces
42
*
43
*   DESCRIPTION
44
*
45
*       Initialize all interfaces on the local node.
46
*
47
*   INPUTS
48
*
49
*       node_id                 The node ID of the local node.
50
*
51
*   OUTPUTS
52
*
53
*       MCAPI_SUCCESS           Initialization was successful.
54
*       interface error         An error occurred.
55
*
56
*************************************************************************/
57
mcapi_status_t mcapi_init_interfaces(mcapi_node_t node_id)
58
{
59
    int             i = 0, j = 0;
60
    mcapi_status_t  status = MCAPI_SUCCESS;
61
    mcapi_uint32_t  prio_count;
62
 
63
    /* Initialize each interface in the system. */
64
    while ( (MCAPI_Int_Init_List[i].mcapi_init != MCAPI_NULL) &&
65
            (j < MCAPI_INTERFACE_COUNT) )
66
    {
67
        /* Initialize the interface. */
68
        status =
69
            MCAPI_Int_Init_List[i].mcapi_init(node_id, &MCAPI_Interface_List[j]);
70
 
71
        /* If this interface was initialized successfully. */
72
        if (status == MCAPI_SUCCESS)
73
        {
74
            /* Determine the number of priorities supported by this interface. */
75
            status = MCAPI_Interface_List[j].mcapi_ioctl(MCAPI_ATTR_NO_PRIORITIES,
76
                                                         (void*)&prio_count,
77
                                                         sizeof(mcapi_uint32_t));
78
 
79
            /* If there are enough priority queues available to support the
80
             * number of priorities provided by the driver.
81
             */
82
            if ( (status == MCAPI_SUCCESS) &&
83
                 (prio_count <= MCAPI_PRIO_COUNT) )
84
            {
85
                /* Move on to the next interface structure. */
86
                j ++;
87
            }
88
 
89
            else
90
            {
91
                status = MCAPI_ERR_PRIORITY;
92
                break;
93
            }
94
        }
95
 
96
        /* The interface could not be initialized.  Report the error
97
         * to the application.
98
         */
99
        else if (status != 1)
100
        {
101
            break;
102
        }
103
 
104
        i ++;
105
    }
106
 
107
    /* Only return an error code if an error occurred.  It is not an error
108
     * to attempt to initialize the loopback interface when it is not present.
109
     */
110
    if (status == 1)
111
    {
112
        status = MCAPI_SUCCESS;
113
    }
114
 
115
    return (status);
116
 
117
}
118
 
119
/*************************************************************************
120
*
121
*   FUNCTION
122
*
123
*       mcapi_find_interface
124
*
125
*   DESCRIPTION
126
*
127
*       Find an interface based on name.
128
*
129
*   INPUTS
130
*
131
*       name                        The unique name of the interface.
132
*
133
*   OUTPUTS
134
*
135
*       A pointer to the interface structure.
136
*
137
*************************************************************************/
138
MCAPI_INTERFACE *mcapi_find_interface(char *name)
139
{
140
    int             i;
141
    MCAPI_INTERFACE *int_ptr = MCAPI_NULL;
142
 
143
    /* Search the interface list. */
144
    for (i = 0; i < MCAPI_INTERFACE_COUNT; i ++)
145
    {
146
        /* If the names match. */
147
        if (strcmp(MCAPI_Interface_List[i].mcapi_int_name, name) == 0)
148
        {
149
            /* Return this interface. */
150
            int_ptr = &MCAPI_Interface_List[i];
151
 
152
            break;
153
        }
154
    }
155
 
156
    return (int_ptr);
157
 
158
}

powered by: WebSVN 2.1.0

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