Line 39... |
Line 39... |
#
|
#
|
# Public functions:
|
# Public functions:
|
#
|
#
|
# - utils::uart_port_list ()
|
# - utils::uart_port_list ()
|
# - utils::uart_open (Device, Baudrate)
|
# - utils::uart_open (Device, Baudrate)
|
|
# - utils::uart_close ()
|
# - utils::uart_tx (Data)
|
# - utils::uart_tx (Data)
|
# - utils::uart_rx (Format, Length)
|
# - utils::uart_rx (Format, Length)
|
#
|
#
|
#----------------------------------------------------------------------------------
|
#----------------------------------------------------------------------------------
|
namespace eval utils {
|
namespace eval utils {
|
Line 85... |
Line 86... |
}
|
}
|
if {![llength $serial_ports]} {
|
if {![llength $serial_ports]} {
|
set serial_ports [list /dev/ttyS0 /dev/ttyS1 /dev/ttyS2 /dev/ttyS3]
|
set serial_ports [list /dev/ttyS0 /dev/ttyS1 /dev/ttyS2 /dev/ttyS3]
|
}
|
}
|
}
|
}
|
|
{Darwin} {
|
|
set serial_ports [glob -nocomplain /dev/cu.*]
|
|
}
|
{Windows NT} {
|
{Windows NT} {
|
package require registry
|
package require registry
|
set serial_base "HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\SERIALCOMM"
|
set serial_base "HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\SERIALCOMM"
|
set values [registry values $serial_base]
|
set values [registry values $serial_base]
|
foreach valueName $values {
|
foreach valueName $values {
|
Line 100... |
Line 104... |
|
|
return $serial_ports
|
return $serial_ports
|
}
|
}
|
|
|
#=============================================================================#
|
#=============================================================================#
|
# utils::uart_open (Device, Baudrate) #
|
# utils::uart_open (Device, Configure, Baudrate) #
|
#-----------------------------------------------------------------------------#
|
#-----------------------------------------------------------------------------#
|
# Description: Open and configure the UART connection. #
|
# Description: Open and configure the UART connection. #
|
# Arguments : Device - Serial port device (i.e. /dev/ttyS0 or COM2:) #
|
# Arguments : Device - Serial port device (i.e. /dev/ttyS0 or COM2:) #
|
# Configure - Configure serial communication (1:UART/0:I2C) #
|
# Configure - Configure serial communication (1:UART/0:I2C) #
|
# Baudrate - UART communication speed. #
|
# Baudrate - UART communication speed. #
|
Line 113... |
Line 117... |
proc uart_open {Device Configure Baudrate} {
|
proc uart_open {Device Configure Baudrate} {
|
|
|
global serial_ch
|
global serial_ch
|
|
|
# Open device for reading and writing
|
# Open device for reading and writing
|
if {[catch {open $Device RDWR} serial_ch]} {
|
if {[catch {open $Device [list RDWR]} serial_ch]} {
|
|
uart_close
|
return 0
|
return 0
|
}
|
}
|
|
|
if {$Configure} {
|
if {$Configure} {
|
# Setup the baud rate
|
# Setup the baud rate
|
Line 132... |
Line 137... |
|
|
return 1
|
return 1
|
}
|
}
|
|
|
#=============================================================================#
|
#=============================================================================#
|
|
# utils::uart_close (Device) #
|
|
#-----------------------------------------------------------------------------#
|
|
# Description: Closse the UART connection. #
|
|
# Arguments : None #
|
|
# Result : 0 if error, 1 otherwise. #
|
|
#=============================================================================#
|
|
proc uart_close {} {
|
|
|
|
global serial_ch
|
|
|
|
# Close the serial port
|
|
if {[info exists serial_ch]} {
|
|
|
|
if {[catch {close $serial_ch} response]} {
|
|
puts "Error while closing serial port:"
|
|
puts "$response"
|
|
after 500
|
|
return 0
|
|
}
|
|
after 500
|
|
}
|
|
return 1
|
|
}
|
|
|
|
#=============================================================================#
|
# utils::uart_tx (Data) #
|
# utils::uart_tx (Data) #
|
#-----------------------------------------------------------------------------#
|
#-----------------------------------------------------------------------------#
|
# Description: Transmit data over the serial debug interface. #
|
# Description: Transmit data over the serial debug interface. #
|
# Arguments : Data - Data byte list to be sent. #
|
# Arguments : Data - Data byte list to be sent. #
|
# Result : 0 if error, 1 otherwise. #
|
# Result : 0 if error, 1 otherwise. #
|