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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [tools/] [lib/] [tcl-lib/] [dbg_uart_generic.tcl] - Blame information for rev 188

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

Line No. Rev Author Line
1 158 olivier.gi
#----------------------------------------------------------------------------------
2 2 olivier.gi
# 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 158 olivier.gi
#----------------------------------------------------------------------------------
24 2 olivier.gi
# 
25 158 olivier.gi
# File Name:   dbg_uart_generic.tcl
26 2 olivier.gi
#
27 15 olivier.gi
# Author(s):
28
#             - Olivier Girard,    olgirard@gmail.com
29
#
30 158 olivier.gi
#----------------------------------------------------------------------------------
31 15 olivier.gi
# $Rev: 158 $
32
# $LastChangedBy: olivier.girard $
33
# $LastChangedDate: 2012-10-15 23:49:09 +0200 (Mon, 15 Oct 2012) $
34 158 olivier.gi
#----------------------------------------------------------------------------------
35 15 olivier.gi
#
36 158 olivier.gi
# Description:
37 2 olivier.gi
#
38 158 olivier.gi
#     Generic UART utility functions for the openMSP430 serial debug interface.
39
#
40
#     Mandatory Public functions:
41
#
42
#         - uart_generic::dbg_open           (Device,  Baudrate)
43
#         - uart_generic::dbg_connect        (CpuAddr)
44
#         - uart_generic::dbg_rd             (CpuAddr, RegisterName)
45
#         - uart_generic::dbg_wr             (CpuAddr, RegisterName, Data)
46
#         - uart_generic::dbg_burst_rx       (CpuAddr, Format,       Length)
47
#         - uart_generic::dbg_burst_tx       (CpuAddr, Format,       DataList)
48
#         - uart_generic::get_allowed_speeds ()
49
#
50
#
51
#     Private functions:
52
#
53
#         - uart::dbg_format_cmd             (RegisterName, Action)
54 2 olivier.gi
# 
55 158 olivier.gi
#----------------------------------------------------------------------------------
56
namespace eval uart_generic {
57 2 olivier.gi
 
58 158 olivier.gi
    #=============================================================================#
59
    # Source required libraries                                                   #
60
    #=============================================================================#
61 2 olivier.gi
 
62 158 olivier.gi
    set     scriptDir [file dirname [info script]]
63
    source $scriptDir/dbg_utils.tcl
64
 
65
 
66
    #=============================================================================#
67
    # uart_generic::dbg_open (Device, Baudrate)                                   #
68
    #-----------------------------------------------------------------------------#
69
    # Description: Open and configure the UART connection.                        #
70
    # Arguments  : Device   - Serial port device (i.e. /dev/ttyS0 or COM2:)       #
71
    #              Baudrate - UART communication speed.                           #
72
    # Result     : 0 if error, 1 otherwise.                                       #
73
    #=============================================================================#
74
    proc dbg_open {Device Baudrate} {
75 2 olivier.gi
 
76 158 olivier.gi
        # Open UART interface
77
        if {![utils::uart_open $Device 1 $Baudrate]} {
78 2 olivier.gi
            return 0
79
        }
80 158 olivier.gi
 
81
        return 1
82 2 olivier.gi
    }
83
 
84
 
85 158 olivier.gi
    #=============================================================================#
86
    # uart_generic::dbg_connect (CpuAddr)                                         #
87
    #-----------------------------------------------------------------------------#
88
    # Description: Send the synchronization frame in order to connect with the    #
89
    #              openMSP430 core.                                               #
90
    # Arguments  : CpuAddr - Unused argument for the UART interface (I2C only).   #
91
    # Result     : 0 if error, 1 otherwise.                                       #
92
    #=============================================================================#
93
    proc dbg_connect {CpuAddr} {
94
 
95
        # Send synchronisation frame
96
        utils::uart_tx {0x80}
97
        after 100
98
 
99
        # Send dummy frame in case the debug interface is already synchronized
100
        utils::uart_tx {0xC0}
101
        utils::uart_tx {0x00}
102 2 olivier.gi
 
103 158 olivier.gi
        return 1
104 2 olivier.gi
    }
105
 
106
 
107 158 olivier.gi
    #=============================================================================#
108
    # uart_generic::dbg_rd (CpuAddr, RegisterName)                                #
109
    #-----------------------------------------------------------------------------#
110
    # Description: Read the specified debug register.                             #
111
    # Arguments  : CpuAddr      - Unused for the UART interface (I2C only).       #
112
    #              RegisterName - Name of the register to be read.                #
113
    # Result     : Register content, in hexadecimal.                              #
114
    #=============================================================================#
115
    proc dbg_rd {CpuAddr RegisterName} {
116 2 olivier.gi
 
117 158 olivier.gi
        # Send command frame
118
        set cmd [dbg_format_cmd $RegisterName RD]
119
        utils::uart_tx $cmd
120 2 olivier.gi
 
121 158 olivier.gi
        # Compute size of data to be received
122
        if [string eq [expr 0x40 & $cmd] 64] {
123
            set format 1
124
            set length 1
125
        } else {
126
            set format 0
127
            set length 2
128
        }
129 2 olivier.gi
 
130 158 olivier.gi
        # Receive data
131
        set rx_data [utils::uart_rx $format $length]
132 2 olivier.gi
 
133 158 olivier.gi
        return $rx_data
134 2 olivier.gi
    }
135
 
136 158 olivier.gi
    #=============================================================================#
137
    # uart_generic::dbg_wr (CpuAddr, RegisterName, Data)                          #
138
    #-----------------------------------------------------------------------------#
139
    # Description: Write to the specified debug register.                         #
140
    # Arguments  : CpuAddr      - Unused for the UART interface (I2C only).       #
141
    #              RegisterName - Name of the register to be written.             #
142
    #              Data         - Data to be written.                             #
143
    # Result     : 0 if error, 1 otherwise.                                       #
144
    #=============================================================================#
145
    proc dbg_wr {CpuAddr RegisterName Data} {
146
 
147
        # Send command frame
148
        set cmd [dbg_format_cmd $RegisterName WR]
149
        utils::uart_tx $cmd
150 2 olivier.gi
 
151 158 olivier.gi
        # Format input data
152
        if {![regexp {0x} $Data match]} {
153
            set Data [format "0x%x" $Data]
154
        }
155
        set hex_val [format %04x $Data]
156
        regexp {(..)(..)} $hex_val match hex_msb hex_lsb
157 2 olivier.gi
 
158 158 olivier.gi
        # Compute size of data to be sent
159
        if [string eq [expr 0x40 & $cmd] 64] {
160
            set size 1
161
        } else {
162
            set size 2
163
        }
164 2 olivier.gi
 
165 158 olivier.gi
        # Send data
166
        utils::uart_tx "0x$hex_lsb"
167
        if {$size==2} {
168
            utils::uart_tx "0x$hex_msb"
169
        }
170 2 olivier.gi
 
171 158 olivier.gi
        return 1
172 2 olivier.gi
    }
173
 
174 158 olivier.gi
    #=============================================================================#
175
    # uart_generic::dbg_burst_rx (CpuAddr, Format, Length)                        #
176
    #-----------------------------------------------------------------------------#
177
    # Description: Receive data list as burst from the serial debug interface.    #
178
    # Arguments  : CpuAddr  - Unused for the UART interface (I2C only).           #
179
    #              Format   - 0 format as 16 bit word, 1 format as 8 bit word.    #
180
    #              Length   - Number of byte to be received.                      #
181
    # Result     : 0 if error, 1 otherwise.                                       #
182
    #=============================================================================#
183
    proc dbg_burst_rx {CpuAddr Format Length} {
184 2 olivier.gi
 
185 158 olivier.gi
        return [utils::uart_rx $Format $Length]
186 2 olivier.gi
 
187 158 olivier.gi
    }
188 2 olivier.gi
 
189 158 olivier.gi
    #=============================================================================#
190
    # uart_generic::dbg_burst_tx (CpuAddr, Format, DataList)                      #
191
    #-----------------------------------------------------------------------------#
192
    # Description: Transmit data list as burst to the serial debug interface.     #
193
    # Arguments  : CpuAddr   - Unused for the UART interface (I2C only).          #
194
    #              Format    - 0 format as 16 bit word, 1 format as 8 bit word.   #
195
    #              DataList  - List of data to be written (in hexadecimal).       #
196
    # Result     : 0 if error, 1 otherwise.                                       #
197
    #=============================================================================#
198
    proc dbg_burst_tx {CpuAddr Format DataList} {
199 2 olivier.gi
 
200 158 olivier.gi
        foreach data [split $DataList] {
201 2 olivier.gi
 
202 158 olivier.gi
            if {$Format==1} {                 ####  8-bit data format ####
203
                # Format data
204
                set data [format %02x $data]
205 2 olivier.gi
 
206 158 olivier.gi
                # Send data
207
                utils::uart_tx "0x$data"
208 2 olivier.gi
 
209 158 olivier.gi
            } else {                          #### 16-bit data format ####
210
                # Format data
211
                set data [format %04x $data]
212
                regexp {(..)(..)} $data match data_msb data_lsb
213
 
214
                # Send data
215
                utils::uart_tx "0x$data_lsb 0x$data_msb"
216
            }
217
        }
218 2 olivier.gi
    }
219
 
220 158 olivier.gi
    #=============================================================================#
221
    # uart_generic::get_allowed_speeds ()                                         #
222
    #-----------------------------------------------------------------------------#
223
    # Description: Return the list of allowed UART baudrates.                     #
224
    #=============================================================================#
225
    proc get_allowed_speeds {} {
226 2 olivier.gi
 
227 158 olivier.gi
        #             Editable    Default             UART-Baudrates
228
        return [list     1        115200      [list          9600          \
229
                                                            19200          \
230
                                                            38400          \
231
                                                            57600          \
232
                                                           115200          \
233
                                                           230400          \
234
                                                           460800          \
235
                                                           500000          \
236
                                                           576000          \
237
                                                           921600          \
238
                                                          1000000          \
239
                                                          1152000          \
240
                                                          2000000]         ]
241 2 olivier.gi
    }
242
 
243 158 olivier.gi
###################################################################################################
244
###################################################################################################
245
###################################################################################################
246
###################################################################################################
247
#######                                                                                     #######
248
#######                             PRIVATE FUNCTIONS                                       #######
249
#######                                                                                     #######
250
###################################################################################################
251
###################################################################################################
252
###################################################################################################
253
###################################################################################################
254 2 olivier.gi
 
255 158 olivier.gi
    #=============================================================================#
256
    # uart_generic::dbg_format_cmd (RegisterName, Action)                         #
257
    #-----------------------------------------------------------------------------#
258
    # Description: Get the correcponding UART command to a given debug register   #
259
    #              access.                                                        #
260
    # Arguments  : RegisterName - Name of the register to be accessed.            #
261
    #              Action       - RD for read / WR for write.                     #
262
    # Result     : Command to be sent via UART.                                   #
263
    #=============================================================================#
264
    proc dbg_format_cmd {RegisterName Action} {
265 2 olivier.gi
 
266 158 olivier.gi
        switch -exact $Action {
267
            RD         {set rd_wr "0x00"}
268
            WR         {set rd_wr "0x080"}
269
            default    {set rd_wr "0x00"}
270
        }
271 2 olivier.gi
 
272 158 olivier.gi
        switch -exact $RegisterName {
273
            CPU_ID_LO  {set uart_cmd  [format "0x%02x" [expr $rd_wr | 0x00 | 0x00]]}
274
            CPU_ID_HI  {set uart_cmd  [format "0x%02x" [expr $rd_wr | 0x00 | 0x01]]}
275
            CPU_CTL    {set uart_cmd  [format "0x%02x" [expr $rd_wr | 0x40 | 0x02]]}
276
            CPU_STAT   {set uart_cmd  [format "0x%02x" [expr $rd_wr | 0x40 | 0x03]]}
277
            MEM_CTL    {set uart_cmd  [format "0x%02x" [expr $rd_wr | 0x40 | 0x04]]}
278
            MEM_ADDR   {set uart_cmd  [format "0x%02x" [expr $rd_wr | 0x00 | 0x05]]}
279
            MEM_DATA   {set uart_cmd  [format "0x%02x" [expr $rd_wr | 0x00 | 0x06]]}
280
            MEM_CNT    {set uart_cmd  [format "0x%02x" [expr $rd_wr | 0x00 | 0x07]]}
281
            BRK0_CTL   {set uart_cmd  [format "0x%02x" [expr $rd_wr | 0x40 | 0x08]]}
282
            BRK0_STAT  {set uart_cmd  [format "0x%02x" [expr $rd_wr | 0x40 | 0x09]]}
283
            BRK0_ADDR0 {set uart_cmd  [format "0x%02x" [expr $rd_wr | 0x00 | 0x0A]]}
284
            BRK0_ADDR1 {set uart_cmd  [format "0x%02x" [expr $rd_wr | 0x00 | 0x0B]]}
285
            BRK1_CTL   {set uart_cmd  [format "0x%02x" [expr $rd_wr | 0x40 | 0x0C]]}
286
            BRK1_STAT  {set uart_cmd  [format "0x%02x" [expr $rd_wr | 0x40 | 0x0D]]}
287
            BRK1_ADDR0 {set uart_cmd  [format "0x%02x" [expr $rd_wr | 0x00 | 0x0E]]}
288
            BRK1_ADDR1 {set uart_cmd  [format "0x%02x" [expr $rd_wr | 0x00 | 0x0F]]}
289
            BRK2_CTL   {set uart_cmd  [format "0x%02x" [expr $rd_wr | 0x40 | 0x10]]}
290
            BRK2_STAT  {set uart_cmd  [format "0x%02x" [expr $rd_wr | 0x40 | 0x11]]}
291
            BRK2_ADDR0 {set uart_cmd  [format "0x%02x" [expr $rd_wr | 0x00 | 0x12]]}
292
            BRK2_ADDR1 {set uart_cmd  [format "0x%02x" [expr $rd_wr | 0x00 | 0x13]]}
293
            BRK3_CTL   {set uart_cmd  [format "0x%02x" [expr $rd_wr | 0x40 | 0x14]]}
294
            BRK3_STAT  {set uart_cmd  [format "0x%02x" [expr $rd_wr | 0x40 | 0x15]]}
295
            BRK3_ADDR0 {set uart_cmd  [format "0x%02x" [expr $rd_wr | 0x00 | 0x16]]}
296
            BRK3_ADDR1 {set uart_cmd  [format "0x%02x" [expr $rd_wr | 0x00 | 0x17]]}
297
            CPU_NR     {set uart_cmd  [format "0x%02x" [expr $rd_wr | 0x00 | 0x18]]}
298
            default    {set uart_cmd  "0x00"}
299
        }
300 2 olivier.gi
 
301 158 olivier.gi
        return $uart_cmd
302 2 olivier.gi
    }
303
 
304
}

powered by: WebSVN 2.1.0

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