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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [tools/] [lib/] [tcl-lib/] [dbg_functions.tcl] - Diff between revs 96 and 110

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 96 Rev 110
Line 26... Line 26...
#
#
# Author(s):
# Author(s):
#             - Olivier Girard,    olgirard@gmail.com
#             - Olivier Girard,    olgirard@gmail.com
#
#
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# $Rev: 96 $
# $Rev: 110 $
# $LastChangedBy: olivier.girard $
# $LastChangedBy: olivier.girard $
# $LastChangedDate: 2011-02-27 21:29:35 +0100 (Sun, 27 Feb 2011) $
# $LastChangedDate: 2011-05-19 22:33:51 +0200 (Thu, 19 May 2011) $
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
#
#
# Description: Main utility functions for the openMSP430 serial debug
# Description: Main utility functions for the openMSP430 serial debug
#             interface.
#             interface.
#
#
Line 71... Line 71...
#               - InitBreakUnits  ()
#               - InitBreakUnits  ()
#               - SetHWBreak      (Type, Addr,      Rd,       Wr)
#               - SetHWBreak      (Type, Addr,      Rd,       Wr)
#               - ClearHWBreak    (Type, Addr)
#               - ClearHWBreak    (Type, Addr)
#               - IsHalted        ()
#               - IsHalted        ()
#               - ClrStatus       ()
#               - ClrStatus       ()
 
#               - GetChipAlias    ()
# 
# 
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
 
 
# GLOBAL VARIABLES
# GLOBAL VARIABLES
global hw_break
global hw_break
 
global omsp_info
 
set    omsp_info(connected) 0
 
 
# SOURCE REQUIRED LIBRARIES
# SOURCE REQUIRED LIBRARIES
source [file dirname [info script]]/dbg_uart.tcl
set     scriptDir [file dirname [info script]]
 
source $scriptDir/dbg_uart.tcl
 
