Correct way to pass struct as an xTaskCreate parameter?
Posted: Tue May 16, 2017 10:00 pm
Hi all,
Perhaps a bit off-topic and perhaps a beginners error, but this one is biting me with all erratic behaviour on the ESP32. So please lend me your ears.
Within an app.h I hold the definitions for structs I use for different tasks. In this example I have a PixelTask which drives a Neopixel depending on bits on an app event group. I use the pvParameter to feed it the proper GPIO when I xTaskCreate it from main like so:
app.h:
config.h:
main.c:
pixel_task.cpp:
The last LOGI will just give me some random piece of 4 bytes of memory it seems, which gives me just an insane number. Same with a wifi_sta task I've created for dealing with the client init and event handling. This is a C task, and the struct looks like
When creating it from main, even with a bigger stacksize, but along the same principle, the task gives me not a random values, but just the wrong values. I end up with the TAG from main for example.
So how does one pass parameters the proper way? I'm missing something here..
thanks for your time,
Martijn
Perhaps a bit off-topic and perhaps a beginners error, but this one is biting me with all erratic behaviour on the ESP32. So please lend me your ears.
Within an app.h I hold the definitions for structs I use for different tasks. In this example I have a PixelTask which drives a Neopixel depending on bits on an app event group. I use the pvParameter to feed it the proper GPIO when I xTaskCreate it from main like so:
app.h:
Code: Select all
/** Structure to initialize Pixel task */
typedef struct {
gpio_num_t dio_pin;
} pixel_config_t;
Code: Select all
#define PIXEL_PIN_DIN GPIO_NUM_19
Code: Select all
pixel_config_t config;
config.dio_pin = PIXEL_PIN_DIN;
xTaskCreate(&pixel_task, "pixel_task", 2048, &config, 5, NULL);
Code: Select all
void pixel_task(void *data) {
pixel_config_t pixel_config = *(pixel_config_t *) data;
ESP_LOGI(TAG, "starting task");
ESP_LOGI(TAG, "pixel_config.dio_pin %i", pixel_config.dio_pin);
Code: Select all
/** Structure to initialize WiFi STA task */
typedef struct {
const char *ssid;
const char *password;
const char *client_hostname;
} local_wifi_sta_config_t;
So how does one pass parameters the proper way? I'm missing something here..
thanks for your time,
Martijn