]> rtime.felk.cvut.cz Git - fpga/openmsp430.git/blob - periph/template_periph_16b.v
Added partial copy of openMSP430.
[fpga/openmsp430.git] / periph / template_periph_16b.v
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2001 Authors
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: template_periph_16b.v
31 // 
32 // *Module Description:
33 //                       16 bit peripheral template.
34 //
35 // *Author(s):
36 //              - Olivier Girard,    olgirard@gmail.com
37 //
38 //----------------------------------------------------------------------------
39 // $Rev: 66 $
40 // $LastChangedBy: olivier.girard $
41 // $LastChangedDate: 2010-03-07 09:09:38 +0100 (Sun, 07 Mar 2010) $
42 //----------------------------------------------------------------------------
43 `include "timescale.v"
44 `include "openMSP430_defines.v"
45
46 module  template_periph_16b (
47
48 // OUTPUTs
49     per_dout,                       // Peripheral data output
50
51 // INPUTs
52     mclk,                           // Main system clock
53     per_addr,                       // Peripheral address
54     per_din,                        // Peripheral data input
55     per_en,                         // Peripheral enable (high active)
56     per_wen,                        // Peripheral write enable (high active)
57     puc                             // Main system reset
58 );
59
60 // OUTPUTs
61 //=========
62 output       [15:0] per_dout;       // Peripheral data output
63
64 // INPUTs
65 //=========
66 input               mclk;           // Main system clock
67 input         [7:0] per_addr;       // Peripheral address
68 input        [15:0] per_din;        // Peripheral data input
69 input               per_en;         // Peripheral enable (high active)
70 input         [1:0] per_wen;        // Peripheral write enable (high active)
71 input               puc;            // Main system reset
72
73
74 //=============================================================================
75 // 1)  PARAMETER DECLARATION
76 //=============================================================================
77
78 // Register addresses
79 parameter           CNTRL1     = 9'h190;
80 parameter           CNTRL2     = 9'h192;
81 parameter           CNTRL3     = 9'h194;
82 parameter           CNTRL4     = 9'h196;
83
84
85 // Register one-hot decoder
86 parameter           CNTRL1_D   = (512'h1 << CNTRL1);
87 parameter           CNTRL2_D   = (512'h1 << CNTRL2);
88 parameter           CNTRL3_D   = (512'h1 << CNTRL3);
89 parameter           CNTRL4_D   = (512'h1 << CNTRL4);
90
91
92 //============================================================================
93 // 2)  REGISTER DECODER
94 //============================================================================
95
96 // Register address decode
97 reg  [511:0]  reg_dec; 
98 always @(per_addr)
99   case ({per_addr,1'b0})
100     CNTRL1 :     reg_dec  =  CNTRL1_D;
101     CNTRL2 :     reg_dec  =  CNTRL2_D;
102     CNTRL3 :     reg_dec  =  CNTRL3_D;
103     CNTRL4 :     reg_dec  =  CNTRL4_D;
104     default:     reg_dec  =  {512{1'b0}};
105   endcase
106
107 // Read/Write probes
108 wire         reg_write =  |per_wen   & per_en;
109 wire         reg_read  = ~|per_wen   & per_en;
110
111 // Read/Write vectors
112 wire [511:0] reg_wr    = reg_dec & {512{reg_write}};
113 wire [511:0] reg_rd    = reg_dec & {512{reg_read}};
114
115
116 //============================================================================
117 // 3) REGISTERS
118 //============================================================================
119
120 // CNTRL1 Register
121 //-----------------   
122 reg  [15:0] cntrl1;
123
124 wire        cntrl1_wr = reg_wr[CNTRL1];
125
126 always @ (posedge mclk or posedge puc)
127   if (puc)            cntrl1 <=  16'h0000;
128   else if (cntrl1_wr) cntrl1 <=  per_din;
129
130    
131 // CNTRL2 Register
132 //-----------------   
133 reg  [15:0] cntrl2;
134
135 wire        cntrl2_wr = reg_wr[CNTRL2];
136
137 always @ (posedge mclk or posedge puc)
138   if (puc)            cntrl2 <=  16'h0000;
139   else if (cntrl2_wr) cntrl2 <=  per_din;
140
141    
142 // CNTRL3 Register
143 //-----------------   
144 reg  [15:0] cntrl3;
145
146 wire        cntrl3_wr = reg_wr[CNTRL3];
147
148 always @ (posedge mclk or posedge puc)
149   if (puc)            cntrl3 <=  16'h0000;
150   else if (cntrl3_wr) cntrl3 <=  per_din;
151
152    
153 // CNTRL4 Register
154 //-----------------   
155 reg  [15:0] cntrl4;
156
157 wire        cntrl4_wr = reg_wr[CNTRL4];
158
159 always @ (posedge mclk or posedge puc)
160   if (puc)            cntrl4 <=  16'h0000;
161   else if (cntrl4_wr) cntrl4 <=  per_din;
162
163
164 //============================================================================
165 // 4) DATA OUTPUT GENERATION
166 //============================================================================
167
168 // Data output mux
169 wire [15:0] cntrl1_rd  = cntrl1  & {16{reg_rd[CNTRL1]}};
170 wire [15:0] cntrl2_rd  = cntrl2  & {16{reg_rd[CNTRL2]}};
171 wire [15:0] cntrl3_rd  = cntrl3  & {16{reg_rd[CNTRL3]}};
172 wire [15:0] cntrl4_rd  = cntrl4  & {16{reg_rd[CNTRL4]}};
173
174 wire [15:0] per_dout   =  cntrl1_rd  |
175                           cntrl2_rd  |
176                           cntrl3_rd  |
177                           cntrl4_rd;
178
179
180 endmodule // template_periph_16b
181
182 `include "openMSP430_undefines.v"