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

Subversion Repositories turbo8051

[/] [turbo8051/] [trunk/] [rtl/] [clkgen/] [clkgen.v] - Blame information for rev 25

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

Line No. Rev Author Line
1 8 dinesha
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  Tubo 8051 cores clockgen Module                             ////
4
////                                                              ////
5
////  This file is part of the Turbo 8051 cores project           ////
6
////  http://www.opencores.org/cores/turbo8051/                   ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  Turbo 8051 definitions.                                     ////
10
////                                                              ////
11
////  To Do:                                                      ////
12
////    nothing                                                   ////
13
////                                                              ////
14
////  Author(s):                                                  ////
15
////      - Dinesh Annayya, dinesha@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
module clkgen (
45
               reset_n      ,
46
               fastsim_mode ,
47 25 dinesha
               mastermode   ,
48 8 dinesha
               xtal_clk     ,
49
               clkout       ,
50
               gen_resetn   ,
51 25 dinesha
               risc_reset   ,
52 8 dinesha
               app_clk      ,
53
               uart_ref_clk
54
              );
55
 
56
 
57
 
58
input           reset_n        ; // Async reset signal
59
input         fastsim_mode   ; // fast sim mode = 1
60 25 dinesha
input         mastermode     ; // 1 : Risc master mode
61 8 dinesha
input           xtal_clk       ; // Xtal clock-25Mhx 
62
output        clkout         ; // clock output, 250Mhz
63
output        gen_resetn     ; // internally generated reset
64 25 dinesha
output        risc_reset      ; // internally generated reset
65 8 dinesha
output        app_clk        ; // application clock
66
output        uart_ref_clk   ; // uart 16x Ref clock
67
 
68
 
69
wire          hard_reset_st  ;
70
wire          configure_st   ;
71
wire          wait_pll_st    ;
72
wire          run_st         ;
73 25 dinesha
wire          slave_run_st   ;
74 8 dinesha
reg           pll_done       ;
75
reg [11:0]         pll_count      ;
76 25 dinesha
reg [2:0]          clkgen_ps      ;
77 8 dinesha
reg           gen_resetn     ; // internally generated reset
78 25 dinesha
reg           risc_reset      ; // internally generated reset
79 8 dinesha
 
80
 
81
assign        clkout = app_clk;
82
wire          pllout;
83
/***********************************************
84
 Alternal PLL pr-programmed for xtal: 25Mhz , clkout 250Mhz
85
*********************************************************/
86
 
87
altera_stargate_pll u_pll (
88
        . areset     (!reset_n ),
89
        . inclk0     (xtal_clk),
90
        . c0         (pllout),
91
        . locked     ()
92
       );
93
 
94
 
95
 
96
//---------------------------------------------
97
//
98
// 100us use 25.000 Mhz clock, counter = 2500(0x9C4)
99
 
100
//--------------------------------------------
101
always @(posedge xtal_clk or negedge reset_n)
102
   begin // {
103
      if (!reset_n)
104
      begin // {
105
         pll_count <= 12'h9C4;
106
      end   // }                                                                 
107
      else if (configure_st)
108
      begin // {
109
         pll_count <= (fastsim_mode) ? 12'h040  :  12'h9C4;
110
      end // }
111
      else if (wait_pll_st)
112
      begin // {
113
         pll_count <= (pll_done) ? pll_count : (pll_count - 1'b1);
114
     end // }
115
   end // }
116
 
117
 
118
/************************************************
119
    PLL Timer Counter
120
************************************************/
121
 
122
always @(posedge xtal_clk or negedge reset_n)
123
begin
124
   if (!reset_n)
125
      pll_done <= 0;
126
   else if (pll_count == 16'h0)
127
      pll_done <= 1;
128
   else if (configure_st)
129
      pll_done <= 0;
130
end
131
 
132
 
133
/************************************************
134
  internally generated reset
135
************************************************/
136
always @(posedge xtal_clk or negedge reset_n )
137
begin
138
   if (!reset_n) begin
139 25 dinesha
      gen_resetn  <=  0;
140
      risc_reset  <=  1;
141 8 dinesha
   end else if(run_st ) begin
142 25 dinesha
      gen_resetn  <=  1;
143
      risc_reset  <=  0;
144
   end else if(slave_run_st ) begin
145
      gen_resetn  <=  1;
146
      risc_reset  <=  1; // Keet Risc in Reset
147 8 dinesha
   end else begin
148 25 dinesha
      gen_resetn  <=  0;
149
      risc_reset  <=  1;
150 8 dinesha
   end
151
end
152
 
153
 
154
/****************************************
155
    Reset State Machine
156
****************************************/
157
/*****************************************
158
   Define Clock Gen stat machine state
159
*****************************************/
160 25 dinesha
`define HARD_RESET      3'b000
161
`define CONFIGURE       3'b001
162
`define WAIT_PLL        3'b010
163
`define RUN             3'b011
164
`define SLAVE_RUN       3'b100
165 8 dinesha
 
166
assign hard_reset_st     = (clkgen_ps == `HARD_RESET);
167
assign configure_st      = (clkgen_ps == `CONFIGURE);
168
assign wait_pll_st       = (clkgen_ps == `WAIT_PLL);
169
assign run_st            = (clkgen_ps == `RUN);
170 25 dinesha
assign slave_run_st      = (clkgen_ps == `SLAVE_RUN);
171 8 dinesha
 
172
always @(posedge xtal_clk or negedge reset_n)
173
begin
174
   if (!reset_n) begin
175
      clkgen_ps <= `HARD_RESET;
176
   end
177
   else begin
178
      case (clkgen_ps)
179
         `HARD_RESET:
180
            clkgen_ps <= `CONFIGURE;
181
 
182
          `CONFIGURE:
183
             clkgen_ps <= `WAIT_PLL;
184
 
185
         `WAIT_PLL:
186 25 dinesha
           if (pll_done) begin
187
              if ( mastermode )
188
                             clkgen_ps <= `RUN;
189
                    else
190
                             clkgen_ps <= `SLAVE_RUN;
191
          end
192 8 dinesha
      endcase
193
   end
194
end
195
 
196
 
197
//----------------------------------
198
// Generate Application clock 125Mhz
199
//----------------------------------
200
 
201
clk_ctl #(2) u_appclk (
202
   // Outputs
203
       .clk_o         (app_clk),
204
   // Inputs
205
       .mclk          (pllout),
206
       .reset_n       (gen_resetn),
207
       .clk_div_ratio (2'b00)
208
   );
209
 
210
 
211
//----------------------------------
212
// Generate Uart Ref Clock clock 50Mhz
213
// 250Mhz/(2+3) = 50Mhz
214
//----------------------------------
215
 
216
clk_ctl #(3) u_uart_clk (
217
   // Outputs
218
       .clk_o         (uart_ref_clk),
219
 
220
   // Inputs
221
       .mclk          (pllout      ),
222
       .reset_n       (gen_resetn  ),
223
       .clk_div_ratio (3'b011      )
224
   );
225
 
226
 
227
 
228
endmodule

powered by: WebSVN 2.1.0

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