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

Subversion Repositories cop

[/] [cop/] [trunk/] [rtl/] [verilog/] [cop_regs.v] - Blame information for rev 11

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

Line No. Rev Author Line
1 2 rehayes
////////////////////////////////////////////////////////////////////////////////
2
//
3
//  Computer Operating Properly - Control registers
4
//
5
//  Author: Bob Hayes
6
//          rehayes@opencores.org
7
//
8
//  Downloaded from: http://www.opencores.org/projects/cop.....
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 cop_regs #(parameter ARST_LVL = 1'b0,      // asynchronous reset level
40
                  parameter INIT_ENA = 1'b1,      // COP Enabled after reset
41
                  parameter SERV_WD_0 = 16'h5555, // First Service Word
42
                  parameter SERV_WD_1 = 16'haaaa, // Second Service Word
43
                  parameter COUNT_SIZE = 16,
44
                  parameter DWIDTH = 16)
45
  (
46
  output reg [COUNT_SIZE-1:0] timeout_value,// COP timout Value
47
  output reg           [ 1:0] cop_irq_en,   // COP IRQ Enable/Value
48
  output reg                  debug_ena,    // Enable COP in system debug mode
49
  output reg                  stop_ena,     // Enable COP in system stop mode
50
  output reg                  wait_ena,     // Enable COP in system wait mode
51
  output reg                  cop_ena,      // Enable COP Timout Counter
52
  output reg                  cwp,          // COP write protect
53
  output reg                  clck,         // COP lock
54
  output reg                  reload_count, // COP System service complete
55
  output reg                  clear_event,  // Reset the COP event register
56
  input                       bus_clk,      // Control register bus clock
57
  input                       async_rst_b,  // Async reset signal
58
  input                       sync_reset,   // Syncronous reset signal
59
  input                       cop_flag,     // COP Rollover Flag
60
  input          [DWIDTH-1:0] write_bus,    // Write Data Bus
61 9 rehayes
  input                [ 4:0] write_regs    // Write Register strobes
62 2 rehayes
  );
63
 
64
 
65
  // registers
66
  reg         service_cop; // Service register to reload COP Timeout Counter
67
 
68
  // Wires
69
  wire [15:0] write_data; // Data bus mux for 8 or 16 bit module bus
70
 
71
  //
72
  // module body
73
  //
74
 
75
  assign write_data = (DWIDTH == 8) ? {write_bus[7:0], write_bus[7:0]} : write_bus;
76
 
77
 
78
  // generate wishbone write registers
79
  always @(posedge bus_clk or negedge async_rst_b)
80
    if (!async_rst_b)
81
      begin
82
        timeout_value <= {COUNT_SIZE{1'b1}};
83
        cop_irq_en    <= 2'b00;
84
        debug_ena     <= 1'b0;
85
        stop_ena      <= 1'b0;
86
        wait_ena      <= 1'b0;
87
        cop_ena       <= INIT_ENA;
88
        cwp           <= 1'b0;
89
        clck          <= 1'b0;
90
        reload_count  <= 1'b0;
91
        service_cop   <= 0;
92
       end
93
    else if (sync_reset)
94
      begin
95
        timeout_value <= {COUNT_SIZE{1'b1}};
96
        cop_irq_en    <= 2'b00;
97
        debug_ena     <= 1'b0;
98
        stop_ena      <= 1'b0;
99
        wait_ena      <= 1'b0;
100
        cop_ena       <= INIT_ENA;
101
        cwp           <= 1'b0;
102
        clck          <= 1'b0;
103
        reload_count  <= 1'b0;
104
        service_cop   <= 0;
105
      end
106
    else
107
      case (write_regs) // synopsys parallel_case
108
         5'b00011 :  // Word Write
109
           begin
110
             clear_event <= write_data[8];
111
             cop_irq_en  <= write_data[7:6];
112
             debug_ena   <= (!cop_ena || !write_data[2]) ? write_data[5] : debug_ena;
113
             stop_ena    <= (!cop_ena || !write_data[2]) ? write_data[4] : stop_ena;
114
             wait_ena    <= (!cop_ena || !write_data[2]) ? write_data[3] : wait_ena;
115
             cop_ena     <= cwp  ? cop_ena : write_data[2];
116
             cwp         <= clck ? cwp : write_data[1];
117
             clck        <= clck || write_data[0];
118
           end
119
         5'b00001 :  // Low Byte Write
120
           begin
121
             cop_irq_en  <= write_data[7:6];
122
             debug_ena   <= (!cop_ena || !write_data[2]) ? write_data[5] : debug_ena;
123
             stop_ena    <= (!cop_ena || !write_data[2]) ? write_data[4] : stop_ena;
124
             wait_ena    <= (!cop_ena || !write_data[2]) ? write_data[3] : wait_ena;
125
             cop_ena     <= cwp ? cop_ena : write_data[2];
126
             cwp         <= clck ? cwp : write_data[1];
127
             clck        <= clck || write_data[0];
128
           end
129
         5'b00010 :  // High Byte Write
130
           begin
131
             clear_event  <= write_data[0];
132
           end
133
 
134
         5'b01100 : timeout_value        <= cop_ena ? timeout_value : write_data;
135
         5'b00100 : timeout_value[ 7:0]  <= cop_ena ? timeout_value[ 7:0] : write_data[7:0];
136
         5'b01000 : timeout_value[15:8]  <= cop_ena ? timeout_value[15:8] : write_data[7:0];
137
 
138
         5'b10000 :
139
           begin
140
             service_cop  <= (write_data == SERV_WD_0);
141
             reload_count <= service_cop && (write_data == SERV_WD_1);
142
           end
143
         default:
144
           begin
145
             reload_count <= 1'b0;
146
             clear_event  <= 1'b0;
147
           end
148
      endcase
149
 
150
 
151
endmodule  // cop_regs

powered by: WebSVN 2.1.0

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