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 17

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
// This source file may be used and distributed without restriction provided
5
// that this copyright statement is not removed from the file and that any
6
// derivative work contains the original copyright notice and the associated
7
// disclaimer.
8
//
9
// This source file is free software; you can redistribute it and/or modify
10
// it under the terms of the GNU Lesser General Public License as published
11
// by the Free Software Foundation; either version 2.1 of the License, or
12
// (at your option) any later version.
13
//
14
// This source is distributed in the hope that it will be useful, but WITHOUT
15
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17
// License for more details.
18
//
19
// You should have received a copy of the GNU Lesser General Public License
20
// along with this source; if not, write to the Free Software Foundation,
21
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
//
23
//----------------------------------------------------------------------------
24
//
25
// *File Name: template_periph_8b.v
26
// 
27
// *Module Description:
28
//                       8 bit peripheral template.
29
//
30
// *Author(s):
31
//              - Olivier Girard,    olgirard@gmail.com
32
//
33
//----------------------------------------------------------------------------
34 17 olivier.gi
// $Rev: 17 $
35
// $LastChangedBy: olivier.girard $
36
// $LastChangedDate: 2009-08-04 23:15:39 +0200 (Tue, 04 Aug 2009) $
37
//----------------------------------------------------------------------------
38 2 olivier.gi
`timescale 1ns / 100ps
39
 
40
module  template_periph_8b (
41
 
42
// OUTPUTs
43
    per_dout,                       // Peripheral data output
44
 
45
// INPUTs
46
    mclk,                           // Main system clock
47
    per_addr,                       // Peripheral address
48
    per_din,                        // Peripheral data input
49
    per_en,                         // Peripheral enable (high active)
50
    per_wen,                        // Peripheral write enable (high active)
51
    puc                             // Main system reset
52
);
53
 
54
// OUTPUTs
55
//=========
56
output      [15:0] per_dout;        // Peripheral data output
57
 
58
// INPUTs
59
//=========
60
input              mclk;            // Main system clock
61
input        [7:0] per_addr;        // Peripheral address
62
input       [15:0] per_din;         // Peripheral data input
63
input              per_en;          // Peripheral enable (high active)
64
input        [1:0] per_wen;         // Peripheral write enable (high active)
65
input              puc;             // Main system reset
66
 
67
 
68
//=============================================================================
69
// 1)  PARAMETER DECLARATION
70
//=============================================================================
71
 
72
// Register addresses
73
parameter          CNTRL1    = 9'h090;
74
parameter          CNTRL2    = 9'h091;
75
parameter          CNTRL3    = 9'h092;
76
parameter          CNTRL4    = 9'h093;
77
 
78
 
79
// Register one-hot decoder
80
parameter          CNTRL1_D  = (256'h1 << (CNTRL1 /2));
81
parameter          CNTRL2_D  = (256'h1 << (CNTRL2 /2));
82
parameter          CNTRL3_D  = (256'h1 << (CNTRL3 /2));
83
parameter          CNTRL4_D  = (256'h1 << (CNTRL4 /2));
84
 
85
 
86
//============================================================================
87
// 2)  REGISTER DECODER
88
//============================================================================
89
 
90
// Register address decode
91
reg  [255:0]  reg_dec;
92
always @(per_addr)
93
  case (per_addr)
94
    (CNTRL1 /2):   reg_dec   = CNTRL1_D;
95
    (CNTRL2 /2):   reg_dec   = CNTRL2_D;
96
    (CNTRL3 /2):   reg_dec   = CNTRL3_D;
97
    (CNTRL4 /2):   reg_dec   = CNTRL4_D;
98
    default    :   reg_dec   = {256{1'b0}};
99
  endcase
100
 
101
// Read/Write probes
102
wire         reg_lo_write =  per_wen[0] & per_en;
103
wire         reg_hi_write =  per_wen[1] & per_en;
104
wire         reg_read     = ~|per_wen   & per_en;
105
 
106
// Read/Write vectors
107
wire [255:0] reg_hi_wr    = reg_dec & {256{reg_hi_write}};
108
wire [255:0] reg_lo_wr    = reg_dec & {256{reg_lo_write}};
109
wire [255:0] reg_rd       = reg_dec & {256{reg_read}};
110
 
111
 
112
//============================================================================
113
// 3) REGISTERS
114
//============================================================================
115
 
116
// CNTRL1 Register
117
//-----------------
118
reg  [7:0] cntrl1;
119
 
120
wire       cntrl1_wr  = CNTRL1[0] ? reg_hi_wr[CNTRL1/2] : reg_lo_wr[CNTRL1/2];
121
wire [7:0] cntrl1_nxt = CNTRL1[0] ? per_din[15:8]       : per_din[7:0];
122
 
123
always @ (posedge mclk or posedge puc)
124
  if (puc)            cntrl1 <=  8'h00;
125
  else if (cntrl1_wr) cntrl1 <=  cntrl1_nxt;
126
 
127
 
128
// CNTRL2 Register
129
//-----------------
130
reg  [7:0] cntrl2;
131
 
132
wire       cntrl2_wr  = CNTRL2[0] ? reg_hi_wr[CNTRL2/2] : reg_lo_wr[CNTRL2/2];
133
wire [7:0] cntrl2_nxt = CNTRL2[0] ? per_din[15:8]       : per_din[7:0];
134
 
135
always @ (posedge mclk or posedge puc)
136
  if (puc)            cntrl2 <=  8'h00;
137
  else if (cntrl2_wr) cntrl2 <=  cntrl2_nxt;
138
 
139
 
140
// CNTRL3 Register
141
//-----------------
142
reg  [7:0] cntrl3;
143
 
144
wire       cntrl3_wr  = CNTRL3[0] ? reg_hi_wr[CNTRL3/2] : reg_lo_wr[CNTRL3/2];
145
wire [7:0] cntrl3_nxt = CNTRL3[0] ? per_din[15:8]       : per_din[7:0];
146
 
147
always @ (posedge mclk or posedge puc)
148
  if (puc)            cntrl3 <=  8'h00;
149
  else if (cntrl3_wr) cntrl3 <=  cntrl3_nxt;
150
 
151
 
152
// CNTRL4 Register
153
//-----------------
154
reg  [7:0] cntrl4;
155
 
156
wire       cntrl4_wr  = CNTRL4[0] ? reg_hi_wr[CNTRL4/2] : reg_lo_wr[CNTRL4/2];
157
wire [7:0] cntrl4_nxt = CNTRL4[0] ? per_din[15:8]       : per_din[7:0];
158
 
159
always @ (posedge mclk or posedge puc)
160
  if (puc)            cntrl4 <=  8'h00;
161
  else if (cntrl4_wr) cntrl4 <=  cntrl4_nxt;
162
 
163
 
164
 
165
//============================================================================
166
// 4) DATA OUTPUT GENERATION
167
//============================================================================
168
 
169
// Data output mux
170
wire [15:0] cntrl1_rd   = (cntrl1  & {8{reg_rd[CNTRL1/2]}})  << (8 & {4{CNTRL1[0]}});
171
wire [15:0] cntrl2_rd   = (cntrl2  & {8{reg_rd[CNTRL2/2]}})  << (8 & {4{CNTRL2[0]}});
172
wire [15:0] cntrl3_rd   = (cntrl3  & {8{reg_rd[CNTRL3/2]}})  << (8 & {4{CNTRL3[0]}});
173
wire [15:0] cntrl4_rd   = (cntrl4  & {8{reg_rd[CNTRL4/2]}})  << (8 & {4{CNTRL4[0]}});
174
 
175
wire [15:0] per_dout  =  cntrl1_rd  |
176
                         cntrl2_rd  |
177
                         cntrl3_rd  |
178
                         cntrl4_rd;
179
 
180
 
181
endmodule // template_periph_8b
182
 
183
 
184
 
185
 
186
 
187
 
188
 

powered by: WebSVN 2.1.0

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