trying to fuse header / inc

This commit is contained in:
2021-07-19 16:25:51 +02:00
parent 7849b8e391
commit d47906e833
767 changed files with 117 additions and 135 deletions

View File

@ -0,0 +1,24 @@
#include "fsfw/osal/rtems/BinarySemaphore.h"
#include <rtems/rtems/sem.h>
BinarySemaphore::BinarySemaphore() {
}
BinarySemaphore::~BinarySemaphore() {
}
// Interface implementation
ReturnValue_t BinarySemaphore::acquire(TimeoutType timeoutType, uint32_t timeoutMs) {
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t BinarySemaphore::release() {
return HasReturnvaluesIF::RETURN_OK;
}
uint8_t BinarySemaphore::getSemaphoreCounter() const {
return 0;
}

View File

@ -0,0 +1,20 @@
target_sources(${LIB_FSFW_NAME}
PRIVATE
Clock.cpp
CpuUsage.cpp
InitTask.cpp
InternalErrorCodes.cpp
MessageQueue.cpp
PeriodicTask.cpp
Mutex.cpp
MutexFactory.cpp
FixedTimeslotTask.cpp
QueueFactory.cpp
RtemsBasic.cpp
RTEMSTaskBase.cpp
TaskFactory.cpp
BinarySemaphore.cpp
SemaphoreFactory.cpp
)

View File

@ -0,0 +1,156 @@
#include "fsfw/osal/rtems/RtemsBasic.h"
#include "fsfw/timemanager/Clock.h"
#include "fsfw/ipc/MutexGuard.h"
#include <rtems/score/todimpl.h>
#include <rtems/rtems/clockimpl.h>
uint16_t Clock::leapSeconds = 0;
MutexIF* Clock::timeMutex = nullptr;
uint32_t Clock::getTicksPerSecond(void){
rtems_interval ticks_per_second = rtems_clock_get_ticks_per_second();
return static_cast<uint32_t>(ticks_per_second);
}
ReturnValue_t Clock::setClock(const TimeOfDay_t* time) {
rtems_time_of_day timeRtems;
timeRtems.year = time->year;
timeRtems.month = time->month;
timeRtems.day = time->day;
timeRtems.hour = time->hour;
timeRtems.minute = time->minute;
timeRtems.second = time->second;
timeRtems.ticks = time->usecond * getTicksPerSecond() / 1e6;
rtems_status_code status = rtems_clock_set(&timeRtems);
switch(status){
case RTEMS_SUCCESSFUL:
return HasReturnvaluesIF::RETURN_OK;
case RTEMS_INVALID_ADDRESS:
return HasReturnvaluesIF::RETURN_FAILED;
case RTEMS_INVALID_CLOCK:
return HasReturnvaluesIF::RETURN_FAILED;
default:
return HasReturnvaluesIF::RETURN_FAILED;
}
}
ReturnValue_t Clock::setClock(const timeval* time) {
timespec newTime;
newTime.tv_sec = time->tv_sec;
if(time->tv_usec < 0) {
// better returnvalue.
return HasReturnvaluesIF::RETURN_FAILED;
}
newTime.tv_nsec = time->tv_usec * TOD_NANOSECONDS_PER_MICROSECOND;
ISR_lock_Context context;
_TOD_Lock();
_TOD_Acquire(&context);
Status_Control status = _TOD_Set(&newTime, &context);
_TOD_Unlock();
if(status == STATUS_SUCCESSFUL) {
return HasReturnvaluesIF::RETURN_OK;
}
// better returnvalue
return HasReturnvaluesIF::RETURN_FAILED;
}
ReturnValue_t Clock::getClock_timeval(timeval* time) {
//Callable from ISR
rtems_status_code status = rtems_clock_get_tod_timeval(time);
switch(status){
case RTEMS_SUCCESSFUL:
return HasReturnvaluesIF::RETURN_OK;
case RTEMS_NOT_DEFINED:
return HasReturnvaluesIF::RETURN_FAILED;
default:
return HasReturnvaluesIF::RETURN_FAILED;
}
}
ReturnValue_t Clock::getUptime(timeval* uptime) {
//According to docs.rtems.org for rtems 5 this method is more accurate than rtems_clock_get_ticks_since_boot
timespec time;
rtems_status_code status = rtems_clock_get_uptime(&time);
uptime->tv_sec = time.tv_sec;
time.tv_nsec = time.tv_nsec / 1000;
uptime->tv_usec = time.tv_nsec;
switch(status){
case RTEMS_SUCCESSFUL:
return HasReturnvaluesIF::RETURN_OK;
default:
return HasReturnvaluesIF::RETURN_FAILED;
}
}
ReturnValue_t Clock::getUptime(uint32_t* uptimeMs) {
//This counter overflows after 50 days
*uptimeMs = rtems_clock_get_ticks_since_boot();
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t Clock::getClock_usecs(uint64_t* time) {
timeval temp_time;
rtems_status_code returnValue = rtems_clock_get_tod_timeval(&temp_time);
*time = ((uint64_t) temp_time.tv_sec * 1000000) + temp_time.tv_usec;
switch(returnValue){
case RTEMS_SUCCESSFUL:
return HasReturnvaluesIF::RETURN_OK;
default:
return HasReturnvaluesIF::RETURN_FAILED;
}
}
ReturnValue_t Clock::getDateAndTime(TimeOfDay_t* time) {
/* For all but the last field, the struct will be filled with the correct values */
rtems_time_of_day timeRtems;
rtems_status_code status = rtems_clock_get_tod(&timeRtems);
switch (status) {
case RTEMS_SUCCESSFUL: {
/* The last field now contains the RTEMS ticks of the seconds from 0
to rtems_clock_get_ticks_per_second() minus one.
We calculate the microseconds accordingly */
time->day = timeRtems.day;
time->hour = timeRtems.hour;
time->minute = timeRtems.minute;
time->month = timeRtems.month;
time->second = timeRtems.second;
time->usecond = static_cast<float>(timeRtems.ticks) /
rtems_clock_get_ticks_per_second() * 1e6;
time->year = timeRtems.year;
return HasReturnvaluesIF::RETURN_OK;
}
case RTEMS_NOT_DEFINED:
/* System date and time is not set */
return HasReturnvaluesIF::RETURN_FAILED;
case RTEMS_INVALID_ADDRESS:
/* time_buffer is NULL */
return HasReturnvaluesIF::RETURN_FAILED;
default:
return HasReturnvaluesIF::RETURN_FAILED;
}
}
ReturnValue_t Clock::convertTimeOfDayToTimeval(const TimeOfDay_t* from,
timeval* to) {
//Fails in 2038..
rtems_time_of_day timeRtems;
timeRtems.year = from->year;
timeRtems.month = from->month;
timeRtems.day = from->day;
timeRtems.hour = from->hour;
timeRtems.minute = from->minute;
timeRtems.second = from->second;
timeRtems.ticks = from->usecond * getTicksPerSecond() / 1e6;
to->tv_sec = _TOD_To_seconds(&timeRtems);
to->tv_usec = from->usecond;
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t Clock::convertTimevalToJD2000(timeval time, double* JD2000) {
*JD2000 = (time.tv_sec - 946728000. + time.tv_usec / 1000000.) / 24.
/ 3600.;
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -0,0 +1,183 @@
#include "fsfw/osal/rtems/CpuUsage.h"
#include "fsfw/serialize/SerialArrayListAdapter.h"
#include "fsfw/serialize/SerializeAdapter.h"
#include <string.h>
extern "C" {
#include <rtems/cpuuse.h>
}
int handlePrint(void * token, const char *format, ...) {
CpuUsage *cpuUsage = (CpuUsage *) token;
if (cpuUsage->counter == 0) {
//header
cpuUsage->counter++;
return 0;
}
if (cpuUsage->counter % 2 == 1) {
{
//we can not tell when the last call is so we assume it be every uneven time
va_list vl;
va_start(vl, format);
float timeSinceLastReset = va_arg(vl,uint32_t);
uint32_t timeSinceLastResetDecimals = va_arg(vl,uint32_t);
timeSinceLastReset = timeSinceLastReset
+ (timeSinceLastResetDecimals / 1000.);
cpuUsage->timeSinceLastReset = timeSinceLastReset;
va_end(vl);
}
//task name and id
va_list vl;
va_start(vl, format);
cpuUsage->cachedValue.id = va_arg(vl,uint32_t);
const char *name = va_arg(vl,const char *);
memcpy(cpuUsage->cachedValue.name, name,
CpuUsage::ThreadData::MAX_LENGTH_OF_THREAD_NAME);
va_end(vl);
} else {
//statistics
va_list vl;
va_start(vl, format);
float run = va_arg(vl,uint32_t);
uint32_t runDecimals = va_arg(vl,uint32_t);
float percent = va_arg(vl,uint32_t);
uint32_t percent_decimals = va_arg(vl,uint32_t);
run = run + (runDecimals / 1000.);
percent = percent + (percent_decimals / 1000.);
cpuUsage->cachedValue.percentUsage = percent;
cpuUsage->cachedValue.timeRunning = run;
cpuUsage->threadData.insert(cpuUsage->cachedValue);
va_end(vl);
}
cpuUsage->counter++;
return 0;
}
CpuUsage::CpuUsage() :
counter(0), timeSinceLastReset(0) {
}
CpuUsage::~CpuUsage() {
}
void CpuUsage::resetCpuUsage() {
rtems_cpu_usage_reset();
}
void CpuUsage::read() {
//rtems_cpu_usage_report_with_plugin(this, &handlePrint);
}
void CpuUsage::clear() {
counter = 0;
timeSinceLastReset = 0;
threadData.clear();
}
ReturnValue_t CpuUsage::serialize(uint8_t** buffer, size_t* size,
size_t maxSize, Endianness streamEndianness) const {
ReturnValue_t result = SerializeAdapter::serialize(
&timeSinceLastReset, buffer, size, maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return SerialArrayListAdapter<ThreadData>::serialize(&threadData, buffer,
size, maxSize, streamEndianness);
}
uint32_t CpuUsage::getSerializedSize() const {
uint32_t size = 0;
size += sizeof(timeSinceLastReset);
size += SerialArrayListAdapter<ThreadData>::getSerializedSize(&threadData);
return size;
}
ReturnValue_t CpuUsage::deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) {
ReturnValue_t result = SerializeAdapter::deSerialize(
&timeSinceLastReset, buffer, size, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return SerialArrayListAdapter<ThreadData>::deSerialize(&threadData, buffer,
size, streamEndianness);
}
ReturnValue_t CpuUsage::ThreadData::serialize(uint8_t** buffer, size_t* size,
size_t maxSize, Endianness streamEndianness) const {
ReturnValue_t result = SerializeAdapter::serialize(&id, buffer,
size, maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if (*size + MAX_LENGTH_OF_THREAD_NAME > maxSize) {
return BUFFER_TOO_SHORT;
}
memcpy(*buffer, name, MAX_LENGTH_OF_THREAD_NAME);
*size += MAX_LENGTH_OF_THREAD_NAME;
*buffer += MAX_LENGTH_OF_THREAD_NAME;
result = SerializeAdapter::serialize(&timeRunning,
buffer, size, maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = SerializeAdapter::serialize(&percentUsage,
buffer, size, maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return HasReturnvaluesIF::RETURN_OK;
}
uint32_t CpuUsage::ThreadData::getSerializedSize() const {
uint32_t size = 0;
size += sizeof(id);
size += MAX_LENGTH_OF_THREAD_NAME;
size += sizeof(timeRunning);
size += sizeof(percentUsage);
return size;
}
ReturnValue_t CpuUsage::ThreadData::deSerialize(const uint8_t** buffer,
size_t* size, Endianness streamEndianness) {
ReturnValue_t result = SerializeAdapter::deSerialize(&id, buffer,
size, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if (*size < MAX_LENGTH_OF_THREAD_NAME) {
return STREAM_TOO_SHORT;
}
memcpy(name, *buffer, MAX_LENGTH_OF_THREAD_NAME);
*buffer -= MAX_LENGTH_OF_THREAD_NAME;
result = SerializeAdapter::deSerialize(&timeRunning,
buffer, size, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = SerializeAdapter::deSerialize(&percentUsage,
buffer, size, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -0,0 +1,53 @@
#ifndef CPUUSAGE_H_
#define CPUUSAGE_H_
#include "fsfw/container/FixedArrayList.h"
#include "fsfw/serialize/SerializeIF.h"
#include <stdarg.h>
class CpuUsage : public SerializeIF {
public:
static const uint8_t MAXIMUM_NUMBER_OF_THREADS = 30;
class ThreadData: public SerializeIF {
public:
static const uint8_t MAX_LENGTH_OF_THREAD_NAME = 4;
uint32_t id;
char name[MAX_LENGTH_OF_THREAD_NAME];
float timeRunning;
float percentUsage;
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
size_t maxSize, Endianness streamEndianness) const override;
virtual size_t getSerializedSize() const override;
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) override;
};
CpuUsage();
virtual ~CpuUsage();
uint8_t counter;
float timeSinceLastReset;
FixedArrayList<ThreadData, MAXIMUM_NUMBER_OF_THREADS> threadData;
ThreadData cachedValue;
static void resetCpuUsage();
void read();
void clear();
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
size_t maxSize, Endianness streamEndianness) const override;
virtual size_t getSerializedSize() const override;
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) override;
};
#endif /* CPUUSAGE_H_ */

View File

@ -0,0 +1,140 @@
#include "fsfw/osal/rtems/FixedTimeslotTask.h"
#include "fsfw/osal/rtems/RtemsBasic.h"
#include "fsfw/tasks/FixedSequenceSlot.h"
#include "fsfw/objectmanager/SystemObjectIF.h"
#include "fsfw/objectmanager/ObjectManager.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include <rtems/bspIo.h>
#include <rtems/io.h>
#include <rtems/rtems/ratemon.h>
#include <rtems/rtems/status.h>
#include <rtems/rtems/tasks.h>
#include <rtems/rtems/types.h>
#include <sys/_stdint.h>
#if FSFW_CPP_OSTREAM_ENABLED == 1
#include <iostream>
#endif
#include <cstddef>
#include <list>
uint32_t FixedTimeslotTask::deadlineMissedCount = 0;
FixedTimeslotTask::FixedTimeslotTask(const char *name, rtems_task_priority setPriority,
size_t setStack, uint32_t setOverallPeriod, void (*setDeadlineMissedFunc)(void)):
RTEMSTaskBase(setPriority, setStack, name), periodId(0), pst(setOverallPeriod) {
// All additional attributes are applied to the object.
this->deadlineMissedFunc = setDeadlineMissedFunc;
}
FixedTimeslotTask::~FixedTimeslotTask() {
}
rtems_task FixedTimeslotTask::taskEntryPoint(rtems_task_argument argument) {
/* The argument is re-interpreted as a FixedTimeslotTask */
FixedTimeslotTask *originalTask(reinterpret_cast<FixedTimeslotTask*>(argument));
/* The task's functionality is called. */
return originalTask->taskFunctionality();
/* Should never be reached */
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "Polling task " << originalTask->getId() << " returned from taskFunctionality." <<
std::endl;
#endif
}
void FixedTimeslotTask::missedDeadlineCounter() {
FixedTimeslotTask::deadlineMissedCount++;
if (FixedTimeslotTask::deadlineMissedCount % 10 == 0) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "PST missed " << FixedTimeslotTask::deadlineMissedCount
<< " deadlines." << std::endl;
#endif
}
}
ReturnValue_t FixedTimeslotTask::startTask() {
rtems_status_code status = rtems_task_start(id, FixedTimeslotTask::taskEntryPoint,
rtems_task_argument((void *) this));
if (status != RTEMS_SUCCESSFUL) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "PollingTask::startTask for " << std::hex << this->getId()
<< std::dec << " failed." << std::endl;
#endif
}
switch(status){
case RTEMS_SUCCESSFUL:
//ask started successfully
return HasReturnvaluesIF::RETURN_OK;
default:
/*
RTEMS_INVALID_ADDRESS - invalid task entry point
RTEMS_INVALID_ID - invalid task id
RTEMS_INCORRECT_STATE - task not in the dormant state
RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task */
return HasReturnvaluesIF::RETURN_FAILED;
}
}
ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId,
uint32_t slotTimeMs, int8_t executionStep) {
ExecutableObjectIF* object = ObjectManager::instance()->get<ExecutableObjectIF>(componentId);
if (object != nullptr) {
pst.addSlot(componentId, slotTimeMs, executionStep, object, this);
return HasReturnvaluesIF::RETURN_OK;
}
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "Component " << std::hex << componentId <<
" not found, not adding it to pst" << std::endl;
#endif
return HasReturnvaluesIF::RETURN_FAILED;
}
uint32_t FixedTimeslotTask::getPeriodMs() const {
return pst.getLengthMs();
}
ReturnValue_t FixedTimeslotTask::checkSequence() const {
return pst.checkSequence();
}
void FixedTimeslotTask::taskFunctionality() {
/* A local iterator for the Polling Sequence Table is created to find the start time for
the first entry. */
FixedSlotSequence::SlotListIter it = pst.current;
/* Initialize the PST with the correct calling task */
pst.intializeSequenceAfterTaskCreation();
/* The start time for the first entry is read. */
rtems_interval interval = RtemsBasic::convertMsToTicks(it->pollingTimeMs);
RTEMSTaskBase::setAndStartPeriod(interval,&periodId);
//The task's "infinite" inner loop is entered.
while (1) {
if (pst.slotFollowsImmediately()) {
/* Do nothing */
}
else {
/* The interval for the next polling slot is selected. */
interval = RtemsBasic::convertMsToTicks(this->pst.getIntervalToNextSlotMs());
/* The period is checked and restarted with the new interval.
If the deadline was missed, the deadlineMissedFunc is called. */
rtems_status_code status = RTEMSTaskBase::restartPeriod(interval,periodId);
if (status == RTEMS_TIMEOUT) {
if (this->deadlineMissedFunc != nullptr) {
this->deadlineMissedFunc();
}
}
}
/* The device handler for this slot is executed and the next one is chosen. */
this->pst.executeAndAdvance();
}
}
ReturnValue_t FixedTimeslotTask::sleepFor(uint32_t ms){
return RTEMSTaskBase::sleepFor(ms);
};

View File

@ -0,0 +1,81 @@
#ifndef FSFW_OSAL_RTEMS_FIXEDTIMESLOTTASK_H_
#define FSFW_OSAL_RTEMS_FIXEDTIMESLOTTASK_H_
#include "RTEMSTaskBase.h"
#include "../../tasks/FixedSlotSequence.h"
#include "../../tasks/FixedTimeslotTaskIF.h"
class FixedTimeslotTask: public RTEMSTaskBase, public FixedTimeslotTaskIF {
public:
/**
* @brief The standard constructor of the class.
* @details
* This is the general constructor of the class. In addition to the TaskBase parameters,
* the following variables are passed:
* @param setDeadlineMissedFunc The function pointer to the deadline missed function
* that shall be assigned.
* @param getPst The object id of the completely initialized polling sequence.
*/
FixedTimeslotTask( const char *name, rtems_task_priority setPriority, size_t setStackSize,
uint32_t overallPeriod, void (*setDeadlineMissedFunc)());
/**
* @brief The destructor of the class.
* @details
* The destructor frees all heap memory that was allocated on thread initialization
* for the PST andthe device handlers. This is done by calling the PST's destructor.
*/
virtual ~FixedTimeslotTask( void );
ReturnValue_t startTask( void );
/**
* This static function can be used as #deadlineMissedFunc.
* It counts missedDeadlines and prints the number of missed deadlines every 10th time.
*/
static void missedDeadlineCounter();
/**
* A helper variable to count missed deadlines.
*/
static uint32_t deadlineMissedCount;
ReturnValue_t addSlot(object_id_t componentId, uint32_t slotTimeMs, int8_t executionStep);
uint32_t getPeriodMs() const;
ReturnValue_t checkSequence() const;
ReturnValue_t sleepFor(uint32_t ms);
protected:
/**
* @brief id of the associated OS period
*/
rtems_id periodId;
FixedSlotSequence pst;
/**
* @brief This attribute holds a function pointer that is executed when a deadline was missed.
*
* @details
* Another function may be announced to determine the actions to perform when a deadline
* was missed. Currently, only one function for missing any deadline is allowed.
* If not used, it shall be declared NULL.
*/
void ( *deadlineMissedFunc )( void ) = nullptr;
/**
* @brief This is the entry point in a new polling thread.
* @details This method is the entry point in the new thread
*/
static rtems_task taskEntryPoint( rtems_task_argument argument );
/**
* @brief This function holds the main functionality of the thread.
* @details
* Holding the main functionality of the task, this method is most important.
* It links the functionalities provided by FixedSlotSequence with the OS's system calls to
* keep the timing of the periods.
*/
void taskFunctionality( void );
};
#endif /* FSFW_OSAL_RTEMS_FIXEDTIMESLOTTASK_H_ */

View File

@ -0,0 +1,11 @@
#include "fsfw/osal/rtems/InitTask.h"
#include "fsfw/osal/rtems/RtemsBasic.h"
InitTask::InitTask() {
}
InitTask::~InitTask() {
rtems_task_delete(RTEMS_SELF);
}

View File

@ -0,0 +1,19 @@
#ifndef OS_RTEMS_INITTASK_H_
#define OS_RTEMS_INITTASK_H_
//TODO move into static function in TaskIF
/**
* The init task is created automatically by RTEMS.
* As one may need to control it (e.g. suspending it for a while),
* this dummy class provides an implementation of TaskIF to do so.
* Warning: The init task is deleted with this stub, i.e. the destructor
* calls rtems_task_delete(RTEMS_SELF)
*/
class InitTask {
public:
InitTask();
virtual ~InitTask();
};
#endif /* OS_RTEMS_INITTASK_H_ */

View File

@ -0,0 +1,62 @@
#include "fsfw/osal/InternalErrorCodes.h"
#include <rtems/score/interr.h>
ReturnValue_t InternalErrorCodes::translate(uint8_t code) {
switch (code) {
//TODO It looks like RTEMS-5 does not provide the same error codes
// case INTERNAL_ERROR_NO_CONFIGURATION_TABLE:
// return NO_CONFIGURATION_TABLE;
// case INTERNAL_ERROR_NO_CPU_TABLE:
// return NO_CPU_TABLE;
// case INTERNAL_ERROR_INVALID_WORKSPACE_ADDRESS:
// return INVALID_WORKSPACE_ADDRESS;
case INTERNAL_ERROR_TOO_LITTLE_WORKSPACE:
return TOO_LITTLE_WORKSPACE;
// case INTERNAL_ERROR_WORKSPACE_ALLOCATION:
// return WORKSPACE_ALLOCATION;
// case INTERNAL_ERROR_INTERRUPT_STACK_TOO_SMALL:
// return INTERRUPT_STACK_TOO_SMALL;
case INTERNAL_ERROR_THREAD_EXITTED:
return THREAD_EXITTED;
case INTERNAL_ERROR_INCONSISTENT_MP_INFORMATION:
return INCONSISTENT_MP_INFORMATION;
case INTERNAL_ERROR_INVALID_NODE:
return INVALID_NODE;
case INTERNAL_ERROR_NO_MPCI:
return NO_MPCI;
case INTERNAL_ERROR_BAD_PACKET:
return BAD_PACKET;
case INTERNAL_ERROR_OUT_OF_PACKETS:
return OUT_OF_PACKETS;
case INTERNAL_ERROR_OUT_OF_GLOBAL_OBJECTS:
return OUT_OF_GLOBAL_OBJECTS;
case INTERNAL_ERROR_OUT_OF_PROXIES:
return OUT_OF_PROXIES;
case INTERNAL_ERROR_INVALID_GLOBAL_ID:
return INVALID_GLOBAL_ID;
#ifndef STM32H743ZI_NUCLEO
case INTERNAL_ERROR_BAD_STACK_HOOK:
return BAD_STACK_HOOK;
#endif
// case INTERNAL_ERROR_BAD_ATTRIBUTES:
// return BAD_ATTRIBUTES;
// case INTERNAL_ERROR_IMPLEMENTATION_KEY_CREATE_INCONSISTENCY:
// return IMPLEMENTATION_KEY_CREATE_INCONSISTENCY;
// case INTERNAL_ERROR_IMPLEMENTATION_BLOCKING_OPERATION_CANCEL:
// return IMPLEMENTATION_BLOCKING_OPERATION_CANCEL;
// case INTERNAL_ERROR_MUTEX_OBTAIN_FROM_BAD_STATE:
// return MUTEX_OBTAIN_FROM_BAD_STATE;
// case INTERNAL_ERROR_UNLIMITED_AND_MAXIMUM_IS_0:
// return UNLIMITED_AND_MAXIMUM_IS_0;
default:
return HasReturnvaluesIF::RETURN_FAILED;
}
}
InternalErrorCodes::InternalErrorCodes() {
}
InternalErrorCodes::~InternalErrorCodes() {
}

View File

@ -0,0 +1,155 @@
#include "fsfw/osal/rtems/MessageQueue.h"
#include "fsfw/osal/rtems/RtemsBasic.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/objectmanager/ObjectManager.h"
#include <cstring>
MessageQueue::MessageQueue(size_t message_depth, size_t max_message_size) :
id(0), lastPartner(0), defaultDestination(NO_QUEUE), internalErrorReporter(nullptr) {
rtems_name name = ('Q' << 24) + (queueCounter++ << 8);
rtems_status_code status = rtems_message_queue_create(name, message_depth,
max_message_size, 0, &(this->id));
if (status != RTEMS_SUCCESSFUL) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "MessageQueue::MessageQueue: Creating Queue " << std::hex
<< name << std::dec << " failed with status:"
<< (uint32_t) status << std::endl;
#endif
this->id = 0;
}
}
MessageQueue::~MessageQueue() {
rtems_message_queue_delete(id);
}
ReturnValue_t MessageQueue::sendMessage(MessageQueueId_t sendTo,
MessageQueueMessageIF* message, bool ignoreFault) {
return sendMessageFrom(sendTo, message, this->getId(), ignoreFault);
}
ReturnValue_t MessageQueue::sendToDefault(MessageQueueMessageIF* message) {
return sendToDefaultFrom(message, this->getId());
}
ReturnValue_t MessageQueue::reply(MessageQueueMessageIF* message) {
if (this->lastPartner != 0) {
return sendMessage(this->lastPartner, message, this->getId());
} else {
return NO_REPLY_PARTNER;
}
}
ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message,
MessageQueueId_t* receivedFrom) {
ReturnValue_t status = this->receiveMessage(message);
*receivedFrom = this->lastPartner;
return status;
}
ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message) {
size_t size = 0;
rtems_status_code status = rtems_message_queue_receive(id,
message->getBuffer(),&size,
RTEMS_NO_WAIT, 1);
if (status == RTEMS_SUCCESSFUL) {
message->setMessageSize(size);
this->lastPartner = message->getSender();
//Check size of incoming message.
if (message->getMessageSize() < message->getMinimumMessageSize()) {
return HasReturnvaluesIF::RETURN_FAILED;
}
} else {
//No message was received. Keep lastPartner anyway, I might send something later.
//But still, delete packet content.
memset(message->getData(), 0, message->getMaximumDataSize());
}
return convertReturnCode(status);
}
MessageQueueId_t MessageQueue::getLastPartner() const {
return this->lastPartner;
}
ReturnValue_t MessageQueue::flush(uint32_t* count) {
rtems_status_code status = rtems_message_queue_flush(id, count);
return convertReturnCode(status);
}
MessageQueueId_t MessageQueue::getId() const {
return this->id;
}
void MessageQueue::setDefaultDestination(MessageQueueId_t defaultDestination) {
this->defaultDestination = defaultDestination;
}
ReturnValue_t MessageQueue::sendMessageFrom(MessageQueueId_t sendTo,
MessageQueueMessageIF* message, MessageQueueId_t sentFrom,
bool ignoreFault) {
message->setSender(sentFrom);
rtems_status_code result = rtems_message_queue_send(sendTo,
message->getBuffer(), message->getMessageSize());
//TODO: Check if we're in ISR.
if (result != RTEMS_SUCCESSFUL && !ignoreFault) {
if (internalErrorReporter == nullptr) {
internalErrorReporter = ObjectManager::instance()->get<InternalErrorReporterIF>(
objects::INTERNAL_ERROR_REPORTER);
}
if (internalErrorReporter != nullptr) {
internalErrorReporter->queueMessageNotSent();
}
}
ReturnValue_t returnCode = convertReturnCode(result);
if(result == MessageQueueIF::EMPTY){
return HasReturnvaluesIF::RETURN_FAILED;
}
return returnCode;
}
ReturnValue_t MessageQueue::sendToDefaultFrom(MessageQueueMessageIF* message,
MessageQueueId_t sentFrom, bool ignoreFault) {
return sendMessageFrom(defaultDestination, message, sentFrom, ignoreFault);
}
MessageQueueId_t MessageQueue::getDefaultDestination() const {
return this->defaultDestination;
}
bool MessageQueue::isDefaultDestinationSet() const {
return (defaultDestination != NO_QUEUE);
}
ReturnValue_t MessageQueue::convertReturnCode(rtems_status_code inValue){
switch(inValue){
case RTEMS_SUCCESSFUL:
return HasReturnvaluesIF::RETURN_OK;
case RTEMS_INVALID_ID:
return HasReturnvaluesIF::RETURN_FAILED;
case RTEMS_TIMEOUT:
return HasReturnvaluesIF::RETURN_FAILED;
case RTEMS_OBJECT_WAS_DELETED:
return HasReturnvaluesIF::RETURN_FAILED;
case RTEMS_INVALID_ADDRESS:
return HasReturnvaluesIF::RETURN_FAILED;
case RTEMS_INVALID_SIZE:
return HasReturnvaluesIF::RETURN_FAILED;
case RTEMS_TOO_MANY:
return MessageQueueIF::FULL;
case RTEMS_UNSATISFIED:
return MessageQueueIF::EMPTY;
default:
return HasReturnvaluesIF::RETURN_FAILED;
}
}
uint16_t MessageQueue::queueCounter = 0;

View File

@ -0,0 +1,172 @@
#ifndef FSFW_OSAL_RTEMS_MESSAGEQUEUE_H_
#define FSFW_OSAL_RTEMS_MESSAGEQUEUE_H_
#include "fsfw/internalerror/InternalErrorReporterIF.h"
#include "fsfw/ipc/MessageQueueIF.h"
#include "fsfw/ipc/MessageQueueMessage.h"
#include "RtemsBasic.h"
/**
* @brief This class manages sending and receiving of message queue messages.
*
* @details Message queues are used to pass asynchronous messages between processes.
* They work like post boxes, where all incoming messages are stored in FIFO
* order. This class creates a new receiving queue and provides methods to fetch
* received messages. Being a child of MessageQueueSender, this class also provides
* methods to send a message to a user-defined or a default destination. In addition
* it also provides a reply method to answer to the queue it received its last message
* from.
* The MessageQueue should be used as "post box" for a single owning object. So all
* message queue communication is "n-to-one".
* For creating the queue, as well as sending and receiving messages, the class makes
* use of the operating system calls provided.
* \ingroup message_queue
*/
class MessageQueue : public MessageQueueIF {
public:
/**
* @brief The constructor initializes and configures the message queue.
* @details By making use of the according operating system call, a message queue is created
* and initialized. The message depth - the maximum number of messages to be
* buffered - may be set with the help of a parameter, whereas the message size is
* automatically set to the maximum message queue message size. The operating system
* sets the message queue id, or i case of failure, it is set to zero.
* @param message_depth The number of messages to be buffered before passing an error to the
* sender. Default is three.
* @param max_message_size With this parameter, the maximum message size can be adjusted.
* This should be left default.
*/
MessageQueue( size_t message_depth = 3, size_t max_message_size = MessageQueueMessage::MAX_MESSAGE_SIZE );
/**
* @brief The destructor deletes the formerly created message queue.
* @details This is accomplished by using the delete call provided by the operating system.
*/
virtual ~MessageQueue();
/**
* @brief This operation sends a message to the given destination.
* @details It directly uses the sendMessage call of the MessageQueueSender parent, but passes its
* queue id as "sentFrom" parameter.
* @param sendTo This parameter specifies the message queue id of the destination message queue.
* @param message A pointer to a previously created message, which is sent.
* @param ignoreFault If set to true, the internal software fault counter is not incremented if queue is full.
*/
ReturnValue_t sendMessage(MessageQueueId_t sendTo,
MessageQueueMessageIF* message, bool ignoreFault = false );
/**
* @brief This operation sends a message to the default destination.
* @details As in the sendMessage method, this function uses the sendToDefault call of the
* MessageQueueSender parent class and adds its queue id as "sentFrom" information.
* @param message A pointer to a previously created message, which is sent.
*/
ReturnValue_t sendToDefault( MessageQueueMessageIF* message );
/**
* @brief This operation sends a message to the last communication partner.
* @details This operation simplifies answering an incoming message by using the stored
* lastParnter information as destination. If there was no message received yet
* (i.e. lastPartner is zero), an error code is returned.
* @param message A pointer to a previously created message, which is sent.
*/
ReturnValue_t reply( MessageQueueMessageIF* message );
/**
* @brief This function reads available messages from the message queue and returns the sender.
* @details It works identically to the other receiveMessage call, but in addition returns the
* sender's queue id.
* @param message A pointer to a message in which the received data is stored.
* @param receivedFrom A pointer to a queue id in which the sender's id is stored.
*/
ReturnValue_t receiveMessage(MessageQueueMessageIF* message,
MessageQueueId_t *receivedFrom);
/**
* @brief This function reads available messages from the message queue.
* @details If data is available it is stored in the passed message pointer. The message's
* original content is overwritten and the sendFrom information is stored in the
* lastPartner attribute. Else, the lastPartner information remains untouched, the
* message's content is cleared and the function returns immediately.
* @param message A pointer to a message in which the received data is stored.
*/
ReturnValue_t receiveMessage(MessageQueueMessageIF* message);
/**
* Deletes all pending messages in the queue.
* @param count The number of flushed messages.
* @return RETURN_OK on success.
*/
ReturnValue_t flush(uint32_t* count);
/**
* @brief This method returns the message queue id of the last communication partner.
*/
MessageQueueId_t getLastPartner() const;
/**
* @brief This method returns the message queue id of this class's message queue.
*/
MessageQueueId_t getId() const;
/**
* \brief With the sendMessage call, a queue message is sent to a receiving queue.
* \details This method takes the message provided, adds the sentFrom information and passes
* it on to the destination provided with an operating system call. The OS's return
* value is returned.
* \param sendTo This parameter specifies the message queue id to send the message to.
* \param message This is a pointer to a previously created message, which is sent.
* \param sentFrom The sentFrom information can be set to inject the sender's queue id into the message.
* This variable is set to zero by default.
* \param ignoreFault If set to true, the internal software fault counter is not incremented if queue is full.
*/
virtual ReturnValue_t sendMessageFrom( MessageQueueId_t sendTo, MessageQueueMessageIF* message, MessageQueueId_t sentFrom = NO_QUEUE, bool ignoreFault = false );
/**
* \brief The sendToDefault method sends a queue message to the default destination.
* \details In all other aspects, it works identical to the sendMessage method.
* \param message This is a pointer to a previously created message, which is sent.
* \param sentFrom The sentFrom information can be set to inject the sender's queue id into the message.
* This variable is set to zero by default.
*/
virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessageIF* message, MessageQueueId_t sentFrom = NO_QUEUE, bool ignoreFault = false );
/**
* \brief This method is a simple setter for the default destination.
*/
void setDefaultDestination(MessageQueueId_t defaultDestination);
/**
* \brief This method is a simple getter for the default destination.
*/
MessageQueueId_t getDefaultDestination() const;
bool isDefaultDestinationSet() const;
private:
/**
* @brief The class stores the queue id it got assigned from the operating system in this attribute.
* If initialization fails, the queue id is set to zero.
*/
MessageQueueId_t id;
/**
* @brief In this attribute, the queue id of the last communication partner is stored
* to allow for replying.
*/
MessageQueueId_t lastPartner;
/**
* @brief The message queue's name -a user specific information for the operating system- is
* generated automatically with the help of this static counter.
*/
/**
* \brief This attribute stores a default destination to send messages to.
* \details It is stored to simplify sending to always-the-same receiver. The attribute may
* be set in the constructor or by a setter call to setDefaultDestination.
*/
MessageQueueId_t defaultDestination;
/**
* \brief This attribute stores a reference to the internal error reporter for reporting full queues.
* \details In the event of a full destination queue, the reporter will be notified. The reference is set
* by lazy loading
*/
InternalErrorReporterIF *internalErrorReporter;
static uint16_t queueCounter;
/**
* A method to convert an OS-specific return code to the frameworks return value concept.
* @param inValue The return code coming from the OS.
* @return The converted return value.
*/
static ReturnValue_t convertReturnCode(rtems_status_code inValue);
};
#endif /* FSFW_OSAL_RTEMS_MESSAGEQUEUE_H_ */

View File

@ -0,0 +1,85 @@
#include "fsfw/osal/rtems/Mutex.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
uint8_t Mutex::count = 0;
Mutex::Mutex() {
rtems_name mutexName = ('M' << 24) + ('T' << 16) + ('X' << 8) + count++;
rtems_status_code status = rtems_semaphore_create(mutexName, 1,
RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY | RTEMS_INHERIT_PRIORITY, 0,
&mutexId);
if (status != RTEMS_SUCCESSFUL) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "Mutex::Mutex: Creation with name, id " << mutexName << ", " << mutexId <<
" failed with " << status << std::endl;
#else
sif::printError("Mutex::Mutex: Creation with name, id %s, %d failed with %d\n", mutexName,
static_cast<int>(mutexId), static_cast<int>(status));
#endif
}
}
Mutex::~Mutex() {
rtems_status_code status = rtems_semaphore_delete(mutexId);
if (status != RTEMS_SUCCESSFUL) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "Mutex: deletion for id " << mutexId
<< " failed with " << status << std::endl;
#endif
}
}
ReturnValue_t Mutex::lockMutex(TimeoutType timeoutType =
TimeoutType::BLOCKING, uint32_t timeoutMs) {
rtems_status_code status = RTEMS_INVALID_ID;
if(timeoutType == MutexIF::TimeoutType::BLOCKING) {
status = rtems_semaphore_obtain(mutexId,
RTEMS_WAIT, RTEMS_NO_TIMEOUT);
}
else if(timeoutType == MutexIF::TimeoutType::POLLING) {
timeoutMs = RTEMS_NO_TIMEOUT;
status = rtems_semaphore_obtain(mutexId,
RTEMS_NO_WAIT, 0);
}
else {
status = rtems_semaphore_obtain(mutexId,
RTEMS_WAIT, timeoutMs);
}
switch(status){
case RTEMS_SUCCESSFUL:
//semaphore obtained successfully
return HasReturnvaluesIF::RETURN_OK;
case RTEMS_UNSATISFIED:
//semaphore not available
return MUTEX_NOT_FOUND;
case RTEMS_TIMEOUT:
//timed out waiting for semaphore
return MUTEX_TIMEOUT;
case RTEMS_OBJECT_WAS_DELETED:
//semaphore deleted while waiting
return MUTEX_DESTROYED_WHILE_WAITING;
case RTEMS_INVALID_ID:
//invalid semaphore id
return MUTEX_INVALID_ID;
default:
return HasReturnvaluesIF::RETURN_FAILED;
}
}
ReturnValue_t Mutex::unlockMutex() {
rtems_status_code status = rtems_semaphore_release(mutexId);
switch(status){
case RTEMS_SUCCESSFUL:
//semaphore obtained successfully
return HasReturnvaluesIF::RETURN_OK;
case RTEMS_NOT_OWNER_OF_RESOURCE:
//semaphore not available
return CURR_THREAD_DOES_NOT_OWN_MUTEX;
case RTEMS_INVALID_ID:
//invalid semaphore id
return MUTEX_INVALID_ID;
default:
return HasReturnvaluesIF::RETURN_FAILED;
}
}

