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_sfr.v
|
26 |
2 |
olivier.gi |
//
|
27 |
|
|
// *Module Description:
|
28 |
|
|
// Processor Special function register
|
29 |
|
|
//
|
30 |
|
|
// *Author(s):
|
31 |
|
|
// - Olivier Girard, olgirard@gmail.com
|
32 |
|
|
//
|
33 |
|
|
//----------------------------------------------------------------------------
|
34 |
17 |
olivier.gi |
// $Rev: 111 $
|
35 |
|
|
// $LastChangedBy: olivier.girard $
|
36 |
|
|
// $LastChangedDate: 2011-05-20 22:39:02 +0200 (Fri, 20 May 2011) $
|
37 |
|
|
//----------------------------------------------------------------------------
|
38 |
104 |
olivier.gi |
`ifdef OMSP_NO_INCLUDE
|
39 |
|
|
`else
|
40 |
23 |
olivier.gi |
`include "openMSP430_defines.v"
|
41 |
104 |
olivier.gi |
`endif
|
42 |
2 |
olivier.gi |
|
43 |
34 |
olivier.gi |
module omsp_sfr (
|
44 |
2 |
olivier.gi |
|
45 |
|
|
// OUTPUTs
|
46 |
|
|
nmie, // Non-maskable interrupt enable
|
47 |
|
|
per_dout, // Peripheral data output
|
48 |
|
|
wdt_irq, // Watchdog-timer interrupt
|
49 |
|
|
wdt_reset, // Watchdog-timer reset
|
50 |
|
|
wdtie, // Watchdog-timer interrupt enable
|
51 |
|
|
|
52 |
|
|
// INPUTs
|
53 |
|
|
mclk, // Main system clock
|
54 |
|
|
nmi_acc, // Non-Maskable interrupt request accepted
|
55 |
|
|
per_addr, // Peripheral address
|
56 |
|
|
per_din, // Peripheral data input
|
57 |
|
|
per_en, // Peripheral enable (high active)
|
58 |
109 |
olivier.gi |
per_we, // Peripheral write enable (high active)
|
59 |
2 |
olivier.gi |
por, // Power-on reset
|
60 |
111 |
olivier.gi |
puc_rst, // Main system reset
|
61 |
2 |
olivier.gi |
wdtifg_clr, // Clear Watchdog-timer interrupt flag
|
62 |
|
|
wdtifg_set, // Set Watchdog-timer interrupt flag
|
63 |
|
|
wdtpw_error, // Watchdog-timer password error
|
64 |
|
|
wdttmsel // Watchdog-timer mode select
|
65 |
|
|
);
|
66 |
|
|
|
67 |
|
|
// OUTPUTs
|
68 |
|
|
//=========
|
69 |
|
|
output nmie; // Non-maskable interrupt enable
|
70 |
|
|
output [15:0] per_dout; // Peripheral data output
|
71 |
|
|
output wdt_irq; // Watchdog-timer interrupt
|
72 |
|
|
output wdt_reset; // Watchdog-timer reset
|
73 |
|
|
output wdtie; // Watchdog-timer interrupt enable
|
74 |
|
|
|
75 |
|
|
// INPUTs
|
76 |
|
|
//=========
|
77 |
|
|
input mclk; // Main system clock
|
78 |
|
|
input nmi_acc; // Non-Maskable interrupt request accepted
|
79 |
111 |
olivier.gi |
input [13:0] per_addr; // Peripheral address
|
80 |
2 |
olivier.gi |
input [15:0] per_din; // Peripheral data input
|
81 |
|
|
input per_en; // Peripheral enable (high active)
|
82 |
109 |
olivier.gi |
input [1:0] per_we; // Peripheral write enable (high active)
|
83 |
2 |
olivier.gi |
input por; // Power-on reset
|
84 |
111 |
olivier.gi |
input puc_rst; // Main system reset
|
85 |
2 |
olivier.gi |
input wdtifg_clr; // Clear Watchdog-timer interrupt flag
|
86 |
|
|
input wdtifg_set; // Set Watchdog-timer interrupt flag
|
87 |
|
|
input wdtpw_error; // Watchdog-timer password error
|
88 |
|
|
input wdttmsel; // Watchdog-timer mode select
|
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'h0000;
|
97 |
2 |
olivier.gi |
|
98 |
111 |
olivier.gi |
// Decoder bit width (defines how many bits are considered for address decoding)
|
99 |
|
|
parameter DEC_WD = 2;
|
100 |
|
|
|
101 |
|
|
// Register addresses offset
|
102 |
|
|
parameter [DEC_WD-1:0] IE1 = 'h0,
|
103 |
|
|
IFG1 = 'h2;
|
104 |
|
|
|
105 |
|
|
// Register one-hot decoder utilities
|
106 |
|
|
parameter DEC_SZ = 2**DEC_WD;
|
107 |
|
|
parameter [DEC_SZ-1:0] BASE_REG = {{DEC_SZ-1{1'b0}}, 1'b1};
|
108 |
|
|
|
109 |
2 |
olivier.gi |
// Register one-hot decoder
|
110 |
111 |
olivier.gi |
parameter [DEC_SZ-1:0] IE1_D = (BASE_REG << IE1),
|
111 |
|
|
IFG1_D = (BASE_REG << IFG1);
|
112 |
2 |
olivier.gi |
|
113 |
|
|
|
114 |
|
|
//============================================================================
|
115 |
|
|
// 2) REGISTER DECODER
|
116 |
|
|
//============================================================================
|
117 |
|
|
|
118 |
111 |
olivier.gi |
// Local register selection
|
119 |
|
|
wire reg_sel = per_en & (per_addr[13:DEC_WD-1]==BASE_ADDR[14:DEC_WD]);
|
120 |
|
|
|
121 |
|
|
// Register local address
|
122 |
|
|
wire [DEC_WD-1:0] reg_addr = {1'b0, per_addr[DEC_WD-2:0]};
|
123 |
|
|
|
124 |
2 |
olivier.gi |
// Register address decode
|
125 |
111 |
olivier.gi |
wire [DEC_SZ-1:0] reg_dec = (IE1_D & {DEC_SZ{(reg_addr==(IE1 >>1))}}) |
|
126 |
|
|
(IFG1_D & {DEC_SZ{(reg_addr==(IFG1 >>1))}});
|
127 |
2 |
olivier.gi |
|
128 |
|
|
// Read/Write probes
|
129 |
111 |
olivier.gi |
wire reg_lo_write = per_we[0] & reg_sel;
|
130 |
|
|
wire reg_hi_write = per_we[1] & reg_sel;
|
131 |
|
|
wire reg_read = ~|per_we & reg_sel;
|
132 |
2 |
olivier.gi |
|
133 |
|
|
// Read/Write vectors
|
134 |
111 |
olivier.gi |
wire [DEC_SZ-1:0] reg_hi_wr = reg_dec & {DEC_SZ{reg_hi_write}};
|
135 |
|
|
wire [DEC_SZ-1:0] reg_lo_wr = reg_dec & {DEC_SZ{reg_lo_write}};
|
136 |
|
|
wire [DEC_SZ-1:0] reg_rd = reg_dec & {DEC_SZ{reg_read}};
|
137 |
2 |
olivier.gi |
|
138 |
|
|
|
139 |
|
|
//============================================================================
|
140 |
|
|
// 3) REGISTERS
|
141 |
|
|
//============================================================================
|
142 |
|
|
|
143 |
|
|
// IE1 Register
|
144 |
|
|
//--------------
|
145 |
|
|
wire [7:0] ie1;
|
146 |
111 |
olivier.gi |
wire ie1_wr = IE1[0] ? reg_hi_wr[IE1] : reg_lo_wr[IE1];
|
147 |
|
|
wire [7:0] ie1_nxt = IE1[0] ? per_din[15:8] : per_din[7:0];
|
148 |
2 |
olivier.gi |
|
149 |
|
|
reg nmie;
|
150 |
111 |
olivier.gi |
always @ (posedge mclk or posedge puc_rst)
|
151 |
|
|
if (puc_rst) nmie <= 1'b0;
|
152 |
2 |
olivier.gi |
else if (nmi_acc) nmie <= 1'b0;
|
153 |
|
|
else if (ie1_wr) nmie <= ie1_nxt[4];
|
154 |
|
|
|
155 |
|
|
reg wdtie;
|
156 |
111 |
olivier.gi |
always @ (posedge mclk or posedge puc_rst)
|
157 |
|
|
if (puc_rst) wdtie <= 1'b0;
|
158 |
|
|
else if (ie1_wr) wdtie <= ie1_nxt[0];
|
159 |
2 |
olivier.gi |
|
160 |
|
|
assign ie1 = {3'b000, nmie, 3'b000, wdtie};
|
161 |
|
|
|
162 |
|
|
|
163 |
|
|
// IFG1 Register
|
164 |
|
|
//---------------
|
165 |
|
|
wire [7:0] ifg1;
|
166 |
111 |
olivier.gi |
wire ifg1_wr = IFG1[0] ? reg_hi_wr[IFG1] : reg_lo_wr[IFG1];
|
167 |
|
|
wire [7:0] ifg1_nxt = IFG1[0] ? per_din[15:8] : per_din[7:0];
|
168 |
2 |
olivier.gi |
|
169 |
|
|
reg nmiifg;
|
170 |
111 |
olivier.gi |
always @ (posedge mclk or posedge puc_rst)
|
171 |
|
|
if (puc_rst) nmiifg <= 1'b0;
|
172 |
2 |
olivier.gi |
else if (nmi_acc) nmiifg <= 1'b1;
|
173 |
|
|
else if (ifg1_wr) nmiifg <= ifg1_nxt[4];
|
174 |
|
|
|
175 |
|
|
reg wdtifg;
|
176 |
|
|
always @ (posedge mclk or posedge por)
|
177 |
|
|
if (por) wdtifg <= 1'b0;
|
178 |
|
|
else if (wdtifg_set) wdtifg <= 1'b1;
|
179 |
|
|
else if (wdttmsel & wdtifg_clr) wdtifg <= 1'b0;
|
180 |
|
|
else if (ifg1_wr) wdtifg <= ifg1_nxt[0];
|
181 |
|
|
|
182 |
|
|
assign ifg1 = {3'b000, nmiifg, 3'b000, wdtifg};
|
183 |
|
|
|
184 |
|
|
|
185 |
|
|
//============================================================================
|
186 |
|
|
// 4) DATA OUTPUT GENERATION
|
187 |
|
|
//============================================================================
|
188 |
|
|
|
189 |
|
|
// Data output mux
|
190 |
111 |
olivier.gi |
wire [15:0] ie1_rd = {8'h00, (ie1 & {8{reg_rd[IE1]}})} << (8 & {4{IE1[0]}});
|
191 |
|
|
wire [15:0] ifg1_rd = {8'h00, (ifg1 & {8{reg_rd[IFG1]}})} << (8 & {4{IFG1[0]}});
|
192 |
2 |
olivier.gi |
|
193 |
|
|
wire [15:0] per_dout = ie1_rd |
|
194 |
|
|
ifg1_rd;
|
195 |
|
|
|
196 |
|
|
|
197 |
|
|
//=============================================================================
|
198 |
|
|
// 5) WATCHDOG INTERRUPT & RESET
|
199 |
|
|
//=============================================================================
|
200 |
|
|
|
201 |
|
|
// Watchdog interrupt generation
|
202 |
|
|
//---------------------------------
|
203 |
|
|
wire wdt_irq = wdttmsel & wdtifg & wdtie;
|
204 |
|
|
|
205 |
|
|
|
206 |
|
|
// Watchdog reset generation
|
207 |
|
|
//-----------------------------
|
208 |
|
|
reg wdt_reset;
|
209 |
|
|
|
210 |
|
|
always @ (posedge mclk or posedge por)
|
211 |
|
|
if (por) wdt_reset <= 1'b0;
|
212 |
|
|
else wdt_reset <= wdtpw_error | (wdtifg_set & ~wdttmsel);
|
213 |
|
|
|
214 |
|
|
|
215 |
34 |
olivier.gi |
endmodule // omsp_sfr
|
216 |
33 |
olivier.gi |
|
217 |
104 |
olivier.gi |
`ifdef OMSP_NO_INCLUDE
|
218 |
|
|
`else
|
219 |
33 |
olivier.gi |
`include "openMSP430_undefines.v"
|
220 |
104 |
olivier.gi |
`endif
|