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

Subversion Repositories openmsp430

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

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

Line No. Rev Author Line
1 80 olivier.gi
//----------------------------------------------------------------------------
2 136 olivier.gi
// Copyright (C) 2009 , Olivier Girard
3 80 olivier.gi
//
4 136 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 80 olivier.gi
//
16 136 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 80 olivier.gi
//
28
//----------------------------------------------------------------------------
29
//
30
// *File Name: omsp_sfr.v
31
// 
32
// *Module Description:
33
//                       Processor Special function register
34 136 olivier.gi
//                       Non-Maskable Interrupt generation
35 80 olivier.gi
//
36
// *Author(s):
37
//              - Olivier Girard,    olgirard@gmail.com
38
//
39
//----------------------------------------------------------------------------
40 181 olivier.gi
// $Rev: 103 $
41 80 olivier.gi
// $LastChangedBy: olivier.girard $
42 181 olivier.gi
// $LastChangedDate: 2011-03-05 15:44:48 +0100 (Sat, 05 Mar 2011) $
43 80 olivier.gi
//----------------------------------------------------------------------------
44 104 olivier.gi
`ifdef OMSP_NO_INCLUDE
45
`else
46 80 olivier.gi
`include "openMSP430_defines.v"
47 104 olivier.gi
`endif
48 80 olivier.gi
 
49
module  omsp_sfr (
50
 
51
// OUTPUTs
52 136 olivier.gi
    cpu_id,                       // CPU ID
53
    nmi_pnd,                      // NMI Pending
54
    nmi_wkup,                     // NMI Wakeup
55 80 olivier.gi
    per_dout,                     // Peripheral data output
56
    wdtie,                        // Watchdog-timer interrupt enable
57 136 olivier.gi
    wdtifg_sw_clr,                // Watchdog-timer interrupt flag software clear
58
    wdtifg_sw_set,                // Watchdog-timer interrupt flag software set
59 80 olivier.gi
 
60
// INPUTs
61 155 olivier.gi
    cpu_nr_inst,                  // Current oMSP instance number
62
    cpu_nr_total,                 // Total number of oMSP instances-1
63 80 olivier.gi
    mclk,                         // Main system clock
64 136 olivier.gi
    nmi,                          // Non-maskable interrupt (asynchronous)
65 80 olivier.gi
    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 107 olivier.gi
    per_we,                       // Peripheral write enable (high active)
70 111 olivier.gi
    puc_rst,                      // Main system reset
71 136 olivier.gi
    scan_mode,                    // Scan mode
72
    wdtifg,                       // Watchdog-timer interrupt flag
73
    wdtnmies                      // Watchdog-timer NMI edge selection
74 80 olivier.gi
);
75
 
76
// OUTPUTs
77
//=========
78 136 olivier.gi
output       [31:0] cpu_id;       // CPU ID
79
output              nmi_pnd;      // NMI Pending
80
output              nmi_wkup;     // NMI Wakeup
81 80 olivier.gi
output       [15:0] per_dout;     // Peripheral data output
82
output              wdtie;        // Watchdog-timer interrupt enable
83 136 olivier.gi
output              wdtifg_sw_clr;// Watchdog-timer interrupt flag software clear
84
output              wdtifg_sw_set;// Watchdog-timer interrupt flag software set
85 80 olivier.gi
 
86
// INPUTs
87
//=========
88 155 olivier.gi
input         [7:0] cpu_nr_inst;  // Current oMSP instance number
89
input         [7:0] cpu_nr_total; // Total number of oMSP instances-1
90 80 olivier.gi
input               mclk;         // Main system clock
91 136 olivier.gi
input               nmi;          // Non-maskable interrupt (asynchronous)
92 80 olivier.gi
input               nmi_acc;      // Non-Maskable interrupt request accepted
93 111 olivier.gi
input        [13:0] per_addr;     // Peripheral address
94 80 olivier.gi
input        [15:0] per_din;      // Peripheral data input
95
input               per_en;       // Peripheral enable (high active)
96 107 olivier.gi
input         [1:0] per_we;       // Peripheral write enable (high active)
97 111 olivier.gi
input               puc_rst;      // Main system reset
98 136 olivier.gi
input               scan_mode;    // Scan mode
99
input               wdtifg;       // Watchdog-timer interrupt flag
100
input               wdtnmies;     // Watchdog-timer NMI edge selection
101 80 olivier.gi
 
