w' X3 F' w% A// We also detect if a gap occurs in the received stream of characters ( I" ~3 K" p3 N, }# V7 t0 j// That can be useful if multiple characters are sent in burst" E: u) U5 G& ~+ K; C% C, Z
// so that multiple characters can be treated as a "packet" ) J! p/ [/ R' k2 p6 R7 D, ^, ~output RxD_endofpacket; // one clock pulse, when no more data is received (RxD_idle is going high) 8 J$ H0 Z5 W. r9 M8 ^output RxD_idle; // no data is being received* S1 I+ _* p: d6 S
) G# d A% ~% N8 k" M
// Baud generator (we use 8 times oversampling) 8 {$ [! ]" E1 C6 M# ]6 Q8 sparameter Baud8 = Baud*8; + f1 x4 P% {; J, G' j- C+ Zparameter Baud8GeneratorAccWidth = 16; ( {; m) S3 P9 U9 I# A0 oparameter Baud8GeneratorInc = ((Baud8<<(Baud8GeneratorAccWidth-7))+(ClkFrequency>>8))/(ClkFrequency>>7);! O9 |" `. W( E& Y* a' Q
reg [Baud8GeneratorAccWidth:0] Baud8GeneratorAcc; U) L6 @6 e* A; k; T+ H% @/ k
always @(posedge clk) 6 r: s/ C5 f- X! t6 D5 W; S1 Z0 O
Baud8GeneratorAcc <= Baud8GeneratorAcc[Baud8GeneratorAccWidth-1:0] + Baud8GeneratorInc;# R) D8 T. y$ e1 ]: @1 ]3 u
wire Baud8Tick = Baud8GeneratorAcc[Baud8GeneratorAccWidth];作者: s850187 時間: 2010-10-20 02:30 PM
//////////////////////////// + D) w, t3 n- f; F; z9 I6 V3 @% [reg [1:0] RxD_sync_inv;9 k: v' q( M! V
always @(posedge clk) $ [1 s/ V( j' y8 f b2 s
if(Baud8Tick) 1 S" E3 z2 Q; P6 \ RxD_sync_inv <= {RxD_sync_inv[0], ~RxD}; 6 b% [+ e. I3 i// we invert RxD, so that the idle becomes "0", to prevent a phantom character to be received at startup+ F' d- Y" [% |) i/ f3 [ {