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/] [test/] [func/] [backend.c] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
/*
2
 * Copyright (c) 2011, 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 <stdio.h>
31
#include <mcapi.h>
32
#include "fts_defs.h"
33
#include "support_suite/mcapid_support.h"
34
#include "mcapid.h"
35
 
36
MCAPID_STRUCT   MCAPID_Reg_Struct, MCAPID_Mgmt_Struct, MCAPID_Echo_Struct[4];
37
 
38
unsigned        MCAPID_Failures = 0;
39
 
40
/************************************************************************
41
*
42
*   FUNCTION
43
*
44
*       MCAPI_FTS_Msg_Server
45
*
46
*   DESCRIPTION
47
*
48
*       Listen on an endpoint for incoming messages, and echo back the
49
*       data.
50
*
51
*************************************************************************/
52
MCAPI_THREAD_ENTRY(MCAPI_FTS_Msg_Echo_Server)
53
{
54
    MCAPID_STRUCT       *mcapi_struct = (MCAPID_STRUCT*)argv;
55
    char                buffer[MCAPID_MSG_LEN];
56
    size_t              rx_len;
57
    mcapi_status_t      status;
58
 
59
    for (;;)
60
    {
61
        /* Wait for a message. */
62
        mcapi_msg_recv(mcapi_struct->local_endp, buffer, MCAPID_MSG_LEN, &rx_len,
63
                       &status);
64
 
65
        if (status == MCAPI_SUCCESS)
66
        {
67
            /* Echo the message. */
68
            mcapi_msg_send(mcapi_struct->local_endp,
69
                           mcapi_get32((unsigned char*)buffer, MCAPID_MGMT_LOCAL_ENDP_OFFSET),
70
                           buffer, MCAPID_MSG_LEN,
71
                           MCAPI_DEFAULT_PRIO, &status);
72
        }
73
    }
74
 
75
} /* MCAPI_FTS_Msg_Echo_Server */
76
 
77
/************************************************************************
78
*
79
*   FUNCTION
80
*
81
*       MCAPI_FTS_Pkt_Server
82
*
83
*   DESCRIPTION
84
*
85
*       Open the receive side of a connection, wait for a connection,
86
*       listen on an endpoint for incoming messages.
87
*
88
*************************************************************************/
89
MCAPI_THREAD_ENTRY(MCAPI_FTS_Pkt_Server)
90
{
91
    MCAPID_STRUCT               *mcapi_struct = (MCAPID_STRUCT*)argv;
92
    char                        *buffer;
93
    size_t                      rx_len;
94
 
95
    for (;;)
96
    {
97
        /* Wait for a connection to be established. */
98
        mcapi_wait(&mcapi_struct->request, &rx_len, &mcapi_struct->status,
99
                   MCAPI_TIMEOUT_INFINITE);
100
 
101
        for (;;)
102
        {
103
            /* Wait for an incoming message. */
104
            mcapi_pktchan_recv(mcapi_struct->pkt_rx_handle, (void**)&buffer,
105
                               &rx_len, &mcapi_struct->status);
106
 
107
            /* If data was received. */
108
            if (mcapi_struct->status == MCAPI_SUCCESS)
109
            {
110
                /* Free the buffer. */
111
                mcapi_pktchan_free(buffer, &mcapi_struct->status);
112
            }
113
 
114
            /* If the connection has been closed. */
115
            else
116
            {
117
                /* Close the receive side. */
118
                mcapi_packetchan_recv_close_i(mcapi_struct->pkt_rx_handle,
119
                                              &mcapi_struct->request,
120
                                              &mcapi_struct->status);
121
 
122
                break;
123
            }
124
        }
125
 
126
        /* Open the local endpoint back up as the receiver. */
127
        mcapi_open_pktchan_recv_i(&mcapi_struct->pkt_rx_handle,
128
                                  mcapi_struct->local_endp,
129
                                  &mcapi_struct->request, &mcapi_struct->status);
130
    }
131
 
132
} /* MCAPI_FTS_Pkt_Server */
133
 
