| 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_16b.v
|
| 26 |
|
|
//
|
| 27 |
|
|
// *Module Description:
|
| 28 |
|
|
// 16 bit peripheral template.
|
| 29 |
|
|
//
|
| 30 |
|
|
// *Author(s):
|
| 31 |
|
|
// - Olivier Girard, olgirard@gmail.com
|
| 32 |
|
|
//
|
| 33 |
|
|
//----------------------------------------------------------------------------
|
| 34 |
|
|
`timescale 1ns / 100ps
|
| 35 |
|
|
|
| 36 |
|
|
module template_periph_16b (
|
| 37 |
|
|
|
| 38 |
|
|
// OUTPUTs
|
| 39 |
|
|
per_dout, // Peripheral data output
|
| 40 |
|
|
|
| 41 |
|
|
// INPUTs
|
| 42 |
|
|
mclk, // Main system clock
|
| 43 |
|
|
per_addr, // Peripheral address
|
| 44 |
|
|
per_din, // Peripheral data input
|
| 45 |
|
|
per_en, // Peripheral enable (high active)
|
| 46 |
|
|
per_wen, // Peripheral write enable (high active)
|
| 47 |
|
|
puc // Main system reset
|
| 48 |
|
|
);
|
| 49 |
|
|
|
| 50 |
|
|
// OUTPUTs
|
| 51 |
|
|
//=========
|
| 52 |
|
|
output [15:0] per_dout; // Peripheral data output
|
| 53 |
|
|
|
| 54 |
|
|
// INPUTs
|
| 55 |
|
|
//=========
|
| 56 |
|
|
input mclk; // Main system clock
|
| 57 |
|
|
input [7:0] per_addr; // Peripheral address
|
| 58 |
|
|
input [15:0] per_din; // Peripheral data input
|
| 59 |
|
|
input per_en; // Peripheral enable (high active)
|
| 60 |
|
|
input [1:0] per_wen; // Peripheral write enable (high active)
|
| 61 |
|
|
input puc; // Main system reset
|
| 62 |
|
|
|
| 63 |
|
|
|
| 64 |
|
|
//=============================================================================
|
| 65 |
|
|
// 1) PARAMETER DECLARATION
|
| 66 |
|
|
//=============================================================================
|
| 67 |
|
|
|
| 68 |
|
|
// Register addresses
|
| 69 |
|
|
parameter CNTRL1 = 9'h190;
|
| 70 |
|
|
parameter CNTRL2 = 9'h192;
|
| 71 |
|
|
parameter CNTRL3 = 9'h194;
|
| 72 |
|
|
parameter CNTRL4 = 9'h196;
|
| 73 |
|
|
|
| 74 |
|
|
|
| 75 |
|
|
// Register one-hot decoder
|
| 76 |
|
|
parameter CNTRL1_D = (512'h1 << CNTRL1);
|
| 77 |
|
|
parameter CNTRL2_D = (512'h1 << CNTRL2);
|
| 78 |
|
|
parameter CNTRL3_D = (512'h1 << CNTRL3);
|
| 79 |
|
|
parameter CNTRL4_D = (512'h1 << CNTRL4);
|
| 80 |
|
|
|
| 81 |
|
|
|
| 82 |
|
|
//============================================================================
|
| 83 |
|
|
// 2) REGISTER DECODER
|
| 84 |
|
|
//============================================================================
|
| 85 |
|
|
|
| 86 |
|
|
// Register address decode
|
| 87 |
|
|
reg [511:0] reg_dec;
|
| 88 |
|
|
always @(per_addr)
|
| 89 |
|
|
case ({per_addr,1'b0})
|
| 90 |
|
|
CNTRL1 : reg_dec = CNTRL1_D;
|
| 91 |
|
|
CNTRL2 : reg_dec = CNTRL2_D;
|
| 92 |
|
|
CNTRL3 : reg_dec = CNTRL3_D;
|
| 93 |
|
|
CNTRL4 : reg_dec = CNTRL4_D;
|
| 94 |
|
|
default: reg_dec = {512{1'b0}};
|
| 95 |
|
|
endcase
|
| 96 |
|
|
|
| 97 |
|
|
// Read/Write probes
|
| 98 |
|
|
wire reg_write = |per_wen & per_en;
|
| 99 |
|
|
wire reg_read = ~|per_wen & per_en;
|
| 100 |
|
|
|
| 101 |
|
|
// Read/Write vectors
|
| 102 |
|
|
wire [511:0] reg_wr = reg_dec & {512{reg_write}};
|
| 103 |
|
|
wire [511:0] reg_rd = reg_dec & {512{reg_read}};
|
| 104 |
|
|
|
| 105 |
|
|
|
| 106 |
|
|
//============================================================================
|
| 107 |
|
|
// 3) REGISTERS
|
| 108 |
|
|
//============================================================================
|
| 109 |
|
|
|
| 110 |
|
|
// CNTRL1 Register
|
| 111 |
|
|
//-----------------
|
| 112 |
|
|
reg [15:0] cntrl1;
|
| 113 |
|
|
|
| 114 |
|
|
wire cntrl1_wr = reg_wr[CNTRL1];
|
| 115 |
|
|
|
| 116 |
|
|
always @ (posedge mclk or posedge puc)
|
| 117 |
|
|
if (puc) cntrl1 <= 16'h0000;
|
| 118 |
|
|
else if (cntrl1_wr) cntrl1 <= per_din;
|
| 119 |
|
|
|
| 120 |
|
|
|
| 121 |
|
|
// CNTRL2 Register
|
| 122 |
|
|
//-----------------
|
| 123 |
|
|
reg [15:0] cntrl2;
|
| 124 |
|
|
|
| 125 |
|
|
wire cntrl2_wr = reg_wr[CNTRL2];
|
| 126 |
|
|
|
| 127 |
|
|
always @ (posedge mclk or posedge puc)
|
| 128 |
|
|
if (puc) cntrl2 <= 16'h0000;
|
| 129 |
|
|
else if (cntrl2_wr) cntrl2 <= per_din;
|
| 130 |
|
|
|
| 131 |
|
|
|
| 132 |
|
|
// CNTRL3 Register
|
| 133 |
|
|
//-----------------
|
| 134 |
|
|
reg [15:0] cntrl3;
|
| 135 |
|
|
|
| 136 |
|
|
wire cntrl3_wr = reg_wr[CNTRL3];
|
| 137 |
|
|
|
| 138 |
|
|
always @ (posedge mclk or posedge puc)
|
| 139 |
|
|
if (puc) cntrl3 <= 16'h0000;
|
| 140 |
|
|
else if (cntrl3_wr) cntrl3 <= per_din;
|
| 141 |
|
|
|
| 142 |
|
|
|
| 143 |
|
|
// CNTRL4 Register
|
| 144 |
|
|
//-----------------
|
| 145 |
|
|
reg [15:0] cntrl4;
|
| 146 |
|
|
|
| 147 |
|
|
wire cntrl4_wr = reg_wr[CNTRL4];
|
| 148 |
|
|
|
| 149 |
|
|
always @ (posedge mclk or posedge puc)
|
| 150 |
|
|
if (puc) cntrl4 <= 16'h0000;
|
| 151 |
|
|
else if (cntrl4_wr) cntrl4 <= per_din;
|
| 152 |
|
|
|
| 153 |
|
|
|
| 154 |
|
|
//============================================================================
|
| 155 |
|
|
// 4) DATA OUTPUT GENERATION
|
| 156 |
|
|
//============================================================================
|
| 157 |
|
|
|
| 158 |
|
|
// Data output mux
|
| 159 |
|
|
wire [15:0] cntrl1_rd = cntrl1 & {16{reg_rd[CNTRL1]}};
|
| 160 |
|
|
wire [15:0] cntrl2_rd = cntrl2 & {16{reg_rd[CNTRL2]}};
|
| 161 |
|
|
wire [15:0] cntrl3_rd = cntrl3 & {16{reg_rd[CNTRL3]}};
|
| 162 |
|
|
wire [15:0] cntrl4_rd = cntrl4 & {16{reg_rd[CNTRL4]}};
|
| 163 |
|
|
|
| 164 |
|
|
wire [15:0] per_dout = cntrl1_rd |
|
| 165 |
|
|
cntrl2_rd |
|
| 166 |
|
|
cntrl3_rd |
|
| 167 |
|
|
cntrl4_rd;
|
| 168 |
|
|
|
| 169 |
|
|
|
| 170 |
|
|
endmodule // template_periph_16b
|
| 171 |
|
|
|
| 172 |
|
|
|
| 173 |
|
|
|
| 174 |
|
|
|
| 175 |
|
|
|
| 176 |
|
|
|