-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathos.cpp
More file actions
126 lines (100 loc) · 3.14 KB
/
os.cpp
File metadata and controls
126 lines (100 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright 2020 Embedded Artistry LLC
// SPDX-License-Identifier: MIT
#include "os.hpp"
#include "freertos_os_helpers.hpp"
#include <FreeRTOS.h>
#include <etl/pool.h>
#include <task.h>
// TODO: Size 0 should enable new/delete and ETL types should not be declared.
using namespace os::freertos;
#pragma mark - Definitions -
#ifndef OS_CV_POOL_SIZE
#define OS_CV_POOL_SIZE 4
#endif
#ifndef OS_THREAD_POOL_SIZE
#define OS_THREAD_POOL_SIZE 4
#endif
#ifndef OS_MUTEX_POOL_SIZE
#define OS_MUTEX_POOL_SIZE 4
#endif
#ifndef OS_SEMAPHORE_POOL_SIZE
#define OS_SEMAPHORE_POOL_SIZE 4
#endif
#ifndef OS_EVENT_FLAG_POOL_SIZE
#define OS_EVENT_FLAG_POOL_SIZE 4
#endif
#pragma mark - Static Memory Pools -
namespace
{
etl::pool<ConditionVariable, OS_CV_POOL_SIZE> cv_factory_;
etl::pool<Thread, OS_THREAD_POOL_SIZE> thread_factory_;
etl::pool<Mutex, OS_MUTEX_POOL_SIZE> mutex_factory_;
etl::pool<Semaphore, OS_SEMAPHORE_POOL_SIZE> semaphore_factory_;
etl::pool<EventFlag, OS_EVENT_FLAG_POOL_SIZE> event_factory_;
} // namespace
#pragma mark - FreeRTOS Handlers -
extern "C" void vApplicationStackOverflowHook(TaskHandle_t xTask, char* pcTaskName)
{
(void) xTask;
(void) pcTaskName;
// TODO: assert(0), or print out register info
while(1)
;
}
#pragma mark - Factory Functions -
embvm::VirtualConditionVariable* freertosOSFactory_impl::createConditionVariable_impl() noexcept
{
return cv_factory_.create();
}
embvm::VirtualThread* freertosOSFactory_impl::createThread_impl(
std::string_view name, embvm::thread::func_t f, embvm::thread::input_t input,
embvm::thread::priority p, size_t stack_size, void* stack_ptr) noexcept
{
return thread_factory_.create(name, f, input, p, stack_size, stack_ptr);
}
embvm::VirtualMutex* freertosOSFactory_impl::createMutex_impl(embvm::mutex::type type,
embvm::mutex::mode mode) noexcept
{
return mutex_factory_.create(type, mode);
}
embvm::VirtualSemaphore*
freertosOSFactory_impl::createSemaphore_impl(embvm::semaphore::mode mode,
embvm::semaphore::count_t ceiling,
embvm::semaphore::count_t initial_count) noexcept
{
return semaphore_factory_.create(mode, ceiling, initial_count);
}
embvm::VirtualEventFlag* freertosOSFactory_impl::createEventFlag_impl() noexcept
{
return event_factory_.create();
}
void freertosOSFactory_impl::destroy_impl(embvm::VirtualConditionVariable* item) noexcept
{
assert(item);
cv_factory_.destroy(reinterpret_cast<ConditionVariable*>(item));
}
void freertosOSFactory_impl::destroy_impl(embvm::VirtualThread* item) noexcept
{
assert(item);
thread_factory_.destroy(reinterpret_cast<Thread*>(item));
}
void freertosOSFactory_impl::destroy_impl(embvm::VirtualMutex* item) noexcept
{
assert(item);
mutex_factory_.destroy(reinterpret_cast<Mutex*>(item));
}
void freertosOSFactory_impl::destroy_impl(embvm::VirtualSemaphore* item) noexcept
{
assert(item);
semaphore_factory_.destroy(reinterpret_cast<Semaphore*>(item));
}
void freertosOSFactory_impl::destroy_impl(embvm::VirtualEventFlag* item) noexcept
{
assert(item);
event_factory_.destroy(reinterpret_cast<EventFlag*>(item));
}
#pragma mark - Supporting Functions -
void os::freertos::startScheduler()
{
vTaskStartScheduler();
}