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

Subversion Repositories 8051

[/] [8051/] [trunk/] [rtl/] [verilog/] [oc8051_tc2.v] - Blame information for rev 112

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

Line No. Rev Author Line
1 81 simont
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  8051 cores timer/counter2 control                           ////
4
////                                                              ////
5
////  This file is part of the 8051 cores project                 ////
6
////  http://www.opencores.org/cores/8051/                        ////
7
////                                                              ////
8
////  Description                                                 ////
9
////   timers and counters 2 8051 core                            ////
10
////                                                              ////
11
////  To Do:                                                      ////
12
////   Nothing                                                    ////
13
////                                                              ////
14
////  Author(s):                                                  ////
15
////      - Simon Teran, simont@opencores.org                     ////
16
////                                                              ////
17
//////////////////////////////////////////////////////////////////////
18
////                                                              ////
19
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
20
////                                                              ////
21
//// This source file may be used and distributed without         ////
22
//// restriction provided that this copyright statement is not    ////
23
//// removed from the file and that any derivative work contains  ////
24
//// the original copyright notice and the associated disclaimer. ////
25
////                                                              ////
26
//// This source file is free software; you can redistribute it   ////
27
//// and/or modify it under the terms of the GNU Lesser General   ////
28
//// Public License as published by the Free Software Foundation; ////
29
//// either version 2.1 of the License, or (at your option) any   ////
30
//// later version.                                               ////
31
////                                                              ////
32
//// This source is distributed in the hope that it will be       ////
33
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
34
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
35
//// PURPOSE.  See the GNU Lesser General Public License for more ////
36
//// details.                                                     ////
37
////                                                              ////
38
//// You should have received a copy of the GNU Lesser General    ////
39
//// Public License along with this source; if not, download it   ////
40
//// from http://www.opencores.org/lgpl.shtml                     ////
41
////                                                              ////
42
//////////////////////////////////////////////////////////////////////
43
//
44
// CVS Revision History
45
//
46
// $Log: not supported by cvs2svn $
47 112 simont
// Revision 1.1  2003/01/13 14:13:12  simont
48
// initial import
49 81 simont
//
50
//
51 112 simont
//
52 81 simont
 
53
`include "oc8051_defines.v"
54
 
55
//synopsys translate_off
56
`include "oc8051_timescale.v"
57
//synopsys translate_on
58
 
59
 
60
 
61 112 simont
module oc8051_tc2 (clk, rst,
62
            wr_addr, rd_addr,
63
            data_in, data_out, bit_out,
64
            wr, wr_bit, bit_in,
65
            t2, t2ex,
66
            rclk, tclk,
67
            brate2, tc2_int,
68
            pres_ow);
69 81 simont
 
70 112 simont
input [7:0]  wr_addr,
71
             data_in,
72
             rd_addr;
73
input        clk,
74
             rst,
75
             wr,
76
             wr_bit,
77
             t2,
78
             t2ex,
79
             bit_in,
80
             pres_ow;   //prescalre owerflov
81 81 simont
output [7:0] data_out;
82 112 simont
output       tc2_int,
83
             bit_out,
84
             rclk,
85
             tclk,
86
             brate2;
87
 
88 81 simont
reg [7:0] data_out;
89
 
90
reg brate2;
91 112 simont
reg [7:0] t2con, tl2, th2, rcap2l, rcap2h;
92 81 simont
 
93
reg neg_trans, t2ex_r, t2_r, tc2_event, tf2_set;
94
 
95
wire run;
96
 
97
//
98
// t2con
99
wire tf2, exf2, exen2, tr2, ct2, cprl2;
100
 
101
assign tc2_int = tf2 | exf2;
102
assign tf2   = t2con[7];
103
assign exf2  = t2con[6];
104
assign rclk  = t2con[5];
105
assign tclk  = t2con[4];
106
assign exen2 = t2con[3];
107
assign tr2   = t2con[2];
108
assign ct2   = t2con[1];
109
assign cprl2 = t2con[0];
110
 
111
assign bit_out = t2con[rd_addr[2:0]];
112
 
113
always @(posedge clk or posedge rst)
114
begin
115
  if (rst) begin
116
    t2con <= #1 `OC8051_RST_T2CON;
117
  end else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_T2CON)) begin
118
    t2con <= #1 data_in;
119
  end else if ((wr) & (wr_bit) & (wr_addr[7:3]==`OC8051_SFR_B_T2CON)) begin
120
    t2con[wr_addr[2:0]] <= #1 bit_in;
121
  end else if (tf2_set) begin
122
    t2con[7] <= #1 1'b1;
123 112 simont
  end else if (exen2 & neg_trans) begin
124
    t2con[6] <= #1 1'b1;
125 81 simont
  end
126
end
127
 
128
 
129
//
130
//th2, tl2
131 112 simont
assign run = tr2 & ((!ct2 & pres_ow) | (ct2 & tc2_event));
132 81 simont
 
133
always @(posedge clk or posedge rst)
134
begin
135
  if (rst) begin
136
//
137
// reset
138
//
139
    tl2 <= #1 `OC8051_RST_TL2;
140
    th2 <= #1 `OC8051_RST_TH2;
141
    brate2 <= #1 1'b0;
142
    tf2_set <= #1 1'b0;
143
  end else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_TH2)) begin
