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

Subversion Repositories oms8051mini

[/] [oms8051mini/] [trunk/] [rtl/] [clkgen/] [clkgen.v] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 dinesha
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OMS 8051 cores clockgen Module                              ////
4
////                                                              ////
5
////  This file is part of the OMS 8051 cores project             ////
6
////  http://www.opencores.org/cores/oms8051mini/                 ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  OMS 8051 definitions.                                       ////
10
////                                                              ////
11
////  To Do:                                                      ////
12
////    nothing                                                   ////
13
////                                                              ////
14
////  Author(s):                                                  ////
15
////      - Dinesh Annayya, dinesha@opencores.org                 ////
16
////                                                              ////
17
////  Revision : Nov 26, 2016                                     //// 
18
////                                                              ////
19
//////////////////////////////////////////////////////////////////////
20
////                                                              ////
21
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
22
////                                                              ////
23
//// This source file may be used and distributed without         ////
24
//// restriction provided that this copyright statement is not    ////
25
//// removed from the file and that any derivative work contains  ////
26
//// the original copyright notice and the associated disclaimer. ////
27
////                                                              ////
28
//// This source file is free software; you can redistribute it   ////
29
//// and/or modify it under the terms of the GNU Lesser General   ////
30
//// Public License as published by the Free Software Foundation; ////
31
//// either version 2.1 of the License, or (at your option) any   ////
32
//// later version.                                               ////
33
////                                                              ////
34
//// This source is distributed in the hope that it will be       ////
35
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
36
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
37
//// PURPOSE.  See the GNU Lesser General Public License for more ////
38
//// details.                                                     ////
39
////                                                              ////
40
//// You should have received a copy of the GNU Lesser General    ////
41
//// Public License along with this source; if not, download it   ////
42
//// from http://www.opencores.org/lgpl.shtml                     ////
43
////                                                              ////
44
//////////////////////////////////////////////////////////////////////
45
 
46
 
47
module clkgen (
48
               reset_n      ,
49
               fastsim_mode ,
50
               mastermode   ,
51
               xtal_clk     ,
52
               clkout       ,
53
               gen_resetn   ,
54
               risc_reset   ,
55
               app_clk      ,
56
               uart_ref_clk
57
              );
58
 
59
 
60
 
61
input           reset_n        ; // Async reset signal
62
input         fastsim_mode   ; // fast sim mode = 1
63
input         mastermode     ; // 1 : Risc master mode
64
input           xtal_clk       ; // Xtal clock-25Mhx 
65
output        clkout         ; // clock output, 250Mhz
66
output        gen_resetn     ; // internally generated reset
67
output        risc_reset      ; // internally generated reset
68
output        app_clk        ; // application clock
69
output        uart_ref_clk   ; // uart 16x Ref clock
70
 
71
 
72
wire          hard_reset_st  ;
73
wire          configure_st   ;
74
wire          wait_pll_st    ;
75
wire          run_st         ;
76
wire          slave_run_st   ;
77
reg           pll_done       ;
78
reg [11:0]         pll_count      ;
79
reg [2:0]          clkgen_ps      ;
80
reg           gen_resetn     ; // internally generated reset
81
reg           risc_reset      ; // internally generated reset
82
 
83
 
84
assign        clkout = app_clk;
85
wire          pllout;
86
/***********************************************
87
 Alternal PLL pr-programmed for xtal: 25Mhz , clkout 250Mhz
88
*********************************************************/
89
/*******************
90
altera_stargate_pll u_pll (
91
        . areset     (!reset_n ),
92
        . inclk0     (xtal_clk),
93
        . c0         (pllout),
94
        . locked     ()
95
       );
96
*************************/
97
 
98
assign pllout = xtal_clk;
99
 
100
//---------------------------------------------
101
//
102
// 100us use 25.000 Mhz clock, counter = 2500(0x9C4)
103
 
104
//--------------------------------------------
105
always @(posedge xtal_clk or negedge reset_n)
106
   begin // {
107
      if (!reset_n)
108
      begin // {
