Skip to content

Multithreading support with xTaskCreate #228

Closed
@marvindinneweth

Description

@marvindinneweth

I want my wifi connection to listen in a separate thread? How can i do this?

Activity

copercini

copercini commented on Feb 23, 2017

@copercini
Contributor
me-no-dev

me-no-dev commented on Feb 23, 2017

@me-no-dev
Member

what do you mean by "listen on another thread"?

marvindinneweth

marvindinneweth commented on Feb 24, 2017

@marvindinneweth
Author

I want to have a different thread where a little rest api is running and responds to get requests. This intirely separated from the main loop.

whatnick

whatnick commented on Mar 17, 2017

@whatnick
Contributor

You might be better served using the RTOS port for the ESP32 which has a clear concept of threads, rather than abstracted like Arduino. https://github.com/espressif/ESP31_RTOS_SDK

igrr

igrr commented on Mar 17, 2017

@igrr
Member

@whatnick what makes you think that this Arduino core is bare metal? It runs on top of FreeRTOS.

whatnick

whatnick commented on Mar 17, 2017

@whatnick
Contributor

I meant as threads explicitly exposed, rather than abstracted away in Arduino land.

me-no-dev

me-no-dev commented on Mar 17, 2017

@me-no-dev
Member

@whatnick nothing is abstracted ;) Arduino runs in one thread and you are free to spin another one or more if you need to. API is exactly the same... as @igrr said, Arduino on ESP32 runs on FreeRTOS

whatnick

whatnick commented on Mar 17, 2017

@whatnick
Contributor

What would be the concrete answer to the above ? A threaded webserver sample ?

me-no-dev

me-no-dev commented on Mar 17, 2017

@me-no-dev
Member

@whatnick so you want an example? I'm not quite sure what the issue is here?
Again, Arduino runs on top of RTOS and the specific RTOS is: https://github.com/espressif/esp-idf

whatnick

whatnick commented on Mar 18, 2017

@whatnick
Contributor
forthlightning

forthlightning commented on Mar 20, 2017

@forthlightning

Not sure about threading.h but freertos has tasks which probably satisfy what you want to do.

I'm on freertos.org all day, here is the task API call that esp-idf uses: http://www.freertos.org/a00125.html

A task has to be of the form

void do_thing_task( void* p ) // gotta have a void pointer as parameter even if unused
{
while( true ) // gotta have infinite loop
    {
        // do things
        vTaskDelay( 1000 / portTICK_PERIOD_MS ) // wait / yield time to other tasks
    }
}

Then you start it with

xTaskCreate( 
&do_thing_task,        // function
"do_thing_task",       // name
 2048,                 // stack
NULL,                  // void* to input parameter
 10,                   // priority 
NULL                   // task handle 
);

baldram

baldram commented on Jul 1, 2017

@baldram

This is a really interesting topic. To clarify my doubts I would like to ask by showing example.

Since arduino-esp32 is built on top of FreeRTOS, does it mean it is possible to call xTaskCreate directly from *.ino code? Is there a sufficient API for doing that?

It would look somehow like this example then:
https://github.com/feilipu/Arduino_FreeRTOS_Library/blob/master/examples/Blink_AnalogRead/Blink_AnalogRead.ino

Is it possible with arduino-esp32 ?

hakuren

hakuren commented on Jul 1, 2017

@hakuren
changed the title [-]Multithreading?[/-] [+]Multithreading support with xTaskCreate?[/+] on Aug 25, 2017

17 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Multithreading support with xTaskCreate · Issue #228 · espressif/arduino-esp32