134
/************************************************************************
135
*
136
*   FUNCTION
137
*
138
*       MCAPI_FTS_Scl_Server
139
*
140
*   DESCRIPTION
141
*
142
*       Open the receive side of a connection, wait for a connection,
143
*       listen on an endpoint for incoming messages.
144
*
145
*************************************************************************/
146
MCAPI_THREAD_ENTRY(MCAPI_FTS_Scl_Server)
147
{
148
    MCAPID_STRUCT   *mcapi_struct = (MCAPID_STRUCT*)argv;
149
    size_t          rx_len;
150
    char            buffer[MCAPID_MGMT_PKT_LEN];
151
    mcapi_uint32_t  type;
152
    mcapi_uint64_t  recv_64;
153
    mcapi_uint32_t  recv_32;
154
    mcapi_uint16_t  recv_16;
155
    mcapi_uint8_t   recv_8;
156
    mcapi_status_t  status;
157
 
158
    for (;;)
159
    {
160
        /* Wait for a message indicating the type of receive to perform. */
161
        mcapi_msg_recv(mcapi_struct->local_endp, buffer, MCAPID_MGMT_PKT_LEN,
162
                       &rx_len, &mcapi_struct->status);
163
 
164
        if (mcapi_struct->status == MCAPI_SUCCESS)
165
        {
166
            type = mcapi_get32((unsigned char*)buffer, MCAPID_MGMT_TYPE_OFFSET);
167
 
168
            /* Check the receive type to ensure it is valid. */
169
            if ( (type == MCAPID_RX_64_BIT_SCL) ||
170
                 (type == MCAPID_RX_32_BIT_SCL) ||
171
                 (type == MCAPID_RX_16_BIT_SCL) ||
172
                 (type == MCAPID_RX_8_BIT_SCL) )
173
            {
174
                /* Send a successful status. */
175
                status = MCAPI_SUCCESS;
176
            }
177
 
178
            else
179
            {
180
                /* Send an error, but continue with opening the receive
181
                 * side and closing in case the other side wants to send
182
                 * data over a closed connection.
183
                 */
184
                status = -1;
185
            }
186
 
187
            /* Put the status in the packet. */
188
            mcapi_put32((unsigned char*)buffer, MCAPID_MGMT_STATUS_OFFSET, status);
189
 
190
            /* Send the response. */
191
            mcapi_msg_send(mcapi_struct->local_endp,
192
                           mcapi_get32((unsigned char*)buffer, MCAPID_MGMT_LOCAL_ENDP_OFFSET),
193
                           buffer, rx_len, MCAPI_DEFAULT_PRIO,
194
                           &mcapi_struct->status);
195
 
196
            /* Open the local endpoint up as the receiver. */
197
            mcapi_open_sclchan_recv_i(&mcapi_struct->scl_rx_handle,
198
                                      mcapi_struct->local_endp,
199
                                      &mcapi_struct->request,
200
                                      &mcapi_struct->status);
201
 
202
            /* Wait for a connection to be established. */
203
            mcapi_wait(&mcapi_struct->request, &rx_len, &mcapi_struct->status,
204
                       MCAPI_TIMEOUT_INFINITE);
205
 
206
            if (mcapi_struct->status == MCAPI_SUCCESS)
207
            {
208
                switch (type)
209
                {
210
                    case MCAPID_RX_64_BIT_SCL:
211
 
212
                        /* Wait for an incoming message. */
213
                        recv_64 = mcapi_sclchan_recv_uint64(mcapi_struct->scl_rx_handle,
214
                                                            &mcapi_struct->status);
215
 
216
                        if ( (mcapi_struct->status == MCAPI_SUCCESS) &&
217
                             (recv_64 != MCAPI_FTS_64BIT_SCALAR) )
218
                        {
219
                            MCAPID_Failures ++;
220
                        }
221
 
222
                        /* Close the receive side. */
223
                        mcapi_sclchan_recv_close_i(mcapi_struct->scl_rx_handle,
224
                                                   &mcapi_struct->request,
225
                                                   &mcapi_struct->status);
226
 
227
                        break;
228
 
229
                    case MCAPID_RX_32_BIT_SCL:
230
 
231
                        /* Wait for an incoming message. */
232
                        recv_32 = mcapi_sclchan_recv_uint32(mcapi_struct->scl_rx_handle,
233
                                                            &mcapi_struct->status);
234
 
235
                        if ( (mcapi_struct->status == MCAPI_SUCCESS) &&
236
                             (recv_32 != MCAPI_FTS_32BIT_SCALAR) )
237
                        {
238
                            MCAPID_Failures ++;
239
                        }
240
 
241
                        /* Close the receive side. */
242
                        mcapi_sclchan_recv_close_i(mcapi_struct->scl_rx_handle,
243
                                                   &mcapi_struct->request,
244
                                                   &mcapi_struct->status);
245
 
246
                        break;
247
 
248
                    case MCAPID_RX_16_BIT_SCL:
249
 
250
                        /* Wait for an incoming message. */
251
                        recv_16 = mcapi_sclchan_recv_uint16(mcapi_struct->scl_rx_handle,
252
                                                            &mcapi_struct->status);
253
 
254
                        if ( (mcapi_struct->status == MCAPI_SUCCESS) &&
255
                             (recv_16 != MCAPI_FTS_16BIT_SCALAR) )
256
                        {
257
                            MCAPID_Failures ++;
258
                        }
259
 
260
                        /* Close the receive side. */
261
                        mcapi_sclchan_recv_close_i(mcapi_struct->scl_rx_handle,
262
                                                   &mcapi_struct->request,
263
                                                   &mcapi_struct->status);
264
 
265
                        break;
266
 
267
                    case MCAPID_RX_8_BIT_SCL:
268
 
269
                        /* Wait for an incoming message. */
270
                        recv_8 = mcapi_sclchan_recv_uint8(mcapi_struct->scl_rx_handle,
271
                                                          &mcapi_struct->status);
272
 
273
                        if ( (mcapi_struct->status == MCAPI_SUCCESS) &&
274
                             (recv_8 != MCAPI_FTS_8BIT_SCALAR) )
275
                        {
276
                            MCAPID_Failures ++;
277
                        }
278
 
279
                        /* Close the receive side. */
280
                        mcapi_sclchan_recv_close_i(mcapi_struct->scl_rx_handle,
281
                                                   &mcapi_struct->request,
282
                                                   &mcapi_struct->status);
283
 
284
                        break;
285
 
286
                    default:
287
 
288
                        /* Close the receive side. */
289
                        mcapi_sclchan_recv_close_i(mcapi_struct->scl_rx_handle,
290
                                                   &mcapi_struct->request,
291
                                                   &mcapi_struct->status);
292
 
293
                        break;
294
                }
295
 
296
                /* Put the status in the packet. */
297
                mcapi_put32((unsigned char*)buffer, MCAPID_MGMT_STATUS_OFFSET, mcapi_struct->status);
298
 
299
                /* Send the response. */
300
                mcapi_msg_send(mcapi_struct->local_endp,
301
                               mcapi_get32((unsigned char*)buffer, MCAPID_MGMT_LOCAL_ENDP_OFFSET),
302
                               buffer, rx_len, MCAPI_DEFAULT_PRIO,
303
                               &mcapi_struct->status);
304
            }
305
 
306
            else
307
            {
308
                /* Close the receive side. */
309
                mcapi_sclchan_recv_close_i(mcapi_struct->scl_rx_handle,
310
                                           &mcapi_struct->request,
311
                                           &mcapi_struct->status);
312
            }
313
        }
314
    }
315
 
316
} /* MCAPI_FTS_Scl_Server */
317
 
