Hi Rac,
Thanks for the confirmation.
am I correct in reading that your problem is solved now?
In short, No, but since Friday I have got it working. Had a number of issues, I think the main one was that the getTaskName function was being called in the initial part of the vPeriodicTask() and not within the for( ; ; ) loop. I havenât yet fully understood when the initial part is executed. Is it correct to assume that this part is executed only once as the task is created, and then it stays within the for( ; ; ) loop?
Other issues were not enough stack allocation in the vCreateTask functions. I would have thought 1000 bytes would be plenty. I donât like using printf within the periodic task so I sent the task name via a queue to a print task name function, but if I enable the vQueueSend() function it seems to completely upset things again and clobber one of the periodic tasks. Code now is as follows :
#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "driver/uart.h"
#include "driver/gpio.h"
#include "esp_log.h"
//#include "esp_hw_support/include/rtc_wdt.h"
#include "sio_esp32.h"
//#include "semphr.h"
static const char *TAG = "gt32";
static void vPeriodicTask(void *pvParameters);
static void vPrintTaskName(void *pvParameters);
extern void init_uart1(void);
extern void init_uart2(void);
TickType_t period1, period2;
QueueHandle_t Q_periodic = NULL;
static int i = 0;
void app_main(void) {
esp_log_level_set(TAG, ESP_LOG_INFO);
// rtc_wdt_protect_off();
// rtc_wdt_disable();
period1 = pdMS_TO_TICKS(5000UL); // 5 seconds
period2 = pdMS_TO_TICKS(3000UL); // 3 seconds
// init_uart1();
// init_uart2();
// Create the task that will run periodically
if (xTaskCreate(vPeriodicTask, "Periodic2", 2000, (void*) period2, 1, NULL) != pdPASS) {
printf("Periodic2 not created successfully");
}
else{
printf("Periodic2 task created successfully\r\n");
}
if (xTaskCreate(vPeriodicTask, "Periodic1", 2000, (void*) period1, 1, NULL) != pdPASS) {
printf("Periodic1 not created successfully");
}
else{
printf("Periodic1 task created successfully\r\n");
}
if (xTaskCreate(vPrintTaskName, "PrintTaskName", 1000, NULL, 1,
NULL) != pdPASS) {
printf("PritTaskName not created successfully\r\n");
}
else{
printf("PritTaskName task created successfully\r\n");
}
// Start the scheduler so the created tasks start executing.
// Scheduler seems to be already started by the rtos system, no need to do it again.
// vTaskStartScheduler();
while (true) {
rtc_wdt_feed();
i++;
printf("Hello from gt32 app_main! %u\n", i);
vTaskDelay(pdMS_TO_TICKS(1000UL)); // This delay seems to be pretty accurate
}
}
/*-----------------------------------------------------------*/
// 1mS granularity, called every second if xDelayms = 1000
static void vPeriodicTask(void *pvParameters) {
const TickType_t xDelayms = (TickType_t) (pvParameters);//pdMS_TO_TICKS( 5000UL ); // 5 seconds
char Task_Name[20];
Q_periodic = xQueueCreate(5, sizeof(Task_Name));
if(Q_periodic == NULL){
printf("Failed to create Q_periodic\r\n");
}
//getTaskName(Task_Name);
//xQueueSend(Q_periodic, (void *)Task_Name, (TickType_t)0);
/* As per most tasks, this task is implemented within an infinite loop. */
for (;;) {
// strcpy(Task_Name, pcTaskGetName(NULL));
getTaskName(Task_Name);
// xQueueSend(Q_periodic, (void *)Task_Name, (TickType_t)0);
printf("Periodic task %s.\r\n", Task_Name);
vTaskDelay(xDelayms);
}
}
Thanks to all for the replies. Any suggestions as to why the vQueueSend() seems to stop the task running would be much appreciated.
Regards
Bill