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_delete_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
 
31
 
32
#include <openmcapi.h>
33
 
34
extern MCAPI_INTERFACE  MCAPI_Interface_List[];
35
 
36
/*************************************************************************
37
*
38
*   FUNCTION
39
*
40
*       mcapi_delete_endpoint
41
*
42
*   DESCRIPTION
43
*
44
*       API routine to delete a specific endpoint on the local node.
45
*       An endpoint can be deleted only by the node that created the
46
*       endpoint.  All pending incoming messages will be discarded
47
*       upon deletion.  If the endpoint is a packet or scalar, the
48
*       connection must be closed before deleting the endpoint.
49
*
50
*   INPUTS
51
*
52
*       endpoint                The endpoint identifier on the local node
53
*                               to delete.
54
*       *mcapi_status           A pointer to memory that will be filled in
55
*                               with the status of the call.
56
*
57
*   OUTPUTS
58
*
59
*       The endpoint identifier associated with the node ID / port ID
60
*       combination.
61
*
62
*************************************************************************/
63
void mcapi_delete_endpoint(mcapi_endpoint_t endpoint,
64
                           mcapi_status_t *mcapi_status)
65
{
66
    MCAPI_GLOBAL_DATA   *node_data;
67
    MCAPI_ENDPOINT      *endp_ptr = MCAPI_NULL;
68
    int                 node_idx;
69
    mcapi_node_t        node_id;
70
    mcapi_port_t        port_id;
71
    MCAPI_BUFFER        *cur_buf;
72
 
73
    /* Ensure mcapi_status is valid. */
74
    if (mcapi_status)
75
    {
76
        /* Get the lock. */
77
        mcapi_lock_node_data();
78
 
79
        /* Get a pointer to the global node list. */
80
        node_data = mcapi_get_node_data();
81
 
82
        /* Get a pointer to the endpoint. */
83
        endp_ptr = mcapi_decode_local_endpoint(node_data, &node_id, &port_id,
84
                                               endpoint, mcapi_status);
85
 
86
        /* Ensure the endpoint is valid. */
87
        if (*mcapi_status == MCAPI_SUCCESS)
88
        {
89
            /* Ensure the endpoint is not part of a connected channel. */
90
            if ( (!(endp_ptr->mcapi_state & MCAPI_ENDP_TX)) &&
91
                 (!(endp_ptr->mcapi_state & MCAPI_ENDP_RX)) )
92
            {
93
                /* Get a pointer to the node structure. */
94
                node_idx = mcapi_find_node(node_id, node_data);
95
 
96
                if (node_idx != -1)
97
                {
98
                    /* Decrement the number of used endpoints on this node. */
99
                    node_data->mcapi_node_list[node_idx].mcapi_endpoint_count --;
100
 
101
                    /* If the endpoint is part of a half-open connection. */
102
                    if (endp_ptr->mcapi_state & MCAPI_ENDP_CONNECTING)
103
                    {
104
                        /* Close the connection. */
105
                        mcapi_tx_fin_msg(endp_ptr, mcapi_status);
106
                    }
107
 
108
                    /* Cancel any threads blocking on this endpoint and set an
109
                     * error in the request structure.
110
                     */
111
                    mcapi_check_resume(MCAPI_REQ_DELETED, endpoint, MCAPI_NULL, 0,
112
                                       MCAPI_ERR_PORT_INVALID);
113
 
114
                    /* Set the state of the entry to closed. */
115
                    endp_ptr->mcapi_state = MCAPI_ENDP_CLOSED;
116
 
117
                    /* Remove the first buffer from the receive queue. */
118
                    cur_buf = mcapi_dequeue(&endp_ptr->mcapi_rx_queue);
119
 
120
                    /* If there is data pending on the endpoint, free it. */
121
                    while (cur_buf)
122
                    {
123
                        /* Remove the buffer from the receive queue and place
124
                         * it on the free list.
125
                         */
126
                        ((MCAPI_INTERFACE*)(cur_buf->mcapi_dev_ptr))->
127
                            mcapi_recover_buffer(cur_buf);
128
 
129
                        /* Get the next buffer. */
130
                        cur_buf = mcapi_dequeue(&endp_ptr->mcapi_rx_queue);
131
                    }
132
 
133
                    *mcapi_status = MCAPI_SUCCESS;
134
                }
135
 
136
                else
137
                {
138
                    *mcapi_status = MCAPI_ERR_ENDP_INVALID;
139
                }
140
            }
141
 
142
            /* Channel must be closed before deleting an endpoint. */
143
            else
144
            {
145
                *mcapi_status = MCAPI_ERR_CHAN_OPEN;
146
            }
147
        }
148
 
149
        /* Release the lock. */
150
        mcapi_unlock_node_data();
151
    }
152
 
153
}

powered by: WebSVN 2.1.0

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