This commit is contained in:
2026-02-01 12:56:05 +01:00
parent f51adeecca
commit 0bdbcb1657
857 changed files with 0 additions and 97661 deletions

View File

@@ -0,0 +1,4 @@
idf_component_register(
SRCS "com/task.cpp"
INCLUDE_DIRS "com"
)

View File

@@ -0,0 +1,111 @@
/**
* @file task.cpp
* @brief Task component implementation
* @author Mahmoud Elmohtady
* @company Nabd solutions - ASF
* @copyright Copyright (c) 2025
*/
#include "task.hpp"
Task::Task()
: m_state(TaskState::CREATED)
, m_priority(TaskPriority::NORMAL)
, m_handle(nullptr)
{
}
Task::~Task()
{
destroy();
}
bool Task::create(const TaskConfig& config, void (*taskFunction)(void*), void* arg)
{
if (config.name == nullptr || taskFunction == nullptr)
{
return false;
}
if (config.stackSize < 2048) // Minimum stack size
{
return false;
}
m_priority = config.priority;
m_state = TaskState::CREATED;
// TODO: Implement actual task creation logic
m_handle = (void*)1; // Placeholder
return true;
}
bool Task::destroy()
{
if (m_state == TaskState::DELETED)
{
return false;
}
// TODO: Implement actual task deletion logic
m_state = TaskState::DELETED;
m_handle = nullptr;
return true;
}
bool Task::suspend()
{
if (m_state != TaskState::RUNNING && m_state != TaskState::READY)
{
return false;
}
// TODO: Implement actual task suspension logic
m_state = TaskState::SUSPENDED;
return true;
}
bool Task::resume()
{
if (m_state != TaskState::SUSPENDED)
{
return false;
}
// TODO: Implement actual task resumption logic
m_state = TaskState::READY;
return true;
}
TaskState Task::getState() const
{
return m_state;
}
TaskPriority Task::getPriority() const
{
return m_priority;
}
bool Task::setPriority(TaskPriority priority)
{
m_priority = priority;
// TODO: Implement actual priority change logic
return true;
}
void Task::delay(uint32_t delayMs)
{
// TODO: Implement actual delay logic
(void)delayMs;
}
Task* Task::getCurrentTask()
{
// TODO: Implement actual current task retrieval
return nullptr;
}

View File

@@ -0,0 +1,134 @@
/**
* @file task.hpp
* @brief Task component header - Manages system tasks and their lifecycle
* @author Mahmoud Elmohtady
* @company Nabd solutions - ASF
* @copyright Copyright (c) 2025
*/
#ifndef TASK_HPP
#define TASK_HPP
#include <cstdint>
#include <cstddef>
/**
* @brief Task priority levels
*/
enum class TaskPriority
{
LOW = 1,
NORMAL = 5,
HIGH = 10,
CRITICAL = 20
};
/**
* @brief Task state enumeration
*/
enum class TaskState
{
CREATED,
READY,
RUNNING,
BLOCKED,
SUSPENDED,
DELETED
};
/**
* @brief Task configuration structure
*/
struct TaskConfig
{
const char* name; ///< Task name
uint32_t stackSize; ///< Stack size in bytes
TaskPriority priority; ///< Task priority
uint32_t coreId; ///< CPU core ID (0 or 1 for ESP32)
};
/**
* @brief Task class
*
* Provides functionality to create, manage, and control tasks
* with scheduling, prioritization, and resource management.
*/
class Task
{
public:
/**
* @brief Constructor
*/
Task();
/**
* @brief Destructor
*/
~Task();
/**
* @brief Create a new task
* @param config Task configuration
* @param taskFunction Function to run in the task
* @param arg Argument to pass to task function
* @return true if task created successfully, false otherwise
*/
bool create(const TaskConfig& config, void (*taskFunction)(void*), void* arg);
/**
* @brief Delete the task
* @return true if deleted successfully, false otherwise
*/
bool destroy();
/**
* @brief Suspend the task
* @return true if suspended successfully, false otherwise
*/
bool suspend();
/**
* @brief Resume the task
* @return true if resumed successfully, false otherwise
*/
bool resume();
/**
* @brief Get the current task state
* @return Current task state
*/
TaskState getState() const;
/**
* @brief Get the task priority
* @return Task priority level
*/
TaskPriority getPriority() const;
/**
* @brief Set the task priority
* @param priority New priority level
* @return true if priority set successfully, false otherwise
*/
bool setPriority(TaskPriority priority);
/**
* @brief Delay task execution
* @param delayMs Delay in milliseconds
*/
static void delay(uint32_t delayMs);
/**
* @brief Get current running task handle
* @return Task handle or nullptr if not running
*/
static Task* getCurrentTask();
private:
TaskState m_state;
TaskPriority m_priority;
void* m_handle;
};
#endif // TASK_HPP

