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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [core/] [rtl/] [verilog/] [periph/] [template_periph_16b.v] - Blame information for rev 106

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

Line No. Rev Author Line
1 2 olivier.gi
//----------------------------------------------------------------------------
2
// Copyright (C) 2001 Authors
3
//
4 66 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 2 olivier.gi
//
16 66 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 2 olivier.gi
//
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 17 olivier.gi
// $Rev: 106 $
40
// $LastChangedBy: olivier.girard $
41
// $LastChangedDate: 2011-03-25 23:01:03 +0100 (Fri, 25 Mar 2011) $
42
//----------------------------------------------------------------------------
43 2 olivier.gi
 
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 106 olivier.gi
    per_we,                         // Peripheral write enable (high active)
55 2 olivier.gi
    puc                             // 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         [7:0] per_addr;       // Peripheral address
66
input        [15:0] per_din;        // Peripheral data input
67
input               per_en;         // Peripheral enable (high active)
68 106 olivier.gi
input         [1:0] per_we;         // Peripheral write enable (high active)
69 2 olivier.gi
input               puc;            // Main system reset
70
 
71
 
72
//=============================================================================
73
// 1)  PARAMETER DECLARATION
74
//=============================================================================
75
 
76
// Register addresses
77
parameter           CNTRL1     = 9'h190;
78
parameter           CNTRL2     = 9'h192;
79
parameter           CNTRL3     = 9'h194;
80
parameter           CNTRL4     = 9'h196;
81
 
82
 
83
// Register one-hot decoder
84
parameter           CNTRL1_D   = (512'h1 << CNTRL1);
85
parameter           CNTRL2_D   = (512'h1 << CNTRL2);
86
parameter           CNTRL3_D   = (512'h1 << CNTRL3);
87
parameter           CNTRL4_D   = (512'h1 << CNTRL4);
88
 
89
 
90
//============================================================================
91
// 2)  REGISTER DECODER
92
//============================================================================
93
 
94
// Register address decode
95
reg  [511:0]  reg_dec;
96
always @(per_addr)
97
  case ({per_addr,1'b0})
98
    CNTRL1 :     reg_dec  =  CNTRL1_D;
99
    CNTRL2 :     reg_dec  =  CNTRL2_D;
100
    CNTRL3 :     reg_dec  =  CNTRL3_D;
101
    CNTRL4 :     reg_dec  =  CNTRL4_D;
102
    default:     reg_dec  =  {512{1'b0}};
103
  endcase
104
 
105
// Read/Write probes
106 106 olivier.gi
wire         reg_write =  |per_we & per_en;
107
wire         reg_read  = ~|per_we & per_en;
108 2 olivier.gi
 
109
// Read/Write vectors
110
wire [511:0] reg_wr    = reg_dec & {512{reg_write}};
111
wire [511:0] reg_rd    = reg_dec & {512{reg_read}};
112
 
113
 
114
//============================================================================
115
// 3) REGISTERS
116
//============================================================================
117
 
118
// CNTRL1 Register
119
//-----------------   
120
reg  [15:0] cntrl1;
121
 
122
wire        cntrl1_wr = reg_wr[CNTRL1];
123
 
124
always @ (posedge mclk or posedge puc)
125
  if (puc)            cntrl1 <=  16'h0000;
126
  else if (cntrl1_wr) cntrl1 <=  per_din;
127
 
128
 
129
// CNTRL2 Register
130
//-----------------   
131
reg  [15:0] cntrl2;
132
 
133
wire        cntrl2_wr = reg_wr[CNTRL2];
134
 
135
always @ (posedge mclk or posedge puc)
136
  if (puc)            cntrl2 <=  16'h0000;
137
  else if (cntrl2_wr) cntrl2 <=  per_din;
138
 
139
 
140
// CNTRL3 Register
141
//-----------------   
142
reg  [15:0] cntrl3;
143
 
144
wire        cntrl3_wr = reg_wr[CNTRL3];
145
 
146
always @ (posedge mclk or posedge puc)
147
  if (puc)            cntrl3 <=  16'h0000;
148
  else if (cntrl3_wr) cntrl3 <=  per_din;
149
 
150
 
151
// CNTRL4 Register
152
//-----------------   
153
reg  [15:0] cntrl4;
154
 
155
wire        cntrl4_wr = reg_wr[CNTRL4];
156
 
157
always @ (posedge mclk or posedge puc)
158
  if (puc)            cntrl4 <=  16'h0000;
159
  else if (cntrl4_wr) cntrl4 <=  per_din;
160
 
161
 
162
//============================================================================
163
// 4) DATA OUTPUT GENERATION
164
//============================================================================
165
 
166
// Data output mux
167
wire [15:0] cntrl1_rd  = cntrl1  & {16{reg_rd[CNTRL1]}};
168
wire [15:0] cntrl2_rd  = cntrl2  & {16{reg_rd[CNTRL2]}};
169
wire [15:0] cntrl3_rd  = cntrl3  & {16{reg_rd[CNTRL3]}};
170
wire [15:0] cntrl4_rd  = cntrl4  & {16{reg_rd[CNTRL4]}};
171
 
172
wire [15:0] per_dout   =  cntrl1_rd  |
173
                          cntrl2_rd  |
174
                          cntrl3_rd  |
175
                          cntrl4_rd;
176
 
177
 
178
endmodule // template_periph_16b

powered by: WebSVN 2.1.0

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