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

Subversion Repositories mips_enhanced

[/] [mips_enhanced/] [trunk/] [grlib-gpl-1.0.19-b3188/] [lib/] [gaisler/] [vlog/] [ctl_fsm1.v] - Blame information for rev 2

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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