Error while trying to create task from other tasks

anudocs
Posts: 6
Joined: Fri Dec 25, 2020 8:18 am

Error while trying to create task from other tasks

Postby anudocs » Mon Jan 04, 2021 10:59 am

I am trying to create one task pub_sub inside a task aws_connect but I am getting error.
Below is the outline of my code :

Code: Select all

 
 //Global variables
 struct Params 
   {
   IoT_Error_t  result;
   AWS_IoT_Client  awsClient;
   }taskParam;

Code: Select all

//Inside aws_connect_task with priority 5

 ESP_LOGI(TAG, "AWS connected");
taskParam.result = rc;
taskParam.awsClient = client;
    ESP_LOGI(TAG, "Starting pub sub");
    if (xTaskCreate(&pub_sub_task, "pub_sub_task", 9216, NULL, 4, NULL) != pdPASS) {
        ESP_LOGE(TAG, "Couldn't create cloud task\n");
    }
  vTaskDelete(NULL);    

Code: Select all

//inside pub_sub_task

    struct Params* taskParams = params;
    IoT_Error_t rc = taskParams->result;
    AWS_IoT_Client client = taskParams->awsClient;
    
    //setting pub sub variables
    while(rc ==SUCESSS)
    {
    //publishing to aws iot core
    }
    vTaskDelete(NULL); 
  
But i get below error when xTaskCreate(&pub_sub_task, "pub_sub_task", 9216, NULL, 4, NULL) is called :

Code: Select all

I (5459) AWS Connect: Starting pub sub
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x4000c2e0  PS      : 0x00060030  A0      : 0x800d8729  A1      : 0x3ffd5a80  
A2      : 0x3ffd5aa0  A3      : 0x00000008  A4      : 0x00000c00  A5      : 0x3ffd5aa0  
A6      : 0x00000001  A7      : 0x000000c0  A8      : 0x00000000  A9      : 0x00060423  
A10     : 0x00000001  A11     : 0x00000001  A12     : 0x00000000  A13     : 0x3ffb4294  
A14     : 0x00000003  A15     : 0x00060023  SAR     : 0x00000000  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000008  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0x000000bf  

Backtrace:0x4000c2dd:0x3ffd5a80 0x400d8726:0x3ffd5a90 0x4008adc9:0x3ffd68e0
0x400d8726: pub_sub_task at /home/anubhav/esp/projects/AWS_IoT_Thing_Shadow/build/../main/aws_connect.c:56

0x4008adc9: vPortTaskWrapper at /home/anubhav/esp/esp-idf/components/freertos/port/xtensa/port.c:168
can someone please help with this error? What am i doing wrong here?

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

Re: Error while trying to create task from other tasks

Postby ESP_Sprite » Tue Jan 05, 2021 1:34 am

Code: Select all

 struct Params* taskParams = params;
Where does 'params' come from?

Also, don't pass params in a global struct like that. Better to use the arg value in the xTaskCreate call to pass stuff like that.

anudocs
Posts: 6
Joined: Fri Dec 25, 2020 8:18 am

Re: Error while trying to create task from other tasks

Postby anudocs » Tue Jan 05, 2021 9:14 am

it is coming from the task parameters

Code: Select all

void pub_sub_task(void *params)

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

Re: Error while trying to create task from other tasks

Postby ESP_Sprite » Wed Jan 06, 2021 1:29 am

Okay, in that case your code works exactly as expected. (Hint: where do you think that params information comes from?)

Who is online

Users browsing this forum: No registered users and 224 guests