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/] [mcapi_get_endp.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
#include <openmcapi.h>
31
 
32
/*************************************************************************
33
*
34
*   FUNCTION
35
*
36
*       mcapi_get_endpoint
37
*
38
*   DESCRIPTION
39
*
40
*       Blocking API routine to retrieve the endpoint identifier
41
*       associated with a specific node ID and port ID.  The routine will
42
*       block until the specific endpoint has been created.
43
*
44
*   INPUTS
45
*
46
*       node_id                 The unique ID of the node on which the target
47
*                               endpoint resides.
48
*       port_id                 The port ID of the target endpoint.
49
*       *mcapi_status           A pointer to memory that will be filled in
50
*                               with the status of the call.
51
*
52
*   OUTPUTS
53
*
54
*       The endpoint identifier associated with the node ID / port ID
55
*       combination.
56
*
57
*************************************************************************/
58
mcapi_endpoint_t mcapi_get_endpoint(mcapi_node_t node_id, mcapi_port_t port_id,
59
                                    mcapi_status_t *mcapi_status)
60
{
61
    MCAPI_GLOBAL_DATA   *node_data;
62
    mcapi_endpoint_t    endpoint = 0;
63
    MCAPI_ENDPOINT      *endp_ptr;
64
    mcapi_request_t     request;
65
 
66
    /* Ensure the status parameter is valid. */
67
    if (mcapi_status)
68
    {
69
        /* Get the lock. */
70
        mcapi_lock_node_data();
71
 
72
        /* Get a pointer to the global node list. */
73
        node_data = mcapi_get_node_data();
74
 
75
        /* If the endpoint is located on the local node. */
76
        if (node_id == MCAPI_Node_ID)
77
        {
78
            /* Get a pointer to the endpoint. */
79
            endp_ptr = mcapi_find_local_endpoint(node_data, node_id,
80
                                                 port_id);
81
 
82
            /* If the endpoint was found. */
83
            if (endp_ptr)
84
            {
85
                /* Return the endpoint handle. */
86
                endpoint = endp_ptr->mcapi_endp_handle;
87
 
88
                /* Set the status. */
89
                *mcapi_status = MCAPI_SUCCESS;
90
            }
91
 
92
            /* The node has not yet been initialized. */
93
            else
94
            {
95
                *mcapi_status = MCAPI_PENDING;
96
            }
97
        }
98
 
99
        /* Otherwise, query the foreign node for the information. */
100
        else
101
        {
102
 
103
            /* If the remote endpoint is not ready loop till it becomes
104
            * available.
105
            */
106
            for (;;)
107
            {
108
                /* Issue the call to get a remote endpoint. */
109
                get_remote_endpoint(node_id, port_id, mcapi_status, 0xffffffff);
110
 
111
                if (*mcapi_status == MCAPI_ERR_TRANSMISSION)
112
                {
113
                    /* Must drop and re-acquire the lock so we don't block
114
                     * other threads forever. */
115
                    mcapi_unlock_node_data();
116
                    MCAPI_Sleep(1);
117
                    mcapi_lock_node_data();
118
                }
119
                else
120
                {
121
                    break;
122
                }
123
            }
124
 
125
            /* The get remote endpoint request was successfully sent. */
126
            if (*mcapi_status == MCAPI_SUCCESS)
127
            {
128
                *mcapi_status = MCAPI_PENDING;
129
            }
130
        }
131
 
132
        /* If the endpoint is not immediately available. */
133
        if (*mcapi_status == MCAPI_PENDING)
134
        {
135
            /* Initialize the request structure. */
136
            mcapi_init_request(&request, MCAPI_REQ_CREATED);
137
 
138
            /* Set up the request structure. */
139
            request.mcapi_target_node_id = node_id;
140
            request.mcapi_target_port_id = port_id;
141
            request.mcapi_endp_ptr = &endpoint;
142
 
143
            /* Suspend until the call completes or is canceled. */
144
            MCAPI_Suspend_Task(node_data, &request, &request.mcapi_cond,
145
                               MCAPI_TIMEOUT_INFINITE);
146
 
147
            *mcapi_status = request.mcapi_status;
148
        }
149
 
150
        /* Release the lock. */
151
        mcapi_unlock_node_data();
152
    }
153
 
154
    return (endpoint);
155
 
156
}

powered by: WebSVN 2.1.0

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