OpenCores
URL https://opencores.org/ocsvn/mips789/mips789/trunk

Subversion Repositories mips789

[/] [mips789/] [trunk/] [core/] [ctl_fsm.v] - Blame information for rev 64

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 64 mcupro
/******************************************************************
2
 *                                                                *
3
 *    Author: Liwei                                               *
4
 *                                                                *
5
 *    This file is part of the "mips789" project.                 *
6
 *    Downloaded from:                                            *
7
 *    http://www.opencores.org/pdownloads.cgi/list/mips789        *
8
 *                                                                *
9
 *    If you encountered any problem, please contact me via       *
10
 *    Email:mcupro@opencores.org  or mcupro@163.com               *
11
 *                                                                *
12
 ******************************************************************/
13
 
14
`include "mips789_defs.v"
15
module ctl_FSM (
16
    input   clk,
17
    input   [2:0] id_cmd,
18
    input   irq,
19
    input   rst,
20
    output  reg iack,
21
    output  reg zz_is_nop,
22
    output  reg id2ra_ctl_clr,
23
    output  reg id2ra_ctl_cls,
24
    output  reg id2ra_ins_clr,
25
    output  reg id2ra_ins_cls,
26
    output  reg [3:0] pc_prectl,
27
    output  reg ra2exec_ctl_clr
28
    );
29
    parameter
30
        ID_CUR   = `FSM_CUR,   ID_LD    = `FSM_LD ,
31
        ID_MUL   = `FSM_MUL,   ID_NOI   = `FSM_NOI,
32
        ID_RET   = `FSM_RET,
33
 
34
        PC_IGN   = `PC_IGN ,   PC_IRQ   = `PC_IRQ,
35
        PC_KEP   = `PC_KEP ,   PC_RST   = `PC_RST;
36
 
37
    reg [5:0] delay_counter;
38
    reg [4:0] CurrState ;
39
    reg [4:0] NextState ;
40
    reg     riack;
41
    always @(posedge clk) if (~rst) riack<=0; else riack<=iack;
42
 
43
    always @(*)
44
    begin //deal with iack
45
        case (CurrState )
46
            `IRQ:iack=1'b1;
47
            `RET:iack=1'b0;
48
            //onlt this 2 states those will change the iack state
49
            default iack=riack;
50
        endcase
51
    end
52
 
53
    always @ (posedge clk )
54
        if (~rst)delay_counter  <=0;
55
        else
56
        case (CurrState)
57
            //any delay state can be added here
58
            `MUL:       delay_counter  <=delay_counter + 1;
59
            default :     delay_counter  <=0;
60
        endcase
61
 
62
/////////////////////////////////////////////////////////
63
//    Finite State Machine 
64
//
65
  /*Finite State Machine part1*/
66
    always @ (posedge clk) if (~rst) CurrState  <= `RST; else CurrState  <= NextState ;
67
 
68
    always @ (*)/*Finite State Machine part2*/
69
    begin
70
        case (CurrState)
71
            `IDLE:
72
            begin
73
                if (~rst)                    NextState  = `RST;
74
              //  else if ((irq)&&(~riack))    NextState  = `IRQ;
75
                else if (id_cmd ==ID_NOI)    NextState  = `NOI;
76
                else if (id_cmd==ID_CUR)     NextState  = `CUR;
77
                else if (id_cmd==ID_MUL)     NextState  = `MUL;
78
                else if (id_cmd==ID_LD)      NextState  = `LD;
79
                else if (id_cmd==ID_RET)     NextState  = `RET;
80
                else                         NextState  = `IDLE;
81
            end
82
            `NOI:
83
            begin
84
                if (id_cmd ==ID_NOI)         NextState  = `NOI;
85
                else if (id_cmd==ID_CUR)     NextState  = `CUR;
86
                else if (id_cmd==ID_MUL)     NextState  = `MUL;
87
                else if (id_cmd==ID_LD)      NextState  = `LD;
88
                else if (id_cmd==ID_RET)     NextState  = `RET;
