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

Subversion Repositories oms8051mini

[/] [oms8051mini/] [trunk/] [rtl/] [8051/] [oc8051_tc.v] - Blame information for rev 31

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

Line No. Rev Author Line
1 2 dinesha
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  8051 cores timer/counter control                            ////
4
////                                                              ////
5
////  This file is part of the 8051 cores project                 ////
6
////  http://www.opencores.org/cores/oms8051mini/                 ////
7
////                                                              ////
8
////  Description                                                 ////
9
////   timers and counters handling for 8051 core                 ////
10
////                                                              ////
11
////  To Do:                                                      ////
12
////   Nothing                                                    ////
13
////                                                              ////
14
////  Author(s):                                                  ////
15
////      - Simon Teran, simont@opencores.org                     ////
16
////      - Dinesh Annayya, dinesha@opencores.org                 ////
17
////                                                              ////
18
//////////////////////////////////////////////////////////////////////
19 25 dinesha
////   v0.0 - Dinesh A, 5th Jan 2017
20
////        1. Active edge of reset changed from High to Low
21
//////////////////////////////////////////////////////////////////////
22 2 dinesha
////                                                              ////
23
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
24
////                                                              ////
25
//// This source file may be used and distributed without         ////
26
//// restriction provided that this copyright statement is not    ////
27
//// removed from the file and that any derivative work contains  ////
28
//// the original copyright notice and the associated disclaimer. ////
29
////                                                              ////
30
//// This source file is free software; you can redistribute it   ////
31
//// and/or modify it under the terms of the GNU Lesser General   ////
32
//// Public License as published by the Free Software Foundation; ////
33
//// either version 2.1 of the License, or (at your option) any   ////
34
//// later version.                                               ////
35
////                                                              ////
36
//// This source is distributed in the hope that it will be       ////
37
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
38
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
39
//// PURPOSE.  See the GNU Lesser General Public License for more ////
40
//// details.                                                     ////
41
////                                                              ////
42
//// You should have received a copy of the GNU Lesser General    ////
43
//// Public License along with this source; if not, download it   ////
44
//// from http://www.opencores.org/lgpl.shtml                     ////
45
////                                                              ////
46
//////////////////////////////////////////////////////////////////////
47
//
48
// CVS Revision History
49
//
50
// $Log: not supported by cvs2svn $
51
// Revision 1.8  2003/04/10 12:43:19  simont
52
// defines for pherypherals added
53
//
54
// Revision 1.7  2003/04/07 14:58:02  simont
55
// change sfr's interface.
56
//
57
// Revision 1.6  2003/04/04 10:34:13  simont
58
// change timers to meet timing specifications (add divider with 12)
59
//
60
// Revision 1.5  2003/01/13 14:14:41  simont
61
// replace some modules
62
//
63
// Revision 1.4  2002/09/30 17:33:59  simont
64
// prepared header
65
//
66
//
67
 
68
`include "top_defines.v"
69
 
70
 
71
 
72 25 dinesha
module oc8051_tc (clk, resetn,
73 2 dinesha
            data_in,
74
            wr_addr,
75
            wr, wr_bit,
76
            ie0, ie1,
77
            tr0, tr1,
78
            t0, t1,
79
            tf0, tf1,
80
            pres_ow,
81
//registers
82
            tmod, tl0, th0, tl1, th1);
83
 
84
input [7:0]  wr_addr,
85
             data_in;
86
input        clk,
87 25 dinesha
             resetn,
88 2 dinesha
             wr,
89
             wr_bit,
90
             ie0,
91
             ie1,
92
             tr0,
93
             tr1,
94
             t0,
95
             t1,
96
             pres_ow;
97
output [7:0] tmod,
98
             tl0,
99
             th0,
100
             tl1,
101
             th1;
102
output       tf0,
103
             tf1;
104
 
105
 
106
reg [7:0] tmod, tl0, th0, tl1, th1;
107
reg tf0, tf1_0, tf1_1, t0_buff, t1_buff;
108
 
109
wire tc0_add, tc1_add;
110
 
111
assign tc0_add = (tr0 & (!tmod[3] | !ie0) & ((!tmod[2] & pres_ow) | (tmod[2] & !t0 & t0_buff)));
112
assign tc1_add = (tr1 & (!tmod[7] | !ie1) & ((!tmod[6] & pres_ow) | (tmod[6] & !t1 & t1_buff)));
113
assign tf1= tf1_0 | tf1_1;
114
 
115
//
116
// read or write from one of the addresses in tmod
117
//
118 25 dinesha
always @(posedge clk or negedge resetn)
119 2 dinesha
begin
120 25 dinesha
 if (resetn == 1'b0) begin
121 2 dinesha
   tmod <=#1 `OC8051_RST_TMOD;
