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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [core/] [bench/] [verilog/] [dbg_uart_tasks.v] - Blame information for rev 154

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: dbg_uart_tasks.v
26
// 
27
// *Module Description:
28
//                      openMSP430 debug interface UART tasks
29
//
30
// *Author(s):
31
//              - Olivier Girard,    olgirard@gmail.com
32
//
33
//----------------------------------------------------------------------------
34 17 olivier.gi
// $Rev: 154 $
35
// $LastChangedBy: olivier.girard $
36
// $LastChangedDate: 2012-10-15 22:44:20 +0200 (Mon, 15 Oct 2012) $
37
//----------------------------------------------------------------------------
38 2 olivier.gi
 
39
// Register B/W and addresses
40
parameter           CPU_ID_LO    =  (8'h00 | 8'h00);
41
parameter           CPU_ID_HI    =  (8'h00 | 8'h01);
42
parameter           CPU_CTL      =  (8'h40 | 8'h02);
43
parameter           CPU_STAT     =  (8'h40 | 8'h03);
44
parameter           MEM_CTL      =  (8'h40 | 8'h04);
45
parameter           MEM_ADDR     =  (8'h00 | 8'h05);
46
parameter           MEM_DATA     =  (8'h00 | 8'h06);
47
parameter           MEM_CNT      =  (8'h00 | 8'h07);
48
parameter           BRK0_CTL     =  (8'h40 | 8'h08);
49
parameter           BRK0_STAT    =  (8'h40 | 8'h09);
50
parameter           BRK0_ADDR0   =  (8'h00 | 8'h0A);
51
parameter           BRK0_ADDR1   =  (8'h00 | 8'h0B);
52
parameter           BRK1_CTL     =  (8'h40 | 8'h0C);
53
parameter           BRK1_STAT    =  (8'h40 | 8'h0D);
54
parameter           BRK1_ADDR0   =  (8'h00 | 8'h0E);
55
parameter           BRK1_ADDR1   =  (8'h00 | 8'h0F);
56
parameter           BRK2_CTL     =  (8'h40 | 8'h10);
57
parameter           BRK2_STAT    =  (8'h40 | 8'h11);
58
parameter           BRK2_ADDR0   =  (8'h00 | 8'h12);
59
parameter           BRK2_ADDR1   =  (8'h00 | 8'h13);
60
parameter           BRK3_CTL     =  (8'h40 | 8'h14);
61
parameter           BRK3_STAT    =  (8'h40 | 8'h15);
62
parameter           BRK3_ADDR0   =  (8'h00 | 8'h16);
63
parameter           BRK3_ADDR1   =  (8'h00 | 8'h17);
64 154 olivier.gi
parameter           CPU_NR       =  (8'h00 | 8'h18);
65 2 olivier.gi
 
66
// Read / Write commands
67
parameter           DBG_WR       =   8'h80;
68
parameter           DBG_RD       =   8'h00;
69
 
70
// Synchronization value
71
parameter           DBG_SYNC     =   8'h80;
72
 
73
 
74
//----------------------------------------------------------------------------
75
// UART COMMUNICATION DATA RATE CONFIGURATION
76
//----------------------------------------------------------------------------
77
// If the auto synchronization mode is set, then the communication speed
78
// is configured by the testbench.
79
// If not, the values from the openMSP430.inc file are taken over.
80
`ifdef DBG_UART_AUTO_SYNC
81 134 olivier.gi
parameter UART_BAUD   = 4000000;
82
integer   UART_PERIOD = 1000000000/UART_BAUD;
83 2 olivier.gi
`else
84 134 olivier.gi
integer   UART_PERIOD = `DBG_UART_CNT;
85 2 olivier.gi
`endif
86
 
87
//----------------------------------------------------------------------------
88
// Receive UART frame from CPU Debug interface (8N1)
89
//----------------------------------------------------------------------------
90 134 olivier.gi
 
91 2 olivier.gi
task dbg_uart_rx;
92 134 olivier.gi
   output [7:0] dbg_rxbuf;
93 2 olivier.gi
 
94 134 olivier.gi
   reg [7:0]     dbg_rxbuf;
95
   reg [7:0]     rxbuf;
96
   integer      rxcnt;
97
   begin
98
      #(1);
99
      dbg_uart_rx_busy = 1'b1;
100
      @(negedge dbg_uart_txd);
101
      dbg_rxbuf = 0;
102
      rxbuf     = 0;
103
      #(3*UART_PERIOD/2);
104
      for (rxcnt = 0; rxcnt < 8; rxcnt = rxcnt + 1)
105
        begin
106
           rxbuf = {dbg_uart_txd, rxbuf[7:1]};
107
           #(UART_PERIOD);
108
        end
109
      dbg_rxbuf        = rxbuf;
110
      dbg_uart_rx_busy = 1'b0;
