Writing to GPIO_OUT_REG to only specific pins

Deouss
Posts: 425
Joined: Tue Mar 20, 2018 11:36 am

Writing to GPIO_OUT_REG to only specific pins

Postby Deouss » Thu May 23, 2019 4:23 pm

Let's say I want to set 12 bits/pins simultaneously with specific values 0/1 to gpio output register but I do not want to change other bits - must be done with one 32bit word write and possibly one write instruction.
Do I have to disable/enable bits with mask first? I don't want to change settings of other pins.
Should it be done with combination of W1TC/W1TS ?
I am looking for fastest possible way - best with asm instructions if possible. Single REG_WRITE is ok too.
Thanks for any suggestions

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: Writing to GPIO_OUT_REG to only specific pins

Postby ESP_Sprite » Fri May 24, 2019 3:40 am

There's no way to mask bits; the way to go would be to either use a read/modify/write on the GPIO value register (but watch out with multitasking there) or use a W1TC/W1TS combo. From an architectural point of view, I'd think W1TS/W1TC would be faster (no reads involved, writes can be queued) but it does have the slight disadvantage that you have an intermediate value on your GPIOs at some point.

Deouss
Posts: 425
Joined: Tue Mar 20, 2018 11:36 am

Re: Writing to GPIO_OUT_REG to only specific pins

Postby Deouss » Fri May 24, 2019 2:10 pm

So operations steps would be:

val => W1TS
val ~= val
val => W1TC

How that would look in asm ?

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: Writing to GPIO_OUT_REG to only specific pins

Postby ESP_Sprite » Sat May 25, 2019 11:50 am

Deouss wrote:
Fri May 24, 2019 2:10 pm
So operations steps would be:

val => W1TS
val ~= val
val => W1TC

How that would look in asm ?
You probably want to mask the bits you don't want to touch.

W1TS <= val & mask
W1TC <= (~val) & mask

I'll leave the assembly to someone else, but chances are it's not going to be that much faster than C. (Maybe a bit because C declares these as volatile; you could work around that though.)

Deouss
Posts: 425
Joined: Tue Mar 20, 2018 11:36 am

Re: Writing to GPIO_OUT_REG to only specific pins

Postby Deouss » Sat May 25, 2019 4:19 pm

Thanks. Well I use whole word only with needed bits so masking is not necessary.
Actually XOR operation might not be needed and data will be precalculated ready to write)
I want to use assembler instructions to repeat inline few times for speeding execution.

Who is online

Users browsing this forum: Bing [Bot] and 91 guests