Line 48... |
Line 48... |
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
//
|
//
|
// CVS Revision History
|
// CVS Revision History
|
//
|
//
|
// $Log: not supported by cvs2svn $
|
// $Log: not supported by cvs2svn $
|
|
// Revision 1.13 2003/06/11 14:21:35 mohor
|
|
// When switching to tx, sync stage is overjumped.
|
|
//
|
// Revision 1.12 2003/02/14 20:17:01 mohor
|
// Revision 1.12 2003/02/14 20:17:01 mohor
|
// Several registers added. Not finished, yet.
|
// Several registers added. Not finished, yet.
|
//
|
//
|
// Revision 1.11 2003/02/09 18:40:29 mohor
|
// Revision 1.11 2003/02/09 18:40:29 mohor
|
// Overload fixed. Hard synchronization also enabled at the last bit of
|
// Overload fixed. Hard synchronization also enabled at the last bit of
|
Line 174... |
Line 177... |
reg clk_en;
|
reg clk_en;
|
reg sync_blocked;
|
reg sync_blocked;
|
reg resync_blocked;
|
reg resync_blocked;
|
reg sampled_bit;
|
reg sampled_bit;
|
reg sampled_bit_q;
|
reg sampled_bit_q;
|
reg [7:0] quant_cnt;
|
reg [4:0] quant_cnt;
|
reg [3:0] delay;
|
reg [3:0] delay;
|
reg sync;
|
reg sync;
|
reg seg1;
|
reg seg1;
|
reg seg2;
|
reg seg2;
|
reg resync_latched;
|
reg resync_latched;
|
reg sample_point;
|
reg sample_point;
|
reg [1:0] sample;
|
reg [1:0] sample;
|
|
reg go_sync;
|
|
|
wire go_sync;
|
wire go_sync_unregistered;
|
wire go_seg1;
|
wire go_seg1;
|
wire go_seg2;
|
wire go_seg2;
|
wire [8:0] preset_cnt;
|
wire [8:0] preset_cnt;
|
wire sync_window;
|
wire sync_window;
|
wire resync;
|
wire resync;
|
|
wire quant_cnt_rst1;
|
|
wire quant_cnt_rst2;
|
|
|
|
|
|
|
assign preset_cnt = (baud_r_presc + 1'b1)<<1; // (BRP+1)*2
|
assign preset_cnt = (baud_r_presc + 1'b1)<<1; // (BRP+1)*2
|
assign hard_sync = (rx_idle | last_bit_of_inter) & (~rx) & sampled_bit & (~sync_blocked) & (~transmitting); // Hard synchronization
|
assign hard_sync = (rx_idle | last_bit_of_inter) & (~rx) & sampled_bit & (~sync_blocked) & (~transmitting); // Hard synchronization
|
assign resync = (~rx_idle) & (~rx) & sampled_bit & (~sync_blocked) & (~resync_blocked) & (~transmitting); // Re-synchronization
|
assign resync = (~rx_idle) & (~rx) & sampled_bit & (~sync_blocked) & (~resync_blocked) & (~transmitting); // Re-synchronization
|
Line 201... |
Line 208... |
/* Generating general enable signal that defines baud rate. */
|
/* Generating general enable signal that defines baud rate. */
|
always @ (posedge clk or posedge rst)
|
always @ (posedge clk or posedge rst)
|
begin
|
begin
|
if (rst)
|
if (rst)
|
clk_cnt <= 0;
|
clk_cnt <= 0;
|
else if (clk_cnt == (preset_cnt-1))
|
else if (clk_cnt == (preset_cnt-1'b1))
|
clk_cnt <=#Tp 0;
|
clk_cnt <=#Tp 0;
|
else
|
else
|
clk_cnt <=#Tp clk_cnt + 1;
|
clk_cnt <=#Tp clk_cnt + 1'b1;
|
end
|
end
|
|
|
|
|
always @ (posedge clk or posedge rst)
|
always @ (posedge clk or posedge rst)
|
begin
|
begin
|
if (rst)
|
if (rst)
|
clk_en <= 1'b0;
|
clk_en <= 1'b0;
|
else if (clk_cnt == (preset_cnt-1))
|
else if (clk_cnt == (preset_cnt-1'b1))
|
clk_en <=#Tp 1'b1;
|
clk_en <=#Tp 1'b1;
|
else
|
else
|
clk_en <=#Tp 1'b0;
|
clk_en <=#Tp 1'b0;
|
end
|
end
|
|
|
|
|
|
|
/* Changing states */
|
/* Changing states */
|
assign go_sync = clk_en & (seg2 & (~hard_sync) & (~resync) & ((quant_cnt == time_segment2)));
|
assign go_sync_unregistered = clk_en & (seg2 & (~hard_sync) & (~resync) & ((quant_cnt[2:0] == time_segment2)));
|
assign go_seg1 = clk_en & (sync | hard_sync | (resync & seg2 & sync_window) | (resync_latched & sync_window));
|
assign go_seg1 = clk_en & (sync | hard_sync | (resync & seg2 & sync_window) | (resync_latched & sync_window));
|
assign go_seg2 = clk_en & (seg1 & (~hard_sync) & (quant_cnt == (time_segment1 + delay)));
|
assign go_seg2 = clk_en & (seg1 & (~hard_sync) & (quant_cnt == (time_segment1 + delay)));
|
|
|
|
|
|
|
|
always @ (posedge clk or posedge rst)
|
|
begin
|
|
if (rst)
|
|
go_sync <= 1'b0;
|
|
else
|
|
go_sync <=#Tp go_sync_unregistered;
|
|
end
|
|
|
|
|
/* When early edge is detected outside of the SJW field, synchronization request is latched and performed when
|
/* When early edge is detected outside of the SJW field, synchronization request is latched and performed when
|
SJW is reached */
|
SJW is reached */
|
always @ (posedge clk or posedge rst)
|
always @ (posedge clk or posedge rst)
|
begin
|
begin
|
if (rst)
|
if (rst)
|
Line 248... |
Line 264... |
begin
|
begin
|
if (rst)
|
if (rst)
|
sync <= 0;
|
sync <= 0;
|
else if (go_sync)
|
else if (go_sync)
|
sync <=#Tp 1'b1;
|
sync <=#Tp 1'b1;
|
else if (go_seg1)
|
else
|
sync <=#Tp 1'b0;
|
sync <=#Tp 1'b0;
|
end
|
end
|
|
|
|
|
assign tx_point = go_sync;
|
assign tx_point = go_sync;
|
Line 280... |
Line 296... |
seg2 <=#Tp 1'b0;
|
seg2 <=#Tp 1'b0;
|
end
|
end
|
|
|
|
|
/* Quant counter */
|
/* Quant counter */
|
|
|
|
assign quant_cnt_rst1 = go_sync | go_seg1 & (~overjump_sync_seg) | go_seg2;
|
|
assign quant_cnt_rst2 = go_seg1 & overjump_sync_seg;
|
always @ (posedge clk or posedge rst)
|
always @ (posedge clk or posedge rst)
|
begin
|
begin
|
if (rst)
|
if (rst)
|
quant_cnt <= 0;
|
quant_cnt <= 0;
|
else if (go_sync | go_seg1 & (~overjump_sync_seg) | go_seg2)
|
else if (quant_cnt_rst1)
|
quant_cnt <=#Tp 0;
|
quant_cnt <=#Tp 0;
|
else if (go_seg1 & overjump_sync_seg)
|
else if (quant_cnt_rst2)
|
quant_cnt <=#Tp 1;
|
quant_cnt <=#Tp 1;
|
else if (clk_en)
|
else if (clk_en)
|
quant_cnt <=#Tp quant_cnt + 1'b1;
|
quant_cnt <=#Tp quant_cnt + 1'b1;
|
end
|
end
|
|
|
Line 299... |
Line 318... |
always @ (posedge clk or posedge rst)
|
always @ (posedge clk or posedge rst)
|
begin
|
begin
|
if (rst)
|
if (rst)
|
delay <= 0;
|
delay <= 0;
|
else if (clk_en & resync & seg1)
|
else if (clk_en & resync & seg1)
|
delay <=#Tp (quant_cnt > sync_jump_width)? (sync_jump_width + 1) : (quant_cnt + 1);
|
delay <=#Tp (quant_cnt > {3'h0, sync_jump_width})? (sync_jump_width + 1'b1) : (quant_cnt + 1'b1);
|
else if (go_sync | go_seg1)
|
else if (go_sync | go_seg1)
|
delay <=#Tp 0;
|
delay <=#Tp 0;
|
end
|
end
|
|
|
|
|
// If early edge appears within this window (in seg2 stage), phase error is fully compensated
|
// If early edge appears within this window (in seg2 stage), phase error is fully compensated
|
assign sync_window = ((time_segment2 - quant_cnt) < ( sync_jump_width + 1));
|
assign sync_window = ((time_segment2 - quant_cnt[2:0]) < ( sync_jump_width + 1'b1));
|
|
|
|
|
// Sampling data (memorizing two samples all the time).
|
// Sampling data (memorizing two samples all the time).
|
always @ (posedge clk or posedge rst)
|
always @ (posedge clk or posedge rst)
|
begin
|
begin
|
Line 356... |
Line 375... |
sync_blocked <=#Tp 1'b0;
|
sync_blocked <=#Tp 1'b0;
|
else if (clk_en)
|
else if (clk_en)
|
begin
|
begin
|
if (hard_sync | resync)
|
if (hard_sync | resync)
|
sync_blocked <=#Tp 1'b1;
|
sync_blocked <=#Tp 1'b1;
|
else if (seg2 & quant_cnt == time_segment2)
|
else if (seg2 & (quant_cnt[2:0] == time_segment2))
|
sync_blocked <=#Tp 1'b0;
|
sync_blocked <=#Tp 1'b0;
|
end
|
end
|
end
|
end
|
|
|
|
|