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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [core/] [rtl/] [verilog/] [omsp_watchdog.v] - Blame information for rev 108

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

Line No. Rev Author Line
1 2 olivier.gi
//----------------------------------------------------------------------------
2
// Copyright (C) 2001 Authors
3
//
4
// This source file may be used and distributed without restriction provided
5
// that this copyright statement is not removed from the file and that any
6
// derivative work contains the original copyright notice and the associated
7
// disclaimer.
8
//
9
// This source file is free software; you can redistribute it and/or modify
10
// it under the terms of the GNU Lesser General Public License as published
11
// by the Free Software Foundation; either version 2.1 of the License, or
12
// (at your option) any later version.
13
//
14
// This source is distributed in the hope that it will be useful, but WITHOUT
15
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17
// License for more details.
18
//
19
// You should have received a copy of the GNU Lesser General Public License
20
// along with this source; if not, write to the Free Software Foundation,
21
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
//
23
//----------------------------------------------------------------------------
24
//
25 34 olivier.gi
// *File Name: omsp_watchdog.v
26 2 olivier.gi
// 
27
// *Module Description:
28
//                       Watchdog Timer
29
//
30
// *Author(s):
31
//              - Olivier Girard,    olgirard@gmail.com
32
//
33
//----------------------------------------------------------------------------
34 17 olivier.gi
// $Rev: 106 $
35
// $LastChangedBy: olivier.girard $
36
// $LastChangedDate: 2011-03-25 23:01:03 +0100 (Fri, 25 Mar 2011) $
37
//----------------------------------------------------------------------------
38 103 olivier.gi
`ifdef OMSP_NO_INCLUDE
39
`else
40 23 olivier.gi
`include "openMSP430_defines.v"
41 103 olivier.gi
`endif
42 2 olivier.gi
 
43 34 olivier.gi
module  omsp_watchdog (
44 2 olivier.gi
 
45
// OUTPUTs
46
    nmi_evt,                        // NMI Event
47
    per_dout,                       // Peripheral data output
48
    wdtifg_set,                     // Set Watchdog-timer interrupt flag
49
    wdtpw_error,                    // Watchdog-timer password error
50
    wdttmsel,                       // Watchdog-timer mode select
51
 
52
// INPUTs
53
    aclk_en,                        // ACLK enable
54
    dbg_freeze,                     // Freeze Watchdog counter
55
    mclk,                           // Main system clock
56
    nmi,                            // Non-maskable interrupt (asynchronous)
57
    nmie,                           // Non-maskable interrupt enable
58
    per_addr,                       // Peripheral address
59
    per_din,                        // Peripheral data input
60
    per_en,                         // Peripheral enable (high active)
61 106 olivier.gi
    per_we,                         // Peripheral write enable (high active)
62 2 olivier.gi
    puc,                            // Main system reset
63
    smclk_en,                       // SMCLK enable
64
    wdtie                           // Watchdog timer interrupt enable
65
);
66
 
67
// OUTPUTs
68
//=========
69
output              nmi_evt;        // NMI Event
70
output       [15:0] per_dout;       // Peripheral data output
71
output              wdtifg_set;     // Set Watchdog-timer interrupt flag
72
output              wdtpw_error;    // Watchdog-timer password error
73
output              wdttmsel;       // Watchdog-timer mode select
74
 
75
// INPUTs
76
//=========
77
input               aclk_en;        // ACLK enable
78
input               dbg_freeze;     // Freeze Watchdog counter
79
input               mclk;           // Main system clock
80
input               nmi;            // Non-maskable interrupt (asynchronous)
81
input               nmie;           // Non-maskable interrupt enable
82
input         [7:0] per_addr;       // Peripheral address
83
input        [15:0] per_din;        // Peripheral data input
84
input               per_en;         // Peripheral enable (high active)
85 106 olivier.gi
input         [1:0] per_we;         // Peripheral write enable (high active)
86 2 olivier.gi
input               puc;            // Main system reset
87
input               smclk_en;       // SMCLK enable
88
input               wdtie;          // Watchdog timer interrupt enable
89
 
90
 
91
//=============================================================================
92
// 1)  PARAMETER DECLARATION
93
//=============================================================================
94
 
95
// Register addresses
96
parameter           WDTCTL     = 9'h120;
97
 
98
 