89
                else                         NextState  = `IDLE;
90
            end
91
            `CUR:   NextState  = `NOI;
92
            `RET:   NextState  = `IDLE;
93
            `IRQ:   NextState  = `IDLE;
94
            `RST:   NextState  = `IDLE;
95
            `LD:    NextState  = `IDLE;
96
            `MUL:   NextState  = (delay_counter==32)?`IDLE:`MUL;
97
            default NextState  =`IDLE;
98
        endcase
99
    end
100
 
101
    always @ (*)/*Finite State Machine part3*/
102
    begin
103
        case (CurrState )
104
            `IDLE: begin id2ra_ins_clr  =  1'b0;
105
                id2ra_ins_cls  =  1'b0;
106
                id2ra_ctl_clr  =  1'b0;
107
                id2ra_ctl_cls  =  1'b0;
108
                ra2exec_ctl_clr   =  1'b0;
109
                pc_prectl=PC_IGN;
110
                zz_is_nop = 0;end
111
      `MUL:  begin
112
                id2ra_ins_clr  =  1'b1;
113
                id2ra_ins_cls  =  1'b0;
114
                id2ra_ctl_clr  =  1'b1;
115
                id2ra_ctl_cls  =  1'b0;
116
                ra2exec_ctl_clr  =  1'b0;
117
                pc_prectl =PC_KEP;
118
                zz_is_nop =0; end
119
      `CUR:  begin
120
                id2ra_ins_clr  =  1'b0;
121
                id2ra_ins_cls  =  1'b1;
122
                id2ra_ctl_clr  =  1'b0;
123
                id2ra_ctl_cls  =  1'b1;
124
                ra2exec_ctl_clr  =  1'b1;
125
                pc_prectl =PC_KEP;
126
                zz_is_nop = 1; end
127
      `RET: begin id2ra_ins_clr  =  1'b0;
128
                id2ra_ins_cls  =  1'b0;
129
                id2ra_ctl_clr  =  1'b0;
130
                id2ra_ctl_cls  =  1'b0;
131
                ra2exec_ctl_clr   =  1'b0;
132
                pc_prectl =PC_IGN;
133
                zz_is_nop = 1'b0;  end
134
      `IRQ: begin
135
                id2ra_ins_clr  =  1'b1;
136
                id2ra_ins_cls  =  1'b0;
137
                id2ra_ctl_clr  =  1'b1;
138
                id2ra_ctl_cls  =  1'b0;
139
                ra2exec_ctl_clr  =  1'b1;
140
                pc_prectl =PC_IRQ;
141
                zz_is_nop = 1'b0;end
142
      `RST: begin
143
                id2ra_ins_clr  =  1'b1;
144
                id2ra_ins_cls  =  1'b0;
145
                id2ra_ctl_clr  =  1'b1;
146
                id2ra_ctl_cls  =  1'b0;
147
                ra2exec_ctl_clr  =  1'b1;
148
                pc_prectl=PC_RST;
149
                zz_is_nop = 1'b1; end
150
      `LD:begin
151
                id2ra_ins_clr  =  1'b1;
152
                id2ra_ins_cls  =  1'b0;
153
                id2ra_ctl_clr  =  1'b1;
154
                id2ra_ctl_cls  =  1'b0;
155
                ra2exec_ctl_clr  =  1'b0;
156
                pc_prectl =PC_KEP;
157
                zz_is_nop = 1'b0;end
158
      `NOI:begin
159
                id2ra_ins_clr  =  1'b0;
160
                id2ra_ins_cls  =  1'b0;
161
                id2ra_ctl_clr  =  1'b0;
162
                id2ra_ctl_cls  =  1'b0;
163
                ra2exec_ctl_clr   =  1'b0;
164
                pc_prectl=PC_IGN;
165
                zz_is_nop = 1'b0;end
166
      default   begin
167
                id2ra_ins_clr  =  1'b1;
168
                id2ra_ins_cls  =  1'b0;
169
                id2ra_ctl_clr  =  1'b1;
170
                id2ra_ctl_cls  =  1'b0;
171
                ra2exec_ctl_clr  =  1'b1;
172
                pc_prectl=PC_RST;
173
                zz_is_nop = 1'b1;end
174
      endcase
175
    end
176
endmodule
177
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.