144
//
145
// write to timer 2 high
146
//
147
    th2 <= #1 data_in;
148
  end else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_TL2)) begin
149
//
150
// write to timer 2 low
151
//
152
    tl2 <= #1 data_in;
153 112 simont
  end else if (!(rclk | tclk) & !cprl2 & exen2 & neg_trans) begin
154 81 simont
//
155
// avto reload mode, exen2=1, 0-1 transition on t2ex pin
156
//
157
    th2 <= #1 rcap2h;
158
    tl2 <= #1 rcap2l;
159
    tf2_set <= #1 1'b0;
160
  end else if (run) begin
161
    if (rclk | tclk) begin
162
//
163
// boud rate generator mode
164
//
165
      if (&{th2, tl2}) begin
166
        th2 <= #1 rcap2h;
167
        tl2 <= #1 rcap2l;
168
        brate2 <= #1 1'b1;
169
      end else begin
170
        {brate2, th2, tl2}  <= #1 {1'b0, th2, tl2} + 17'h1;
171
      end
172
      tf2_set <= #1 1'b0;
173
    end else if (cprl2) begin
174
//
175
// capture mode
176
//
177
      {tf2_set, th2, tl2}  <= #1 {1'b0, th2, tl2} + 17'h1;
178 112 simont
    end else begin
179 81 simont
//
180 112 simont
// auto reload mode
181 81 simont
//
182
      if (&{th2, tl2}) begin
183
        th2 <= #1 rcap2h;
184
        tl2 <= #1 rcap2l;
185
        tf2_set <= #1 1'b1;
186
      end else begin
187
        {tf2_set, th2, tl2} <= #1 {1'b0, th2, tl2} + 17'h1;
188
      end
189
    end
190
  end else tf2_set <= #1 1'b0;
191
end
192
 
193
 
194
//
195
// rcap2l, rcap2h
196
always @(posedge clk or posedge rst)
197
begin
198
  if (rst) begin
199
    rcap2l <= #1 `OC8051_RST_RCAP2L;
200
    rcap2h <= #1 `OC8051_RST_RCAP2H;
201
  end else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_RCAP2H)) begin
202
    rcap2h <= #1 data_in;
203
  end else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_RCAP2L)) begin
204
    rcap2l <= #1 data_in;
205
  end else if (!(rclk | tclk) & exen2 & cprl2 & neg_trans) begin
206
    rcap2l <= #1 tl2;
207
    rcap2h <= #1 th2;
208
  end
209
end
210
 
211
 
212
//
213
//
214
always @(posedge clk or posedge rst)
215
begin
216
  if (rst) begin
217
    neg_trans <= #1 1'b0;
218
    t2ex_r <= #1 1'b0;
219
  end else if (t2ex) begin
220
    neg_trans <= #1 1'b0;
221
    t2ex_r <= #1 1'b1;
222
  end else if (t2ex_r) begin
223
    neg_trans <= #1 1'b1;
224
    t2ex_r <= #1 1'b0;
225
  end else begin
226
    neg_trans <= #1 1'b0;
227
    t2ex_r <= #1 t2ex_r;
228
  end
229
end
230
 
231
//
232
//
233
always @(posedge clk or posedge rst)
234
begin
235
  if (rst) begin
236
    tc2_event <= #1 1'b0;
237
    t2_r <= #1 1'b0;
238
  end else if (t2) begin
239
    tc2_event <= #1 1'b0;
240
    t2_r <= #1 1'b1;
241
  end else if (!t2 & t2_r) begin
242
//  end if (t2_r) begin
243
    tc2_event <= #1 1'b1;
244
    t2_r <= #1 1'b0;
245
  end else begin
246
    tc2_event <= #1 1'b0;
247
  end
248
end
249
 
250 112 simont
always @(rd_addr or t2con or tl2 or th2 or rcap2l or rcap2h)
251 81 simont
begin
252
  case (rd_addr)
253
    `OC8051_SFR_RCAP2H: data_out = rcap2h;
254
    `OC8051_SFR_RCAP2L: data_out = rcap2l;
255
    `OC8051_SFR_TH2:    data_out = th2;
256
    `OC8051_SFR_TL2:    data_out = tl2;
257
    default:            data_out = t2con;
258
  endcase
259
 
260
end
261
 
262
endmodule

powered by: WebSVN 2.1.0

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