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_test.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_boolean_t __mcapi_test(mcapi_request_t *request, size_t *size,
35
                             mcapi_status_t *mcapi_status)
36
{
37
    MCAPI_GLOBAL_DATA   *node_data;
38
    mcapi_boolean_t     ret_val = MCAPI_FALSE;
39
    MCAPI_ENDPOINT      *endp_ptr = MCAPI_NULL;
40
    mcapi_port_t        port_id;
41
    mcapi_node_t        node_id;
42
 
43
    /* Validate the mcapi_status input parameter. */
44
    if (mcapi_status)
45
    {
46
        /* Validate request. */
47
        if (request)
48
        {
49
            /* Check if the request has been canceled. */
50
            if (request->mcapi_status != MCAPI_ERR_REQUEST_CANCELLED)
51
            {
52
                /* Validate size. */
53
                if (size)
54
                {
55
                    /* Get a pointer to the global node list. */
56
                    node_data = mcapi_get_node_data();
57
 
58
                    /* If checking for creation of an endpoint. */
59
                    if (request->mcapi_type == MCAPI_REQ_CREATED)
60
                    {
61
                        /* If the endpoint is local. */
62
                        if (request->mcapi_target_node_id == MCAPI_Node_ID)
63
                        {
64
                            /* Get a pointer to the endpoint. */
65
                            endp_ptr =
66
                                mcapi_find_local_endpoint(node_data,
67
                                                          request->mcapi_target_node_id,
68
                                                          request->mcapi_target_port_id);
69
 
70
                            /* If the endpoint was found. */
71
                            if (endp_ptr)
72
                            {
73
                                /* Set the status to success. */
74
                                *mcapi_status = request->mcapi_status =
75
                                    MCAPI_SUCCESS;
76
 
77
                                /* Set the user's memory to the endpoint. */
78
                                *(request->mcapi_endp_ptr) = endp_ptr->mcapi_endp_handle;
79
 
80
                                ret_val = MCAPI_TRUE;
81
                            }
82
 
83
                            /* The endpoint has not been created on the node. */
84
                            else
85
                            {
86
                                *mcapi_status = MCAPI_PENDING;
87
                            }
88
                        }
89
 
90
                        /* If the remote request has completed or failed. */
91
                        else if (request->mcapi_status != MCAPI_PENDING)
92
                        {
93
                            *mcapi_status = request->mcapi_status;
94
 
95
                            ret_val = MCAPI_TRUE;
96
                        }
97
 
98
                        /* The endpoint has not been created. */
99
                        else
100
                        {
101
                            *mcapi_status = MCAPI_PENDING;
102
                        }
103
                    }
104
 
105
                    /* Checking for something other than endpoint creation. */
106
                    else
107
                    {
108
                        /* Decode the endpoint. */
109
                        endp_ptr =
110
                            mcapi_decode_local_endpoint(node_data, &node_id, &port_id,
111
                                                        request->mcapi_target_endp, mcapi_status);
112
 
113
                        /* Switch based on the operation being checked. */
114
                        switch (request->mcapi_type)
115
                        {
116
                            case MCAPI_REQ_TX_FIN:
117
 
118
                                /* Ensure the endpoint was found. */
119
                                if (endp_ptr)
120
                                {
121
                                    /* Set the number of bytes transmitted. */
122
                                    *size = request->mcapi_byte_count;
123
                                }
124
 
125
                                /* If data was transmitted or an error
126
                                 * occurred.
127
                                 */
128
                                if (request->mcapi_status != MCAPI_PENDING)
129
                                {
130
                                    /* Set the status. */
131
                                    *mcapi_status = request->mcapi_status;
132
 
133
                                    ret_val = MCAPI_TRUE;
134
                                }
135
 
136
                                /* The data has not been transmitted. */
137
                                else
138
                                {
139
                                    *mcapi_status = MCAPI_PENDING;
140
                                }
141
 
142
                                break;
143
 
144
                            case MCAPI_REQ_RX_FIN:
145
 
146
                                /* If there is data on this endpoint. */
147
                                if (endp_ptr)
148
                                {
149
                                    /* Data has been received on the endpoint. */
150
                                    if (request->mcapi_status == MCAPI_SUCCESS)
151
                                    {
152
                                        /* Set the status to success. */
153
                                        *mcapi_status = MCAPI_SUCCESS;
154
 
155
                                        /* Set the number of bytes in the request
156
                                         * structure.
157
                                         */
158
                                        *size = request->mcapi_byte_count;
159
 
160
                                        ret_val = MCAPI_TRUE;
161
                                    }
162
 
163
                                    /* No data has been received on the endpoint. */
164
                                    else if (request->mcapi_status == MCAPI_PENDING)
165
                                    {
166
                                        /* Set the status. */
167
                                        *mcapi_status = MCAPI_PENDING;
168
 
169
                                        /* Indicate that no data has been received. */
170
                                        *size = 0;
171
                                    }
172
 
173
                                    /* An error occurred. */
174
                                    else
175
                                    {
176
                                        /* Set the status. */
177
                                        *mcapi_status = request->mcapi_status;
178
 
179
                                        /* Indicate that no data has been received. */
180
                                        *size = 0;
181
                                    }
182
                                }
183
 
184
                                /* The endpoint is invalid, therefore this request
185
                                 * structure is invalid.
186
                                 */
187
                                else
188
                                {
189
                                    *mcapi_status = MCAPI_ERR_REQUEST_INVALID;
190
                                }
191
 
192
                                break;
193
 
194
                            case MCAPI_REQ_CONNECTED:
195
 
196
                                /* If the request is no longer in the pending state. */
197
                                if (request->mcapi_status != MCAPI_PENDING)
198
                                {
199
                                    /* Set the status. */
200
                                    *mcapi_status = request->mcapi_status;
201
 
202
                                    ret_val = MCAPI_TRUE;
203
                                }
204
 
205
                                /* The endpoint has not been connected. */
206
                                else
207
                                {
208
                                    *mcapi_status = MCAPI_PENDING;
209
                                }
210
 
211
                                break;
212
 
213
                            case MCAPI_REQ_RX_OPEN:
214
 
215
                                /* If the endpoint is open for receive. */
216
                                if ( (endp_ptr) &&
217
                                     (endp_ptr->mcapi_state & MCAPI_ENDP_RX) &&
218
                                     (endp_ptr->mcapi_state & MCAPI_ENDP_CONNECTED) )
219
                                {
220
                                    /* Set the status to success. */
221
                                    *mcapi_status = request->mcapi_status =
222
                                        MCAPI_SUCCESS;
223
 
224
                                    ret_val = MCAPI_TRUE;
225
                                }
226
 
227
                                /* The endpoint is not open for receive. */
228
                                else
229
                                {
230
                                    *mcapi_status = MCAPI_PENDING;
231
                                }
232
 
233
                                break;
234
 
235
                            case MCAPI_REQ_CLOSED:
236
 
237
                                /* If the endpoint is disconnected. */
238
                                if ( (endp_ptr) &&
239
                                     (endp_ptr->mcapi_state & MCAPI_ENDP_DISCONNECTED) )
240
                                {
241
                                    /* Set the status to success. */
242
                                    *mcapi_status = request->mcapi_status =
243
                                        MCAPI_SUCCESS;
244
 
245
                                    ret_val = MCAPI_TRUE;
246
                                }
247
 
248
                                /* The endpoint is not open for receive. */
249
                                else
250
                                {
251
                                    *mcapi_status = MCAPI_PENDING;
252
                                }
253
 
254
                                break;
255
 
256
                            case MCAPI_REQ_TX_OPEN:
257
 
258
                                /* If the endpoint is open for transmit. */
259
                                if ( (endp_ptr) &&
260
                                     (endp_ptr->mcapi_state & MCAPI_ENDP_TX) &&
261
                                     (endp_ptr->mcapi_state & MCAPI_ENDP_CONNECTED) )
262
                                {
263
                                    /* Set the status to success. */
264
                                    *mcapi_status = request->mcapi_status =
265
                                        MCAPI_SUCCESS;
266
 
267
                                    ret_val = MCAPI_TRUE;
268
                                }
269
 
270
                                /* The endpoint is not open for transmit. */
271
                                else
272
                                {
273
                                    *mcapi_status = MCAPI_PENDING;
274
                                }
275
 
276
                                break;
277
 
278
                            default:
279
 
280
                                *mcapi_status = MCAPI_ERR_REQUEST_INVALID;
281
                                break;
282
                        }
283
                    }
284
                }
285
 
286
                /* The size parameter is invalid. */
287
                else
288
                {
289
                    *mcapi_status = MCAPI_ERR_PARAMETER;
290
                }
291
            }
292
 
293
            /* The request has been canceled. */
294
            else
295
            {
296
                *mcapi_status = MCAPI_ERR_REQUEST_CANCELLED;
297
            }
298
        }
299
 
300
        /* The request parameter is invalid. */
301
        else
302
        {
303
            *mcapi_status = MCAPI_ERR_REQUEST_INVALID;
304
        }
305
    }
306
 
307
    return (ret_val);
308
 
309
}
310
 
