@@ -57,8 +57,6 @@ architecture RTL of UART2WBM is
57
57
58
58
begin
59
59
60
- WB_CYC <= '1' ;
61
-
62
60
process (CLK)
63
61
begin
64
62
if (rising_edge (CLK)) then
@@ -104,11 +102,12 @@ begin
104
102
addr_next <= addr_reg;
105
103
dout_next <= dout_reg;
106
104
WB_STB <= '0' ;
105
+ WB_CYC <= '0' ;
107
106
uart_din <= cmd_reg;
108
107
uart_din_vld <= '0' ;
109
108
110
109
case fsm_pstate is
111
- when cmd =>
110
+ when cmd => -- idle and read request cmd from UART
112
111
cmd_next <= uart_dout;
113
112
114
113
if (uart_dout_vld = '1' ) then
@@ -117,7 +116,7 @@ begin
117
116
fsm_nstate <= cmd;
118
117
end if ;
119
118
120
- when addr_low =>
119
+ when addr_low => -- read low bits of address from UART
121
120
addr_next(7 downto 0 ) <= uart_dout;
122
121
123
122
if (uart_dout_vld = '1' ) then
@@ -126,20 +125,20 @@ begin
126
125
fsm_nstate <= addr_low;
127
126
end if ;
128
127
129
- when addr_high =>
128
+ when addr_high => -- read high bits of address from UART
130
129
addr_next(15 downto 8 ) <= uart_dout;
131
130
132
131
if (uart_dout_vld = '1' ) then
133
132
if (cmd_reg(0 ) = '1' ) then
134
- fsm_nstate <= dout0;
133
+ fsm_nstate <= dout0; -- write cmd
135
134
else
136
- fsm_nstate <= request; -- read request
135
+ fsm_nstate <= request; -- read cmd
137
136
end if ;
138
137
else
139
138
fsm_nstate <= addr_high;
140
139
end if ;
141
140
142
- when dout0 =>
141
+ when dout0 => -- read data byte 0 from UART (write cmd only)
143
142
dout_next(7 downto 0 ) <= uart_dout;
144
143
145
144
if (uart_dout_vld = '1' ) then
@@ -148,7 +147,7 @@ begin
148
147
fsm_nstate <= dout0;
149
148
end if ;
150
149
151
- when dout1 =>
150
+ when dout1 => -- read data byte 1 from UART (write cmd only)
152
151
dout_next(15 downto 8 ) <= uart_dout;
153
152
154
153
if (uart_dout_vld = '1' ) then
@@ -157,7 +156,7 @@ begin
157
156
fsm_nstate <= dout1;
158
157
end if ;
159
158
160
- when dout2 =>
159
+ when dout2 => -- read data byte 2 from UART (write cmd only)
161
160
dout_next(23 downto 16 ) <= uart_dout;
162
161
163
162
if (uart_dout_vld = '1' ) then
@@ -166,7 +165,7 @@ begin
166
165
fsm_nstate <= dout2;
167
166
end if ;
168
167
169
- when dout3 =>
168
+ when dout3 => -- read data byte 3 from UART (write cmd only)
170
169
dout_next(31 downto 24 ) <= uart_dout;
171
170
172
171
if (uart_dout_vld = '1' ) then
@@ -175,37 +174,40 @@ begin
175
174
fsm_nstate <= dout3;
176
175
end if ;
177
176
178
- when request =>
177
+ when request => -- send WR or RD request to Wishbone bus
179
178
WB_STB <= '1' ; -- request is valid
179
+ WB_CYC <= '1' ;
180
180
181
181
if (WB_STALL = '0' ) then
182
182
fsm_nstate <= wait4ack;
183
183
else
184
184
fsm_nstate <= request;
185
185
end if ;
186
186
187
- when wait4ack =>
187
+ when wait4ack => -- wait for ACK on Wishbone bus
188
+ WB_CYC <= '1' ;
189
+
188
190
if (WB_ACK = '1' ) then
189
191
fsm_nstate <= response;
190
192
else
191
193
fsm_nstate <= wait4ack;
192
194
end if ;
193
195
194
- when response =>
196
+ when response => -- send response cmd to UART
195
197
uart_din <= cmd_reg;
196
198
uart_din_vld <= '1' ;
197
199
198
200
if (uart_din_rdy = '1' ) then
199
201
if (cmd_reg(0 ) = '1' ) then
200
- fsm_nstate <= cmd;
202
+ fsm_nstate <= cmd; -- idle or new read request cmd (write cmd only)
201
203
else
202
- fsm_nstate <= din0;
204
+ fsm_nstate <= din0; -- send read data to UART (read cmd only)
203
205
end if ;
204
206
else
205
207
fsm_nstate <= response;
206
208
end if ;
207
209
208
- when din0 =>
210
+ when din0 => -- send read data byte 0 to UART (read cmd only)
209
211
uart_din <= din_reg(7 downto 0 );
210
212
uart_din_vld <= '1' ;
211
213
@@ -215,7 +217,7 @@ begin
215
217
fsm_nstate <= din0;
216
218
end if ;
217
219
218
- when din1 =>
220
+ when din1 => -- send read data byte 1 to UART (read cmd only)
219
221
uart_din <= din_reg(15 downto 8 );
220
222
uart_din_vld <= '1' ;
221
223
@@ -225,7 +227,7 @@ begin
225
227
fsm_nstate <= din1;
226
228
end if ;
227
229
228
- when din2 =>
230
+ when din2 => -- send read data byte 2 to UART (read cmd only)
229
231
uart_din <= din_reg(23 downto 16 );
230
232
uart_din_vld <= '1' ;
231
233
@@ -235,7 +237,7 @@ begin
235
237
fsm_nstate <= din2;
236
238
end if ;
237
239
238
- when din3 =>
240
+ when din3 => -- send read data byte 3 to UART (read cmd only)
239
241
uart_din <= din_reg(31 downto 24 );
240
242
uart_din_vld <= '1' ;
241
243
0 commit comments