View File

@@ -0,0 +1,114 @@
/**
* @file test_task.cpp
* @brief Unit tests for Task component
* @author Mahmoud Elmohtady
* @company Nabd solutions - ASF
* @copyright Copyright (c) 2025
*/
#include "unity.h"
#include "task.hpp"
extern "C" {
void setUp(void)
{
// Set up test fixtures before each test
}
void tearDown(void)
{
// Clean up test fixtures after each test
}
/**
* @brief Test task creation with valid parameters
*/
void test_task_create_valid(void)
{
Task task;
TaskConfig config = {"test_task", 4096, TaskPriority::NORMAL, 0};
bool result = task.create(config, [](void* arg){(void)arg;}, nullptr);
TEST_ASSERT_TRUE(result);
TEST_ASSERT_EQUAL(TaskState::CREATED, task.getState());
}
/**
* @brief Test task creation with invalid parameters
*/
void test_task_create_invalid_name(void)
{
Task task;
TaskConfig config = {nullptr, 4096, TaskPriority::NORMAL, 0};
bool result = task.create(config, [](void* arg){(void)arg;}, nullptr);
TEST_ASSERT_FALSE(result);
}
/**
* @brief Test task creation with small stack size
*/
void test_task_create_small_stack(void)
{
Task task;
TaskConfig config = {"test_task", 1024, TaskPriority::NORMAL, 0};
bool result = task.create(config, [](void* arg){(void)arg;}, nullptr);
TEST_ASSERT_FALSE(result);
}
/**
* @brief Test task destroy
*/
void test_task_destroy(void)
{
Task task;
TaskConfig config = {"test_task", 4096, TaskPriority::NORMAL, 0};
task.create(config, [](void* arg){(void)arg;}, nullptr);
bool result = task.destroy();
TEST_ASSERT_TRUE(result);
TEST_ASSERT_EQUAL(TaskState::DELETED, task.getState());
}
/**
* @brief Test task suspend
*/
void test_task_suspend(void)
{
Task task;
TaskConfig config = {"test_task", 4096, TaskPriority::NORMAL, 0};
task.create(config, [](void* arg){(void)arg;}, nullptr);
// TODO: Set task to running state for proper suspend test
// For now, test will likely fail as task is in CREATED state
// This is expected until proper state management is implemented
}
/**
* @brief Test task resume
*/
void test_task_resume(void)
{
Task task;
TaskConfig config = {"test_task", 4096, TaskPriority::NORMAL, 0};
task.create(config, [](void* arg){(void)arg;}, nullptr);
// TODO: Suspend task first, then resume
}
/**
* @brief Test task priority get and set
*/
void test_task_priority(void)
{
Task task;
TaskConfig config = {"test_task", 4096, TaskPriority::NORMAL, 0};
task.create(config, [](void* arg){(void)arg;}, nullptr);
TEST_ASSERT_EQUAL(TaskPriority::NORMAL, task.getPriority());
bool result = task.setPriority(TaskPriority::HIGH);
TEST_ASSERT_TRUE(result);
TEST_ASSERT_EQUAL(TaskPriority::HIGH, task.getPriority());
}
} // extern "C"