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

Subversion Repositories openmsp430

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

powered by: WebSVN 2.1.0

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