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
|
|
module fsm_1(
input wire sclk,
input wire rst_n,
input wire write_start,
output wire error_flag
);
parameter IDLE = 5'b00001; //state[0]
parameter WRITE = 5'b00010; //state[1]
parameter READ = 5'b00100; //state[2]
parameter CHECK = 5'b01000; //state[3]
parameter ERROR = 5'b10000; //state[4]
reg [4:0] state; //状态指示,独热码
reg write_end;
reg [9:0] write_cnt;
reg read_end;
reg [9:0] read_cnt;
/
//第1段:状态迁移描述(对state的赋值)单独写在一个always块 always @(posedge sclk or negedge rst_n) begin
if(rst_n == 1'b0)
state <= IDLE;
else begin //begin...end间的语句也是并行执行的
case(state) //状态机使用case语句描述,而不能使用if...else,这是由综合器的特性决定的
IDLE:
if(write_start == 1'b1)
|