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

Subversion Repositories pit

[/] [pit/] [trunk/] [rtl/] [sys_verilog/] [pit_regs.sv] - Blame information for rev 24

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 21 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) 2011, 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  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 24 rehayes
module pit_regs #(parameter COUNT_SIZE = 16,
40 21 rehayes
                  parameter NO_PRESCALE = 1'b0,
41
                  parameter DWIDTH = 16)
42
  (
43
  output logic [COUNT_SIZE-1:0] mod_value,    // Main Counter Modulo Value
44
  output                 [ 3:0] pit_pre_scl,  // PIT Prescaler Value
45
  output logic                  pit_slave,    // PIT Slave Mode
46
  output logic                  pit_flg_clr,  // Clear PIT Rollover Flag
47
  output logic                  pit_ien,      // PIT Interrupt Enable
48
  output logic                  cnt_sync_o,   // PIT Counter Enable
49
  output logic                  pit_irq_o,    // PIT interrupt
50
  input                         bus_clk,      // Control register bus clock
51
  input                         async_rst_b,  // Async reset signal
52
  input                         sync_reset,   // Syncronous reset signal
53
  input                         pit_flag,     // PIT Rollover Flag
54
  input            [DWIDTH-1:0] write_bus,    // Write Data Bus
55
  input                  [ 3:0] write_regs,   // Write Register strobes
56
  input                         cnt_flag_o    // Counter Rollover Flag
57
  );
58
 
59
 
60
  // registers
61
  logic [ 3:0] pit_pre;   // Optional register for PIT Prescale Counter modulo
62
                          //  This register should be removed durning synthesis
63
                          //  if the "NO_PRESCALE" parameter is set
64
 
65
  // Wires
66
  logic [15:0] write_data; // Data bus mux for 8 or 16 bit module bus
67
 
68
  //
69
  // module body
70
  //
71
 
72
  assign write_data = (DWIDTH == 8) ? {write_bus[7:0], write_bus[7:0]} : write_bus;
73
 
74
  assign pit_pre_scl = NO_PRESCALE ? 4'b0 : pit_pre;
75
 
76
  // generate wishbone write registers
77 22 rehayes
  always_ff @(posedge bus_clk or negedge async_rst_b)
78 21 rehayes
    if (!async_rst_b)
79
      begin
80
        pit_slave   <= 1'b0;
81
        pit_pre     <= 4'b0;
82
        pit_flg_clr <= 1'b0;
83
        pit_ien     <= 1'b0;
84
        cnt_sync_o  <= 1'b0;
85
        mod_value   <= 0;
86
       end
87
    else if (sync_reset)
88
      begin
89
        pit_slave   <= 1'b0;
90
        pit_pre     <= 4'b0;
91
        pit_flg_clr <= 1'b0;
92
        pit_ien     <= 1'b0;
93
        cnt_sync_o  <= 1'b0;
94
        mod_value   <= 0;
95
      end
96
    else
97
      case (write_regs) // synopsys parallel_case
98 24 rehayes
         4'b0011 :  // 16-bit write
99 21 rehayes
           begin
100
             pit_slave   <= write_data[15];
101
             pit_pre     <= write_data[11:8];
102
             pit_flg_clr <= write_data[2];
103
             pit_ien     <= write_data[1];
104
             cnt_sync_o  <= write_data[0];
105
           end
106 24 rehayes
         4'b0001 :  // 8-bit low byte write
107 21 rehayes
           begin
108
             pit_flg_clr <= write_data[2];
109
             pit_ien     <= write_data[1];
110
             cnt_sync_o  <= write_data[0];
111
           end
112 24 rehayes
         4'b0010 :  // 8-bit high byte write
113 21 rehayes
           begin
114
             pit_slave   <= write_data[7];
115
             pit_pre     <= write_data[3:0];
116
           end
117
         4'b1100 : mod_value        <= write_data;
118
         4'b0100 : mod_value[ 7:0]  <= write_data[7:0];
119
         4'b1000 : mod_value[15:8]  <= write_data[7:0];
120
         default:
121
           pit_flg_clr <= 1'b0;
122
      endcase
123
 
124
  // generate interrupt request signals
125 22 rehayes
  always_ff @(posedge bus_clk or negedge async_rst_b)
126 21 rehayes
    if (!async_rst_b)
127
      pit_irq_o <= 0;
128
    else if (sync_reset)
129
      pit_irq_o <= 0;
130
    else
131
      pit_irq_o <= cnt_flag_o && pit_ien; // interrupt signal is only generated
132
                                          //  when IEN (interrupt enable bit is set)
133
 
134
 
135
endmodule  // pit_regs

powered by: WebSVN 2.1.0

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