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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [fpga/] [actel_m1a3pl_dev_kit/] [bench/] [verilog/] [dbg_uart_tasks.v] - Blame information for rev 211

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

Line No. Rev Author Line
1 108 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
// $Rev: 17 $
35
// $LastChangedBy: olivier.girard $
36
// $LastChangedDate: 2009-08-04 23:15:39 +0200 (Tue, 04 Aug 2009) $
37
//----------------------------------------------------------------------------
38
 
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
 
65
// Read / Write commands
66
parameter           DBG_WR       =   8'h80;
67
parameter           DBG_RD       =   8'h00;
68
 
69
// Synchronization value
70
parameter           DBG_SYNC     =   8'h80;
71
 
72
 
73
//----------------------------------------------------------------------------
74
// UART COMMUNICATION DATA RATE CONFIGURATION
75
//----------------------------------------------------------------------------
76
// If the auto synchronization mode is set, then the communication speed
77
// is configured by the testbench.
78
// If not, the values from the openMSP430.inc file are taken over.
79
`ifdef DBG_UART_AUTO_SYNC
80 136 olivier.gi
parameter UART_BAUD   = 4000000;
81
integer   UART_PERIOD = 1000000000/UART_BAUD;
82 108 olivier.gi
`else
83 136 olivier.gi
integer   UART_PERIOD = `DBG_UART_CNT;
84 108 olivier.gi
`endif
85
 
86
//----------------------------------------------------------------------------
87
// Receive UART frame from CPU Debug interface (8N1)
88
//----------------------------------------------------------------------------
89 136 olivier.gi
 
90 108 olivier.gi
task dbg_uart_rx;
91 136 olivier.gi
   output [7:0] dbg_rxbuf;
92 108 olivier.gi
 
93 136 olivier.gi
   reg [7:0]     dbg_rxbuf;
94
   reg [7:0]     rxbuf;
95
   integer      rxcnt;
96
   begin
97
      #(1);
98
      dbg_uart_rx_busy = 1'b1;
99
      @(negedge dbg_uart_txd);
100
      dbg_rxbuf = 0;
101
      rxbuf     = 0;
102
      #(3*UART_PERIOD/2);
103
      for (rxcnt = 0; rxcnt < 8; rxcnt = rxcnt + 1)
104
        begin
105
           rxbuf = {dbg_uart_txd, rxbuf[7:1]};
106
           #(UART_PERIOD);
107
        end
108
      dbg_rxbuf        = rxbuf;
109
      dbg_uart_rx_busy = 1'b0;
110
   end
111 108 olivier.gi
endtask
112
 
113
task dbg_uart_rx16;
114
 
115 136 olivier.gi
   reg [7:0] rxbuf_lo;
116
   reg [7:0] rxbuf_hi;
117
   begin
118
      rxbuf_lo = 8'h00;
119
      rxbuf_hi = 8'h00;
120
      dbg_uart_rx(rxbuf_lo);
121
      dbg_uart_rx(rxbuf_hi);
122
      dbg_uart_buf = {rxbuf_hi, rxbuf_lo};
123
   end
124 108 olivier.gi
endtask
125
 
126
task dbg_uart_rx8;
127
 
128 136 olivier.gi
   reg [7:0] rxbuf;
129
   begin
130
      rxbuf = 8'h00;
131
      dbg_uart_rx(rxbuf);
132
      dbg_uart_buf = {8'h00, rxbuf};
133
   end
134 108 olivier.gi
endtask
135
 
136
//----------------------------------------------------------------------------
137
// Transmit UART frame to CPU Debug interface (8N1)
138
//----------------------------------------------------------------------------
139
task dbg_uart_tx;
140 136 olivier.gi
   input  [7:0] txbuf;
141
 
142
   reg [9:0]     txbuf_full;
143
   integer      txcnt;
144
   begin
145
      #(1);
146
      dbg_uart_tx_busy = 1'b1;
147
      dbg_uart_rxd_pre = 1'b1;
148
      txbuf_full       = {1'b1, txbuf, 1'b0};
149
      for (txcnt = 0; txcnt < 10; txcnt = txcnt + 1)
150
        begin
151
           #(UART_PERIOD);
152
           dbg_uart_rxd_pre =  txbuf_full[txcnt];
153
        end
154
      dbg_uart_tx_busy = 1'b0;
155
   end
156 108 olivier.gi
endtask
157
 
158
task dbg_uart_tx16;
159 136 olivier.gi
   input  [15:0] txbuf;
160
 
161
   begin
162
      dbg_uart_tx(txbuf[7:0]);
163
      dbg_uart_tx(txbuf[15:8]);
164
   end
165 108 olivier.gi
endtask
166
 
167 136 olivier.gi
always @(posedge mclk or posedge dbg_rst)
168
  if (dbg_rst)
169
    begin
170
       dbg_uart_rxd_sel <= 1'b0;
171
       dbg_uart_rxd_dly <= 1'b1;
172
    end
173
  else if (dbg_en)
174
    begin
175
       dbg_uart_rxd_sel <= dbg_uart_rxd_meta ? $random : 1'b0;
176
       dbg_uart_rxd_dly <= dbg_uart_rxd_pre;
177
    end
178 108 olivier.gi
 
179 136 olivier.gi
assign dbg_uart_rxd = dbg_uart_rxd_sel ? dbg_uart_rxd_dly : dbg_uart_rxd_pre;
180
 
181
 
182 108 olivier.gi
//----------------------------------------------------------------------------
183
// Write to Debug register
184
//----------------------------------------------------------------------------
185
task dbg_uart_wr;
186 136 olivier.gi
   input  [7:0] dbg_reg;
187
   input [15:0] dbg_data;
188
 
189
   begin
190
      dbg_uart_tx(DBG_WR | dbg_reg);
191
      dbg_uart_tx(dbg_data[7:0]);
192
      if (~dbg_reg[6])
193
        dbg_uart_tx(dbg_data[15:8]);
194
   end
195 108 olivier.gi
endtask
196
 
197
 
198
//----------------------------------------------------------------------------
199
// Read Debug register
200
//----------------------------------------------------------------------------
201
task dbg_uart_rd;
202 136 olivier.gi
   input  [7:0] dbg_reg;
203
 
204
   reg [7:0]     rxbuf_lo;
205
   reg [7:0]     rxbuf_hi;
206
   begin
207
      rxbuf_lo = 8'h00;
208
      rxbuf_hi = 8'h00;
209
      dbg_uart_tx(DBG_RD | dbg_reg);
210
      dbg_uart_rx(rxbuf_lo);
211
      if (~dbg_reg[6])
212
        dbg_uart_rx(rxbuf_hi);
213 108 olivier.gi
 
214 136 olivier.gi
      dbg_uart_buf = {rxbuf_hi, rxbuf_lo};
215 108 olivier.gi
      end
216
endtask
217 136 olivier.gi
 
218
//----------------------------------------------------------------------------
219
// Send synchronization frame
220
//----------------------------------------------------------------------------
221
task dbg_uart_sync;
222
   begin
223
      dbg_uart_tx(DBG_SYNC);
224
      repeat(10) @(posedge mclk);
225
   end
226
endtask
227
 
228
 

powered by: WebSVN 2.1.0

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