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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1k_startup/] [rtl/] [verilog/] [spi_clgen.v] - Blame information for rev 822

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

Line No. Rev Author Line
1 2 marcus.erl
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  spi_clgen.v                                                 ////
4
////                                                              ////
5
////  This file is part of the SPI IP core project                ////
6
////  http://www.opencores.org/projects/spi/                      ////
7
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - Simon Srot (simons@opencores.org)                     ////
10
////                                                              ////
11
////  All additional information is avaliable in the Readme.txt   ////
12
////  file.                                                       ////
13
////                                                              ////
14
//////////////////////////////////////////////////////////////////////
15
////                                                              ////
16
//// Copyright (C) 2002 Authors                                   ////
17
////                                                              ////
18
//// This source file may be used and distributed without         ////
19
//// restriction provided that this copyright statement is not    ////
20
//// removed from the file and that any derivative work contains  ////
21
//// the original copyright notice and the associated disclaimer. ////
22
////                                                              ////
23
//// This source file is free software; you can redistribute it   ////
24
//// and/or modify it under the terms of the GNU Lesser General   ////
25
//// Public License as published by the Free Software Foundation; ////
26
//// either version 2.1 of the License, or (at your option) any   ////
27
//// later version.                                               ////
28
////                                                              ////
29
//// This source is distributed in the hope that it will be       ////
30
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
31
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
32
//// PURPOSE.  See the GNU Lesser General Public License for more ////
33
//// details.                                                     ////
34
////                                                              ////
35
//// You should have received a copy of the GNU Lesser General    ////
36
//// Public License along with this source; if not, download it   ////
37
//// from http://www.opencores.org/lgpl.shtml                     ////
38
////                                                              ////
39
//////////////////////////////////////////////////////////////////////
40
 
41
`include "spi_defines.v"
42
`include "timescale.v"
43
 
44
module spi_flash_clgen (clk_in, rst, go, enable, last_clk, clk_out, pos_edge, neg_edge);
45
 
46
   parameter divider_len = 2;
47
   parameter divider = 1;
48
 
49
   parameter Tp = 1;
50
 
51
   input                            clk_in;   // input clock (system clock)
52
   input                            rst;      // reset
53
   input                            enable;   // clock enable
54
   input                            go;       // start transfer
55
   input                            last_clk; // last clock
56
   //input [spi_divider_len-1:0]     divider;  // clock divider (output clock is divided by this value)
57
   output                           clk_out;  // output clock
58
   output                           pos_edge; // pulse marking positive edge of clk_out
59
   output                           neg_edge; // pulse marking negative edge of clk_out
60
 
61
   reg                              clk_out;
62
   reg                              pos_edge;
63
   reg                              neg_edge;
64
 
65
   reg [divider_len-1:0]             cnt;      // clock counter 
66
   wire                             cnt_zero; // conter is equal to zero
67
   wire                             cnt_one;  // conter is equal to one
68
 
69
 
70
   assign cnt_zero = cnt == {divider_len{1'b0}};
71
   assign cnt_one  = cnt == {{divider_len-1{1'b0}}, 1'b1};
72
 
73
   // Counter counts half period
74
   always @(posedge clk_in or posedge rst)
75
     begin
76
        if(rst)
77
          cnt <= #Tp {divider_len{1'b1}};
78
        else
79
          begin
80
             if(!enable || cnt_zero)
81
               cnt <= #Tp divider;
82
             else
83
               cnt <= #Tp cnt - {{divider_len-1{1'b0}}, 1'b1};
84
          end
85
     end
86
 
87
   // clk_out is asserted every other half period
88
   always @(posedge clk_in or posedge rst)
89
     begin
90
        if(rst)
91
          clk_out <= #Tp 1'b0;
92
        else
93
          clk_out <= #Tp (enable && cnt_zero && (!last_clk || clk_out)) ? ~clk_out : clk_out;
94
     end
95
 
96
   // Pos and neg edge signals
97
   always @(posedge clk_in or posedge rst)
98
     begin
99
        if(rst)
100
          begin
101
             pos_edge  <= #Tp 1'b0;
102
             neg_edge  <= #Tp 1'b0;
103
          end
104
        else
105
          begin
106
             pos_edge  <= #Tp (enable && !clk_out && cnt_one) || (!(|divider) && clk_out) || (!(|divider) && go && !enable);
107
             neg_edge  <= #Tp (enable && clk_out && cnt_one) || (!(|divider) && !clk_out && enable);
108
          end
109
     end
110
endmodule

powered by: WebSVN 2.1.0

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