View File

@ -0,0 +1,18 @@
#ifndef FSFW_OSAL_RTEMS_MUTEX_H_
#define FSFW_OSAL_RTEMS_MUTEX_H_
#include "../../ipc/MutexIF.h"
#include "RtemsBasic.h"
class Mutex : public MutexIF {
public:
Mutex();
~Mutex();
ReturnValue_t lockMutex(TimeoutType timeoutType, uint32_t timeoutMs = 0);
ReturnValue_t unlockMutex();
private:
rtems_id mutexId = 0;
static uint8_t count;
};
#endif /* FSFW_OSAL_RTEMS_MUTEX_H_ */

View File

@ -0,0 +1,24 @@
#include "fsfw/osal/rtems/Mutex.h"
#include "fsfw/ipc/MutexFactory.h"
MutexFactory* MutexFactory::factoryInstance = new MutexFactory();
MutexFactory::MutexFactory() {
}
MutexFactory::~MutexFactory() {
}
MutexFactory* MutexFactory::instance() {
return MutexFactory::factoryInstance;
}
MutexIF* MutexFactory::createMutex() {
return new Mutex();
}
void MutexFactory::deleteMutex(MutexIF* mutex) {
delete mutex;
}

View File

@ -0,0 +1,84 @@
#include "fsfw/osal/rtems/PeriodicTask.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/objectmanager/ObjectManager.h"
#include "fsfw/tasks/ExecutableObjectIF.h"
PeriodicTask::PeriodicTask(const char *name, rtems_task_priority setPriority,
size_t setStack, rtems_interval setPeriod, void (*setDeadlineMissedFunc)()) :
RTEMSTaskBase(setPriority, setStack, name),
periodTicks(RtemsBasic::convertMsToTicks(setPeriod)),
deadlineMissedFunc(setDeadlineMissedFunc) {
}
PeriodicTask::~PeriodicTask(void) {
/* Do not delete objects, we were responsible for pointers only. */
rtems_rate_monotonic_delete(periodId);
}
rtems_task PeriodicTask::taskEntryPoint(rtems_task_argument argument) {
/* The argument is re-interpreted as MultiObjectTask. The Task object is global,
so it is found from any place. */
PeriodicTask *originalTask(reinterpret_cast<PeriodicTask*>(argument));
return originalTask->taskFunctionality();;
}
ReturnValue_t PeriodicTask::startTask() {
rtems_status_code status = rtems_task_start(id, PeriodicTask::taskEntryPoint,
rtems_task_argument((void *) this));
if (status != RTEMS_SUCCESSFUL) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "ObjectTask::startTask for " << std::hex << this->getId()
<< std::dec << " failed." << std::endl;
#endif
}
switch(status){
case RTEMS_SUCCESSFUL:
/* Task started successfully */
return HasReturnvaluesIF::RETURN_OK;
default:
/* RTEMS_INVALID_ADDRESS - invalid task entry point
RTEMS_INVALID_ID - invalid task id
RTEMS_INCORRECT_STATE - task not in the dormant state
RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task */
return HasReturnvaluesIF::RETURN_FAILED;
}
}
ReturnValue_t PeriodicTask::sleepFor(uint32_t ms) {
return RTEMSTaskBase::sleepFor(ms);
}
void PeriodicTask::taskFunctionality() {
RTEMSTaskBase::setAndStartPeriod(periodTicks,&periodId);
for (const auto& object: objectList) {
object->initializeAfterTaskCreation();
}
/* The task's "infinite" inner loop is entered. */
while (1) {
for (const auto& object: objectList) {
object->performOperation();
}
rtems_status_code status = RTEMSTaskBase::restartPeriod(periodTicks,periodId);
if (status == RTEMS_TIMEOUT) {
if (this->deadlineMissedFunc != nullptr) {
this->deadlineMissedFunc();
}
}
}
}
ReturnValue_t PeriodicTask::addComponent(object_id_t object) {
ExecutableObjectIF* newObject = ObjectManager::instance()->get<ExecutableObjectIF>(object);
if (newObject == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED;
}
objectList.push_back(newObject);
newObject->setTaskIF(this);
return HasReturnvaluesIF::RETURN_OK;
}
uint32_t PeriodicTask::getPeriodMs() const {
return RtemsBasic::convertTicksToMs(periodTicks);
}