source $scriptDir/xml.tcl
 
 
 
 
#=============================================================================#
#=============================================================================#
# ExecutePOR ()                                                               #
# ExecutePOR ()                                                               #
#-----------------------------------------------------------------------------#
#-----------------------------------------------------------------------------#
# Description: Executes a power-up clear (PUC) command.                       #
# Description: Executes a power-up clear (PUC) command.                       #
# Arguments  : None.                                                          #
# Arguments  : None.                                                          #
# Result     : 0 if error, 1 otherwise.                                       #
# Result     : 0 if error, 1 otherwise.                                       #
#=============================================================================#
#=============================================================================#
proc ExecutePOR {} {
proc ExecutePOR {} {
 
 
    set result 1
 
 
 
    # Set PUC
    # Set PUC
    set cpu_ctl_org [dbg_uart_rd CPU_CTL]
    set cpu_ctl_org [dbg_uart_rd CPU_CTL]
    set cpu_ctl_new [expr 0x40 | $cpu_ctl_org]
    set cpu_ctl_new [expr 0x40 | $cpu_ctl_org]
    dbg_uart_wr CPU_CTL $cpu_ctl_new
    dbg_uart_wr CPU_CTL $cpu_ctl_new
 
 
Line 102... Line 106...
    set cpu_ctl_org [expr 0x5f & $cpu_ctl_org]
    set cpu_ctl_org [expr 0x5f & $cpu_ctl_org]
    dbg_uart_wr CPU_CTL $cpu_ctl_org
    dbg_uart_wr CPU_CTL $cpu_ctl_org
 
 
    # Check CPU ID
    # Check CPU ID
    if {![VerifyCPU_ID]} {
    if {![VerifyCPU_ID]} {
        set result 0
        return 0
    }
    }
 
 
    # Check status: make sure a PUC occured
    # Check status: make sure a PUC occured
    set cpu_stat_val [dbg_uart_rd CPU_STAT]
    set cpu_stat_val [dbg_uart_rd CPU_STAT]
    set puc_pnd      [expr 0x04 & $cpu_stat_val]
    set puc_pnd      [expr 0x04 & $cpu_stat_val]
    if {![string eq $puc_pnd 4]} {
    if {![string eq $puc_pnd 4]} {
        set result 0
        return 0
    }
    }
 
 
    # Clear PUC pending flag
    # Clear PUC pending flag
    dbg_uart_wr CPU_STAT 0x04
    dbg_uart_wr CPU_STAT 0x04
 
 
    return $result
    return 1
}
}
 
 
#=============================================================================#
#=============================================================================#
# SetPC (Addr)                                                                #
# SetPC (Addr)                                                                #
#-----------------------------------------------------------------------------#
#-----------------------------------------------------------------------------#
Line 197... Line 201...
# Result     : 0 if error, 1 otherwise.                                       #
# Result     : 0 if error, 1 otherwise.                                       #
#=============================================================================#
#=============================================================================#
proc GetDevice {} {
proc GetDevice {} {
 
 
    global hw_break
    global hw_break
 
    global omsp_info
 
 
    # Set UART global variables
    # Set UART global variables
    if {![info exists ::serial_baudrate]} {
    if {![info exists ::serial_baudrate]} {
        set ::serial_baudrate 9600
        set ::serial_baudrate 9600
    }
    }
Line 211... Line 216...
    # Open connection
    # Open connection
    if {![dbg_uart_connect $::serial_device $::serial_baudrate]} {
    if {![dbg_uart_connect $::serial_device $::serial_baudrate]} {
        return 0
        return 0
    }
    }
 
 
 
    if {[VerifyCPU_ID]} {
 
 
    # Enable auto-freeze & software breakpoints
    # Enable auto-freeze & software breakpoints
    dbg_uart_wr CPU_CTL 0x0018
    dbg_uart_wr CPU_CTL 0x0018
 
 
 
        # Initialize the omsp_info global variable
 
        GetCPU_ID
 
        set omsp_info(connected) 1
 
 
    # Get number of hardware breakpoints
    # Get number of hardware breakpoints
    set hw_break(num) [InitBreakUnits]
    set hw_break(num) [InitBreakUnits]
 
        set omsp_info(hw_break) $hw_break(num)
 
 
    # Check CPU ID
 
    return [VerifyCPU_ID]
        return 1
 
    } else {
 
        return 0
 
    }
}
}
 
 
#=============================================================================#
#=============================================================================#
# ReleaseDevice (Addr)                                                        #
# ReleaseDevice (Addr)                                                        #
#-----------------------------------------------------------------------------#
#-----------------------------------------------------------------------------#
Line 430... Line 445...
}
}
 
 
#=============================================================================#
#=============================================================================#
# GetCPU_ID ()                                                                #
# GetCPU_ID ()                                                                #
#-----------------------------------------------------------------------------#
#-----------------------------------------------------------------------------#
# Description: This function reads the CPU_ID from the target device.         #
# Description: This function reads the CPU_ID from the target device, update  #
 
#              the omsp_info global variable and return the raw CPU_ID value. #
# Arguments  : None.                                                          #
# Arguments  : None.                                                          #
# Result     : Return CPU_ID.                                                 #
# Result     : Return CPU_ID.                                                 #
#=============================================================================#
#=============================================================================#
proc GetCPU_ID { } {
proc GetCPU_ID { } {
 
 
 
    global omsp_info
 
 
 
    # Retreive CPU_ID values
    regsub {0x} [dbg_uart_rd CPU_ID_LO] {} cpu_id_lo
    regsub {0x} [dbg_uart_rd CPU_ID_LO] {} cpu_id_lo
    regsub {0x} [dbg_uart_rd CPU_ID_HI] {} cpu_id_hi
    regsub {0x} [dbg_uart_rd CPU_ID_HI] {} cpu_id_hi
 
 
    return "0x$cpu_id_hi$cpu_id_lo"
    set cpu_id    "0x$cpu_id_hi$cpu_id_lo"
 
    set cpu_id_lo "0x$cpu_id_lo"
 
    set cpu_id_hi "0x$cpu_id_hi"
 
 
 
 
 
    # Extract the omsp info depending on the CPU version
 
    set omsp_info(cpu_ver) [expr ($cpu_id_lo & 0x0007)+1]
 
    if {$omsp_info(cpu_ver)==1} {
 
        set omsp_info(asic)         0
 
        set omsp_info(user_ver)    --
 
        set omsp_info(per_size)   512
 
        set omsp_info(mpy)         --
 
        set omsp_info(dmem_size)  [expr $cpu_id_lo]
 
        set omsp_info(pmem_size)  [expr $cpu_id_hi]
 
    } else {
 
        set omsp_info(asic)       [expr  ($cpu_id_lo & 0x0008)/8]
 
        set omsp_info(user_ver)   [expr  ($cpu_id_lo & 0x01f0)/9]
 
        set omsp_info(per_size)   [expr (($cpu_id_lo & 0xfe00)/512)  * 512]
 
        set omsp_info(mpy)        [expr  ($cpu_id_hi & 0x0001)/1]
 
        set omsp_info(dmem_size)  [expr (($cpu_id_hi & 0x03fe)/2)    * 128]
 
        set omsp_info(pmem_size)  [expr (($cpu_id_hi & 0xfc00)/1024) * 1024]
 
    }
 
 
 
    set omsp_info(alias) [GetChipAlias]
 
 
 
    return $cpu_id
}
}
 
 
#=============================================================================#
#=============================================================================#
# GetCPU_ID_SIZE ()                                                           #
# GetCPU_ID_SIZE ()                                                           #
#-----------------------------------------------------------------------------#
#-----------------------------------------------------------------------------#
# Description: Returns the ROM and RAM sizes of the connected device.         #
# Description: Returns the Data and Program memory sizes of the connected     #
 
