1 //----------------------------------------------------------------------------
2 // Copyright (C) 2001 Authors
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
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.
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.
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
23 //----------------------------------------------------------------------------
25 // *File Name: omsp_gpio.v
27 // *Module Description:
28 // Digital I/O interface
31 // - Olivier Girard, olgirard@gmail.com
33 //----------------------------------------------------------------------------
35 // $LastChangedBy: olivier.girard $
36 // $LastChangedDate: 2010-11-23 20:36:16 +0100 (Tue, 23 Nov 2010) $
37 //----------------------------------------------------------------------------
38 `include "timescale.v"
39 `include "openMSP430_defines.v"
44 irq_port1, // Port 1 interrupt
45 irq_port2, // Port 2 interrupt
46 p1_dout, // Port 1 data output
47 p1_dout_en, // Port 1 data output enable
48 p1_sel, // Port 1 function select
49 p2_dout, // Port 2 data output
50 p2_dout_en, // Port 2 data output enable
51 p2_sel, // Port 2 function select
52 p3_dout, // Port 3 data output
53 p3_dout_en, // Port 3 data output enable
54 p3_sel, // Port 3 function select
55 p4_dout, // Port 4 data output
56 p4_dout_en, // Port 4 data output enable
57 p4_sel, // Port 4 function select
58 p5_dout, // Port 5 data output
59 p5_dout_en, // Port 5 data output enable
60 p5_sel, // Port 5 function select
61 p6_dout, // Port 6 data output
62 p6_dout_en, // Port 6 data output enable
63 p6_sel, // Port 6 function select
64 per_dout, // Peripheral data output
67 mclk, // Main system clock
68 p1_din, // Port 1 data input
69 p2_din, // Port 2 data input
70 p3_din, // Port 3 data input
71 p4_din, // Port 4 data input
72 p5_din, // Port 5 data input
73 p6_din, // Port 6 data input
74 per_addr, // Peripheral address
75 per_din, // Peripheral data input
76 per_en, // Peripheral enable (high active)
77 per_wen, // Peripheral write enable (high active)
78 puc // Main system reset
83 parameter P1_EN = 1'b1; // Enable Port 1
84 parameter P2_EN = 1'b1; // Enable Port 2
85 parameter P3_EN = 1'b0; // Enable Port 3
86 parameter P4_EN = 1'b0; // Enable Port 4
87 parameter P5_EN = 1'b0; // Enable Port 5
88 parameter P6_EN = 1'b0; // Enable Port 6
93 output irq_port1; // Port 1 interrupt
94 output irq_port2; // Port 2 interrupt
95 output [7:0] p1_dout; // Port 1 data output
96 output [7:0] p1_dout_en; // Port 1 data output enable
97 output [7:0] p1_sel; // Port 1 function select
98 output [7:0] p2_dout; // Port 2 data output
99 output [7:0] p2_dout_en; // Port 2 data output enable
100 output [7:0] p2_sel; // Port 2 function select
101 output [7:0] p3_dout; // Port 3 data output
102 output [7:0] p3_dout_en; // Port 3 data output enable
103 output [7:0] p3_sel; // Port 3 function select
104 output [7:0] p4_dout; // Port 4 data output
105 output [7:0] p4_dout_en; // Port 4 data output enable
106 output [7:0] p4_sel; // Port 4 function select
107 output [7:0] p5_dout; // Port 5 data output
108 output [7:0] p5_dout_en; // Port 5 data output enable
109 output [7:0] p5_sel; // Port 5 function select
110 output [7:0] p6_dout; // Port 6 data output
111 output [7:0] p6_dout_en; // Port 6 data output enable
112 output [7:0] p6_sel; // Port 6 function select
113 output [15:0] per_dout; // Peripheral data output
117 input mclk; // Main system clock
118 input [7:0] p1_din; // Port 1 data input
119 input [7:0] p2_din; // Port 2 data input
120 input [7:0] p3_din; // Port 3 data input
121 input [7:0] p4_din; // Port 4 data input
122 input [7:0] p5_din; // Port 5 data input
123 input [7:0] p6_din; // Port 6 data input
124 input [7:0] per_addr; // Peripheral address
125 input [15:0] per_din; // Peripheral data input
126 input per_en; // Peripheral enable (high active)
127 input [1:0] per_wen; // Peripheral write enable (high active)
128 input puc; // Main system reset
131 //=============================================================================
132 // 1) PARAMETER DECLARATION
133 //=============================================================================
136 parameter P1_EN_MSK = {8{P1_EN[0]}};
137 parameter P2_EN_MSK = {8{P2_EN[0]}};
138 parameter P3_EN_MSK = {8{P3_EN[0]}};
139 parameter P4_EN_MSK = {8{P4_EN[0]}};
140 parameter P5_EN_MSK = {8{P5_EN[0]}};
141 parameter P6_EN_MSK = {8{P6_EN[0]}};
143 // Register addresses
144 parameter P1IN = 9'h020; // Port 1
145 parameter P1OUT = 9'h021;
146 parameter P1DIR = 9'h022;
147 parameter P1IFG = 9'h023;
148 parameter P1IES = 9'h024;
149 parameter P1IE = 9'h025;
150 parameter P1SEL = 9'h026;
151 parameter P2IN = 9'h028; // Port 2
152 parameter P2OUT = 9'h029;
153 parameter P2DIR = 9'h02A;
154 parameter P2IFG = 9'h02B;
155 parameter P2IES = 9'h02C;
156 parameter P2IE = 9'h02D;
157 parameter P2SEL = 9'h02E;
158 parameter P3IN = 9'h018; // Port 3
159 parameter P3OUT = 9'h019;
160 parameter P3DIR = 9'h01A;
161 parameter P3SEL = 9'h01B;
162 parameter P4IN = 9'h01C; // Port 4
163 parameter P4OUT = 9'h01D;
164 parameter P4DIR = 9'h01E;
165 parameter P4SEL = 9'h01F;
166 parameter P5IN = 9'h030; // Port 5
167 parameter P5OUT = 9'h031;
168 parameter P5DIR = 9'h032;
169 parameter P5SEL = 9'h033;
170 parameter P6IN = 9'h034; // Port 6
171 parameter P6OUT = 9'h035;
172 parameter P6DIR = 9'h036;
173 parameter P6SEL = 9'h037;
176 // Register one-hot decoder
177 parameter P1IN_D = (256'h1 << (P1IN /2)); // Port 1
178 parameter P1OUT_D = (256'h1 << (P1OUT /2));
179 parameter P1DIR_D = (256'h1 << (P1DIR /2));
180 parameter P1IFG_D = (256'h1 << (P1IFG /2));
181 parameter P1IES_D = (256'h1 << (P1IES /2));
182 parameter P1IE_D = (256'h1 << (P1IE /2));
183 parameter P1SEL_D = (256'h1 << (P1SEL /2));
184 parameter P2IN_D = (256'h1 << (P2IN /2)); // Port 2
185 parameter P2OUT_D = (256'h1 << (P2OUT /2));
186 parameter P2DIR_D = (256'h1 << (P2DIR /2));
187 parameter P2IFG_D = (256'h1 << (P2IFG /2));
188 parameter P2IES_D = (256'h1 << (P2IES /2));
189 parameter P2IE_D = (256'h1 << (P2IE /2));
190 parameter P2SEL_D = (256'h1 << (P2SEL /2));
191 parameter P3IN_D = (256'h1 << (P3IN /2)); // Port 3
192 parameter P3OUT_D = (256'h1 << (P3OUT /2));
193 parameter P3DIR_D = (256'h1 << (P3DIR /2));
194 parameter P3SEL_D = (256'h1 << (P3SEL /2));
195 parameter P4IN_D = (256'h1 << (P4IN /2)); // Port 4
196 parameter P4OUT_D = (256'h1 << (P4OUT /2));
197 parameter P4DIR_D = (256'h1 << (P4DIR /2));
198 parameter P4SEL_D = (256'h1 << (P4SEL /2));
199 parameter P5IN_D = (256'h1 << (P5IN /2)); // Port 5
200 parameter P5OUT_D = (256'h1 << (P5OUT /2));
201 parameter P5DIR_D = (256'h1 << (P5DIR /2));
202 parameter P5SEL_D = (256'h1 << (P5SEL /2));
203 parameter P6IN_D = (256'h1 << (P6IN /2)); // Port 6
204 parameter P6OUT_D = (256'h1 << (P6OUT /2));
205 parameter P6DIR_D = (256'h1 << (P6DIR /2));
206 parameter P6SEL_D = (256'h1 << (P6SEL /2));
209 //============================================================================
210 // 2) REGISTER DECODER
211 //============================================================================
213 // Register address decode
217 (P1IN /2): reg_dec = P1IN_D & {256{P1_EN[0]}};
218 (P1OUT /2): reg_dec = P1OUT_D & {256{P1_EN[0]}};
219 (P1DIR /2): reg_dec = P1DIR_D & {256{P1_EN[0]}};
220 (P1IFG /2): reg_dec = P1IFG_D & {256{P1_EN[0]}};
221 (P1IES /2): reg_dec = P1IES_D & {256{P1_EN[0]}};
222 (P1IE /2): reg_dec = P1IE_D & {256{P1_EN[0]}};
223 (P1SEL /2): reg_dec = P1SEL_D & {256{P1_EN[0]}};
224 (P2IN /2): reg_dec = P2IN_D & {256{P2_EN[0]}};
225 (P2OUT /2): reg_dec = P2OUT_D & {256{P2_EN[0]}};
226 (P2DIR /2): reg_dec = P2DIR_D & {256{P2_EN[0]}};
227 (P2IFG /2): reg_dec = P2IFG_D & {256{P2_EN[0]}};
228 (P2IES /2): reg_dec = P2IES_D & {256{P2_EN[0]}};
229 (P2IE /2): reg_dec = P2IE_D & {256{P2_EN[0]}};
230 (P2SEL /2): reg_dec = P2SEL_D & {256{P2_EN[0]}};
231 (P3IN /2): reg_dec = P3IN_D & {256{P3_EN[0]}};
232 (P3OUT /2): reg_dec = P3OUT_D & {256{P3_EN[0]}};
233 (P3DIR /2): reg_dec = P3DIR_D & {256{P3_EN[0]}};
234 (P3SEL /2): reg_dec = P3SEL_D & {256{P3_EN[0]}};
235 (P4IN /2): reg_dec = P4IN_D & {256{P4_EN[0]}};
236 (P4OUT /2): reg_dec = P4OUT_D & {256{P4_EN[0]}};
237 (P4DIR /2): reg_dec = P4DIR_D & {256{P4_EN[0]}};
238 (P4SEL /2): reg_dec = P4SEL_D & {256{P4_EN[0]}};
239 (P5IN /2): reg_dec = P5IN_D & {256{P5_EN[0]}};
240 (P5OUT /2): reg_dec = P5OUT_D & {256{P5_EN[0]}};
241 (P5DIR /2): reg_dec = P5DIR_D & {256{P5_EN[0]}};
242 (P5SEL /2): reg_dec = P5SEL_D & {256{P5_EN[0]}};
243 (P6IN /2): reg_dec = P6IN_D & {256{P6_EN[0]}};
244 (P6OUT /2): reg_dec = P6OUT_D & {256{P6_EN[0]}};
245 (P6DIR /2): reg_dec = P6DIR_D & {256{P6_EN[0]}};
246 (P6SEL /2): reg_dec = P6SEL_D & {256{P6_EN[0]}};
247 default : reg_dec = {256{1'b0}};
251 wire reg_lo_write = per_wen[0] & per_en;
252 wire reg_hi_write = per_wen[1] & per_en;
253 wire reg_read = ~|per_wen & per_en;
255 // Read/Write vectors
256 wire [255:0] reg_hi_wr = reg_dec & {256{reg_hi_write}};
257 wire [255:0] reg_lo_wr = reg_dec & {256{reg_lo_write}};
258 wire [255:0] reg_rd = reg_dec & {256{reg_read}};
261 //============================================================================
263 //============================================================================
270 always @ (posedge mclk or posedge puc)
278 p1in_s <= p1_din & P1_EN_MSK;
279 p1in <= p1in_s & P1_EN_MSK;
287 wire p1out_wr = P1OUT[0] ? reg_hi_wr[P1OUT/2] : reg_lo_wr[P1OUT/2];
288 wire [7:0] p1out_nxt = P1OUT[0] ? per_din[15:8] : per_din[7:0];
290 always @ (posedge mclk or posedge puc)
291 if (puc) p1out <= 8'h00;
292 else if (p1out_wr) p1out <= p1out_nxt & P1_EN_MSK;
294 assign p1_dout = p1out;
301 wire p1dir_wr = P1DIR[0] ? reg_hi_wr[P1DIR/2] : reg_lo_wr[P1DIR/2];
302 wire [7:0] p1dir_nxt = P1DIR[0] ? per_din[15:8] : per_din[7:0];
304 always @ (posedge mclk or posedge puc)
305 if (puc) p1dir <= 8'h00;
306 else if (p1dir_wr) p1dir <= p1dir_nxt & P1_EN_MSK;
308 assign p1_dout_en = p1dir;
315 wire p1ifg_wr = P1IFG[0] ? reg_hi_wr[P1IFG/2] : reg_lo_wr[P1IFG/2];
316 wire [7:0] p1ifg_nxt = P1IFG[0] ? per_din[15:8] : per_din[7:0];
317 wire [7:0] p1ifg_set;
319 always @ (posedge mclk or posedge puc)
320 if (puc) p1ifg <= 8'h00;
321 else if (p1ifg_wr) p1ifg <= (p1ifg_nxt | p1ifg_set) & P1_EN_MSK;
322 else p1ifg <= (p1ifg | p1ifg_set) & P1_EN_MSK;
328 wire p1ies_wr = P1IES[0] ? reg_hi_wr[P1IES/2] : reg_lo_wr[P1IES/2];
329 wire [7:0] p1ies_nxt = P1IES[0] ? per_din[15:8] : per_din[7:0];
331 always @ (posedge mclk or posedge puc)
332 if (puc) p1ies <= 8'h00;
333 else if (p1ies_wr) p1ies <= p1ies_nxt & P1_EN_MSK;
340 wire p1ie_wr = P1IE[0] ? reg_hi_wr[P1IE/2] : reg_lo_wr[P1IE/2];
341 wire [7:0] p1ie_nxt = P1IE[0] ? per_din[15:8] : per_din[7:0];
343 always @ (posedge mclk or posedge puc)
344 if (puc) p1ie <= 8'h00;
345 else if (p1ie_wr) p1ie <= p1ie_nxt & P1_EN_MSK;
352 wire p1sel_wr = P1SEL[0] ? reg_hi_wr[P1SEL/2] : reg_lo_wr[P1SEL/2];
353 wire [7:0] p1sel_nxt = P1SEL[0] ? per_din[15:8] : per_din[7:0];
355 always @ (posedge mclk or posedge puc)
356 if (puc) p1sel <= 8'h00;
357 else if (p1sel_wr) p1sel <= p1sel_nxt & P1_EN_MSK;
359 assign p1_sel = p1sel;
367 always @ (posedge mclk or posedge puc)
375 p2in_s <= p2_din & P2_EN_MSK;
376 p2in <= p2in_s & P2_EN_MSK;
384 wire p2out_wr = P2OUT[0] ? reg_hi_wr[P2OUT/2] : reg_lo_wr[P2OUT/2];
385 wire [7:0] p2out_nxt = P2OUT[0] ? per_din[15:8] : per_din[7:0];
387 always @ (posedge mclk or posedge puc)
388 if (puc) p2out <= 8'h00;
389 else if (p2out_wr) p2out <= p2out_nxt & P2_EN_MSK;
391 assign p2_dout = p2out;
398 wire p2dir_wr = P2DIR[0] ? reg_hi_wr[P2DIR/2] : reg_lo_wr[P2DIR/2];
399 wire [7:0] p2dir_nxt = P2DIR[0] ? per_din[15:8] : per_din[7:0];
401 always @ (posedge mclk or posedge puc)
402 if (puc) p2dir <= 8'h00;
403 else if (p2dir_wr) p2dir <= p2dir_nxt & P2_EN_MSK;
405 assign p2_dout_en = p2dir;
412 wire p2ifg_wr = P2IFG[0] ? reg_hi_wr[P2IFG/2] : reg_lo_wr[P2IFG/2];
413 wire [7:0] p2ifg_nxt = P2IFG[0] ? per_din[15:8] : per_din[7:0];
414 wire [7:0] p2ifg_set;
416 always @ (posedge mclk or posedge puc)
417 if (puc) p2ifg <= 8'h00;
418 else if (p2ifg_wr) p2ifg <= (p2ifg_nxt | p2ifg_set) & P2_EN_MSK;
419 else p2ifg <= (p2ifg | p2ifg_set) & P2_EN_MSK;
426 wire p2ies_wr = P2IES[0] ? reg_hi_wr[P2IES/2] : reg_lo_wr[P2IES/2];
427 wire [7:0] p2ies_nxt = P2IES[0] ? per_din[15:8] : per_din[7:0];
429 always @ (posedge mclk or posedge puc)
430 if (puc) p2ies <= 8'h00;
431 else if (p2ies_wr) p2ies <= p2ies_nxt & P2_EN_MSK;
438 wire p2ie_wr = P2IE[0] ? reg_hi_wr[P2IE/2] : reg_lo_wr[P2IE/2];
439 wire [7:0] p2ie_nxt = P2IE[0] ? per_din[15:8] : per_din[7:0];
441 always @ (posedge mclk or posedge puc)
442 if (puc) p2ie <= 8'h00;
443 else if (p2ie_wr) p2ie <= p2ie_nxt & P2_EN_MSK;
450 wire p2sel_wr = P2SEL[0] ? reg_hi_wr[P2SEL/2] : reg_lo_wr[P2SEL/2];
451 wire [7:0] p2sel_nxt = P2SEL[0] ? per_din[15:8] : per_din[7:0];
453 always @ (posedge mclk or posedge puc)
454 if (puc) p2sel <= 8'h00;
455 else if (p2sel_wr) p2sel <= p2sel_nxt & P2_EN_MSK;
457 assign p2_sel = p2sel;
465 always @ (posedge mclk or posedge puc)
473 p3in_s <= p3_din & P3_EN_MSK;
474 p3in <= p3in_s & P3_EN_MSK;
482 wire p3out_wr = P3OUT[0] ? reg_hi_wr[P3OUT/2] : reg_lo_wr[P3OUT/2];
483 wire [7:0] p3out_nxt = P3OUT[0] ? per_din[15:8] : per_din[7:0];
485 always @ (posedge mclk or posedge puc)
486 if (puc) p3out <= 8'h00;
487 else if (p3out_wr) p3out <= p3out_nxt & P3_EN_MSK;
489 assign p3_dout = p3out;
496 wire p3dir_wr = P3DIR[0] ? reg_hi_wr[P3DIR/2] : reg_lo_wr[P3DIR/2];
497 wire [7:0] p3dir_nxt = P3DIR[0] ? per_din[15:8] : per_din[7:0];
499 always @ (posedge mclk or posedge puc)
500 if (puc) p3dir <= 8'h00;
501 else if (p3dir_wr) p3dir <= p3dir_nxt & P3_EN_MSK;
503 assign p3_dout_en = p3dir;
510 wire p3sel_wr = P3SEL[0] ? reg_hi_wr[P3SEL/2] : reg_lo_wr[P3SEL/2];
511 wire [7:0] p3sel_nxt = P3SEL[0] ? per_din[15:8] : per_din[7:0];
513 always @ (posedge mclk or posedge puc)
514 if (puc) p3sel <= 8'h00;
515 else if (p3sel_wr) p3sel <= p3sel_nxt & P3_EN_MSK;
517 assign p3_sel = p3sel;
525 always @ (posedge mclk or posedge puc)
533 p4in_s <= p4_din & P4_EN_MSK;
534 p4in <= p4in_s & P4_EN_MSK;
542 wire p4out_wr = P4OUT[0] ? reg_hi_wr[P4OUT/2] : reg_lo_wr[P4OUT/2];
543 wire [7:0] p4out_nxt = P4OUT[0] ? per_din[15:8] : per_din[7:0];
545 always @ (posedge mclk or posedge puc)
546 if (puc) p4out <= 8'h00;
547 else if (p4out_wr) p4out <= p4out_nxt & P4_EN_MSK;
549 assign p4_dout = p4out;
556 wire p4dir_wr = P4DIR[0] ? reg_hi_wr[P4DIR/2] : reg_lo_wr[P4DIR/2];
557 wire [7:0] p4dir_nxt = P4DIR[0] ? per_din[15:8] : per_din[7:0];
559 always @ (posedge mclk or posedge puc)
560 if (puc) p4dir <= 8'h00;
561 else if (p4dir_wr) p4dir <= p4dir_nxt & P4_EN_MSK;
563 assign p4_dout_en = p4dir;
570 wire p4sel_wr = P4SEL[0] ? reg_hi_wr[P4SEL/2] : reg_lo_wr[P4SEL/2];
571 wire [7:0] p4sel_nxt = P4SEL[0] ? per_din[15:8] : per_din[7:0];
573 always @ (posedge mclk or posedge puc)
574 if (puc) p4sel <= 8'h00;
575 else if (p4sel_wr) p4sel <= p4sel_nxt & P4_EN_MSK;
577 assign p4_sel = p4sel;
585 always @ (posedge mclk or posedge puc)
593 p5in_s <= p5_din & P5_EN_MSK;
594 p5in <= p5in_s & P5_EN_MSK;
602 wire p5out_wr = P5OUT[0] ? reg_hi_wr[P5OUT/2] : reg_lo_wr[P5OUT/2];
603 wire [7:0] p5out_nxt = P5OUT[0] ? per_din[15:8] : per_din[7:0];
605 always @ (posedge mclk or posedge puc)
606 if (puc) p5out <= 8'h00;
607 else if (p5out_wr) p5out <= p5out_nxt & P5_EN_MSK;
609 assign p5_dout = p5out;
616 wire p5dir_wr = P5DIR[0] ? reg_hi_wr[P5DIR/2] : reg_lo_wr[P5DIR/2];
617 wire [7:0] p5dir_nxt = P5DIR[0] ? per_din[15:8] : per_din[7:0];
619 always @ (posedge mclk or posedge puc)
620 if (puc) p5dir <= 8'h00;
621 else if (p5dir_wr) p5dir <= p5dir_nxt & P5_EN_MSK;
623 assign p5_dout_en = p5dir;
630 wire p5sel_wr = P5SEL[0] ? reg_hi_wr[P5SEL/2] : reg_lo_wr[P5SEL/2];
631 wire [7:0] p5sel_nxt = P5SEL[0] ? per_din[15:8] : per_din[7:0];
633 always @ (posedge mclk or posedge puc)
634 if (puc) p5sel <= 8'h00;
635 else if (p5sel_wr) p5sel <= p5sel_nxt & P5_EN_MSK;
637 assign p5_sel = p5sel;
645 always @ (posedge mclk or posedge puc)
653 p6in_s <= p6_din & P6_EN_MSK;
654 p6in <= p6in_s & P6_EN_MSK;
662 wire p6out_wr = P6OUT[0] ? reg_hi_wr[P6OUT/2] : reg_lo_wr[P6OUT/2];
663 wire [7:0] p6out_nxt = P6OUT[0] ? per_din[15:8] : per_din[7:0];
665 always @ (posedge mclk or posedge puc)
666 if (puc) p6out <= 8'h00;
667 else if (p6out_wr) p6out <= p6out_nxt & P6_EN_MSK;
669 assign p6_dout = p6out;
676 wire p6dir_wr = P6DIR[0] ? reg_hi_wr[P6DIR/2] : reg_lo_wr[P6DIR/2];
677 wire [7:0] p6dir_nxt = P6DIR[0] ? per_din[15:8] : per_din[7:0];
679 always @ (posedge mclk or posedge puc)
680 if (puc) p6dir <= 8'h00;
681 else if (p6dir_wr) p6dir <= p6dir_nxt & P6_EN_MSK;
683 assign p6_dout_en = p6dir;
690 wire p6sel_wr = P6SEL[0] ? reg_hi_wr[P6SEL/2] : reg_lo_wr[P6SEL/2];
691 wire [7:0] p6sel_nxt = P6SEL[0] ? per_din[15:8] : per_din[7:0];
693 always @ (posedge mclk or posedge puc)
694 if (puc) p6sel <= 8'h00;
695 else if (p6sel_wr) p6sel <= p6sel_nxt & P6_EN_MSK;
697 assign p6_sel = p6sel;
701 //============================================================================
702 // 4) INTERRUPT GENERATION
703 //============================================================================
710 always @ (posedge mclk or posedge puc)
711 if (puc) p1in_dly <= 8'h00;
712 else p1in_dly <= p1in & P1_EN_MSK;
715 wire [7:0] p1in_re = p1in & ~p1in_dly;
716 wire [7:0] p1in_fe = ~p1in & p1in_dly;
718 // Set interrupt flag
719 assign p1ifg_set = {p1ies[7] ? p1in_fe[7] : p1in_re[7],
720 p1ies[6] ? p1in_fe[6] : p1in_re[6],
721 p1ies[5] ? p1in_fe[5] : p1in_re[5],
722 p1ies[4] ? p1in_fe[4] : p1in_re[4],
723 p1ies[3] ? p1in_fe[3] : p1in_re[3],
724 p1ies[2] ? p1in_fe[2] : p1in_re[2],
725 p1ies[1] ? p1in_fe[1] : p1in_re[1],
726 p1ies[0] ? p1in_fe[0] : p1in_re[0]} & P1_EN_MSK;
728 // Generate CPU interrupt
729 assign irq_port1 = |(p1ie & p1ifg) & P1_EN[0];
737 always @ (posedge mclk or posedge puc)
738 if (puc) p2in_dly <= 8'h00;
739 else p2in_dly <= p2in & P2_EN_MSK;
742 wire [7:0] p2in_re = p2in & ~p2in_dly;
743 wire [7:0] p2in_fe = ~p2in & p2in_dly;
745 // Set interrupt flag
746 assign p2ifg_set = {p2ies[7] ? p2in_fe[7] : p2in_re[7],
747 p2ies[6] ? p2in_fe[6] : p2in_re[6],
748 p2ies[5] ? p2in_fe[5] : p2in_re[5],
749 p2ies[4] ? p2in_fe[4] : p2in_re[4],
750 p2ies[3] ? p2in_fe[3] : p2in_re[3],
751 p2ies[2] ? p2in_fe[2] : p2in_re[2],
752 p2ies[1] ? p2in_fe[1] : p2in_re[1],
753 p2ies[0] ? p2in_fe[0] : p2in_re[0]} & P2_EN_MSK;
755 // Generate CPU interrupt
756 assign irq_port2 = |(p2ie & p2ifg) & P2_EN[0];
759 //============================================================================
760 // 5) DATA OUTPUT GENERATION
761 //============================================================================
764 wire [15:0] p1in_rd = (p1in & {8{reg_rd[P1IN/2]}}) << (8 & {4{P1IN[0]}});
765 wire [15:0] p1out_rd = (p1out & {8{reg_rd[P1OUT/2]}}) << (8 & {4{P1OUT[0]}});
766 wire [15:0] p1dir_rd = (p1dir & {8{reg_rd[P1DIR/2]}}) << (8 & {4{P1DIR[0]}});
767 wire [15:0] p1ifg_rd = (p1ifg & {8{reg_rd[P1IFG/2]}}) << (8 & {4{P1IFG[0]}});
768 wire [15:0] p1ies_rd = (p1ies & {8{reg_rd[P1IES/2]}}) << (8 & {4{P1IES[0]}});
769 wire [15:0] p1ie_rd = (p1ie & {8{reg_rd[P1IE/2]}}) << (8 & {4{P1IE[0]}});
770 wire [15:0] p1sel_rd = (p1sel & {8{reg_rd[P1SEL/2]}}) << (8 & {4{P1SEL[0]}});
771 wire [15:0] p2in_rd = (p2in & {8{reg_rd[P2IN/2]}}) << (8 & {4{P2IN[0]}});
772 wire [15:0] p2out_rd = (p2out & {8{reg_rd[P2OUT/2]}}) << (8 & {4{P2OUT[0]}});
773 wire [15:0] p2dir_rd = (p2dir & {8{reg_rd[P2DIR/2]}}) << (8 & {4{P2DIR[0]}});
774 wire [15:0] p2ifg_rd = (p2ifg & {8{reg_rd[P2IFG/2]}}) << (8 & {4{P2IFG[0]}});
775 wire [15:0] p2ies_rd = (p2ies & {8{reg_rd[P2IES/2]}}) << (8 & {4{P2IES[0]}});
776 wire [15:0] p2ie_rd = (p2ie & {8{reg_rd[P2IE/2]}}) << (8 & {4{P2IE[0]}});
777 wire [15:0] p2sel_rd = (p2sel & {8{reg_rd[P2SEL/2]}}) << (8 & {4{P2SEL[0]}});
778 wire [15:0] p3in_rd = (p3in & {8{reg_rd[P3IN/2]}}) << (8 & {4{P3IN[0]}});
779 wire [15:0] p3out_rd = (p3out & {8{reg_rd[P3OUT/2]}}) << (8 & {4{P3OUT[0]}});
780 wire [15:0] p3dir_rd = (p3dir & {8{reg_rd[P3DIR/2]}}) << (8 & {4{P3DIR[0]}});
781 wire [15:0] p3sel_rd = (p3sel & {8{reg_rd[P3SEL/2]}}) << (8 & {4{P3SEL[0]}});
782 wire [15:0] p4in_rd = (p4in & {8{reg_rd[P4IN/2]}}) << (8 & {4{P4IN[0]}});
783 wire [15:0] p4out_rd = (p4out & {8{reg_rd[P4OUT/2]}}) << (8 & {4{P4OUT[0]}});
784 wire [15:0] p4dir_rd = (p4dir & {8{reg_rd[P4DIR/2]}}) << (8 & {4{P4DIR[0]}});
785 wire [15:0] p4sel_rd = (p4sel & {8{reg_rd[P4SEL/2]}}) << (8 & {4{P4SEL[0]}});
786 wire [15:0] p5in_rd = (p5in & {8{reg_rd[P5IN/2]}}) << (8 & {4{P5IN[0]}});
787 wire [15:0] p5out_rd = (p5out & {8{reg_rd[P5OUT/2]}}) << (8 & {4{P5OUT[0]}});
788 wire [15:0] p5dir_rd = (p5dir & {8{reg_rd[P5DIR/2]}}) << (8 & {4{P5DIR[0]}});
789 wire [15:0] p5sel_rd = (p5sel & {8{reg_rd[P5SEL/2]}}) << (8 & {4{P5SEL[0]}});
790 wire [15:0] p6in_rd = (p6in & {8{reg_rd[P6IN/2]}}) << (8 & {4{P6IN[0]}});
791 wire [15:0] p6out_rd = (p6out & {8{reg_rd[P6OUT/2]}}) << (8 & {4{P6OUT[0]}});
792 wire [15:0] p6dir_rd = (p6dir & {8{reg_rd[P6DIR/2]}}) << (8 & {4{P6DIR[0]}});
793 wire [15:0] p6sel_rd = (p6sel & {8{reg_rd[P6SEL/2]}}) << (8 & {4{P6SEL[0]}});
795 wire [15:0] per_dout = p1in_rd |
826 endmodule // omsp_gpio
828 `include "openMSP430_undefines.v"