311
/*************************************************************************
312
*
313
*   FUNCTION
314
*
315
*       mcapi_test
316
*
317
*   DESCRIPTION
318
*
319
*       Non-blocking API routine to check if a specified non-blocking
320
*       routine has completed.  If the specified operation is a send
321
*       or receive operation, the number of bytes sent/received will
322
*       be returned.
323
*
324
*   INPUTS
325
*
326
*       *request                A pointer to the request structure filled
327
*                               in by the specific operation being tested
328
*                               for completion.
329
*       *size                   A pointer to memory that will be filled in
330
*                               with the number of bytes sent/received if
331
*                               the operation in question is a send or
332
*                               receive operation.
333
*       *mcapi_status           A pointer to memory that will be filled in
334
*                               with the status of the call.
335
*
336
*   OUTPUTS
337
*
338
*       MCAPI_TRUE              The operation has completed.
339
*       MCAPI_FALSE             The operation has not completed or an
340
*                               error has occurred.
341
*
342
*************************************************************************/
343
mcapi_boolean_t mcapi_test(mcapi_request_t *request, size_t *size,
344
                           mcapi_status_t *mcapi_status)
345
{
346
    mcapi_boolean_t rc;
347
 
348
    mcapi_lock_node_data();
349
    rc = __mcapi_test(request, size, mcapi_status);
350
    mcapi_unlock_node_data();
351
 
352
    return rc;
353
}

powered by: WebSVN 2.1.0

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