-
Notifications
You must be signed in to change notification settings - Fork 0
/
TX_FSM.v
127 lines (115 loc) · 3.6 KB
/
TX_FSM.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
module TX_FSM (
input wire CLK,
input wire RST,
input wire Data_Valid,
input wire PAR_EN,
input wire ser_done,
output reg ser_en,
output reg busy,
output reg par_en,
output reg load,
output reg [1:0] mux_sel
);
localparam STATE_REG_WIDTH = 3; /*5 states*/
reg [STATE_REG_WIDTH-1:0] current_state, next_state;
/* States encoding in gray code*/
localparam [STATE_REG_WIDTH-1: 0] IDLE = 3'b000,
START = 3'b001,
SERIALIZATION = 3'b011,
PARITY = 3'b010,
STOP = 3'b110;
/*State Transition*/
always @(posedge CLK or negedge RST) begin
if (~RST) begin
current_state <=IDLE;
end
else begin
current_state <= next_state;
end
end
/*Next State and output logic*/
always @(*) begin
/*Defualt Values*/
mux_sel = 'b00;
ser_en = 'b0;
busy = 'b0;
par_en = 'b0;
load = 'b0;
case (current_state)
IDLE : begin
/*NS Logic*/
if (Data_Valid) begin
next_state <= START;
end
else begin
next_state <= IDLE;
end
/*OP logic*/
if(PAR_EN && Data_Valid)
par_en = 1'b1;
else
par_en = 1'b0;
/*Load the serializer*/
if(Data_Valid)
load = 'b1;
else
load = 'b0;
end
START : begin
/*NS Logic*/
next_state <= SERIALIZATION;
/*OP logic*/
busy = 'b1;
mux_sel = 'b00;
end
SERIALIZATION : begin
/*NS Logic*/
if (ser_done && PAR_EN) begin
next_state <= PARITY;
end
else if (ser_done && ~PAR_EN) begin
next_state <= STOP;
end
else begin // Serialization is not done
next_state <= SERIALIZATION;
end
/*OP logic*/
busy = 'b1;
mux_sel = 'b10;
ser_en = 'b1;
end
PARITY : begin
/*NS Logic*/
next_state <= STOP;
/*OP logic*/
busy = 'b1;
mux_sel = 'b11;
end
STOP : begin
/*NS Logic*/
if (Data_Valid) begin
next_state <= START;
end
else begin
next_state <= IDLE;
end
/*OP logic*/
busy = 'b1;
mux_sel = 'b01;
/*enable parity in case two frames are sent togeather (IDLE state is omitted) */
if(PAR_EN && Data_Valid)
par_en = 1'b1;
else
par_en = 1'b0;
/*Load the serializer (in case IDLE is omitted)*/
if(Data_Valid)
load = 'b1;
else
load = 'b0;
end
default : begin
next_state <= IDLE;
end
endcase
end
endmodule