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 2

Go to most recent revision | 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
 
35
// Register B/W and addresses
36
parameter           CPU_ID_LO    =  (8'h00 | 8'h00);
37
parameter           CPU_ID_HI    =  (8'h00 | 8'h01);
38
parameter           CPU_CTL      =  (8'h40 | 8'h02);
39
parameter           CPU_STAT     =  (8'h40 | 8'h03);
40
parameter           MEM_CTL      =  (8'h40 | 8'h04);
41
parameter           MEM_ADDR     =  (8'h00 | 8'h05);
42
parameter           MEM_DATA     =  (8'h00 | 8'h06);
43
parameter           MEM_CNT      =  (8'h00 | 8'h07);
44
parameter           BRK0_CTL     =  (8'h40 | 8'h08);
45
parameter           BRK0_STAT    =  (8'h40 | 8'h09);
46
parameter           BRK0_ADDR0   =  (8'h00 | 8'h0A);
47
parameter           BRK0_ADDR1   =  (8'h00 | 8'h0B);
48
parameter           BRK1_CTL     =  (8'h40 | 8'h0C);
49
parameter           BRK1_STAT    =  (8'h40 | 8'h0D);
50
parameter           BRK1_ADDR0   =  (8'h00 | 8'h0E);
51
parameter           BRK1_ADDR1   =  (8'h00 | 8'h0F);
52
parameter           BRK2_CTL     =  (8'h40 | 8'h10);
53
parameter           BRK2_STAT    =  (8'h40 | 8'h11);
54
parameter           BRK2_ADDR0   =  (8'h00 | 8'h12);
55
parameter           BRK2_ADDR1   =  (8'h00 | 8'h13);
56
parameter           BRK3_CTL     =  (8'h40 | 8'h14);
57
parameter           BRK3_STAT    =  (8'h40 | 8'h15);
58
parameter           BRK3_ADDR0   =  (8'h00 | 8'h16);
59
parameter           BRK3_ADDR1   =  (8'h00 | 8'h17);
60
 
61
// Read / Write commands
62
parameter           DBG_WR       =   8'h80;
63
parameter           DBG_RD       =   8'h00;
64
 
65
// Synchronization value
66
parameter           DBG_SYNC     =   8'h80;
67
 
68
 
69
//----------------------------------------------------------------------------
70
// UART COMMUNICATION DATA RATE CONFIGURATION
71
//----------------------------------------------------------------------------
72
// If the auto synchronization mode is set, then the communication speed
73
// is configured by the testbench.
74
// If not, the values from the openMSP430.inc file are taken over.
75
`ifdef DBG_UART_AUTO_SYNC
76
parameter UART_BAUD = 4000000;
77
parameter UART_CNT  = ((20000000/UART_BAUD)-1);
78
`else
79
parameter UART_CNT  = `DBG_UART_CNT;
80
`endif
81
 
82
//----------------------------------------------------------------------------
83
// Receive UART frame from CPU Debug interface (8N1)
84
//----------------------------------------------------------------------------
85
task dbg_uart_rx;
86
      output [7:0] dbg_rxbuf;
87
 
88
      reg [7:0] dbg_rxbuf;
89
      reg [7:0] rxbuf;
90
      integer   rxcnt;
91
      begin
92
         @(negedge dbg_uart_txd);
93
         dbg_rxbuf = 0;
94
         rxbuf = 0;
95
         repeat((UART_CNT+1)/2) @(posedge mclk);
96
         for (rxcnt = 0; rxcnt < 8; rxcnt = rxcnt + 1)
97
           begin
98
              repeat(UART_CNT+1) @(posedge mclk);
99
              rxbuf = {dbg_uart_txd, rxbuf[7:1]};
100
           end
101
         dbg_rxbuf = rxbuf;
102
      end
103
endtask
104
 
105
task dbg_uart_rx16;
106
 
107
      reg [7:0] rxbuf_lo;
108
      reg [7:0] rxbuf_hi;
109
      begin
110
         rxbuf_lo = 8'h00;
111
         rxbuf_hi = 8'h00;
112
         dbg_uart_rx(rxbuf_lo);
113
         dbg_uart_rx(rxbuf_hi);
114
         dbg_uart_buf = {rxbuf_hi, rxbuf_lo};
115
      end
116
endtask
117
 
118
task dbg_uart_rx8;
119
 
120
      reg [7:0] rxbuf;
121
      begin
122
         rxbuf = 8'h00;
123
         dbg_uart_rx(rxbuf);
124
         dbg_uart_buf = {8'h00, rxbuf};
125
      end
126
endtask
127
 
128
//----------------------------------------------------------------------------
129
// Transmit UART frame to CPU Debug interface (8N1)
130
//----------------------------------------------------------------------------
131
task dbg_uart_tx;
132
      input  [7:0] txbuf;
133
 
134
      reg [9:0] txbuf_full;
135
      integer   txcnt;
136
      begin
137
         dbg_uart_rxd = 1'b1;
138
         txbuf_full   = {1'b1, txbuf, 1'b0};
139
         for (txcnt = 0; txcnt < 10; txcnt = txcnt + 1)
140
           begin
141
              repeat(UART_CNT+1) @(posedge mclk);
142
              dbg_uart_rxd =  txbuf_full[txcnt];
143
           end
144
      end
145
endtask
146
 
147
task dbg_uart_tx16;
148
      input  [15:0] txbuf;
149
 
150
      begin
151
         dbg_uart_tx(txbuf[7:0]);
152
         dbg_uart_tx(txbuf[15:8]);
153
      end
154
endtask
155
 
156
 
157
//----------------------------------------------------------------------------
158
// Write to Debug register
159
//----------------------------------------------------------------------------
160
task dbg_uart_wr;
161
      input  [7:0] dbg_reg;
162
      input [15:0] dbg_data;
163
 
164
      begin
165
         dbg_uart_tx(DBG_WR | dbg_reg);
166
         dbg_uart_tx(dbg_data[7:0]);
167
         if (~dbg_reg[6])
168
           dbg_uart_tx(dbg_data[15:8]);
169
      end
170
endtask
171
 
172
 
173
//----------------------------------------------------------------------------
174
// Read Debug register
175
//----------------------------------------------------------------------------
176
task dbg_uart_rd;
177
      input  [7:0] dbg_reg;
178
 
179
      reg [7:0] rxbuf_lo;
180
      reg [7:0] rxbuf_hi;
181
      begin
182
         rxbuf_lo = 8'h00;
183
         rxbuf_hi = 8'h00;
184
         dbg_uart_tx(DBG_RD | dbg_reg);
185
         dbg_uart_rx(rxbuf_lo);
186
         if (~dbg_reg[6])
187
           dbg_uart_rx(rxbuf_hi);
188
 
189
         dbg_uart_buf = {rxbuf_hi, rxbuf_lo};
190
      end
191
endtask

powered by: WebSVN 2.1.0

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