Skip to content

Commit 1e894c5

Browse files
committed
[BUGFIX]: Fix WB_CYC signal and add some comments in UART2WBM
1 parent 5182cb4 commit 1e894c5

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

examples/uart2wb/uart2wbm.vhd

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ architecture RTL of UART2WBM is
5757

5858
begin
5959

60-
WB_CYC <= '1';
61-
6260
process (CLK)
6361
begin
6462
if (rising_edge(CLK)) then
@@ -104,11 +102,12 @@ begin
104102
addr_next <= addr_reg;
105103
dout_next <= dout_reg;
106104
WB_STB <= '0';
105+
WB_CYC <= '0';
107106
uart_din <= cmd_reg;
108107
uart_din_vld <= '0';
109108

110109
case fsm_pstate is
111-
when cmd =>
110+
when cmd => -- idle and read request cmd from UART
112111
cmd_next <= uart_dout;
113112

114113
if (uart_dout_vld = '1') then
@@ -117,7 +116,7 @@ begin
117116
fsm_nstate <= cmd;
118117
end if;
119118

120-
when addr_low =>
119+
when addr_low => -- read low bits of address from UART
121120
addr_next(7 downto 0) <= uart_dout;
122121

123122
if (uart_dout_vld = '1') then
@@ -126,20 +125,20 @@ begin
126125
fsm_nstate <= addr_low;
127126
end if;
128127

129-
when addr_high =>
128+
when addr_high => -- read high bits of address from UART
130129
addr_next(15 downto 8) <= uart_dout;
131130

132131
if (uart_dout_vld = '1') then
133132
if (cmd_reg(0) = '1') then
134-
fsm_nstate <= dout0;
133+
fsm_nstate <= dout0; -- write cmd
135134
else
136-
fsm_nstate <= request; -- read request
135+
fsm_nstate <= request; -- read cmd
137136
end if;
138137
else
139138
fsm_nstate <= addr_high;
140139
end if;
141140

142-
when dout0 =>
141+
when dout0 => -- read data byte 0 from UART (write cmd only)
143142
dout_next(7 downto 0) <= uart_dout;
144143

145144
if (uart_dout_vld = '1') then
@@ -148,7 +147,7 @@ begin
148147
fsm_nstate <= dout0;
149148
end if;
150149

151-
when dout1 =>
150+
when dout1 => -- read data byte 1 from UART (write cmd only)
152151
dout_next(15 downto 8) <= uart_dout;
153152

154153
if (uart_dout_vld = '1') then
@@ -157,7 +156,7 @@ begin
157156
fsm_nstate <= dout1;
158157
end if;
159158

160-
when dout2 =>
159+
when dout2 => -- read data byte 2 from UART (write cmd only)
161160
dout_next(23 downto 16) <= uart_dout;
162161

163162
if (uart_dout_vld = '1') then
@@ -166,7 +165,7 @@ begin
166165
fsm_nstate <= dout2;
167166
end if;
168167

169-
when dout3 =>
168+
when dout3 => -- read data byte 3 from UART (write cmd only)
170169
dout_next(31 downto 24) <= uart_dout;
171170

172171
if (uart_dout_vld = '1') then
@@ -175,37 +174,40 @@ begin
175174
fsm_nstate <= dout3;
176175
end if;
177176

178-
when request =>
177+
when request => -- send WR or RD request to Wishbone bus
179178
WB_STB <= '1'; -- request is valid
179+
WB_CYC <= '1';
180180

181181
if (WB_STALL = '0') then
182182
fsm_nstate <= wait4ack;
183183
else
184184
fsm_nstate <= request;
185185
end if;
186186

187-
when wait4ack =>
187+
when wait4ack => -- wait for ACK on Wishbone bus
188+
WB_CYC <= '1';
189+
188190
if (WB_ACK = '1') then
189191
fsm_nstate <= response;
190192
else
191193
fsm_nstate <= wait4ack;
192194
end if;
193195

194-
when response =>
196+
when response => -- send response cmd to UART
195197
uart_din <= cmd_reg;
196198
uart_din_vld <= '1';
197199

198200
if (uart_din_rdy = '1') then
199201
if (cmd_reg(0) = '1') then
200-
fsm_nstate <= cmd;
202+
fsm_nstate <= cmd; -- idle or new read request cmd (write cmd only)
201203
else
202-
fsm_nstate <= din0;
204+
fsm_nstate <= din0; -- send read data to UART (read cmd only)
203205
end if;
204206
else
205207
fsm_nstate <= response;
206208
end if;
207209

208-
when din0 =>
210+
when din0 => -- send read data byte 0 to UART (read cmd only)
209211
uart_din <= din_reg(7 downto 0);
210212
uart_din_vld <= '1';
211213

@@ -215,7 +217,7 @@ begin
215217
fsm_nstate <= din0;
216218
end if;
217219

218-
when din1 =>
220+
when din1 => -- send read data byte 1 to UART (read cmd only)
219221
uart_din <= din_reg(15 downto 8);
220222
uart_din_vld <= '1';
221223

@@ -225,7 +227,7 @@ begin
225227
fsm_nstate <= din1;
226228
end if;
227229

228-
when din2 =>
230+
when din2 => -- send read data byte 2 to UART (read cmd only)
229231
uart_din <= din_reg(23 downto 16);
230232
uart_din_vld <= '1';
231233

@@ -235,7 +237,7 @@ begin
235237
fsm_nstate <= din2;
236238
end if;
237239

238-
when din3 =>
240+
when din3 => -- send read data byte 3 to UART (read cmd only)
239241
uart_din <= din_reg(31 downto 24);
240242
uart_din_vld <= '1';
241243

0 commit comments

Comments
 (0)