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,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