📄 pm5337_util.tcl
字号:
#------------------------------------------------------------------------------# SCRIPT NAME: pm5337_util.tcl# DESCRIPTION: These scripts are not device specific, but are# called by other routines in this archive.# This file includes the following procedures:# 1) admrd# 2) admwr# 3) admrdb# 4) admwrb# 5) admindrd# 6) admindwr# 7) Poll_BUSY_Bit# 8) Linear_APS_Source_Select# 9) MDIOWrite# 10) MDIORead# 11) MDIOClockSet# 12) imask# 13) EOS_MSTAT_Counter_Demo## NOTES:## REVISION HISTORY:# Preliminary 1 # - Script created##------------------------------------------------------------------------------#------------------------------------------------------------------------------# PROC NAME: admrd## DESCRIPTION: This procedure is a wrapper to a system specific # 'read' function. ## PARAMETERS: devID - This parameter is used to specify the device # under configuration. If devID is -1, this function# is echo on the TCL console.# # address - Register offset or bit name# # NOTES: 1. Clear-on-read (i.e. interrupts) bit values# may be lost.# 2. The bit name is the form of SUBSYSTEM::MTSB::TSB::Bitname##------------------------------------------------------------------------------#source /home/apps/indirect.tclproc admrd {devID address} { if {$devID != -1} { ### Addressing by register offset ### # Replace READ_ADM with the system specific read command set rResult [rd adm [format "0x%04X" $address]] # Return read value in hex format set rResult [format "0x%04X" $rResult] return $rResult } else { # Echo the admrd command to TCL console puts "admrd 0 [format "0x%04X" $address] <br>"; } }#------------------------------------------------------------------------------# PROC NAME: admwr## DESCRIPTION: This procedure is a wrapper to a system specific# write function. ## PARAMETERS: devID - This parameter is used to specify the device # under configuration. If devID is -1, this function# is echo on the TCL console.## address - Register offset ## value - Register value# # NOTES: #------------------------------------------------------------------proc admwr {devID address value} { if {$devID != -1} { ### Addressing by register offset ### # Replace WRITE_ADM with the system specific read command wr adm [format "0x%04X" $address] [format "0x%04X" $value] } else { # Echo the admwr command to TCL console puts "admwr 0 [format "0x%04X" $address] [format "0x%04X" $value] <br>"; } }#------------------------------------------------------------------# PROC NAME: admrdb## DESCRIPTION: Read a single bit from a register## PARAMETERS: devID - This parameter is used to specify the device # under configuration. If devID is -1, this function# is echo on the TCL console.## address - Register offset ## bit - Bit position to be read# # NOTES: Clear-on-read (i.e. interrupts) bit values# may be lost.##------------------------------------------------------------------proc admrdb {devID address bit} { set address [format "0x%04X" $address] if {$devID != -1} { set data [admrd $devID $address] if {$bit >= 0 && $bit <=30} { set bitmask [expr int(pow(2,$bit))] } elseif {$bit == 31} { set bitmask 0x80000000 ;# int() command can't handle this value } else { puts "Invalid Bit Position Value" return } # Display bit value on console set data [expr [expr $data & $bitmask ] >> $bit] return $data } else { # Echo the admrdb command to TCL console puts "admrdb 0 [format "0x%04X" $address] $bit <br>"; } }#------------------------------------------------------------------# PROC NAME: admwrb## DESCRIPTION: Write a single bit to a register## PARAMETERS: devID - This parameter is used to specify the device # under configuration. If devID is -1, this function# is echo on the TCL console.## address - Register offset ## bit - Bit position to be written## value - Bit value 0 or 1 ## NOTES: This procedure reads the register value before writing# the specified bit. Clear-on-read (i.e. interrupts) bit # values may be lost.##------------------------------------------------------------------proc admwrb {devID address bit value} { set address [format "0x%04X" $address] set value [format "0x%04X" $value] if {$devID != -1} { if {$bit >= 0 && $bit <=30} { set bitmask [expr int(pow(2,$bit))] } elseif {$bit == 31} { set bitmask 0x80000000 ;# int() command can't handle this value } else { puts "Invalid Bit Position Value" return } # Read the current register value set data [admrd $devID $address] # Modify value if {$value == 1} { set data [expr $data | $bitmask] } else { set data [expr $data & ~($bitmask)] } # Write value to register return [admwr $devID [format "0x%04X" $address] [format "0x%04X" $data]] } else { # Echo the admwrb command to TCL console puts "admwrb 0 [format "0x%04X" $address] $bit $value <br>"; }}#-------------------------------------------------------------------------------------------------------------# PROC NAME: admindrd## DESCRIPTION: This procedure is a wrapper to a system specific# indirect read function. ## PARAMETERS: devID - This parameter is used to specify the device # under configuration. If devID is -1, this function# is echo on the TCL console.## block - name of the system block## iaddr - indirect register address## para1 to para4: the definition for para1 to para4 depends on which system block# is being access.## NOTES: ##------------------------------------------------------------------------------------------------------------proc admindrd {devID block {para1 -1} {para2 -1} {para3 -1} {para4 -1} {para5 -1} {para6 -1} {para7 -1} {para8 -1} {para9 -1} {para10 -1} {para11 -1} {para12 -1}} { source /home/apps/indirect.tcl if {$para1 == -1} { set para1 "" } if {$para2 == -1} { set para2 "" } if {$para3 == -1} { set para3 "" } if {$para4 == -1} { set para4 "" } if {$para5 == -1} { set para5 "" } if {$para6 == -1} { set para6 "" } if {$para7 == -1} { set para7 "" } if {$para8 == -1} { set para8 "" } if {$para9 == -1} { set para9 "" } if {$para10 == -1} { set para10 "" } if {$para11 == -1} { set para11 "" } if {$para12 == -1} { set para12 "" } if {$devID != -1} { # put adm indirect read driver command here set value [ iread "adm" $block $para1 $para2 $para3 $para4 $para5 $para6 $para7 $para8 $para9 $para10 $para11 $para12] return $value put_error $rv return -1 } else { # Echo the admindrd command to TCL console puts "admindrd 0 $block $para1 $para2 $para3 $para4 $para5 $para6 $para7 $para8 $para9 $para10 $para11 $para12<br>"; }}#-------------------------------------------------------------------------------------------------------------# PROC NAME: admindwr## DESCRIPTION: This procedure is a wrapper to a system specific# indirect read function. ## PARAMETERS: devID - This parameter is used to specify the device # under configuration. If devID is -1, this function# is echo on the TCL console.## block - name of the system block## iaddr - indirect register address## value - register value## para1 to para4: the definition for para1 to para4 depends on which system block# is being access.## NOTES: ##------------------------------------------------------------------------------------------------------------proc admindwr {devID block {para1 -1} {para2 -1} {para3 -1} {para4 -1} {para5 -1} {para6 -1} {para7 -1} {para8 -1} {para9 -1} {para10 -1} {para11 -1} {para12 -1}} { source /home/apps/indirect.tcl if {$para1 == -1} { set para1 "" } if {$para2 == -1} { set para2 "" } if {$para3 == -1} { set para3 "" } if {$para4 == -1} { set para4 "" } if {$para5 == -1} { set para5 "" } if {$para6 == -1} { set para6 "" } if {$para7 == -1} { set para7 "" } if {$para8 == -1} { set para8 "" } if {$para9 == -1} { set para9 "" } if {$para10 == -1} { set para10 "" } if {$para11 == -1} { set para11 "" } if {$para12 == -1} { set para12 "" } if {$devID != -1} { # put adm indirect read driver command here iwrite "adm" $block $para1 $para2 $para3 $para4 $para5 $para6 $para7 $para8 $para9 $para10 $para11 $para12 } else { # Echo the admindwr command to TCL console puts "admindwr 0 $block $para1 $para2 $para3 $para4 $para5 $para6 $para7 $para8 $para9 $para10 $para11 $para12<br>"; } }#------------------------------------------------------------------------------ # SCRIPT NAME: # # DESCRIPTION: This procedure poll the BUSY bit on the specified indirect # address register. When the BUSY bit is high for 500 read # cycle, it will return a error message. When the BUSY bit is # low, it will exit immediately without an error message. # # PARAMETERS: devID - This parameter is used to specify the device # under configuration. If devID is -1, this function# is echo on the TCL console.## address - register address## bit_pos - BUSY Bit bit position # # NOTES: # #------------------------------------------------------------------------------ proc Poll_BUSY_Bit {devID address bit_pos} { if {$devID != -1} { # Poll BUSY until 0 or return error when BUSY bit stays high for 500 cycles for {set i 0} {$i < 500} {incr i} { set busy [admrdb $devID $address $bit_pos] if {$busy == 0} { break } } if {$busy == 1} { puts "Error: BUSY bit in $address stayed high for 500 read cycles" return } } else { # Echo the Poll_BUSY_Bit command to TCL console puts "Poll_BUSY [format "0x%04X" $address] $bit_pos <br>"; }} #------------------------------------------------------------------------------ # SCRIPT NAME: # # DESCRIPTION: This procedure poll the BUSY bit on the specified indirect # address register. When the BUSY bit is high for 500 read # cycle, it will return a error message. When the BUSY bit is # low, it will exit immediately without an error message. # # PARAMETERS: devID - This parameter is used to specify the device # under configuration. If devID is -1, this function# is echo on the TCL console.## address - register address## bit_pos - BUSY Bit bit position # # NOTES: # #------------------------------------------------------------------------------ proc Poll_BUSY_Bit_H {devID address bit_pos} { if {$devID != -1} { # Poll BUSY until 0 or return error when BUSY bit stays high for 500 cycles for {set i 0} {$i < 500} {incr i} { set busy [admrdb $devID $address $bit_pos] if {$busy == 1} { break } } if {$busy == 0} { puts "Error: BUSY bit in $address stayed low for 500 read cycles" return } } else { # Echo the Poll_BUSY_Bit command to TCL console puts "Poll_BUSY [format "0x%04X" $address] $bit_pos <br>"; }} #------------------------------------------------------------------------------ # SCRIPT NAME: Linear_APS_Source_Select # # DESCRIPTION: Select Line Interface #1 or Line Interface #2 # # PARAMETERS: devID - This parameter is used to specify the device # under configuration. If devID is -1, this function# is echo on the TCL console.## src - 0 (Line Interface #1 is selected),# 1 (Line Interface #2 is selected)# # NOTES: This procedure is used with the Linear 1+1 APS demo (ADM622_Config2)# #------------------------------------------------------------------------------ proc Linear_APS_Source_Select {devID src} { if {$src == 0} { # Traffic from line interface #1 is selected admwrb $devID 0x102A 14 0 } elseif {$src == 1} { # Traffic from line interface #1 is selected admwrb $devID 0x102A 14 1 }}#*******************************************************************************# MDIOClockSet#******************************************************************************proc MDIOClockSet { divider } { wr adm 0xEFC1 $divider;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -