Skip to content

Commit 81eddbd

Browse files
author
Sebastien Bourdeauducq
committedNov 23, 2011
softusb: new DPLL
1 parent 4c22685 commit 81eddbd

File tree

1 file changed

+35
-17
lines changed

1 file changed

+35
-17
lines changed
 

‎cores/softusb/rtl/softusb_rx.v

+35-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Milkymist SoC
3-
* Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
3+
* Copyright (C) 2007, 2008, 2009, 2010, 2011 Sebastien Bourdeauducq
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -105,26 +105,44 @@ always @(*) begin
105105
end
106106

107107
/* DPLL */
108-
reg rx_r;
109-
always @(posedge usb_clk)
110-
rx_r <= rx;
111-
wire transition = (rx != rx_r);
108+
reg [2:0] div8_counter;
109+
reg div8_ce;
110+
initial div8_counter <= 3'd0;
111+
always @(posedge usb_clk) begin
112+
div8_counter <= div8_counter + 3'd1;
113+
div8_ce <= div8_counter == 3'd0;
114+
end
115+
116+
wire speed_ce = ~low_speed | div8_ce;
117+
118+
reg [3:0] dpll_state;
119+
reg [3:0] dpll_next_state;
112120

113-
reg [4:0] dpll_counter;
114-
reg dpll_ce;
115121
always @(posedge usb_clk) begin
116-
if(rxreset) begin
117-
dpll_counter <= 5'd0;
118-
dpll_ce <= 1'b0;
119-
end else begin
120-
if(transition)
121-
dpll_counter <= 5'd0;
122-
else
123-
dpll_counter <= dpll_counter + 5'd1;
124-
dpll_ce <= low_speed ? (dpll_counter == 5'd13) : (transition|(dpll_counter[1:0] == 2'd3));
125-
end
122+
if(rxreset)
123+
dpll_state <= 4'h5;
124+
else if(speed_ce)
125+
dpll_state <= dpll_next_state;
126126
end
127127

128+
always @(*) begin
129+
dpll_next_state = dpll_state;
130+
case(dpll_state)
131+
4'h5: dpll_next_state = 4'h7;
132+
4'h7: if( rx_corrected) dpll_next_state = 4'h6; else dpll_next_state = 4'hb;
133+
4'h6: if( rx_corrected) dpll_next_state = 4'h4; else dpll_next_state = 4'h1;
134+
4'h4: if( rx_corrected) dpll_next_state = 4'h5; else dpll_next_state = 4'h1;
135+
4'h1: dpll_next_state = 4'h3;
136+
4'h3: if(~rx_corrected) dpll_next_state = 4'h2; else dpll_next_state = 4'hf;
137+
4'h2: if(~rx_corrected) dpll_next_state = 4'h0; else dpll_next_state = 4'h5;
138+
4'h0: if(~rx_corrected) dpll_next_state = 4'h1; else dpll_next_state = 4'h5;
139+
4'hb: dpll_next_state = 4'h2;
140+
4'hf: dpll_next_state = 4'h6;
141+
endcase
142+
end
143+
144+
wire dpll_ce = speed_ce & (dpll_next_state[1] & ~dpll_state[1]);
145+
128146
/* Serial->Parallel converter */
129147

130148
reg [2:0] bitcount;

0 commit comments

Comments
 (0)