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/] [scal_rcv.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
/*************************************************************************
35
*
36
*   FUNCTION
37
*
38
*       scal_rcv
39
*
40
*   DESCRIPTION
41
*
42
*       Receive a scalar over a connected channel.
43
*
44
*   INPUTS
45
*
46
*       receive_handle          The local handle that is receiving the data.
47
*       *scalar                 A pointer to memory that will be filled with
48
*                               the received scalar.
49
*       type                    The type of scalar to be received; u64, u32,
50
*                               u16, u8.
51
*       *mcapi_status           A pointer to memory that will be filled in
52
*                               with the status of the call.
53
*
54
*   OUTPUTS
55
*
56
*       None.
57
*
58
*************************************************************************/
59
void scal_rcv(mcapi_sclchan_recv_hndl_t receive_handle, MCAPI_SCALAR *scalar,
60
              mcapi_uint8_t type, mcapi_status_t *mcapi_status)
61
{
62
    MCAPI_GLOBAL_DATA   *node_data;
63
    MCAPI_ENDPOINT      *rx_endp_ptr;
64
    mcapi_port_t        port_id;
65
    mcapi_node_t        node_id;
66
    MCAPI_BUFFER        *rx_buf = MCAPI_NULL;
67
    mcapi_request_t     request;
68
 
69
    /* Validate the incoming status parameter. */
70
    if (mcapi_status)
71
    {
72
        /* Lock the global data structure. */
73
        mcapi_lock_node_data();
74
 
75
        /* Get a pointer to the global node list. */
76
        node_data = mcapi_get_node_data();
77
 
78
        /* Get a pointer to the endpoint that is sending data. */
79
        rx_endp_ptr = mcapi_decode_local_endpoint(node_data, &node_id,
80
                                                  &port_id, receive_handle,
81
                                                  mcapi_status);
82
 
83
        /* Ensure the receive endpoint is valid. */
84
        if (*mcapi_status == MCAPI_SUCCESS)
85
        {
86
            /* Ensure this is a receive handle. */
87
            if (rx_endp_ptr->mcapi_state & MCAPI_ENDP_RX)
88
            {
89
                /* Ensure this is a scalar channel. */
90
                if (rx_endp_ptr->mcapi_chan_type == MCAPI_CHAN_SCAL_TYPE)
91
                {
92
                    /* If the endpoint is still connected and there is no data
93
                     * on the endpoint.
94
                     */
95
                    if ( (rx_endp_ptr->mcapi_state & MCAPI_ENDP_CONNECTED) &&
96
                         (!rx_endp_ptr->mcapi_rx_queue.head) )
97
                    {
98
                        /* Initialize the request structure. */
99
                        mcapi_init_request(&request, MCAPI_REQ_RX_FIN);
100
 
101
                        /* Set up the request structure. */
102
                        request.mcapi_target_endp = receive_handle;
103
                        request.mcapi_chan_type = MCAPI_CHAN_SCAL_TYPE;
104
 
105
                        MCAPI_Suspend_Task(node_data, &request, &request.mcapi_cond,
106
                                           MCAPI_TIMEOUT_INFINITE);
107
 
108
                        /* Set the status. */
109
                        *mcapi_status = request.mcapi_status;
110
                    }
111
 
112
                    /* Check if there is data on the endpoint. */
113
                    if (rx_endp_ptr->mcapi_rx_queue.head)
114
                    {
115
                        /* Set the status to success. */
116
                        *mcapi_status = MCAPI_SUCCESS;
117
 
118
                        /* Get a pointer to the head of the queue. */
119
                        rx_buf = rx_endp_ptr->mcapi_rx_queue.head;
120
 
121
                        /* Remove the MCAPI header from the packet. */
122
                        rx_buf->buf_size -= MCAPI_HEADER_LEN;
123
 
124
                        switch (type)
125
                        {
126
                            case MCAPI_SCALAR_UINT8:
127
 
128
                                /* Ensure there are 8-bits of data waiting. */
129
                                if (rx_buf->buf_size == sizeof(mcapi_uint8_t))
130
                                {
131
                                    /* Get the 8-bits from the packet in native
132
                                     * order.
133
                                     */
134
                                    scalar->mcapi_scal.scal_uint8 =
135
                                        MCAPI_GET8(rx_buf->buf_ptr, MCAPI_HEADER_LEN);
136
                                }
137
 
138
                                /* The application is using the wrong scalar
139
                                 * receive routine to retrieve this data.
140
                                 */
141
                                else
142
                                {
143
                                    *mcapi_status = MCAPI_ERR_GENERAL;
144
                                }
145
 
146
                                break;
147
 
148
                            case MCAPI_SCALAR_UINT16:
149
 
150
                                /* Ensure there are 16-bits of data waiting. */
151
                                if (rx_buf->buf_size == sizeof(mcapi_uint16_t))
152
                                {
153
                                    /* Get the 16-bits from the packet in native
154
                                     * order.
155
                                     */
156
                                    scalar->mcapi_scal.scal_uint16 =
157
                                        MCAPI_GET16(rx_buf->buf_ptr, MCAPI_HEADER_LEN);
158
                                }
159
 
160
                                /* The application is using the wrong scalar
161
                                 * receive routine to retrieve this data.
162
                                 */
163
                                else
164
                                {
165
                                    *mcapi_status = MCAPI_ERR_GENERAL;
166
                                }
167
 
168
                                break;
169
 
170
                            case MCAPI_SCALAR_UINT32:
171
 
172
                                /* Ensure there are 32-bits of data waiting. */
173
                                if (rx_buf->buf_size == sizeof(mcapi_uint32_t))
174
                                {
175
                                    /* Get the 32-bits from the packet in native
176
                                     * order.
177
                                     */
178
                                    scalar->mcapi_scal.scal_uint32 =
179
                                        MCAPI_GET32(rx_buf->buf_ptr, MCAPI_HEADER_LEN);
180
                                }
181
 
182
                                /* The application is using the wrong scalar
183
                                 * receive routine to retrieve this data.
184
                                 */
185
                                else
186
                                {
187
                                    *mcapi_status = MCAPI_ERR_GENERAL;
188
                                }
189
 
190
                                break;
191
 
192
                            case MCAPI_SCALAR_UINT64:
193
 
194
                                /* Ensure there are 64-bits of data waiting. */
195
                                if (rx_buf->buf_size == sizeof(mcapi_uint64_t))
196
                                {
197
                                    /* Get the 64-bits from the packet in native
198
                                     * order.
199
                                     */
200
                                    scalar->mcapi_scal.scal_uint64 =
201
                                        MCAPI_GET64(rx_buf->buf_ptr, MCAPI_HEADER_LEN);
202
                                }
203
 
204
                                /* The application is using the wrong scalar
205
                                 * receive routine to retrieve this data.
206
                                 */
207
                                else
208
                                {
209
                                    *mcapi_status = MCAPI_ERR_GENERAL;
210
                                }
211
 
212
                                break;
213
 
214
                            default:
215
 
216
                                /* This can never happen. */
217
                                break;
218
                        }
219
 
220
                        /* Put the buffer back on the free list. */
221
                        if (*mcapi_status != MCAPI_ERR_GENERAL)
222
                        {
223
                            /* Remove the buffer from the receive queue. */
224
                            rx_buf = mcapi_dequeue(&rx_endp_ptr->mcapi_rx_queue);
225
 
226
                            /* Free the buffer. */
227
                            ((MCAPI_INTERFACE*)(rx_buf->mcapi_dev_ptr))->
228
                                mcapi_recover_buffer(rx_buf);
229
                        }
230
                    }
231
 
232
                    /* If the endpoint is no longer connected. */
233
                    else if (!(rx_endp_ptr->mcapi_state & MCAPI_ENDP_CONNECTED))
234
                    {
235
                        *mcapi_status = MCAPI_ERR_CHAN_INVALID;
236
                    }
237
                }
238
 
239
                /* The channel is a packet channel. */
240
                else
241
                {
242
                    *mcapi_status = MCAPI_ERR_CHAN_TYPE;
243
                }
244
            }
245
 
246
            /* Attempting to receive on a send handle. */
247
            else if (rx_endp_ptr->mcapi_state & MCAPI_ENDP_TX)
248
            {
249
                *mcapi_status = MCAPI_ERR_CHAN_DIRECTION;
250
            }
251
 
252
            /* The receive side has been closed. */
253
            else
254
            {
255
                *mcapi_status = MCAPI_ERR_CHAN_INVALID;
256
            }
257
        }
258
 
259
        else if (*mcapi_status == MCAPI_ERR_ENDP_INVALID)
260
        {
261
            *mcapi_status = MCAPI_ERR_CHAN_INVALID;
262
        }
263
 
264
        /* Unlock the global data structure. */
265
        mcapi_unlock_node_data();
266
    }
267
 
268
}

powered by: WebSVN 2.1.0

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