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_snd.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_send
39
*
40
*   DESCRIPTION
41
*
42
*       Send a scalar over a connected channel.  Called by both
43
*       blocking and non-blocking transmission routines.
44
*
45
*   INPUTS
46
*
47
*       send_handle             The transmission handle.
48
*       *buffer                 A pointer to the data to transmit.
49
*       type                    The type of scalar to transmit.
50
*       *mcapi_status           A pointer to memory that will be filled in
51
*                               with the status of the call.
52
*
53
*   OUTPUTS
54
*
55
*       None.
56
*
57
*************************************************************************/
58
void scal_send(mcapi_pktchan_send_hndl_t send_handle, MCAPI_SCALAR *buffer,
59
               mcapi_uint8_t type, mcapi_status_t *mcapi_status)
60
{
61
    mcapi_port_t        port_id;
62
    mcapi_node_t        node_id;
63
    MCAPI_GLOBAL_DATA   *node_data;
64
    MCAPI_ENDPOINT      *tx_endp_ptr = MCAPI_NULL;
65
    MCAPI_BUFFER        *tx_buf;
66
 
67
    if (mcapi_status)
68
    {
69
        /* Lock the global data structure. */
70
        mcapi_lock_node_data();
71
 
72
        /* Get a pointer to the global node list. */
73
        node_data = mcapi_get_node_data();
74
 
75
        /* Get a pointer to the endpoint that is sending data. */
76
        tx_endp_ptr = mcapi_decode_local_endpoint(node_data, &node_id,
77
                                                  &port_id, send_handle,
78
                                                  mcapi_status);
79
 
80
        /* Ensure the transmit endpoint is valid. */
81
        if (*mcapi_status == MCAPI_SUCCESS)
82
        {
83
            /* Ensure the handle is open for sending. */
84
            if ( (tx_endp_ptr->mcapi_state & MCAPI_ENDP_TX) &&
85
                 (tx_endp_ptr->mcapi_state & MCAPI_ENDP_CONNECTED) )
86
            {
87
                /* Ensure the handle is for a scalar channel. */
88
                if (tx_endp_ptr->mcapi_chan_type == MCAPI_CHAN_SCAL_TYPE)
89
                {
90
                    /* Get a transmission buffer for tracking when the outgoing
91
                     * data has been successfully sent.
92
                     */
93
                    tx_buf = tx_endp_ptr->mcapi_route->mcapi_rt_int->
94
                        mcapi_get_buffer(tx_endp_ptr->mcapi_foreign_node_id,
95
                                         sizeof(mcapi_uint64_t) + MCAPI_HEADER_LEN,
96
                                         tx_endp_ptr->mcapi_priority);
97
 
98
                    if (tx_buf)
99
                    {
100
                        /* Save a pointer to the tx interface. */
101
                        tx_buf->mcapi_dev_ptr =
102
                            (MCAPI_POINTER)(tx_endp_ptr->mcapi_route->mcapi_rt_int);
103
 
104
                        /* Set the source node in the packet. */
105
                        MCAPI_PUT16(tx_buf->buf_ptr, MCAPI_SRC_NODE_OFFSET,
106
                                    tx_endp_ptr->mcapi_node_id);
107
 
108
                        /* Set the source port in the packet. */
109
                        MCAPI_PUT16(tx_buf->buf_ptr, MCAPI_SRC_PORT_OFFSET,
110
                                    tx_endp_ptr->mcapi_port_id);
111
 
112
                        /* Set the destination node in the packet. */
113
                        MCAPI_PUT16(tx_buf->buf_ptr, MCAPI_DEST_NODE_OFFSET,
114
                                    tx_endp_ptr->mcapi_foreign_node_id);
115
 
116
                        /* Set the destination port in the packet. */
117
                        MCAPI_PUT16(tx_buf->buf_ptr, MCAPI_DEST_PORT_OFFSET,
118
                                    tx_endp_ptr->mcapi_foreign_port_id);
119
 
120
                        /* Set the priority of the packet. */
121
                        MCAPI_PUT16(tx_buf->buf_ptr, MCAPI_PRIO_OFFSET,
122
                                    tx_endp_ptr->mcapi_priority);
123
 
124
                        /* Zero out the unused bits. */
125
                        MCAPI_PUT16(tx_buf->buf_ptr, MCAPI_UNUSED_OFFSET, 0);
126
 
127
                        switch (type)
128
                        {
129
                            case MCAPI_SCALAR_UINT8:
130
 
131
                                /* Put the 8-bits in the packet in network order. */
132
                                MCAPI_PUT8(tx_buf->buf_ptr, MCAPI_HEADER_LEN,
133
                                           buffer->mcapi_scal.scal_uint8);
134
 
135
                                tx_buf->buf_size = sizeof(mcapi_uint8_t);
136
 
137
                                break;
138
 
139
                            case MCAPI_SCALAR_UINT16:
140
 
141
                                /* Put the 16-bits in the packet in network order. */
142
                                MCAPI_PUT16(tx_buf->buf_ptr, MCAPI_HEADER_LEN,
143
                                            buffer->mcapi_scal.scal_uint16);
144
 
145
                                tx_buf->buf_size = sizeof(mcapi_uint16_t);
146
 
147
                                break;
148
 
149
                            case MCAPI_SCALAR_UINT32:
150
 
151
                                /* Put the 32-bits in the packet in network order. */
152
                                MCAPI_PUT32(tx_buf->buf_ptr, MCAPI_HEADER_LEN,
153
                                            buffer->mcapi_scal.scal_uint32);
154
 
155
                                tx_buf->buf_size = sizeof(mcapi_uint32_t);
156
 
157
                                break;
158
 
159
                            case MCAPI_SCALAR_UINT64:
160
 
161
                                /* Put the 64-bits in the packet in network order. */
162
                                MCAPI_PUT64(tx_buf->buf_ptr, MCAPI_HEADER_LEN,
163
                                            buffer->mcapi_scal.scal_uint64);
164
 
165
                                tx_buf->buf_size = sizeof(mcapi_uint64_t);
166
 
167
                                break;
168
 
169
                            default:
170
 
171
                                /* This can never happen. */
172
                                break;
173
                        }
174
 
175
                        /* Set the length of the data in the buffer. */
176
                        tx_buf->buf_size += MCAPI_HEADER_LEN;
177
 
178
                        /* Pass the data to the transport layer driver. */
179
                        *mcapi_status = tx_endp_ptr->mcapi_route->mcapi_rt_int->
180
                            mcapi_tx_output(tx_buf, tx_buf->buf_size,
181
                                            tx_endp_ptr->mcapi_priority,
182
                                            tx_endp_ptr);
183
 
184
                        /* If the routine cannot complete immediately. */
185
                        if (*mcapi_status != MCAPI_SUCCESS)
186
                        {
187
                            /* Return the transmission buffer to the list of
188
                             * free buffers in the system.
189
                             */
190
                            ((MCAPI_INTERFACE*)(tx_buf->mcapi_dev_ptr))->
191
                                mcapi_recover_buffer(tx_buf);
192
                        }
193
                    }
194
 
195
                    /* There are no transmission buffers available to process this
196
                     * request.
197
                     */
198
                    else
199
                    {
200
                        *mcapi_status = MCAPI_ERR_TRANSMISSION;
201
                    }
202
                }
203
 
204
                /* The handle is for a packet channel. */
205
                else
206
                {
207
                    *mcapi_status = MCAPI_ERR_CHAN_TYPE;
208
                }
209
            }
210
 
211
            /* The handle is open for receiving. */
212
            else
213
            {
214
                /* If this is a receive channel. */
215
                if (tx_endp_ptr->mcapi_state & MCAPI_ENDP_RX)
216
                {
217
                    *mcapi_status = MCAPI_ERR_CHAN_DIRECTION;
218
                }
219
 
220
                /* Otherwise, the connection has been closed. */
221
                else
222
                {
223
                    *mcapi_status = MCAPI_ERR_CHAN_INVALID;
224
                }
225
            }
226
        }
227
 
228
        else
229
        {
230
            *mcapi_status = MCAPI_ERR_CHAN_INVALID;
231
        }
232
 
233
        /* Unlock the global data structure. */
234
        mcapi_unlock_node_data();
235
    }
236
 
237
}

powered by: WebSVN 2.1.0

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