c understanding struct pointer -


could explain line static volatile gpio_registers* const gpio[] in code below?

and syntax (volatile gpio_registers*) inside block do?

// gpio hardware registers // typedef struct {   uint32_t mode;   uint32_t type;   uint32_t speed;   uint32_t push_pull;   uint32_t idr;   uint32_t odr;   uint32_t bsrr;   uint32_t lock;   uint32_t alt_fn1;   uint32_t alt_fn2; } gpio_registers;   // ports can selected using enumeration // (port) index array. // port addresses can calculated using enum since // ports @ same offset each other. // static volatile gpio_registers* const gpio[] = {   (volatile gpio_registers*)(gpio_base_addr + (port_a << 10)),   (volatile gpio_registers*)(gpio_base_addr + (port_b << 10)),   (volatile gpio_registers*)(gpio_base_addr + (port_c << 10)),   (volatile gpio_registers*)(gpio_base_addr + (port_d << 10)),   (volatile gpio_registers*)(gpio_base_addr + (port_e << 10)),   (volatile gpio_registers*)(gpio_base_addr + (port_f << 10)) }; 

static volatile gpio_registers* const gpio[] static array of pointer gpio_registers variables.

each element of array point physical address of soc/mcu. each element points physical gpio port. take of soc/mcu datasheet details. you'll find out each gpio port of soc has 32bits registers specified gpio_registers struct.

(volatile gpio_registers*) simple type cast required due fact gpio_base_addr , other defines simple "numbers" , must specify type of "numbers".


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -