1 |
221 |
olivier.gi |
//----------------------------------------------------------------------------
|
2 |
|
|
// Copyright (C) 2009 , Olivier Girard
|
3 |
|
|
//
|
4 |
|
|
// 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 |
|
|
//
|
16 |
|
|
// 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 |
|
|
//
|
28 |
|
|
//----------------------------------------------------------------------------
|
29 |
|
|
//
|
30 |
|
|
// *File Name: omsp_sfr.v
|
31 |
|
|
//
|
32 |
|
|
// *Module Description:
|
33 |
|
|
// Processor Special function register
|
34 |
|
|
// Non-Maskable Interrupt generation
|
35 |
|
|
//
|
36 |
|
|
// *Author(s):
|
37 |
|
|
// - Olivier Girard, olgirard@gmail.com
|
38 |
|
|
//
|
39 |
|
|
//----------------------------------------------------------------------------
|
40 |
|
|
// $Rev$
|
41 |
|
|
// $LastChangedBy$
|
42 |
|
|
// $LastChangedDate$
|
43 |
|
|
//----------------------------------------------------------------------------
|
44 |
|
|
`ifdef OMSP_NO_INCLUDE
|
45 |
|
|
`else
|
46 |
|
|
`include "openMSP430_defines.v"
|
47 |
|
|
`endif
|
48 |
|
|
|
49 |
|
|
module omsp_sfr (
|
50 |
|
|
|
51 |
|
|
// OUTPUTs
|
52 |
|
|
cpu_id, // CPU ID
|
53 |
|
|
nmi_pnd, // NMI Pending
|
54 |
|
|
nmi_wkup, // NMI Wakeup
|
55 |
|
|
per_dout, // Peripheral data output
|
56 |
|
|
wdtie, // Watchdog-timer interrupt enable
|
57 |
|
|
wdtifg_sw_clr, // Watchdog-timer interrupt flag software clear
|
58 |
|
|
wdtifg_sw_set, // Watchdog-timer interrupt flag software set
|
59 |
|
|
|
60 |
|
|
// INPUTs
|
61 |
|
|
cpu_nr_inst, // Current oMSP instance number
|
62 |
|
|
cpu_nr_total, // Total number of oMSP instances-1
|
63 |
|
|
mclk, // Main system clock
|
64 |
|
|
nmi, // Non-maskable interrupt (asynchronous)
|
65 |
|
|
nmi_acc, // Non-Maskable interrupt request accepted
|
66 |
|
|
per_addr, // Peripheral address
|
67 |
|
|
per_din, // Peripheral data input
|
68 |
|
|
per_en, // Peripheral enable (high active)
|
69 |
|
|
per_we, // Peripheral write enable (high active)
|
70 |
|
|
puc_rst, // Main system reset
|
71 |
|
|
scan_mode, // Scan mode
|
72 |
|
|
wdtifg, // Watchdog-timer interrupt flag
|
73 |
|
|
wdtnmies // Watchdog-timer NMI edge selection
|
74 |
|
|
);
|
75 |
|
|
|
76 |
|
|
// OUTPUTs
|
77 |
|
|
//=========
|
78 |
|
|
output [31:0] cpu_id; // CPU ID
|
79 |
|
|
output nmi_pnd; // NMI Pending
|
80 |
|
|
output nmi_wkup; // NMI Wakeup
|
81 |
|
|
output [15:0] per_dout; // Peripheral data output
|
82 |
|
|
output wdtie; // Watchdog-timer interrupt enable
|
83 |
|
|
output wdtifg_sw_clr;// Watchdog-timer interrupt flag software clear
|
84 |
|
|
output wdtifg_sw_set;// Watchdog-timer interrupt flag software set
|
85 |
|
|
|
86 |
|
|
// INPUTs
|
87 |
|
|
//=========
|
88 |
|
|
input [7:0] cpu_nr_inst; // Current oMSP instance number
|
89 |
|
|
input [7:0] cpu_nr_total; // Total number of oMSP instances-1
|
90 |
|
|
input mclk; // Main system clock
|
91 |
|
|
input nmi; // Non-maskable interrupt (asynchronous)
|
92 |
|
|
input nmi_acc; // Non-Maskable interrupt request accepted
|
93 |
|
|
input [13:0] per_addr; // Peripheral address
|
94 |
|
|
input [15:0] per_din; // Peripheral data input
|
95 |
|
|
input per_en; // Peripheral enable (high active)
|
96 |
|
|
input [1:0] per_we; // Peripheral write enable (high active)
|
97 |
|
|
input puc_rst; // Main system reset
|
98 |
|
|
input scan_mode; // Scan mode
|
99 |
|
|
input wdtifg; // Watchdog-timer interrupt flag
|
100 |
|
|
input wdtnmies; // Watchdog-timer NMI edge selection
|
101 |
|
|
|
102 |
|
|
|
103 |
|
|
//=============================================================================
|
104 |
|
|
// 1) PARAMETER DECLARATION
|
105 |
|
|
//=============================================================================
|
106 |
|
|
|
107 |
|
|
// Register base address (must be aligned to decoder bit width)
|
108 |
|
|
parameter [14:0] BASE_ADDR = 15'h0000;
|
109 |
|
|
|
110 |
|
|
// Decoder bit width (defines how many bits are considered for address decoding)
|
111 |
|
|
parameter DEC_WD = 4;
|
112 |
|
|
|
113 |
|
|
// Register addresses offset
|
114 |
|
|
parameter [DEC_WD-1:0] IE1 = 'h0,
|
115 |
|
|
IFG1 = 'h2,
|
116 |
|
|
CPU_ID_LO = 'h4,
|
117 |
|
|
CPU_ID_HI = 'h6,
|
118 |
|
|
CPU_NR = 'h8;
|
119 |
|
|
|
120 |
|
|
// Register one-hot decoder utilities
|
121 |
|
|
parameter DEC_SZ = (1 << DEC_WD);
|
122 |
|
|
parameter [DEC_SZ-1:0] BASE_REG = {{DEC_SZ-1{1'b0}}, 1'b1};
|
123 |
|
|
|
124 |
|
|
// Register one-hot decoder
|
125 |
|
|
parameter [DEC_SZ-1:0] IE1_D = (BASE_REG << IE1),
|
126 |
|
|
IFG1_D = (BASE_REG << IFG1),
|
127 |
|
|
CPU_ID_LO_D = (BASE_REG << CPU_ID_LO),
|
128 |
|
|
CPU_ID_HI_D = (BASE_REG << CPU_ID_HI),
|
129 |
|
|
CPU_NR_D = (BASE_REG << CPU_NR);
|
130 |
|
|
|
131 |
|
|
|
132 |
|
|
//============================================================================
|
133 |
|
|
// 2) REGISTER DECODER
|
134 |
|
|
//============================================================================
|
135 |
|
|
|
136 |
|
|
// Local register selection
|
137 |
|
|
wire reg_sel = per_en & (per_addr[13:DEC_WD-1]==BASE_ADDR[14:DEC_WD]);
|
138 |
|
|
|
139 |
|
|
// Register local address
|
140 |
|
|
wire [DEC_WD-1:0] reg_addr = {1'b0, per_addr[DEC_WD-2:0]};
|
141 |
|
|
|
142 |
|
|
// Register address decode
|
143 |
|
|
wire [DEC_SZ-1:0] reg_dec = (IE1_D & {DEC_SZ{(reg_addr==(IE1 >>1))}}) |
|
144 |
|
|
(IFG1_D & {DEC_SZ{(reg_addr==(IFG1 >>1))}}) |
|
145 |
|
|
(CPU_ID_LO_D & {DEC_SZ{(reg_addr==(CPU_ID_LO >>1))}}) |
|
146 |
|
|
(CPU_ID_HI_D & {DEC_SZ{(reg_addr==(CPU_ID_HI >>1))}}) |
|
147 |
|
|
(CPU_NR_D & {DEC_SZ{(reg_addr==(CPU_NR >>1))}});
|
148 |
|
|
|
149 |
|
|
// Read/Write probes
|
150 |
|
|
wire reg_lo_write = per_we[0] & reg_sel;
|
151 |
|
|
wire reg_hi_write = per_we[1] & reg_sel;
|
152 |
|
|
wire reg_read = ~|per_we & reg_sel;
|
153 |
|
|
|
154 |
|
|
// Read/Write vectors
|
155 |
|
|
wire [DEC_SZ-1:0] reg_hi_wr = reg_dec & {DEC_SZ{reg_hi_write}};
|
156 |
|
|
wire [DEC_SZ-1:0] reg_lo_wr = reg_dec & {DEC_SZ{reg_lo_write}};
|
157 |
|
|
wire [DEC_SZ-1:0] reg_rd = reg_dec & {DEC_SZ{reg_read}};
|
158 |
|
|
|
159 |
|
|
|
160 |
|
|
//============================================================================
|
161 |
|
|
// 3) REGISTERS
|
162 |
|
|
//============================================================================
|
163 |
|
|
|
164 |
|
|
// IE1 Register
|
165 |
|
|
//--------------
|
166 |
|
|
wire [7:0] ie1;
|
167 |
|
|
wire ie1_wr = IE1[0] ? reg_hi_wr[IE1] : reg_lo_wr[IE1];
|
168 |
|
|
wire [7:0] ie1_nxt = IE1[0] ? per_din[15:8] : per_din[7:0];
|
169 |
|
|
|
170 |
|
|
`ifdef NMI
|
171 |
|
|
reg nmie;
|
172 |
|
|
always @ (posedge mclk or posedge puc_rst)
|
173 |
|
|
if (puc_rst) nmie <= 1'b0;
|
174 |
|
|
else if (nmi_acc) nmie <= 1'b0;
|
175 |
|
|
else if (ie1_wr) nmie <= ie1_nxt[4];
|
176 |
|
|
`else
|
177 |
|
|
wire nmie = 1'b0;
|
178 |
|
|
`endif
|
179 |
|
|
|
180 |
|
|
`ifdef WATCHDOG
|
181 |
|
|
reg wdtie;
|
182 |
|
|
always @ (posedge mclk or posedge puc_rst)
|
183 |
|
|
if (puc_rst) wdtie <= 1'b0;
|
184 |
|
|
else if (ie1_wr) wdtie <= ie1_nxt[0];
|
185 |
|
|
`else
|
186 |
|
|
wire wdtie = 1'b0;
|
187 |
|
|
`endif
|
188 |
|
|
|
189 |
|
|
assign ie1 = {3'b000, nmie, 3'b000, wdtie};
|
190 |
|
|
|
191 |
|
|
|
192 |
|
|
// IFG1 Register
|
193 |
|
|
//---------------
|
194 |
|
|
wire [7:0] ifg1;
|
195 |
|
|
|
196 |
|
|
wire ifg1_wr = IFG1[0] ? reg_hi_wr[IFG1] : reg_lo_wr[IFG1];
|
197 |
|
|
wire [7:0] ifg1_nxt = IFG1[0] ? per_din[15:8] : per_din[7:0];
|
198 |
|
|
|
199 |
|
|
`ifdef NMI
|
200 |
|
|
reg nmiifg;
|
201 |
|
|
wire nmi_edge;
|
202 |
|
|
always @ (posedge mclk or posedge puc_rst)
|
203 |
|
|
if (puc_rst) nmiifg <= 1'b0;
|
204 |
|
|
else if (nmi_edge) nmiifg <= 1'b1;
|
205 |
|
|
else if (ifg1_wr) nmiifg <= ifg1_nxt[4];
|
206 |
|
|
`else
|
207 |
|
|
wire nmiifg = 1'b0;
|
208 |
|
|
`endif
|
209 |
|
|
|
210 |
|
|
`ifdef WATCHDOG
|
211 |
|
|
assign wdtifg_sw_clr = ifg1_wr & ~ifg1_nxt[0];
|
212 |
|
|
assign wdtifg_sw_set = ifg1_wr & ifg1_nxt[0];
|
213 |
|
|
`else
|
214 |
|
|
assign wdtifg_sw_clr = 1'b0;
|
215 |
|
|
assign wdtifg_sw_set = 1'b0;
|
216 |
|
|
`endif
|
217 |
|
|
|
218 |
|
|
assign ifg1 = {3'b000, nmiifg, 3'b000, wdtifg};
|
219 |
|
|
|
220 |
|
|
|
221 |
|
|
// CPU_ID Register (READ ONLY)
|
222 |
|
|
//-----------------------------
|
223 |
|
|
// -------------------------------------------------------------------
|
224 |
|
|
// CPU_ID_LO: | 15 14 13 12 11 10 9 | 8 7 6 5 4 | 3 | 2 1 0 |
|
225 |
|
|
// |----------------------------+-----------------+------+-------------|
|
226 |
|
|
// | PER_SPACE | USER_VERSION | ASIC | CPU_VERSION |
|
227 |
|
|
// --------------------------------------------------------------------
|
228 |
|
|
// CPU_ID_HI: | 15 14 13 12 11 10 | 9 8 7 6 5 4 3 2 1 | 0 |
|
229 |
|
|
// |----------------------------+-------------------------------+------|
|
230 |
|
|
// | PMEM_SIZE | DMEM_SIZE | MPY |
|
231 |
|
|
// -------------------------------------------------------------------
|
232 |
|
|
|
233 |
|
|
wire [2:0] cpu_version = `CPU_VERSION;
|
234 |
|
|
`ifdef ASIC
|
235 |
|
|
wire cpu_asic = 1'b1;
|
236 |
|
|
`else
|
237 |
|
|
wire cpu_asic = 1'b0;
|
238 |
|
|
`endif
|
239 |
|
|
wire [4:0] user_version = `USER_VERSION;
|
240 |
|
|
wire [6:0] per_space = (`PER_SIZE >> 9); // cpu_id_per * 512 = peripheral space size
|
241 |
|
|
`ifdef MULTIPLIER
|
242 |
|
|
wire mpy_info = 1'b1;
|
243 |
|
|
`else
|
244 |
|
|
wire mpy_info = 1'b0;
|
245 |
|
|
`endif
|
246 |
|
|
wire [8:0] dmem_size = (`DMEM_SIZE >> 7); // cpu_id_dmem * 128 = data memory size
|
247 |
|
|
wire [5:0] pmem_size = (`PMEM_SIZE >> 10); // cpu_id_pmem * 1024 = program memory size
|
248 |
|
|
|
249 |
|
|
assign cpu_id = {pmem_size,
|
250 |
|
|
dmem_size,
|
251 |
|
|
mpy_info,
|
252 |
|
|
per_space,
|
253 |
|
|
user_version,
|
254 |
|
|
cpu_asic,
|
255 |
|
|
cpu_version};
|
256 |
|
|
|
257 |
|
|
|
258 |
|
|
// CPU_NR Register (READ ONLY)
|
259 |
|
|
//-----------------------------
|
260 |
|
|
// -------------------------------------------------------------------
|
261 |
|
|
// | 15 14 13 12 11 10 9 8 | 7 6 5 4 3 2 1 0 |
|
262 |
|
|
// |---------------------------------+---------------------------------|
|
263 |
|
|
// | CPU_TOTAL_NR | CPU_INST_NR |
|
264 |
|
|
// -------------------------------------------------------------------
|
265 |
|
|
|
266 |
|
|
wire [15:0] cpu_nr = {cpu_nr_total, cpu_nr_inst};
|
267 |
|
|
|
268 |
|
|
|
269 |
|
|
//============================================================================
|
270 |
|
|
// 4) DATA OUTPUT GENERATION
|
271 |
|
|
//============================================================================
|
272 |
|
|
|
273 |
|
|
// Data output mux
|
274 |
|
|
wire [15:0] ie1_rd = {8'h00, (ie1 & {8{reg_rd[IE1]}})} << (8 & {4{IE1[0]}});
|
275 |
|
|
wire [15:0] ifg1_rd = {8'h00, (ifg1 & {8{reg_rd[IFG1]}})} << (8 & {4{IFG1[0]}});
|
276 |
|
|
wire [15:0] cpu_id_lo_rd = cpu_id[15:0] & {16{reg_rd[CPU_ID_LO]}};
|
277 |
|
|
wire [15:0] cpu_id_hi_rd = cpu_id[31:16] & {16{reg_rd[CPU_ID_HI]}};
|
278 |
|
|
wire [15:0] cpu_nr_rd = cpu_nr & {16{reg_rd[CPU_NR]}};
|
279 |
|
|
|
280 |
|
|
wire [15:0] per_dout = ie1_rd |
|
281 |
|
|
ifg1_rd |
|
282 |
|
|
cpu_id_lo_rd |
|
283 |
|
|
cpu_id_hi_rd |
|
284 |
|
|
cpu_nr_rd;
|
285 |
|
|
|
286 |
|
|
|
287 |
|
|
//=============================================================================
|
288 |
|
|
// 5) NMI GENERATION
|
289 |
|
|
//=============================================================================
|
290 |
|
|
// NOTE THAT THE NMI INPUT IS ASSUMED TO BE NON-GLITCHY
|
291 |
|
|
`ifdef NMI
|
292 |
|
|
|
293 |
|
|
//-----------------------------------
|
294 |
|
|
// Edge selection
|
295 |
|
|
//-----------------------------------
|
296 |
|
|
wire nmi_pol = nmi ^ wdtnmies;
|
297 |
|
|
|
298 |
|
|
//-----------------------------------
|
299 |
|
|
// Pulse capture and synchronization
|
300 |
|
|
//-----------------------------------
|
301 |
|
|
`ifdef SYNC_NMI
|
302 |
|
|
`ifdef ASIC_CLOCKING
|
303 |
|
|
// Glitch free reset for the event capture
|
304 |
|
|
reg nmi_capture_rst;
|
305 |
|
|
always @(posedge mclk or posedge puc_rst)
|
306 |
|
|
if (puc_rst) nmi_capture_rst <= 1'b1;
|
307 |
|
|
else nmi_capture_rst <= ifg1_wr & ~ifg1_nxt[4];
|
308 |
|
|
|
309 |
|
|
// NMI event capture
|
310 |
|
|
wire nmi_capture;
|
311 |
|
|
omsp_wakeup_cell wakeup_cell_nmi (
|
312 |
|
|
.wkup_out (nmi_capture), // Wakup signal (asynchronous)
|
313 |
|
|
.scan_clk (mclk), // Scan clock
|
314 |
|
|
.scan_mode (scan_mode), // Scan mode
|
315 |
|
|
.scan_rst (puc_rst), // Scan reset
|
316 |
|
|
.wkup_clear (nmi_capture_rst), // Glitch free wakeup event clear
|
317 |
|
|
.wkup_event (nmi_pol) // Glitch free asynchronous wakeup event
|
318 |
|
|
);
|
319 |
|
|
`else
|
320 |
|
|
wire UNUSED_scan_mode = scan_mode;
|
321 |
|
|
wire nmi_capture = nmi_pol;
|
322 |
|
|
`endif
|
323 |
|
|
|
324 |
|
|
// Synchronization
|
325 |
|
|
wire nmi_s;
|
326 |
|
|
omsp_sync_cell sync_cell_nmi (
|
327 |
|
|
.data_out (nmi_s),
|
328 |
|
|
.data_in (nmi_capture),
|
329 |
|
|
.clk (mclk),
|
330 |
|
|
.rst (puc_rst)
|
331 |
|
|
);
|
332 |
|
|
|
333 |
|
|
`else
|
334 |
|
|
wire UNUSED_scan_mode = scan_mode;
|
335 |
|
|
wire nmi_capture = nmi_pol;
|
336 |
|
|
wire nmi_s = nmi_pol;
|
337 |
|
|
`endif
|
338 |
|
|
|
339 |
|
|
//-----------------------------------
|
340 |
|
|
// NMI Pending flag
|
341 |
|
|
//-----------------------------------
|
342 |
|
|
|
343 |
|
|
// Delay
|
344 |
|
|
reg nmi_dly;
|
345 |
|
|
always @ (posedge mclk or posedge puc_rst)
|
346 |
|
|
if (puc_rst) nmi_dly <= 1'b0;
|
347 |
|
|
else nmi_dly <= nmi_s;
|
348 |
|
|
|
349 |
|
|
// Edge detection
|
350 |
|
|
assign nmi_edge = ~nmi_dly & nmi_s;
|
351 |
|
|
|
352 |
|
|
// NMI pending
|
353 |
|
|
wire nmi_pnd = nmiifg & nmie;
|
354 |
|
|
|
355 |
|
|
// NMI wakeup
|
356 |
|
|
`ifdef ASIC_CLOCKING
|
357 |
|
|
wire nmi_wkup;
|
358 |
|
|
omsp_and_gate and_nmi_wkup (.y(nmi_wkup), .a(nmi_capture ^ nmi_dly), .b(nmie));
|
359 |
|
|
`else
|
360 |
|
|
wire nmi_wkup = 1'b0;
|
361 |
|
|
`endif
|
362 |
|
|
|
363 |
|
|
`else
|
364 |
|
|
|
365 |
|
|
wire nmi_pnd = 1'b0;
|
366 |
|
|
wire nmi_wkup = 1'b0;
|
367 |
|
|
wire UNUSED_scan_mode = scan_mode;
|
368 |
|
|
wire UNUSED_nmi = nmi;
|
369 |
|
|
wire UNUSED_nmi_acc = nmi_acc;
|
370 |
|
|
wire UNUSED_wdtnmies = wdtnmies;
|
371 |
|
|
`endif
|
372 |
|
|
|
373 |
|
|
// LINT cleanup
|
374 |
|
|
wire [7:0] UNUSED_per_din_15_8 = per_din[15:8];
|
375 |
|
|
|
376 |
|
|
endmodule // omsp_sfr
|
377 |
|
|
|
378 |
|
|
`ifdef OMSP_NO_INCLUDE
|
379 |
|
|
`else
|
380 |
|
|
`include "openMSP430_undefines.v"
|
381 |
|
|
`endif
|