View File

@ -0,0 +1,107 @@
#ifndef FSFW_OSAL_RTEMS_PERIODICTASK_H_
#define FSFW_OSAL_RTEMS_PERIODICTASK_H_
#include "RTEMSTaskBase.h"
#include "../../objectmanager/ObjectManagerIF.h"
#include "../../tasks/PeriodicTaskIF.h"
#include <vector>
class ExecutableObjectIF;
/**
* @brief This class represents a specialized task for periodic activities of multiple objects.
*
* @details MultiObjectTask is an extension to ObjectTask in the way that it is able to execute
* multiple objects that implement the ExecutableObjectIF interface. The objects must be
* added prior to starting the task.
* @author baetz
* @ingroup task_handling
*/
class PeriodicTask: public RTEMSTaskBase, public PeriodicTaskIF {
public:
/**
* @brief Standard constructor of the class.
* @details The class is initialized without allocated objects. These need to be added
* with #addObject.
* In the underlying TaskBase class, a new operating system task is created.
* In addition to the TaskBase parameters, the period, the pointer to the
* aforementioned initialization function and an optional "deadline-missed"
* function pointer is passed.
* @param priority Sets the priority of a task. Values range from a low 0 to a high 99.
* @param stack_size The stack size reserved by the operating system for the task.
* @param setPeriod The length of the period with which the task's functionality will be
* executed. It is expressed in clock ticks.
* @param setDeadlineMissedFunc The function pointer to the deadline missed function
* that shall be assigned.
*/
PeriodicTask(const char *name, rtems_task_priority setPriority, size_t setStack,
rtems_interval setPeriod, void (*setDeadlineMissedFunc)());
/**
* @brief Currently, the executed object's lifetime is not coupled with the task object's
* lifetime, so the destructor is empty.
*/
virtual ~PeriodicTask(void);
/**
* @brief The method to start the task.
* @details The method starts the task with the respective system call.
* Entry point is the taskEntryPoint method described below.
* The address of the task object is passed as an argument
* to the system call.
*/
ReturnValue_t startTask(void);
/**
* Adds an object to the list of objects to be executed.
* The objects are executed in the order added.
* @param object Id of the object to add.
* @return RETURN_OK on success, RETURN_FAILED if the object could not be added.
*/
ReturnValue_t addComponent(object_id_t object) override;
uint32_t getPeriodMs() const override;
ReturnValue_t sleepFor(uint32_t ms) override;
protected:
typedef std::vector<ExecutableObjectIF*> ObjectList; //!< Typedef for the List of objects.
/**
* @brief This attribute holds a list of objects to be executed.
*/
ObjectList objectList;
/**
* @brief The period of the task.
* @details The period determines the frequency of the task's execution. It is expressed in clock ticks.
*/
rtems_interval periodTicks;
/**
* @brief id of the associated OS period
*/
rtems_id periodId = 0;
/**
* @brief The pointer to the deadline-missed function.
* @details This pointer stores the function that is executed if the task's deadline is missed.
* So, each may react individually on a timing failure. The pointer may be nullptr,
* then nothing happens on missing the deadline. The deadline is equal to the next execution
* of the periodic task.
*/
void (*deadlineMissedFunc)(void);
/**
* @brief This is the function executed in the new task's context.
* @details It converts the argument back to the thread object type and copies the class instance
* to the task context. The taskFunctionality method is called afterwards.
* @param A pointer to the task object itself is passed as argument.
*/
static rtems_task taskEntryPoint(rtems_task_argument argument);
/**
* @brief The function containing the actual functionality of the task.
* @details The method sets and starts
* the task's period, then enters a loop that is repeated as long as the isRunning
* attribute is true. Within the loop, all performOperation methods of the added
* objects are called. Afterwards the checkAndRestartPeriod system call blocks the task
* until the next period.
* On missing the deadline, the deadlineMissedFunction is executed.
*/
void taskFunctionality(void);
};
#endif /* FSFW_OSAL_RTEMS_PERIODICTASK_H_ */

