taken over host osal from upstream branch

This commit is contained in:
Robin Müller 2020-12-05 17:09:49 +01:00
parent c5c776e676
commit 248ceebf81
10 changed files with 36 additions and 56 deletions

View File

@ -106,11 +106,6 @@ ReturnValue_t Clock::getUptime(uint32_t* uptimeMs) {
return HasReturnvaluesIF::RETURN_OK;
}
uint32_t Clock::getUptimeSeconds() {
timeval uptime = getUptime();
return uptime.tv_sec;
}
ReturnValue_t Clock::getDateAndTime(TimeOfDay_t* time) {
// do some magic with chrono (C++20!)

View File

@ -1,7 +1,9 @@
#include "FixedTimeslotTask.h"
#include "Mutex.h"
#include "../../osal/host/FixedTimeslotTask.h"
#include "../../ipc/MutexFactory.h"
#include "../../osal/host/Mutex.h"
#include "../../osal/host/FixedTimeslotTask.h"
#include "../../serviceinterface/ServiceInterfaceStream.h"
#include "../../tasks/ExecutableObjectIF.h"
@ -33,18 +35,18 @@ FixedTimeslotTask::FixedTimeslotTask(const char *name, TaskPriority setPriority,
reinterpret_cast<HANDLE>(mainThread.native_handle()),
ABOVE_NORMAL_PRIORITY_CLASS);
if(result != 0) {
sif::error << "FixedTimeslotTask: Windows SetPriorityClass failed with "
<< "code " << GetLastError() << std::endl;
sif::error << "FixedTimeslotTask: Windows SetPriorityClass failed with code "
<< GetLastError() << std::endl;
}
result = SetThreadPriority(
reinterpret_cast<HANDLE>(mainThread.native_handle()),
THREAD_PRIORITY_NORMAL);
if(result != 0) {
sif::error << "FixedTimeslotTask: Windows SetPriorityClass failed with "
"code " << GetLastError() << std::endl;
sif::error << "FixedTimeslotTask: Windows SetPriorityClass failed with code "
<< GetLastError() << std::endl;
}
#elif defined(LINUX)
// we can just copy and paste the code from linux here.
// TODO: we can just copy and paste the code from the linux OSAL here.
#endif
}
@ -58,8 +60,7 @@ FixedTimeslotTask::~FixedTimeslotTask(void) {
}
void FixedTimeslotTask::taskEntryPoint(void* argument) {
FixedTimeslotTask *originalTask(
reinterpret_cast<FixedTimeslotTask*>(argument));
FixedTimeslotTask *originalTask(reinterpret_cast<FixedTimeslotTask*>(argument));
if (not originalTask->started) {
// we have to suspend/block here until the task is started.
@ -114,8 +115,9 @@ void FixedTimeslotTask::taskFunctionality() {
this->pollingSeqTable.executeAndAdvance();
if (not pollingSeqTable.slotFollowsImmediately()) {
// we need to wait before executing the current slot
//this gives us the time to wait:
interval = chron_ms(this->pollingSeqTable.getIntervalToPreviousSlotMs());
// this gives us the time to wait:
interval = chron_ms(
this->pollingSeqTable.getIntervalToPreviousSlotMs());
delayForInterval(&currentStartTime, interval);
//TODO deadline missed check
}

View File

@ -74,7 +74,7 @@ protected:
//!< Typedef for the List of objects.
typedef std::vector<ExecutableObjectIF*> ObjectList;
std::thread mainThread;
std::atomic<bool> terminateThread = false;
std::atomic<bool> terminateThread { false };
//! Polling sequence table which contains the object to execute
//! and information like the timeslots and the passed execution step.

View File

@ -34,7 +34,7 @@ ReturnValue_t MessageQueue::sendToDefaultFrom(MessageQueueMessageIF* message,
}
ReturnValue_t MessageQueue::reply(MessageQueueMessageIF* message) {
if (this->lastPartner != 0) {
if (this->lastPartner != MessageQueueIF::NO_QUEUE) {
return sendMessageFrom(this->lastPartner, message, this->getId());
} else {
return MessageQueueIF::NO_REPLY_PARTNER;
@ -106,6 +106,7 @@ bool MessageQueue::isDefaultDestinationSet() const {
ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
MessageQueueMessageIF* message, MessageQueueId_t sentFrom,
bool ignoreFault) {
message->setSender(sentFrom);
if(message->getMessageSize() > message->getMaximumMessageSize()) {
// Actually, this should never happen or an error will be emitted
// in MessageQueueMessage.
@ -126,7 +127,6 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
// TODO: Better returnvalue
return HasReturnvaluesIF::RETURN_FAILED;
}
if(targetQueue->messageQueue.size() < targetQueue->messageDepth) {
MutexHelper mutexLock(targetQueue->queueLock,
MutexIF::TimeoutType::WAITING, 20);
@ -145,7 +145,6 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
else {
return MessageQueueIF::FULL;
}
message->setSender(sentFrom);
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -4,21 +4,18 @@
Mutex::Mutex() {}
ReturnValue_t Mutex::lockMutex(TimeoutType timeoutType, uint32_t timeoutMs) {
if(timeoutMs == MutexIF::BLOCKING) {
if(timeoutType == MutexIF::BLOCKING) {
mutex.lock();
locked = true;
return HasReturnvaluesIF::RETURN_OK;
}
else if(timeoutMs == MutexIF::POLLING) {
else if(timeoutType == MutexIF::POLLING) {
if(mutex.try_lock()) {
locked = true;
return HasReturnvaluesIF::RETURN_OK;
}
}
else if(timeoutMs > MutexIF::POLLING){
auto chronoMs = std::chrono::milliseconds(timeoutMs);
if(mutex.try_lock_for(chronoMs)) {
locked = true;
return HasReturnvaluesIF::RETURN_OK;
}
}
@ -26,11 +23,7 @@ ReturnValue_t Mutex::lockMutex(TimeoutType timeoutType, uint32_t timeoutMs) {
}
ReturnValue_t Mutex::unlockMutex() {
if(not locked) {
return MutexIF::CURR_THREAD_DOES_NOT_OWN_MUTEX;
}
mutex.unlock();
locked = false;
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -1,5 +1,5 @@
#ifndef FSFW_OSAL_HOST_MUTEX_H_
#define FSFW_OSAL_HOST_MUTEX_H_
#ifndef FSFW_OSAL_HOSTED_MUTEX_H_
#define FSFW_OSAL_HOSTED_MUTEX_H_
#include "../../ipc/MutexIF.h"
@ -22,8 +22,8 @@ public:
std::timed_mutex* getMutexHandle();
private:
bool locked = false;
//bool locked = false;
std::timed_mutex mutex;
};
#endif /* FSFW_OSAL_HOST_MUTEX_H_ */
#endif /* FSFW_OSAL_HOSTED_MUTEX_H_ */

View File

@ -89,16 +89,16 @@ ReturnValue_t PeriodicTask::sleepFor(uint32_t ms) {
}
void PeriodicTask::taskFunctionality() {
for (const auto& object: objectList) {
object->initializeAfterTaskCreation();
}
std::chrono::milliseconds periodChrono(static_cast<uint32_t>(period*1000));
auto currentStartTime {
std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch())
};
auto nextStartTime{ currentStartTime };
for (const auto& object: objectList) {
object->initializeAfterTaskCreation();
}
auto nextStartTime { currentStartTime };
/* Enter the loop that defines the task behavior. */
for (;;) {
@ -109,10 +109,6 @@ void PeriodicTask::taskFunctionality() {
object->performOperation();
}
if(not delayForInterval(&currentStartTime, periodChrono)) {
#ifdef DEBUG
sif::warning << "PeriodicTask: " << taskName <<
" missed deadline!\n" << std::flush;
#endif
if(deadlineMissedFunc != nullptr) {
this->deadlineMissedFunc();
}
@ -126,7 +122,6 @@ ReturnValue_t PeriodicTask::addComponent(object_id_t object) {
if (newObject == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED;
}
newObject->setTaskIF(this);
objectList.push_back(newObject);
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -69,7 +69,7 @@ protected:
//!< Typedef for the List of objects.
typedef std::vector<ExecutableObjectIF*> ObjectList;
std::thread mainThread;
std::atomic<bool> terminateThread = false;
std::atomic<bool> terminateThread { false };
/**
* @brief This attribute holds a list of objects to be executed.

View File

@ -1,7 +1,11 @@
#include "MessageQueue.h"
#include "../../ipc/QueueFactory.h"
#include "../../ipc/MessageQueueSenderIF.h"
#include "../../ipc/MessageQueueMessageIF.h"
#include "../../ipc/QueueFactory.h"
#include "../../serviceinterface/ServiceInterfaceStream.h"
#include <cstring>
QueueFactory* QueueFactory::factoryInstance = nullptr;

View File

@ -44,17 +44,9 @@ MessageQueueIF* QueueMapManager::getMessageQueue(
return queueIter->second;
}
else {
if(messageQueueId == MessageQueueIF::NO_QUEUE) {
sif::error << "QueueMapManager::getQueueHandle: Configuration"
<< " error, NO_QUEUE was passed to this function!"
<< std::endl;
}
else {
sif::warning << "QueueMapManager::getQueueHandle: The ID "
<< messageQueueId << " does not exists in the map."
<< std::endl;
}
return nullptr;
sif::warning << "QueueMapManager::getQueueHandle: The ID " <<
messageQueueId << " does not exists in the map" << std::endl;
return nullptr;
}
}