-
Notifications
You must be signed in to change notification settings - Fork 1
/
BlueAXI4UnixBridges.h
195 lines (184 loc) · 8.43 KB
/
BlueAXI4UnixBridges.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#ifndef BLUE_AXI4_UNIX_BRIDGES_H
#define BLUE_AXI4_UNIX_BRIDGES_H
/*-
* Copyright (c) 2022 Alexandre Joannou
* All rights reserved.
*
* This material is based upon work supported by the DoD Information Analysis
* Center Program Management Office (DoD IAC PMO), sponsored by the Defense
* Technical Information Center (DTIC) under Contract No. FA807518D0004. Any
* opinions, findings and conclusions or recommendations expressed in this
* material are those of the author(s) and do not necessarily reflect the views
* of the Air Force Installation Contracting Agency (AFICA).
*
* @BERI_LICENSE_HEADER_START@
*
* Licensed to BERI Open Systems C.I.C. (BERI) under one or more contributor
* license agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership. BERI licenses this
* file to you under the BERI Hardware-Software License, Version 1.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.beri-open-systems.org/legal/license-1-0.txt
*
* Unless required by applicable law or agreed to in writing, Work distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* @BERI_LICENSE_HEADER_END@
*/
// This header declares the BlueUnixFifo API for C client, as well as the C
// functions to be wrapped in Bluespec SystemVerilog BDPI calls for use in
// BSV simulator code.
#include <BlueUnixBridges.h>
#include "BlueAXI4UnixBridgesHelpers.h"
// An AXI4UnixFifo port descriptor
typedef struct {
bub_fifo_desc_t aw;
bub_fifo_desc_t w;
bub_fifo_desc_t b;
bub_fifo_desc_t ar;
bub_fifo_desc_t r;
} baub_port_fifo_desc_t;
// AXI4 Unix Bridges Fifo API
////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
extern "C" {
#endif
baub_port_fifo_desc_t* baub_fifo_OpenChannelsAsMaster
( char* awSrc_path, size_t awSrc_bytesize, deserializer_t awSrc_deserializer
, char* wSrc_path, size_t wSrc_bytesize, deserializer_t wSrc_deserializer
, char* bSnk_path, size_t bSnk_bytesize, serializer_t bSnk_serializer
, char* arSrc_path, size_t arSrc_bytesize, deserializer_t arSrc_deserializer
, char* rSnk_path, size_t rSnk_bytesize, serializer_t rSnk_serializer );
baub_port_fifo_desc_t* baub_fifo_OpenChannelsAsSlave
( char* awSnk_path, size_t awSnk_bytesize, serializer_t awSnk_serializer
, char* wSnk_path, size_t wSnk_bytesize, serializer_t wSnk_serializer
, char* bSrc_path, size_t bSrc_bytesize, deserializer_t bSrc_deserializer
, char* arSnk_path, size_t arSnk_bytesize, serializer_t arSnk_serializer
, char* rSrc_path, size_t rSrc_bytesize, deserializer_t rSrc_deserializer );
void baub_fifo_Close (baub_port_fifo_desc_t* desc);
#define AXI4_(IDsz,ADDRsz,DATAsz,AWsz,Wsz,Bsz,ARsz,Rsz,defId,sym) \
baub_axi4_ ## IDsz ## _ ## ADDRsz ## _ ## DATAsz ## _ \
## AWsz ## _ ## Wsz ## _ ## Bsz ## _ ## ARsz ## _ ## Rsz ## _ \
## defId ## _ ## sym
#define DEF_AXI4_API(IDsz,ADDRsz,DATAsz,AWsz,Wsz,Bsz,ARsz,Rsz,defId) \
DEF_AXI4_HEPLERS_API(IDsz,ADDRsz,DATAsz,AWsz,Wsz,Bsz,ARsz,Rsz,defId) \
baub_port_fifo_desc_t* \
AXI4_(IDsz,ADDRsz,DATAsz,AWsz,Wsz,Bsz,ARsz,Rsz,defId,fifo_OpenAsMaster) \
(char* path) { \
size_t len = strlen (path) + 10; \
char* awSrc_path = (char*) malloc (len * sizeof(char)); \
char* wSrc_path = (char*) malloc (len * sizeof(char)); \
char* bSnk_path = (char*) malloc (len * sizeof(char)); \
char* arSrc_path = (char*) malloc (len * sizeof(char)); \
char* rSnk_path = (char*) malloc (len * sizeof(char)); \
strcpy (awSrc_path, path); \
strcpy ( wSrc_path, path); \
strcpy ( bSnk_path, path); \
strcpy (arSrc_path, path); \
strcpy ( rSnk_path, path); \
strcat (awSrc_path, "/awSource"); \
strcat ( wSrc_path, "/wSource"); \
strcat ( bSnk_path, "/bSink"); \
strcat (arSrc_path, "/arSource"); \
strcat ( rSnk_path, "/rSink"); \
baub_port_fifo_desc_t* mstrDesc = baub_fifo_OpenChannelsAsMaster \
( awSrc_path, AXI4_AW_BYTEsz(IDsz,ADDRsz,AWsz) \
, &AXI4_AW_(IDsz,ADDRsz,AWsz,defId,deserialize_flit) \
, wSrc_path, AXI4_W_BYTEsz(DATAsz,Wsz), &AXI4_W_(DATAsz,Wsz,defId,deserialize_flit) \
, bSnk_path, AXI4_B_BYTEsz(IDsz,Bsz), &AXI4_B_(IDsz,Bsz,defId,serialize_flit) \
, arSrc_path, AXI4_AR_BYTEsz(IDsz,ADDRsz,ARsz) \
, &AXI4_AR_(IDsz,ADDRsz,ARsz,defId,deserialize_flit) \
, rSnk_path, AXI4_R_BYTEsz(IDsz,DATAsz,Rsz) \
, &AXI4_R_(IDsz,DATAsz,Rsz,defId,serialize_flit) ); \
printf("opened axi4 master port:\n"); \
printf( "\taw: %s, %0d bytes (from %0d bits), decoder: %p\n" \
, awSrc_path \
, AXI4_AW_BYTEsz(IDsz,ADDRsz,AWsz) \
, AXI4_AW_BITsz(IDsz,ADDRsz,AWsz) \
, &AXI4_AW_(IDsz,ADDRsz,AWsz,defId,deserialize_flit)); \
printf( "\tw: %s, %0d bytes (from %0d bits), decoder: %p\n" \
, wSrc_path \
, AXI4_W_BYTEsz(DATAsz,Wsz) \
, AXI4_W_BITsz(DATAsz,Wsz) \
, &AXI4_W_(DATAsz,Wsz,defId,deserialize_flit)); \
printf( "\tb: %s, %0d bytes (from %0d bits), encoder: %p\n" \
, bSnk_path \
, AXI4_B_BYTEsz(IDsz,Bsz) \
, AXI4_B_BITsz(IDsz,Bsz) \
, &AXI4_B_(IDsz,Bsz,defId,serialize_flit)); \
printf( "\tar: %s, %0d bytes (from %0d bits), decoder: %p\n" \
, arSrc_path \
, AXI4_AR_BYTEsz(IDsz,ADDRsz,ARsz) \
, AXI4_AR_BITsz(IDsz,ADDRsz,ARsz) \
, &AXI4_AR_(IDsz,ADDRsz,ARsz,defId,deserialize_flit)); \
printf( "\tr: %s, %0d bytes (from %0d bits), encoder: %p\n" \
, rSnk_path \
, AXI4_R_BYTEsz(IDsz,DATAsz,Rsz) \
, AXI4_R_BITsz(IDsz,DATAsz,Rsz) \
, &AXI4_R_(IDsz,DATAsz,Rsz,defId,serialize_flit)); \
return mstrDesc; \
} \
baub_port_fifo_desc_t* \
AXI4_(IDsz,ADDRsz,DATAsz,AWsz,Wsz,Bsz,ARsz,Rsz,defId,fifo_OpenAsSlave) \
(char* path) { \
size_t len = strlen (path) + 10; \
char* awSnk_path = (char*) malloc (len * sizeof(char)); \
char* wSnk_path = (char*) malloc (len * sizeof(char)); \
char* bSrc_path = (char*) malloc (len * sizeof(char)); \
char* arSnk_path = (char*) malloc (len * sizeof(char)); \
char* rSrc_path = (char*) malloc (len * sizeof(char)); \
strcpy (awSnk_path, path); \
strcpy ( wSnk_path, path); \
strcpy ( bSrc_path, path); \
strcpy (arSnk_path, path); \
strcpy ( rSrc_path, path); \
strcat (awSnk_path, "/awSink"); \
strcat ( wSnk_path, "/wSink"); \
strcat ( bSrc_path, "/bSource"); \
strcat (arSnk_path, "/arSink"); \
strcat ( rSrc_path, "/rSource"); \
baub_port_fifo_desc_t* slvDesc = baub_fifo_OpenChannelsAsSlave \
( awSnk_path, AXI4_AW_BYTEsz(IDsz,ADDRsz,AWsz) \
, &AXI4_AW_(IDsz,ADDRsz,AWsz,defId,serialize_flit) \
, wSnk_path, AXI4_W_BYTEsz(DATAsz,Wsz), &AXI4_W_(DATAsz,Wsz,defId,serialize_flit) \
, bSrc_path, AXI4_B_BYTEsz(IDsz,Bsz), &AXI4_B_(IDsz,Bsz,defId,deserialize_flit) \
, arSnk_path, AXI4_AR_BYTEsz(IDsz,ADDRsz,ARsz) \
, &AXI4_AR_(IDsz,ADDRsz,ARsz,defId,serialize_flit) \
, rSrc_path, AXI4_R_BYTEsz(IDsz,DATAsz,Rsz) \
, &AXI4_R_(IDsz,DATAsz,Rsz,defId,deserialize_flit) ); \
printf("opened axi4 slave port:\n"); \
printf( "\taw: %s, %0d bytes (from %0d bits), encoder: %p\n" \
, awSnk_path \
, AXI4_AW_BYTEsz(IDsz,ADDRsz,AWsz) \
, AXI4_AW_BITsz(IDsz,ADDRsz,AWsz) \
, &AXI4_AW_(IDsz,ADDRsz,AWsz,defId,serialize_flit)); \
printf( "\tw: %s, %0d bytes (from %0d bits), encoder: %p\n" \
, wSnk_path \
, AXI4_W_BYTEsz(DATAsz,Wsz) \
, AXI4_W_BITsz(DATAsz,Wsz) \
, &AXI4_W_(DATAsz,Wsz,defId,serialize_flit)); \
printf( "\tb: %s, %0d bytes (from %0d bits), decoder: %p\n" \
, bSrc_path \
, AXI4_B_BYTEsz(IDsz,Bsz) \
, AXI4_B_BITsz(IDsz,Bsz) \
, &AXI4_B_(IDsz,Bsz,defId,deserialize_flit)); \
printf( "\tar: %s, %0d bytes (from %0d bits), encoder: %p\n" \
, arSnk_path \
, AXI4_AR_BYTEsz(IDsz,ADDRsz,ARsz) \
, AXI4_AR_BITsz(IDsz,ADDRsz,ARsz) \
, &AXI4_AR_(IDsz,ADDRsz,ARsz,defId,serialize_flit)); \
printf( "\tr: %s, %0d bytes (from %0d bits), decoder: %p\n" \
, rSrc_path \
, AXI4_R_BYTEsz(IDsz,DATAsz,Rsz) \
, AXI4_R_BITsz(IDsz,DATAsz,Rsz) \
, &AXI4_R_(IDsz,DATAsz,Rsz,defId,deserialize_flit)); \
return slvDesc; \
}
#ifdef __cplusplus
}
#endif
#endif