View File

@ -0,0 +1,61 @@
#include "fsfw/osal/rtems/MessageQueue.h"
#include "fsfw/osal/rtems/RtemsBasic.h"
#include "fsfw/ipc/QueueFactory.h"
#include "fsfw/ipc/MessageQueueSenderIF.h"
QueueFactory* QueueFactory::factoryInstance = nullptr;
ReturnValue_t MessageQueueSenderIF::sendMessage(MessageQueueId_t sendTo,
MessageQueueMessageIF* message, MessageQueueId_t sentFrom,bool ignoreFault) {
//TODO add ignoreFault functionality
message->setSender(sentFrom);
rtems_status_code result = rtems_message_queue_send(sendTo, message->getBuffer(),
message->getMessageSize());
switch(result){
case RTEMS_SUCCESSFUL:
//message sent successfully
return HasReturnvaluesIF::RETURN_OK;
case RTEMS_INVALID_ID:
//invalid queue id
return HasReturnvaluesIF::RETURN_FAILED;
case RTEMS_INVALID_SIZE:
// invalid message size
return HasReturnvaluesIF::RETURN_FAILED;
case RTEMS_INVALID_ADDRESS:
//buffer is NULL
return HasReturnvaluesIF::RETURN_FAILED;
case RTEMS_UNSATISFIED:
//out of message buffers
return HasReturnvaluesIF::RETURN_FAILED;
case RTEMS_TOO_MANY:
//queue's limit has been reached
return MessageQueueIF::FULL;
default:
return HasReturnvaluesIF::RETURN_FAILED;
}
}
QueueFactory* QueueFactory::instance() {
if (factoryInstance == nullptr) {
factoryInstance = new QueueFactory;
}
return factoryInstance;
}
QueueFactory::QueueFactory() {
}
QueueFactory::~QueueFactory() {
}
MessageQueueIF* QueueFactory::createMessageQueue(uint32_t messageDepth,
size_t maxMessageSize) {
return new MessageQueue(messageDepth, maxMessageSize);
}
void QueueFactory::deleteMessageQueue(MessageQueueIF* queue) {
delete queue;
}

