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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [core/] [rtl/] [verilog/] [omsp_mem_backbone.v] - Blame information for rev 130

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

Line No. Rev Author Line
1 2 olivier.gi
//----------------------------------------------------------------------------
2 117 olivier.gi
// Copyright (C) 2009 , Olivier Girard
3 2 olivier.gi
//
4 117 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 117 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 34 olivier.gi
// *File Name: omsp_mem_backbone.v
31 2 olivier.gi
// 
32
// *Module Description:
33
//                       Memory interface backbone (decoder + arbiter)
34
//
35
// *Author(s):
36
//              - Olivier Girard,    olgirard@gmail.com
37
//
38
//----------------------------------------------------------------------------
39 17 olivier.gi
// $Rev: 117 $
40
// $LastChangedBy: olivier.girard $
41
// $LastChangedDate: 2011-06-23 21:30:51 +0200 (Thu, 23 Jun 2011) $
42
//----------------------------------------------------------------------------
43 103 olivier.gi
`ifdef OMSP_NO_INCLUDE
44
`else
45 23 olivier.gi
`include "openMSP430_defines.v"
46 103 olivier.gi
`endif
47 2 olivier.gi
 
48 34 olivier.gi
module  omsp_mem_backbone (
49 2 olivier.gi
 
50
// OUTPUTs
51
    dbg_mem_din,                    // Debug unit Memory data input
52 33 olivier.gi
    dmem_addr,                      // Data Memory address
53
    dmem_cen,                       // Data Memory chip enable (low active)
54
    dmem_din,                       // Data Memory data input
55
    dmem_wen,                       // Data Memory write enable (low active)
56 2 olivier.gi
    eu_mdb_in,                      // Execution Unit Memory data bus input
57
    fe_mdb_in,                      // Frontend Memory data bus input
58 33 olivier.gi
    fe_pmem_wait,                   // Frontend wait for Instruction fetch
59 2 olivier.gi
    per_addr,                       // Peripheral address
60
    per_din,                        // Peripheral data input
61 106 olivier.gi
    per_we,                         // Peripheral write enable (high active)
62 2 olivier.gi
    per_en,                         // Peripheral enable (high active)
63 33 olivier.gi
    pmem_addr,                      // Program Memory address
64
    pmem_cen,                       // Program Memory chip enable (low active)
65
    pmem_din,                       // Program Memory data input (optional)
66
    pmem_wen,                       // Program Memory write enable (low active) (optional)
67 2 olivier.gi
 
68
// INPUTs
69
    dbg_halt_st,                    // Halt/Run status from CPU
70
    dbg_mem_addr,                   // Debug address for rd/wr access
71
    dbg_mem_dout,                   // Debug unit data output
72
    dbg_mem_en,                     // Debug unit memory enable
73
    dbg_mem_wr,                     // Debug unit memory write
74 33 olivier.gi
    dmem_dout,                      // Data Memory data output
75 2 olivier.gi
    eu_mab,                         // Execution Unit Memory address bus
76
    eu_mb_en,                       // Execution Unit Memory bus enable
77
    eu_mb_wr,                       // Execution Unit Memory bus write transfer
78
    eu_mdb_out,                     // Execution Unit Memory data bus output
79
    fe_mab,                         // Frontend Memory address bus
80
    fe_mb_en,                       // Frontend Memory bus enable
81
    mclk,                           // Main system clock
82
    per_dout,                       // Peripheral data output
83 33 olivier.gi
    pmem_dout,                      // Program Memory data output
84 111 olivier.gi
    puc_rst                         // Main system reset
85 2 olivier.gi
);
86
 
