mirror of
https://github.com/alexandrebobkov/ESP-Nodes.git
synced 2025-08-08 03:42:24 +00:00
FreeRTOS
This commit is contained in:
@@ -73,8 +73,6 @@ void app_main(void)
|
|||||||
|
|
||||||
printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size());
|
printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
xMutex = xSemaphoreCreateMutex();
|
xMutex = xSemaphoreCreateMutex();
|
||||||
if (xMutex == NULL) {
|
if (xMutex == NULL) {
|
||||||
printf("Failed to create mutex\n");
|
printf("Failed to create mutex\n");
|
||||||
@@ -92,29 +90,19 @@ void app_main(void)
|
|||||||
xTaskCreate(task2, "Task2", 2048, NULL, 15, NULL);
|
xTaskCreate(task2, "Task2", 2048, NULL, 15, NULL);
|
||||||
xTaskCreate(display_task, "DisplayTask", 2048, NULL, 5, NULL);
|
xTaskCreate(display_task, "DisplayTask", 2048, NULL, 5, NULL);
|
||||||
xTaskCreate(restart_task, "TaskRestart", 2048, NULL, 20, NULL);
|
xTaskCreate(restart_task, "TaskRestart", 2048, NULL, 20, NULL);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void task1(void *pvParameters) {
|
void task1(void *pvParameters) {
|
||||||
uint32_t x = 0;
|
uint32_t x = 0;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (xSemaphoreTake(xMutex, 1500)) {
|
if (xSemaphoreTake(xMutex, 1500)) {
|
||||||
printf("Task 1 is running\n");
|
printf("Task 1 is running\n");
|
||||||
|
|
||||||
/*SensorsData data = {
|
|
||||||
.num1 = x,
|
|
||||||
.num2 = 0,
|
|
||||||
.num3 = 0,
|
|
||||||
};*/
|
|
||||||
s_data.num1 = x;
|
s_data.num1 = x;
|
||||||
//xQueueSend(xQueue1, &data, 0);
|
|
||||||
xQueueSend(xQueue1, &s_data, 0);
|
xQueueSend(xQueue1, &s_data, 0);
|
||||||
printf("Task 1 sent x=%" PRIu32 "\n", x);
|
printf("Task 1 sent x=%" PRIu32 "\n", x);
|
||||||
x+=2;
|
x+=2;
|
||||||
|
vTaskDelay((500));
|
||||||
vTaskDelay((500)); // Delay for 1 second
|
|
||||||
xSemaphoreGive(xMutex);
|
xSemaphoreGive(xMutex);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -130,19 +118,11 @@ void task2(void *pvParameters) {
|
|||||||
while (1) {
|
while (1) {
|
||||||
if (xSemaphoreTake(xMutex, 1500)) {
|
if (xSemaphoreTake(xMutex, 1500)) {
|
||||||
printf("Task 2 is running\n");
|
printf("Task 2 is running\n");
|
||||||
|
|
||||||
/*SensorsData data = {
|
|
||||||
.num1 = 0,
|
|
||||||
.num2 = y,
|
|
||||||
.num3 = 0,
|
|
||||||
};*/
|
|
||||||
s_data.num2 = y;
|
s_data.num2 = y;
|
||||||
//xQueueSend(xQueue2, &data, 0);
|
|
||||||
xQueueSend(xQueue2, &s_data, 0);
|
xQueueSend(xQueue2, &s_data, 0);
|
||||||
printf("Task 2 sent y=%" PRIu32 "\n", y);
|
printf("Task 2 sent y=%" PRIu32 "\n", y);
|
||||||
y++;
|
y++;
|
||||||
|
vTaskDelay((250));
|
||||||
vTaskDelay((250)); // Delay for 2 seconds
|
|
||||||
xSemaphoreGive(xMutex);
|
xSemaphoreGive(xMutex);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -172,5 +152,3 @@ void display_task(void *pvParameters) {
|
|||||||
vTaskDelay(50);
|
vTaskDelay(50);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user