-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemux.v
154 lines (114 loc) · 2.63 KB
/
demux.v
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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 23:12:00 11/23/2020
// Design Name:
// Module Name: demux
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
`define RESET 100
//`define PREPARE_OUTPUT_DATA 150
`define OUTPUT_DATA 200
`define caesar 0
`define scytale 1
`define zigzag 2
module demux #(
parameter MST_DWIDTH = 32,
parameter SYS_DWIDTH = 8
)(
// Clock and reset interface
input clk_sys,
input clk_mst,
input rst_n,
//Select interface
input[1:0] select,
// Input interface
input [MST_DWIDTH -1 : 0] data_i,
input valid_i,
//output interfaces
output reg [SYS_DWIDTH - 1 : 0] data0_o,
output reg valid0_o,
output reg [SYS_DWIDTH - 1 : 0] data1_o,
output reg valid1_o,
output reg [SYS_DWIDTH - 1 : 0] data2_o,
output reg valid2_o
);
reg[MST_DWIDTH - 1 : 0] data_mst;
reg valid_i_mst;
reg[7 : 0] state, next_state;
//reg[7 : 0] counter = 0;
reg[7 : 0] i, i_next;
always @(posedge clk_mst) begin
// latch pe intrari
data_mst <= data_i;
valid_i_mst <= valid_i;
state <= next_state;
if(~rst_n) begin
state <= `RESET;
end
end
// Trecere la urmatorul cuvant de 8 biti de afisat
always @(posedge clk_sys) begin
i <= i_next;
end
always @(*) begin
// Reinitializare valori la inceput
valid0_o = 0;
valid1_o = 0;
valid2_o = 0;
data0_o = 0;
data1_o = 0;
data2_o = 0;
case(state)
`RESET: begin
i_next = 3;
valid0_o = 0;
valid1_o = 0;
valid2_o = 0;
data0_o = 0;
data1_o = 0;
data2_o = 0;
next_state = `OUTPUT_DATA;
end
`OUTPUT_DATA: begin
if(valid_i_mst) begin
// Selectare output line
case(select)
`caesar: begin
valid0_o = 1;
data0_o = data_mst[SYS_DWIDTH * i +: 8];
i_next = i - 1;
end
`scytale: begin
valid1_o = 1;
data1_o = data_mst[SYS_DWIDTH * i +: 8];
i_next = i - 1;
end
`zigzag: begin
valid2_o = 1;
data2_o = data_mst[SYS_DWIDTH * i +: 8];
i_next = i - 1;
end
endcase
if(i == 0) begin
next_state = `OUTPUT_DATA;
// Reinitializare i_next
i_next = 3;
end
end
end
endcase
end
endmodule