View File

@ -0,0 +1,84 @@
#include "fsfw/osal/rtems/RTEMSTaskBase.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
const size_t PeriodicTaskIF::MINIMUM_STACK_SIZE = RTEMS_MINIMUM_STACK_SIZE;
RTEMSTaskBase::RTEMSTaskBase(rtems_task_priority set_priority, size_t stack_size,
const char *name) {
rtems_name osalName = 0;
for (uint8_t i = 0; i < 4; i++) {
if (name[i] == 0) {
break;
}
osalName += name[i] << (8 * (3 - i));
}
//The task is created with the operating system's system call.
rtems_status_code status = RTEMS_UNSATISFIED;
if (set_priority <= 99) {
status = rtems_task_create(osalName,
(0xFF - 2 * set_priority), stack_size,
RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_NO_ASR,
RTEMS_FLOATING_POINT, &id);
}
ReturnValue_t result = convertReturnCode(status);
if (result != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "TaskBase::TaskBase: createTask with name " << std::hex
<< osalName << std::dec << " failed with return code "
<< (uint32_t) status << std::endl;
#endif
this->id = 0;
}
}
RTEMSTaskBase::~RTEMSTaskBase() {
rtems_task_delete(id);
}
rtems_id RTEMSTaskBase::getId() {
return this->id;
}
ReturnValue_t RTEMSTaskBase::sleepFor(uint32_t ms) {
rtems_status_code status = rtems_task_wake_after(RtemsBasic::convertMsToTicks(ms));
return convertReturnCode(status);
}
ReturnValue_t RTEMSTaskBase::convertReturnCode(rtems_status_code inValue) {
switch (inValue) {
case RTEMS_SUCCESSFUL:
return HasReturnvaluesIF::RETURN_OK;
case RTEMS_MP_NOT_CONFIGURED:
return HasReturnvaluesIF::RETURN_FAILED;
case RTEMS_INVALID_NAME:
return HasReturnvaluesIF::RETURN_FAILED;
case RTEMS_TOO_MANY:
return HasReturnvaluesIF::RETURN_FAILED;
case RTEMS_INVALID_ADDRESS:
return HasReturnvaluesIF::RETURN_FAILED;
case RTEMS_UNSATISFIED:
return HasReturnvaluesIF::RETURN_FAILED;
case RTEMS_INVALID_PRIORITY:
return HasReturnvaluesIF::RETURN_FAILED;
default:
return HasReturnvaluesIF::RETURN_FAILED;
}
}
ReturnValue_t RTEMSTaskBase::setAndStartPeriod(rtems_interval period, rtems_id *periodId) {
rtems_name periodName = (('P' << 24) + ('e' << 16) + ('r' << 8) + 'd');
rtems_status_code status = rtems_rate_monotonic_create(periodName, periodId);
if (status == RTEMS_SUCCESSFUL) {
status = restartPeriod(period,*periodId);
}
return convertReturnCode(status);
}
rtems_status_code RTEMSTaskBase::restartPeriod(rtems_interval period, rtems_id periodId){
//This is necessary to avoid a call with period = 0, which does not start the period.
rtems_status_code status = rtems_rate_monotonic_period(periodId, period + 1);
return status;
}