87
// OUTPUTs
88
//=========
89 33 olivier.gi
output        [15:0] dbg_mem_din;   // Debug unit Memory data input
90
output [`DMEM_MSB:0] dmem_addr;     // Data Memory address
91
output               dmem_cen;      // Data Memory chip enable (low active)
92
output        [15:0] dmem_din;      // Data Memory data input
93
output         [1:0] dmem_wen;      // Data Memory write enable (low active)
94
output        [15:0] eu_mdb_in;     // Execution Unit Memory data bus input
95
output        [15:0] fe_mdb_in;     // Frontend Memory data bus input
96
output               fe_pmem_wait;  // Frontend wait for Instruction fetch
97 111 olivier.gi
output        [13:0] per_addr;      // Peripheral address
98 33 olivier.gi
output        [15:0] per_din;       // Peripheral data input
99 106 olivier.gi
output         [1:0] per_we;        // Peripheral write enable (high active)
100 33 olivier.gi
output               per_en;        // Peripheral enable (high active)
101
output [`PMEM_MSB:0] pmem_addr;     // Program Memory address
102
output               pmem_cen;      // Program Memory chip enable (low active)
103
output        [15:0] pmem_din;      // Program Memory data input (optional)
104
output         [1:0] pmem_wen;      // Program Memory write enable (low active) (optional)
105 2 olivier.gi
 
106
// INPUTs
107
//=========
108 33 olivier.gi
input                dbg_halt_st;   // Halt/Run status from CPU
109
input         [15:0] dbg_mem_addr;  // Debug address for rd/wr access
110
input         [15:0] dbg_mem_dout;  // Debug unit data output
111
input                dbg_mem_en;    // Debug unit memory enable
112
input          [1:0] dbg_mem_wr;    // Debug unit memory write
113
input         [15:0] dmem_dout;     // Data Memory data output
114
input         [14:0] eu_mab;        // Execution Unit Memory address bus
115
input                eu_mb_en;      // Execution Unit Memory bus enable
116
input          [1:0] eu_mb_wr;      // Execution Unit Memory bus write transfer
117
input         [15:0] eu_mdb_out;    // Execution Unit Memory data bus output
118
input         [14:0] fe_mab;        // Frontend Memory address bus
119
input                fe_mb_en;      // Frontend Memory bus enable
120
input                mclk;          // Main system clock
121
input         [15:0] per_dout;      // Peripheral data output
122
input         [15:0] pmem_dout;     // Program Memory data output
123 111 olivier.gi
input                puc_rst;       // Main system reset
124 2 olivier.gi
 
125
 
126
//=============================================================================
127
// 1)  DECODER
128
//=============================================================================
129
 
130
// RAM Interface
131
//------------------
132
 
