1 |
145 |
lanttu |
/*
|
2 |
|
|
Copyright (c) 2008, The Multicore Association
|
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
|
7 |
|
|
met:
|
8 |
|
|
|
9 |
|
|
(1) Redistributions of source code must retain the above copyright
|
10 |
|
|
notice, this list of conditions and the following disclaimer.
|
11 |
|
|
|
12 |
|
|
(2) Redistributions in binary form must reproduce the above copyright
|
13 |
|
|
notice, this list of conditions and the following disclaimer in the
|
14 |
|
|
documentation and/or other materials provided with the distribution.
|
15 |
|
|
|
16 |
|
|
(3) Neither the name of the Multicore Association nor the names of its
|
17 |
|
|
contributors may be used to endorse or promote products derived from
|
18 |
|
|
this software without specific prior written permission.
|
19 |
|
|
|
20 |
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
21 |
|
|
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
22 |
|
|
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
23 |
|
|
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
24 |
|
|
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
25 |
|
|
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
26 |
|
|
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
27 |
|
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
28 |
|
|
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
29 |
|
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
30 |
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31 |
|
|
*/
|
32 |
|
|
|
33 |
|
|
// **************************************************************************
|
34 |
|
|
// File : transport_nios.h
|
35 |
|
|
// Author : Lauri Matilainen
|
36 |
|
|
// Date : 17.09.2010
|
37 |
|
|
// Decription : FUNCAPI transport layer implementation for NIOS II
|
38 |
|
|
// (modified from The Multicore Association example
|
39 |
|
|
// shared memory implementation)
|
40 |
|
|
// Version history : 17.09.2005 Lauri Matilainen 1st mod version
|
41 |
|
|
//
|
42 |
|
|
//
|
43 |
|
|
//
|
44 |
|
|
//
|
45 |
|
|
// **************************************************************************
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
#ifndef _TRANSPORT_NIOS_H_
|
50 |
|
|
#define _TRANSPORT_NIOS_H_
|
51 |
|
|
|
52 |
|
|
#include "mcapi_datatypes.h"
|
53 |
|
|
#include "mcapi_config.h"
|
54 |
|
|
|
55 |
|
|
#include <stdarg.h> /* for va_list */
|
56 |
|
|
#include <stdio.h> /* for the inlined dprintf routine */
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
/*******************************************************************
|
60 |
|
|
definitions and constants
|
61 |
|
|
*******************************************************************/
|
62 |
|
|
/* the debug level */
|
63 |
|
|
extern int mcapi_debug;
|
64 |
|
|
|
65 |
|
|
/* we leave one empty element so that the array implementation
|
66 |
|
|
can tell the difference between empty and full */
|
67 |
|
|
|
68 |
|
|
#define MAX_QUEUE_ENTRIES (MAX_QUEUE_ELEMENTS + 1)
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
/*******************************************************************
|
72 |
|
|
mcapi_trans data types
|
73 |
|
|
*******************************************************************/
|
74 |
|
|
/* buffer entry is used for msgs, pkts and scalars */
|
75 |
|
|
/* NOTE: if you change the buffer_entry data structure then you also
|
76 |
|
|
need to update the pointer arithmetic in mcapi_trans_pktchan_free */
|
77 |
|
|
typedef struct {
|
78 |
|
|
uint32_t magic_num;
|
79 |
|
|
uint32_t size; /* size (in bytes) of the buffer */
|
80 |
|
|
mcapi_boolean_t in_use;
|
81 |
|
|
char buff [MAX_PKT_SIZE];
|
82 |
|
|
uint64_t scalar;
|
83 |
|
|
} buffer_entry;
|
84 |
|
|
|
85 |
|
|
typedef struct {
|
86 |
|
|
mcapi_request_t* request; /* holds a reservation for an outstanding receive request */
|
87 |
|
|
buffer_entry* b; /* the pointer to the actual buffer entry in the buffer pool */
|
88 |
|
|
mcapi_boolean_t invalid;
|
89 |
|
|
} buffer_descriptor;
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
typedef struct {
|
93 |
|
|
mcapi_boolean_t valid;
|
94 |
|
|
uint16_t attribute_num;
|
95 |
|
|
uint32_t bytes;
|
96 |
|
|
void* attribute_d;
|
97 |
|
|
} attribute_entry;
|
98 |
|
|
|
99 |
|
|
typedef struct {
|
100 |
|
|
/* the next 3 data members are only valid for channels */
|
101 |
|
|
mcapi_endpoint_t send_endpt;
|
102 |
|
|
mcapi_endpoint_t recv_endpt;
|
103 |
|
|
uint8_t channel_type;
|
104 |
|
|
|
105 |
|
|
uint32_t num_elements;
|
106 |
|
|
uint16_t head;
|
107 |
|
|
uint16_t tail;
|
108 |
|
|
buffer_descriptor elements[MAX_QUEUE_ENTRIES+1];
|
109 |
|
|
}queue;
|
110 |
|
|
|
111 |
|
|
|
112 |
|
|
typedef struct {
|
113 |
|
|
uint32_t port_num;
|
114 |
|
|
mcapi_boolean_t valid;
|
115 |
|
|
mcapi_boolean_t anonymous;
|
116 |
|
|
mcapi_boolean_t open;
|
117 |
|
|
mcapi_boolean_t connected;
|
118 |
|
|
uint32_t num_attributes;
|
119 |
|
|
attribute_entry attributes [MAX_ATTRIBUTES];
|
120 |
|
|
queue recv_queue;
|
121 |
|
|
} endpoint_entry;
|
122 |
|
|
|
123 |
|
|
typedef struct {
|
124 |
|
|
uint16_t num_endpoints;
|
125 |
|
|
endpoint_entry endpoints[MAX_ENDPOINTS];
|
126 |
|
|
} node_descriptor;
|
127 |
|
|
|
128 |
|
|
typedef struct {
|
129 |
|
|
uint32_t node_num;
|
130 |
|
|
mcapi_boolean_t finalized;
|
131 |
|
|
mcapi_boolean_t valid;
|
132 |
|
|
node_descriptor node_d;
|
133 |
|
|
} node_entry;
|
134 |
|
|
|
135 |
|
|
|
136 |
|
|
typedef struct {
|
137 |
|
|
uint16_t num_nodes;
|
138 |
|
|
node_entry nodes[MAX_NODES];
|
139 |
|
|
buffer_entry buffers [MAX_BUFFERS];
|
140 |
|
|
} mcapi_database;
|
141 |
|
|
|
142 |
|
|
|
143 |
|
|
/* debug printing */
|
144 |
|
|
/* Inline this (and define in header) so that it can be compiled out if WITH_DEBUG is 0 */
|
145 |
|
|
inline void mcapi_dprintf(int level,const char *format, ...) {
|
146 |
|
|
if (WITH_DEBUG) {
|
147 |
|
|
va_list ap;
|
148 |
|
|
va_start(ap,format);
|
149 |
|
|
if (level <= mcapi_debug){
|
150 |
|
|
printf("MCAPI_DEBUG:");
|
151 |
|
|
/* call variatic printf */
|
152 |
|
|
vprintf(format,ap);
|
153 |
|
|
}
|
154 |
|
|
va_end(ap);
|
155 |
|
|
}
|
156 |
|
|
}
|
157 |
|
|
|
158 |
|
|
|
159 |
|
|
|
160 |
|
|
#endif
|