102
 
103
//=============================================================================
104
// 1)  PARAMETER DECLARATION
105
//=============================================================================
106
 
107 111 olivier.gi
// Register base address (must be aligned to decoder bit width)
108
parameter       [14:0] BASE_ADDR   = 15'h0000;
109 80 olivier.gi
 
110 111 olivier.gi
// Decoder bit width (defines how many bits are considered for address decoding)
111 155 olivier.gi
parameter              DEC_WD      =  4;
112 111 olivier.gi
 
113
// Register addresses offset
114
parameter [DEC_WD-1:0] IE1         =  'h0,
115 136 olivier.gi
                       IFG1        =  'h2,
116
                       CPU_ID_LO   =  'h4,
117 155 olivier.gi
                       CPU_ID_HI   =  'h6,
118
                       CPU_NR      =  'h8;
119 111 olivier.gi
 
120
// Register one-hot decoder utilities
121 136 olivier.gi
parameter              DEC_SZ      =  (1 << DEC_WD);
122 111 olivier.gi
parameter [DEC_SZ-1:0] BASE_REG    =  {{DEC_SZ-1{1'b0}}, 1'b1};
123
 
124 80 olivier.gi
// Register one-hot decoder
125 111 olivier.gi
parameter [DEC_SZ-1:0] IE1_D       = (BASE_REG << IE1),
126 136 olivier.gi
                       IFG1_D      = (BASE_REG << IFG1),
127
                       CPU_ID_LO_D = (BASE_REG << CPU_ID_LO),
128 155 olivier.gi
                       CPU_ID_HI_D = (BASE_REG << CPU_ID_HI),
129
                       CPU_NR_D    = (BASE_REG << CPU_NR);
130 80 olivier.gi
 
131
 
132
//============================================================================
133
// 2)  REGISTER DECODER
134
//============================================================================
135
 
136 111 olivier.gi
// 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 80 olivier.gi
// Register address decode
143 136 olivier.gi
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 155 olivier.gi
                                 (CPU_ID_HI_D  &  {DEC_SZ{(reg_addr==(CPU_ID_HI >>1))}})  |
147
                                 (CPU_NR_D     &  {DEC_SZ{(reg_addr==(CPU_NR    >>1))}});
148 80 olivier.gi
 
149
// Read/Write probes
150 111 olivier.gi
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 80 olivier.gi
 
154
// Read/Write vectors
155 111 olivier.gi
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 80 olivier.gi
 
159
 
160
//============================================================================
161
// 3) REGISTERS
162
//============================================================================
163
 
164
// IE1 Register
165
//--------------
166
wire [7:0] ie1;
167 111 olivier.gi
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 80 olivier.gi
 
170 136 olivier.gi
`ifdef NMI
171 80 olivier.gi
reg        nmie;
172 111 olivier.gi
always @ (posedge mclk or posedge puc_rst)
173
  if (puc_rst)      nmie  <=  1'b0;
174 80 olivier.gi
  else if (nmi_acc) nmie  <=  1'b0;
175
  else if (ie1_wr)  nmie  <=  ie1_nxt[4];
176 136 olivier.gi
`else
177
wire       nmie  =  1'b0;
178
`endif
179 80 olivier.gi
 
180 136 olivier.gi
`ifdef WATCHDOG
181 80 olivier.gi
reg        wdtie;
182 111 olivier.gi
always @ (posedge mclk or posedge puc_rst)
183
  if (puc_rst)      wdtie <=  1'b0;
184
  else if (ie1_wr)  wdtie <=  ie1_nxt[0];
185 136 olivier.gi
`else
186
wire       wdtie =  1'b0;
187
`endif
188 80 olivier.gi
 
189
assign  ie1 = {3'b000, nmie, 3'b000, wdtie};
190
 
191
 
192
// IFG1 Register
193
//---------------
194
wire [7:0] ifg1;
195 136 olivier.gi
 
196 111 olivier.gi
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 80 olivier.gi
 
199 136 olivier.gi
`ifdef NMI
200 80 olivier.gi
reg        nmiifg;
201 136 olivier.gi
wire       nmi_edge;
202 111 olivier.gi
always @ (posedge mclk or posedge puc_rst)
203
  if (puc_rst)       nmiifg <=  1'b0;
204 136 olivier.gi
  else if (nmi_edge) nmiifg <=  1'b1;
205 80 olivier.gi
  else if (ifg1_wr)  nmiifg <=  ifg1_nxt[4];
206 136 olivier.gi
`else
207
wire       nmiifg = 1'b0;
208
`endif
209 80 olivier.gi
 
210 136 olivier.gi
`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 80 olivier.gi
 
218
assign  ifg1 = {3'b000, nmiifg, 3'b000, wdtifg};
219
 
220
 
221 136 olivier.gi
// 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 155 olivier.gi
// 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 80 olivier.gi
//============================================================================
270
// 4) DATA OUTPUT GENERATION
271
//============================================================================
272
 
273
// Data output mux
274 136 olivier.gi
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 155 olivier.gi
wire [15:0] cpu_nr_rd     = cpu_nr        & {16{reg_rd[CPU_NR]}};
279 80 olivier.gi
 
280 136 olivier.gi
wire [15:0] per_dout =  ie1_rd       |
281
                        ifg1_rd      |
282
                        cpu_id_lo_rd |
283 155 olivier.gi
                        cpu_id_hi_rd |
284
                        cpu_nr_rd;
285 80 olivier.gi
 
286
 
287
//=============================================================================
288 136 olivier.gi
// 5)  NMI GENERATION
289 80 olivier.gi
//=============================================================================
290 136 olivier.gi
// NOTE THAT THE NMI INPUT IS ASSUMED TO BE NON-GLITCHY
291
`ifdef NMI
292 80 olivier.gi
 
293 136 olivier.gi
//-----------------------------------
294
// Edge selection
295
//-----------------------------------
296
wire nmi_pol = nmi ^ wdtnmies;
297 80 olivier.gi
 
298 136 olivier.gi
//-----------------------------------
299
// Pulse capture and synchronization
300
//-----------------------------------
301
`ifdef SYNC_NMI
302 181 olivier.gi
  `ifdef ASIC_CLOCKING
303 136 olivier.gi
   // 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   nmi_capture = nmi_pol;
321
  `endif
322 80 olivier.gi
 
323 136 olivier.gi
   // Synchronization
324
   wire   nmi_s;
325
   omsp_sync_cell sync_cell_nmi (
326
       .data_out  (nmi_s),
327
       .data_in   (nmi_capture),
328
       .clk       (mclk),
329
       .rst       (puc_rst)
330
   );
331 80 olivier.gi
 
332 136 olivier.gi
`else
333
   wire   nmi_capture = nmi_pol;
334
   wire   nmi_s       = nmi_pol;
335
`endif
336 80 olivier.gi
 
337 136 olivier.gi
//-----------------------------------
338
// NMI Pending flag
339
//-----------------------------------
340
 
341
// Delay
342
reg  nmi_dly;
343
always @ (posedge mclk or posedge puc_rst)
344
  if (puc_rst) nmi_dly <= 1'b0;
345
  else         nmi_dly <= nmi_s;
346
 
347
// Edge detection
348
assign      nmi_edge  = ~nmi_dly & nmi_s;
349
 
350
// NMI pending
351
wire        nmi_pnd   = nmiifg & nmie;
352
 
353
// NMI wakeup
354 181 olivier.gi
`ifdef ASIC_CLOCKING
355 136 olivier.gi
wire        nmi_wkup;
356
omsp_and_gate and_nmi_wkup (.y(nmi_wkup), .a(nmi_capture ^ nmi_dly), .b(nmie));
357
`else
358
wire        nmi_wkup  = 1'b0;
359
`endif
360
 
361
`else
362
 
363
wire        nmi_pnd   = 1'b0;
364
wire        nmi_wkup  = 1'b0;
365
 
366
`endif
367
 
368 80 olivier.gi
endmodule // omsp_sfr
369
 
370 104 olivier.gi
`ifdef OMSP_NO_INCLUDE
371
`else
372 80 olivier.gi
`include "openMSP430_undefines.v"
373 104 olivier.gi
`endif

powered by: WebSVN 2.1.0

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