122
 end else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_TMOD))
123
    tmod <= #1 data_in;
124
end
125
 
126
//
127
// TIMER COUNTER 0
128
//
129 25 dinesha
always @(posedge clk or negedge resetn)
130 2 dinesha
begin
131 25 dinesha
 if (resetn == 1'b0) begin
132 2 dinesha
   tl0 <=#1 `OC8051_RST_TL0;
133
   th0 <=#1 `OC8051_RST_TH0;
134
   tf0 <= #1 1'b0;
135
   tf1_0 <= #1 1'b0;
136
 end else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_TL0)) begin
137
   tl0 <= #1 data_in;
138
   tf0 <= #1 1'b0;
139
   tf1_0 <= #1 1'b0;
140
 end else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_TH0)) begin
141
   th0 <= #1 data_in;
142
   tf0 <= #1 1'b0;
143
   tf1_0 <= #1 1'b0;
144
 end else begin
145
     case (tmod[1:0]) /* synopsys full_case parallel_case */
146
      `OC8051_MODE0: begin                       // mode 0
147
        tf1_0 <= #1 1'b0;
148
        if (tc0_add)
149
          {tf0, th0,tl0[4:0]} <= #1 {1'b0, th0, tl0[4:0]}+ 1'b1;
150
      end
151
      `OC8051_MODE1: begin                       // mode 1
152
        tf1_0 <= #1 1'b0;
153
        if (tc0_add)
154
          {tf0, th0,tl0} <= #1 {1'b0, th0, tl0}+ 1'b1;
155
      end
156
 
157
      `OC8051_MODE2: begin                       // mode 2
158
        tf1_0 <= #1 1'b0;
159
        if (tc0_add) begin
160
          if (tl0 == 8'b1111_1111) begin
161
            tf0 <=#1 1'b1;
162
            tl0 <=#1 th0;
163
           end
164
          else begin
165
            tl0 <=#1 tl0 + 8'h1;
166
            tf0 <= #1 1'b0;
167
          end
168
        end
169
      end
170
      `OC8051_MODE3: begin                       // mode 3
171
 
172
         if (tc0_add)
173
           {tf0, tl0} <= #1 {1'b0, tl0} +1'b1;
174
 
175
         if (tr1 & pres_ow)
176
           {tf1_0, th0} <= #1 {1'b0, th0} +1'b1;
177
 
178
      end
179
/*      default:begin
180
        tf0 <= #1 1'b0;
181
        tf1_0 <= #1 1'b0;
182
      end*/
183
    endcase
184
 end
185
end
186
 
187
//
188
// TIMER COUNTER 1
189
//
190 25 dinesha
always @(posedge clk or negedge resetn)
191 2 dinesha
begin
192 25 dinesha
 if (resetn == 1'b0) begin
193 2 dinesha
   tl1 <=#1 `OC8051_RST_TL1;
194
   th1 <=#1 `OC8051_RST_TH1;
195
   tf1_1 <= #1 1'b0;
196
 end else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_TL1)) begin
197
   tl1 <= #1 data_in;
198
   tf1_1 <= #1 1'b0;
199
 end else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_TH1)) begin
200
   th1 <= #1 data_in;
201
   tf1_1 <= #1 1'b0;
202
 end else begin
203
     case (tmod[5:4]) /* synopsys full_case parallel_case */
204
      `OC8051_MODE0: begin                       // mode 0
205
        if (tc1_add)
206
          {tf1_1, th1,tl1[4:0]} <= #1 {1'b0, th1, tl1[4:0]}+ 1'b1;
207
      end
208
      `OC8051_MODE1: begin                       // mode 1
209
        if (tc1_add)
210
          {tf1_1, th1,tl1} <= #1 {1'b0, th1, tl1}+ 1'b1;
211
      end
212
 
213
      `OC8051_MODE2: begin                       // mode 2
214
        if (tc1_add) begin
215
          if (tl1 == 8'b1111_1111) begin
216
            tf1_1 <=#1 1'b1;
217
            tl1 <=#1 th1;
218
           end
219
          else begin
220
            tl1 <=#1 tl1 + 8'h1;
221
            tf1_1 <= #1 1'b0;
222
          end
223
        end
224
      end
225
/*      default:begin
226
        tf1_1 <= #1 1'b0;
227
      end*/
228
    endcase
229
 end
230
end
231
 
232
 
233 25 dinesha
always @(posedge clk or negedge resetn)
234
  if (resetn == 1'b0) begin
235 2 dinesha
    t0_buff <= #1 1'b0;
236
    t1_buff <= #1 1'b0;
237
  end else begin
238
    t0_buff <= #1 t0;
239
    t1_buff <= #1 t1;
240
  end
241
endmodule

powered by: WebSVN 2.1.0

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