View File

@ -0,0 +1,47 @@
#ifndef FSFW_OSAL_RTEMS_RTEMSTASKBASE_H_
#define FSFW_OSAL_RTEMS_RTEMSTASKBASE_H_
#include "RtemsBasic.h"
#include "../../tasks/PeriodicTaskIF.h"
/**
* @brief This is the basic task handling class for rtems.
*
* @details Task creation base class for rtems.
*/
class RTEMSTaskBase {
protected:
/**
* @brief The class stores the task id it got assigned from the operating system in this attribute.
* If initialization fails, the id is set to zero.
*/
rtems_id id;
public:
/**
* @brief The constructor creates and initializes a task.
* @details This is accomplished by using the operating system call to create a task. The name is
* created automatically with the help od taskCounter. Priority and stack size are
* adjustable, all other attributes are set with default values.
* @param priority Sets the priority of a task. Values range from a low 0 to a high 99.
* @param stack_size The stack size reserved by the operating system for the task.
* @param nam The name of the Task, as a null-terminated String. Currently max 4 chars supported (excluding Null-terminator), rest will be truncated
*/
RTEMSTaskBase( rtems_task_priority priority, size_t stack_size, const char *name);
/**
* @brief In the destructor, the created task is deleted.
*/
virtual ~RTEMSTaskBase();
/**
* @brief This method returns the task id of this class.
*/
rtems_id getId();
ReturnValue_t sleepFor(uint32_t ms);
static ReturnValue_t setAndStartPeriod(rtems_interval period, rtems_id *periodId);
static rtems_status_code restartPeriod(rtems_interval period, rtems_id periodId);
private:
static ReturnValue_t convertReturnCode(rtems_status_code inValue);
};
#endif /* FSFW_OSAL_RTEMS_RTEMSTASKBASE_H_ */

