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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [fpga/] [actel_m1a3pl_dev_kit/] [rtl/] [verilog/] [openmsp430/] [omsp_watchdog.v] - Blame information for rev 112

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

Line No. Rev Author Line
1 80 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
// *File Name: omsp_watchdog.v
26
// 
27
// *Module Description:
28
//                       Watchdog Timer
29
//
30
// *Author(s):
31
//              - Olivier Girard,    olgirard@gmail.com
32
//
33
//----------------------------------------------------------------------------
34 111 olivier.gi
// $Rev: 103 $
35 80 olivier.gi
// $LastChangedBy: olivier.girard $
36 111 olivier.gi
// $LastChangedDate: 2011-03-05 15:44:48 +0100 (Sat, 05 Mar 2011) $
37 80 olivier.gi
//----------------------------------------------------------------------------
38 104 olivier.gi
`ifdef OMSP_NO_INCLUDE
39
`else
40 80 olivier.gi
`include "openMSP430_defines.v"
41 104 olivier.gi
`endif
42 80 olivier.gi
 
43
module  omsp_watchdog (
44
 
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 107 olivier.gi
    per_we,                         // Peripheral write enable (high active)
62 111 olivier.gi
    puc_rst,                        // Main system reset
63 80 olivier.gi
    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 111 olivier.gi
input        [13:0] per_addr;       // Peripheral address
83 80 olivier.gi
input        [15:0] per_din;        // Peripheral data input
84
input               per_en;         // Peripheral enable (high active)
85 107 olivier.gi
input         [1:0] per_we;         // Peripheral write enable (high active)
86 111 olivier.gi
input               puc_rst;        // Main system reset
87 80 olivier.gi
input               smclk_en;       // SMCLK enable
88
input               wdtie;          // Watchdog timer interrupt enable
89
 
90
 
91
//=============================================================================
92
// 1)  PARAMETER DECLARATION
93
//=============================================================================
94
 
95 111 olivier.gi
// Register base address (must be aligned to decoder bit width)
96
parameter       [14:0] BASE_ADDR   = 15'h0120;
97 80 olivier.gi
 
98 111 olivier.gi
// Decoder bit width (defines how many bits are considered for address decoding)
99
parameter              DEC_WD      =  2;
100 80 olivier.gi
 
101 111 olivier.gi
// Register addresses offset
102
parameter [DEC_WD-1:0] WDTCTL      = 'h0;
103
 
104
// Register one-hot decoder utilities
105
parameter              DEC_SZ      =  2**DEC_WD;
106
parameter [DEC_SZ-1:0] BASE_REG    =  {{DEC_SZ-1{1'b0}}, 1'b1};
107
 
108 80 olivier.gi
// Register one-hot decoder
109 111 olivier.gi
parameter [DEC_SZ-1:0] WDTCTL_D    = (BASE_REG << WDTCTL);
110 80 olivier.gi
 
111
 
112
//============================================================================
113
// 2)  REGISTER DECODER
114
//============================================================================
115
 
116 111 olivier.gi
// Local register selection
117
wire              reg_sel   =  per_en & (per_addr[13:DEC_WD-1]==BASE_ADDR[14:DEC_WD]);
118
 
119
// Register local address
120
wire [DEC_WD-1:0] reg_addr  =  {per_addr[DEC_WD-2:0], 1'b0};
121
 
122 80 olivier.gi
// Register address decode
123 111 olivier.gi
wire [DEC_SZ-1:0] reg_dec   =  (WDTCTL_D & {DEC_SZ{(reg_addr==WDTCTL)}});
124 80 olivier.gi
 
125
// Read/Write probes
126 111 olivier.gi
wire              reg_write =  |per_we & reg_sel;
127
wire              reg_read  = ~|per_we & reg_sel;
128 80 olivier.gi
 
129
// Read/Write vectors
130 111 olivier.gi
wire [DEC_SZ-1:0] reg_wr    = reg_dec & {DEC_SZ{reg_write}};
131
wire [DEC_SZ-1:0] reg_rd    = reg_dec & {DEC_SZ{reg_read}};
132 80 olivier.gi
 
133
 
134
//============================================================================
135
// 3) REGISTERS
136
//============================================================================
137
 
138
// WDTCTL Register
139
//-----------------
140
// WDTNMI & WDTSSEL are not implemented and therefore masked
141
 
142
reg  [7:0] wdtctl;
143
 
144
wire       wdtctl_wr = reg_wr[WDTCTL];
145
 
146 111 olivier.gi
always @ (posedge mclk or posedge puc_rst)
147
  if (puc_rst)        wdtctl <=  8'h00;
148 80 olivier.gi
  else if (wdtctl_wr) wdtctl <=  per_din[7:0] & 8'hd7;
149
 
150
wire       wdtpw_error = wdtctl_wr & (per_din[15:8]!=8'h5a);
151
wire       wdttmsel    = wdtctl[4];
152
 
153
 
154
//============================================================================
155
// 3) REGISTERS
156
//============================================================================
157
 
158
// Data output mux
159
wire [15:0] wdtctl_rd  = {8'h69, wdtctl}  & {16{reg_rd[WDTCTL]}};
160
 
161
wire [15:0] per_dout   =  wdtctl_rd;
162
 
163
 
164
//=============================================================================
165
// 4)  NMI GENERATION
166
//=============================================================================
167
 
168 111 olivier.gi
// Synchronization
169
wire   nmi_s;
170
`ifdef SYNC_NMI
171
omsp_sync_cell sync_cell_nmi (
172
    .data_out (nmi_s),
173
    .clk      (mclk),
174
    .data_in  (nmi),
175
    .rst      (puc_rst)
176
);
177
`else
178
assign nmi_s = nmi;
179
`endif
180
 
181
// Delay
182
reg  nmi_dly;
183
always @ (posedge mclk or posedge puc_rst)
184
  if (puc_rst) nmi_dly <= 1'b0;
185
  else         nmi_dly <= nmi_s;
186 80 olivier.gi
 
187
// Edge detection
188 111 olivier.gi
wire        nmi_re    = ~nmi_dly &  nmi_s & nmie;
189
wire        nmi_fe    =  nmi_dly & ~nmi_s & nmie;
190 80 olivier.gi
 
191
// NMI event
192
wire        nmi_evt   = wdtctl[6] ? nmi_fe : nmi_re;
193
 
194
 
195
//=============================================================================
196
// 5)  WATCHDOG TIMER
197
//=============================================================================
198
 
199
// Watchdog clock source selection
200
//---------------------------------
201
wire  clk_src_en = wdtctl[2] ? aclk_en : smclk_en;
202
 
203
 
204
// Watchdog 16 bit counter
205
//--------------------------
206
reg [15:0] wdtcnt;
207
 
208
wire       wdtcnt_clr = (wdtctl_wr & per_din[3]) | wdtifg_set;
209
 
210 111 olivier.gi
always @ (posedge mclk or posedge puc_rst)
211
  if (puc_rst)                                    wdtcnt <= 16'h0000;
212 80 olivier.gi
  else if (wdtcnt_clr)                            wdtcnt <= 16'h0000;
213
  else if (~wdtctl[7] & clk_src_en & ~dbg_freeze) wdtcnt <= wdtcnt+16'h0001;
214
 
215
 
216
// Interval selection mux
217
//--------------------------
218
reg        wdtqn;
219
 
220
always @(wdtctl or wdtcnt)
221
    case(wdtctl[1:0])
222
      2'b00  : wdtqn =  wdtcnt[15];
223
      2'b01  : wdtqn =  wdtcnt[13];
224
      2'b10  : wdtqn =  wdtcnt[9];
225
      default: wdtqn =  wdtcnt[6];
226
    endcase
227
 
228
 
229
// Watchdog event detection
230
//-----------------------------
231
reg        wdtqn_dly;
232
 
233 111 olivier.gi
always @ (posedge mclk or posedge puc_rst)
234
  if (puc_rst) wdtqn_dly <= 1'b0;
235
  else         wdtqn_dly <= wdtqn;
236 80 olivier.gi
 
237
wire       wdtifg_set =  (~wdtqn_dly & wdtqn) | wdtpw_error;
238
 
239
 
240
endmodule // omsp_watchdog
241
 
242 104 olivier.gi
`ifdef OMSP_NO_INCLUDE
243
`else
244 80 olivier.gi
`include "openMSP430_undefines.v"
245 104 olivier.gi
`endif

powered by: WebSVN 2.1.0

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