2021-02-04 12:42:43 +01:00
|
|
|
#include "taskutils.h"
|
|
|
|
|
|
2021-08-09 16:38:13 +02:00
|
|
|
#include "sdkconfig.h"
|
|
|
|
|
#define LOG_LOCAL_LEVEL CONFIG_ESPCPPUTILS_LOG_LOCAL_LEVEL
|
|
|
|
|
|
2022-06-22 14:54:30 +02:00
|
|
|
// system includes
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
2021-08-09 16:38:13 +02:00
|
|
|
// esp-idf includes
|
|
|
|
|
#include <esp_log.h>
|
|
|
|
|
|
2021-02-04 12:42:43 +01:00
|
|
|
namespace espcpputils {
|
2021-08-09 16:38:13 +02:00
|
|
|
namespace {
|
|
|
|
|
constexpr const char * const TAG = "ESPCPPUTILS";
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2021-02-09 18:16:31 +01:00
|
|
|
BaseType_t createTask(TaskFunction_t pvTaskCode,
|
|
|
|
|
const char * const pcName,
|
|
|
|
|
const uint32_t usStackDepth,
|
|
|
|
|
void * const pvParameters,
|
|
|
|
|
UBaseType_t uxPriority,
|
|
|
|
|
TaskHandle_t * const pvCreatedTask,
|
|
|
|
|
CoreAffinity coreAffinity)
|
|
|
|
|
{
|
|
|
|
|
switch (coreAffinity)
|
|
|
|
|
{
|
|
|
|
|
case CoreAffinity::Core0:
|
|
|
|
|
case CoreAffinity::Core1:
|
2021-08-09 16:38:13 +02:00
|
|
|
{
|
|
|
|
|
const auto result = xTaskCreatePinnedToCore(pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pvCreatedTask, int(coreAffinity));
|
|
|
|
|
if (result != pdPASS)
|
|
|
|
|
ESP_LOGW(TAG, "xTaskCreatePinnedToCore() %s failed with %i", pcName, result);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2021-02-09 18:16:31 +01:00
|
|
|
case CoreAffinity::Both:
|
2021-08-09 16:38:13 +02:00
|
|
|
{
|
|
|
|
|
const auto result = xTaskCreate(pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pvCreatedTask);
|
|
|
|
|
if (result != pdPASS)
|
|
|
|
|
ESP_LOGW(TAG, "xTaskCreate() %s failed with %i", pcName, result);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2021-02-09 18:16:31 +01:00
|
|
|
default:
|
2021-08-09 16:38:13 +02:00
|
|
|
ESP_LOGE(TAG, "unknown coreAffinity %i", std::to_underlying(coreAffinity));
|
|
|
|
|
return pdFAIL;
|
2021-02-09 18:16:31 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-04 12:42:43 +01:00
|
|
|
} // namespace espcpputils
|