-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbitstream_packets.h
More file actions
175 lines (144 loc) · 4.89 KB
/
bitstream_packets.h
File metadata and controls
175 lines (144 loc) · 4.89 KB
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
/*
* Copyright (C) 2006, 2007 Jean-Baptiste Note <jean-baptiste.note@m4x.org>
*
* This file is part of debit.
*
* Debit is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Debit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with debit. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _BITSTREAM_PACKETS_H
#define _BITSTREAM_PACKETS_H
/*
* V1 packet type
*/
typedef struct {
unsigned word_count :11;
unsigned __rsvd :2;
unsigned reg_addr :14;
unsigned rd :1;
unsigned wr :1;
unsigned type :3;
} v2_packet1_t;
#define V1_PKT_WORDC_OFFSET 0
#define V1_PKT_WORDC_LEN 11
#define V1_PKT_WORDC_MASK ((1<<V1_PKT_WORDC_LEN) - 1) << V1_PKT_WORDC_OFFSET
#define V1_PKT_RSVD_OFFSET (V1_PKT_WORDC_OFFSET + V1_PKT_WORDC_LEN)
#define V1_PKT_RSVD_LEN 2
#define V1_PKT_RSVD_MASK ((1<<V1_PKT_RSVD_LEN) - 1) << V1_PKT_RSVD_OFFSET
#define V1_PKT_REGA_OFFSET (V1_PKT_RSVD_OFFSET + V1_PKT_RSVD_LEN)
#define V1_PKT_REGA_LEN 14
#define V1_PKT_REGA_MASK ((1<<V1_PKT_REGA_LEN) - 1) << V1_PKT_REGA_OFFSET
#define V1_PKT_RD_OFFSET (V1_PKT_REGA_OFFSET + V1_PKT_REGA_LEN)
#define V1_PKT_RD_LEN 1
#define V1_PKT_RD_MASK ((1<<V1_PKT_RD_LEN) - 1) << V1_PKT_RD_OFFSET
#define V1_PKT_WR_OFFSET (V1_PKT_RD_OFFSET + V1_PKT_RD_LEN)
#define V1_PKT_WR_LEN 1
#define V1_PKT_WR_MASK ((1<<V1_PKT_WR_LEN) - 1) << V1_PKT_WR_OFFSET
#define V1_PKT_TYPE_OFFSET (V1_PKT_WR_OFFSET + V1_PKT_WR_LEN)
#define V1_PKT_TYPE_LEN 3
#define V1_PKT_TYPE_MASK ((1<<V1_PKT_TYPE_LEN) - 1) << V1_PKT_TYPE_OFFSET
static inline unsigned
wordc_of_pkt1(const uint32_t pkt1) {
return (pkt1 & V1_PKT_WORDC_MASK) >> V1_PKT_WORDC_OFFSET;
}
static inline unsigned
rsvd_of_pkt1(const uint32_t pkt1) {
return (pkt1 & V1_PKT_RSVD_MASK) >> V1_PKT_RSVD_OFFSET;
}
static inline unsigned
rega_of_pkt1(const uint32_t pkt1) {
return (pkt1 & V1_PKT_REGA_MASK) >> V1_PKT_REGA_OFFSET;
}
static inline unsigned
rd_of_pkt1(const uint32_t pkt1) {
return (pkt1 & V1_PKT_RD_MASK) >> V1_PKT_RD_OFFSET;
}
static inline unsigned
wr_of_pkt1(const uint32_t pkt1) {
return (pkt1 & V1_PKT_WR_MASK) >> V1_PKT_WR_OFFSET;
}
static inline unsigned
type_of_pkt1(const uint32_t pkt1) {
return (pkt1 & V1_PKT_TYPE_MASK) >> V1_PKT_TYPE_OFFSET;
}
/*
* V2 packet type
*/
typedef struct {
unsigned word_count :27;
unsigned rd :1;
unsigned wr :1;
unsigned type :3;
} v2_packet2_t;
#define V2_PKT_WORDC_OFFSET 0
#define V2_PKT_WORDC_LEN 27
#define V2_PKT_WORDC_MASK ((1<<V2_PKT_WORDC_LEN) - 1) << V2_PKT_WORDC_OFFSET
#define V2_PKT_WR_OFFSET (V2_PKT_WORDC_OFFSET + V2_PKT_WORDC_LEN)
#define V2_PKT_WR_LEN 1
#define V2_PKT_WR_MASK ((1<<V2_PKT_WR_LEN) - 1) << V2_PKT_WR_OFFSET
#define V2_PKT_RD_OFFSET (V2_PKT_WR_OFFSET + V2_PKT_WR_LEN)
#define V2_PKT_RD_LEN 1
#define V2_PKT_RD_MASK ((1<<V2_PKT_RD_LEN) - 1) << V2_PKT_RD_OFFSET
#define V2_PKT_TYPE_OFFSET (V2_PKT_RD_OFFSET + V2_PKT_RD_LEN)
#define V2_PKT_TYPE_LEN 3
#define V2_PKT_TYPE_MASK ((1<<V2_PKT_TYPE_LEN) - 1) << V2_PKT_TYPE_OFFSET
static inline unsigned
wordc_of_v2pkt(const uint32_t v2pkt) {
return (v2pkt & V2_PKT_WORDC_MASK) >> V2_PKT_WORDC_OFFSET;
}
static inline unsigned
rd_of_v2pkt(const uint32_t v2pkt) {
return (v2pkt & V2_PKT_RD_MASK) >> V2_PKT_RD_OFFSET;
}
static inline unsigned
wr_of_v2pkt(const uint32_t v2pkt) {
return (v2pkt & V2_PKT_WR_MASK) >> V2_PKT_WR_OFFSET;
}
static inline unsigned
type_of_v2pkt(const uint32_t v2pkt) {
return (v2pkt & V2_PKT_TYPE_MASK) >> V2_PKT_TYPE_OFFSET;
}
typedef enum _cmd_pkt_ver {
TYPE_V1 = 1, TYPE_V2 = 2,
} cmd_pkt_ver_t;
typedef enum _special_words {
SYNCHRO_0 = 0x000000BBU,
SYNCHRO_1 = 0x11220044U,
SYNCHRO = 0xAA995566U,
NOOP = 0x20000000U,
NULLPKT = 0x00000000U,
} special_word_t;
typedef struct _xil_register {
guint32 value;
} xil_register_t;
/* Building packets */
static inline uint32_t
build_pkt2(const unsigned wordc, const unsigned rd, const unsigned wr) {
return (
((TYPE_V2 << V2_PKT_TYPE_OFFSET) & V2_PKT_TYPE_MASK) |
((wr << V2_PKT_WR_OFFSET) & V2_PKT_WR_MASK) |
((rd << V2_PKT_RD_OFFSET) & V2_PKT_RD_MASK) |
((wordc << V2_PKT_WORDC_OFFSET) & V2_PKT_WORDC_MASK)
);
}
static inline uint32_t
build_pkt1(const unsigned wordc, const unsigned rega, const unsigned rd, const unsigned wr) {
return (
((TYPE_V1 << V1_PKT_TYPE_OFFSET) & V1_PKT_TYPE_MASK) |
((wr << V1_PKT_WR_OFFSET) & V1_PKT_WR_MASK) |
((rd << V1_PKT_RD_OFFSET) & V1_PKT_RD_MASK) |
((rega << V1_PKT_REGA_OFFSET) & V1_PKT_REGA_MASK) |
((wordc << V1_PKT_WORDC_OFFSET) & V1_PKT_WORDC_MASK)
);
}
#endif /* _BITSTREAM_PACKETS_H */