Skip to content

[BUG] gpio_poll() hangs master #448

@ag88889

Description

@ag88889

Description of problem: gpio_poll() hangs master

Using gpio_poll() as that

void erpc::spiWaitForSlaveReadyGpio(int gpioHandle)
{
    for (;;)
    {
         if (gpio_poll(gpioHandle, -1))
         {
             break;
         }
    }
}

hangs master.

To Reproduce

I got that behaviour when
erpc_c/transports/erpc_spidev_master_transport.cpp
was tested with gpio synchronization turned on.

Expected behavior

No hangs.

Screenshots

Desktop (please complete the following information)

  • OS Linux orangepizero3 6.1.31-sun50iw9 1.0.4 SMP Thu Jul 11 16:37:41 CST 2024 aarch64 GNU/Linux
  • eRPC Version 1.13.0

Steps you didn't forgot to do

  • I checked if there is no related issue opened/closed.
  • I checked that there doesn't exist opened PR which is solving this issue.

Additional context

That's modification works fine:

int gpio_poll(int fd, int timeout)  // 0/1 - new pin state, -2 - error, -1 - timeout
{
    int pollr;
    struct pollfd fds;
    int ret;
    char val;

    fds.fd = fd;
    fds.events = POLLIN | POLLPRI | POLLERR;
    ;
    pollr = poll(&fds, 1, timeout);

    if (pollr < 0)
    {
        (void)fprintf(stderr, "Could not poll gpio (%d).\r\n", errno);
        ret = -2;
    }
    else
    {
        if ((fds.revents & (POLLPRI | POLLIN) ) > 0)
        {
            lseek(fds.fd, 0, SEEK_SET);
            read(fds.fd, &val, 1);
            ret = val-'0';
        }
        else if ((fds.revents & POLLERR) > 0)
        {
            (void)fprintf(stderr, "Error while polling gpio (%d).\r\n", errno);
            ret = -2;
        }
        else
        {
            ret = -1;
        }
    }

    return ret;
}

/***********************/

void erpc::spiWaitForSlaveReadyGpio(int gpioHandle)
{
    for (;;)
    {
         if (gpio_poll(gpioHandle, -1) == 0)
         {
             break;
         }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions