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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [fpga/] [xilinx_avnet_lx9microbard/] [rtl/] [verilog/] [openmsp430/] [periph/] [template_periph_16b.v] - Blame information for rev 157

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 157 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: 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: 103 $
40
// $LastChangedBy: olivier.girard $
41
// $LastChangedDate: 2011-03-05 15:44:48 +0100 (Sat, 05 Mar 2011) $
42
//----------------------------------------------------------------------------
43
 
44
module  template_periph_16b (
45
 
46
// OUTPUTs
47
    per_dout,                       // Peripheral data output
48
 
49
// INPUTs
50
    mclk,                           // Main system clock
51
    per_addr,                       // Peripheral address
52
    per_din,                        // Peripheral data input
53
    per_en,                         // Peripheral enable (high active)
54
    per_we,                         // Peripheral write enable (high active)
55
    puc_rst                         // Main system reset
56
);
57
 
58
// OUTPUTs
59
//=========
60
output       [15:0] per_dout;       // Peripheral data output
61
 
62
// INPUTs
63
//=========
64
input               mclk;           // Main system clock
65
input        [13:0] per_addr;       // Peripheral address
66
input        [15:0] per_din;        // Peripheral data input
67
input               per_en;         // Peripheral enable (high active)
68
input         [1:0] per_we;         // Peripheral write enable (high active)
69
input               puc_rst;        // Main system reset
70
 
71
 
72
//=============================================================================
73
// 1)  PARAMETER DECLARATION
74
//=============================================================================
75
 
76
// Register base address (must be aligned to decoder bit width)
77
parameter       [14:0] BASE_ADDR   = 15'h0190;
78
 
79
// Decoder bit width (defines how many bits are considered for address decoding)
80
parameter              DEC_WD      =  3;
81
 
82
// Register addresses offset
83
parameter [DEC_WD-1:0] CNTRL1      = 'h0,
84
                       CNTRL2      = 'h2,
85
                       CNTRL3      = 'h4,
86
                       CNTRL4      = 'h6;
87
 
88
// Register one-hot decoder utilities
89
parameter              DEC_SZ      =  (1 << DEC_WD);
90
parameter [DEC_SZ-1:0] BASE_REG    =  {{DEC_SZ-1{1'b0}}, 1'b1};
91
 
92
// Register one-hot decoder
93
parameter [DEC_SZ-1:0] CNTRL1_D    = (BASE_REG << CNTRL1),
94
                       CNTRL2_D    = (BASE_REG << CNTRL2),
95
                       CNTRL3_D    = (BASE_REG << CNTRL3),
96
                       CNTRL4_D    = (BASE_REG << CNTRL4);
97
 
98
 
99
//============================================================================
100
// 2)  REGISTER DECODER
101
//============================================================================
102
 
103
// Local register selection
104
wire              reg_sel   =  per_en & (per_addr[13:DEC_WD-1]==BASE_ADDR[14:DEC_WD]);
105
 
106
// Register local address
107
wire [DEC_WD-1:0] reg_addr  =  {per_addr[DEC_WD-2:0], 1'b0};
108
 
109
// Register address decode
110
wire [DEC_SZ-1:0] reg_dec   =  (CNTRL1_D  &  {DEC_SZ{(reg_addr == CNTRL1 )}})  |
111
                               (CNTRL2_D  &  {DEC_SZ{(reg_addr == CNTRL2 )}})  |
112
                               (CNTRL3_D  &  {DEC_SZ{(reg_addr == CNTRL3 )}})  |
113
                               (CNTRL4_D  &  {DEC_SZ{(reg_addr == CNTRL4 )}});
114
 
115
// Read/Write probes
116
wire              reg_write =  |per_we & reg_sel;
117
wire              reg_read  = ~|per_we & reg_sel;
118
 
119
// Read/Write vectors
120
wire [DEC_SZ-1:0] reg_wr    = reg_dec & {DEC_SZ{reg_write}};
121
wire [DEC_SZ-1:0] reg_rd    = reg_dec & {DEC_SZ{reg_read}};
122
 
123
 
124
//============================================================================
125
// 3) REGISTERS
126
//============================================================================
127
 
128
// CNTRL1 Register
129
//-----------------   
130
reg  [15:0] cntrl1;
131
 
132
wire        cntrl1_wr = reg_wr[CNTRL1];
133
 
134
always @ (posedge mclk or posedge puc_rst)
135
  if (puc_rst)        cntrl1 <=  16'h0000;
136
  else if (cntrl1_wr) cntrl1 <=  per_din;
137
 
138
 
139
// CNTRL2 Register
140
//-----------------   
141
reg  [15:0] cntrl2;
142
 
143
wire        cntrl2_wr = reg_wr[CNTRL2];
144
 
145
always @ (posedge mclk or posedge puc_rst)
146
  if (puc_rst)        cntrl2 <=  16'h0000;
147
  else if (cntrl2_wr) cntrl2 <=  per_din;
148
 
149
 
150
// CNTRL3 Register
151
//-----------------   
152
reg  [15:0] cntrl3;
153
 
154
wire        cntrl3_wr = reg_wr[CNTRL3];
155
 
156
always @ (posedge mclk or posedge puc_rst)
157
  if (puc_rst)        cntrl3 <=  16'h0000;
158
  else if (cntrl3_wr) cntrl3 <=  per_din;
159
 
160
 
161
// CNTRL4 Register
162
//-----------------   
163
reg  [15:0] cntrl4;
164
 
165
wire        cntrl4_wr = reg_wr[CNTRL4];
166
 
167
always @ (posedge mclk or posedge puc_rst)
168
  if (puc_rst)        cntrl4 <=  16'h0000;
169
  else if (cntrl4_wr) cntrl4 <=  per_din;
170
 
171
 
172
//============================================================================
173
// 4) DATA OUTPUT GENERATION
174
//============================================================================
175
 
176
// Data output mux
177
wire [15:0] cntrl1_rd  = cntrl1  & {16{reg_rd[CNTRL1]}};
178
wire [15:0] cntrl2_rd  = cntrl2  & {16{reg_rd[CNTRL2]}};
179
wire [15:0] cntrl3_rd  = cntrl3  & {16{reg_rd[CNTRL3]}};
180
wire [15:0] cntrl4_rd  = cntrl4  & {16{reg_rd[CNTRL4]}};
181
 
182
wire [15:0] per_dout   =  cntrl1_rd  |
183
                          cntrl2_rd  |
184
                          cntrl3_rd  |
185
                          cntrl4_rd;
186
 
187
 
188
endmodule // template_periph_16b

powered by: WebSVN 2.1.0

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