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

Subversion Repositories pit

[/] [pit/] [trunk/] [rtl/] [verilog/] [pit_regs.v] - Blame information for rev 15

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

Line No. Rev Author Line
1 2 rehayes
////////////////////////////////////////////////////////////////////////////////
2
//
3
//  WISHBONE revB.2 compliant Programable Interrupt Timer - Control registers
4
//
5
//  Author: Bob Hayes
6
//          rehayes@opencores.org
7
//
8
//  Downloaded from: http://www.opencores.org/projects/pit.....
9
//
10
////////////////////////////////////////////////////////////////////////////////
11
// Copyright (c) 2009, Robert Hayes
12
//
13
// All rights reserved.
14
//
15
// Redistribution and use in source and binary forms, with or without
16
// modification, are permitted provided that the following conditions are met:
17
//     * Redistributions of source code must retain the above copyright
18
//       notice, this list of conditions and the following disclaimer.
19
//     * Redistributions in binary form must reproduce the above copyright
20
//       notice, this list of conditions and the following disclaimer in the
21
//       documentation and/or other materials provided with the distribution.
22
//     * Neither the name of the <organization> nor the
23
//       names of its contributors may be used to endorse or promote products
24
//       derived from this software without specific prior written permission.
25
//
26
// THIS SOFTWARE IS PROVIDED BY Robert Hayes ''AS IS'' AND ANY
27
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29
// DISCLAIMED. IN NO EVENT SHALL Robert Hayes BE LIABLE FOR ANY
30
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
33
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
////////////////////////////////////////////////////////////////////////////////
37
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
38
 
39
module pit_regs #(parameter ARST_LVL = 1'b0,  // asynchronous reset level
40
                  parameter COUNT_SIZE = 16,
41
                  parameter NO_PRESCALE = 1'b0,
42
                  parameter DWIDTH = 16)
43
  (
44
  output reg [COUNT_SIZE-1:0] mod_value,    // Main Counter Modulo Value
45
  output               [ 3:0] pit_pre_scl,  // PIT Prescaler Value
46
  output reg                  pit_slave,    // PIT Slave Mode
47
  output reg                  pit_flg_clr,  // Clear PIT Rollover Flag
48
  output reg                  pit_ien,      // PIT Interrupt Enable
49
  output reg                  cnt_sync_o,   // PIT Counter Enable
50
  output reg                  pit_irq_o,    // PIT interrupt
51
  input                       bus_clk,      // Control register bus clock
52
  input                       async_rst_b,  // Async reset signal
53
  input                       sync_reset,   // Syncronous reset signal
54
  input                       pit_flag,     // PIT Rollover Flag
55
  input          [DWIDTH-1:0] write_bus,    // Write Data Bus
56
  input                [ 3:0] write_regs,   // Write Register strobes
57
  input                       cnt_flag_o    // Counter Rollover Flag 
58
  );
59
 
60
 
61
  // registers
62
  reg  [ 3:0] pit_pre;    // Optional register for PIT Prescale Counter modulo
63
                          //  This register should be removed durning synthesis
64
                          //  if the "NO_PRESCALE" parameter is set
65
 
66
  // Wires
67
  wire [15:0] write_data; // Data bus mux for 8 or 16 bit module bus
68
 
69
  //
70
  // module body
71
  //
72
 
73
  assign write_data = (DWIDTH == 8) ? {write_bus[7:0], write_bus[7:0]} : write_bus;
74
 
75
  assign pit_pre_scl = NO_PRESCALE ? 4'b0 : pit_pre;
76
 
77
  // generate wishbone write registers
78
  always @(posedge bus_clk or negedge async_rst_b)
79
    if (!async_rst_b)
80
      begin
81
        pit_slave   <= 1'b0;
82
        pit_pre     <= 4'b0;
83
        pit_flg_clr <= 1'b0;
84
        pit_ien     <= 1'b0;
85
        cnt_sync_o  <= 1'b0;
86
        mod_value   <= 0;
87
       end
88
    else if (sync_reset)
89
      begin
90
        pit_slave   <= 1'b0;
91
        pit_pre     <= 4'b0;
92
        pit_flg_clr <= 1'b0;
93
        pit_ien     <= 1'b0;
94
        cnt_sync_o  <= 1'b0;
95
        mod_value   <= 0;
96
      end
97
    else
98
      case (write_regs) // synopsys parallel_case
99
         4'b0011 :
100
           begin
101
             pit_slave   <= write_data[15];
102
             pit_pre     <= write_data[11:8];
103
             pit_flg_clr <= write_data[2];
104
             pit_ien     <= write_data[1];
105
             cnt_sync_o  <= write_data[0];
106
           end
107
         4'b0001 :
108
           begin
109
             pit_flg_clr <= write_data[2];
110
             pit_ien     <= write_data[1];
111
             cnt_sync_o  <= write_data[0];
112
           end
113
         4'b0010 :
114
           begin
115
             pit_slave   <= write_data[7];
116
             pit_pre     <= write_data[3:0];
117
           end
118
         4'b1100 : mod_value        <= write_data;
119
         4'b0100 : mod_value[ 7:0]  <= write_data[7:0];
120
         4'b1000 : mod_value[15:8]  <= write_data[7:0];
121
         default:
122
           pit_flg_clr <= 1'b0;
123
      endcase
124
 
125
  // generate interrupt request signals
126
  always @(posedge bus_clk or negedge async_rst_b)
127
    if (!async_rst_b)
128
      pit_irq_o <= 0;
129
    else if (sync_reset)
130
      pit_irq_o <= 0;
131
    else
132
      pit_irq_o <= cnt_flag_o && pit_ien; // interrupt signal is only generated
133
                                          //  when IEN (interrupt enable bit is set)
134
 
135
 
136
endmodule  // pit_regs

powered by: WebSVN 2.1.0

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