99
// Register one-hot decoder
100
parameter           WDTCTL_D   = (512'h1 << WDTCTL);
101
 
102
 
103
//============================================================================
104
// 2)  REGISTER DECODER
105
//============================================================================
106
 
107
// Register address decode
108
reg  [511:0]  reg_dec;
109
always @(per_addr)
110
  case ({per_addr,1'b0})
111
    WDTCTL :     reg_dec  =  WDTCTL_D;
112
    default:     reg_dec  =  {512{1'b0}};
113
  endcase
114
 
115
// Read/Write probes
116 106 olivier.gi
wire reg_write =  |per_we & per_en;
117
wire reg_read  = ~|per_we & per_en;
118 2 olivier.gi
 
119
// Read/Write vectors
120
wire [511:0] reg_wr    = reg_dec & {512{reg_write}};
121
wire [511:0] reg_rd    = reg_dec & {512{reg_read}};
122
 
123
 
124
//============================================================================
125
// 3) REGISTERS
126
//============================================================================
127
 
128
// WDTCTL Register
129
//-----------------
130
// WDTNMI & WDTSSEL are not implemented and therefore masked
131
 
132
reg  [7:0] wdtctl;
133
 
134
wire       wdtctl_wr = reg_wr[WDTCTL];
135
 
136
always @ (posedge mclk or posedge puc)
137
  if (puc)            wdtctl <=  8'h00;
138
  else if (wdtctl_wr) wdtctl <=  per_din[7:0] & 8'hd7;
139
 
140
wire       wdtpw_error = wdtctl_wr & (per_din[15:8]!=8'h5a);
141
wire       wdttmsel    = wdtctl[4];
142
 
143
 
144
//============================================================================
145
// 3) REGISTERS
146
//============================================================================
147
 
148
// Data output mux
149
wire [15:0] wdtctl_rd  = {8'h69, wdtctl}  & {16{reg_rd[WDTCTL]}};
150
 
151
wire [15:0] per_dout   =  wdtctl_rd;
152
 
153
 
154
//=============================================================================
155
// 4)  NMI GENERATION
156
//=============================================================================
157
 
158
// Synchronization state
159
reg [2:0] nmi_sync;
160
always @ (posedge mclk or posedge puc)
161
  if (puc)  nmi_sync <= 3'h0;
162
  else      nmi_sync <= {nmi_sync[1:0], nmi};
163
 
164
// Edge detection
165 84 olivier.gi
wire        nmi_re    = ~nmi_sync[2] &  nmi_sync[1] & nmie;
166
wire        nmi_fe    =  nmi_sync[2] & ~nmi_sync[1] & nmie;
167 2 olivier.gi
 
168
// NMI event
169
wire        nmi_evt   = wdtctl[6] ? nmi_fe : nmi_re;
170
 
171
 
172
//=============================================================================
173
// 5)  WATCHDOG TIMER
174
//=============================================================================
175
 
176
// Watchdog clock source selection
177
//---------------------------------
178
wire  clk_src_en = wdtctl[2] ? aclk_en : smclk_en;
179
 
180
 
181
// Watchdog 16 bit counter
182
//--------------------------
183
reg [15:0] wdtcnt;
184
 
185
wire       wdtcnt_clr = (wdtctl_wr & per_din[3]) | wdtifg_set;
186
 
187
always @ (posedge mclk or posedge puc)
188
  if (puc)                                        wdtcnt <= 16'h0000;
189
  else if (wdtcnt_clr)                            wdtcnt <= 16'h0000;
190
  else if (~wdtctl[7] & clk_src_en & ~dbg_freeze) wdtcnt <= wdtcnt+16'h0001;
191
 
192
 
193
// Interval selection mux
194
//--------------------------
195
reg        wdtqn;
196
 
197
always @(wdtctl or wdtcnt)
198
    case(wdtctl[1:0])
199
      2'b00  : wdtqn =  wdtcnt[15];
200
      2'b01  : wdtqn =  wdtcnt[13];
201
      2'b10  : wdtqn =  wdtcnt[9];
202
      default: wdtqn =  wdtcnt[6];
203
    endcase
204
 
205
 
206
// Watchdog event detection
207
//-----------------------------
208
reg        wdtqn_dly;
209
 
210
always @ (posedge mclk or posedge puc)
211
  if (puc) wdtqn_dly <= 1'b0;
212
  else     wdtqn_dly <= wdtqn;
213
 
214
wire       wdtifg_set =  (~wdtqn_dly & wdtqn) | wdtpw_error;
215
 
216
 
217 34 olivier.gi
endmodule // omsp_watchdog
218 2 olivier.gi
 
219 103 olivier.gi
`ifdef OMSP_NO_INCLUDE
220
`else
221 33 olivier.gi
`include "openMSP430_undefines.v"
222 103 olivier.gi
`endif

powered by: WebSVN 2.1.0

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