xTaskCreatePinnedToCore - task priority

doglike
Posts: 63
Joined: Fri Aug 18, 2017 4:21 pm

xTaskCreatePinnedToCore - task priority

Postby doglike » Mon May 20, 2019 11:45 am

Hi,

I have a question about the task priorities, which I didn't clearly understand.
In this example: I have 2 tasks on the same core1. TASK_1 has prio 1. TASK_2 has prio 2.

Code: Select all

xTaskCreatePinnedToCore (TASK_1,	"TASK_1",	4096, (void *)1, 1, NULL, CORE1);
xTaskCreatePinnedToCore (TASK_2,	"TASK_2",	4096, (void *)1, 2, NULL, CORE1);
What is the priority of those task exactly doing / what is happening here ?
Thanks a lot!


doglike
Posts: 63
Joined: Fri Aug 18, 2017 4:21 pm

Re: xTaskCreatePinnedToCore - task priority

Postby doglike » Mon May 20, 2019 1:27 pm

Thanks WiFive!

So if I understand this right, then a higher prio task can interrupt a lower prio task ?

Which one is the higher prio - the smaller number or the greater ?

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: xTaskCreatePinnedToCore - task priority

Postby WiFive » Mon May 20, 2019 6:39 pm

Greater

Ritesh
Posts: 1383
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: xTaskCreatePinnedToCore - task priority

Postby Ritesh » Mon May 20, 2019 6:49 pm

doglike wrote:
Mon May 20, 2019 1:27 pm
Thanks WiFive!

So if I understand this right, then a higher prio task can interrupt a lower prio task ?

Which one is the higher prio - the smaller number or the greater ?
Here, Higher number means high priority. Also you can get more information regarding freeRTOS from below link

https://www.freertos.org

Let me know if need any further help for that
Regards,
Ritesh Prajapati

doglike
Posts: 63
Joined: Fri Aug 18, 2017 4:21 pm

Re: xTaskCreatePinnedToCore - task priority

Postby doglike » Mon May 20, 2019 7:23 pm

Thank you guys for the awesome support ! :)

Ritesh
Posts: 1383
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: xTaskCreatePinnedToCore - task priority

Postby Ritesh » Tue May 21, 2019 3:27 am

doglike wrote:
Mon May 20, 2019 7:23 pm
Thank you guys for the awesome support ! :)
Most Welcome. Let me know if you need any further support regarding that.
Regards,
Ritesh Prajapati

User avatar
fasani
Posts: 197
Joined: Wed Jan 30, 2019 12:00 pm
Location: Barcelona
Contact:

Re: xTaskCreatePinnedToCore - task priority

Postby fasani » Tue May 21, 2019 8:54 am

I have a question regarding xTaskCreatePinnedToCore. It's possible to pass an array of bytes :

Code: Select all

        // Save compressed in memory instead of simply: uint8_t compressed[compressedBytes.size()];
        receivedLength = packet.length();

        compressed  = (uint8_t*)malloc(receivedLength); // I would like to pass this instead of assigning it globally
        
        for ( int i = 0; i < packet.length(); i++ ) {
            uint8_t conv = (int) packet.data()[i];
            compressed[i] = conv;
            // Bytes read here are OK
            Serial.print(conv);Serial.print(",");
        }

          xTaskCreatePinnedToCore(
                    brTask,        /* Task function. */
                    "uncompress",  /* name of task. */
                    20000,         /* Stack size of task */
                    (void*)&compressed,   /* send the bytes as a parameter */
                    9,             /* priority of the task */
                    &brotliTask,   /* Task handle to keep track of created task */
                    0);            /* pin task to core 1 */


// And then I would like read this array in the task
// Task sent to the core to decompress + push to Output
void brTask(void * parameter){  
    uint8_t * brOutBuffer = (uint8_t*)malloc(BROTLI_DECOMPRESSION_BUFFER);
    Serial.print("Free heap: "+String(ESP.getFreeHeap()));
     Serial.print("Brotli IN compressed bytes:"); Serial.print(receivedLength);
    size_t bufferLength = BROTLI_DECOMPRESSION_BUFFER;

// Note, tried to loop here over this but I don't get the same bytes
Serial.println(*((uint8_t*)parameter));

    brotli = BrotliDecoderDecompress(
      receivedLength,
      (const uint8_t *)compressed,
      &bufferLength,
      brOutBuffer);
      free(compressed);
      printMessage("Unbrotli result: "+String(brotli)); // Should return 1 on correct decompression
      printMessage("bufferLength OUT:");printMessage(String(bufferLength));
      if (brotli == 0) {
        printMessage("Decompresion failed");
      }
      printMessage("Uncompressing:");
      Serial.printf("%.*s\n", bufferLength, brOutBuffer); 
}

According to an Article read in techtutorialsx.com I could pass a parameter. But is possible to pass an array ?
I tried reading this bytes array in the other end and it's different. I'm pointing it to a wrong pointer in memory ?

And also I wanted to ask, would it be safer to do this, than to declare the compiler array at a global label ?

(NOTE: Codebox button in this BBforum needs a fix, it outputs codebox instead of code that is the right BBCODE)
Thanks in advance for your answers
epdiy collaborator | http://fasani.de Fan of Espressif MCUs and electronic design

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: xTaskCreatePinnedToCore - task priority

Postby ESP_Sprite » Wed May 22, 2019 3:30 am

You can pass a pointer. If you cast your array to (void*), you can cast it back to a pointer in the task itself, and then use that as an array.

Who is online

Users browsing this forum: Baldhead and 126 guests