109
         pll_count <= 12'h9C4;
110
      end   // }                                                                 
111
      else if (configure_st)
112
      begin // {
113
         pll_count <= (fastsim_mode) ? 12'h040  :  12'h9C4;
114
      end // }
115
      else if (wait_pll_st)
116
      begin // {
117
         pll_count <= (pll_done) ? pll_count : (pll_count - 1'b1);
118
     end // }
119
   end // }
120
 
121
 
122
/************************************************
123
    PLL Timer Counter
124
************************************************/
125
 
126
always @(posedge xtal_clk or negedge reset_n)
127
begin
128
   if (!reset_n)
129
      pll_done <= 0;
130
   else if (pll_count == 16'h0)
131
      pll_done <= 1;
132
   else if (configure_st)
133
      pll_done <= 0;
134
end
135
 
136
 
137
/************************************************
138
  internally generated reset
139
************************************************/
140
always @(posedge xtal_clk or negedge reset_n )
141
begin
142
   if (!reset_n) begin
143
      gen_resetn  <=  0;
144
      risc_reset  <=  1;
145
   end else if(run_st ) begin
146
      gen_resetn  <=  1;
147
      risc_reset  <=  0;
148
   end else if(slave_run_st ) begin
149
      gen_resetn  <=  1;
150
      risc_reset  <=  1; // Keet Risc in Reset
151
   end else begin
152
      gen_resetn  <=  0;
153
      risc_reset  <=  1;
154
   end
155
end
156
 
157
 
158
/****************************************
159
    Reset State Machine
160
****************************************/
161
/*****************************************
162
   Define Clock Gen stat machine state
163
*****************************************/
164
`define HARD_RESET      3'b000
165
`define CONFIGURE       3'b001
166
`define WAIT_PLL        3'b010
167
`define RUN             3'b011
168
`define SLAVE_RUN       3'b100
169
 
170
assign hard_reset_st     = (clkgen_ps == `HARD_RESET);
171
assign configure_st      = (clkgen_ps == `CONFIGURE);
172
assign wait_pll_st       = (clkgen_ps == `WAIT_PLL);
173
assign run_st            = (clkgen_ps == `RUN);
174
assign slave_run_st      = (clkgen_ps == `SLAVE_RUN);
175
 
176
always @(posedge xtal_clk or negedge reset_n)
177
begin
178
   if (!reset_n) begin
179
      clkgen_ps <= `HARD_RESET;
180
   end
181
   else begin
182
      case (clkgen_ps)
183
         `HARD_RESET:
184
            clkgen_ps <= `CONFIGURE;
185
 
186
          `CONFIGURE:
187
             clkgen_ps <= `WAIT_PLL;
188
 
189
         `WAIT_PLL:
190
           if (pll_done) begin
191
              if ( mastermode )
192
                             clkgen_ps <= `RUN;
193
                    else
194
                             clkgen_ps <= `SLAVE_RUN;
195
          end
196
      endcase
197
   end
198
end
199
 
200
 
201
//----------------------------------
202
// Generate Application clock 125Mhz
203
//----------------------------------
204
 
205
clk_ctl #(1) u_appclk (
206
   // Outputs
207
       .clk_o         (app_clk),
208
   // Inputs
209
       .mclk          (pllout),
210
       .reset_n       (gen_resetn),
211
       .clk_div_ratio (2'b00)
212
   );
213
 
214
 
215
//----------------------------------
216
// Generate Uart Ref Clock clock 50Mhz
217
// 200Mhz/(2+0) = 50Mhz
218
// 250Mhz/(2+3) = 50Mhz
219
//----------------------------------
220
 
221
clk_ctl #(2) u_uart_clk (
222
   // Outputs
223
       .clk_o         (uart_ref_clk),
224
 
225
   // Inputs
226
       .mclk          (pllout      ),
227
       .reset_n       (gen_resetn  ),
228
       .clk_div_ratio (3'b000      )
229
   );
230
 
231
 
232
 
233
endmodule

powered by: WebSVN 2.1.0

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