Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Global variable in Tcl

Tags:

tcl

I am trying to use a global variable (gpio_out_set_3) by declaring it outside a function (because the variable might be used in other functions too in future). Inside the function, I have declared the same variable as 'global' and trying to access it through '$gpio_out_set_3'.

I am getting an error "can't read "gpio_out_set_3": no such variable"

set gpio_out_set_3 0x03
proc port2phy { device } {
   global gpio_out_set_3 
   erf_wr devcpu_gcb $gpio_out_set_3 $phy_mdc_gate_en
  }

Please help.

like image 240
user3565150 Avatar asked Mar 04 '26 17:03

user3565150


1 Answers

Declare all of your global variable at the beginning of your main file using variable command.

variable gpio_out_set_3 0x03

TIP: I dont like the global command. I always forget to use, and hard to see which variable is global and which variable is local. I prefer the $::<varname>, which points to the global namespace.

proc port2phy { device } {
   erf_wr devcpu_gcb $::gpio_out_set_3 $phy_mdc_gate_en
}
like image 102
betontalpfa Avatar answered Mar 07 '26 10:03

betontalpfa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!