dpcnt001h.vmd
3 KB
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
/**************************************************************/
/* Verilog module of datapath cell DPCNT001H */
/* Designed by Lin Yang VLSI Technology Nov. 5, 90 */
/* Designed by Chunling Liu Compass July 6, 92 */
/* Modified by Linda J. Xu Compass Nov. 2, 92 */
/* */
/* The following is the port description */
/* Data ports */
/* D : the input port */
/* Q : the output port */
/* QN : the output port */
/* Control ports */
/* INST_CP : the clock signal */
/* INST_CLEAR : the clear signal */
/* INST_CIN : the carry input */
/* INST_COUT : the carry output */
/* INST_LOAD : the load enable signal */
/* INST_COUNT : the count enable signal */
/* INST_ID : the increment/decrement control signal */
/* Parameters */
/* WORDSIZE : the word size of the datapath cell */
/* DELAY : the delay time from input to output */
/* BF : the with/without buffer flag */
/* 0 for without buffer; 1 for with buffer */
/**************************************************************/
module dpcnt001h(D, Q, QN, INST_CP, INST_CLEAR, INST_CIN,
INST_COUT, INST_LOAD, INST_COUNT, INST_ID);
parameter WORDSIZE = 8, DELAY = 3, SETUP = 1, HOLD = 1, BF = 1;
input [WORDSIZE-1:0] D;
output [WORDSIZE-1:0] Q, QN;
input INST_CP, INST_CLEAR, INST_CIN;
output INST_COUT;
input INST_LOAD, INST_COUNT, INST_ID;
reg [WORDSIZE-1:0] dff;
reg cout;
function [WORDSIZE:0] cnt;
input [WORDSIZE-1:0] d;
reg flag;
begin
flag = WORDSIZE-1;
if (BF ==1)
flag = 1'b0;
if (INST_CLEAR == 0)
cnt = {WORDSIZE{1'b0}};
else if (INST_CLEAR == 1)
begin
if (INST_LOAD == 1)
cnt = ~(~d);
else if (INST_LOAD == 0)
begin
case ({INST_COUNT,INST_CIN,INST_ID})
3'b 101 : cnt = dff + 'b1;
3'b 100 : cnt = dff + {WORDSIZE{1'b1}};
3'b 000 ,
3'b 001 ,
3'b 010 ,
3'b 011 ,
3'b 110 ,
3'b 111 : cnt = dff;
default cnt = {WORDSIZE{1'b x}};
endcase
end
else
cnt[WORDSIZE-1:0] = {WORDSIZE{1'bx}};
end
else
cnt[WORDSIZE-1:0] = {WORDSIZE{1'bx}};
cnt[WORDSIZE] = flag ^ (&cnt[WORDSIZE-1:0]);
end
endfunction
always @ ( posedge INST_CP or negedge INST_CLEAR)
{cout, dff} = cnt(D);
assign #DELAY INST_COUT = cout, Q = dff, QN = ~dff;
endmodule