Page 1 of 1

xTaskCreatePinnedToCore - task priority

Posted: Mon May 20, 2019 11:45 am
by doglike
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!

Re: xTaskCreatePinnedToCore - task priority

Posted: Mon May 20, 2019 1:01 pm
by WiFive

Re: xTaskCreatePinnedToCore - task priority

Posted: Mon May 20, 2019 1:27 pm
by doglike
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 ?

Re: xTaskCreatePinnedToCore - task priority

Posted: Mon May 20, 2019 6:39 pm
by WiFive
Greater

Re: xTaskCreatePinnedToCore - task priority

Posted: Mon May 20, 2019 6:49 pm
by Ritesh
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

Re: xTaskCreatePinnedToCore - task priority

Posted: Mon May 20, 2019 7:23 pm
by doglike
Thank you guys for the awesome support ! :)

Re: xTaskCreatePinnedToCore - task priority

Posted: Tue May 21, 2019 3:27 am
by Ritesh
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.

Re: xTaskCreatePinnedToCore - task priority

Posted: Tue May 21, 2019 8:54 am
by fasani
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

Re: xTaskCreatePinnedToCore - task priority

Posted: Wed May 22, 2019 3:30 am
by ESP_Sprite
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.