111
   end
112 2 olivier.gi
endtask
113
 
114
task dbg_uart_rx16;
115
 
116 134 olivier.gi
   reg [7:0] rxbuf_lo;
117
   reg [7:0] rxbuf_hi;
118
   begin
119
      rxbuf_lo = 8'h00;
120
      rxbuf_hi = 8'h00;
121
      dbg_uart_rx(rxbuf_lo);
122
      dbg_uart_rx(rxbuf_hi);
123
      dbg_uart_buf = {rxbuf_hi, rxbuf_lo};
124
   end
125 2 olivier.gi
endtask
126
 
127
task dbg_uart_rx8;
128
 
129 134 olivier.gi
   reg [7:0] rxbuf;
130
   begin
131
      rxbuf = 8'h00;
132
      dbg_uart_rx(rxbuf);
133
      dbg_uart_buf = {8'h00, rxbuf};
134
   end
135 2 olivier.gi
endtask
136
 
137
//----------------------------------------------------------------------------
138
// Transmit UART frame to CPU Debug interface (8N1)
139
//----------------------------------------------------------------------------
140
task dbg_uart_tx;
141 134 olivier.gi
   input  [7:0] txbuf;
142
 
143
   reg [9:0]     txbuf_full;
144
   integer      txcnt;
145
   begin
146
      #(1);
147
      dbg_uart_tx_busy = 1'b1;
148
      dbg_uart_rxd_pre = 1'b1;
149
      txbuf_full       = {1'b1, txbuf, 1'b0};
150
      for (txcnt = 0; txcnt < 10; txcnt = txcnt + 1)
151
        begin
152
           #(UART_PERIOD);
153
           dbg_uart_rxd_pre =  txbuf_full[txcnt];
154
        end
155
      dbg_uart_tx_busy = 1'b0;
156
   end
157 2 olivier.gi
endtask
158
 
159
task dbg_uart_tx16;
160 134 olivier.gi
   input  [15:0] txbuf;
161
 
162
   begin
163
      dbg_uart_tx(txbuf[7:0]);
164
      dbg_uart_tx(txbuf[15:8]);
165
   end
166 2 olivier.gi
endtask
167
 
168 134 olivier.gi
always @(posedge mclk or posedge dbg_rst)
169
  if (dbg_rst)
170
    begin
171
       dbg_uart_rxd_sel <= 1'b0;
172
       dbg_uart_rxd_dly <= 1'b1;
173
    end
174
  else if (dbg_en)
175
    begin
176
       dbg_uart_rxd_sel <= dbg_uart_rxd_meta ? $random : 1'b0;
177
       dbg_uart_rxd_dly <= dbg_uart_rxd_pre;
178
    end
179 2 olivier.gi
 
180 134 olivier.gi
assign dbg_uart_rxd = dbg_uart_rxd_sel ? dbg_uart_rxd_dly : dbg_uart_rxd_pre;
181
 
182
 
183 2 olivier.gi
//----------------------------------------------------------------------------
184
// Write to Debug register
185
//----------------------------------------------------------------------------
186
task dbg_uart_wr;
187 134 olivier.gi
   input  [7:0] dbg_reg;
188
   input [15:0] dbg_data;
189
 
190
   begin
191
      dbg_uart_tx(DBG_WR | dbg_reg);
192
      dbg_uart_tx(dbg_data[7:0]);
193
      if (~dbg_reg[6])
194
        dbg_uart_tx(dbg_data[15:8]);
195
   end
196 2 olivier.gi
endtask
197
 
198
 
199
//----------------------------------------------------------------------------
200
// Read Debug register
201
//----------------------------------------------------------------------------
202
task dbg_uart_rd;
203 134 olivier.gi
   input  [7:0] dbg_reg;
204
 
205
   reg [7:0]     rxbuf_lo;
206
   reg [7:0]     rxbuf_hi;
207
   begin
208
      rxbuf_lo = 8'h00;
209
      rxbuf_hi = 8'h00;
210
      dbg_uart_tx(DBG_RD | dbg_reg);
211
      dbg_uart_rx(rxbuf_lo);
212
      if (~dbg_reg[6])
213
        dbg_uart_rx(rxbuf_hi);
214 2 olivier.gi
 
215 134 olivier.gi
      dbg_uart_buf = {rxbuf_hi, rxbuf_lo};
216 2 olivier.gi
      end
217
endtask
218 134 olivier.gi
 
219
//----------------------------------------------------------------------------
220
// Send synchronization frame
221
//----------------------------------------------------------------------------
222
task dbg_uart_sync;
223
   begin
224
      dbg_uart_tx(DBG_SYNC);
225
      repeat(10) @(posedge mclk);
226
   end
227
endtask
228
 
229
 

powered by: WebSVN 2.1.0

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