1 |
2 |
olivier.gi |
//----------------------------------------------------------------------------
|
2 |
117 |
olivier.gi |
// Copyright (C) 2009 , Olivier Girard
|
3 |
2 |
olivier.gi |
//
|
4 |
117 |
olivier.gi |
// Redistribution and use in source and binary forms, with or without
|
5 |
|
|
// modification, are permitted provided that the following conditions
|
6 |
|
|
// are met:
|
7 |
|
|
// * Redistributions of source code must retain the above copyright
|
8 |
|
|
// notice, this list of conditions and the following disclaimer.
|
9 |
|
|
// * Redistributions in binary form must reproduce the above copyright
|
10 |
|
|
// notice, this list of conditions and the following disclaimer in the
|
11 |
|
|
// documentation and/or other materials provided with the distribution.
|
12 |
|
|
// * Neither the name of the authors nor the names of its contributors
|
13 |
|
|
// may be used to endorse or promote products derived from this software
|
14 |
|
|
// without specific prior written permission.
|
15 |
2 |
olivier.gi |
//
|
16 |
117 |
olivier.gi |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17 |
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18 |
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
19 |
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
20 |
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
21 |
|
|
// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
22 |
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
23 |
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
24 |
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
25 |
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
26 |
|
|
// THE POSSIBILITY OF SUCH DAMAGE
|
27 |
2 |
olivier.gi |
//
|
28 |
|
|
//----------------------------------------------------------------------------
|
29 |
|
|
//
|
30 |
34 |
olivier.gi |
// *File Name: omsp_sfr.v
|
31 |
2 |
olivier.gi |
//
|
32 |
|
|
// *Module Description:
|
33 |
|
|
// Processor Special function register
|
34 |
|
|
//
|
35 |
|
|
// *Author(s):
|
36 |
|
|
// - Olivier Girard, olgirard@gmail.com
|
37 |
|
|
//
|
38 |
|
|
//----------------------------------------------------------------------------
|
39 |
17 |
olivier.gi |
// $Rev: 117 $
|
40 |
|
|
// $LastChangedBy: olivier.girard $
|
41 |
|
|
// $LastChangedDate: 2011-06-23 21:30:51 +0200 (Thu, 23 Jun 2011) $
|
42 |
|
|
//----------------------------------------------------------------------------
|
43 |
103 |
olivier.gi |
`ifdef OMSP_NO_INCLUDE
|
44 |
|
|
`else
|
45 |
23 |
olivier.gi |
`include "openMSP430_defines.v"
|
46 |
103 |
olivier.gi |
`endif
|
47 |
2 |
olivier.gi |
|
48 |
34 |
olivier.gi |
module omsp_sfr (
|
49 |
2 |
olivier.gi |
|
50 |
|
|
// OUTPUTs
|
51 |
|
|
nmie, // Non-maskable interrupt enable
|
52 |
|
|
per_dout, // Peripheral data output
|
53 |
|
|
wdt_irq, // Watchdog-timer interrupt
|
54 |
|
|
wdt_reset, // Watchdog-timer reset
|
55 |
|
|
wdtie, // Watchdog-timer interrupt enable
|
56 |
|
|
|
57 |
|
|
// INPUTs
|
58 |
|
|
mclk, // Main system clock
|
59 |
|
|
nmi_acc, // Non-Maskable interrupt request accepted
|
60 |
|
|
per_addr, // Peripheral address
|
61 |
|
|
per_din, // Peripheral data input
|
62 |
|
|
per_en, // Peripheral enable (high active)
|
63 |
106 |
olivier.gi |
per_we, // Peripheral write enable (high active)
|
64 |
2 |
olivier.gi |
por, // Power-on reset
|
65 |
111 |
olivier.gi |
puc_rst, // Main system reset
|
66 |
2 |
olivier.gi |
wdtifg_clr, // Clear Watchdog-timer interrupt flag
|
67 |
|
|
wdtifg_set, // Set Watchdog-timer interrupt flag
|
68 |
|
|
wdtpw_error, // Watchdog-timer password error
|
69 |
|
|
wdttmsel // Watchdog-timer mode select
|
70 |
|
|
);
|
71 |
|
|
|
72 |
|
|
// OUTPUTs
|
73 |
|
|
//=========
|
74 |
|
|
output nmie; // Non-maskable interrupt enable
|
75 |
|
|
output [15:0] per_dout; // Peripheral data output
|
76 |
|
|
output wdt_irq; // Watchdog-timer interrupt
|
77 |
|
|
output wdt_reset; // Watchdog-timer reset
|
78 |
|
|
output wdtie; // Watchdog-timer interrupt enable
|
79 |
|
|
|
80 |
|
|
// INPUTs
|
81 |
|
|
//=========
|
82 |
|
|
input mclk; // Main system clock
|
83 |
|
|
input nmi_acc; // Non-Maskable interrupt request accepted
|
84 |
111 |
olivier.gi |
input [13:0] per_addr; // Peripheral address
|
85 |
2 |
olivier.gi |
input [15:0] per_din; // Peripheral data input
|
86 |
|
|
input per_en; // Peripheral enable (high active)
|
87 |
106 |
olivier.gi |
input [1:0] per_we; // Peripheral write enable (high active)
|
88 |
2 |
olivier.gi |
input por; // Power-on reset
|
89 |
111 |
olivier.gi |
input puc_rst; // Main system reset
|
90 |
2 |
olivier.gi |
input wdtifg_clr; // Clear Watchdog-timer interrupt flag
|
91 |
|
|
input wdtifg_set; // Set Watchdog-timer interrupt flag
|
92 |
|
|
input wdtpw_error; // Watchdog-timer password error
|
93 |
|
|
input wdttmsel; // Watchdog-timer mode select
|
94 |
|
|
|
95 |
|
|
|
96 |
|
|
//=============================================================================
|
97 |
|
|
// 1) PARAMETER DECLARATION
|
98 |
|
|
//=============================================================================
|
99 |
|
|
|
100 |
111 |
olivier.gi |
// Register base address (must be aligned to decoder bit width)
|
101 |
|
|
parameter [14:0] BASE_ADDR = 15'h0000;
|
102 |
2 |
olivier.gi |
|
103 |
111 |
olivier.gi |
// Decoder bit width (defines how many bits are considered for address decoding)
|
104 |
|
|
parameter DEC_WD = 2;
|
105 |
|
|
|
106 |
|
|
// Register addresses offset
|
107 |
|
|
parameter [DEC_WD-1:0] IE1 = 'h0,
|
108 |
|
|
IFG1 = 'h2;
|
109 |
|
|
|
110 |
|
|
// Register one-hot decoder utilities
|
111 |
|
|
parameter DEC_SZ = 2**DEC_WD;
|
112 |
|
|
parameter [DEC_SZ-1:0] BASE_REG = {{DEC_SZ-1{1'b0}}, 1'b1};
|
113 |
|
|
|
114 |
2 |
olivier.gi |
// Register one-hot decoder
|
115 |
111 |
olivier.gi |
parameter [DEC_SZ-1:0] IE1_D = (BASE_REG << IE1),
|
116 |
|
|
IFG1_D = (BASE_REG << IFG1);
|
117 |
2 |
olivier.gi |
|
118 |
|
|
|
119 |
|
|
//============================================================================
|
120 |
|
|
// 2) REGISTER DECODER
|
121 |
|
|
//============================================================================
|
122 |
|
|
|
123 |
111 |
olivier.gi |
// Local register selection
|
124 |
|
|
wire reg_sel = per_en & (per_addr[13:DEC_WD-1]==BASE_ADDR[14:DEC_WD]);
|
125 |
|
|
|
126 |
|
|
// Register local address
|
127 |
|
|
wire [DEC_WD-1:0] reg_addr = {1'b0, per_addr[DEC_WD-2:0]};
|
128 |
|
|
|
129 |
2 |
olivier.gi |
// Register address decode
|
130 |
111 |
olivier.gi |
wire [DEC_SZ-1:0] reg_dec = (IE1_D & {DEC_SZ{(reg_addr==(IE1 >>1))}}) |
|
131 |
|
|
(IFG1_D & {DEC_SZ{(reg_addr==(IFG1 >>1))}});
|
132 |
2 |
olivier.gi |
|
133 |
|
|
// Read/Write probes
|
134 |
111 |
olivier.gi |
wire reg_lo_write = per_we[0] & reg_sel;
|
135 |
|
|
wire reg_hi_write = per_we[1] & reg_sel;
|
136 |
|
|
wire reg_read = ~|per_we & reg_sel;
|
137 |
2 |
olivier.gi |
|
138 |
|
|
// Read/Write vectors
|
139 |
111 |
olivier.gi |
wire [DEC_SZ-1:0] reg_hi_wr = reg_dec & {DEC_SZ{reg_hi_write}};
|
140 |
|
|
wire [DEC_SZ-1:0] reg_lo_wr = reg_dec & {DEC_SZ{reg_lo_write}};
|
141 |
|
|
wire [DEC_SZ-1:0] reg_rd = reg_dec & {DEC_SZ{reg_read}};
|
142 |
2 |
olivier.gi |
|
143 |
|
|
|
144 |
|
|
//============================================================================
|
145 |
|
|
// 3) REGISTERS
|
146 |
|
|
//============================================================================
|
147 |
|
|
|
148 |
|
|
// IE1 Register
|
149 |
|
|
//--------------
|
150 |
|
|
wire [7:0] ie1;
|
151 |
111 |
olivier.gi |
wire ie1_wr = IE1[0] ? reg_hi_wr[IE1] : reg_lo_wr[IE1];
|
152 |
|
|
wire [7:0] ie1_nxt = IE1[0] ? per_din[15:8] : per_din[7:0];
|
153 |
2 |
olivier.gi |
|
154 |
|
|
reg nmie;
|
155 |
111 |
olivier.gi |
always @ (posedge mclk or posedge puc_rst)
|
156 |
|
|
if (puc_rst) nmie <= 1'b0;
|
157 |
2 |
olivier.gi |
else if (nmi_acc) nmie <= 1'b0;
|
158 |
|
|
else if (ie1_wr) nmie <= ie1_nxt[4];
|
159 |
|
|
|
160 |
|
|
reg wdtie;
|
161 |
111 |
olivier.gi |
always @ (posedge mclk or posedge puc_rst)
|
162 |
|
|
if (puc_rst) wdtie <= 1'b0;
|
163 |
|
|
else if (ie1_wr) wdtie <= ie1_nxt[0];
|
164 |
2 |
olivier.gi |
|
165 |
|
|
assign ie1 = {3'b000, nmie, 3'b000, wdtie};
|
166 |
|
|
|
167 |
|
|
|
168 |
|
|
// IFG1 Register
|
169 |
|
|
//---------------
|
170 |
|
|
wire [7:0] ifg1;
|
171 |
111 |
olivier.gi |
wire ifg1_wr = IFG1[0] ? reg_hi_wr[IFG1] : reg_lo_wr[IFG1];
|
172 |
|
|
wire [7:0] ifg1_nxt = IFG1[0] ? per_din[15:8] : per_din[7:0];
|
173 |
2 |
olivier.gi |
|
174 |
|
|
reg nmiifg;
|
175 |
111 |
olivier.gi |
always @ (posedge mclk or posedge puc_rst)
|
176 |
|
|
if (puc_rst) nmiifg <= 1'b0;
|
177 |
2 |
olivier.gi |
else if (nmi_acc) nmiifg <= 1'b1;
|
178 |
|
|
else if (ifg1_wr) nmiifg <= ifg1_nxt[4];
|
179 |
|
|
|
180 |
|
|
reg wdtifg;
|
181 |
|
|
always @ (posedge mclk or posedge por)
|
182 |
|
|
if (por) wdtifg <= 1'b0;
|
183 |
|
|
else if (wdtifg_set) wdtifg <= 1'b1;
|
184 |
|
|
else if (wdttmsel & wdtifg_clr) wdtifg <= 1'b0;
|
185 |
|
|
else if (ifg1_wr) wdtifg <= ifg1_nxt[0];
|
186 |
|
|
|
187 |
|
|
assign ifg1 = {3'b000, nmiifg, 3'b000, wdtifg};
|
188 |
|
|
|
189 |
|
|
|
190 |
|
|
//============================================================================
|
191 |
|
|
// 4) DATA OUTPUT GENERATION
|
192 |
|
|
//============================================================================
|
193 |
|
|
|
194 |
|
|
// Data output mux
|
195 |
111 |
olivier.gi |
wire [15:0] ie1_rd = {8'h00, (ie1 & {8{reg_rd[IE1]}})} << (8 & {4{IE1[0]}});
|
196 |
|
|
wire [15:0] ifg1_rd = {8'h00, (ifg1 & {8{reg_rd[IFG1]}})} << (8 & {4{IFG1[0]}});
|
197 |
2 |
olivier.gi |
|
198 |
|
|
wire [15:0] per_dout = ie1_rd |
|
199 |
|
|
ifg1_rd;
|
200 |
|
|
|
201 |
|
|
|
202 |
|
|
//=============================================================================
|
203 |
|
|
// 5) WATCHDOG INTERRUPT & RESET
|
204 |
|
|
//=============================================================================
|
205 |
|
|
|
206 |
|
|
// Watchdog interrupt generation
|
207 |
|
|
//---------------------------------
|
208 |
|
|
wire wdt_irq = wdttmsel & wdtifg & wdtie;
|
209 |
|
|
|
210 |
|
|
|
211 |
|
|
// Watchdog reset generation
|
212 |
|
|
//-----------------------------
|
213 |
|
|
reg wdt_reset;
|
214 |
|
|
|
215 |
|
|
always @ (posedge mclk or posedge por)
|
216 |
|
|
if (por) wdt_reset <= 1'b0;
|
217 |
|
|
else wdt_reset <= wdtpw_error | (wdtifg_set & ~wdttmsel);
|
218 |
|
|
|
219 |
|
|
|
220 |
34 |
olivier.gi |
endmodule // omsp_sfr
|
221 |
33 |
olivier.gi |
|
222 |
103 |
olivier.gi |
`ifdef OMSP_NO_INCLUDE
|
223 |
|
|
`else
|
224 |
33 |
olivier.gi |
`include "openMSP430_undefines.v"
|
225 |
103 |
olivier.gi |
`endif
|