Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using select() with stdin (IDFGH-2540) #4627

Closed
eduardsui opened this issue Jan 13, 2020 · 3 comments
Closed

Using select() with stdin (IDFGH-2540) #4627

eduardsui opened this issue Jan 13, 2020 · 3 comments

Comments

@eduardsui
Copy link

Hello,

I'm facing a issue when running select() with stdin file descriptor. abort() gets called in locks.c, here:

    if (!xPortCanYield()) {
        /* In ISR Context */
        if (mutex_type == queueQUEUE_TYPE_RECURSIVE_MUTEX) {
            abort(); /* recursive mutexes make no sense in ISR context */
        }

The offending code is:

void app_main() {
    while (1) {
        int s;
        fd_set rfds;
        struct timeval tv = {
            .tv_sec = 100,
            .tv_usec = 0,
        };

        FD_ZERO(&rfds);
        FD_SET(fileno(stdin), &rfds);

        s = select(2, &rfds, NULL, NULL, &tv);

        if (s < 0) {
            printf("Select failed: errno %d", errno);
        } else if (s == 0) {
            printf("Timeout has been reached and nothing has been received");
        }
    }
}
@github-actions github-actions bot changed the title Using select() with stdin Using select() with stdin (IDFGH-2540) Jan 13, 2020
@igrr
Copy link
Member

igrr commented Jan 13, 2020

Please make sure you are not calling select from an interrupt or a critical section.

@dobairoland
Copy link
Collaborator

The crash is caused by an assertion which tries to print (from a critical section) that the UART driver is not installed.

@eduardsui Please call uart_driver_install() and esp_vfs_dev_uart_use_driver() in the beginning.

Please take a look at driver initialization in the following examples:
https://github.com/espressif/esp-idf/tree/master/examples/peripherals/uart/uart_select
https://github.com/espressif/esp-idf/tree/master/examples/system/select

@eduardsui
Copy link
Author

Thank you, it works perfectly after UART driver is installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants