LOIC R

[SOM APF8 - iMX28] file system gpio event crach board

Discussion created by LOIC R on Oct 27, 2017
Latest reply on Jan 15, 2018 by Fabio Estevam

Hi,

 

When I configure sysfs gpio, for example :

 

cd /sys/class/gpio/

echo 45 > export

echo rising > edge // or falling or both

 

and use program after, my board crash.

 

When I configure the edge at "none", the poll is not blocking

 

Can you help me please?

 

Best Regards

Loïc

 

-----------------------------------------------------------------------------

 

#include <fcntl.h>
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

 

int main(int argc, char * argv[])
{
    int fd;
    struct pollfd  fds;
    char buffer[2];

 

    if (argc != 2) {
        fprintf(stderr, "usage: %s \n", argv[0]);
        exit(EXIT_FAILURE);
    }
    if ((fd = open(argv[1], O_RDONLY)) < 0) {
        perror(argv[1]);
        exit(EXIT_FAILURE);
    }
    while (1) {
        fds.fd = fd;
        fds.events = POLLPRI; // or POLLIN
        if (poll(& fds, 1, -1) < 0) {
            perror("poll");
            break;
        }
    printf("event\n");
        lseek(fd, 0, SEEK_SET);
        if (read(fd, & buffer, 2) != 2) {
            perror("read");
            break;
        }
        buffer[1] = '\0';
    }
    close(fd);
    return EXIT_SUCCESS;
}

Outcomes