foss-for-synopsys-dwc-arc-processors / embarc_osp

embARC Open Software Platform (OSP) - An embedded software distribution for IoT and other embedded applications for ARC
https://www.embarc.org/
BSD 3-Clause "New" or "Revised" License
70 stars 62 forks source link

Read PIN input value without using gpio_read() in Iotdk #111

Closed ericwu13 closed 5 years ago

ericwu13 commented 5 years ago

Issue Summary

I want to have a faster pin access time in IOTDK. Thanks.

uint8_t input_value = PIND&4 // get the input value of pin number 2 at port D
IRISZZW commented 5 years ago

when you use the gpio_read function, you will finally call _lr( (unsigned)(dev->reg_base + EXT_PORTA) );//(gpio.c) for example,PIN GPIO_8B0_3: dev->reg_base = AR_IO_GPIO_8B0_SWPORTA_DR = 0x80017800;//(dfss_gpio_obj.c) #define EXT_PORTA (0x50) /* GPIO External Port A Register *///(gpio.c)

so, you can do it:

uint8_t input_value = _lr(0x80017850) & (1 << 3); //pin num 3 at gpio_8b0

before read, make sure you have done the initial for pin.

ericwu13 commented 5 years ago

Thanks. The speed is significantly increased. But instead of using _lr, which will cause linking error (I think I just didn't include needed header files for it), we can use the below without doing any modification to include statements:

uint8_t value = _arc_aux_read(0x80017850) & (1 << 3) // read pin num 3 at gpio_8b0