forked from pConst/basic_verilog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreverse_bytes.sv
49 lines (36 loc) · 1.21 KB
/
reverse_bytes.sv
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
//------------------------------------------------------------------------------
// reverse_bytes.sv
// Konstantin Pavlov, [email protected]
//------------------------------------------------------------------------------
// INFO ------------------------------------------------------------------------
// "Physically" reverses bytes order within multi-byte array
// Thus in[15] byte becomes out[7], in[0] becomes out[8] and vise-versa
// Module could be used to convert big-endian data to little-endian
// Module is no doubt synthesizable, but its instance does NOT occupy any FPGA resources!
/* --- INSTANTIATION TEMPLATE BEGIN ---
reverse_bytes #(
.BYTES( 2 )
) RV1 (
.in( smth[15:0] ),
.out( htms[15:0] ) // reversed byte order
);
--- INSTANTIATION TEMPLATE END ---*/
module reverse_bytes #( parameter
BYTES = 8
)(
input [(BYTES*8-1):0] in,
output logic [(BYTES*8-1):0] out
);
logic [BYTES-1:0][7:0] byte_data;
assign byte_data = in;
logic [BYTES-1:0][7:0] rev_byte_data;
genvar i;
generate
for (i = 0; i < BYTES ; i++) begin : gen_reverse
always_comb begin
rev_byte_data[i] = byte_data[(BYTES-1)-i];
end // always_comb
end // for
endgenerate
assign out = rev_byte_data;
endmodule