133
// Execution unit access
134 33 olivier.gi
wire               eu_dmem_cen   = ~(eu_mb_en & (eu_mab>=(`DMEM_BASE>>1)) &
135
                                                (eu_mab<((`DMEM_BASE+`DMEM_SIZE)>>1)));
136 111 olivier.gi
wire        [15:0] eu_dmem_addr  = {1'b0, eu_mab}-(`DMEM_BASE>>1);
137 2 olivier.gi
 
138
// Debug interface access
139 33 olivier.gi
wire               dbg_dmem_cen  = ~(dbg_mem_en & (dbg_mem_addr[15:1]>=(`DMEM_BASE>>1)) &
140
                                                  (dbg_mem_addr[15:1]<((`DMEM_BASE+`DMEM_SIZE)>>1)));
141 111 olivier.gi
wire        [15:0] dbg_dmem_addr = {1'b0, dbg_mem_addr[15:1]}-(`DMEM_BASE>>1);
142 2 olivier.gi
 
143
 
144
// RAM Interface
145 33 olivier.gi
wire [`DMEM_MSB:0] dmem_addr     = ~dbg_dmem_cen ? dbg_dmem_addr[`DMEM_MSB:0] : eu_dmem_addr[`DMEM_MSB:0];
146
wire               dmem_cen      =  dbg_dmem_cen & eu_dmem_cen;
147
wire         [1:0] dmem_wen      = ~(dbg_mem_wr | eu_mb_wr);
148
wire        [15:0] dmem_din      = ~dbg_dmem_cen ? dbg_mem_dout : eu_mdb_out;
149 2 olivier.gi
 
150
 
151
// ROM Interface
152
//------------------
153 33 olivier.gi
parameter          PMEM_OFFSET   = (16'hFFFF-`PMEM_SIZE+1);
154 2 olivier.gi
 
155
// Execution unit access (only read access are accepted)
156 33 olivier.gi
wire               eu_pmem_cen   = ~(eu_mb_en & ~|eu_mb_wr & (eu_mab>=(PMEM_OFFSET>>1)));
157
wire        [15:0] eu_pmem_addr  = eu_mab-(PMEM_OFFSET>>1);
158 2 olivier.gi
 
159
// Front-end access
160 33 olivier.gi
wire               fe_pmem_cen   = ~(fe_mb_en & (fe_mab>=(PMEM_OFFSET>>1)));
161
wire        [15:0] fe_pmem_addr  = fe_mab-(PMEM_OFFSET>>1);
162 2 olivier.gi
 
163
// Debug interface access
164 33 olivier.gi
wire               dbg_pmem_cen  = ~(dbg_mem_en & (dbg_mem_addr[15:1]>=(PMEM_OFFSET>>1)));
165 111 olivier.gi
wire        [15:0] dbg_pmem_addr = {1'b0, dbg_mem_addr[15:1]}-(PMEM_OFFSET>>1);
166 2 olivier.gi
 
167
 
168
// ROM Interface (Execution unit has priority)
169 33 olivier.gi
wire [`PMEM_MSB:0] pmem_addr     = ~dbg_pmem_cen ? dbg_pmem_addr[`PMEM_MSB:0] :
170
                                   ~eu_pmem_cen  ? eu_pmem_addr[`PMEM_MSB:0]  : fe_pmem_addr[`PMEM_MSB:0];
171
wire               pmem_cen      =  fe_pmem_cen & eu_pmem_cen & dbg_pmem_cen;
172
wire         [1:0] pmem_wen      = ~dbg_mem_wr;
173
wire        [15:0] pmem_din      =  dbg_mem_dout;
174 2 olivier.gi
 
175 33 olivier.gi
wire               fe_pmem_wait  = (~fe_pmem_cen & ~eu_pmem_cen);
176 2 olivier.gi
 
177
 
178
// Peripherals
179
//--------------------
180 111 olivier.gi
wire              dbg_per_en   =  dbg_mem_en & (dbg_mem_addr[15:`PER_AWIDTH+1]=={15-`PER_AWIDTH{1'b0}});
181
wire              eu_per_en    =  eu_mb_en   & (eu_mab[14:`PER_AWIDTH]        =={15-`PER_AWIDTH{1'b0}});
182 2 olivier.gi
 
183 111 olivier.gi
wire       [15:0] per_din      =  dbg_mem_en ? dbg_mem_dout               : eu_mdb_out;
184
wire        [1:0] per_we       =  dbg_mem_en ? dbg_mem_wr                 : eu_mb_wr;
185
wire              per_en       =  dbg_mem_en ? dbg_per_en                 : eu_per_en;
186
wire [`PER_MSB:0] per_addr_mux =  dbg_mem_en ? dbg_mem_addr[`PER_MSB+1:1] : eu_mab[`PER_MSB:0];
187
wire       [14:0] per_addr_ful =  {{15-`PER_AWIDTH{1'b0}}, per_addr_mux};
188
wire       [13:0] per_addr     =   per_addr_ful[13:0];
189 2 olivier.gi
 
190
reg   [15:0] per_dout_val;
191 111 olivier.gi
always @ (posedge mclk or posedge puc_rst)
192
  if (puc_rst)  per_dout_val <= 16'h0000;
193 2 olivier.gi
  else          per_dout_val <= per_dout;
194
 
195
 
196
// Frontend data Mux
197
//---------------------------------
198
// Whenever the frontend doesn't access the ROM,  backup the data
199
 
200
// Detect whenever the data should be backuped and restored
201 33 olivier.gi
reg         fe_pmem_cen_dly;
202 111 olivier.gi
always @(posedge mclk or posedge puc_rst)
203
  if (puc_rst) fe_pmem_cen_dly <=  1'b0;
204 33 olivier.gi
  else         fe_pmem_cen_dly <=  fe_pmem_cen;
205 2 olivier.gi
 
206 33 olivier.gi
wire fe_pmem_save    = ( fe_pmem_cen & ~fe_pmem_cen_dly) & ~dbg_halt_st;
207
wire fe_pmem_restore = (~fe_pmem_cen &  fe_pmem_cen_dly) |  dbg_halt_st;
208 2 olivier.gi
 
209 33 olivier.gi
reg  [15:0] pmem_dout_bckup;
210 111 olivier.gi
always @(posedge mclk or posedge puc_rst)
211
  if (puc_rst)           pmem_dout_bckup     <=  16'h0000;
212 33 olivier.gi
  else if (fe_pmem_save) pmem_dout_bckup     <=  pmem_dout;
213 2 olivier.gi
 
214
// Mux between the ROM data and the backup
215 33 olivier.gi
reg         pmem_dout_bckup_sel;
216 111 olivier.gi
always @(posedge mclk or posedge puc_rst)
217
  if (puc_rst)              pmem_dout_bckup_sel <=  1'b0;
218 33 olivier.gi
  else if (fe_pmem_save)    pmem_dout_bckup_sel <=  1'b1;
219
  else if (fe_pmem_restore) pmem_dout_bckup_sel <=  1'b0;
220 2 olivier.gi
 
221 33 olivier.gi
assign fe_mdb_in = pmem_dout_bckup_sel ? pmem_dout_bckup : pmem_dout;
222 2 olivier.gi
 
223
 
224
// Execution-Unit data Mux
225
//---------------------------------
226
 
227
// Select between peripherals, RAM and ROM
228
reg [1:0] eu_mdb_in_sel;
229 111 olivier.gi
always @(posedge mclk or posedge puc_rst)
230
  if (puc_rst)  eu_mdb_in_sel <= 2'b00;
231
  else          eu_mdb_in_sel <= {~eu_pmem_cen, per_en};
232 2 olivier.gi
 
233
// Mux
234 33 olivier.gi
assign      eu_mdb_in      = eu_mdb_in_sel[1] ? pmem_dout    :
235
                             eu_mdb_in_sel[0] ? per_dout_val : dmem_dout;
236 2 olivier.gi
 
237
// Debug interface  data Mux
238
//---------------------------------
239
 
240
// Select between peripherals, RAM and ROM
241 106 olivier.gi
`ifdef DBG_EN
242
reg   [1:0] dbg_mem_din_sel;
243 111 olivier.gi
always @(posedge mclk or posedge puc_rst)
244
  if (puc_rst)  dbg_mem_din_sel <= 2'b00;
245
  else          dbg_mem_din_sel <= {~dbg_pmem_cen, dbg_per_en};
246 2 olivier.gi
 
247 106 olivier.gi
`else
248
wire  [1:0] dbg_mem_din_sel  = 2'b00;
249
`endif
250
 
251 2 olivier.gi
// Mux
252 33 olivier.gi
assign      dbg_mem_din  = dbg_mem_din_sel[1] ? pmem_dout    :
253
                           dbg_mem_din_sel[0] ? per_dout_val : dmem_dout;
254 2 olivier.gi
 
255
 
256 34 olivier.gi
endmodule // omsp_mem_backbone
257 2 olivier.gi
 
258 103 olivier.gi
`ifdef OMSP_NO_INCLUDE
259
`else
260 33 olivier.gi
`include "openMSP430_undefines.v"
261 103 olivier.gi
`endif

powered by: WebSVN 2.1.0

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