cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
wtneo@leica
Explorer
Explorer
1,169 Views
Registered: ‎09-25-2017

How to map true and false values in xparameters.h to integer

Jump to solution

Hi,

  I have created my own IP with GUI to let user turn on/off some features.

 

  In IP Packager, these settings are set as Boolean to let user tick or untick in block diagram.

 

 Because of this, these parameters are exported like below in xparameters.h:

 

    #define  XPAR_MYIP_0_IS_MONOCHROME   true

 

  

  Problem:  I need to map this to integer 1 or 0 but  not sure how.  Anyone can help?

 

regards,

 

Neo

0 Kudos
1 Solution

Accepted Solutions
stephenm
Moderator
Moderator
1,276 Views
Registered: ‎09-12-2007

The xparameter.h file is populated using the TCL files in the data folder for each driver. For example, taking the AXI GPIO as reference as it is simple:

2018.1\data\embeddedsw\XilinxProcessorIPLib\drivers\gpio_v4_3\data\gpio.tcl

 

There is a generate proc that will be run:

 

proc generate {drv_handle} {
::hsi::utils::define_include_file $drv_handle "xparameters.h" "XGpio" "NUM_INSTANCES" "C_BASEADDR" "C_HIGHADDR" "DEVICE_ID" "C_INTERRUPT_PRESENT" "C_IS_DUAL"
::hsi::utils::define_config_file $drv_handle "xgpio_g.c" "XGpio" "DEVICE_ID" "C_BASEADDR" "C_INTERRUPT_PRESENT" "C_IS_DUAL"
::hsi::utils::define_canonical_xpars $drv_handle "xparameters.h" "Gpio" "C_BASEADDR" "C_HIGHADDR" "DEVICE_ID" "C_INTERRUPT_PRESENT" "C_IS_DUAL"
}

 

So, this will add the params for Num_instances, base_address, ect.. Im assuming your driver looks similar. So, what you can do is, remove the parameter from the list here, and create a custom proc to add the info you want. for example:

 

proc add_params {drv_handle file_name} 

    set ip_name [string toupper $drv_handle]

    #note: I made a guess at the param name here.

    set param_name [get_property IS_MONOCHROME [get_cells  $drv_handle]]  

    if {$param_name != ""} {

        set file_handle [::hsi::utils::open_include_file $file_name]

        if {$param_name == "true"} {

              puts $file_handle "\#define XPAR_${ip_name}_IS_MONOCHROME 1"

        } else {

              puts $file_handle "\#define XPAR_${ip_name}_IS_MONOCHROME 0"

        }

        close $file_handle

    }

}

 

Then update the generate proc to call this new proc:

 

proc generate {drv_handle} {
::hsi::utils::define_include_file $drv_handle "xparameters.h" "XGpio" "NUM_INSTANCES" "C_BASEADDR" "C_HIGHADDR" "DEVICE_ID" "C_INTERRUPT_PRESENT" "C_IS_DUAL"
::hsi::utils::define_config_file $drv_handle "xgpio_g.c" "XGpio" "DEVICE_ID" "C_BASEADDR" "C_INTERRUPT_PRESENT" "C_IS_DUAL"
::hsi::utils::define_canonical_xpars $drv_handle "xparameters.h" "Gpio" "C_BASEADDR" "C_HIGHADDR" "DEVICE_ID" "C_INTERRUPT_PRESENT" "C_IS_DUAL"

add_params $drv_handle "xparameters.h" 
}

 

 

 

View solution in original post

0 Kudos
3 Replies
smcnutt
Contributor
Contributor
1,148 Views
Registered: ‎04-04-2018

Hi Neo,

 

stdbool.h has what you desire. For details see The Open Group Base Specification for example.

 

Regards,

--Scott

 

Edit: Fix link to Open Group stdbool.h page.

0 Kudos
stephenm
Moderator
Moderator
1,277 Views
Registered: ‎09-12-2007

The xparameter.h file is populated using the TCL files in the data folder for each driver. For example, taking the AXI GPIO as reference as it is simple:

2018.1\data\embeddedsw\XilinxProcessorIPLib\drivers\gpio_v4_3\data\gpio.tcl

 

There is a generate proc that will be run:

 

proc generate {drv_handle} {
::hsi::utils::define_include_file $drv_handle "xparameters.h" "XGpio" "NUM_INSTANCES" "C_BASEADDR" "C_HIGHADDR" "DEVICE_ID" "C_INTERRUPT_PRESENT" "C_IS_DUAL"
::hsi::utils::define_config_file $drv_handle "xgpio_g.c" "XGpio" "DEVICE_ID" "C_BASEADDR" "C_INTERRUPT_PRESENT" "C_IS_DUAL"
::hsi::utils::define_canonical_xpars $drv_handle "xparameters.h" "Gpio" "C_BASEADDR" "C_HIGHADDR" "DEVICE_ID" "C_INTERRUPT_PRESENT" "C_IS_DUAL"
}

 

So, this will add the params for Num_instances, base_address, ect.. Im assuming your driver looks similar. So, what you can do is, remove the parameter from the list here, and create a custom proc to add the info you want. for example:

 

proc add_params {drv_handle file_name} 

    set ip_name [string toupper $drv_handle]

    #note: I made a guess at the param name here.

    set param_name [get_property IS_MONOCHROME [get_cells  $drv_handle]]  

    if {$param_name != ""} {

        set file_handle [::hsi::utils::open_include_file $file_name]

        if {$param_name == "true"} {

              puts $file_handle "\#define XPAR_${ip_name}_IS_MONOCHROME 1"

        } else {

              puts $file_handle "\#define XPAR_${ip_name}_IS_MONOCHROME 0"

        }

        close $file_handle

    }

}

 

Then update the generate proc to call this new proc:

 

proc generate {drv_handle} {
::hsi::utils::define_include_file $drv_handle "xparameters.h" "XGpio" "NUM_INSTANCES" "C_BASEADDR" "C_HIGHADDR" "DEVICE_ID" "C_INTERRUPT_PRESENT" "C_IS_DUAL"
::hsi::utils::define_config_file $drv_handle "xgpio_g.c" "XGpio" "DEVICE_ID" "C_BASEADDR" "C_INTERRUPT_PRESENT" "C_IS_DUAL"
::hsi::utils::define_canonical_xpars $drv_handle "xparameters.h" "Gpio" "C_BASEADDR" "C_HIGHADDR" "DEVICE_ID" "C_INTERRUPT_PRESENT" "C_IS_DUAL"

add_params $drv_handle "xparameters.h" 
}

 

 

 

View solution in original post

0 Kudos
wtneo@leica
Explorer
Explorer
1,057 Views
Registered: ‎09-25-2017

Tks all,

 

  I did not want to add boolean type to my driver for one time use only, so I did not use stdbool.h

 

  I found this solution elsewhere, so I added this to the driver file :

 

#define true 1

#define false 0

 

  So it works for me now.

 

Regards,

 

Neo

 

  

0 Kudos