#              device.                                                        #
# Arguments  : None.                                                          #
# Arguments  : None.                                                          #
# Result     : Return "ROM_SIZE RAM_SIZE" in byte.                            #
# Result     : Return "PMEM_SIZE DMEM_SIZE" in byte.                          #
#=============================================================================#
#=============================================================================#
proc GetCPU_ID_SIZE {} {
proc GetCPU_ID_SIZE {} {
 
 
    set cpu_id_full [GetCPU_ID]
    global omsp_info
    regexp {(....)(....)$} $cpu_id_full match rom_size ram_size
 
 
 
    if {[info exists rom_size]} {
    if {[info exists omsp_info(pmem_size)]} {
        set rom_size [expr 0x$rom_size]
        set pmem_size $omsp_info(pmem_size)
    } else {
    } else {
        set rom_size -1
        set pmem_size -1
    }
    }
    if {[info exists ram_size]} {
    if {[info exists omsp_info(dmem_size)]} {
        set ram_size [expr 0x$ram_size]
        set dmem_size $omsp_info(dmem_size)
    } else {
    } else {
        set ram_size -1
        set dmem_size -1
    }
    }
 
 
    return "$rom_size $ram_size"
    return "$pmem_size $dmem_size"
}
}
 
 
#=============================================================================#
#=============================================================================#
# VerifyCPU_ID ()                                                             #
# VerifyCPU_ID ()                                                             #
#-----------------------------------------------------------------------------#
#-----------------------------------------------------------------------------#
Line 479... Line 523...
#=============================================================================#
#=============================================================================#
proc VerifyCPU_ID {} {
proc VerifyCPU_ID {} {
 
 
    set cpu_id_full [GetCPU_ID]
    set cpu_id_full [GetCPU_ID]
 
 
    if {[string eq "0x00000000" $cpu_id_full] | [string eq "0x" $cpu_id_full]} {
    if {[string eq "0x00000000" $cpu_id_full] |
 
        ([string length $cpu_id_full]!=10)} {
        set result 0
        set result 0
    } else {
    } else {
        set result 1
        set result 1
    }
    }
    return $result
    return $result
Line 831... Line 876...
    dbg_uart_wr BRK3_STAT 0xff
    dbg_uart_wr BRK3_STAT 0xff
 
 
    return 1
    return 1
}
}
 
 
 No newline at end of file
 No newline at end of file
 
#=============================================================================#
 
# GetChipAlias ()                                                             #
 
#-----------------------------------------------------------------------------#
 
# Description: Parse the chip alias XML file an return the alias name.        #
 
# Arguments  : None.                                                          #
 
# Result     : Chip Alias.                                                    #
 
#=============================================================================#
 
