Reputation: 77
I was working on the ESP-32 with FreeRTOS, What I was trying to achieve is , I want to pass the character entered by the user to a task.. And the following piece of code is what I have written and which is not working as expected,
#include <stdio.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
void task(void* pvParameters){
char* data;
data = (char *) pvParameters;
while (true)
{
printf("%s\n", data);
vTaskDelay(2000 / portTICK_PERIOD_MS);
}
}
void app_main(void){
char c = 0;
char * data = "Hello";
while (c != '\n')
{
c = getchar();
if(c != 0xff){
data = &c ;
printf(" The entered %c\n", c);
printf(" The data entered %c\n", *data);
}
vTaskDelay(100/portTICK_PERIOD_MS);
}
xTaskCreate(task, "task1", 4096, (void*) data, 1, NULL);
}
What is the mistake I am making here.
Upvotes: 0
Views: 724
Reputation: 3246
Is app_main() a task? If not you cannot call vTaskDelay() in it as the scheduler is not running there is nothing to delay.
Are you just trying to pass a stream of input characters to a task? If so then a stream buffer might be the most appropriate https://www.freertos.org/RTOS-stream-buffer-example.html
On the other hand, you might just be trying to pass one set of data to the task when the task is created?
Upvotes: 0
Reputation: 67820
For example usuing queues:
In the task you wait for the queue. In the user interface task you post the queue.
BTW your code is wrong in many other ways. Is full of UBs. I would advice to start from the C book, then learn how communication between task should be done and eventually to start with freeRTOS.
Upvotes: 1