eive-obsw/bsp_hosted/scheduling.cpp

281 lines
11 KiB
C++
Raw Permalink Normal View History

2022-11-15 17:08:10 +01:00
#include "linux/scheduling.h"
2020-12-29 14:37:39 +01:00
2022-06-17 08:31:36 +02:00
#include <bsp_hosted/fsfwconfig/pollingsequence/DummyPst.h>
2022-01-17 15:58:27 +01:00
#include <fsfw/objectmanager/ObjectManager.h>
2020-09-30 17:17:01 +02:00
#include <fsfw/objectmanager/ObjectManagerIF.h>
2022-08-24 17:27:47 +02:00
#include <fsfw/returnvalues/returnvalue.h>
2020-09-30 17:17:01 +02:00
#include <fsfw/serviceinterface/ServiceInterfaceStream.h>
#include <fsfw/tasks/FixedTimeslotTaskIF.h>
#include <fsfw/tasks/PeriodicTaskIF.h>
#include <fsfw/tasks/TaskFactory.h>
2021-03-04 18:29:28 +01:00
#include <mission/utility/InitMission.h>
2020-09-30 17:17:01 +02:00
2022-11-15 17:08:10 +01:00
#include <iostream>
2022-01-17 15:58:27 +01:00
2022-11-15 17:21:12 +01:00
#include "OBSWConfig.h"
2023-03-26 16:58:05 +02:00
#include "mission/scheduling.h"
2023-09-06 13:40:38 +02:00
#include "objectFactory.h"
2022-11-15 17:21:12 +01:00
#include "scheduling.h"
2020-09-30 21:07:30 +02:00
#ifdef LINUX
ServiceInterfaceStream sif::debug("DEBUG");
ServiceInterfaceStream sif::info("INFO");
ServiceInterfaceStream sif::warning("WARNING");
2020-09-30 17:17:01 +02:00
ServiceInterfaceStream sif::error("ERROR", false, false, true);
2020-09-30 21:07:30 +02:00
#else
ServiceInterfaceStream sif::debug("DEBUG", true);
ServiceInterfaceStream sif::info("INFO", true);
ServiceInterfaceStream sif::warning("WARNING", true);
ServiceInterfaceStream sif::error("ERROR", true, false, true);
#endif
2020-09-30 17:17:01 +02:00
2022-01-17 15:58:27 +01:00
ObjectManagerIF* objectManager = nullptr;
2020-09-30 17:17:01 +02:00
2022-11-15 17:03:46 +01:00
void scheduling::initMission() {
2022-01-17 15:58:27 +01:00
sif::info << "Building global objects.." << std::endl;
/* Instantiate global object manager and also create all objects */
ObjectManager::instance()->setObjectFactoryFunction(ObjectFactory::produce, nullptr);
sif::info << "Initializing all objects.." << std::endl;
ObjectManager::instance()->initialize();
/* This function creates and starts all tasks */
initTasks();
2020-09-30 17:17:01 +02:00
}
2022-11-15 17:03:46 +01:00
void scheduling::initTasks() {
2022-01-17 15:58:27 +01:00
TaskFactory* factory = TaskFactory::instance();
if (factory == nullptr) {
/* Should never happen ! */
return;
}
2021-03-04 18:29:28 +01:00
#if OBSW_PRINT_MISSED_DEADLINES == 1
2022-01-17 15:58:27 +01:00
void (*missedDeadlineFunc)(void) = TaskFactory::printMissedDeadline;
2021-03-04 18:29:28 +01:00
#else
2022-01-17 15:58:27 +01:00
void (*missedDeadlineFunc)(void) = nullptr;
2021-03-04 18:29:28 +01:00
#endif
2022-01-17 15:58:27 +01:00
/* TMTC Distribution */
2022-11-15 16:46:47 +01:00
PeriodicTaskIF* tmtcDistributor = factory->createPeriodicTask(
2023-02-10 14:02:27 +01:00
"DIST", 60, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.2, missedDeadlineFunc);
2022-11-15 16:46:47 +01:00
ReturnValue_t result = tmtcDistributor->addComponent(objects::CCSDS_PACKET_DISTRIBUTOR);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
sif::error << "Adding CCSDS distributor failed" << std::endl;
2022-01-17 15:58:27 +01:00
}
2022-11-15 16:46:47 +01:00
result = tmtcDistributor->addComponent(objects::PUS_PACKET_DISTRIBUTOR);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
sif::error << "Adding PUS distributor failed" << std::endl;
2023-02-10 14:02:27 +01:00
}
result = tmtcDistributor->addComponent(objects::CFDP_DISTRIBUTOR);
if (result != returnvalue::OK) {
sif::error << "Adding CFDP distributor failed" << std::endl;
2022-01-17 15:58:27 +01:00
}
2023-09-06 13:40:38 +02:00
#if OBSW_ADD_TMTC_UDP_SERVER == 1
2022-12-02 16:47:28 +01:00
result = tmtcDistributor->addComponent(objects::UDP_TMTC_SERVER);
if (result != returnvalue::OK) {
2023-02-10 14:02:27 +01:00
sif::error << "adding UDP server failed" << std::endl;
2022-12-02 16:47:28 +01:00
}
2023-09-06 13:40:38 +02:00
#endif
2022-12-02 16:47:28 +01:00
result = tmtcDistributor->addComponent(objects::TCP_TMTC_SERVER);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2023-02-10 14:02:27 +01:00
sif::error << "adding TCP server failed" << std::endl;
2022-01-17 15:58:27 +01:00
}
2022-11-15 16:46:47 +01:00
2023-09-06 13:40:38 +02:00
#if OBSW_ADD_TMTC_UDP_SERVER == 1
2022-12-02 16:47:28 +01:00
PeriodicTaskIF* udpPollingTask = factory->createPeriodicTask(
"UDP_POLLING", 70, PeriodicTaskIF::MINIMUM_STACK_SIZE, 2.0, missedDeadlineFunc);
result = udpPollingTask->addComponent(objects::UDP_TMTC_POLLING_TASK);
if (result != returnvalue::OK) {
sif::error << "Add component UDP Polling failed" << std::endl;
}
2023-09-06 13:40:38 +02:00
#endif
2022-12-02 16:47:28 +01:00
PeriodicTaskIF* tcpPollingTask = factory->createPeriodicTask(
"TCP_POLLING", 70, PeriodicTaskIF::MINIMUM_STACK_SIZE, 2.0, missedDeadlineFunc);
result = tcpPollingTask->addComponent(objects::TCP_TMTC_POLLING_TASK);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 15:58:27 +01:00
sif::error << "Add component UDP Polling failed" << std::endl;
}
2023-04-26 17:38:06 +02:00
PeriodicTaskIF* liveTmTask = factory->createPeriodicTask(
2023-09-06 13:40:38 +02:00
"LIVE_TM", 55, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.2, nullptr, &RR_SCHEDULING);
result = liveTmTask->addComponent(objects::LIVE_TM_TASK);
if (result != returnvalue::OK) {
scheduling::printAddObjectError("LIVE_TM", objects::LIVE_TM_TASK);
}
2022-01-17 15:58:27 +01:00
2023-02-20 16:10:35 +01:00
PeriodicTaskIF* pusHighPrio = factory->createPeriodicTask(
"PUS_HIGH_PRIO", 60, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.200, missedDeadlineFunc);
result = pusHighPrio->addComponent(objects::PUS_SERVICE_1_VERIFICATION);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 15:58:27 +01:00
sif::error << "Object add component failed" << std::endl;
}
2023-02-20 16:10:35 +01:00
result = pusHighPrio->addComponent(objects::EVENT_MANAGER);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2023-02-20 16:10:35 +01:00
scheduling::printAddObjectError("EVENT_MGMT", objects::EVENT_MANAGER);
}
2023-02-20 16:10:35 +01:00
result = pusHighPrio->addComponent(objects::PUS_SERVICE_5_EVENT_REPORTING);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-11-15 17:03:46 +01:00
scheduling::printAddObjectError("PUS5", objects::PUS_SERVICE_5_EVENT_REPORTING);
2022-01-17 15:58:27 +01:00
}
2023-02-20 16:10:35 +01:00
result = pusHighPrio->addComponent(objects::PUS_SERVICE_9_TIME_MGMT);
if (result != returnvalue::OK) {
scheduling::printAddObjectError("PUS9", objects::PUS_SERVICE_9_TIME_MGMT);
}
2022-01-17 15:58:27 +01:00
2023-02-20 16:10:35 +01:00
PeriodicTaskIF* pusMedPrio = factory->createPeriodicTask(
"PUS_MED_PRIO", 40, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.8, missedDeadlineFunc);
2022-01-17 15:58:27 +01:00
result = pusHighPrio->addComponent(objects::PUS_SERVICE_2_DEVICE_ACCESS);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-11-15 17:03:46 +01:00
scheduling::printAddObjectError("PUS2", objects::PUS_SERVICE_2_DEVICE_ACCESS);
2022-01-17 15:58:27 +01:00
}
result = pusHighPrio->addComponent(objects::PUS_SERVICE_3_HOUSEKEEPING);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-11-15 17:03:46 +01:00
scheduling::printAddObjectError("PUS3", objects::PUS_SERVICE_3_HOUSEKEEPING);
}
2022-01-17 15:58:27 +01:00
result = pusMedPrio->addComponent(objects::PUS_SERVICE_8_FUNCTION_MGMT);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-11-15 17:03:46 +01:00
scheduling::printAddObjectError("PUS8", objects::PUS_SERVICE_8_FUNCTION_MGMT);
2022-01-17 15:58:27 +01:00
}
2023-02-20 16:10:35 +01:00
result = pusMedPrio->addComponent(objects::PUS_SERVICE_15_TM_STORAGE);
if (result != returnvalue::OK) {
scheduling::printAddObjectError("PUS15", objects::PUS_SERVICE_15_TM_STORAGE);
}
2022-01-17 15:58:27 +01:00
result = pusMedPrio->addComponent(objects::PUS_SERVICE_200_MODE_MGMT);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-11-15 17:03:46 +01:00
scheduling::printAddObjectError("PUS200", objects::PUS_SERVICE_200_MODE_MGMT);
2022-01-17 15:58:27 +01:00
}
result = pusMedPrio->addComponent(objects::PUS_SERVICE_20_PARAMETERS);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-11-15 17:03:46 +01:00
scheduling::printAddObjectError("PUS20", objects::PUS_SERVICE_20_PARAMETERS);
2022-01-17 15:58:27 +01:00
}
2023-02-20 16:10:35 +01:00
result = pusMedPrio->addComponent(objects::PUS_SERVICE_17_TEST);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-11-15 17:03:46 +01:00
scheduling::printAddObjectError("PUS17", objects::PUS_SERVICE_17_TEST);
2022-01-17 15:58:27 +01:00
}
2022-06-13 08:58:06 +02:00
PeriodicTaskIF* thermalTask = factory->createPeriodicTask(
"THERMAL_CTL_TASK", 40, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.0, missedDeadlineFunc);
result = thermalTask->addComponent(objects::CORE_CONTROLLER);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
scheduling::printAddObjectError("CORE_CTRL", objects::CORE_CONTROLLER);
2022-06-17 08:31:36 +02:00
}
result = thermalTask->addComponent(objects::THERMAL_CONTROLLER);
if (result != returnvalue::OK) {
scheduling::printAddObjectError("THERMAL_CONTROLLER", objects::THERMAL_CONTROLLER);
}
2023-02-22 17:50:03 +01:00
result = thermalTask->addComponent(objects::HEATER_HANDLER);
if (result != returnvalue::OK) {
scheduling::printAddObjectError("HEATER_HANDLER", objects::HEATER_HANDLER);
}
FixedTimeslotTaskIF* pstTask = factory->createFixedTimeslotTask(
"DUMMY_PST", 75, PeriodicTaskIF::MINIMUM_STACK_SIZE * 4, 0.5, missedDeadlineFunc);
result = dummy_pst::pst(pstTask);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
sif::error << "Failed to add dummy pst to fixed timeslot task" << std::endl;
}
2023-02-10 14:02:27 +01:00
#if OBSW_ADD_CFDP_COMPONENTS == 1
PeriodicTaskIF* cfdpTask = factory->createPeriodicTask(
"CFDP Handler", 45, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.4, missedDeadlineFunc);
result = cfdpTask->addComponent(objects::CFDP_HANDLER);
if (result != returnvalue::OK) {
scheduling::printAddObjectError("CFDP Handler", objects::CFDP_HANDLER);
}
#endif
2023-09-06 13:40:38 +02:00
// If those are added at a later stage..
/*
PeriodicTaskIF* logTmTask = factory->createPeriodicTask(
"LOG_PSTORE", 0, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.0, nullptr);
result = logTmTask->addComponent(objects::LOG_STORE_AND_TM_TASK);
if (result != returnvalue::OK) {
scheduling::printAddObjectError("LOG_STORE_AND_TM", objects::LOG_STORE_AND_TM_TASK);
}
PeriodicTaskIF* hkTmTask =
factory->createPeriodicTask("HK_PSTORE", 0, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.0, nullptr);
result = hkTmTask->addComponent(objects::HK_STORE_AND_TM_TASK);
if (result != returnvalue::OK) {
scheduling::printAddObjectError("HK_STORE_AND_TM", objects::HK_STORE_AND_TM_TASK);
}
PeriodicTaskIF* cfdpTmTask = factory->createPeriodicTask(
"CFDP_PSTORE", 0, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.0, nullptr);
result = cfdpTmTask->addComponent(objects::CFDP_STORE_AND_TM_TASK);
if (result != returnvalue::OK) {
scheduling::printAddObjectError("CFDP_STORE_AND_TM", objects::CFDP_STORE_AND_TM_TASK);
}
*/
2022-11-15 16:59:33 +01:00
#if OBSW_ADD_PLOC_SUPERVISOR == 1
PeriodicTaskIF* supvHelperTask = factory->createPeriodicTask(
2022-11-15 17:42:53 +01:00
"PLOC_SUPV_HELPER", 20, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.0, missedDeadlineFunc);
2022-11-15 16:59:33 +01:00
result = supvHelperTask->addComponent(objects::PLOC_SUPERVISOR_HELPER);
if (result != returnvalue::OK) {
2022-11-15 17:03:46 +01:00
scheduling::printAddObjectError("PLOC_SUPV_HELPER", objects::PLOC_SUPERVISOR_HELPER);
2022-11-15 16:59:33 +01:00
}
#endif /* OBSW_ADD_PLOC_SUPERVISOR */
PeriodicTaskIF* plTask = factory->createPeriodicTask(
"PL_TASK", 25, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.0, missedDeadlineFunc);
2022-11-15 17:21:12 +01:00
scheduling::addMpsocSupvHandlers(plTask);
2020-11-20 18:10:39 +01:00
#if OBSW_ADD_TEST_CODE == 1
2022-01-17 15:58:27 +01:00
result = testTask->addComponent(objects::TEST_TASK);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-11-15 17:03:46 +01:00
scheduling::printAddObjectError("TEST_TASK", objects::TEST_TASK);
2022-01-17 15:58:27 +01:00
}
2021-03-04 18:29:28 +01:00
#endif /* OBSW_ADD_TEST_CODE == 1 */
2022-12-02 16:58:21 +01:00
PeriodicTaskIF* dummyTask = factory->createPeriodicTask(
"DUMMY_TASK", 35, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.8, missedDeadlineFunc);
dummyTask->addComponent(objects::THERMAL_TEMP_INSERTER);
2023-08-16 13:35:09 +02:00
scheduling::scheduleTmpTempSensors(dummyTask, true);
2022-12-02 18:08:49 +01:00
scheduling::scheduleRtdSensors(dummyTask);
2022-12-02 16:58:21 +01:00
dummyTask->addComponent(objects::SUS_0_N_LOC_XFYFZM_PT_XF);
dummyTask->addComponent(objects::SUS_1_N_LOC_XBYFZM_PT_XB);
dummyTask->addComponent(objects::SUS_2_N_LOC_XFYBZB_PT_YB);
dummyTask->addComponent(objects::SUS_3_N_LOC_XFYBZF_PT_YF);
dummyTask->addComponent(objects::SUS_4_N_LOC_XMYFZF_PT_ZF);
dummyTask->addComponent(objects::SUS_5_N_LOC_XFYMZB_PT_ZB);
dummyTask->addComponent(objects::SUS_6_R_LOC_XFYBZM_PT_XF);
dummyTask->addComponent(objects::SUS_7_R_LOC_XBYBZM_PT_XB);
dummyTask->addComponent(objects::SUS_8_R_LOC_XBYBZB_PT_YB);
dummyTask->addComponent(objects::SUS_9_R_LOC_XBYBZB_PT_YF);
dummyTask->addComponent(objects::SUS_10_N_LOC_XMYBZF_PT_ZF);
dummyTask->addComponent(objects::SUS_11_R_LOC_XBYMZB_PT_ZB);
2022-11-25 10:37:10 +01:00
2022-01-17 15:58:27 +01:00
sif::info << "Starting tasks.." << std::endl;
2022-11-15 16:46:47 +01:00
tmtcDistributor->startTask();
2023-09-06 13:40:38 +02:00
#if OBSW_ADD_TMTC_UDP_SERVER == 1
2022-12-02 16:47:28 +01:00
udpPollingTask->startTask();
2023-09-06 13:40:38 +02:00
#endif
2022-12-02 16:47:28 +01:00
tcpPollingTask->startTask();
liveTmTask->startTask();
2021-03-04 18:29:28 +01:00
2022-01-17 15:58:27 +01:00
pusHighPrio->startTask();
pusMedPrio->startTask();
2020-09-30 17:17:01 +02:00
pstTask->startTask();
2022-06-13 08:58:06 +02:00
thermalTask->startTask();
2022-12-02 16:58:21 +01:00
dummyTask->startTask();
2023-09-06 13:40:38 +02:00
// If those are added at a later stage..
// logTmTask->startTask();
// cfdpTmTask->startTask();
// hkTmTask->startTask();
2023-09-06 13:40:38 +02:00
2022-11-15 17:24:38 +01:00
#if OBSW_ADD_PLOC_SUPERVISOR == 1
supvHelperTask->startTask();
#endif
#if OBSW_ADD_PLOC_SUPERVISOR == 1 || OBSW_ADD_PLOC_MPSOC == 1
plTask->startTask();
#endif
2023-02-10 14:02:27 +01:00
#if OBSW_ADD_CFDP_COMPONENTS == 1
cfdpTask->startTask();
#endif
2020-11-20 18:10:39 +01:00
#if OBSW_ADD_TEST_CODE == 1
2022-01-17 15:58:27 +01:00
testTask->startTask();
2021-03-04 18:29:28 +01:00
#endif /* OBSW_ADD_TEST_CODE == 1 */
2022-01-17 15:58:27 +01:00
sif::info << "Tasks started.." << std::endl;
2020-09-30 17:17:01 +02:00
}