| 1 |
80 |
olivier.gi |
//----------------------------------------------------------------------------
|
| 2 |
|
|
// Copyright (C) 2009 Authors
|
| 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_8b.v
|
| 31 |
|
|
//
|
| 32 |
|
|
// *Module Description:
|
| 33 |
|
|
// 8 bit peripheral template.
|
| 34 |
|
|
//
|
| 35 |
|
|
// *Author(s):
|
| 36 |
|
|
// - Olivier Girard, olgirard@gmail.com
|
| 37 |
|
|
//
|
| 38 |
|
|
//----------------------------------------------------------------------------
|
| 39 |
104 |
olivier.gi |
// $Rev: 103 $
|
| 40 |
80 |
olivier.gi |
// $LastChangedBy: olivier.girard $
|
| 41 |
104 |
olivier.gi |
// $LastChangedDate: 2011-03-05 15:44:48 +0100 (Sat, 05 Mar 2011) $
|
| 42 |
80 |
olivier.gi |
//----------------------------------------------------------------------------
|
| 43 |
104 |
olivier.gi |
`ifdef OMSP_NO_INCLUDE
|
| 44 |
|
|
`else
|
| 45 |
80 |
olivier.gi |
`include "openMSP430_defines.v"
|
| 46 |
104 |
olivier.gi |
`endif
|
| 47 |
80 |
olivier.gi |
|
| 48 |
|
|
module template_periph_8b (
|
| 49 |
|
|
|
| 50 |
|
|
// OUTPUTs
|
| 51 |
|
|
per_dout, // Peripheral data output
|
| 52 |
|
|
|
| 53 |
|
|
// INPUTs
|
| 54 |
|
|
mclk, // Main system clock
|
| 55 |
|
|
per_addr, // Peripheral address
|
| 56 |
|
|
per_din, // Peripheral data input
|
| 57 |
|
|
per_en, // Peripheral enable (high active)
|
| 58 |
|
|
per_wen, // Peripheral write enable (high active)
|
| 59 |
|
|
puc // Main system reset
|
| 60 |
|
|
);
|
| 61 |
|
|
|
| 62 |
|
|
// OUTPUTs
|
| 63 |
|
|
//=========
|
| 64 |
|
|
output [15:0] per_dout; // Peripheral data output
|
| 65 |
|
|
|
| 66 |
|
|
// INPUTs
|
| 67 |
|
|
//=========
|
| 68 |
|
|
input mclk; // Main system clock
|
| 69 |
|
|
input [7:0] per_addr; // Peripheral address
|
| 70 |
|
|
input [15:0] per_din; // Peripheral data input
|
| 71 |
|
|
input per_en; // Peripheral enable (high active)
|
| 72 |
|
|
input [1:0] per_wen; // Peripheral write enable (high active)
|
| 73 |
|
|
input puc; // Main system reset
|
| 74 |
|
|
|
| 75 |
|
|
|
| 76 |
|
|
//=============================================================================
|
| 77 |
|
|
// 1) PARAMETER DECLARATION
|
| 78 |
|
|
//=============================================================================
|
| 79 |
|
|
|
| 80 |
|
|
// Register addresses
|
| 81 |
|
|
parameter CNTRL1 = 9'h090;
|
| 82 |
|
|
parameter CNTRL2 = 9'h091;
|
| 83 |
|
|
parameter CNTRL3 = 9'h092;
|
| 84 |
|
|
parameter CNTRL4 = 9'h093;
|
| 85 |
|
|
|
| 86 |
|
|
|
| 87 |
|
|
// Register one-hot decoder
|
| 88 |
|
|
parameter CNTRL1_D = (256'h1 << (CNTRL1 /2));
|
| 89 |
|
|
parameter CNTRL2_D = (256'h1 << (CNTRL2 /2));
|
| 90 |
|
|
parameter CNTRL3_D = (256'h1 << (CNTRL3 /2));
|
| 91 |
|
|
parameter CNTRL4_D = (256'h1 << (CNTRL4 /2));
|
| 92 |
|
|
|
| 93 |
|
|
|
| 94 |
|
|
//============================================================================
|
| 95 |
|
|
// 2) REGISTER DECODER
|
| 96 |
|
|
//============================================================================
|
| 97 |
|
|
|
| 98 |
|
|
// Register address decode
|
| 99 |
|
|
reg [255:0] reg_dec;
|
| 100 |
|
|
always @(per_addr)
|
| 101 |
|
|
case (per_addr)
|
| 102 |
|
|
(CNTRL1 /2): reg_dec = CNTRL1_D;
|
| 103 |
|
|
(CNTRL2 /2): reg_dec = CNTRL2_D;
|
| 104 |
|
|
(CNTRL3 /2): reg_dec = CNTRL3_D;
|
| 105 |
|
|
(CNTRL4 /2): reg_dec = CNTRL4_D;
|
| 106 |
|
|
default : reg_dec = {256{1'b0}};
|
| 107 |
|
|
endcase
|
| 108 |
|
|
|
| 109 |
|
|
// Read/Write probes
|
| 110 |
|
|
wire reg_lo_write = per_wen[0] & per_en;
|
| 111 |
|
|
wire reg_hi_write = per_wen[1] & per_en;
|
| 112 |
|
|
wire reg_read = ~|per_wen & per_en;
|
| 113 |
|
|
|
| 114 |
|
|
// Read/Write vectors
|
| 115 |
|
|
wire [255:0] reg_hi_wr = reg_dec & {256{reg_hi_write}};
|
| 116 |
|
|
wire [255:0] reg_lo_wr = reg_dec & {256{reg_lo_write}};
|
| 117 |
|
|
wire [255:0] reg_rd = reg_dec & {256{reg_read}};
|
| 118 |
|
|
|
| 119 |
|
|
|
| 120 |
|
|
//============================================================================
|
| 121 |
|
|
// 3) REGISTERS
|
| 122 |
|
|
//============================================================================
|
| 123 |
|
|
|
| 124 |
|
|
// CNTRL1 Register
|
| 125 |
|
|
//-----------------
|
| 126 |
|
|
reg [7:0] cntrl1;
|
| 127 |
|
|
|
| 128 |
|
|
wire cntrl1_wr = CNTRL1[0] ? reg_hi_wr[CNTRL1/2] : reg_lo_wr[CNTRL1/2];
|
| 129 |
|
|
wire [7:0] cntrl1_nxt = CNTRL1[0] ? per_din[15:8] : per_din[7:0];
|
| 130 |
|
|
|
| 131 |
|
|
always @ (posedge mclk or posedge puc)
|
| 132 |
|
|
if (puc) cntrl1 <= 8'h00;
|
| 133 |
|
|
else if (cntrl1_wr) cntrl1 <= cntrl1_nxt;
|
| 134 |
|
|
|
| 135 |
|
|
|
| 136 |
|
|
// CNTRL2 Register
|
| 137 |
|
|
//-----------------
|
| 138 |
|
|
reg [7:0] cntrl2;
|
| 139 |
|
|
|
| 140 |
|
|
wire cntrl2_wr = CNTRL2[0] ? reg_hi_wr[CNTRL2/2] : reg_lo_wr[CNTRL2/2];
|
| 141 |
|
|
wire [7:0] cntrl2_nxt = CNTRL2[0] ? per_din[15:8] : per_din[7:0];
|
| 142 |
|
|
|
| 143 |
|
|
always @ (posedge mclk or posedge puc)
|
| 144 |
|
|
if (puc) cntrl2 <= 8'h00;
|
| 145 |
|
|
else if (cntrl2_wr) cntrl2 <= cntrl2_nxt;
|
| 146 |
|
|
|
| 147 |
|
|
|
| 148 |
|
|
// CNTRL3 Register
|
| 149 |
|
|
//-----------------
|
| 150 |
|
|
reg [7:0] cntrl3;
|
| 151 |
|
|
|
| 152 |
|
|
wire cntrl3_wr = CNTRL3[0] ? reg_hi_wr[CNTRL3/2] : reg_lo_wr[CNTRL3/2];
|
| 153 |
|
|
wire [7:0] cntrl3_nxt = CNTRL3[0] ? per_din[15:8] : per_din[7:0];
|
| 154 |
|
|
|
| 155 |
|
|
always @ (posedge mclk or posedge puc)
|
| 156 |
|
|
if (puc) cntrl3 <= 8'h00;
|
| 157 |
|
|
else if (cntrl3_wr) cntrl3 <= cntrl3_nxt;
|
| 158 |
|
|
|
| 159 |
|
|
|
| 160 |
|
|
// CNTRL4 Register
|
| 161 |
|
|
//-----------------
|
| 162 |
|
|
reg [7:0] cntrl4;
|
| 163 |
|
|
|
| 164 |
|
|
wire cntrl4_wr = CNTRL4[0] ? reg_hi_wr[CNTRL4/2] : reg_lo_wr[CNTRL4/2];
|
| 165 |
|
|
wire [7:0] cntrl4_nxt = CNTRL4[0] ? per_din[15:8] : per_din[7:0];
|
| 166 |
|
|
|
| 167 |
|
|
always @ (posedge mclk or posedge puc)
|
| 168 |
|
|
if (puc) cntrl4 <= 8'h00;
|
| 169 |
|
|
else if (cntrl4_wr) cntrl4 <= cntrl4_nxt;
|
| 170 |
|
|
|
| 171 |
|
|
|
| 172 |
|
|
|
| 173 |
|
|
//============================================================================
|
| 174 |
|
|
// 4) DATA OUTPUT GENERATION
|
| 175 |
|
|
//============================================================================
|
| 176 |
|
|
|
| 177 |
|
|
// Data output mux
|
| 178 |
85 |
olivier.gi |
wire [15:0] cntrl1_rd = {8'h00, (cntrl1 & {8{reg_rd[CNTRL1/2]}})} << (8 & {4{CNTRL1[0]}});
|
| 179 |
|
|
wire [15:0] cntrl2_rd = {8'h00, (cntrl2 & {8{reg_rd[CNTRL2/2]}})} << (8 & {4{CNTRL2[0]}});
|
| 180 |
|
|
wire [15:0] cntrl3_rd = {8'h00, (cntrl3 & {8{reg_rd[CNTRL3/2]}})} << (8 & {4{CNTRL3[0]}});
|
| 181 |
|
|
wire [15:0] cntrl4_rd = {8'h00, (cntrl4 & {8{reg_rd[CNTRL4/2]}})} << (8 & {4{CNTRL4[0]}});
|
| 182 |
80 |
olivier.gi |
|
| 183 |
|
|
wire [15:0] per_dout = cntrl1_rd |
|
| 184 |
|
|
cntrl2_rd |
|
| 185 |
|
|
cntrl3_rd |
|
| 186 |
|
|
cntrl4_rd;
|
| 187 |
|
|
|
| 188 |
|
|
|
| 189 |
|
|
endmodule // template_periph_8b
|
| 190 |
|
|
|
| 191 |
104 |
olivier.gi |
`ifdef OMSP_NO_INCLUDE
|
| 192 |
|
|
`else
|
| 193 |
80 |
olivier.gi |
`include "openMSP430_undefines.v"
|
| 194 |
104 |
olivier.gi |
`endif
|