Merge pull request 'init after task creation moved to task functionality' (#178) from KSat/fsfw:mueller/TaskUpdates into master
Reviewed-on: fsfw/fsfw#178
This commit is contained in:
commit
4f5b233505
@ -64,6 +64,11 @@ ReturnValue_t PeriodicTask::sleepFor(uint32_t ms) {
|
|||||||
void PeriodicTask::taskFunctionality() {
|
void PeriodicTask::taskFunctionality() {
|
||||||
TickType_t xLastWakeTime;
|
TickType_t xLastWakeTime;
|
||||||
const TickType_t xPeriod = pdMS_TO_TICKS(this->period * 1000.);
|
const TickType_t xPeriod = pdMS_TO_TICKS(this->period * 1000.);
|
||||||
|
|
||||||
|
for (auto const &object: objectList) {
|
||||||
|
object->initializeAfterTaskCreation();
|
||||||
|
}
|
||||||
|
|
||||||
/* The xLastWakeTime variable needs to be initialized with the current tick
|
/* The xLastWakeTime variable needs to be initialized with the current tick
|
||||||
count. Note that this is the only time the variable is written to
|
count. Note that this is the only time the variable is written to
|
||||||
explicitly. After this assignment, xLastWakeTime is updated automatically
|
explicitly. After this assignment, xLastWakeTime is updated automatically
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
#ifndef FRAMEWORK_OSAL_FREERTOS_PERIODICTASK_H_
|
#ifndef FSFW_OSAL_FREERTOS_PERIODICTASK_H_
|
||||||
#define FRAMEWORK_OSAL_FREERTOS_PERIODICTASK_H_
|
#define FSFW_OSAL_FREERTOS_PERIODICTASK_H_
|
||||||
|
|
||||||
|
#include "FreeRTOSTaskIF.h"
|
||||||
#include "../../objectmanager/ObjectManagerIF.h"
|
#include "../../objectmanager/ObjectManagerIF.h"
|
||||||
#include "../../tasks/PeriodicTaskIF.h"
|
#include "../../tasks/PeriodicTaskIF.h"
|
||||||
#include "../../tasks/Typedef.h"
|
#include "../../tasks/Typedef.h"
|
||||||
#include "FreeRTOSTaskIF.h"
|
|
||||||
|
|
||||||
|
|
||||||
#include <freertos/FreeRTOS.h>
|
#include <freertos/FreeRTOS.h>
|
||||||
#include <freertos/task.h>
|
#include <freertos/task.h>
|
||||||
@ -24,7 +23,6 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Keep in Mind that you need to call before this vTaskStartScheduler()!
|
* Keep in Mind that you need to call before this vTaskStartScheduler()!
|
||||||
* A lot of task parameters are set in "FreeRTOSConfig.h".
|
* A lot of task parameters are set in "FreeRTOSConfig.h".
|
||||||
* TODO: why does this need to be called before vTaskStartScheduler?
|
|
||||||
* @details
|
* @details
|
||||||
* The class is initialized without allocated objects.
|
* The class is initialized without allocated objects.
|
||||||
* These need to be added with #addComponent.
|
* These need to be added with #addComponent.
|
||||||
@ -125,4 +123,4 @@ protected:
|
|||||||
void handleMissedDeadline();
|
void handleMissedDeadline();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* PERIODICTASK_H_ */
|
#endif /* FSFW_OSAL_FREERTOS_PERIODICTASK_H_ */
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
|
|
||||||
PeriodicPosixTask::PeriodicPosixTask(const char* name_, int priority_,
|
PeriodicPosixTask::PeriodicPosixTask(const char* name_, int priority_,
|
||||||
size_t stackSize_, uint32_t period_, void(deadlineMissedFunc_)()):
|
size_t stackSize_, uint32_t period_, void(deadlineMissedFunc_)()):
|
||||||
PosixThread(name_,priority_,stackSize_),objectList(),started(false),
|
PosixThread(name_, priority_, stackSize_), objectList(), started(false),
|
||||||
periodMs(period_),deadlineMissedFunc(deadlineMissedFunc_) {
|
periodMs(period_), deadlineMissedFunc(deadlineMissedFunc_) {
|
||||||
}
|
}
|
||||||
|
|
||||||
PeriodicPosixTask::~PeriodicPosixTask() {
|
PeriodicPosixTask::~PeriodicPosixTask() {
|
||||||
@ -25,6 +25,8 @@ ReturnValue_t PeriodicPosixTask::addComponent(object_id_t object) {
|
|||||||
ExecutableObjectIF* newObject = objectManager->get<ExecutableObjectIF>(
|
ExecutableObjectIF* newObject = objectManager->get<ExecutableObjectIF>(
|
||||||
object);
|
object);
|
||||||
if (newObject == nullptr) {
|
if (newObject == nullptr) {
|
||||||
|
sif::error << "PeriodicTask::addComponent: Invalid object. Make sure"
|
||||||
|
<< " it implements ExecutableObjectIF!" << std::endl;
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
objectList.push_back(newObject);
|
objectList.push_back(newObject);
|
||||||
@ -38,35 +40,41 @@ ReturnValue_t PeriodicPosixTask::sleepFor(uint32_t ms) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ReturnValue_t PeriodicPosixTask::startTask(void){
|
ReturnValue_t PeriodicPosixTask::startTask(void) {
|
||||||
started = true;
|
started = true;
|
||||||
//sif::info << stackSize << std::endl;
|
//sif::info << stackSize << std::endl;
|
||||||
PosixThread::createTask(&taskEntryPoint,this);
|
PosixThread::createTask(&taskEntryPoint,this);
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeriodicPosixTask::taskFunctionality(void){
|
void PeriodicPosixTask::taskFunctionality(void) {
|
||||||
if(!started){
|
if(not started) {
|
||||||
suspend();
|
suspend();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto const &object: objectList) {
|
||||||
|
object->initializeAfterTaskCreation();
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t lastWakeTime = getCurrentMonotonicTimeMs();
|
uint64_t lastWakeTime = getCurrentMonotonicTimeMs();
|
||||||
//The task's "infinite" inner loop is entered.
|
//The task's "infinite" inner loop is entered.
|
||||||
while (1) {
|
while (1) {
|
||||||
for (ObjectList::iterator it = objectList.begin();
|
for (auto const &object: objectList) {
|
||||||
it != objectList.end(); ++it) {
|
object->performOperation();
|
||||||
(*it)->performOperation();
|
|
||||||
}
|
}
|
||||||
if(!PosixThread::delayUntil(&lastWakeTime,periodMs)){
|
|
||||||
|
if(not PosixThread::delayUntil(&lastWakeTime, periodMs)){
|
||||||
char name[20] = {0};
|
char name[20] = {0};
|
||||||
int status = pthread_getname_np(pthread_self(),name,sizeof(name));
|
int status = pthread_getname_np(pthread_self(), name, sizeof(name));
|
||||||
if(status==0){
|
if(status == 0) {
|
||||||
sif::error << "PeriodicPosixTask " << name << ": Deadline "
|
sif::error << "PeriodicPosixTask " << name << ": Deadline "
|
||||||
"missed." << std::endl;
|
"missed." << std::endl;
|
||||||
}else{
|
}
|
||||||
|
else {
|
||||||
sif::error << "PeriodicPosixTask X: Deadline missed. " <<
|
sif::error << "PeriodicPosixTask X: Deadline missed. " <<
|
||||||
status << std::endl;
|
status << std::endl;
|
||||||
}
|
}
|
||||||
if (this->deadlineMissedFunc != NULL) {
|
if (this->deadlineMissedFunc != nullptr) {
|
||||||
this->deadlineMissedFunc();
|
this->deadlineMissedFunc();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ public:
|
|||||||
* The address of the task object is passed as an argument
|
* The address of the task object is passed as an argument
|
||||||
* to the system call.
|
* to the system call.
|
||||||
*/
|
*/
|
||||||
ReturnValue_t startTask(void);
|
ReturnValue_t startTask() override;
|
||||||
/**
|
/**
|
||||||
* Adds an object to the list of objects to be executed.
|
* Adds an object to the list of objects to be executed.
|
||||||
* The objects are executed in the order added.
|
* The objects are executed in the order added.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user