View File

@ -0,0 +1 @@
#include "fsfw/osal/rtems/RtemsBasic.h"

View File

@ -0,0 +1,26 @@
#ifndef FSFW_OSAL_RTEMS_RTEMSBASIC_H_
#define FSFW_OSAL_RTEMS_RTEMSBASIC_H_
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include <rtems.h>
#include <rtems/libio.h>
#include <rtems/error.h>
#include <rtems/stackchk.h>
#include <cstddef>
class RtemsBasic {
public:
static rtems_interval convertMsToTicks(uint32_t msIn) {
rtems_interval ticks_per_second = rtems_clock_get_ticks_per_second();
return (ticks_per_second * msIn) / 1000;
}
static rtems_interval convertTicksToMs(rtems_interval ticksIn) {
rtems_interval ticks_per_second = rtems_clock_get_ticks_per_second();
return (ticksIn * 1000) / ticks_per_second;
}
};
#endif /* FSFW_OSAL_RTEMS_RTEMSBASIC_H_ */

View File

@ -0,0 +1,34 @@
#include "fsfw/osal/rtems/BinarySemaphore.h"
//#include "fsfw/osal/rtems/CountingSemaphore.h"
#include "fsfw/tasks/SemaphoreFactory.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
SemaphoreFactory* SemaphoreFactory::factoryInstance = nullptr;
SemaphoreFactory::SemaphoreFactory() {
}
SemaphoreFactory::~SemaphoreFactory() {
delete factoryInstance;
}
SemaphoreFactory* SemaphoreFactory::instance() {
if (factoryInstance == nullptr){
factoryInstance = new SemaphoreFactory();
}
return SemaphoreFactory::factoryInstance;
}
SemaphoreIF* SemaphoreFactory::createBinarySemaphore(uint32_t argument) {
return new BinarySemaphore();
}
SemaphoreIF* SemaphoreFactory::createCountingSemaphore(uint8_t maxCount,
uint8_t initCount, uint32_t argument) {
return nullptr;
}
void SemaphoreFactory::deleteSemaphore(SemaphoreIF* semaphore) {
delete semaphore;
}

