Line 43... |
Line 43... |
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
//
|
//
|
// CVS Revision History
|
// CVS Revision History
|
//
|
//
|
// $Log: not supported by cvs2svn $
|
// $Log: not supported by cvs2svn $
|
|
// Revision 1.5 2002/12/27 00:12:52 mohor
|
|
// Header changed, testbench improved to send a frame (crc still missing).
|
|
//
|
// Revision 1.4 2002/12/26 01:33:05 mohor
|
// Revision 1.4 2002/12/26 01:33:05 mohor
|
// Tripple sampling supported.
|
// Tripple sampling supported.
|
//
|
//
|
// Revision 1.3 2002/12/25 23:44:16 mohor
|
// Revision 1.3 2002/12/25 23:44:16 mohor
|
// Commented lines removed.
|
// Commented lines removed.
|
Line 70... |
Line 73... |
clk,
|
clk,
|
rst,
|
rst,
|
rx,
|
rx,
|
|
|
/* Mode register */
|
/* Mode register */
|
reset_mode, // Not used !!!
|
reset_mode,
|
|
|
/* Bus Timing 0 register */
|
/* Bus Timing 0 register */
|
baud_r_presc,
|
baud_r_presc,
|
sync_jump_width,
|
sync_jump_width,
|
|
|
Line 82... |
Line 85... |
time_segment1,
|
time_segment1,
|
time_segment2,
|
time_segment2,
|
triple_sampling,
|
triple_sampling,
|
|
|
/* Output signals from this module */
|
/* Output signals from this module */
|
take_sample,
|
|
clk_en,
|
clk_en,
|
|
sample_point,
|
|
sampled_bit,
|
|
sampled_bit_q,
|
|
|
|
/* Output from can_bsp module */
|
|
rx_idle
|
|
|
/* States */
|
|
idle
|
|
|
|
|
|
|
|
);
|
);
|
|
|
Line 110... |
Line 116... |
/* Bus Timing 1 register */
|
/* Bus Timing 1 register */
|
input [3:0] time_segment1;
|
input [3:0] time_segment1;
|
input [2:0] time_segment2;
|
input [2:0] time_segment2;
|
input triple_sampling;
|
input triple_sampling;
|
|
|
|
/* Output from can_bsp module */
|
|
input rx_idle;
|
|
|
/* Output signals from this module */
|
/* Output signals from this module */
|
output take_sample; // NOT USED, YET
|
|
output clk_en;
|
output clk_en;
|
|
output sample_point;
|
|
output sampled_bit;
|
|
output sampled_bit_q;
|
|
|
input idle;
|
|
|
|
|
|
reg [8:0] clk_cnt;
|
reg [8:0] clk_cnt;
|
reg clk_en;
|
reg clk_en;
|
reg sync_blocked;
|
reg sync_blocked;
|
reg sampled_bit;
|
reg sampled_bit;
|
|
reg sampled_bit_q;
|
reg [7:0] quant_cnt;
|
reg [7: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_pulse;
|
reg sample_point;
|
reg [1:0] sample;
|
reg [1:0] sample;
|
|
|
wire go_sync;
|
wire go_sync;
|
wire go_seg1;
|
wire go_seg1;
|
wire go_seg2;
|
wire go_seg2;
|
Line 141... |
Line 152... |
wire sync_window;
|
wire sync_window;
|
|
|
|
|
|
|
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 = idle & (~rx) & sampled_bit & (~sync_blocked); // Hard synchronization
|
assign hard_sync = rx_idle & (~rx) & sampled_bit & (~sync_blocked); // Hard synchronization
|
assign resync = (~idle) & (~rx) & sampled_bit & (~sync_blocked); // Re-synchronization
|
assign resync = (~rx_idle) & (~rx) & sampled_bit & (~sync_blocked); // Re-synchronization
|
|
|
|
|
/* 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)
|
begin
|
|
clk_cnt <= 0;
|
clk_cnt <= 0;
|
clk_en <= 1'b0;
|
else if (clk_cnt == (preset_cnt-1) | reset_mode)
|
|
clk_cnt <=#Tp 0;
|
|
else
|
|
clk_cnt <=#Tp clk_cnt + 1;
|
end
|
end
|
else if (clk_cnt == (preset_cnt-1))
|
|
|
|
|
always @ (posedge clk or posedge rst)
|
begin
|
begin
|
clk_cnt <=#Tp 0;
|
if (rst)
|
|
clk_en <= 1'b0;
|
|
else if (clk_cnt == (preset_cnt-1))
|
clk_en <=#Tp 1'b1;
|
clk_en <=#Tp 1'b1;
|
end
|
|
else
|
else
|
begin
|
|
clk_cnt <=#Tp clk_cnt + 1;
|
|
clk_en <=#Tp 1'b0;
|
clk_en <=#Tp 1'b0;
|
end
|
end
|
end
|
|
|
|
|
|
|
|
/* Changing states */
|
/* Changing states */
|
//assign go_sync = clk_en & (seg2 & (~resync) & ((quant_cnt == time_segment2)));
|
assign go_sync = clk_en & (seg2 & (~hard_sync) & (~resync) & ((quant_cnt == time_segment2)));
|
assign go_sync = clk_en & (seg2 & ((quant_cnt == 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 & (quant_cnt == (time_segment1 + delay)));
|
assign go_seg2 = clk_en & (seg1 & (~hard_sync) & (quant_cnt == (time_segment1 + delay)));
|
|
|
|
|
|
|
/* 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)
|
Line 192... |
Line 205... |
|
|
/* Synchronization stage/segment */
|
/* Synchronization stage/segment */
|
always @ (posedge clk or posedge rst)
|
always @ (posedge clk or posedge rst)
|
begin
|
begin
|
if (rst)
|
if (rst)
|
sync <= 1;
|
sync <= 0;
|
else if (go_sync)
|
else if (go_sync)
|
sync <=#Tp 1'b1;
|
sync <=#Tp 1'b1;
|
else if (go_seg1)
|
else if (go_seg1)
|
sync <=#Tp 1'b0;
|
sync <=#Tp 1'b0;
|
end
|
end
|
Line 204... |
Line 217... |
|
|
/* Seg1 stage/segment (together with propagation segment which is 1 quant long) */
|
/* Seg1 stage/segment (together with propagation segment which is 1 quant long) */
|
always @ (posedge clk or posedge rst)
|
always @ (posedge clk or posedge rst)
|
begin
|
begin
|
if (rst)
|
if (rst)
|
seg1 <= 0;
|
seg1 <= 1;
|
else if (go_seg1)
|
else if (go_seg1)
|
seg1 <=#Tp 1'b1;
|
seg1 <=#Tp 1'b1;
|
else if (go_seg2)
|
else if (go_seg2)
|
seg1 <=#Tp 1'b0;
|
seg1 <=#Tp 1'b0;
|
end
|
end
|
Line 268... |
Line 281... |
always @ (posedge clk or posedge rst)
|
always @ (posedge clk or posedge rst)
|
begin
|
begin
|
if (rst)
|
if (rst)
|
begin
|
begin
|
sampled_bit <= 1;
|
sampled_bit <= 1;
|
sample_pulse <= 0;
|
sampled_bit_q <= 1;
|
|
sample_point <= 0;
|
end
|
end
|
else if (clk_en)
|
else if (clk_en)
|
begin
|
begin
|
if (seg1 & (quant_cnt == (time_segment1 + delay)))
|
if (seg1 & (quant_cnt == (time_segment1 + delay)))
|
begin
|
begin
|
sample_pulse <=#Tp 1;
|
sample_point <=#Tp 1;
|
|
sampled_bit_q <=#Tp sampled_bit;
|
if (triple_sampling)
|
if (triple_sampling)
|
sampled_bit <=#Tp (sample[0] & sample[1]) | ( sample[0] & rx) | (sample[1] & rx);
|
sampled_bit <=#Tp (sample[0] & sample[1]) | ( sample[0] & rx) | (sample[1] & rx);
|
else
|
else
|
sampled_bit <=#Tp rx;
|
sampled_bit <=#Tp rx;
|
end
|
end
|
end
|
end
|
else
|
else
|
sample_pulse <=#Tp 0; // Sample pulse is for development purposes only. REMOVE ME.
|
sample_point <=#Tp 0;
|
end
|
end
|
|
|
|
|
|
|
/* Blocking synchronization (can occur only once in a bit time) */
|
/* Blocking synchronization (can occur only once in a bit time) */
|