We have upgraded the community system as part of the upgrade a password reset is required for all users before login in.

Atomic GPIO-register access?



  • Hey, kids! I am expecting to receive my very first Omega soon, namely the Omega2+, and I figured that it wouldn't hurt if I tried to learn some more details about it while waiting. One thing that pops to my mind is: are the GPIO-register accesses used by e.g. fast-gpio atomic operations? Like, say, if you have two processes trying to access the same register simultaneously, both trying to operate on different pins -- without atomic operations fast-gpio has to read the register, modify it, then write it back, but if the first process gets interrupted before it manages to write its changes back to the register and the other process reads the register's contents during this time, one or the other process would have its changes overwritten by the other.

    On my STM32 ARM Cortex-m0 MCUs there is bit-banding memory-map functionality exactly for this kind of stuff, Raspberry's Broadcom SoC has specific instructions for this, but I have no experience with MIPS-architecture and I have no idea if they offer anything similar.



  • From the new docs:
    https://docs.onion.io/omega2-docs/using-gpios.html

    The fast-gpio command is similar to gpioctl in that it is used to control the Omega’s GPIOs. The difference is that while gpioctl worked by setting file values inside the /sys/class/gpio directory, fast-gpio works by setting GPIO registers and is inherently a faster process.

    I haven't seen the source code for gpioctl, but I would expect it to be atomic. And about fast-gpio, I would definitely not expect that to be atomic.



  • @fossette gpioctl doesn't access the registers directly, so it's not relevant to my question. Also, of course it is atomic, since all sysfs gpio-accesses go through the kernel's pinctrl. I specifically want to know if the SoC used by Omega2+ offers one or another kind of atomic access to the said registers and whether fast-gpio uses such a mechanism or not.



  • @WereCatf said in Atomic GPIO-register access?:

    gpioctl doesn't access the registers directly

    It does ... eventually!



  • @fossette The sysfs gpio-interface provides no way of accessing the registers, all accesses go through the kernel, like I said. Unless they've modified gpioctl to work differently on Omega-boards it does not use anything other than the sysfs-interface.



  • @WereCatf You might like to look at the code I have published in https://github.com/KitBishop/Omega-GPIO-I2C-Arduino

    In particular, you will see that the methods GPIOAccess::rawSet and GPIOAccess::rawGet in https://github.com/KitBishop/Omega-GPIO-I2C-Arduino/blob/master/libnewgpio/src/GPIOAccess.cpp set and get the GPIO pin values via atomic operations on the memory mapped registers used for GPIO



  • @Kit-Bishop The GPIOAccess:rawGet-method answers my question perfectly, it's exactly what I was hoping to find out! Thank you very much! 😃



  • That's VERY interesting, Kit! Thanks! Your library makes a clever use of the GPIO_DSET and GPIO_DCLR registers of the SoC chipset, which by itself makes the write operation atomic.

    So, to answer the OP, the Omega2 does have the bit-banding memory-map feature for GPIOs. If the fast-gpio functions are well designed, there's no reason why they shouldn't be atomic (but again, I have not seen those specific source code yet to confirm or refute their atomicity).



Looks like your connection to Community was lost, please wait while we try to reconnect.