18#if !defined(RSI_INTERNAL)
22#define RSI_GLOBAL(type, name) \
23 static_assert(sizeof(std::atomic<type>) == sizeof(type), "Expected size of "#type" to be equal to std::atomic<"#type">."); \
24 alignas(uint64_t) std::atomic<type> name
26#define REGISTER_GLOBAL(name) \
27 { #name, offsetof(GlobalData, name), sizeof(GlobalData::name), RSIDataTypeGet<decltype(GlobalData::name.load())>::type }
33namespace RealTimeTasks
38 class RTTaskImplementation;
39 class RTTaskManagerImplementation;
47 inline constexpr int32_t RTTaskManagerCountMaximum = 8;
49 inline constexpr int32_t RTTaskCountMaximum = 64;
51 inline constexpr char RTTaskManagerExecutableName[] =
"rttaskmanager";
117 using TaskFunction = int32_t(*)(GlobalData*,
char*,
const uint32_t);
192 RTTaskCreationParameters(
const char*
const argFunctionName,
const char*
const argLibraryName =
nullptr,
const char*
const argLibraryDirectory =
nullptr)
199 if (argFunctionName ==
nullptr)
201 throw std::invalid_argument(
"Task function name must not be null.");
205 if (argLibraryName !=
nullptr)
214 if (argLibraryDirectory !=
nullptr)
274 static constexpr uint64_t ErrorMessageSizeMaximum = 512;
275 char ErrorMessage[ErrorMessageSizeMaximum] = {};
356 typedef int32_t (*GlobalMemberOffsetGetter)(
const char*
const name);
357 typedef int32_t (*GlobalNamesGetter)(
const char* names[], int32_t capacity);
358 typedef int32_t (*GlobalMemberTypeGetter)(
const char*
const name);
360 inline constexpr int32_t GlobalMaxSize = 2048;
362#if !defined(RSI_INTERNAL)
363#if !defined(__INTIME__)
368 const char*
const VersionGet()
override;
369 int32_t MpiVersionMajor()
override;
370 int32_t MpiVersionMinor()
override;
371 int32_t MpiVersionRelease()
override;
372 int32_t RSIVersionMajor()
override;
373 int32_t RSIVersionMinor()
override;
374 int32_t RSIVersionMicro()
override;
375 int32_t RSIVersionPatch()
override;
376 int32_t NumberGet()
override;
377 int32_t ErrorLogCountGet()
override;
378 const RsiError*
const ErrorLogGet()
override;
379 void ErrorLogClear()
override;
380 void ThrowExceptions(
bool state)
override;
384 void Trace(
bool state)
override;
385 void TraceMaskOnSet(
RSITrace maskOn)
override;
386 bool TraceMaskOnGet(
RSITrace maskOn)
override;
387 void TraceMaskOffSet(
RSITrace maskOff)
override;
388 void TraceMaskClear()
override;
389 void TraceFileSet(
const char*
const fileName)
override;
390 void TraceFileClose()
override;
391 void TraceInjectMessage(
RSITrace traceLevel,
const char*
const message)
override;
393 virtual ~RapidCodeBehavior();
394 RapidCodeBehavior(
const RapidCodeBehavior&);
395 RapidCodeBehavior& operator=(
const RapidCodeBehavior&);
396 RapidCodeBehavior(RapidCodeBehavior&&);
397 RapidCodeBehavior& operator=(RapidCodeBehavior&&);
399 class Implementation;
401 Implementation* rapidCodeBehavior =
nullptr;
402 RapidCodeBehavior(Implementation*);
413 class RSI_API
RTTask :
public virtual RapidCodeBehavior
498 static constexpr int64_t ExecutionCountWaitFailure = -1;
500 static constexpr int64_t ExecutionCountDefault = 1;
502 static constexpr int32_t ExecutionCountWaitTimeoutMillisecondsDefault = 250;
512 RTTaskImplementation* pImpl =
nullptr;
513 RTTask(RTTaskImplementation*, RapidCodeBehavior::Implementation*);
514 friend class RTTaskBuilder;
567 virtual RapidVector<const char*>
GlobalNamesGet(
const char*
const libraryName =
nullptr,
const char*
const libraryDirectory =
nullptr);
623 virtual RTTask TaskSubmit(
const char*
const functionName,
const char*
const libraryName = RTTaskCreationParameters::LibraryNameDefault,
const char*
const libraryDirectory =
nullptr);
671 virtual void TaskRemove(
const int32_t taskId);
682 RTTaskManagerImplementation* pImpl =
nullptr;
683 Storage* storage =
nullptr;
684 RTTaskManager(RTTaskManagerImplementation*, Storage* storage, RapidCodeBehavior::Implementation*);
685 friend class RTTaskManagerBuilder;
692 template <
int32_t Capacity>
693 class GlobalMetadataMap {
711 constexpr GlobalMetadataMap() : data(), tail(0) {}
713 constexpr GlobalMetadataMap(std::initializer_list<Metadata> initData)
715 for (
const auto& item : initData)
721 constexpr int32_t Size()
const {
return tail; }
723 constexpr Metadata operator[](int32_t index)
const {
return data[index]; }
725 constexpr Metadata operator[](
const char* key)
const
727 for (int32_t index = 0; index < tail; ++index)
729 auto& metadata = data[index];
730 if (std::strcmp(metadata.key, key)==0)
735 constexpr char errorMessageFormat[] =
"Key '%s' not found in GlobalMetadata.";
736 constexpr int32_t bufferSize = 256;
737 char buffer[bufferSize] = {0};
738 std::snprintf(buffer, bufferSize, errorMessageFormat, key);
739 throw std::out_of_range(buffer);
743 Metadata data[Capacity]{};
749 template<
typename Type,
typename =
void>
751 template<
typename Type>
752 struct RSIDataTypeGet<Type, typename std::enable_if<std::is_integral<Type>::value && std::is_signed<Type>::value , void>::type>
754 template<
typename Type>
755 struct RSIDataTypeGet<Type, typename std::enable_if<std::is_integral<Type>::value && std::is_unsigned<Type>::value , void>::type>
757 template<
typename Type>
758 struct RSIDataTypeGet<Type, typename std::enable_if<std::is_floating_point<Type>::value, void>::type>
The RapidCode base class. All non-error objects are derived from this class.
void Stop()
Stop the task from executing.
int64_t ExecutionCountRelativeWait(int64_t count=ExecutionCountDefault, int32_t timeoutMs=ExecutionCountWaitTimeoutMillisecondsDefault)
Wait for the task to execute a specific number of times relative to current count.
void TimingReset()
Reset the timing statistics for the task.
int32_t IdGet()
Get the ID of the task.
int64_t ExecutionCountAbsoluteWait(int64_t count=ExecutionCountDefault, int32_t timeoutMs=ExecutionCountWaitTimeoutMillisecondsDefault)
Wait for the task to reach a specific execution count.
RTTaskInfo InfoGet()
Get information about the task.
RTTaskStatus StatusGet()
Get the current status of the task.
Interface for controlling and monitoring a single real-time task. See RTTaskManager::TaskSubmit and R...
RSI::RapidCode::FirmwareValue GlobalValueGet(int32_t offset)
Read a GlobalTag by its offset. (internal use)
RTTask TaskSubmit(const RTTaskCreationParameters ¶meters)
Submit a new task to the manager using creation parameters.
RSI::RapidCode::FirmwareValue GlobalValueGet(const char *const name, const char *const libraryName=nullptr, const char *const libraryDirectory=nullptr)
Read a GlobalTag by its name.
RapidVector< RTTask > TasksGet()
Get all tasks managed by this RTTaskManager.
RapidVector< const char * > GlobalNamesGet(const char *const libraryName=nullptr, const char *const libraryDirectory=nullptr)
Get names of all global variables.
RTTask TaskSubmit(const char *const functionName, const char *const libraryName=RTTaskCreationParameters::LibraryNameDefault, const char *const libraryDirectory=nullptr)
Submit a new task to the manager using function and library names.
RSI::RapidCode::RSIDataType GlobalTypeGet(const char *const name, const char *const libraryName=nullptr, const char *const libraryDirectory=nullptr)
Get the type of a GlobalTag variable.
void GlobalValueSet(const RSI::RapidCode::FirmwareValue &value, const char *const name, const char *const libraryName=nullptr, const char *const libraryDirectory=nullptr)
Set the value of a GlobalTag variable.
int32_t IdGet()
Get the ID of the manager.
static RapidVector< RTTaskManager > Discover()
Discover all active RTTaskManager instances.
RTTaskManagerInfo InfoGet()
Get information about the manager.
void Shutdown()
Shutdown the RTTaskManager firmware.
RTTaskManagerStatus StatusGet()
Get the current status of the manager.
static RTTaskManager Create(const RTTaskManagerCreationParameters ¶meters)
Create a new RTTaskManager instance.
static RTTaskManager Get(const int32_t managerId)
Get an existing RTTaskManager by ID.
Interface for managing real-time tasks firmware. See Real-Time Tasks for more information.
Represents the error details thrown as an exception by all RapidCode classes. This class contains an ...
Tracing allows for low level logs to be generated.
TaskPriority
Enum representing the priority levels for a real-time task.
@ MediumLow
A medium-low real-time priority level.
@ Low
A low real-time priority level.
@ Highest
The highest real-time priority level for an RTTask. Is below the priority of the main thread of the R...
@ High
A high real-time priority level.
@ Medium
A medium real-time priority level. This is the default priority for real-time tasks.
@ MediumHigh
A medium-high real-time priority level.
@ Lowest
The lowest real-time priority level for an RTTask. Is above standard thread priorities.
@ NonRealTime
A task without any real-time priority, given the operating system's default.
RTTaskManagerState
Enum representing the possible states of an RTTaskManager.
@ Stopped
Manager firmware is initialized but not currently running.
RTTaskState
Enum representing the possible states of a real-time task.
@ Dead
Task is not initialized or has been terminated.
@ Waiting
Task is active but waiting for its next scheduled execution time.
@ Running
Task is currently executing.
@ Disabled
Task is initialized but not currently executing.
PlatformType
Enum representing the platform type for an RTTaskManager.
@ Native
Native platform (where the library is running, Windows or Linux).
@ Windows
Standard Windows (useful for debugging tasks before running on INtime).
@ Linux
Linux with PREEMPT_RT.
RSIDataType
Data types for User Limits and other triggers.
@ RSIDataTypeUINT32
uint32 (unsigned 32-bit integer)
@ RSIDataTypeDOUBLE
double (64-bit floating point)
@ RSIDataTypeINT64
int64 (signed 64-bit integer)
@ RSIDataTypeINVALID
invalid
@ RSIDataTypeINT16
signed 16-bit integer
@ RSIDataTypeUINT16
unsigned 16-bit integer
@ RSIDataTypeINT32
int32 (signed 32-bit integer)
@ RSIDataTypeUINT64
uint64 (unsigned 64-bit integer)
@ RSIDataTypeFLOAT
float (32-bit floating point, rarely used)
RSIErrorMessage
All possible RSI Error Messages.
RTTaskCreationParameters(const char *const argFunctionName, const char *const argLibraryName=nullptr, const char *const argLibraryDirectory=nullptr)
Constructor with function name and library details.
RTTaskCreationParameters specifies all the information required to create and configure a real-time t...
static constexpr int32_t RepeatForever
Special value to indicate the task should repeat forever.
char FunctionName[NameLengthMaximum]
Name of the task function to execute.
char LibraryName[NameLengthMaximum]
Name of the library containing the task function.
char UserLabel[NameLengthMaximum]
User-defined label for the task.
int32_t Repeats
Number of times the task should execute (RepeatForever for infinite, 0 for none (one-shot)).
TaskPriority Priority
Priority of the task (coming soon).
static constexpr int32_t RepeatNone
Special value to indicate the task should not repeat.
static constexpr int32_t PeriodDefault
Default execution period in RMP sample periods.
static constexpr int32_t DirectoryLengthMaximum
Maximum length of the library directory path.
char LibraryDirectory[DirectoryLengthMaximum]
Path to the directory containing the library with the task function.
int32_t Period
Execution period of the task in RMP sample periods.
static constexpr int32_t PhaseDefault
Default phase offset for task execution.
int32_t Phase
Phase offset for task execution. For example, if you have 4 tasks with a period of 4,...
static constexpr bool EnableTimingDefault
Default setting for timing measurements.
static constexpr int32_t NameLengthMaximum
Maximum length of name fields (library, function, user label).
static constexpr TaskPriority PriorityDefault
Default priority for real-time tasks.
static constexpr const char *const LibraryNameDefault
Default library name for the task function.
bool EnableTiming
Whether to enable timing measurements for the task. Keep in mind, enabling timing does add a small am...
RTTaskInfo provides information about a real-time task, including its creation parameters....
RTTaskCreationParameters CreationParameters
Creation parameters used to create the task.
RTTaskManagerCreationParameters specifies all the information required to create and configure an RTT...
bool NoRmp
Disable the initialization of the RMP and RapidCode objects on task manager startup and their use in ...
char UserLabel[NameLengthMaximum]
User-defined label for the manager.
int32_t CpuCore
[Linux] CPU core to which the manager should be pinned (-1 for no pinning).
static constexpr int32_t DirectoryLengthMaximum
Maximum length of the directory path.
char NodeName[NameLengthMaximum]
[INtime] Name of the node on which the manager will run.
char RTTaskDirectory[DirectoryLengthMaximum]
Path to the directory containing the real-time task libraries.
static constexpr int32_t NameLengthMaximum
Maximum length of name fields (node name, user label).
Information about RTTaskManager firmware, including its creation parameters and ID....
int32_t Id
ID of the manager.
RTTaskManagerCreationParameters CreationParameters
Creation parameters used to create the manager.
RTTaskManagerStatus provides status information for RTTaskManager firmware, including its current sta...
uint64_t CycleTimeMax
Maximum execution time of a cycle in nanoseconds.
uint64_t TaskSubmissionCount
Number of tasks submitted to the manager.
RTTaskManagerState State
Current state of the manager.
double StartTimeDeltaMean
Mean difference between the current and previous start of the main task manager loop execution in nan...
uint64_t CycleTimeLast
Execution time of the last cycle in nanoseconds.
uint64_t StartTimeDeltaLast
Last difference between the current and previous start of the main task manager loop execution in nan...
double CycleTimeMean
Mean execution time of cycles in nanoseconds.
uint64_t CycleTimeMin
Minimum execution time of a cycle in nanoseconds.
int64_t CycleCount
Number of cycles executed by the manager.
uint64_t StartTimeDeltaMax
Maximum difference between the current and previous start of the main task manager loop execution in ...
RTTaskStatus provides status information for a real-time task, including its current state,...
double StartTimeDeltaMean
Mean difference between the current and previous start of the task execution in nanoseconds.
RTTaskState State
Current state of the task.
uint64_t StartTimeDeltaLast
Last difference between the current and previous start of the task execution in nanoseconds.
static constexpr uint64_t InvalidExecutionTime
Invalid value for execution time, indicating timing is not enabled or the task has not executed.
uint64_t ExecutionTimeMin
Minimum execution time of the task in nanoseconds.
uint64_t ExecutionTimeMax
Maximum execution time of the task in nanoseconds.
int64_t ExecutionCount
Number of times the task has executed.
uint64_t StartTimeDeltaMax
Maximum difference between the current and previous start of the task execution in nanoseconds.
double ExecutionTimeMean
Mean execution time of the task in nanoseconds.
uint64_t ExecutionTimeLast
Last execution time of the task in nanoseconds.
RTTaskStatus()=default
Default constructor.
static constexpr int64_t InvalidExecutionCount
Invalid value for execution count, indicating the task has not executed.
Union representing a generic RMP firmware value with multiple data types, stored in 64-bits.