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

Subversion Repositories oms8051mini

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

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

powered by: WebSVN 2.1.0

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