RTXI  3.0.0
The Real-Time eXperiment Interface Reference Manual
rtos.hpp
Go to the documentation of this file.
1 #ifndef RTOS_H
2 #define RTOS_H
3 
4 #include <any>
5 #include <functional>
6 #include <thread>
7 
8 #include <errno.h>
9 #include <string.h>
10 
11 #include "debug.hpp"
12 #include "fifo.hpp"
13 
14 namespace RT::OS
15 {
16 
17 const int64_t SECONDS_TO_NANOSECONDS =
18  1000000000; // Conversion from sec to nsec
19 const int64_t DEFAULT_PERIOD = 1000000; // Default period is set to 1 msec
20 const uint64_t DEFAULT_FIFO_SIZE = 255; // Default Fifo size of 255 bytes
21 const size_t PROCESSOR_COUNT = std::thread::hardware_concurrency();
30 struct Task
31 {
33  int64_t next_t = 0;
34  bool task_finished = false;
35  std::thread rt_thread;
36  std::any thread_id;
37 };
38 
48 int initiate(RT::OS::Task* task);
49 
57 void shutdown(RT::OS::Task* task);
58 
66 void deleteTask(Task* task);
67 
78 int setPeriod(Task* task, int64_t period);
79 
94 int64_t getPeriod();
95 
104 void sleepTimestep(Task* task);
105 
113 bool isRealtime();
114 
122 int64_t getTime();
123 
134 double getCpuUsage();
135 
147 int createTask(Task* task, void (*func)(void*), void* arg);
148 
155 void renameOSThread(std::thread& thread, const std::string& name);
156 } // namespace RT::OS
157 
158 #endif
Definition: fifo.cpp:31
int createTask(Task *task, void(*func)(void *), void *arg)
Definition: rtos_evl.cpp:86
const uint64_t DEFAULT_FIFO_SIZE
Definition: rtos.hpp:20
int64_t getPeriod()
Definition: rtos_evl.cpp:150
int setPeriod(Task *task, int64_t period)
Definition: rtos_evl.cpp:144
const int64_t SECONDS_TO_NANOSECONDS
Definition: rtos.hpp:17
void shutdown(RT::OS::Task *task)
Definition: rtos_evl.cpp:72
bool isRealtime()
void sleepTimestep(Task *task)
Definition: rtos_evl.cpp:159
void renameOSThread(std::thread &thread, const std::string &name)
Definition: rtos_evl.cpp:175
const size_t PROCESSOR_COUNT
Definition: rtos.hpp:21
int64_t getTime()
int initiate(RT::OS::Task *task)
Definition: rtos_evl.cpp:39
void deleteTask(Task *task)
Definition: rtos_evl.cpp:117
const int64_t DEFAULT_PERIOD
Definition: rtos.hpp:19
double getCpuUsage()
bool task_finished
Definition: rtos.hpp:34
std::any thread_id
Definition: rtos.hpp:36
int64_t next_t
Definition: rtos.hpp:33
std::thread rt_thread
Definition: rtos.hpp:35
int64_t period
Definition: rtos.hpp:32