Compare commits
No commits in common. "c335211ef8a33a7dbe0781b5c6dd53e1231fc4e4" and "8e96588829046656d8b51acf9ab21edb0dc37265" have entirely different histories.
c335211ef8
...
8e96588829
@ -1,120 +0,0 @@
|
|||||||
/*
|
|
||||||
* tasks_task.hpp
|
|
||||||
*
|
|
||||||
* Created on: Mar 18, 2021
|
|
||||||
* Author: erki
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef SKULLC_THREADS_THREAD_HPP_
|
|
||||||
#define SKULLC_THREADS_THREAD_HPP_
|
|
||||||
|
|
||||||
#include <cmsis_os.h>
|
|
||||||
|
|
||||||
#include <freertos_os2.h>
|
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <cstring>
|
|
||||||
#include <tuple>
|
|
||||||
|
|
||||||
#include <peripherals_utility.hpp>
|
|
||||||
|
|
||||||
namespace Threads
|
|
||||||
{
|
|
||||||
|
|
||||||
template<typename CRTP>
|
|
||||||
class Thread
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Thread(const osThreadAttr_t attrs)
|
|
||||||
: attributes(attrs)
|
|
||||||
{
|
|
||||||
auto f = [](void* d) {
|
|
||||||
CRTP* dd = static_cast<CRTP*>(d);
|
|
||||||
(*dd)();
|
|
||||||
};
|
|
||||||
|
|
||||||
thread_id = osThreadNew(f, this, &attributes);
|
|
||||||
assert(thread_id != nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
Thread(const char* name, const osPriority_t priority, const std::uint32_t stack_size)
|
|
||||||
: Thread(constructThreadAttrs_(name, priority, stack_size))
|
|
||||||
{}
|
|
||||||
|
|
||||||
Thread(const Thread&) = delete;
|
|
||||||
Thread(Thread&&) = delete;
|
|
||||||
|
|
||||||
osThreadId_t thread_id;
|
|
||||||
osThreadAttr_t attributes;
|
|
||||||
|
|
||||||
constexpr TaskHandle_t taskHandle() const
|
|
||||||
{
|
|
||||||
return static_cast<TaskHandle_t>(thread_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] BaseType_t notify(const long value, const eNotifyAction action)
|
|
||||||
{
|
|
||||||
return xTaskNotify(taskHandle(), value, action);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @returns Tuple. First member indicating the return value of the underlying notify
|
|
||||||
* function, the second member indicating whether a higher priority task was awoken.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
[[nodiscard]] std::pair<BaseType_t, BaseType_t> notifyFromIsr(const long value, const eNotifyAction action)
|
|
||||||
{
|
|
||||||
BaseType_t was_notified = pdFALSE;
|
|
||||||
|
|
||||||
const BaseType_t rval = xTaskNotifyFromISR(taskHandle(), value, action, &was_notified);
|
|
||||||
|
|
||||||
return {rval, was_notified};
|
|
||||||
}
|
|
||||||
|
|
||||||
void yield()
|
|
||||||
{
|
|
||||||
osThreadYield();
|
|
||||||
}
|
|
||||||
|
|
||||||
void sleep(const unsigned long delay)
|
|
||||||
{
|
|
||||||
osDelay(delay);
|
|
||||||
}
|
|
||||||
|
|
||||||
void sleepUntil(const unsigned long deadline)
|
|
||||||
{
|
|
||||||
osDelayUntil(deadline);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool notifyWait(const TickType_t delay) const
|
|
||||||
{
|
|
||||||
return xTaskNotifyWait(0, std::numeric_limits<unsigned long>::max(), nullptr, delay);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::pair<bool, unsigned long> notifyWait(const TickType_t delay, const unsigned long set_on_entry, const unsigned long set_on_exit) const
|
|
||||||
{
|
|
||||||
unsigned long notification_value = 0;
|
|
||||||
const bool rval = xTaskNotifyWait(set_on_entry, set_on_exit, ¬ification_value, delay);
|
|
||||||
|
|
||||||
return {rval, notification_value};
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
osThreadAttr_t constructThreadAttrs_(const char* name, const osPriority_t priority, const std::uint32_t stack_size)
|
|
||||||
{
|
|
||||||
auto attrs = Peripherals::zeroInitialized<osThreadAttr_t>();
|
|
||||||
|
|
||||||
attrs.name = name;
|
|
||||||
attrs.priority = priority;
|
|
||||||
attrs.stack_size = stack_size;
|
|
||||||
|
|
||||||
return attrs;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}// namespace Threads
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* SKULLC_THREADS_THREAD_HPP_ */
|
|
||||||
@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* utility_staticpointer.hpp
|
|
||||||
*
|
|
||||||
* Created on: Jun 8, 2021
|
|
||||||
* Author: erki
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef SKULLC_UTILITY_STATICPOINTER_HPP_
|
|
||||||
#define SKULLC_UTILITY_STATICPOINTER_HPP_
|
|
||||||
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
namespace Utility
|
|
||||||
{
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct StaticPointer
|
|
||||||
{
|
|
||||||
using value_type = T;
|
|
||||||
|
|
||||||
alignas(value_type) unsigned char storage[sizeof(value_type)];
|
|
||||||
|
|
||||||
template<class... Args>
|
|
||||||
value_type& setup(Args&&... args)
|
|
||||||
{
|
|
||||||
initialized_ = true;
|
|
||||||
return *(new (storage) value_type(std::forward<Args>(args)...));
|
|
||||||
}
|
|
||||||
|
|
||||||
value_type& operator*() const
|
|
||||||
{
|
|
||||||
return reinterpret_cast<T*>(storage);
|
|
||||||
}
|
|
||||||
|
|
||||||
value_type* operator->() const noexcept
|
|
||||||
{
|
|
||||||
return reinterpret_cast<T*>(storage);
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr explicit operator bool() const
|
|
||||||
{
|
|
||||||
return isInitialized();
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr bool isInitialized() const
|
|
||||||
{
|
|
||||||
return initialized_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool initialized_ = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
}// namespace Utility
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* SKULLC_UTILITY_STATICPOINTER_HPP_ */
|
|
||||||
Loading…
x
Reference in New Issue
Block a user