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

Subversion Repositories versatile_library

[/] [versatile_library/] [trunk/] [backend/] [altera/] [lpm_ff.v] - Blame information for rev 74

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 74 unneback
//START_MODULE_NAME------------------------------------------------------------
2
//
3
// Module Name     :  lpm_ff
4
//
5
// Description     :  Parameterized flipflop megafunction. The lpm_ff function
6
//                    contains features that are not available in the DFF, DFFE,
7
//                    DFFEA, TFF, and TFFE primitives, such as synchronous or
8
//                    asynchronous set, clear, and load inputs.
9
 
10
//
11
// Limitation      :  n/a
12
//
13
// Results expected:  Data output from D or T flipflops. 
14
//
15
//END_MODULE_NAME--------------------------------------------------------------
16
 
17
// BEGINNING OF MODULE
18
`timescale 1 ps / 1 ps
19
 
20
// MODULE DECLARATION
21
module lpm_ff (
22
    data,   // T-type flipflop: Toggle enable
23
            // D-type flipflop: Data input
24
 
25
    clock,  // Positive-edge-triggered clock. (Required)
26
    enable, // Clock enable input.
27
    aclr,   // Asynchronous clear input.
28
    aset,   // Asynchronous set input.
29
 
30
    aload,  // Asynchronous load input. Asynchronously loads the flipflop with
31
            // the value on the data input.
32
 
33
    sclr,   // Synchronous clear input.
34
    sset,   // Synchronous set input.
35
 
36
    sload,  // Synchronous load input. Loads the flipflop with the value on the
37
            // data input on the next active clock edge.
38
 
39
    q       // Data output from D or T flipflops. (Required)
40
);
41
 
42
// GLOBAL PARAMETER DECLARATION
43
    parameter lpm_width  = 1; // Width of the data[] and q[] ports. (Required)
44
    parameter lpm_avalue = "UNUSED";    // Constant value that is loaded when aset is high.
45
    parameter lpm_svalue = "UNUSED";    // Constant value that is loaded on the rising edge
46
                                        // of clock when sset is high.
47
    parameter lpm_pvalue = "UNUSED";
48
    parameter lpm_fftype = "DFF";       // Type of flipflop
49
    parameter lpm_type = "lpm_ff";
50
    parameter lpm_hint = "UNUSED";
51
 
52
// INPUT PORT DECLARATION
53
    input  [lpm_width-1:0] data;
54
    input  clock;
55
    input  enable;
56
    input  aclr;
57
    input  aset;
58
    input  aload;
59
    input  sclr;
60
    input  sset;
61
    input  sload ;
62
 
63
// OUTPUT PORT DECLARATION
64
    output [lpm_width-1:0] q;
65
 
66
// INTERNAL REGISTER/SIGNAL DECLARATION
67
    reg  [lpm_width-1:0] tmp_q;
68
    reg  [lpm_width-1:0] adata;
69
    reg  use_adata;
70
    reg  [lpm_width-1:0] svalue;
71
    reg  [lpm_width-1:0] avalue;
72
    reg  [lpm_width-1:0] pvalue;
73
 
74
// INTERNAL WIRE DECLARATION
75
    wire [lpm_width-1:0] final_q;
76
 
77
// LOCAL INTEGER DECLARATION
78
    integer i;
79
 
80
// INTERNAL TRI DECLARATION
81
    tri1  [lpm_width-1:0] data;
82
    tri1 enable;
83
    tri0 sload;
84
    tri0 sclr;
85
    tri0 sset;
86
    tri0 aload;
87
    tri0 aclr;
88
    tri0 aset;
89
 
90
    wire i_enable;
91
    wire i_sload;
92
    wire i_sclr;
93
    wire i_sset;
94
    wire i_aload;
95
    wire i_aclr;
96
    wire i_aset;
97
    buf (i_enable, enable);
98
    buf (i_sload, sload);
99
    buf (i_sclr, sclr);
100
    buf (i_sset, sset);
101
    buf (i_aload, aload);
102
    buf (i_aclr, aclr);
103
    buf (i_aset, aset);
104
 
105
// TASK DECLARATION
106
    task string_to_reg;
107
    input  [8*40:1] string_value;
108
    output [lpm_width-1:0] value;
109
 
110
    reg [8*40:1] reg_s;
111
    reg [8:1] digit;
112
    reg [8:1] tmp;
113
    reg [lpm_width-1:0] ivalue;
114
 
115
    integer m;
116
 
117
    begin
118
        ivalue = {lpm_width{1'b0}};
119
        reg_s = string_value;
120
        for (m=1; m<=40; m=m+1)
121
        begin
122
            tmp = reg_s[320:313];
123
            digit = tmp & 8'b00001111;
124
            reg_s = reg_s << 8;
125
            ivalue = ivalue * 10 + digit;
126
        end
127
        value = ivalue;
128
    end
129
    endtask
130
 
131
// INITIAL CONSTRUCT BLOCK
132
    initial
133
    begin
134
        if (lpm_width <= 0)
135
        begin
136
            $display("Value of lpm_width parameter must be greater than 0(ERROR)");
137
            $display("Time: %0t  Instance: %m", $time);
138
            $finish;
139
        end
140
 
141
        if ((lpm_fftype != "DFF") &&
142
            (lpm_fftype != "TFF") &&
143
            (lpm_fftype != "UNUSED"))          // non-LPM 220 standard
144
        begin
145
            $display("Error!  LPM_FFTYPE value must be \"DFF\" or \"TFF\".");
146
            $display("Time: %0t  Instance: %m", $time);
147
            $finish;
148
        end
149
 
150
        if (lpm_avalue == "UNUSED")
151
            avalue =  {lpm_width{1'b1}};
152
        else
153
            string_to_reg(lpm_avalue, avalue);
154
 
155
        if (lpm_svalue == "UNUSED")
156
            svalue =  {lpm_width{1'b1}};
157
        else
158
            string_to_reg(lpm_svalue, svalue);
159
 
160
        if (lpm_pvalue == "UNUSED")
161
            pvalue =  {lpm_width{1'b0}};
162
        else
163
            string_to_reg(lpm_pvalue, pvalue);
164
 
165
        tmp_q = pvalue;
166
        use_adata = 1'b0;
167
    end
168
 
169
// ALWAYS CONSTRUCT BLOCK
170
    always @(posedge i_aclr or posedge i_aset or posedge i_aload or posedge clock)
171
    begin // Asynchronous process
172
        if (i_aclr || i_aset || i_aload)
173
            use_adata <= 1'b1;
174
        else if ($time > 0)
175
        begin // Synchronous process
176
            if (i_enable)
177
            begin
178
                use_adata <= 1'b0;
179
 
180
                if (i_sclr)
181
                    tmp_q <= 0;
182
                else if (i_sset)
183
                    tmp_q <= svalue;
184
                else if (i_sload)  // Load data
185
                    tmp_q <= data;
186
                else
187
                begin
188
                    if (lpm_fftype == "TFF") // toggle
189
                    begin
190
                        for (i = 0; i < lpm_width; i=i+1)
191
                            if (data[i] == 1'b1)
192
                                tmp_q[i] <= ~final_q[i];
193
                            else
194
                                tmp_q[i] <= final_q[i];
195
                    end
196
                    else    // DFF, load data
197
                        tmp_q <= data;
198
                end
199
            end
200
        end
201
    end
202
 
203
    always @(i_aclr or i_aset or i_aload or data or avalue or pvalue)
204
    begin
205
        if (i_aclr === 1'b1)
206
            adata <= {lpm_width{1'b0}};
207
        else if (i_aclr === 1'bx)
208
            adata <= {lpm_width{1'bx}};
209
        else if (i_aset)
210
            adata <= avalue;
211
        else if (i_aload)
212
            adata <= data;
213
        else if ((i_aclr === 1'b0) && ($time == 0))
214
            adata <= pvalue;
215
    end
216
 
217
// CONTINOUS ASSIGNMENT
218
    assign q = final_q;
219
    assign final_q = (use_adata == 1'b1) ? adata : tmp_q;
220
 
221
endmodule // lpm_ff
222
// END OF MODULE

powered by: WebSVN 2.1.0

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