proc GetChipAlias {} {
 
 
 
    global omsp_info
 
 
 
    # Set XML file name
 
    if {[info exists  ::env(OMSP_XML_FILE)]} {
 
        set xmlFile $::env(OMSP_XML_FILE)
 
    } else {
 
        set xmlFile [file normalize "$::scriptDir/../../omsp_alias.xml"]
 
    }
 
 
 
    # Read XML file
 
    if {[file exists $xmlFile]} {
 
        set fp [open $xmlFile r]
 
        set xmlData [read $fp]
 
        close $fp
 
    } else {
 
        puts "WARNING: the XML alias file was not found - $xmlFile"
 
        return ""
 
    }
 
 
 
    # Analyze XML file
 
    ::XML::Init $xmlData
 
    set wellFormed [::XML::IsWellFormed]
 
    if {$wellFormed ne ""} {
 
        puts "WARNING: the XML alias file is not well-formed - $xmlFile \n $wellFormed"
 
        return ""
 
    }
 
 
 
    #========================================================================#
 
    # Create list from XML file                                              #
 
    #========================================================================#
 
    set aliasList    ""
 
    set currentALIAS ""
 
    set currentTYPE  ""
 
    set currentTAG   ""
 
    while {1} {
 
        foreach {type val attr etype} [::XML::NextToken] break
 
        if {$type == "EOF"} break
 
 
 
        # Detect the start of a new alias description
 
        if {($type == "XML") & ($val == "omsp:alias") & ($etype == "START")} {
 
            set aliasName ""
 
            regexp {val=\"(.*)\"} $attr whole_match aliasName
 
            lappend aliasList $aliasName
 
            set currentALIAS $aliasName
 
        }
 
 
 
        # Detect start and end of the configuration field
 
        if {($type == "XML") & ($val == "omsp:configuration")} {
 
 
 
            if {($etype == "START")} {
 
                set currentTYPE  "config"
 
 
 
            } elseif {($etype == "END")} {
 
                set currentTYPE  ""
 
            }
 
        }
 
 
 
        # Detect start and end of the extra_info field
 
        if {($type == "XML") & ($val == "omsp:extra_info")} {
 
 
 
            if {($etype == "START")} {
 
                set currentTYPE  "extra_info"
 
                set idx 0
 
 
 
            } elseif {($etype == "END")} {
 
                set currentTYPE  ""
 
            }
 
        }
 
 
 
        # Detect the current TAG
 
        if {($type == "XML") & ($etype == "START")} {
 
            regsub {omsp:} $val {} val
 
            set currentTAG $val
 
        }
 
 
 
        if {($type == "TXT")} {
 
            if {$currentTYPE=="extra_info"} {
 
                set alias($currentALIAS,$currentTYPE,$idx,$currentTAG) $val
 
                incr idx
 
            } else {
 
                set alias($currentALIAS,$currentTYPE,$currentTAG) $val
 
            }
 
        }
 
    }
 
 
 
    #========================================================================#
 
    # Check if the current OMSP_INFO has an alias match                      #
 
    #========================================================================#
 
    foreach currentALIAS $aliasList {
 
        set aliasCONFIG [array names alias -glob "$currentALIAS,config,*"]
 
        set aliasEXTRA  [lsort -increasing [array names alias -glob "$currentALIAS,extra_info,*"]]
 
 
 
        #----------------------------------#
 
        # Is current alias matching ?      #
 
        #----------------------------------#
 
        set match       1
 
        set description ""
 
        foreach currentCONFIG $aliasCONFIG {
 
 
 
            regsub "$currentALIAS,config," $currentCONFIG {} configName
 
 
 
            if {![string eq $omsp_info($configName) $alias($currentCONFIG)]} {
 
                set match 0
 
            }
 
        }
 
 
 
        #----------------------------------#
 
        # If matching, get the extra infos #
 
        #----------------------------------#
 
        if {$match} {
 
 
 
            set idx 0
 
            foreach currentEXTRA $aliasEXTRA {
 
                regsub "$currentALIAS,extra_info," $currentEXTRA {} extraName
 
                set omsp_info(extra,$idx,$extraName) $alias($currentEXTRA)
 
                incr idx
 
            }
 
            return $currentALIAS
 
        }
 
    }
 
 
 
    return ""
 
}
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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