318
#ifdef LCL_MGMT_UNBROKEN
319
/************************************************************************
320
*
321
*   FUNCTION
322
*
323
*       MCAPI_FTS_Local_Services
324
*
325
*   DESCRIPTION
326
*
327
*       This function processes incoming packets instructing the node
328
*       to create an endpoint, delete an endpoint, etc.
329
*
330
*************************************************************************/
331
MCAPI_THREAD_ENTRY(MCAPI_FTS_Local_Services)
332
{
333
    size_t          rx_len;
334
    MCAPID_STRUCT   *mcapi_struct = (MCAPID_STRUCT*)argv;
335
    char            buffer[MCAPID_MGMT_PKT_LEN];
336
 
337
    for (;;)
338
    {
339
        /* Wait for a message. */
340
        mcapi_msg_recv(mcapi_struct->local_endp, buffer, MCAPID_MGMT_PKT_LEN,
341
                       &rx_len, &mcapi_struct->status);
342
 
343
        if (mcapi_struct->status == MCAPI_SUCCESS)
344
        {
345
            /* Sleep the appropriate amount of time - this gives the other side
346
             * time to issue a command before the management task causes an
347
             * action.
348
             */
349
            MCAPID_Sleep(mcapi_get32((unsigned char*)buffer, MCAPID_MGMT_PAUSE_OFFSET));
350
 
351
            /* Determine the type of message. */
352
            switch (mcapi_get32((unsigned char*)buffer, MCAPID_MGMT_TYPE_OFFSET))
353
            {
354
                case MCAPID_CANCEL_REQUEST:
355
 
356
                    /* Cancel the pending local request. */
357
                    mcapi_cancel((mcapi_request_t*)(mcapi_get32((unsigned char*)buffer, MCAPID_MGMT_STATUS_OFFSET)),
358
                                 &mcapi_struct->status);
359
 
360
                    break;
361
 
362
                case MCAPID_WAIT_REQUEST:
363
 
364
                    /* Wait for the specified request. */
365
                    mcapi_wait((mcapi_request_t*)(mcapi_get32((unsigned char*)buffer, MCAPID_MGMT_STATUS_OFFSET)),
366
                               &rx_len, &mcapi_struct->status, MCAPI_TIMEOUT_INFINITE);
367
 
368
                    break;
369
 
370
                default:
371
 
372
                    mcapi_struct->status = -1;
373
                    break;
374
            }
375
 
376
            /* Put the status in the packet. */
377
            mcapi_put32((unsigned char*)buffer, MCAPID_MGMT_STATUS_OFFSET, mcapi_struct->status);
378
 
379
            /* Send the response using the specified priority. */
380
            mcapi_msg_send(mcapi_struct->local_endp,
381
                           mcapi_get32((unsigned char*)buffer, MCAPID_MGMT_LOCAL_ENDP_OFFSET),
382
                           buffer, rx_len, mcapi_get32((unsigned char*)buffer, MCAPID_MGMT_PRIO_OFFSET),
383
                           &mcapi_struct->status);
384
        }
385
    }
386
 
387
} /* MCAPI_FTS_Local_Services */
388
#endif
389
 
