]> rtime.felk.cvut.cz Git - fpga/openmsp430.git/blob - periph/template_periph_8b.v
e41ac169b744838259d97e87f625af1383786fad
[fpga/openmsp430.git] / periph / template_periph_8b.v
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2009 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_8b.v
31 // 
32 // *Module Description:
33 //                       8 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_8b (
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'h090;
80 parameter          CNTRL2    = 9'h091;
81 parameter          CNTRL3    = 9'h092;
82 parameter          CNTRL4    = 9'h093;
83
84    
85 // Register one-hot decoder
86 parameter          CNTRL1_D  = (256'h1 << (CNTRL1 /2));
87 parameter          CNTRL2_D  = (256'h1 << (CNTRL2 /2)); 
88 parameter          CNTRL3_D  = (256'h1 << (CNTRL3 /2)); 
89 parameter          CNTRL4_D  = (256'h1 << (CNTRL4 /2)); 
90
91
92 //============================================================================
93 // 2)  REGISTER DECODER
94 //============================================================================
95
96 // Register address decode
97 reg  [255:0]  reg_dec; 
98 always @(per_addr)
99   case (per_addr)
100     (CNTRL1 /2):   reg_dec   = CNTRL1_D;
101     (CNTRL2 /2):   reg_dec   = CNTRL2_D;
102     (CNTRL3 /2):   reg_dec   = CNTRL3_D;
103     (CNTRL4 /2):   reg_dec   = CNTRL4_D;
104     default    :   reg_dec   = {256{1'b0}};
105   endcase
106
107 // Read/Write probes
108 wire         reg_lo_write =  per_wen[0] & per_en;
109 wire         reg_hi_write =  per_wen[1] & per_en;
110 wire         reg_read     = ~|per_wen   & per_en;
111
112 // Read/Write vectors
113 wire [255:0] reg_hi_wr    = reg_dec & {256{reg_hi_write}};
114 wire [255:0] reg_lo_wr    = reg_dec & {256{reg_lo_write}};
115 wire [255:0] reg_rd       = reg_dec & {256{reg_read}};
116
117
118 //============================================================================
119 // 3) REGISTERS
120 //============================================================================
121
122 // CNTRL1 Register
123 //-----------------
124 reg  [7:0] cntrl1;
125
126 wire       cntrl1_wr  = CNTRL1[0] ? reg_hi_wr[CNTRL1/2] : reg_lo_wr[CNTRL1/2];
127 wire [7:0] cntrl1_nxt = CNTRL1[0] ? per_din[15:8]       : per_din[7:0];
128
129 always @ (posedge mclk or posedge puc)
130   if (puc)            cntrl1 <=  8'h00;
131   else if (cntrl1_wr) cntrl1 <=  cntrl1_nxt;
132
133    
134 // CNTRL2 Register
135 //-----------------
136 reg  [7:0] cntrl2;
137
138 wire       cntrl2_wr  = CNTRL2[0] ? reg_hi_wr[CNTRL2/2] : reg_lo_wr[CNTRL2/2];
139 wire [7:0] cntrl2_nxt = CNTRL2[0] ? per_din[15:8]       : per_din[7:0];
140
141 always @ (posedge mclk or posedge puc)
142   if (puc)            cntrl2 <=  8'h00;
143   else if (cntrl2_wr) cntrl2 <=  cntrl2_nxt;
144
145    
146 // CNTRL3 Register
147 //-----------------
148 reg  [7:0] cntrl3;
149
150 wire       cntrl3_wr  = CNTRL3[0] ? reg_hi_wr[CNTRL3/2] : reg_lo_wr[CNTRL3/2];
151 wire [7:0] cntrl3_nxt = CNTRL3[0] ? per_din[15:8]       : per_din[7:0];
152
153 always @ (posedge mclk or posedge puc)
154   if (puc)            cntrl3 <=  8'h00;
155   else if (cntrl3_wr) cntrl3 <=  cntrl3_nxt;
156
157    
158 // CNTRL4 Register
159 //-----------------
160 reg  [7:0] cntrl4;
161
162 wire       cntrl4_wr  = CNTRL4[0] ? reg_hi_wr[CNTRL4/2] : reg_lo_wr[CNTRL4/2];
163 wire [7:0] cntrl4_nxt = CNTRL4[0] ? per_din[15:8]       : per_din[7:0];
164
165 always @ (posedge mclk or posedge puc)
166   if (puc)            cntrl4 <=  8'h00;
167   else if (cntrl4_wr) cntrl4 <=  cntrl4_nxt;
168
169
170
171 //============================================================================
172 // 4) DATA OUTPUT GENERATION
173 //============================================================================
174
175 // Data output mux
176 wire [15:0] cntrl1_rd   = (cntrl1  & {8{reg_rd[CNTRL1/2]}})  << (8 & {4{CNTRL1[0]}});
177 wire [15:0] cntrl2_rd   = (cntrl2  & {8{reg_rd[CNTRL2/2]}})  << (8 & {4{CNTRL2[0]}});
178 wire [15:0] cntrl3_rd   = (cntrl3  & {8{reg_rd[CNTRL3/2]}})  << (8 & {4{CNTRL3[0]}});
179 wire [15:0] cntrl4_rd   = (cntrl4  & {8{reg_rd[CNTRL4/2]}})  << (8 & {4{CNTRL4[0]}});
180
181 wire [15:0] per_dout  =  cntrl1_rd  |
182                          cntrl2_rd  |
183                          cntrl3_rd  |
184                          cntrl4_rd;
185
186    
187 endmodule // template_periph_8b
188
189 `include "openMSP430_undefines.v"