View File

@ -0,0 +1,53 @@
#include "fsfw/osal/rtems/FixedTimeslotTask.h"
#include "fsfw/osal/rtems/PeriodicTask.h"
#include "fsfw/osal/rtems/InitTask.h"
#include "fsfw/osal/rtems/RtemsBasic.h"
#include "fsfw/tasks/TaskFactory.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
//TODO: Different variant than the lazy loading in QueueFactory. What's better and why?
TaskFactory* TaskFactory::factoryInstance = new TaskFactory();
TaskFactory::~TaskFactory() {
}
TaskFactory* TaskFactory::instance() {
return TaskFactory::factoryInstance;
}
PeriodicTaskIF* TaskFactory::createPeriodicTask(TaskName name_, TaskPriority taskPriority_,
TaskStackSize stackSize_,TaskPeriod periodInSeconds_,
TaskDeadlineMissedFunction deadLineMissedFunction_) {
rtems_interval taskPeriod = periodInSeconds_ * Clock::getTicksPerSecond();
return static_cast<PeriodicTaskIF*>(new PeriodicTask(name_, taskPriority_, stackSize_,
taskPeriod,deadLineMissedFunction_));
}
FixedTimeslotTaskIF* TaskFactory::createFixedTimeslotTask(TaskName name_,
TaskPriority taskPriority_,TaskStackSize stackSize_,TaskPeriod periodInSeconds_,
TaskDeadlineMissedFunction deadLineMissedFunction_) {
rtems_interval taskPeriod = periodInSeconds_ * Clock::getTicksPerSecond();
return static_cast<FixedTimeslotTaskIF*>(new FixedTimeslotTask(name_, taskPriority_,
stackSize_, taskPeriod, deadLineMissedFunction_));
}
ReturnValue_t TaskFactory::deleteTask(PeriodicTaskIF* task) {
//TODO not implemented
return HasReturnvaluesIF::RETURN_FAILED;
}
ReturnValue_t TaskFactory::delayTask(uint32_t delayMs){
rtems_task_wake_after(RtemsBasic::convertMsToTicks(delayMs));
//Only return value is "RTEMS_SUCCESSFUL - always successful" so it has been neglected
return HasReturnvaluesIF::RETURN_OK;
}
void TaskFactory::printMissedDeadline() {
/* TODO: Implement */
return;
}
TaskFactory::TaskFactory() {
}