390
int mcapi_test_start(int argc, char *argv[])
391
{
392
    mcapi_status_t status;
393
    mcapi_version_t version;
394
 
395
    /* Initialize MCAPI on the node. */
396
    mcapi_initialize(FUNC_BACKEND_NODE_ID, &version, &status);
397
 
398
    /* If an error occurred, the demo has failed. */
399
    if (status != MCAPI_SUCCESS) {
400
        printf("%s\n", "mcapi_initialize() failed!");
401
        MCAPID_Failures++;
402
        goto out;
403
    }
404
 
405
    /* Start the registration server. */
406
    MCAPID_Create_Thread(&MCAPID_Registration_Server, &MCAPID_Reg_Struct);
407
 
408
    /* Let the registration server come up. */
409
    MCAPID_Sleep(2000);
410
 
411
    /* The management service. */
412
    MCAPID_Mgmt_Struct.type = MCAPI_MSG_RX_TYPE;
413
    MCAPID_Mgmt_Struct.node = FUNC_BACKEND_NODE_ID;
414
    MCAPID_Mgmt_Struct.local_port = MCAPI_PORT_ANY;
415
    MCAPID_Mgmt_Struct.service = "mgmt_svc";
416
    MCAPID_Mgmt_Struct.thread_entry = MCAPID_Mgmt_Service;
417
    MCAPID_Create_Service(&MCAPID_Mgmt_Struct);
418
 
419
    /* The message echo service. */
420
    MCAPID_Echo_Struct[0].type = MCAPI_MSG_RX_TYPE;
421
    MCAPID_Echo_Struct[0].node = FUNC_BACKEND_NODE_ID;
422
    MCAPID_Echo_Struct[0].local_port = MCAPI_PORT_ANY;
423
    MCAPID_Echo_Struct[0].service = "msg_echo_svr";
424
    MCAPID_Echo_Struct[0].thread_entry = MCAPI_FTS_Msg_Echo_Server;
425
    MCAPID_Create_Service(&MCAPID_Echo_Struct[0]);
426
 
427
    /* The packet discard service. */
428
    MCAPID_Echo_Struct[1].type = MCAPI_CHAN_PKT_RX_TYPE;
429
    MCAPID_Echo_Struct[1].node = FUNC_BACKEND_NODE_ID;
430
    MCAPID_Echo_Struct[1].local_port = MCAPI_PORT_ANY;
431
    MCAPID_Echo_Struct[1].service = "pkt_svr";
432
    MCAPID_Echo_Struct[1].thread_entry = MCAPI_FTS_Pkt_Server;
433
    MCAPID_Create_Service(&MCAPID_Echo_Struct[1]);
434
 
435
    /* The scalar discard service. */
436
    MCAPID_Echo_Struct[2].type = MCAPI_MSG_RX_TYPE;
437
    MCAPID_Echo_Struct[2].node = FUNC_BACKEND_NODE_ID;
438
    MCAPID_Echo_Struct[2].local_port = MCAPI_PORT_ANY;
439
    MCAPID_Echo_Struct[2].service = "scl_svr";
440
    MCAPID_Echo_Struct[2].thread_entry = MCAPI_FTS_Scl_Server;
441
    MCAPID_Create_Service(&MCAPID_Echo_Struct[2]);
442
 
443
#ifdef LCL_MGMT_UNBROKEN
444
    /* The local services service. */
445
    MCAPID_Echo_Struct[3].type = MCAPI_MSG_RX_TYPE;
446
    MCAPID_Echo_Struct[3].node = FUNC_BACKEND_NODE_ID;
447
    MCAPID_Echo_Struct[3].local_port = MCAPI_PORT_ANY;
448
    MCAPID_Echo_Struct[3].service = "lcl_mgmt";
449
    MCAPID_Echo_Struct[3].thread_entry = MCAPI_FTS_Local_Services;
450
    MCAPID_Create_Service(&MCAPID_Echo_Struct[3]);
451
#endif
452
 
453
    while (1); /* XXX */
454
 
455
out:
456
    return MCAPID_Failures;
457
}

powered by: WebSVN 2.1.0

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