lilzz
Posts: 411
Joined: Sat Nov 30, 2013 5:27 pm

what's this linux structure?

Tue Oct 28, 2014 4:43 pm

Code: Select all

  #define GPIO_CHIP(_bank) { \
    	.irq_base = IRQ_GPIO_BASE_ ## _bank, \
    	.gpio_chip = { \
    		.label = "Bank " # _bank, \
    		.owner = THIS_MODULE, \
    		.set = gpio_set_value, \
    		.get = gpio_get_value, \
    		.direction_output =gpio_direction_output, \
    		.direction_input = gpio_direction_input, \
    		.base = GPIO_BASE_ ## _bank, \
    		.ngpio =GPIO_NUM_ ## _bank, \
    	}, \
    }
What's this define with .label and .set and others?

Code: Select all

 static void gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value)
    {
    	uint32_t __iomem *reg = CHIP_TO_REG(chip, REG_GPIO_DATA_SET);
    	reg += !value;
    	writel(BIT(gpio), reg);
    }
This function with writel, __iomen, BIT() , where are they referenced from in Linux?

User avatar
PeterO
Posts: 5880
Joined: Sun Jul 22, 2012 4:14 pm

Re: what's this linux structure?

Tue Oct 28, 2014 4:46 pm

It would help if you said where you had found this code.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6229
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: what's this linux structure?

Tue Oct 28, 2014 4:48 pm

The question is a little vague, so I don't know which part you don't understand.

However, all of the important structures and functions are defined in the linux kernel source.
http://lxr.free-electrons.com/source/in ... v=3.12#L52

User avatar
joan
Posts: 14936
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: what's this linux structure?

Tue Oct 28, 2014 7:47 pm


Nolaan
Posts: 57
Joined: Thu Jul 10, 2014 6:35 pm
Contact: Website

Re: what's this linux structure?

Wed Oct 29, 2014 3:05 pm

It's just a macro to access GPIO chips consistently, think about it like an API. # is replaced by the argument in the call ie _bank .
## is used for concatenation of arguments. This combination of macro and structure is a clever way to define high level operations to manipulate you GPIO.
http://www.jetsonblog.com
twitter : @nolaan_boy

Return to “C/C++”