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

Subversion Repositories embedded_risc

[/] [embedded_risc/] [trunk/] [Verilog/] [timer.v] - Blame information for rev 29

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 26 hosseinami
/*********************************************************
2
 MODULE:                Sub Level Timer Device
3
 
4
 FILE NAME:     timer.v
5
 VERSION:       1.0
6
 DATE:          May 21th, 2002
7
 AUTHOR:                Hossein Amidi
8
 COMPANY:
9
 CODE TYPE:     Register Transfer Level
10
 
11
 DESCRIPTION:   This module is the top level RTL code of Timer verilog code.
12
 
13
 It will instantiate the following blocks in the ASIC:
14
 
15
 
16
 Hossein Amidi
17
 (C) April 2002
18
 
19
*********************************************************/
20
 
21
// DEFINES
22
`timescale 1ns / 10ps
23
 
24
// TOP MODULE
25
module timer(// Inputs
26
                                        reset,
27
                                        clk0,
28
                                        timer_host_datain,
29
                                        timer_cmd,
30
                                        timer_addr,
31
                                        // Outputs
32
                                        timer_host_dataout,
33
                                        timer_irq
34
                                        );
35
 
36
 
37
// Parameter
38
`include        "parameter.v"
39
 
40
// Inputs
41
input reset;
42
input clk0;
43
input [data_size - 1 : 0]timer_host_datain;
44
input [cmd_size - 1 : 0]timer_cmd;
45
input [padd_size - 1 : 0]timer_addr;
46
 
47
// Outputs
48
output [data_size - 1 : 0]timer_host_dataout;
49
output timer_irq;
50
 
51
 
52
// Signal Declarations
53
wire reset;
54
wire clk0;
55
wire [data_size - 1 : 0]timer_host_datain;
56
wire [cmd_size - 1 : 0]timer_cmd;
57
wire [padd_size - 1 : 0]timer_addr;
58
 
59
wire [data_size - 1 : 0]timer_host_dataout;
60
reg timer_irq;
61
 
62
reg [data_size - 1 : 0]timer_reg_dataout;
63
reg [timer_size - 1 : 0]timer;
64
 
65
wire [timer_reg_width - 1 : 0] timer_register0;
66
wire [timer_reg_width - 1 : 0] timer_register1;
67
wire [timer_reg_width - 1 : 0] timer_register2;
68
wire [timer_reg_width - 1 : 0] timer_register3;
69
 
70
wire timed_out;
71
wire running;
72
wire irq_enb;
73
wire continuous;
74
wire timer_start;
75
wire timer_stop;
76
 
77
// Internal Registers
78
 
79
/***************** Internal Register of Timer configuration *******************/
80
reg [timer_reg_width - 1 : 0] timer_register [timer_reg_depth - 1 : 0];
81
 
82
 
83
// Assignment statments
84
assign timer_host_dataout = timer_reg_dataout;
85
 
86
// Internal Register Mapping
87
assign timer_register0 = timer_register[0];      // Status Register
88
assign timer_register1 = timer_register[1];     // Control Register
89
assign timer_register2 = timer_register[2];     // Time-Out Period
90
assign timer_register3 = timer_register[3];     // Snapshot Register
91
 
92
// Status Register
93
assign timed_out   = timer_register0[0];
94
assign running     = timer_register0[1];
95
 
96
// Control Register
97
assign irq_enb     = timer_register1[0];
98
assign continuous  = timer_register1[1];
99
assign timer_start = timer_register1[2];
100
assign timer_stop  = timer_register1[3];
101
 
102
 
103
// Setting the internal Registers by the Host (CPU)
104
always @(posedge reset or posedge clk0)
105
begin
106
        if(reset == 1'b1)
107
        begin
108
                timer_reg_dataout  <= 32'h0;
109
                timer_register[0] <= 32'h0;
110
                timer_register[1] <= 32'h0;
111
                timer_register[2] <= 32'h0;
112
                timer_register[3] <= 32'h0;
113
        end
114
        else
115
        begin
116
                if(timer_cmd == 3'b010)
117
                begin
118
                        case(timer_addr)
119
                                24'h080020: timer_register[0] <= timer_host_datain;              // Status Register
120
                                24'h080021: timer_register[1] <= timer_host_datain;             // Control Register
121
                                24'h080022: timer_register[2] <= timer_host_datain;             // Time-Out Period
122
                                24'h080023: timer_register[3] <= timer_host_datain;             // Timer Snapshot
123
                        endcase
124
                end
125
                else
126
                if(timer_cmd == 3'b001)
127
                begin
128
                        case(timer_addr)
129
                                24'h080020: timer_reg_dataout <= timer_register[0];
130
                                24'h080021: timer_reg_dataout <= timer_register[1];
131
                                24'h080022: timer_reg_dataout <= timer_register[2];
132
                                24'h080023: timer_reg_dataout <= timer_register[3];
133
                        endcase
134
                end
135
 
136
        // Set the Status Register timed_out bit to one if timer is in continuous mode
137
        // and timer reached the maximum        time set by CPU
138
        if((continuous == 1'b1) && (timer == timer_register2))
139
                timer_register[0] <= timer_register0 & 32'h1;
140
        else
141
                timer_register[0] <= timer_register0 & 32'h0;
142
 
143
        // Set the Status Register running bit to one if the timer started and not reached
144
        // the maximum value
145
        if((timer_start == 1'b1) && (timer_irq == 1'b0))
146
                timer_register[0] <= timer_register0 & 32'h2;
147
        else
148
                timer_register[0] <= timer_register0 & 32'h0;
149
 
150
        // Set the timer snapshot to current value of timer for CPU to evaluate
151
        timer_register[3] <= timer;
152
 
153
        end
154
end
155
 
156
 
157
// 32-bit Timer and it's control signals base on the internal register settings
158
always @(posedge reset or posedge clk0)
159
begin
160
        if(reset == 1'b1)
161
        begin
162
                timer <= 32'h0;
163
        end
164
        else
165
        begin
166
                // Star Counting
167
                if((timer_start == 1'b1) && (timer_stop == 1'b0))
168
                        timer <= timer + 1;
169
                else
170
                        timer <= timer;
171
                // Stop Counting
172
                if(timer_stop == 1'b1)
173
                        timer <= timer;
174
                // Set time to begin (zero) value
175
                if((continuous == 1'b1) && (timer == timer_register2))
176
                        timer <= 32'h0;
177
                // Set the irq pin if the irq_enb is one and timmer reaches the maximum
178
                if((irq_enb == 1'b1) && (timer == timer_register2))
179
                        timer_irq <= 1'b1;
180
                else
181
                        timer_irq <= 1'b0;
182
 
183
        end
184
end
185
 
186
 
187
endmodule

powered by: WebSVN 2.1.0

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