diff --git a/config/OBSWVersion.h b/config/OBSWVersion.h index ae16728..2445ff4 100644 --- a/config/OBSWVersion.h +++ b/config/OBSWVersion.h @@ -1,8 +1,8 @@ #ifndef COMMON_OBSWVERSION_H_ #define COMMON_OBSWVERSION_H_ -#define FSFW_EXAMPLE_VERSION 1 -#define FSFW_EXAMPLE_SUBVERSION 4 -#define FSFW_EXAMPLE_REVISION 0 +#define FSFW_EXAMPLE_VERSION 1 +#define FSFW_EXAMPLE_SUBVERSION 4 +#define FSFW_EXAMPLE_REVISION 0 #endif /* COMMON_OBSWVERSION_H_ */ diff --git a/config/commonClassIds.h b/config/commonClassIds.h index 6baae60..75b2cbd 100644 --- a/config/commonClassIds.h +++ b/config/commonClassIds.h @@ -4,10 +4,10 @@ #include "fsfw/returnvalues/FwClassIds.h" namespace CLASS_ID { -enum commonClassIds: uint8_t { - COMMON_CLASS_ID_START = FW_CLASS_ID_COUNT, - DUMMY_HANDLER, //DDH - COMMON_CLASS_ID_END // [EXPORT] : [END] +enum commonClassIds : uint8_t { + COMMON_CLASS_ID_START = FW_CLASS_ID_COUNT, + DUMMY_HANDLER, // DDH + COMMON_CLASS_ID_END // [EXPORT] : [END] }; } diff --git a/config/commonPollingSequenceFactory.cpp b/config/commonPollingSequenceFactory.cpp index 4aa772a..63050f8 100644 --- a/config/commonPollingSequenceFactory.cpp +++ b/config/commonPollingSequenceFactory.cpp @@ -1,83 +1,67 @@ -#include "pollingsequence/pollingSequenceFactory.h" -#include "objects/systemObjectList.h" - -#include "example/test/FsfwExampleTask.h" - #include #include #include +#include "example/test/FsfwExampleTask.h" +#include "objects/systemObjectList.h" +#include "pollingsequence/pollingSequenceFactory.h" ReturnValue_t pst::pollingSequenceExamples(FixedTimeslotTaskIF* thisSequence) { - uint32_t length = thisSequence->getPeriodMs(); + uint32_t length = thisSequence->getPeriodMs(); - thisSequence->addSlot(objects::TEST_DUMMY_1, length * 0, - FsfwExampleTask::OpCodes::SEND_RAND_NUM); - thisSequence->addSlot(objects::TEST_DUMMY_2, length * 0, - FsfwExampleTask::OpCodes::SEND_RAND_NUM); - thisSequence->addSlot(objects::TEST_DUMMY_3, length * 0, - FsfwExampleTask::OpCodes::SEND_RAND_NUM); + thisSequence->addSlot(objects::TEST_DUMMY_1, length * 0, FsfwExampleTask::OpCodes::SEND_RAND_NUM); + thisSequence->addSlot(objects::TEST_DUMMY_2, length * 0, FsfwExampleTask::OpCodes::SEND_RAND_NUM); + thisSequence->addSlot(objects::TEST_DUMMY_3, length * 0, FsfwExampleTask::OpCodes::SEND_RAND_NUM); - thisSequence->addSlot(objects::TEST_DUMMY_1, length * 0.2, - FsfwExampleTask::OpCodes::RECEIVE_RAND_NUM); - thisSequence->addSlot(objects::TEST_DUMMY_2, length * 0.2, - FsfwExampleTask::OpCodes::RECEIVE_RAND_NUM); - thisSequence->addSlot(objects::TEST_DUMMY_3, length * 0.2, - FsfwExampleTask::OpCodes::RECEIVE_RAND_NUM); + thisSequence->addSlot(objects::TEST_DUMMY_1, length * 0.2, + FsfwExampleTask::OpCodes::RECEIVE_RAND_NUM); + thisSequence->addSlot(objects::TEST_DUMMY_2, length * 0.2, + FsfwExampleTask::OpCodes::RECEIVE_RAND_NUM); + thisSequence->addSlot(objects::TEST_DUMMY_3, length * 0.2, + FsfwExampleTask::OpCodes::RECEIVE_RAND_NUM); - thisSequence->addSlot(objects::TEST_DUMMY_1, length * 0.5, - FsfwExampleTask::OpCodes::DELAY_SHORT); - thisSequence->addSlot(objects::TEST_DUMMY_2, length * 0.5, - FsfwExampleTask::OpCodes::DELAY_SHORT); - thisSequence->addSlot(objects::TEST_DUMMY_3, length * 0.5, - FsfwExampleTask::OpCodes::DELAY_SHORT); + thisSequence->addSlot(objects::TEST_DUMMY_1, length * 0.5, FsfwExampleTask::OpCodes::DELAY_SHORT); + thisSequence->addSlot(objects::TEST_DUMMY_2, length * 0.5, FsfwExampleTask::OpCodes::DELAY_SHORT); + thisSequence->addSlot(objects::TEST_DUMMY_3, length * 0.5, FsfwExampleTask::OpCodes::DELAY_SHORT); - if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) { - return HasReturnvaluesIF::RETURN_OK; - } - else { + if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) { + return HasReturnvaluesIF::RETURN_OK; + } else { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "pst::pollingSequenceInitFunction: Initialization errors!" << std::endl; + sif::error << "pst::pollingSequenceInitFunction: Initialization errors!" << std::endl; #else - sif::printError("pst::pollingSequenceInitFunction: Initialization errors!\n"); + sif::printError("pst::pollingSequenceInitFunction: Initialization errors!\n"); #endif - return HasReturnvaluesIF::RETURN_FAILED; - } + return HasReturnvaluesIF::RETURN_FAILED; + } } -ReturnValue_t pst::pollingSequenceDevices(FixedTimeslotTaskIF *thisSequence) { - uint32_t length = thisSequence->getPeriodMs(); +ReturnValue_t pst::pollingSequenceDevices(FixedTimeslotTaskIF* thisSequence) { + uint32_t length = thisSequence->getPeriodMs(); - thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_0, 0, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_1, 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_0, 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_1, 0, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_0, 0.3 * length, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_1, 0.3 * length, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_0, 0.3 * length, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_1, 0.3 * length, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_0, 0.45 * length, - DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_1, 0.45 * length, - DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_0, 0.45 * length, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_1, 0.45 * length, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_0, 0.6 * length, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_1, 0.6 * length, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_0, 0.6 * length, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_1, 0.6 * length, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_0, 0.8 * length, DeviceHandlerIF::GET_READ); - thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_1, 0.8 * length, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_0, 0.8 * length, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_1, 0.8 * length, DeviceHandlerIF::GET_READ); - if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) { - return HasReturnvaluesIF::RETURN_OK; - } - else { + if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) { + return HasReturnvaluesIF::RETURN_OK; + } else { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "pst::pollingSequenceTestFunction: Initialization errors!" << std::endl; + sif::error << "pst::pollingSequenceTestFunction: Initialization errors!" << std::endl; #else - sif::printError("pst::pollingSequenceTestFunction: Initialization errors!\n"); + sif::printError("pst::pollingSequenceTestFunction: Initialization errors!\n"); #endif - return HasReturnvaluesIF::RETURN_FAILED; - } + return HasReturnvaluesIF::RETURN_FAILED; + } } - - - - diff --git a/config/commonSubsystemIds.h b/config/commonSubsystemIds.h index 1c9d682..9d71b65 100644 --- a/config/commonSubsystemIds.h +++ b/config/commonSubsystemIds.h @@ -7,12 +7,11 @@ * The subsystem IDs will be part of the event IDs used throughout the FSFW. */ namespace SUBSYSTEM_ID { -enum commonSubsystemId: uint8_t { - COMMON_SUBSYSTEM_ID_START = FW_SUBSYSTEM_ID_RANGE, - TEST_TASK_ID = 105, - COMMON_SUBSYSTEM_ID_END +enum commonSubsystemId : uint8_t { + COMMON_SUBSYSTEM_ID_START = FW_SUBSYSTEM_ID_RANGE, + TEST_TASK_ID = 105, + COMMON_SUBSYSTEM_ID_END }; } - #endif /* COMMON_CONFIG_COMMONSUBSYSTEMIDS_H_ */ diff --git a/config/commonSystemObjects.h b/config/commonSystemObjects.h index 07cd239..dc76bac 100644 --- a/config/commonSystemObjects.h +++ b/config/commonSystemObjects.h @@ -1,40 +1,39 @@ #ifndef COMMON_COMMONSYSTEMOBJECTS_H_ #define COMMON_COMMONSYSTEMOBJECTS_H_ -#include #include +#include + namespace objects { -enum commonObjects: object_id_t { +enum commonObjects : object_id_t { - /* 0x41 ('A') for Assemblies */ - TEST_ASSEMBLY = 0x4100CAFE, + /* 0x41 ('A') for Assemblies */ + TEST_ASSEMBLY = 0x4100CAFE, - /* 0x43 ('C') for Controllers */ - TEST_CONTROLLER = 0x4301CAFE, + /* 0x43 ('C') for Controllers */ + TEST_CONTROLLER = 0x4301CAFE, - /* 0x44 ('D') for Device Handlers */ - TEST_DEVICE_HANDLER_0 = 0x4401AFFE, - TEST_DEVICE_HANDLER_1 = 0x4402AFFE, + /* 0x44 ('D') for Device Handlers */ + TEST_DEVICE_HANDLER_0 = 0x4401AFFE, + TEST_DEVICE_HANDLER_1 = 0x4402AFFE, - /* 0x49 ('I') for Communication Interfaces */ - TEST_ECHO_COM_IF = 0x4900AFFE, + /* 0x49 ('I') for Communication Interfaces */ + TEST_ECHO_COM_IF = 0x4900AFFE, - /* 0x63 ('C') for core objects */ - CCSDS_DISTRIBUTOR = 0x63000000, - PUS_DISTRIBUTOR = 0x63000001, - TM_FUNNEL = 0x63000002, + /* 0x63 ('C') for core objects */ + CCSDS_DISTRIBUTOR = 0x63000000, + PUS_DISTRIBUTOR = 0x63000001, + TM_FUNNEL = 0x63000002, - /* 0x74 ('t') for test and example objects */ - TEST_TASK = 0x7400CAFE, - TEST_DUMMY_1 = 0x74000001, - TEST_DUMMY_2 = 0x74000002, - TEST_DUMMY_3= 0x74000003, - TEST_DUMMY_4 = 0x74000004, - TEST_DUMMY_5 = 0x74000005, + /* 0x74 ('t') for test and example objects */ + TEST_TASK = 0x7400CAFE, + TEST_DUMMY_1 = 0x74000001, + TEST_DUMMY_2 = 0x74000002, + TEST_DUMMY_3 = 0x74000003, + TEST_DUMMY_4 = 0x74000004, + TEST_DUMMY_5 = 0x74000005, }; } - - #endif /* COMMON_COMMONSYSTEMOBJECTS_H_ */ diff --git a/example/controller/FsfwTestController.cpp b/example/controller/FsfwTestController.cpp index 0fde6e0..fd32d45 100644 --- a/example/controller/FsfwTestController.cpp +++ b/example/controller/FsfwTestController.cpp @@ -1,217 +1,220 @@ -#include #include "FsfwTestController.h" +#include + FsfwTestController::FsfwTestController(object_id_t objectId, object_id_t device0, - object_id_t device1, uint8_t verboseLevel): - TestController(objectId, objects::NO_OBJECT, 5), device0Id(device0), - device1Id(device1), deviceDataset0(device0), deviceDataset1(device1) { + object_id_t device1, uint8_t verboseLevel) + : TestController(objectId, objects::NO_OBJECT, 5), + device0Id(device0), + device1Id(device1), + deviceDataset0(device0), + deviceDataset1(device1) {} + +FsfwTestController::~FsfwTestController() {} + +ReturnValue_t FsfwTestController::handleCommandMessage(CommandMessage* message) { + return HasReturnvaluesIF::RETURN_OK; } -FsfwTestController::~FsfwTestController() { - -} - -ReturnValue_t FsfwTestController::handleCommandMessage(CommandMessage *message) { - return HasReturnvaluesIF::RETURN_OK; -} - -ReturnValue_t FsfwTestController::initializeLocalDataPool(localpool::DataPool &localDataPoolMap, - LocalDataPoolManager &poolManager) { - return HasReturnvaluesIF::RETURN_OK; +ReturnValue_t FsfwTestController::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, + LocalDataPoolManager& poolManager) { + return HasReturnvaluesIF::RETURN_OK; } void FsfwTestController::performControlOperation() { - // We will trace variables if we received an update notification or snapshots - if (verboseLevel >= 1) { - if(not traceVariable) { - return; - } - switch(currentTraceType) { - case(NONE): { - break; - } - case(TRACE_DEV_0_UINT8): { - if(traceCounter == 0) { - #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "Tracing finished" << std::endl; - #else - sif::printInfo("Tracing finished\n"); - #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ - traceVariable = false; - traceCounter = traceCycles; - currentTraceType = TraceTypes::NONE; - break; - } - PoolReadGuard readHelper(&deviceDataset0.testUint8Var); - #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "Tracing device 0 variable 0 (UINT8), current value: " << - static_cast(deviceDataset0.testUint8Var.value) << std::endl; - #else - sif::printInfo("Tracing device 0 variable 0 (UINT8), current value: %d\n", - deviceDataset0.testUint8Var.value); - #endif - traceCounter--; - break; - } - case(TRACE_DEV_0_VECTOR): { - break; - } - - } + // We will trace variables if we received an update notification or snapshots + if (verboseLevel >= 1) { + if (not traceVariable) { + return; } + switch (currentTraceType) { + case (NONE): { + break; + } + case (TRACE_DEV_0_UINT8): { + if (traceCounter == 0) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "Tracing finished" << std::endl; +#else + sif::printInfo("Tracing finished\n"); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ + traceVariable = false; + traceCounter = traceCycles; + currentTraceType = TraceTypes::NONE; + break; + } + PoolReadGuard readHelper(&deviceDataset0.testUint8Var); +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "Tracing device 0 variable 0 (UINT8), current value: " + << static_cast(deviceDataset0.testUint8Var.value) << std::endl; +#else + sif::printInfo("Tracing device 0 variable 0 (UINT8), current value: %d\n", + deviceDataset0.testUint8Var.value); +#endif + traceCounter--; + break; + } + case (TRACE_DEV_0_VECTOR): { + break; + } + } + } } ReturnValue_t FsfwTestController::initializeAfterTaskCreation() { - namespace td = testdevice; - ReturnValue_t result = TestController::initializeAfterTaskCreation(); - if(result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - HasLocalDataPoolIF* device0 = ObjectManager::instance()->get( - deviceDataset0.getCreatorObjectId()); - if(device0 == nullptr) { - #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "TestController::initializeAfterTaskCreation: Test device handler 0 " - "handle invalid!" << std::endl; - #else - sif::printWarning("TestController::initializeAfterTaskCreation: Test device handler 0 " - "handle invalid!"); - #endif - return ObjectManagerIF::CHILD_INIT_FAILED; - } - ProvidesDataPoolSubscriptionIF* subscriptionIF = device0->getSubscriptionInterface(); - if(subscriptionIF != nullptr) { - /* For DEVICE_0, we only subscribe for notifications */ - subscriptionIF->subscribeForSetUpdateMessage(td::TEST_SET_ID, getObjectId(), - getCommandQueue(), false); - subscriptionIF->subscribeForVariableUpdateMessage(td::PoolIds::TEST_UINT8_ID, - getObjectId(), getCommandQueue(), false); - } - - - HasLocalDataPoolIF* device1 = ObjectManager::instance()->get( - deviceDataset0.getCreatorObjectId()); - if(device1 == nullptr) { - #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "TestController::initializeAfterTaskCreation: Test device handler 1 " - "handle invalid!" << std::endl; - #else - sif::printWarning("TestController::initializeAfterTaskCreation: Test device handler 1 " - "handle invalid!"); - #endif - } - - subscriptionIF = device1->getSubscriptionInterface(); - if(subscriptionIF != nullptr) { - /* For DEVICE_1, we will subscribe for snapshots */ - subscriptionIF->subscribeForSetUpdateMessage(td::TEST_SET_ID, getObjectId(), - getCommandQueue(), true); - subscriptionIF->subscribeForVariableUpdateMessage(td::PoolIds::TEST_UINT8_ID, - getObjectId(), getCommandQueue(), true); - } + namespace td = testdevice; + ReturnValue_t result = TestController::initializeAfterTaskCreation(); + if (result != HasReturnvaluesIF::RETURN_OK) { return result; + } + HasLocalDataPoolIF* device0 = + ObjectManager::instance()->get(deviceDataset0.getCreatorObjectId()); + if (device0 == nullptr) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "TestController::initializeAfterTaskCreation: Test device handler 0 " + "handle invalid!" + << std::endl; +#else + sif::printWarning( + "TestController::initializeAfterTaskCreation: Test device handler 0 " + "handle invalid!"); +#endif + return ObjectManagerIF::CHILD_INIT_FAILED; + } + ProvidesDataPoolSubscriptionIF* subscriptionIF = device0->getSubscriptionInterface(); + if (subscriptionIF != nullptr) { + /* For DEVICE_0, we only subscribe for notifications */ + subscriptionIF->subscribeForSetUpdateMessage(td::TEST_SET_ID, getObjectId(), getCommandQueue(), + false); + subscriptionIF->subscribeForVariableUpdateMessage(td::PoolIds::TEST_UINT8_ID, getObjectId(), + getCommandQueue(), false); + } + + HasLocalDataPoolIF* device1 = + ObjectManager::instance()->get(deviceDataset0.getCreatorObjectId()); + if (device1 == nullptr) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "TestController::initializeAfterTaskCreation: Test device handler 1 " + "handle invalid!" + << std::endl; +#else + sif::printWarning( + "TestController::initializeAfterTaskCreation: Test device handler 1 " + "handle invalid!"); +#endif + } + + subscriptionIF = device1->getSubscriptionInterface(); + if (subscriptionIF != nullptr) { + /* For DEVICE_1, we will subscribe for snapshots */ + subscriptionIF->subscribeForSetUpdateMessage(td::TEST_SET_ID, getObjectId(), getCommandQueue(), + true); + subscriptionIF->subscribeForVariableUpdateMessage(td::PoolIds::TEST_UINT8_ID, getObjectId(), + getCommandQueue(), true); + } + return result; } -LocalPoolDataSetBase* FsfwTestController::getDataSetHandle(sid_t sid) { - - return nullptr; -} +LocalPoolDataSetBase* FsfwTestController::getDataSetHandle(sid_t sid) { return nullptr; } ReturnValue_t FsfwTestController::checkModeCommand(Mode_t mode, Submode_t submode, - uint32_t *msToReachTheMode) { - return HasReturnvaluesIF::RETURN_OK; + uint32_t* msToReachTheMode) { + return HasReturnvaluesIF::RETURN_OK; } void FsfwTestController::handleChangedDataset(sid_t sid, store_address_t storeId, - bool* clearMessage) { - using namespace std; + bool* clearMessage) { + using namespace std; - if (verboseLevel >= 1) { - char const* printout = nullptr; - if(storeId == storeId::INVALID_STORE_ADDRESS) { - printout = "Notification"; - } - else { - printout = "Snapshot"; - } + if (verboseLevel >= 1) { + char const* printout = nullptr; + if (storeId == storeId::INVALID_STORE_ADDRESS) { + printout = "Notification"; + } else { + printout = "Snapshot"; + } #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "FsfwTestController::handleChangedDataset: " << printout << " update" - "from object ID " << setw(8) << setfill('0') << hex << sid.objectId << - " and set ID " << sid.ownerSetId << dec << setfill(' ') << endl; + sif::info << "FsfwTestController::handleChangedDataset: " << printout + << " update" + "from object ID " + << setw(8) << setfill('0') << hex << sid.objectId << " and set ID " << sid.ownerSetId + << dec << setfill(' ') << endl; #else - sif::printInfo("FsfwTestController::handleChangedPoolVariable: %s update from" - "object ID 0x%08x and set ID %lu\n", printout, sid.objectId, sid.ownerSetId); + sif::printInfo( + "FsfwTestController::handleChangedPoolVariable: %s update from" + "object ID 0x%08x and set ID %lu\n", + printout, sid.objectId, sid.ownerSetId); #endif - if (storeId == storeId::INVALID_STORE_ADDRESS) { - if(sid.objectId == device0Id) { - PoolReadGuard readHelper(&deviceDataset0.testFloat3Vec); - float floatVec[3]; - floatVec[0] = deviceDataset0.testFloat3Vec.value[0]; - floatVec[1] = deviceDataset0.testFloat3Vec.value[1]; - floatVec[2] = deviceDataset0.testFloat3Vec.value[2]; + if (storeId == storeId::INVALID_STORE_ADDRESS) { + if (sid.objectId == device0Id) { + PoolReadGuard readHelper(&deviceDataset0.testFloat3Vec); + float floatVec[3]; + floatVec[0] = deviceDataset0.testFloat3Vec.value[0]; + floatVec[1] = deviceDataset0.testFloat3Vec.value[1]; + floatVec[2] = deviceDataset0.testFloat3Vec.value[2]; #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "Current float vector (3) values: [" << floatVec[0] << ", " << - floatVec[1] << ", " << floatVec[2] << "]" << std::endl; + sif::info << "Current float vector (3) values: [" << floatVec[0] << ", " << floatVec[1] + << ", " << floatVec[2] << "]" << std::endl; #else - sif::printInfo("Current float vector (3) values: [%f, %f, %f]\n", - floatVec[0], floatVec[1], floatVec[2]); + sif::printInfo("Current float vector (3) values: [%f, %f, %f]\n", floatVec[0], floatVec[1], + floatVec[2]); #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ - } - } + } } + } - /* We will trace the variables for snapshots and update notifications */ - if(not traceVariable) { - traceVariable = true; - traceCounter = traceCycles; - currentTraceType = TraceTypes::TRACE_DEV_0_VECTOR; - } + /* We will trace the variables for snapshots and update notifications */ + if (not traceVariable) { + traceVariable = true; + traceCounter = traceCycles; + currentTraceType = TraceTypes::TRACE_DEV_0_VECTOR; + } } void FsfwTestController::handleChangedPoolVariable(gp_id_t globPoolId, store_address_t storeId, - bool* clearMessage) { + bool* clearMessage) { + using namespace std; - using namespace std; - - if (verboseLevel >= 1) { - char const* printout = nullptr; - if (storeId == storeId::INVALID_STORE_ADDRESS) { - printout = "Notification"; - } - else { - printout = "Snapshot"; - } - -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "TestController::handleChangedPoolVariable: " << printout << " update from object " - "ID 0x" << setw(8) << setfill('0') << hex << globPoolId.objectId << - " and local pool ID " << globPoolId.localPoolId << dec << setfill(' ') << endl; -#else - sif::printInfo("TestController::handleChangedPoolVariable: %s update from object ID 0x%08x and " - "local pool ID %lu\n", printout, globPoolId.objectId, globPoolId.localPoolId); -#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ - - if (storeId == storeId::INVALID_STORE_ADDRESS) { - if(globPoolId.objectId == device0Id) { - PoolReadGuard readHelper(&deviceDataset0.testUint8Var); -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "Current test variable 0 (UINT8) value: " << static_cast( - deviceDataset0.testUint8Var.value) << std::endl; -#else - sif::printInfo("Current test variable 0 (UINT8) value %d\n", - deviceDataset0.testUint8Var.value); -#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ - } - } + if (verboseLevel >= 1) { + char const* printout = nullptr; + if (storeId == storeId::INVALID_STORE_ADDRESS) { + printout = "Notification"; + } else { + printout = "Snapshot"; } - /* We will trace the variables for snapshots and update notifications */ - if(not traceVariable) { - traceVariable = true; - traceCounter = traceCycles; - currentTraceType = TraceTypes::TRACE_DEV_0_UINT8; +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "TestController::handleChangedPoolVariable: " << printout + << " update from object " + "ID 0x" + << setw(8) << setfill('0') << hex << globPoolId.objectId << " and local pool ID " + << globPoolId.localPoolId << dec << setfill(' ') << endl; +#else + sif::printInfo( + "TestController::handleChangedPoolVariable: %s update from object ID 0x%08x and " + "local pool ID %lu\n", + printout, globPoolId.objectId, globPoolId.localPoolId); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ + + if (storeId == storeId::INVALID_STORE_ADDRESS) { + if (globPoolId.objectId == device0Id) { + PoolReadGuard readHelper(&deviceDataset0.testUint8Var); +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "Current test variable 0 (UINT8) value: " + << static_cast(deviceDataset0.testUint8Var.value) << std::endl; +#else + sif::printInfo("Current test variable 0 (UINT8) value %d\n", + deviceDataset0.testUint8Var.value); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ + } } + } + + /* We will trace the variables for snapshots and update notifications */ + if (not traceVariable) { + traceVariable = true; + traceCounter = traceCycles; + currentTraceType = TraceTypes::TRACE_DEV_0_UINT8; + } } - - diff --git a/example/controller/FsfwTestController.h b/example/controller/FsfwTestController.h index 3baa196..38c4d0b 100644 --- a/example/controller/FsfwTestController.h +++ b/example/controller/FsfwTestController.h @@ -4,50 +4,41 @@ #include "fsfw/controller/ExtendedControllerBase.h" #include "fsfw_tests/integration/controller/TestController.h" -class FsfwTestController: public TestController { -public: - FsfwTestController(object_id_t objectId, object_id_t device0, object_id_t device1, - uint8_t verboseLevel = 0); - virtual~ FsfwTestController(); - ReturnValue_t handleCommandMessage(CommandMessage *message) override; +class FsfwTestController : public TestController { + public: + FsfwTestController(object_id_t objectId, object_id_t device0, object_id_t device1, + uint8_t verboseLevel = 0); + virtual ~FsfwTestController(); + ReturnValue_t handleCommandMessage(CommandMessage* message) override; - /** - * Periodic helper from ControllerBase, implemented by child class. - */ - void performControlOperation() override; + /** + * Periodic helper from ControllerBase, implemented by child class. + */ + void performControlOperation() override; -private: + private: + object_id_t device0Id; + object_id_t device1Id; + testdevice::TestDataSet deviceDataset0; + testdevice::TestDataSet deviceDataset1; - object_id_t device0Id; - object_id_t device1Id; - testdevice::TestDataSet deviceDataset0; - testdevice::TestDataSet deviceDataset1; + uint8_t verboseLevel = 0; + bool traceVariable = false; + uint8_t traceCycles = 5; + uint8_t traceCounter = traceCycles; - uint8_t verboseLevel = 0; - bool traceVariable = false; - uint8_t traceCycles = 5; - uint8_t traceCounter = traceCycles; - - enum TraceTypes { - NONE, - TRACE_DEV_0_UINT8, - TRACE_DEV_0_VECTOR - }; - TraceTypes currentTraceType = TraceTypes::NONE; - - ReturnValue_t initializeAfterTaskCreation() override; - void handleChangedDataset(sid_t sid, store_address_t storeId, - bool* clearMessage) override; - void handleChangedPoolVariable(gp_id_t globPoolId, store_address_t storeId, - bool* clearMessage) override; - ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap, - LocalDataPoolManager& poolManager) override; - LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override; - ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode, - uint32_t *msToReachTheMode) override ; + enum TraceTypes { NONE, TRACE_DEV_0_UINT8, TRACE_DEV_0_VECTOR }; + TraceTypes currentTraceType = TraceTypes::NONE; + ReturnValue_t initializeAfterTaskCreation() override; + void handleChangedDataset(sid_t sid, store_address_t storeId, bool* clearMessage) override; + void handleChangedPoolVariable(gp_id_t globPoolId, store_address_t storeId, + bool* clearMessage) override; + ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap, + LocalDataPoolManager& poolManager) override; + LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override; + ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode, + uint32_t* msToReachTheMode) override; }; - - #endif /* EXAMPLE_COMMON_EXAMPLE_CONTROLLER_FSFWTESTCONTROLLER_H_ */ diff --git a/example/core/GenericFactory.cpp b/example/core/GenericFactory.cpp index e6f0ddc..168856e 100644 --- a/example/core/GenericFactory.cpp +++ b/example/core/GenericFactory.cpp @@ -1,22 +1,10 @@ #include "GenericFactory.h" #include "OBSWConfig.h" -#include "fsfw/FSFW.h" -#include "tmtc/apid.h" -#include "tmtc/pusIds.h" -#include "objects/systemObjectList.h" - -#include "example/utility/TmFunnel.h" #include "example/test/FsfwExampleTask.h" #include "example/test/FsfwReaderTask.h" - -#include "fsfw_tests/internal/InternalUnitTester.h" -#include "fsfw_tests/integration/assemblies/TestAssembly.h" -#include "fsfw_tests/integration/devices/TestCookie.h" -#include "fsfw_tests/integration/devices/TestDeviceHandler.h" -#include "fsfw_tests/integration/devices/TestEchoComIF.h" -#include "fsfw_tests/integration/controller/TestController.h" - +#include "example/utility/TmFunnel.h" +#include "fsfw/FSFW.h" #include "fsfw/devicehandlers/CookieIF.h" #include "fsfw/events/EventManager.h" #include "fsfw/health/HealthTable.h" @@ -34,126 +22,125 @@ #include "fsfw/tcdistribution/PUSDistributor.h" #include "fsfw/timemanager/TimeStamper.h" #include "fsfw/tmtcpacket/pus/tm.h" - - +#include "fsfw_tests/integration/assemblies/TestAssembly.h" +#include "fsfw_tests/integration/controller/TestController.h" +#include "fsfw_tests/integration/devices/TestCookie.h" +#include "fsfw_tests/integration/devices/TestDeviceHandler.h" +#include "fsfw_tests/integration/devices/TestEchoComIF.h" +#include "fsfw_tests/internal/InternalUnitTester.h" +#include "objects/systemObjectList.h" +#include "tmtc/apid.h" +#include "tmtc/pusIds.h" void ObjectFactory::produceGenericObjects() { #if OBSW_ADD_CORE_COMPONENTS == 1 - /* Framework objects */ - new EventManager(objects::EVENT_MANAGER); - new HealthTable(objects::HEALTH_TABLE); - new InternalErrorReporter(objects::INTERNAL_ERROR_REPORTER); - new TimeStamper(objects::TIME_STAMPER); - new CCSDSDistributor(apid::APID, objects::CCSDS_DISTRIBUTOR); - new PUSDistributor(apid::APID, objects::PUS_DISTRIBUTOR, - objects::CCSDS_DISTRIBUTOR); - new TmFunnel(objects::TM_FUNNEL); + /* Framework objects */ + new EventManager(objects::EVENT_MANAGER); + new HealthTable(objects::HEALTH_TABLE); + new InternalErrorReporter(objects::INTERNAL_ERROR_REPORTER); + new TimeStamper(objects::TIME_STAMPER); + new CCSDSDistributor(apid::APID, objects::CCSDS_DISTRIBUTOR); + new PUSDistributor(apid::APID, objects::PUS_DISTRIBUTOR, objects::CCSDS_DISTRIBUTOR); + new TmFunnel(objects::TM_FUNNEL); #endif /* OBSW_ADD_CORE_COMPONENTS == 1 */ - /* PUS stack */ + /* PUS stack */ #if OBSW_ADD_PUS_STACK == 1 - new Service1TelecommandVerification(objects::PUS_SERVICE_1_VERIFICATION, - apid::APID, pus::PUS_SERVICE_1, objects::TM_FUNNEL, 5); - new Service2DeviceAccess(objects::PUS_SERVICE_2_DEVICE_ACCESS, - apid::APID, pus::PUS_SERVICE_2, 3, 10); - new Service3Housekeeping(objects::PUS_SERVICE_3_HOUSEKEEPING, apid::APID, pus::PUS_SERVICE_3); - new Service5EventReporting(objects::PUS_SERVICE_5_EVENT_REPORTING, - apid::APID, pus::PUS_SERVICE_5, 50); - new Service8FunctionManagement(objects::PUS_SERVICE_8_FUNCTION_MGMT, - apid::APID, pus::PUS_SERVICE_8, 3, 10); - new Service9TimeManagement(objects::PUS_SERVICE_9_TIME_MGMT, apid::APID, - pus::PUS_SERVICE_9); - new Service17Test(objects::PUS_SERVICE_17_TEST, apid::APID, - pus::PUS_SERVICE_17); - new Service20ParameterManagement(objects::PUS_SERVICE_20_PARAMETERS, apid::APID, - pus::PUS_SERVICE_20); - new CService200ModeCommanding(objects::PUS_SERVICE_200_MODE_MGMT, - apid::APID, pus::PUS_SERVICE_200); + new Service1TelecommandVerification(objects::PUS_SERVICE_1_VERIFICATION, apid::APID, + pus::PUS_SERVICE_1, objects::TM_FUNNEL, 5); + new Service2DeviceAccess(objects::PUS_SERVICE_2_DEVICE_ACCESS, apid::APID, pus::PUS_SERVICE_2, 3, + 10); + new Service3Housekeeping(objects::PUS_SERVICE_3_HOUSEKEEPING, apid::APID, pus::PUS_SERVICE_3); + new Service5EventReporting(objects::PUS_SERVICE_5_EVENT_REPORTING, apid::APID, pus::PUS_SERVICE_5, + 50); + new Service8FunctionManagement(objects::PUS_SERVICE_8_FUNCTION_MGMT, apid::APID, + pus::PUS_SERVICE_8, 3, 10); + new Service9TimeManagement(objects::PUS_SERVICE_9_TIME_MGMT, apid::APID, pus::PUS_SERVICE_9); + new Service17Test(objects::PUS_SERVICE_17_TEST, apid::APID, pus::PUS_SERVICE_17); + new Service20ParameterManagement(objects::PUS_SERVICE_20_PARAMETERS, apid::APID, + pus::PUS_SERVICE_20); + new CService200ModeCommanding(objects::PUS_SERVICE_200_MODE_MGMT, apid::APID, + pus::PUS_SERVICE_200); #endif /* OBSW_ADD_PUS_STACK == 1 */ #if OBSW_ADD_TASK_EXAMPLE == 1 - /* Demo objects */ - new FsfwExampleTask(objects::TEST_DUMMY_1); - new FsfwExampleTask(objects::TEST_DUMMY_2); - new FsfwExampleTask(objects::TEST_DUMMY_3); + /* Demo objects */ + new FsfwExampleTask(objects::TEST_DUMMY_1); + new FsfwExampleTask(objects::TEST_DUMMY_2); + new FsfwExampleTask(objects::TEST_DUMMY_3); - - bool enablePrintout = false; + bool enablePrintout = false; #if OBSW_TASK_EXAMPLE_PRINTOUT == 1 - enablePrintout = true; + enablePrintout = true; #endif - new FsfwReaderTask(objects::TEST_DUMMY_4, enablePrintout); + new FsfwReaderTask(objects::TEST_DUMMY_4, enablePrintout); #endif /* OBSW_ADD_TASK_EXAMPLE == 1 */ #if OBSW_ADD_DEVICE_HANDLER_DEMO == 1 #if OBSW_DEVICE_HANDLER_PRINTOUT == 1 - bool enableInfoPrintout = true; + bool enableInfoPrintout = true; #else - bool enableInfoPrintout = false; + bool enableInfoPrintout = false; #endif /* OBSW_DEVICE_HANDLER_PRINTOUT == 1 */ - /* Demo device handler object */ - size_t expectedMaxReplyLen = 64; - CookieIF* testCookie = new TestCookie( - static_cast(testdevice::DeviceIndex::DEVICE_0), expectedMaxReplyLen); - new TestEchoComIF(objects::TEST_ECHO_COM_IF); - new TestDevice(objects::TEST_DEVICE_HANDLER_0, objects::TEST_ECHO_COM_IF, testCookie, - testdevice::DeviceIndex::DEVICE_0, enableInfoPrintout); - testCookie = new TestCookie(static_cast(testdevice::DeviceIndex::DEVICE_1), - expectedMaxReplyLen); - new TestDevice(objects::TEST_DEVICE_HANDLER_1, objects::TEST_ECHO_COM_IF, testCookie, - testdevice::DeviceIndex::DEVICE_1, enableInfoPrintout); + /* Demo device handler object */ + size_t expectedMaxReplyLen = 64; + CookieIF* testCookie = new TestCookie(static_cast(testdevice::DeviceIndex::DEVICE_0), + expectedMaxReplyLen); + new TestEchoComIF(objects::TEST_ECHO_COM_IF); + new TestDevice(objects::TEST_DEVICE_HANDLER_0, objects::TEST_ECHO_COM_IF, testCookie, + testdevice::DeviceIndex::DEVICE_0, enableInfoPrintout); + testCookie = new TestCookie(static_cast(testdevice::DeviceIndex::DEVICE_1), + expectedMaxReplyLen); + new TestDevice(objects::TEST_DEVICE_HANDLER_1, objects::TEST_ECHO_COM_IF, testCookie, + testdevice::DeviceIndex::DEVICE_1, enableInfoPrintout); - new TestAssembly(objects::TEST_ASSEMBLY, objects::NO_OBJECT, objects::TEST_DEVICE_HANDLER_0, - objects::TEST_DEVICE_HANDLER_1); + new TestAssembly(objects::TEST_ASSEMBLY, objects::NO_OBJECT, objects::TEST_DEVICE_HANDLER_0, + objects::TEST_DEVICE_HANDLER_1); #endif /* OBSW_ADD_DEVICE_HANDLER_DEMO == 1 */ - - /* Demo controller object */ + /* Demo controller object */ #if OBSW_ADD_CONTROLLER_DEMO == 1 #if OBSW_CONTROLLER_PRINTOUT == 1 #endif - new TestController(objects::TEST_CONTROLLER, objects::NO_OBJECT); + new TestController(objects::TEST_CONTROLLER, objects::NO_OBJECT); #endif /* OBSW_ADD_CONTROLLER_DEMO == 1 */ #if OBSW_PERFORM_INTERNAL_UNITTEST == 1 - InternalUnitTester::TestConfig testCfg; - testCfg.testArrayPrinter = false; + InternalUnitTester::TestConfig testCfg; + testCfg.testArrayPrinter = false; #if defined FSFW_OSAL_HOST - // Not implemented yet for hosted OSAL (requires C++20) - testCfg.testSemaphores = false; + // Not implemented yet for hosted OSAL (requires C++20) + testCfg.testSemaphores = false; #endif - InternalUnitTester unittester; - unittester.performTests(testCfg); + InternalUnitTester unittester; + unittester.performTests(testCfg); #endif /* OBSW_PERFORM_INTERNAL_UNITTEST == 1 */ } void Factory::setStaticFrameworkObjectIds() { - MonitoringReportContent::timeStamperId = objects::TIME_STAMPER; - MonitoringReportContent::timeStamperId = objects::TIME_STAMPER; - MonitoringReportContent::timeStamperId = objects::TIME_STAMPER; - MonitoringReportContent::timeStamperId = objects::TIME_STAMPER; - MonitoringReportContent::timeStamperId = objects::TIME_STAMPER; - MonitoringReportContent::timeStamperId = objects::TIME_STAMPER; + MonitoringReportContent::timeStamperId = objects::TIME_STAMPER; + MonitoringReportContent::timeStamperId = objects::TIME_STAMPER; + MonitoringReportContent::timeStamperId = objects::TIME_STAMPER; + MonitoringReportContent::timeStamperId = objects::TIME_STAMPER; + MonitoringReportContent::timeStamperId = objects::TIME_STAMPER; + MonitoringReportContent::timeStamperId = objects::TIME_STAMPER; - TmFunnel::downlinkDestination = objects::DOWNLINK_DESTINATION; - // No storage object for now. - TmFunnel::storageDestination = objects::NO_OBJECT; + TmFunnel::downlinkDestination = objects::DOWNLINK_DESTINATION; + // No storage object for now. + TmFunnel::storageDestination = objects::NO_OBJECT; - PusServiceBase::packetSource = objects::PUS_DISTRIBUTOR; - PusServiceBase::packetDestination = objects::TM_FUNNEL; + PusServiceBase::packetSource = objects::PUS_DISTRIBUTOR; + PusServiceBase::packetDestination = objects::TM_FUNNEL; - CommandingServiceBase::defaultPacketSource = objects::PUS_DISTRIBUTOR; - CommandingServiceBase::defaultPacketDestination = objects::TM_FUNNEL; + CommandingServiceBase::defaultPacketSource = objects::PUS_DISTRIBUTOR; + CommandingServiceBase::defaultPacketDestination = objects::TM_FUNNEL; - VerificationReporter::messageReceiver = objects::PUS_SERVICE_1_VERIFICATION; - - TmPacketBase::timeStamperId = objects::TIME_STAMPER; + VerificationReporter::messageReceiver = objects::PUS_SERVICE_1_VERIFICATION; + TmPacketBase::timeStamperId = objects::TIME_STAMPER; } - - diff --git a/example/core/GenericFactory.h b/example/core/GenericFactory.h index bddce53..3cf5d41 100644 --- a/example/core/GenericFactory.h +++ b/example/core/GenericFactory.h @@ -11,7 +11,6 @@ namespace ObjectFactory { */ void produceGenericObjects(); -} - +} // namespace ObjectFactory #endif /* MISSION_CORE_GENERICFACTORY_H_ */ diff --git a/example/devices/TestDeviceHandler.h b/example/devices/TestDeviceHandler.h index 38a8812..90d85d5 100644 --- a/example/devices/TestDeviceHandler.h +++ b/example/devices/TestDeviceHandler.h @@ -3,10 +3,8 @@ //#include "fsfw_tests/integration/TestDeviceHandler.h" // -//class FsfwTestDeviceHandler: public TestDeviceHandler { +// class FsfwTestDeviceHandler: public TestDeviceHandler { // //}; - - #endif /* EXAMPLE_COMMON_DEVICES_TESTDEVICEHANDLER_H_ */ diff --git a/example/test/FsfwExampleTask.cpp b/example/test/FsfwExampleTask.cpp index 7fe35ac..c478763 100644 --- a/example/test/FsfwExampleTask.cpp +++ b/example/test/FsfwExampleTask.cpp @@ -1,264 +1,238 @@ #include "FsfwExampleTask.h" + +#include +#include +#include +#include +#include + #include "OBSWConfig.h" #include "commonSystemObjects.h" #include "objects/systemObjectList.h" -#include -#include -#include -#include -#include - - -FsfwExampleTask::FsfwExampleTask(object_id_t objectId): SystemObject(objectId), - poolManager(this, nullptr), demoSet(this), - monitor(objectId, MONITOR_ID, gp_id_t(objectId, FsfwDemoSet::VARIABLE_LIMIT), 30, 10) -{ - commandQueue = QueueFactory::instance()->createMessageQueue(10, - CommandMessage::MAX_MESSAGE_SIZE); +FsfwExampleTask::FsfwExampleTask(object_id_t objectId) + : SystemObject(objectId), + poolManager(this, nullptr), + demoSet(this), + monitor(objectId, MONITOR_ID, gp_id_t(objectId, FsfwDemoSet::VARIABLE_LIMIT), 30, 10) { + commandQueue = QueueFactory::instance()->createMessageQueue(10, CommandMessage::MAX_MESSAGE_SIZE); } -FsfwExampleTask::~FsfwExampleTask() { -} +FsfwExampleTask::~FsfwExampleTask() {} ReturnValue_t FsfwExampleTask::performOperation(uint8_t operationCode) { - if(operationCode == OpCodes::DELAY_SHORT){ - TaskFactory::delayTask(5); + if (operationCode == OpCodes::DELAY_SHORT) { + TaskFactory::delayTask(5); + } + + // TODO: Move this to new test controller? + ReturnValue_t result = performMonitoringDemo(); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + + if (operationCode == OpCodes::SEND_RAND_NUM) { + result = performSendOperation(); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; } + } - // TODO: Move this to new test controller? - ReturnValue_t result = performMonitoringDemo(); - if(result != HasReturnvaluesIF::RETURN_OK) { - return result; - } + if (operationCode == OpCodes::RECEIVE_RAND_NUM) { + result = performReceiveOperation(); + } - if (operationCode == OpCodes::SEND_RAND_NUM) { - result = performSendOperation(); - if(result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - } - - - if (operationCode == OpCodes::RECEIVE_RAND_NUM) { - result = performReceiveOperation(); - - } - - return 0; + return 0; } object_id_t FsfwExampleTask::getNextRecipient() { - switch(this->getObjectId()) { - case(objects::TEST_DUMMY_1): { - return objects::TEST_DUMMY_2; + switch (this->getObjectId()) { + case (objects::TEST_DUMMY_1): { + return objects::TEST_DUMMY_2; } - case(objects::TEST_DUMMY_2): { - return objects::TEST_DUMMY_3; + case (objects::TEST_DUMMY_2): { + return objects::TEST_DUMMY_3; } - case(objects::TEST_DUMMY_3): { - return objects::TEST_DUMMY_1; + case (objects::TEST_DUMMY_3): { + return objects::TEST_DUMMY_1; } default: - return objects::TEST_DUMMY_1; - } + return objects::TEST_DUMMY_1; + } } object_id_t FsfwExampleTask::getSender() { - switch(this->getObjectId()) { - case(objects::TEST_DUMMY_1): { - return objects::TEST_DUMMY_3; + switch (this->getObjectId()) { + case (objects::TEST_DUMMY_1): { + return objects::TEST_DUMMY_3; } - case(objects::TEST_DUMMY_2): { - return objects::TEST_DUMMY_1; + case (objects::TEST_DUMMY_2): { + return objects::TEST_DUMMY_1; } - case(objects::TEST_DUMMY_3): { - return objects::TEST_DUMMY_2; + case (objects::TEST_DUMMY_3): { + return objects::TEST_DUMMY_2; } default: - return objects::TEST_DUMMY_1; - } + return objects::TEST_DUMMY_1; + } } - ReturnValue_t FsfwExampleTask::initialize() { - // Get the dataset of the sender. Will be cached for later checks. - object_id_t sender = getSender(); - HasLocalDataPoolIF* senderIF = ObjectManager::instance()->get(sender); - if(senderIF == nullptr) { + // Get the dataset of the sender. Will be cached for later checks. + object_id_t sender = getSender(); + HasLocalDataPoolIF* senderIF = ObjectManager::instance()->get(sender); + if (senderIF == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "FsfwDemoTask::initialize: Sender object invalid!" << std::endl; + sif::error << "FsfwDemoTask::initialize: Sender object invalid!" << std::endl; #else - sif::printError("FsfwDemoTask::initialize: Sender object invalid!\n"); + sif::printError("FsfwDemoTask::initialize: Sender object invalid!\n"); #endif - return HasReturnvaluesIF::RETURN_FAILED; - } + return HasReturnvaluesIF::RETURN_FAILED; + } - // we need a private copy of the previous dataset.. or we use the shared dataset. - senderSet = new FsfwDemoSet(senderIF); - if(senderSet == nullptr) { + // we need a private copy of the previous dataset.. or we use the shared dataset. + senderSet = new FsfwDemoSet(senderIF); + if (senderSet == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "FsfwDemoTask::initialize: Sender dataset invalid!" << std::endl; + sif::error << "FsfwDemoTask::initialize: Sender dataset invalid!" << std::endl; #else - sif::printError("FsfwDemoTask::initialize: Sender dataset invalid!\n"); + sif::printError("FsfwDemoTask::initialize: Sender dataset invalid!\n"); #endif - return HasReturnvaluesIF::RETURN_FAILED; - } - return poolManager.initialize(commandQueue); + return HasReturnvaluesIF::RETURN_FAILED; + } + return poolManager.initialize(commandQueue); } ReturnValue_t FsfwExampleTask::initializeAfterTaskCreation() { - return poolManager.initializeAfterTaskCreation(); + return poolManager.initializeAfterTaskCreation(); } -object_id_t FsfwExampleTask::getObjectId() const { - return SystemObject::getObjectId(); -} +object_id_t FsfwExampleTask::getObjectId() const { return SystemObject::getObjectId(); } -MessageQueueId_t FsfwExampleTask::getMessageQueueId(){ - return commandQueue->getId(); -} +MessageQueueId_t FsfwExampleTask::getMessageQueueId() { return commandQueue->getId(); } -void FsfwExampleTask::setTaskIF(PeriodicTaskIF* task){ - this->task = task; -} +void FsfwExampleTask::setTaskIF(PeriodicTaskIF* task) { this->task = task; } -LocalPoolDataSetBase* FsfwExampleTask::getDataSetHandle(sid_t sid) { - return &demoSet; -} +LocalPoolDataSetBase* FsfwExampleTask::getDataSetHandle(sid_t sid) { return &demoSet; } -uint32_t FsfwExampleTask::getPeriodicOperationFrequency() const { - return task->getPeriodMs(); -} +uint32_t FsfwExampleTask::getPeriodicOperationFrequency() const { return task->getPeriodMs(); } -ReturnValue_t FsfwExampleTask::initializeLocalDataPool( - localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) { - localDataPoolMap.emplace(FsfwDemoSet::PoolIds::VARIABLE, new PoolEntry({0})); - localDataPoolMap.emplace(FsfwDemoSet::PoolIds::VARIABLE_LIMIT, new PoolEntry({0})); - return HasReturnvaluesIF::RETURN_OK; +ReturnValue_t FsfwExampleTask::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, + LocalDataPoolManager& poolManager) { + localDataPoolMap.emplace(FsfwDemoSet::PoolIds::VARIABLE, new PoolEntry({0})); + localDataPoolMap.emplace(FsfwDemoSet::PoolIds::VARIABLE_LIMIT, new PoolEntry({0})); + return HasReturnvaluesIF::RETURN_OK; } ReturnValue_t FsfwExampleTask::performMonitoringDemo() { - ReturnValue_t result = demoSet.variableLimit.read( - MutexIF::TimeoutType::WAITING, 20); - if(result != HasReturnvaluesIF::RETURN_OK) { - /* Configuration error */ + ReturnValue_t result = demoSet.variableLimit.read(MutexIF::TimeoutType::WAITING, 20); + if (result != HasReturnvaluesIF::RETURN_OK) { + /* Configuration error */ #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "DummyObject::performOperation: Could not read variableLimit!" << std::endl; + sif::error << "DummyObject::performOperation: Could not read variableLimit!" << std::endl; #else - sif::printError("DummyObject::performOperation: Could not read variableLimit!\n"); + sif::printError("DummyObject::performOperation: Could not read variableLimit!\n"); #endif - return result; + return result; + } + if (this->getObjectId() == objects::TEST_DUMMY_5) { + if (demoSet.variableLimit.value > 20) { + demoSet.variableLimit.value = 0; } - if(this->getObjectId() == objects::TEST_DUMMY_5){ - if(demoSet.variableLimit.value > 20){ - demoSet.variableLimit.value = 0; - } - demoSet.variableLimit.value++; - demoSet.variableLimit.commit(20); - monitor.check(); - } - return HasReturnvaluesIF::RETURN_OK; + demoSet.variableLimit.value++; + demoSet.variableLimit.commit(20); + monitor.check(); + } + return HasReturnvaluesIF::RETURN_OK; } ReturnValue_t FsfwExampleTask::performSendOperation() { - object_id_t nextRecipient = getNextRecipient(); - FsfwExampleTask* target = ObjectManager::instance()->get(nextRecipient); - if (target == nullptr) { - /* Configuration error */ + object_id_t nextRecipient = getNextRecipient(); + FsfwExampleTask* target = ObjectManager::instance()->get(nextRecipient); + if (target == nullptr) { + /* Configuration error */ #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "DummyObject::performOperation: Next recipient does not exist!" << std::endl; + sif::error << "DummyObject::performOperation: Next recipient does not exist!" << std::endl; #else - sif::printError("DummyObject::performOperation: Next recipient does not exist!\n"); + sif::printError("DummyObject::performOperation: Next recipient does not exist!\n"); #endif - return HasReturnvaluesIF::RETURN_FAILED; - } + return HasReturnvaluesIF::RETURN_FAILED; + } + uint32_t randomNumber = rand() % 100; + CommandMessage message; + message.setParameter(randomNumber); + message.setParameter2(this->getMessageQueueId()); - uint32_t randomNumber = rand() % 100; - CommandMessage message; - message.setParameter(randomNumber); - message.setParameter2(this->getMessageQueueId()); - - /* Send message using own message queue */ - ReturnValue_t result = commandQueue->sendMessage(target->getMessageQueueId(), &message); - if (result != HasReturnvaluesIF::RETURN_OK - && result != MessageQueueIF::FULL) { + /* Send message using own message queue */ + ReturnValue_t result = commandQueue->sendMessage(target->getMessageQueueId(), &message); + if (result != HasReturnvaluesIF::RETURN_OK && result != MessageQueueIF::FULL) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "FsfwDemoTask::performSendOperation: Send failed with " << result << - std::endl; + sif::error << "FsfwDemoTask::performSendOperation: Send failed with " << result << std::endl; #else - sif::printError("FsfwDemoTask::performSendOperation: Send failed with %hu\n", result); + sif::printError("FsfwDemoTask::performSendOperation: Send failed with %hu\n", result); #endif - } + } - /* Send message without via MessageQueueSenderIF */ - result = MessageQueueSenderIF::sendMessage(target->getMessageQueueId(), &message, - commandQueue->getId()); - if (result != HasReturnvaluesIF::RETURN_OK - && result != MessageQueueIF::FULL) { + /* Send message without via MessageQueueSenderIF */ + result = MessageQueueSenderIF::sendMessage(target->getMessageQueueId(), &message, + commandQueue->getId()); + if (result != HasReturnvaluesIF::RETURN_OK && result != MessageQueueIF::FULL) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "FsfwDemoTask::performSendOperation: Send failed with " << result << std::endl; + sif::error << "FsfwDemoTask::performSendOperation: Send failed with " << result << std::endl; #else - sif::printError("FsfwDemoTask::performSendOperation: Send failed with %hu\n", result); + sif::printError("FsfwDemoTask::performSendOperation: Send failed with %hu\n", result); #endif - } + } - demoSet.variableWrite.value = randomNumber; - result = demoSet.variableWrite.commit(20); + demoSet.variableWrite.value = randomNumber; + result = demoSet.variableWrite.commit(20); - return result; + return result; } ReturnValue_t FsfwExampleTask::performReceiveOperation() { - ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; - while (result != MessageQueueIF::EMPTY) { - CommandMessage receivedMessage; - result = commandQueue->receiveMessage(&receivedMessage); - if (result != HasReturnvaluesIF::RETURN_OK - && result != MessageQueueIF::EMPTY) { + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + while (result != MessageQueueIF::EMPTY) { + CommandMessage receivedMessage; + result = commandQueue->receiveMessage(&receivedMessage); + if (result != HasReturnvaluesIF::RETURN_OK && result != MessageQueueIF::EMPTY) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::debug << "Receive failed with " << result << std::endl; + sif::debug << "Receive failed with " << result << std::endl; #endif - break; - } - if (result != MessageQueueIF::EMPTY) { + break; + } + if (result != MessageQueueIF::EMPTY) { #if FSFW_CPP_OSTREAM_ENABLED == 1 #if OBSW_VERBOSE_LEVEL >= 2 - sif::debug << "Message Received by " << getObjectId() << " from Queue " << - receivedMessage.getSender() << " ObjectId " << receivedMessage.getParameter() << - " Queue " << receivedMessage.getParameter2() << std::endl; + sif::debug << "Message Received by " << getObjectId() << " from Queue " + << receivedMessage.getSender() << " ObjectId " << receivedMessage.getParameter() + << " Queue " << receivedMessage.getParameter2() << std::endl; #endif #endif - if(senderSet == nullptr) { - return HasReturnvaluesIF::RETURN_FAILED; - } + if (senderSet == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } - result = senderSet->variableRead.read(MutexIF::TimeoutType::WAITING, - 20); - if(result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - if(senderSet->variableRead.value != receivedMessage.getParameter()) { + result = senderSet->variableRead.read(MutexIF::TimeoutType::WAITING, 20); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + if (senderSet->variableRead.value != receivedMessage.getParameter()) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "FsfwDemoTask::performReceiveOperation: Variable " << std::hex << - "0x" << senderSet->variableRead.getDataPoolId() << std::dec << - " has wrong value." << std::endl; - sif::error << "Value: " << demoSet.variableRead.value << ", expected: " << - receivedMessage.getParameter() << std::endl; + sif::error << "FsfwDemoTask::performReceiveOperation: Variable " << std::hex << "0x" + << senderSet->variableRead.getDataPoolId() << std::dec << " has wrong value." + << std::endl; + sif::error << "Value: " << demoSet.variableRead.value + << ", expected: " << receivedMessage.getParameter() << std::endl; #endif - } - - } + } } - return result; + } + return result; } -MessageQueueId_t FsfwExampleTask::getCommandQueue() const { - return commandQueue->getId(); -} +MessageQueueId_t FsfwExampleTask::getCommandQueue() const { return commandQueue->getId(); } -LocalDataPoolManager* FsfwExampleTask::getHkManagerHandle() { - return &poolManager; -} +LocalDataPoolManager* FsfwExampleTask::getHkManagerHandle() { return &poolManager; } diff --git a/example/test/FsfwExampleTask.h b/example/test/FsfwExampleTask.h index b68269e..9d2cb52 100644 --- a/example/test/FsfwExampleTask.h +++ b/example/test/FsfwExampleTask.h @@ -1,18 +1,17 @@ #ifndef MISSION_DEMO_FSFWDEMOTASK_H_ #define MISSION_DEMO_FSFWDEMOTASK_H_ -#include "testdefinitions/demoDefinitions.h" - -#include #include -#include -#include +#include #include #include +#include +#include + +#include "testdefinitions/demoDefinitions.h" class PeriodicTaskIF; - /** * @brief This demo set shows the local data pool functionality and fixed * timeslot capabilities of the FSFW. @@ -25,91 +24,82 @@ class PeriodicTaskIF; * value directly from the sender via the local data pool interface. * If the timing is set up correctly, the values will always be the same. */ -class FsfwExampleTask: - public ExecutableObjectIF, - public SystemObject, - public HasLocalDataPoolIF { -public: - enum OpCodes { - SEND_RAND_NUM, - RECEIVE_RAND_NUM, - DELAY_SHORT - }; +class FsfwExampleTask : public ExecutableObjectIF, public SystemObject, public HasLocalDataPoolIF { + public: + enum OpCodes { SEND_RAND_NUM, RECEIVE_RAND_NUM, DELAY_SHORT }; - static constexpr uint8_t MONITOR_ID = 2; + static constexpr uint8_t MONITOR_ID = 2; - /** - * @brief Simple constructor, only expects object ID. - * @param objectId - */ - FsfwExampleTask(object_id_t objectId); + /** + * @brief Simple constructor, only expects object ID. + * @param objectId + */ + FsfwExampleTask(object_id_t objectId); - virtual ~FsfwExampleTask(); + virtual ~FsfwExampleTask(); - /** - * @brief The performOperation method is executed in a task. - * @details There are no restrictions for calls within this method, so any - * other member of the class can be used. - * @return Currently, the return value is ignored. - */ - virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override; + /** + * @brief The performOperation method is executed in a task. + * @details There are no restrictions for calls within this method, so any + * other member of the class can be used. + * @return Currently, the return value is ignored. + */ + virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override; - /** - * @brief This function will be called by the global object manager - * @details - * This function will always be called before any tasks are started. - * It can also be used to return error codes in the software initialization - * process cleanly. - * @return - */ - virtual ReturnValue_t initialize() override; + /** + * @brief This function will be called by the global object manager + * @details + * This function will always be called before any tasks are started. + * It can also be used to return error codes in the software initialization + * process cleanly. + * @return + */ + virtual ReturnValue_t initialize() override; - /** - * @brief This function will be called by the OSAL task handlers - * @details - * This function will be called before the first #performOperation - * call after the tasks have been started. It can be used if some - * initialization process requires task specific properties like - * periodic intervals (by using the PeriodicTaskIF* handle). - * @return - */ - virtual ReturnValue_t initializeAfterTaskCreation() override; + /** + * @brief This function will be called by the OSAL task handlers + * @details + * This function will be called before the first #performOperation + * call after the tasks have been started. It can be used if some + * initialization process requires task specific properties like + * periodic intervals (by using the PeriodicTaskIF* handle). + * @return + */ + virtual ReturnValue_t initializeAfterTaskCreation() override; - /** - * This function will be called by the OSAL task handler. The - * task interface handle can be cached to access task specific properties. - * @param task - */ - void setTaskIF(PeriodicTaskIF* task) override; + /** + * This function will be called by the OSAL task handler. The + * task interface handle can be cached to access task specific properties. + * @param task + */ + void setTaskIF(PeriodicTaskIF* task) override; - object_id_t getObjectId() const override; + object_id_t getObjectId() const override; - MessageQueueId_t getMessageQueueId(); + MessageQueueId_t getMessageQueueId(); + private: + LocalDataPoolManager poolManager; + FsfwDemoSet* senderSet = nullptr; + FsfwDemoSet demoSet; + AbsLimitMonitor monitor; + PeriodicTaskIF* task = nullptr; + MessageQueueIF* commandQueue = nullptr; -private: - LocalDataPoolManager poolManager; - FsfwDemoSet* senderSet = nullptr; - FsfwDemoSet demoSet; - AbsLimitMonitor monitor; - PeriodicTaskIF* task = nullptr; - MessageQueueIF* commandQueue = nullptr; + /* HasLocalDatapoolIF overrides */ + MessageQueueId_t getCommandQueue() const override; + LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override; + uint32_t getPeriodicOperationFrequency() const override; + ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap, + LocalDataPoolManager& poolManager) override; + LocalDataPoolManager* getHkManagerHandle() override; - /* HasLocalDatapoolIF overrides */ - MessageQueueId_t getCommandQueue() const override; - LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override; - uint32_t getPeriodicOperationFrequency() const override; - ReturnValue_t initializeLocalDataPool( - localpool::DataPool& localDataPoolMap, - LocalDataPoolManager& poolManager) override; - LocalDataPoolManager* getHkManagerHandle() override; + object_id_t getNextRecipient(); + object_id_t getSender(); - object_id_t getNextRecipient(); - object_id_t getSender(); - - ReturnValue_t performMonitoringDemo(); - ReturnValue_t performSendOperation(); - ReturnValue_t performReceiveOperation(); + ReturnValue_t performMonitoringDemo(); + ReturnValue_t performSendOperation(); + ReturnValue_t performReceiveOperation(); }; #endif /* MISSION_DEMO_FSFWDEMOTASK_H_ */ diff --git a/example/test/FsfwReaderTask.cpp b/example/test/FsfwReaderTask.cpp index 9a19090..5c1440a 100644 --- a/example/test/FsfwReaderTask.cpp +++ b/example/test/FsfwReaderTask.cpp @@ -1,55 +1,54 @@ #include "FsfwReaderTask.h" +#include #include #include #include #include -#include - - -FsfwReaderTask::FsfwReaderTask(object_id_t objectId, bool enablePrintout): - SystemObject(objectId), printoutEnabled(enablePrintout), opDivider(10), - readSet(this->getObjectId(), - gp_id_t(objects::TEST_DUMMY_1, FsfwDemoSet::PoolIds::VARIABLE), - gp_id_t(objects::TEST_DUMMY_2, FsfwDemoSet::PoolIds::VARIABLE), - gp_id_t(objects::TEST_DUMMY_3, FsfwDemoSet::PoolIds::VARIABLE)) { - /* Special protection for set reading because each variable is read from a different pool */ - readSet.setReadCommitProtectionBehaviour(true); +FsfwReaderTask::FsfwReaderTask(object_id_t objectId, bool enablePrintout) + : SystemObject(objectId), + printoutEnabled(enablePrintout), + opDivider(10), + readSet(this->getObjectId(), gp_id_t(objects::TEST_DUMMY_1, FsfwDemoSet::PoolIds::VARIABLE), + gp_id_t(objects::TEST_DUMMY_2, FsfwDemoSet::PoolIds::VARIABLE), + gp_id_t(objects::TEST_DUMMY_3, FsfwDemoSet::PoolIds::VARIABLE)) { + /* Special protection for set reading because each variable is read from a different pool */ + readSet.setReadCommitProtectionBehaviour(true); } -FsfwReaderTask::~FsfwReaderTask() { -} +FsfwReaderTask::~FsfwReaderTask() {} ReturnValue_t FsfwReaderTask::initializeAfterTaskCreation() { - /* Give other task some time to set up local data pools. */ - TaskFactory::delayTask(20); - return HasReturnvaluesIF::RETURN_OK; + /* Give other task some time to set up local data pools. */ + TaskFactory::delayTask(20); + return HasReturnvaluesIF::RETURN_OK; } ReturnValue_t FsfwReaderTask::performOperation(uint8_t operationCode) { - PoolReadGuard readHelper(&readSet); + PoolReadGuard readHelper(&readSet); - uint32_t variable1 = readSet.variable1.value; - uint32_t variable2 = readSet.variable2.value; - uint32_t variable3 = readSet.variable3.value; + uint32_t variable1 = readSet.variable1.value; + uint32_t variable2 = readSet.variable2.value; + uint32_t variable3 = readSet.variable3.value; #if OBSW_VERBOSE_LEVEL >= 1 - if(opDivider.checkAndIncrement() and printoutEnabled) { + if (opDivider.checkAndIncrement() and printoutEnabled) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "FsfwPeriodicTask::performOperation: Reading variables." << std::endl; - sif::info << "Variable read from demo object 1: " << variable1 << std::endl; - sif::info << "Variable read from demo object 2: " << variable2 << std::endl; - sif::info << "Variable read from demo object 3: " << variable3 << std::endl; + sif::info << "FsfwPeriodicTask::performOperation: Reading variables." << std::endl; + sif::info << "Variable read from demo object 1: " << variable1 << std::endl; + sif::info << "Variable read from demo object 2: " << variable2 << std::endl; + sif::info << "Variable read from demo object 3: " << variable3 << std::endl; #else - sif::printInfo("FsfwPeriodicTask::performOperation: Reading variables.\n\r"); - sif::printInfo("Variable read from demo object 1: %d\n\r", variable1); - sif::printInfo("Variable read from demo object 2: %d\n\r", variable2); - sif::printInfo("Variable read from demo object 3: %d\n\r", variable3); + sif::printInfo("FsfwPeriodicTask::performOperation: Reading variables.\n\r"); + sif::printInfo("Variable read from demo object 1: %d\n\r", variable1); + sif::printInfo("Variable read from demo object 2: %d\n\r", variable2); + sif::printInfo("Variable read from demo object 3: %d\n\r", variable3); #endif - } + } #else - if(variable1 and variable2 and variable3) {}; + if (variable1 and variable2 and variable3) { + }; #endif - return HasReturnvaluesIF::RETURN_OK; + return HasReturnvaluesIF::RETURN_OK; } diff --git a/example/test/FsfwReaderTask.h b/example/test/FsfwReaderTask.h index 216a82f..419435e 100644 --- a/example/test/FsfwReaderTask.h +++ b/example/test/FsfwReaderTask.h @@ -1,24 +1,24 @@ #ifndef MISSION_DEMO_FSFWPERIODICTASK_H_ #define MISSION_DEMO_FSFWPERIODICTASK_H_ +#include +#include +#include + #include "testdefinitions/demoDefinitions.h" -#include -#include -#include +class FsfwReaderTask : public ExecutableObjectIF, public SystemObject { + public: + FsfwReaderTask(object_id_t objectId, bool enablePrintout); + ~FsfwReaderTask() override; -class FsfwReaderTask: public ExecutableObjectIF, public SystemObject { -public: - FsfwReaderTask(object_id_t objectId, bool enablePrintout); - ~FsfwReaderTask() override; + ReturnValue_t initializeAfterTaskCreation() override; + ReturnValue_t performOperation(uint8_t operationCode = 0) override; - ReturnValue_t initializeAfterTaskCreation() override; - ReturnValue_t performOperation(uint8_t operationCode = 0) override; - -private: - bool printoutEnabled = false; - PeriodicOperationDivider opDivider; - CompleteDemoReadSet readSet; + private: + bool printoutEnabled = false; + PeriodicOperationDivider opDivider; + CompleteDemoReadSet readSet; }; #endif /* MISSION_DEMO_FSFWPERIODICTASK_H_ */ diff --git a/example/test/FsfwTestTask.cpp b/example/test/FsfwTestTask.cpp index 0375c02..355ef50 100644 --- a/example/test/FsfwTestTask.cpp +++ b/example/test/FsfwTestTask.cpp @@ -1,12 +1,11 @@ #include "FsfwTestTask.h" -FsfwTestTask::FsfwTestTask(object_id_t objectId, bool periodicEvent): - TestTask(objectId), periodicEvent(periodicEvent) { -} +FsfwTestTask::FsfwTestTask(object_id_t objectId, bool periodicEvent) + : TestTask(objectId), periodicEvent(periodicEvent) {} ReturnValue_t FsfwTestTask::performPeriodicAction() { - if(periodicEvent) { - triggerEvent(TEST_EVENT, 0x1234, 0x4321); - } - return HasReturnvaluesIF::RETURN_OK; + if (periodicEvent) { + triggerEvent(TEST_EVENT, 0x1234, 0x4321); + } + return HasReturnvaluesIF::RETURN_OK; } diff --git a/example/test/FsfwTestTask.h b/example/test/FsfwTestTask.h index 080ff7d..285add9 100644 --- a/example/test/FsfwTestTask.h +++ b/example/test/FsfwTestTask.h @@ -1,21 +1,20 @@ #ifndef EXAMPLE_COMMON_EXAMPLE_TEST_FSFWTESTTASK_H_ #define EXAMPLE_COMMON_EXAMPLE_TEST_FSFWTESTTASK_H_ +#include "events/subsystemIdRanges.h" +#include "fsfw/events/Event.h" #include "fsfw_tests/integration/task/TestTask.h" -#include "fsfw/events/Event.h" -#include "events/subsystemIdRanges.h" +class FsfwTestTask : public TestTask { + public: + FsfwTestTask(object_id_t objectId, bool periodicEvent); -class FsfwTestTask: public TestTask { -public: - FsfwTestTask(object_id_t objectId, bool periodicEvent); + ReturnValue_t performPeriodicAction() override; - ReturnValue_t performPeriodicAction() override; -private: - - bool periodicEvent = false; - static constexpr uint8_t subsystemId = SUBSYSTEM_ID::TEST_TASK_ID; - static constexpr Event TEST_EVENT = event::makeEvent(subsystemId, 0, severity::INFO); + private: + bool periodicEvent = false; + static constexpr uint8_t subsystemId = SUBSYSTEM_ID::TEST_TASK_ID; + static constexpr Event TEST_EVENT = event::makeEvent(subsystemId, 0, severity::INFO); }; #endif /* EXAMPLE_COMMON_EXAMPLE_TEST_FSFWTESTTASK_H_ */ diff --git a/example/test/MutexExample.cpp b/example/test/MutexExample.cpp index 06af15c..fb209ad 100644 --- a/example/test/MutexExample.cpp +++ b/example/test/MutexExample.cpp @@ -3,45 +3,43 @@ #include #include +void MutexExample::example() { + MutexIF* mutex = MutexFactory::instance()->createMutex(); + MutexIF* mutex2 = MutexFactory::instance()->createMutex(); -void MutexExample::example(){ - MutexIF* mutex = MutexFactory::instance()->createMutex(); - MutexIF* mutex2 = MutexFactory::instance()->createMutex(); - - ReturnValue_t result = mutex->lockMutex(MutexIF::TimeoutType::WAITING, - 2 * 60 * 1000); - if (result != HasReturnvaluesIF::RETURN_OK) { + ReturnValue_t result = mutex->lockMutex(MutexIF::TimeoutType::WAITING, 2 * 60 * 1000); + if (result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "MutexExample::example: Lock Failed with " << result << std::endl; + sif::error << "MutexExample::example: Lock Failed with " << result << std::endl; #else - sif::printError("MutexExample::example: Lock Failed with %hu\n", result); + sif::printError("MutexExample::example: Lock Failed with %hu\n", result); #endif - } + } - result = mutex2->lockMutex(MutexIF::TimeoutType::BLOCKING); - if (result != HasReturnvaluesIF::RETURN_OK) { + result = mutex2->lockMutex(MutexIF::TimeoutType::BLOCKING); + if (result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "MutexExample::example: Lock Failed with " << result << std::endl; + sif::error << "MutexExample::example: Lock Failed with " << result << std::endl; #else - sif::printError("MutexExample::example: Lock Failed with %hu\n", result); + sif::printError("MutexExample::example: Lock Failed with %hu\n", result); #endif - } + } - result = mutex->unlockMutex(); - if (result != HasReturnvaluesIF::RETURN_OK) { + result = mutex->unlockMutex(); + if (result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "MutexExample::example: Unlock Failed with " << result << std::endl; + sif::error << "MutexExample::example: Unlock Failed with " << result << std::endl; #else - sif::printError("MutexExample::example: Unlock Failed with %hu\n", result); + sif::printError("MutexExample::example: Unlock Failed with %hu\n", result); #endif - } + } - result = mutex2->unlockMutex(); - if (result != HasReturnvaluesIF::RETURN_OK) { + result = mutex2->unlockMutex(); + if (result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "MutexExample::example: Unlock Failed with " << result << std::endl; + sif::error << "MutexExample::example: Unlock Failed with " << result << std::endl; #else - sif::printError("MutexExample::example: Unlock Failed with %hu\n", result); + sif::printError("MutexExample::example: Unlock Failed with %hu\n", result); #endif - } + } } diff --git a/example/test/MutexExample.h b/example/test/MutexExample.h index c476928..5bf76b0 100644 --- a/example/test/MutexExample.h +++ b/example/test/MutexExample.h @@ -2,7 +2,7 @@ #define EXAMPLE_COMMON_MUTEXEXAMPLE_H_ namespace MutexExample { - void example(); +void example(); }; #endif /* EXAMPLE_COMMON_MUTEXEXAMPLE_H_ */ diff --git a/example/test/testdefinitions/demoDefinitions.h b/example/test/testdefinitions/demoDefinitions.h index 711168f..f79fa78 100644 --- a/example/test/testdefinitions/demoDefinitions.h +++ b/example/test/testdefinitions/demoDefinitions.h @@ -1,8 +1,8 @@ #ifndef MISSION_DEMO_DEMODEFINITIONS_H_ #define MISSION_DEMO_DEMODEFINITIONS_H_ -#include #include +#include /** * @brief This demo set showcases the local data pool functionality of the @@ -11,27 +11,22 @@ * Each demo object will have an own instance of this set class, which contains * pool variables (for read and write access respectively). */ -class FsfwDemoSet: public StaticLocalDataSet<3> { -public: +class FsfwDemoSet : public StaticLocalDataSet<3> { + public: + static constexpr uint32_t DEMO_SET_ID = 0; - static constexpr uint32_t DEMO_SET_ID = 0; + enum PoolIds { VARIABLE, VARIABLE_LIMIT }; - enum PoolIds { - VARIABLE, - VARIABLE_LIMIT - }; + FsfwDemoSet(HasLocalDataPoolIF* hkOwner) : StaticLocalDataSet(hkOwner, DEMO_SET_ID) {} - FsfwDemoSet(HasLocalDataPoolIF* hkOwner): - StaticLocalDataSet(hkOwner, DEMO_SET_ID) {} - - lp_var_t variableRead = lp_var_t(sid.objectId, - PoolIds::VARIABLE, this, pool_rwm_t::VAR_READ); - lp_var_t variableWrite = lp_var_t(sid.objectId, - PoolIds::VARIABLE, this, pool_rwm_t::VAR_WRITE); - lp_var_t variableLimit = lp_var_t(sid.objectId, - PoolIds::VARIABLE_LIMIT, this); -private: + lp_var_t variableRead = + lp_var_t(sid.objectId, PoolIds::VARIABLE, this, pool_rwm_t::VAR_READ); + lp_var_t variableWrite = + lp_var_t(sid.objectId, PoolIds::VARIABLE, this, pool_rwm_t::VAR_WRITE); + lp_var_t variableLimit = + lp_var_t(sid.objectId, PoolIds::VARIABLE_LIMIT, this); + private: }; /** @@ -39,25 +34,21 @@ private: * above. An example application would be a consumer object like a controller * which reads multiple sensor values at once. */ -class CompleteDemoReadSet: public StaticLocalDataSet<3> { -public: - static constexpr uint32_t DEMO_SET_ID = 0; +class CompleteDemoReadSet : public StaticLocalDataSet<3> { + public: + static constexpr uint32_t DEMO_SET_ID = 0; - CompleteDemoReadSet(object_id_t owner, gp_id_t variable1, - gp_id_t variable2, gp_id_t variable3): - StaticLocalDataSet(sid_t(owner, DEMO_SET_ID)), - variable1(variable1, this, pool_rwm_t::VAR_READ), - variable2(variable2, this, pool_rwm_t::VAR_READ), - variable3(variable3, this, pool_rwm_t::VAR_READ) {} + CompleteDemoReadSet(object_id_t owner, gp_id_t variable1, gp_id_t variable2, gp_id_t variable3) + : StaticLocalDataSet(sid_t(owner, DEMO_SET_ID)), + variable1(variable1, this, pool_rwm_t::VAR_READ), + variable2(variable2, this, pool_rwm_t::VAR_READ), + variable3(variable3, this, pool_rwm_t::VAR_READ) {} + lp_var_t variable1; + lp_var_t variable2; + lp_var_t variable3; - lp_var_t variable1; - lp_var_t variable2; - lp_var_t variable3; -private: + private: }; - - - #endif /* MISSION_DEMO_DEMODEFINITIONS_H_ */ diff --git a/example/utility/PusPacketCreator.cpp b/example/utility/PusPacketCreator.cpp index f67af8b..bdfafca 100644 --- a/example/utility/PusPacketCreator.cpp +++ b/example/utility/PusPacketCreator.cpp @@ -1,10 +1,9 @@ -#include -#include #include #include +#include +#include #include void PusPacketCreator::createPusPacketAndPrint() { - // TODO: use TC packet stored here instead.. - + // TODO: use TC packet stored here instead.. } diff --git a/example/utility/PusPacketCreator.h b/example/utility/PusPacketCreator.h index 5a1f178..7fa46b7 100644 --- a/example/utility/PusPacketCreator.h +++ b/example/utility/PusPacketCreator.h @@ -9,8 +9,8 @@ #define MISSION_UTILITY_PUSPACKETCREATOR_H_ class PusPacketCreator { -public: - static void createPusPacketAndPrint(); + public: + static void createPusPacketAndPrint(); }; #endif /* MISSION_UTILITY_PUSPACKETCREATOR_H_ */ diff --git a/example/utility/TaskCreation.h b/example/utility/TaskCreation.h index d72f698..6aede3b 100644 --- a/example/utility/TaskCreation.h +++ b/example/utility/TaskCreation.h @@ -8,15 +8,14 @@ namespace task { void printInitError(const char* objName, object_id_t objectId) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "InitMission: Adding object " << objName << "(" - << std::setw(8) << std::setfill('0') << std::hex << objectId - << std::dec << ") failed." << std::endl; + sif::error << "InitMission: Adding object " << objName << "(" << std::setw(8) << std::setfill('0') + << std::hex << objectId << std::dec << ") failed." << std::endl; #else - sif::printError("InitMission: Adding object %s (0x%08x) failed.\n", - objName, static_cast(objectId)); + sif::printError("InitMission: Adding object %s (0x%08x) failed.\n", objName, + static_cast(objectId)); #endif } -} +} // namespace task #endif /* MISSION_UTILITY_TASKCREATION_H_ */ diff --git a/example/utility/TmFunnel.cpp b/example/utility/TmFunnel.cpp index 0b0568a..896df0a 100644 --- a/example/utility/TmFunnel.cpp +++ b/example/utility/TmFunnel.cpp @@ -2,119 +2,113 @@ #include #include -#include #include +#include object_id_t TmFunnel::downlinkDestination = objects::NO_OBJECT; object_id_t TmFunnel::storageDestination = objects::NO_OBJECT; -TmFunnel::TmFunnel(object_id_t objectId, uint32_t messageDepth): - SystemObject(objectId), messageDepth(messageDepth) { - tmQueue = QueueFactory::instance()->createMessageQueue(messageDepth, - MessageQueueMessage::MAX_MESSAGE_SIZE); - storageQueue = QueueFactory::instance()->createMessageQueue(messageDepth, - MessageQueueMessage::MAX_MESSAGE_SIZE); +TmFunnel::TmFunnel(object_id_t objectId, uint32_t messageDepth) + : SystemObject(objectId), messageDepth(messageDepth) { + tmQueue = QueueFactory::instance()->createMessageQueue(messageDepth, + MessageQueueMessage::MAX_MESSAGE_SIZE); + storageQueue = QueueFactory::instance()->createMessageQueue( + messageDepth, MessageQueueMessage::MAX_MESSAGE_SIZE); } -TmFunnel::~TmFunnel() { -} +TmFunnel::~TmFunnel() {} MessageQueueId_t TmFunnel::getReportReceptionQueue(uint8_t virtualChannel) { - return tmQueue->getId(); + return tmQueue->getId(); } ReturnValue_t TmFunnel::performOperation(uint8_t operationCode) { - TmTcMessage currentMessage; - ReturnValue_t status = tmQueue->receiveMessage(¤tMessage); - while(status == HasReturnvaluesIF::RETURN_OK) - { - status = handlePacket(¤tMessage); - if(status != HasReturnvaluesIF::RETURN_OK){ - break; - } - status = tmQueue->receiveMessage(¤tMessage); + TmTcMessage currentMessage; + ReturnValue_t status = tmQueue->receiveMessage(¤tMessage); + while (status == HasReturnvaluesIF::RETURN_OK) { + status = handlePacket(¤tMessage); + if (status != HasReturnvaluesIF::RETURN_OK) { + break; } + status = tmQueue->receiveMessage(¤tMessage); + } - if (status == MessageQueueIF::EMPTY) { - return HasReturnvaluesIF::RETURN_OK; - } - else { - return status; - } + if (status == MessageQueueIF::EMPTY) { + return HasReturnvaluesIF::RETURN_OK; + } else { + return status; + } } ReturnValue_t TmFunnel::handlePacket(TmTcMessage* message) { - uint8_t* packetData = nullptr; - size_t size = 0; - ReturnValue_t result = tmPool->modifyData(message->getStorageId(), - &packetData, &size); - if(result != HasReturnvaluesIF::RETURN_OK){ - return result; - } - TmPacketPusC packet(packetData); - packet.setPacketSequenceCount(this->sourceSequenceCount); - sourceSequenceCount++; - sourceSequenceCount = sourceSequenceCount % - SpacePacketBase::LIMIT_SEQUENCE_COUNT; - packet.setErrorControl(); - - result = tmQueue->sendToDefault(message); - if(result != HasReturnvaluesIF::RETURN_OK){ - tmPool->deleteData(message->getStorageId()); -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "TmFunnel::handlePacket: Error sending to downlink handler" << std::endl; -#endif - return result; - } - - if(storageDestination != objects::NO_OBJECT) { - result = storageQueue->sendToDefault(message); - if(result != HasReturnvaluesIF::RETURN_OK){ - tmPool->deleteData(message->getStorageId()); -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "TmFunnel::handlePacket: Error sending to storage handler" << std::endl; -#endif - return result; - } - } + uint8_t* packetData = nullptr; + size_t size = 0; + ReturnValue_t result = tmPool->modifyData(message->getStorageId(), &packetData, &size); + if (result != HasReturnvaluesIF::RETURN_OK) { return result; + } + TmPacketPusC packet(packetData); + packet.setPacketSequenceCount(this->sourceSequenceCount); + sourceSequenceCount++; + sourceSequenceCount = sourceSequenceCount % SpacePacketBase::LIMIT_SEQUENCE_COUNT; + packet.setErrorControl(); + + result = tmQueue->sendToDefault(message); + if (result != HasReturnvaluesIF::RETURN_OK) { + tmPool->deleteData(message->getStorageId()); +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "TmFunnel::handlePacket: Error sending to downlink handler" << std::endl; +#endif + return result; + } + + if (storageDestination != objects::NO_OBJECT) { + result = storageQueue->sendToDefault(message); + if (result != HasReturnvaluesIF::RETURN_OK) { + tmPool->deleteData(message->getStorageId()); +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "TmFunnel::handlePacket: Error sending to storage handler" << std::endl; +#endif + return result; + } + } + return result; } ReturnValue_t TmFunnel::initialize() { - - tmPool = ObjectManager::instance()->get(objects::TM_STORE); - if(tmPool == nullptr) { + tmPool = ObjectManager::instance()->get(objects::TM_STORE); + if (tmPool == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "TmFunnel::initialize: TM store not set." << std::endl; - sif::error << "Make sure the tm store is set up properly and implements StorageManagerIF" << - std::endl; + sif::error << "TmFunnel::initialize: TM store not set." << std::endl; + sif::error << "Make sure the tm store is set up properly and implements StorageManagerIF" + << std::endl; #endif - return ObjectManagerIF::CHILD_INIT_FAILED; - } + return ObjectManagerIF::CHILD_INIT_FAILED; + } - AcceptsTelemetryIF* tmTarget = ObjectManager::instance()-> - get(downlinkDestination); - if(tmTarget == nullptr){ + AcceptsTelemetryIF* tmTarget = + ObjectManager::instance()->get(downlinkDestination); + if (tmTarget == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "TmFunnel::initialize: Downlink Destination not set." << std::endl; - sif::error << "Make sure the downlink destination object is set up properly and implements " - "AcceptsTelemetryIF" << std::endl; + sif::error << "TmFunnel::initialize: Downlink Destination not set." << std::endl; + sif::error << "Make sure the downlink destination object is set up properly and implements " + "AcceptsTelemetryIF" + << std::endl; #endif - return ObjectManagerIF::CHILD_INIT_FAILED; - } - tmQueue->setDefaultDestination(tmTarget->getReportReceptionQueue()); - - // Storage destination is optional. - if(storageDestination == objects::NO_OBJECT) { - return SystemObject::initialize(); - } - - AcceptsTelemetryIF* storageTarget = ObjectManager::instance()-> - get(storageDestination); - if(storageTarget != nullptr) { - storageQueue->setDefaultDestination( - storageTarget->getReportReceptionQueue()); - } + return ObjectManagerIF::CHILD_INIT_FAILED; + } + tmQueue->setDefaultDestination(tmTarget->getReportReceptionQueue()); + // Storage destination is optional. + if (storageDestination == objects::NO_OBJECT) { return SystemObject::initialize(); + } + + AcceptsTelemetryIF* storageTarget = + ObjectManager::instance()->get(storageDestination); + if (storageTarget != nullptr) { + storageQueue->setDefaultDestination(storageTarget->getReportReceptionQueue()); + } + + return SystemObject::initialize(); } diff --git a/example/utility/TmFunnel.h b/example/utility/TmFunnel.h index d9af4a8..3d066f6 100644 --- a/example/utility/TmFunnel.h +++ b/example/utility/TmFunnel.h @@ -1,13 +1,13 @@ #ifndef MISSION_UTILITY_TMFUNNEL_H_ #define MISSION_UTILITY_TMFUNNEL_H_ +#include #include #include #include -#include #include -namespace Factory{ +namespace Factory { void setStaticFrameworkObjectIds(); } @@ -19,33 +19,30 @@ void setStaticFrameworkObjectIds(); * @ingroup utility * @author J. Meier */ -class TmFunnel: - public AcceptsTelemetryIF, - public ExecutableObjectIF, - public SystemObject { - friend void (Factory::setStaticFrameworkObjectIds)(); -public: - TmFunnel(object_id_t objectId, uint32_t messageDepth = 20); - virtual ~TmFunnel(); +class TmFunnel : public AcceptsTelemetryIF, public ExecutableObjectIF, public SystemObject { + friend void(Factory::setStaticFrameworkObjectIds)(); - virtual MessageQueueId_t getReportReceptionQueue( - uint8_t virtualChannel = 0) override; - virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override; - virtual ReturnValue_t initialize() override; + public: + TmFunnel(object_id_t objectId, uint32_t messageDepth = 20); + virtual ~TmFunnel(); -protected: - static object_id_t downlinkDestination; - static object_id_t storageDestination; + virtual MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel = 0) override; + virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override; + virtual ReturnValue_t initialize() override; -private: - uint16_t sourceSequenceCount = 0; - MessageQueueIF* tmQueue = nullptr; - MessageQueueIF* storageQueue = nullptr; + protected: + static object_id_t downlinkDestination; + static object_id_t storageDestination; - StorageManagerIF* tmPool = nullptr; - uint32_t messageDepth = 0; + private: + uint16_t sourceSequenceCount = 0; + MessageQueueIF* tmQueue = nullptr; + MessageQueueIF* storageQueue = nullptr; - ReturnValue_t handlePacket(TmTcMessage* message); + StorageManagerIF* tmPool = nullptr; + uint32_t messageDepth = 0; + + ReturnValue_t handlePacket(TmTcMessage* message); }; #endif /* MISSION_UTILITY_TMFUNNEL_H_ */ diff --git a/example/utility/compile_time.h b/example/utility/compile_time.h index c55673f..0e36724 100644 --- a/example/utility/compile_time.h +++ b/example/utility/compile_time.h @@ -5,14 +5,17 @@ * Authors: * * Assembled from the code released on Stackoverflow by: - * Dennis (instructable.com/member/nqtronix) | https://stackoverflow.com/questions/23032002/c-c-how-to-get-integer-unix-timestamp-of-build-time-not-string + * Dennis (instructable.com/member/nqtronix) | + * https://stackoverflow.com/questions/23032002/c-c-how-to-get-integer-unix-timestamp-of-build-time-not-string * and - * Alexis Wilke | https://stackoverflow.com/questions/10538444/do-you-know-of-a-c-macro-to-compute-unix-time-and-date + * Alexis Wilke | + * https://stackoverflow.com/questions/10538444/do-you-know-of-a-c-macro-to-compute-unix-time-and-date * * Assembled by Jean Rabault * - * UNIX_TIMESTAMP gives the UNIX timestamp (unsigned long integer of seconds since 1st Jan 1970) of compilation from macros using the compiler defined __TIME__ macro. - * This should include Gregorian calendar leap days, in particular the 29ths of February, 100 and 400 years modulo leaps. + * UNIX_TIMESTAMP gives the UNIX timestamp (unsigned long integer of seconds since 1st Jan 1970) of + * compilation from macros using the compiler defined __TIME__ macro. This should include Gregorian + * calendar leap days, in particular the 29ths of February, 100 and 400 years modulo leaps. * * Careful: __TIME__ is the local time of the computer, NOT the UTC time in general! * @@ -22,76 +25,66 @@ #define COMPILE_TIME_H_ // Some definitions for calculation -#define SEC_PER_MIN 60UL -#define SEC_PER_HOUR 3600UL -#define SEC_PER_DAY 86400UL -#define SEC_PER_YEAR (SEC_PER_DAY*365) +#define SEC_PER_MIN 60UL +#define SEC_PER_HOUR 3600UL +#define SEC_PER_DAY 86400UL +#define SEC_PER_YEAR (SEC_PER_DAY * 365) // extracts 1..4 characters from a string and interprets it as a decimal value -#define CONV_STR2DEC_1(str, i) (str[i]>'0'?str[i]-'0':0) -#define CONV_STR2DEC_2(str, i) (CONV_STR2DEC_1(str, i)*10 + str[i+1]-'0') -#define CONV_STR2DEC_3(str, i) (CONV_STR2DEC_2(str, i)*10 + str[i+2]-'0') -#define CONV_STR2DEC_4(str, i) (CONV_STR2DEC_3(str, i)*10 + str[i+3]-'0') +#define CONV_STR2DEC_1(str, i) (str[i] > '0' ? str[i] - '0' : 0) +#define CONV_STR2DEC_2(str, i) (CONV_STR2DEC_1(str, i) * 10 + str[i + 1] - '0') +#define CONV_STR2DEC_3(str, i) (CONV_STR2DEC_2(str, i) * 10 + str[i + 2] - '0') +#define CONV_STR2DEC_4(str, i) (CONV_STR2DEC_3(str, i) * 10 + str[i + 3] - '0') // Custom "glue logic" to convert the month name to a usable number -#define GET_MONTH(str, i) (str[i]=='J' && str[i+1]=='a' && str[i+2]=='n' ? 1 : \ - str[i]=='F' && str[i+1]=='e' && str[i+2]=='b' ? 2 : \ - str[i]=='M' && str[i+1]=='a' && str[i+2]=='r' ? 3 : \ - str[i]=='A' && str[i+1]=='p' && str[i+2]=='r' ? 4 : \ - str[i]=='M' && str[i+1]=='a' && str[i+2]=='y' ? 5 : \ - str[i]=='J' && str[i+1]=='u' && str[i+2]=='n' ? 6 : \ - str[i]=='J' && str[i+1]=='u' && str[i+2]=='l' ? 7 : \ - str[i]=='A' && str[i+1]=='u' && str[i+2]=='g' ? 8 : \ - str[i]=='S' && str[i+1]=='e' && str[i+2]=='p' ? 9 : \ - str[i]=='O' && str[i+1]=='c' && str[i+2]=='t' ? 10 : \ - str[i]=='N' && str[i+1]=='o' && str[i+2]=='v' ? 11 : \ - str[i]=='D' && str[i+1]=='e' && str[i+2]=='c' ? 12 : 0) +#define GET_MONTH(str, i) \ + (str[i] == 'J' && str[i + 1] == 'a' && str[i + 2] == 'n' ? 1 \ + : str[i] == 'F' && str[i + 1] == 'e' && str[i + 2] == 'b' ? 2 \ + : str[i] == 'M' && str[i + 1] == 'a' && str[i + 2] == 'r' ? 3 \ + : str[i] == 'A' && str[i + 1] == 'p' && str[i + 2] == 'r' ? 4 \ + : str[i] == 'M' && str[i + 1] == 'a' && str[i + 2] == 'y' ? 5 \ + : str[i] == 'J' && str[i + 1] == 'u' && str[i + 2] == 'n' ? 6 \ + : str[i] == 'J' && str[i + 1] == 'u' && str[i + 2] == 'l' ? 7 \ + : str[i] == 'A' && str[i + 1] == 'u' && str[i + 2] == 'g' ? 8 \ + : str[i] == 'S' && str[i + 1] == 'e' && str[i + 2] == 'p' ? 9 \ + : str[i] == 'O' && str[i + 1] == 'c' && str[i + 2] == 't' ? 10 \ + : str[i] == 'N' && str[i + 1] == 'o' && str[i + 2] == 'v' ? 11 \ + : str[i] == 'D' && str[i + 1] == 'e' && str[i + 2] == 'c' ? 12 \ + : 0) // extract the information from the time string given by __TIME__ and __DATE__ -#define __TIME_SECONDS__ CONV_STR2DEC_2(__TIME__, 6) -#define __TIME_MINUTES__ CONV_STR2DEC_2(__TIME__, 3) -#define __TIME_HOURS__ CONV_STR2DEC_2(__TIME__, 0) -#define __TIME_DAYS__ CONV_STR2DEC_2(__DATE__, 4) -#define __TIME_MONTH__ GET_MONTH(__DATE__, 0) -#define __TIME_YEARS__ CONV_STR2DEC_4(__DATE__, 7) +#define __TIME_SECONDS__ CONV_STR2DEC_2(__TIME__, 6) +#define __TIME_MINUTES__ CONV_STR2DEC_2(__TIME__, 3) +#define __TIME_HOURS__ CONV_STR2DEC_2(__TIME__, 0) +#define __TIME_DAYS__ CONV_STR2DEC_2(__DATE__, 4) +#define __TIME_MONTH__ GET_MONTH(__DATE__, 0) +#define __TIME_YEARS__ CONV_STR2DEC_4(__DATE__, 7) // Days in February #define _UNIX_TIMESTAMP_FDAY(year) \ - (((year) % 400) == 0UL ? 29UL : \ - (((year) % 100) == 0UL ? 28UL : \ - (((year) % 4) == 0UL ? 29UL : \ - 28UL))) + (((year) % 400) == 0UL ? 29UL \ + : (((year) % 100) == 0UL ? 28UL : (((year) % 4) == 0UL ? 29UL : 28UL))) // Days in the year -#define _UNIX_TIMESTAMP_YDAY(year, month, day) \ - ( \ - /* January */ day \ - /* February */ + (month >= 2 ? 31UL : 0UL) \ - /* March */ + (month >= 3 ? _UNIX_TIMESTAMP_FDAY(year) : 0UL) \ - /* April */ + (month >= 4 ? 31UL : 0UL) \ - /* May */ + (month >= 5 ? 30UL : 0UL) \ - /* June */ + (month >= 6 ? 31UL : 0UL) \ - /* July */ + (month >= 7 ? 30UL : 0UL) \ - /* August */ + (month >= 8 ? 31UL : 0UL) \ - /* September */+ (month >= 9 ? 31UL : 0UL) \ - /* October */ + (month >= 10 ? 30UL : 0UL) \ - /* November */ + (month >= 11 ? 31UL : 0UL) \ - /* December */ + (month >= 12 ? 30UL : 0UL) \ - ) +#define _UNIX_TIMESTAMP_YDAY(year, month, day) \ + (/* January */ day /* February */ + (month >= 2 ? 31UL : 0UL) /* March */ + \ + (month >= 3 ? _UNIX_TIMESTAMP_FDAY(year) : 0UL) /* April */ + \ + (month >= 4 ? 31UL : 0UL) /* May */ + (month >= 5 ? 30UL : 0UL) /* June */ + \ + (month >= 6 ? 31UL : 0UL) /* July */ + (month >= 7 ? 30UL : 0UL) /* August */ + \ + (month >= 8 ? 31UL : 0UL) /* September */ + (month >= 9 ? 31UL : 0UL) /* October */ + \ + (month >= 10 ? 30UL : 0UL) /* November */ + (month >= 11 ? 31UL : 0UL) /* December */ + \ + (month >= 12 ? 30UL : 0UL)) // get the UNIX timestamp from a digits representation -#define _UNIX_TIMESTAMP(year, month, day, hour, minute, second) \ - ( /* time */ second \ - + minute * SEC_PER_MIN \ - + hour * SEC_PER_HOUR \ - + /* year day (month + day) */ (_UNIX_TIMESTAMP_YDAY(year, month, day) - 1) * SEC_PER_DAY \ - + /* year */ (year - 1970UL) * SEC_PER_YEAR \ - + ((year - 1969UL) / 4UL) * SEC_PER_DAY \ - - ((year - 1901UL) / 100UL) * SEC_PER_DAY \ - + ((year - 1601UL) / 400UL) * SEC_PER_DAY \ - ) +#define _UNIX_TIMESTAMP(year, month, day, hour, minute, second) \ + (/* time */ second + minute * SEC_PER_MIN + hour * SEC_PER_HOUR + \ + /* year day (month + day) */ (_UNIX_TIMESTAMP_YDAY(year, month, day) - 1) * SEC_PER_DAY + \ + /* year */ (year - 1970UL) * SEC_PER_YEAR + ((year - 1969UL) / 4UL) * SEC_PER_DAY - \ + ((year - 1901UL) / 100UL) * SEC_PER_DAY + ((year - 1601UL) / 400UL) * SEC_PER_DAY) // the UNIX timestamp -#define UNIX_TIMESTAMP (_UNIX_TIMESTAMP(__TIME_YEARS__, __TIME_MONTH__, __TIME_DAYS__, __TIME_HOURS__, __TIME_MINUTES__, __TIME_SECONDS__)) +#define UNIX_TIMESTAMP \ + (_UNIX_TIMESTAMP(__TIME_YEARS__, __TIME_MONTH__, __TIME_DAYS__, __TIME_HOURS__, \ + __TIME_MINUTES__, __TIME_SECONDS__)) #endif diff --git a/example/utility/utility.cpp b/example/utility/utility.cpp index 26481db..3630fc2 100644 --- a/example/utility/utility.cpp +++ b/example/utility/utility.cpp @@ -1,22 +1,22 @@ #include "utility.h" + #include #include - #include -void utility::commonInitPrint(const char *const os, const char* const board) { - if(os == nullptr or board == nullptr) { - return; - } +void utility::commonInitPrint(const char* const os, const char* const board) { + if (os == nullptr or board == nullptr) { + return; + } #if FSFW_CPP_OSTREAM_ENABLED == 1 - std::cout << "-- FSFW Example (" << os<< ") v" << FSFW_EXAMPLE_VERSION << "." << - FSFW_EXAMPLE_SUBVERSION << "." << FSFW_EXAMPLE_REVISION << " --" << std::endl; - std::cout << "-- Compiled for " << board << " --" << std::endl; - std::cout << "-- Compiled on " << __DATE__ << " " << __TIME__ << " --" << std::endl; + std::cout << "-- FSFW Example (" << os << ") v" << FSFW_EXAMPLE_VERSION << "." + << FSFW_EXAMPLE_SUBVERSION << "." << FSFW_EXAMPLE_REVISION << " --" << std::endl; + std::cout << "-- Compiled for " << board << " --" << std::endl; + std::cout << "-- Compiled on " << __DATE__ << " " << __TIME__ << " --" << std::endl; #else - printf("\n\r-- FSFW Example (%s) v%d.%d.%d --\n", os, FSFW_EXAMPLE_VERSION, - FSFW_EXAMPLE_SUBVERSION, FSFW_EXAMPLE_REVISION); - printf("-- Compiled for %s --\n", board); - printf("-- Compiled on %s %s --\n", __DATE__, __TIME__); + printf("\n\r-- FSFW Example (%s) v%d.%d.%d --\n", os, FSFW_EXAMPLE_VERSION, + FSFW_EXAMPLE_SUBVERSION, FSFW_EXAMPLE_REVISION); + printf("-- Compiled for %s --\n", board); + printf("-- Compiled on %s %s --\n", __DATE__, __TIME__); #endif } diff --git a/example/utility/utility.h b/example/utility/utility.h index 6cf6f35..4f1683a 100644 --- a/example/utility/utility.h +++ b/example/utility/utility.h @@ -3,9 +3,8 @@ namespace utility { -void commonInitPrint(const char *const os, const char* const board); +void commonInitPrint(const char* const os, const char* const board); } - #endif /* COMMON_UTILITY_UTILITY_H_ */ diff --git a/stm32h7/STM32TestTask.cpp b/stm32h7/STM32TestTask.cpp index 49a3294..c34ccf9 100644 --- a/stm32h7/STM32TestTask.cpp +++ b/stm32h7/STM32TestTask.cpp @@ -1,33 +1,33 @@ #include "STM32TestTask.h" -#include "stm32h7xx_nucleo.h" -#include "OBSWConfig.h" -STM32TestTask::STM32TestTask(object_id_t objectId, bool enablePrintout, - bool blinkyLed): TestTask(objectId), blinkyLed(blinkyLed) { - BSP_LED_Init(LED1); - BSP_LED_Init(LED2); - BSP_LED_Init(LED3); +#include "OBSWConfig.h" +#include "stm32h7xx_nucleo.h" + +STM32TestTask::STM32TestTask(object_id_t objectId, bool enablePrintout, bool blinkyLed) + : TestTask(objectId), blinkyLed(blinkyLed) { + BSP_LED_Init(LED1); + BSP_LED_Init(LED2); + BSP_LED_Init(LED3); } ReturnValue_t STM32TestTask::performPeriodicAction() { - if(blinkyLed) { + if (blinkyLed) { #if OBSW_ETHERNET_USE_LEDS == 0 - BSP_LED_Toggle(LED1); - BSP_LED_Toggle(LED2); + BSP_LED_Toggle(LED1); + BSP_LED_Toggle(LED2); #endif - BSP_LED_Toggle(LED3); - } - if(testSpi) { - spiTest->performOperation(); - } - return TestTask::performPeriodicAction(); + BSP_LED_Toggle(LED3); + } + if (testSpi) { + spiTest->performOperation(); + } + return TestTask::performPeriodicAction(); } ReturnValue_t STM32TestTask::initialize() { - if(testSpi) { - spiComIF = new SpiComIF(objects::SPI_COM_IF); - spiTest = new SpiTest(*spiComIF); - - } - return TestTask::initialize(); + if (testSpi) { + spiComIF = new SpiComIF(objects::SPI_COM_IF); + spiTest = new SpiTest(*spiComIF); + } + return TestTask::initialize(); } diff --git a/stm32h7/STM32TestTask.h b/stm32h7/STM32TestTask.h index 01de582..0f75d71 100644 --- a/stm32h7/STM32TestTask.h +++ b/stm32h7/STM32TestTask.h @@ -4,22 +4,19 @@ #include "bsp_stm32h7_freertos/boardtest/SpiTest.h" #include "fsfw_tests/integration/task/TestTask.h" -class STM32TestTask: public TestTask { -public: - STM32TestTask(object_id_t objectId, bool enablePrintout, bool blinkyLed = true); +class STM32TestTask : public TestTask { + public: + STM32TestTask(object_id_t objectId, bool enablePrintout, bool blinkyLed = true); - ReturnValue_t initialize() override; - ReturnValue_t performPeriodicAction() override; -private: + ReturnValue_t initialize() override; + ReturnValue_t performPeriodicAction() override; - SpiComIF* spiComIF = nullptr; - SpiTest* spiTest = nullptr; - - bool blinkyLed = false; - bool testSpi = true; + private: + SpiComIF* spiComIF = nullptr; + SpiTest* spiTest = nullptr; + bool blinkyLed = false; + bool testSpi = true; }; - - #endif /* BSP_STM32_BOARDTEST_STM32TESTTASK_H_ */ diff --git a/stm32h7/networking/TmTcLwIpUdpBridge.cpp b/stm32h7/networking/TmTcLwIpUdpBridge.cpp index 5404f3c..cd580a6 100644 --- a/stm32h7/networking/TmTcLwIpUdpBridge.cpp +++ b/stm32h7/networking/TmTcLwIpUdpBridge.cpp @@ -1,204 +1,189 @@ #include "TmTcLwIpUdpBridge.h" -#include "udp_config.h" + +#include +#include +#include +#include + #include "app_ethernet.h" #include "ethernetif.h" -#include +#include "udp_config.h" -#include -#include -#include - - -TmTcLwIpUdpBridge::TmTcLwIpUdpBridge(object_id_t objectId, - object_id_t ccsdsPacketDistributor, object_id_t tmStoreId, - object_id_t tcStoreId): - TmTcBridge(objectId, ccsdsPacketDistributor, tmStoreId, tcStoreId) { - TmTcLwIpUdpBridge::lastAdd.addr = IPADDR_TYPE_ANY; +TmTcLwIpUdpBridge::TmTcLwIpUdpBridge(object_id_t objectId, object_id_t ccsdsPacketDistributor, + object_id_t tmStoreId, object_id_t tcStoreId) + : TmTcBridge(objectId, ccsdsPacketDistributor, tmStoreId, tcStoreId) { + TmTcLwIpUdpBridge::lastAdd.addr = IPADDR_TYPE_ANY; } TmTcLwIpUdpBridge::~TmTcLwIpUdpBridge() {} ReturnValue_t TmTcLwIpUdpBridge::initialize() { - TmTcBridge::initialize(); - bridgeLock = MutexFactory::instance()->createMutex(); - if(bridgeLock == nullptr) { - return ObjectManagerIF::CHILD_INIT_FAILED; - } - ReturnValue_t result = udp_server_init(); - return result; + TmTcBridge::initialize(); + bridgeLock = MutexFactory::instance()->createMutex(); + if (bridgeLock == nullptr) { + return ObjectManagerIF::CHILD_INIT_FAILED; + } + ReturnValue_t result = udp_server_init(); + return result; } ReturnValue_t TmTcLwIpUdpBridge::udp_server_init(void) { - err_t err; - /* Create a new UDP control block */ - TmTcLwIpUdpBridge::upcb = udp_new(); - if (TmTcLwIpUdpBridge::upcb) - { - /* Bind the upcb to the UDP_PORT port */ - /* Using IP_ADDR_ANY allow the upcb to be used by any local interface */ - err = udp_bind(TmTcLwIpUdpBridge::upcb, IP_ADDR_ANY, UDP_SERVER_PORT); + err_t err; + /* Create a new UDP control block */ + TmTcLwIpUdpBridge::upcb = udp_new(); + if (TmTcLwIpUdpBridge::upcb) { + /* Bind the upcb to the UDP_PORT port */ + /* Using IP_ADDR_ANY allow the upcb to be used by any local interface */ + err = udp_bind(TmTcLwIpUdpBridge::upcb, IP_ADDR_ANY, UDP_SERVER_PORT); - if(err == ERR_OK) - { - /* Set a receive callback for the upcb */ - udp_recv(TmTcLwIpUdpBridge::upcb, &udp_server_receive_callback, - (void*) this); - return RETURN_OK; - } - else - { - udp_remove(TmTcLwIpUdpBridge::upcb); - return RETURN_FAILED; - } + if (err == ERR_OK) { + /* Set a receive callback for the upcb */ + udp_recv(TmTcLwIpUdpBridge::upcb, &udp_server_receive_callback, (void*)this); + return RETURN_OK; } else { - return RETURN_FAILED; + udp_remove(TmTcLwIpUdpBridge::upcb); + return RETURN_FAILED; } + } else { + return RETURN_FAILED; + } } ReturnValue_t TmTcLwIpUdpBridge::performOperation(uint8_t operationCode) { - TmTcBridge::performOperation(); + TmTcBridge::performOperation(); #if TCPIP_RECV_WIRETAPPING == 1 - if(connectFlag) { - uint32_t ipAddress = ((ip4_addr*) &lastAdd)->addr; - int ipAddress1 = (ipAddress & 0xFF000000) >> 24; - int ipAddress2 = (ipAddress & 0xFF0000) >> 16; - int ipAddress3 = (ipAddress & 0xFF00) >> 8; - int ipAddress4 = ipAddress & 0xFF; + if (connectFlag) { + uint32_t ipAddress = ((ip4_addr*)&lastAdd)->addr; + int ipAddress1 = (ipAddress & 0xFF000000) >> 24; + int ipAddress2 = (ipAddress & 0xFF0000) >> 16; + int ipAddress3 = (ipAddress & 0xFF00) >> 8; + int ipAddress4 = ipAddress & 0xFF; #if OBSW_VERBOSE_LEVEL == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "TmTcLwIpUdpBridge: Client IP Address " << std::dec - << ipAddress4 << "." << ipAddress3 << "." << ipAddress2 << "." - << ipAddress1 << std::endl; - uint16_t portSwapped = EndianConverter::convertBigEndian(lastPort); - sif::info << "TmTcLwIpUdpBridge: Client IP Port " - << (int)portSwapped << std::endl; + sif::info << "TmTcLwIpUdpBridge: Client IP Address " << std::dec << ipAddress4 << "." + << ipAddress3 << "." << ipAddress2 << "." << ipAddress1 << std::endl; + uint16_t portSwapped = EndianConverter::convertBigEndian(lastPort); + sif::info << "TmTcLwIpUdpBridge: Client IP Port " << (int)portSwapped << std::endl; #else - sif::printInfo("TmTcLwIpUdpBridge: Client IP Address %d.%d.%d.%d\n", - ipAddress4, ipAddress3, ipAddress2, ipAddress1); - uint16_t portSwapped = EndianConverter::convertBigEndian(lastPort); - sif::printInfo("TmTcLwIpUdpBridge: Client IP Port: %d\n", portSwapped); + sif::printInfo("TmTcLwIpUdpBridge: Client IP Address %d.%d.%d.%d\n", ipAddress4, ipAddress3, + ipAddress2, ipAddress1); + uint16_t portSwapped = EndianConverter::convertBigEndian(lastPort); + sif::printInfo("TmTcLwIpUdpBridge: Client IP Port: %d\n", portSwapped); #endif #endif - connectFlag = false; - } + connectFlag = false; + } #endif - return RETURN_OK; + return RETURN_OK; } -ReturnValue_t TmTcLwIpUdpBridge::sendTm(const uint8_t * data, size_t dataLen) { - struct pbuf *p_tx = pbuf_alloc(PBUF_TRANSPORT, dataLen, PBUF_RAM); - if ((p_tx != nullptr) && (lastAdd.addr != IPADDR_TYPE_ANY) && (upcb != nullptr)) { - /* copy data to pbuf */ - err_t err = pbuf_take(p_tx, (char*) data, dataLen); - if(err!=ERR_OK){ - pbuf_free(p_tx); - return err; - } - /* Connect to the remote client */ - err = udp_connect(TmTcLwIpUdpBridge::upcb, &lastAdd , lastPort); - if(err != ERR_OK){ - pbuf_free(p_tx); - return err; - } - /* Tell the client that we have accepted it */ - err = udp_send(TmTcLwIpUdpBridge::upcb, p_tx); - pbuf_free(p_tx); - if(err!=ERR_OK){ - return err; - } - - /* free the UDP connection, so we can accept new clients */ - udp_disconnect (TmTcLwIpUdpBridge::upcb); +ReturnValue_t TmTcLwIpUdpBridge::sendTm(const uint8_t* data, size_t dataLen) { + struct pbuf* p_tx = pbuf_alloc(PBUF_TRANSPORT, dataLen, PBUF_RAM); + if ((p_tx != nullptr) && (lastAdd.addr != IPADDR_TYPE_ANY) && (upcb != nullptr)) { + /* copy data to pbuf */ + err_t err = pbuf_take(p_tx, (char*)data, dataLen); + if (err != ERR_OK) { + pbuf_free(p_tx); + return err; } - else{ - return RETURN_FAILED; + /* Connect to the remote client */ + err = udp_connect(TmTcLwIpUdpBridge::upcb, &lastAdd, lastPort); + if (err != ERR_OK) { + pbuf_free(p_tx); + return err; } - return RETURN_OK; -} - - -void TmTcLwIpUdpBridge::udp_server_receive_callback(void* arg, - struct udp_pcb* upcb_, struct pbuf* p, const ip_addr_t* addr, - u16_t port) { - struct pbuf *p_tx = nullptr; - auto udpBridge = reinterpret_cast(arg); - if(udpBridge == nullptr) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "TmTcLwIpUdpBridge::udp_server_receive_callback: Invalid UDP bridge!" << - std::endl; -#else - sif::printWarning("TmTcLwIpUdpBridge::udp_server_receive_callback: Invalid UDP bridge!\n"); -#endif - } - /* allocate pbuf from RAM*/ - p_tx = pbuf_alloc(PBUF_TRANSPORT,p->len, PBUF_RAM); - - if(p_tx != NULL) - { - if(udpBridge != nullptr) { - MutexGuard lg(udpBridge->bridgeLock); - udpBridge->upcb = upcb_; - udpBridge->lastAdd = *addr; - udpBridge->lastPort = port; - if(not udpBridge->comLinkUp()) { - udpBridge->registerCommConnect(); -#if TCPIP_RECV_WIRETAPPING == 1 - udpBridge->connectFlag = true; -#endif - /* This should have already been done, but we will still do it */ - udpBridge->physicalConnectStatusChange(true); - } - } - pbuf_take(p_tx, (char*)p->payload, p->len); - /* send the received data to the uart port */ - char* data = reinterpret_cast(p_tx->payload); - *(data+p_tx->len) = '\0'; - -#if TCPIP_RECV_WIRETAPPING == 1 - udpBridge->printData(p,data); -#endif - - store_address_t storeId; - ReturnValue_t returnValue = udpBridge->tcStore->addData(&storeId, - reinterpret_cast(p->payload), p->len); - if (returnValue != RETURN_OK) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "UDP Server: Data storage failed" << std::endl; -#endif - pbuf_free(p_tx); - return; - } - TmTcMessage message(storeId); - if (udpBridge->tmTcReceptionQueue->sendToDefault(&message) - != RETURN_OK) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "TmTcLwIpUdpBridgw::udp_server_receive_callback:" - << " Sending message to queue failed" << std::endl; -#endif - udpBridge->tcStore->deleteData(storeId); - } - } - /* Free the p_tx buffer */ + /* Tell the client that we have accepted it */ + err = udp_send(TmTcLwIpUdpBridge::upcb, p_tx); pbuf_free(p_tx); + if (err != ERR_OK) { + return err; + } + + /* free the UDP connection, so we can accept new clients */ + udp_disconnect(TmTcLwIpUdpBridge::upcb); + } else { + return RETURN_FAILED; + } + return RETURN_OK; +} + +void TmTcLwIpUdpBridge::udp_server_receive_callback(void* arg, struct udp_pcb* upcb_, + struct pbuf* p, const ip_addr_t* addr, + u16_t port) { + struct pbuf* p_tx = nullptr; + auto udpBridge = reinterpret_cast(arg); + if (udpBridge == nullptr) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "TmTcLwIpUdpBridge::udp_server_receive_callback: Invalid UDP bridge!" + << std::endl; +#else + sif::printWarning("TmTcLwIpUdpBridge::udp_server_receive_callback: Invalid UDP bridge!\n"); +#endif + } + /* allocate pbuf from RAM*/ + p_tx = pbuf_alloc(PBUF_TRANSPORT, p->len, PBUF_RAM); + + if (p_tx != NULL) { + if (udpBridge != nullptr) { + MutexGuard lg(udpBridge->bridgeLock); + udpBridge->upcb = upcb_; + udpBridge->lastAdd = *addr; + udpBridge->lastPort = port; + if (not udpBridge->comLinkUp()) { + udpBridge->registerCommConnect(); +#if TCPIP_RECV_WIRETAPPING == 1 + udpBridge->connectFlag = true; +#endif + /* This should have already been done, but we will still do it */ + udpBridge->physicalConnectStatusChange(true); + } + } + pbuf_take(p_tx, (char*)p->payload, p->len); + /* send the received data to the uart port */ + char* data = reinterpret_cast(p_tx->payload); + *(data + p_tx->len) = '\0'; + +#if TCPIP_RECV_WIRETAPPING == 1 + udpBridge->printData(p, data); +#endif + + store_address_t storeId; + ReturnValue_t returnValue = + udpBridge->tcStore->addData(&storeId, reinterpret_cast(p->payload), p->len); + if (returnValue != RETURN_OK) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "UDP Server: Data storage failed" << std::endl; +#endif + pbuf_free(p_tx); + return; + } + TmTcMessage message(storeId); + if (udpBridge->tmTcReceptionQueue->sendToDefault(&message) != RETURN_OK) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "TmTcLwIpUdpBridgw::udp_server_receive_callback:" + << " Sending message to queue failed" << std::endl; +#endif + udpBridge->tcStore->deleteData(storeId); + } + } + /* Free the p_tx buffer */ + pbuf_free(p_tx); } /* Caller must ensure thread-safety */ -bool TmTcLwIpUdpBridge::comLinkUp() const { - return communicationLinkUp; -} +bool TmTcLwIpUdpBridge::comLinkUp() const { return communicationLinkUp; } /* Caller must ensure thread-safety */ void TmTcLwIpUdpBridge::physicalConnectStatusChange(bool connect) { - if(connect) { - /* Physical connection does not mean there is a recipient to send packets too. - This will be done by the receive callback! */ - physicalConnection = true; - } - else { - physicalConnection = false; - /* If there is no physical connection, we can't send anything back */ - registerCommDisconnect(); - } + if (connect) { + /* Physical connection does not mean there is a recipient to send packets too. + This will be done by the receive callback! */ + physicalConnection = true; + } else { + physicalConnection = false; + /* If there is no physical connection, we can't send anything back */ + registerCommDisconnect(); + } } diff --git a/stm32h7/networking/TmTcLwIpUdpBridge.h b/stm32h7/networking/TmTcLwIpUdpBridge.h index fb2f5d5..0138e09 100644 --- a/stm32h7/networking/TmTcLwIpUdpBridge.h +++ b/stm32h7/networking/TmTcLwIpUdpBridge.h @@ -2,9 +2,8 @@ #define BSP_STM32_RTEMS_NETWORKING_TMTCUDPBRIDGE_H_ #include - -#include #include +#include #define TCPIP_RECV_WIRETAPPING 0 @@ -12,68 +11,67 @@ * This bridge is used to forward TMTC packets received via LwIP UDP to the internal software bus. */ class TmTcLwIpUdpBridge : public TmTcBridge { - friend class UdpTcLwIpPollingTask; -public: - TmTcLwIpUdpBridge(object_id_t objectId, - object_id_t ccsdsPacketDistributor, object_id_t tmStoreId, - object_id_t tcStoreId); - virtual ~TmTcLwIpUdpBridge(); + friend class UdpTcLwIpPollingTask; - virtual ReturnValue_t initialize() override; - ReturnValue_t udp_server_init(); + public: + TmTcLwIpUdpBridge(object_id_t objectId, object_id_t ccsdsPacketDistributor, object_id_t tmStoreId, + object_id_t tcStoreId); + virtual ~TmTcLwIpUdpBridge(); - /** - * In addition to default implementation, ethernet link status is checked. - * @param operationCode - * @return - */ - virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override; + virtual ReturnValue_t initialize() override; + ReturnValue_t udp_server_init(); - /** TM Send implementation uses udp_send function from lwIP stack - * @param data - * @param dataLen - * @return - */ - virtual ReturnValue_t sendTm(const uint8_t * data, size_t dataLen) override; + /** + * In addition to default implementation, ethernet link status is checked. + * @param operationCode + * @return + */ + virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override; - /** - * @brief This function is called when an UDP datagram has been - * received on the port UDP_PORT. - * @param arg - * @param upcb_ - * @param p - * @param addr Source address which will be bound to TmTcUdpBridge::lastAdd - * @param port - */ - static void udp_server_receive_callback(void *arg, - struct udp_pcb *upcb_, struct pbuf *p, const ip_addr_t *addr, - u16_t port); + /** TM Send implementation uses udp_send function from lwIP stack + * @param data + * @param dataLen + * @return + */ + virtual ReturnValue_t sendTm(const uint8_t *data, size_t dataLen) override; - /** - * Check whether the communication link is up. - * Caller must ensure thread-safety by using the bridge lock. - * @return - */ - bool comLinkUp() const; + /** + * @brief This function is called when an UDP datagram has been + * received on the port UDP_PORT. + * @param arg + * @param upcb_ + * @param p + * @param addr Source address which will be bound to TmTcUdpBridge::lastAdd + * @param port + */ + static void udp_server_receive_callback(void *arg, struct udp_pcb *upcb_, struct pbuf *p, + const ip_addr_t *addr, u16_t port); -private: - struct udp_pcb *upcb = nullptr; - ip_addr_t lastAdd; - u16_t lastPort = 0; - bool physicalConnection = false; - MutexIF* bridgeLock = nullptr; + /** + * Check whether the communication link is up. + * Caller must ensure thread-safety by using the bridge lock. + * @return + */ + bool comLinkUp() const; + + private: + struct udp_pcb *upcb = nullptr; + ip_addr_t lastAdd; + u16_t lastPort = 0; + bool physicalConnection = false; + MutexIF *bridgeLock = nullptr; #if TCPIP_RECV_WIRETAPPING == 1 - bool connectFlag = false; + bool connectFlag = false; #endif - /** - * Used to notify bridge about change in the physical ethernet connection. - * Connection does not mean that replies are possible (recipient not set yet), but - * disconnect means that we can't send anything. Caller must ensure thread-safety - * by using the bridge lock. - */ - void physicalConnectStatusChange(bool connect); + /** + * Used to notify bridge about change in the physical ethernet connection. + * Connection does not mean that replies are possible (recipient not set yet), but + * disconnect means that we can't send anything. Caller must ensure thread-safety + * by using the bridge lock. + */ + void physicalConnectStatusChange(bool connect); }; #endif /* BSP_STM32_RTEMS_NETWORKING_TMTCUDPBRIDGE_H_ */ diff --git a/stm32h7/networking/UdpTcLwIpPollingTask.cpp b/stm32h7/networking/UdpTcLwIpPollingTask.cpp index 8aec5f9..aeb70e0 100644 --- a/stm32h7/networking/UdpTcLwIpPollingTask.cpp +++ b/stm32h7/networking/UdpTcLwIpPollingTask.cpp @@ -1,66 +1,60 @@ #include "UdpTcLwIpPollingTask.h" -#include "TmTcLwIpUdpBridge.h" -#include "app_ethernet.h" -#include "ethernetif.h" -#include "app_dhcp.h" -#include "networking.h" + #include +#include "TmTcLwIpUdpBridge.h" +#include "app_dhcp.h" +#include "app_ethernet.h" +#include "ethernetif.h" #include "fsfw/ipc/MutexGuard.h" -#include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/objectmanager/ObjectManager.h" - - - +#include "fsfw/serviceinterface/ServiceInterface.h" #include "lwip/timeouts.h" +#include "networking.h" UdpTcLwIpPollingTask::UdpTcLwIpPollingTask(object_id_t objectId, object_id_t bridgeId, - struct netif* gnetif): - SystemObject(objectId), periodicHandleCounter(0), bridgeId(bridgeId), gnetif(gnetif) { -} + struct netif* gnetif) + : SystemObject(objectId), periodicHandleCounter(0), bridgeId(bridgeId), gnetif(gnetif) {} -UdpTcLwIpPollingTask::~UdpTcLwIpPollingTask() { -} +UdpTcLwIpPollingTask::~UdpTcLwIpPollingTask() {} ReturnValue_t UdpTcLwIpPollingTask::initialize() { - udpBridge = ObjectManager::instance()->get(bridgeId); - if(udpBridge == nullptr) { - return ObjectManagerIF::CHILD_INIT_FAILED; - } - if (netif_is_link_up(gnetif)) { - networking::setEthCableConnected(true); - } - return RETURN_OK; + udpBridge = ObjectManager::instance()->get(bridgeId); + if (udpBridge == nullptr) { + return ObjectManagerIF::CHILD_INIT_FAILED; + } + if (netif_is_link_up(gnetif)) { + networking::setEthCableConnected(true); + } + return RETURN_OK; } - /* Poll the EMAC Interface and pass content to the network interface (lwIP) */ ReturnValue_t UdpTcLwIpPollingTask::performOperation(uint8_t operationCode) { - /* Read a received packet from the Ethernet buffers and send it - to the lwIP for handling */ - ethernetif_input(gnetif); + /* Read a received packet from the Ethernet buffers and send it + to the lwIP for handling */ + ethernetif_input(gnetif); - /* Handle timeouts */ - sys_check_timeouts(); + /* Handle timeouts */ + sys_check_timeouts(); #if LWIP_NETIF_LINK_CALLBACK == 1 - networking::ethernetLinkPeriodicHandle(gnetif); + networking::ethernetLinkPeriodicHandle(gnetif); #endif - if(udpBridge != nullptr) { - MutexGuard lg(udpBridge->bridgeLock); - /* In case ethernet cable is disconnected */ - if(not networking::getEthCableConnected() and udpBridge->comLinkUp()) { - udpBridge->physicalConnectStatusChange(false); - } - else if(networking::getEthCableConnected() and not udpBridge->comLinkUp()) { - udpBridge->physicalConnectStatusChange(true); - } + if (udpBridge != nullptr) { + MutexGuard lg(udpBridge->bridgeLock); + /* In case ethernet cable is disconnected */ + if (not networking::getEthCableConnected() and udpBridge->comLinkUp()) { + udpBridge->physicalConnectStatusChange(false); + } else if (networking::getEthCableConnected() and not udpBridge->comLinkUp()) { + udpBridge->physicalConnectStatusChange(true); } + } #if LWIP_DHCP == 1 - DHCP_Periodic_Handle(gnetif); + DHCP_Periodic_Handle(gnetif); #endif - return RETURN_OK; + return RETURN_OK; } diff --git a/stm32h7/networking/UdpTcLwIpPollingTask.h b/stm32h7/networking/UdpTcLwIpPollingTask.h index 0440650..d9c72c3 100644 --- a/stm32h7/networking/UdpTcLwIpPollingTask.h +++ b/stm32h7/networking/UdpTcLwIpPollingTask.h @@ -2,9 +2,8 @@ #define BSP_STM32_RTEMS_EMACPOLLINGTASK_H_ #include -#include #include - +#include #include class TmTcLwIpUdpBridge; @@ -13,29 +12,28 @@ class TmTcLwIpUdpBridge; * @brief Separate task to poll EMAC interface. * Polled data is passed to the netif (lwIP) */ -class UdpTcLwIpPollingTask: - public SystemObject, - public ExecutableObjectIF, - public HasReturnvaluesIF { -public: - UdpTcLwIpPollingTask(object_id_t objectId, object_id_t bridgeId, struct netif* gnetif); - virtual ~UdpTcLwIpPollingTask(); +class UdpTcLwIpPollingTask : public SystemObject, + public ExecutableObjectIF, + public HasReturnvaluesIF { + public: + UdpTcLwIpPollingTask(object_id_t objectId, object_id_t bridgeId, struct netif* gnetif); + virtual ~UdpTcLwIpPollingTask(); - virtual ReturnValue_t initialize() override; + virtual ReturnValue_t initialize() override; - /** - * Executed periodically. - * @param operationCode - * @return - */ - virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override; -private: - static const uint8_t PERIODIC_HANDLE_TRIGGER = 5; - uint8_t periodicHandleCounter; - object_id_t bridgeId = 0; - TmTcLwIpUdpBridge* udpBridge = nullptr; - struct netif* gnetif = nullptr; + /** + * Executed periodically. + * @param operationCode + * @return + */ + virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override; + + private: + static const uint8_t PERIODIC_HANDLE_TRIGGER = 5; + uint8_t periodicHandleCounter; + object_id_t bridgeId = 0; + TmTcLwIpUdpBridge* udpBridge = nullptr; + struct netif* gnetif = nullptr; }; - #endif /* BSP_STM32_RTEMS_EMACPOLLINGTASK_H_ */ diff --git a/stm32h7/networking/app_dhcp.cpp b/stm32h7/networking/app_dhcp.cpp index 9b2faa6..8d20bed 100644 --- a/stm32h7/networking/app_dhcp.cpp +++ b/stm32h7/networking/app_dhcp.cpp @@ -1,13 +1,12 @@ -#include "OBSWConfig.h" - #include "app_dhcp.h" -#include "app_ethernet.h" -#include "networking.h" -#include "udp_config.h" -#include "ethernetif.h" +#include "OBSWConfig.h" +#include "app_ethernet.h" +#include "ethernetif.h" #include "lwip/dhcp.h" +#include "networking.h" #include "stm32h7xx_nucleo.h" +#include "udp_config.h" #if LWIP_DHCP == 1 @@ -24,57 +23,56 @@ void handle_dhcp_down(struct netif* netif); * @param None * @retval None */ -void DHCP_Process(struct netif *netif) -{ - struct dhcp* dhcp = NULL; - switch (DHCP_state) { +void DHCP_Process(struct netif* netif) { + struct dhcp* dhcp = NULL; + switch (DHCP_state) { case DHCP_START: { - handle_dhcp_start(netif); - break; + handle_dhcp_start(netif); + break; } case DHCP_WAIT_ADDRESS: { - handle_dhcp_wait(netif, &dhcp); - break; + handle_dhcp_wait(netif, &dhcp); + break; } case DHCP_LINK_DOWN: { - handle_dhcp_down(netif); - break; + handle_dhcp_down(netif); + break; } default: { - break; - } + break; } + } } void handle_dhcp_timeout(struct netif* netif) { - ip_addr_t ipaddr; - ip_addr_t netmask; - ip_addr_t gw; + ip_addr_t ipaddr; + ip_addr_t netmask; + ip_addr_t gw; - DHCP_state = DHCP_TIMEOUT; + DHCP_state = DHCP_TIMEOUT; - /* Stop DHCP */ - dhcp_stop(netif); + /* Stop DHCP */ + dhcp_stop(netif); - /* Static address used */ - networking::setLwipAddresses(&ipaddr, &netmask, &gw); - netif_set_addr(netif, &ipaddr, &netmask, &gw); + /* Static address used */ + networking::setLwipAddresses(&ipaddr, &netmask, &gw); + netif_set_addr(netif, &ipaddr, &netmask, &gw); - printf("DHCP Timeout\n\r"); - uint8_t iptxt[20]; - sprintf((char *)iptxt, "%s", ip4addr_ntoa(netif_ip4_addr(netif))); - printf("Assigning static IP address: %s\n", iptxt); + printf("DHCP Timeout\n\r"); + uint8_t iptxt[20]; + sprintf((char*)iptxt, "%s", ip4addr_ntoa(netif_ip4_addr(netif))); + printf("Assigning static IP address: %s\n", iptxt); #if defined FSFW_OSAL_FREERTOS - ETH_HandleTypeDef* handle = getEthernetHandle(); - handle->gState = HAL_ETH_STATE_READY; + ETH_HandleTypeDef* handle = getEthernetHandle(); + handle->gState = HAL_ETH_STATE_READY; #endif #if OBSW_ETHERNET_TMTC_COMMANDING == 1 #if OBSW_ETHERNET_USE_LED1_LED2 == 1 - BSP_LED_On(LED1); - BSP_LED_Off(LED2); + BSP_LED_On(LED1); + BSP_LED_Off(LED2); #endif #endif } @@ -84,74 +82,67 @@ void handle_dhcp_timeout(struct netif* netif) { * @param netif * @retval None */ -void DHCP_Periodic_Handle(struct netif *netif) -{ - /* Fine DHCP periodic process every 500ms */ - if (HAL_GetTick() - DHCPfineTimer >= DHCP_FINE_TIMER_MSECS) { - DHCPfineTimer = HAL_GetTick(); - /* process DHCP state machine */ - DHCP_Process(netif); - } +void DHCP_Periodic_Handle(struct netif* netif) { + /* Fine DHCP periodic process every 500ms */ + if (HAL_GetTick() - DHCPfineTimer >= DHCP_FINE_TIMER_MSECS) { + DHCPfineTimer = HAL_GetTick(); + /* process DHCP state machine */ + DHCP_Process(netif); + } } void handle_dhcp_start(struct netif* netif) { - printf("handle_dhcp_start: Looking for DHCP server ...\n\r"); + printf("handle_dhcp_start: Looking for DHCP server ...\n\r"); #if OBSW_ETHERNET_TMTC_COMMANDING == 1 #if OBSW_ETHERNET_USE_LED1_LED2 == 1 - BSP_LED_Off(LED1); - BSP_LED_Off(LED2); + BSP_LED_Off(LED1); + BSP_LED_Off(LED2); #endif #endif - ip_addr_set_zero_ip4(&netif->ip_addr); - ip_addr_set_zero_ip4(&netif->netmask); - ip_addr_set_zero_ip4(&netif->gw); - dhcp_start(netif); - DHCP_state = DHCP_WAIT_ADDRESS; + ip_addr_set_zero_ip4(&netif->ip_addr); + ip_addr_set_zero_ip4(&netif->netmask); + ip_addr_set_zero_ip4(&netif->gw); + dhcp_start(netif); + DHCP_state = DHCP_WAIT_ADDRESS; } void handle_dhcp_wait(struct netif* netif, struct dhcp** dhcp) { - if (dhcp_supplied_address(netif)) { - DHCP_state = DHCP_ADDRESS_ASSIGNED; - printf("IP address assigned by a DHCP server: %s\n\r", ip4addr_ntoa(netif_ip4_addr(netif))); - printf("Listener port: %d\n\r", UDP_SERVER_PORT); + if (dhcp_supplied_address(netif)) { + DHCP_state = DHCP_ADDRESS_ASSIGNED; + printf("IP address assigned by a DHCP server: %s\n\r", ip4addr_ntoa(netif_ip4_addr(netif))); + printf("Listener port: %d\n\r", UDP_SERVER_PORT); #if OBSW_ETHERNET_TMTC_COMMANDING == 1 #if OBSW_ETHERNET_USE_LED1_LED2 == 1 - BSP_LED_On(LED1); - BSP_LED_Off(LED2); + BSP_LED_On(LED1); + BSP_LED_Off(LED2); #endif #endif - } - else { - *dhcp = (struct dhcp*) netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP); + } else { + *dhcp = (struct dhcp*)netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP); - /* DHCP timeout */ - if ((*dhcp)->tries > MAX_DHCP_TRIES) - { - handle_dhcp_timeout(netif); - } + /* DHCP timeout */ + if ((*dhcp)->tries > MAX_DHCP_TRIES) { + handle_dhcp_timeout(netif); } + } } void handle_dhcp_down(struct netif* netif) { - DHCP_state = DHCP_OFF; + DHCP_state = DHCP_OFF; #if OBSW_ETHERNET_TMTC_COMMANDING == 1 - printf("DHCP_Process: The network cable is not connected.\n\r"); + printf("DHCP_Process: The network cable is not connected.\n\r"); #if OBSW_ETHERNET_USE_LED1_LED2 == 1 - BSP_LED_Off(LED1); - BSP_LED_On(LED2); + BSP_LED_Off(LED1); + BSP_LED_On(LED2); #endif #endif - /* Global boolean to track ethernet connection */ - networking::setEthCableConnected(false); + /* Global boolean to track ethernet connection */ + networking::setEthCableConnected(false); } -uint8_t get_dhcp_state() { - return DHCP_state; -} +uint8_t get_dhcp_state() { return DHCP_state; } -void set_dhcp_state(uint8_t new_state) { - DHCP_state = new_state; -} +void set_dhcp_state(uint8_t new_state) { DHCP_state = new_state; } #endif /* LWIP_DHCP == 1 */ diff --git a/stm32h7/networking/app_dhcp.h b/stm32h7/networking/app_dhcp.h index d077275..1c67423 100644 --- a/stm32h7/networking/app_dhcp.h +++ b/stm32h7/networking/app_dhcp.h @@ -12,12 +12,12 @@ extern "C" { #include "lwip/netif.h" /* DHCP process states */ -#define DHCP_OFF (uint8_t) 0 -#define DHCP_START (uint8_t) 1 -#define DHCP_WAIT_ADDRESS (uint8_t) 2 -#define DHCP_ADDRESS_ASSIGNED (uint8_t) 3 -#define DHCP_TIMEOUT (uint8_t) 4 -#define DHCP_LINK_DOWN (uint8_t) 5 +#define DHCP_OFF (uint8_t)0 +#define DHCP_START (uint8_t)1 +#define DHCP_WAIT_ADDRESS (uint8_t)2 +#define DHCP_ADDRESS_ASSIGNED (uint8_t)3 +#define DHCP_TIMEOUT (uint8_t)4 +#define DHCP_LINK_DOWN (uint8_t)5 uint8_t get_dhcp_state(); void set_dhcp_state(uint8_t new_state); diff --git a/stm32h7/networking/app_ethernet.cpp b/stm32h7/networking/app_ethernet.cpp index 86c120c..068a029 100644 --- a/stm32h7/networking/app_ethernet.cpp +++ b/stm32h7/networking/app_ethernet.cpp @@ -1,17 +1,18 @@ /* Includes ------------------------------------------------------------------*/ #include "app_ethernet.h" + #include "ethernetif.h" -#include "udp_config.h" #include "networking.h" +#include "udp_config.h" #if LWIP_DHCP #include "app_dhcp.h" #endif -#include -#include -#include #include +#include +#include +#include /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ @@ -22,55 +23,49 @@ uint32_t ethernetLinkTimer = 0; /* Private function prototypes -----------------------------------------------*/ void handle_status_change(struct netif* netif, bool link_up); - /* Private functions ---------------------------------------------------------*/ /** * @brief Notify the User about the network interface config status * @param netif: the network interface * @retval None */ -void networking::ethernetLinkStatusUpdated(struct netif *netif) -{ - if (netif_is_link_up(netif)) - { - networking::setEthCableConnected(true); - handle_status_change(netif, true); - } - else - { - networking::setEthCableConnected(false); - handle_status_change(netif, false); - } +void networking::ethernetLinkStatusUpdated(struct netif* netif) { + if (netif_is_link_up(netif)) { + networking::setEthCableConnected(true); + handle_status_change(netif, true); + } else { + networking::setEthCableConnected(false); + handle_status_change(netif, false); + } } void handle_status_change(struct netif* netif, bool link_up) { - if(link_up) { + if (link_up) { #if LWIP_DHCP - /* Update DHCP state machine */ - set_dhcp_state(DHCP_START); + /* Update DHCP state machine */ + set_dhcp_state(DHCP_START); #else - uint8_t iptxt[20]; - sprintf((char *)iptxt, "%s", ip4addr_ntoa(netif_ip4_addr(netif))); - printf("\rNetwork cable connected. Static IP address: %s | Port: %d\n\r", iptxt, - UDP_SERVER_PORT); + uint8_t iptxt[20]; + sprintf((char*)iptxt, "%s", ip4addr_ntoa(netif_ip4_addr(netif))); + printf("\rNetwork cable connected. Static IP address: %s | Port: %d\n\r", iptxt, + UDP_SERVER_PORT); #if OBSW_ETHERNET_USE_LED1_LED2 == 1 - BSP_LED_On(LED1); - BSP_LED_Off(LED2); + BSP_LED_On(LED1); + BSP_LED_Off(LED2); #endif #endif /* LWIP_DHCP */ - } - else { - printf("Network cable disconnected\n\r"); + } else { + printf("Network cable disconnected\n\r"); #if LWIP_DHCP - /* Update DHCP state machine */ - set_dhcp_state(DHCP_LINK_DOWN); + /* Update DHCP state machine */ + set_dhcp_state(DHCP_LINK_DOWN); #else #if OBSW_ETHERNET_USE_LED1_LED2 == 1 - BSP_LED_Off(LED1); - BSP_LED_On(LED2); + BSP_LED_Off(LED1); + BSP_LED_On(LED2); #endif #endif /* LWIP_DHCP */ - } + } } #if LWIP_NETIF_LINK_CALLBACK @@ -80,14 +75,12 @@ void handle_status_change(struct netif* netif, bool link_up) { * @param netif * @retval None */ -void networking::ethernetLinkPeriodicHandle(struct netif *netif) -{ - /* Ethernet Link every 100ms */ - if (HAL_GetTick() - ethernetLinkTimer >= 100) - { - ethernetLinkTimer = HAL_GetTick(); - ethernet_link_check_state(netif); - } +void networking::ethernetLinkPeriodicHandle(struct netif* netif) { + /* Ethernet Link every 100ms */ + if (HAL_GetTick() - ethernetLinkTimer >= 100) { + ethernetLinkTimer = HAL_GetTick(); + ethernet_link_check_state(netif); + } } #endif /* LWIP_NETIF_LINK_CALLBACK */ diff --git a/stm32h7/networking/app_ethernet.h b/stm32h7/networking/app_ethernet.h index f0cd403..4662ff3 100644 --- a/stm32h7/networking/app_ethernet.h +++ b/stm32h7/networking/app_ethernet.h @@ -1,54 +1,54 @@ /** - ****************************************************************************** - * @file LwIP/LwIP_UDP_Echo_Client/Inc/app_ethernet.h - * @author MCD Application Team - * @brief Header for app_ethernet.c module - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2017 STMicroelectronics International N.V. - * All rights reserved.

- * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted, provided that the following conditions are met: - * - * 1. Redistribution of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of other - * contributors to this software may be used to endorse or promote products - * derived from this software without specific written permission. - * 4. This software, including modifications and/or derivative works of this - * software, must execute solely and exclusively on microcontroller or - * microprocessor devices manufactured by or for STMicroelectronics. - * 5. Redistribution and use of this software other than as permitted under - * this license is void and will automatically terminate your rights under - * this license. - * - * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY - * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT - * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file LwIP/LwIP_UDP_Echo_Client/Inc/app_ethernet.h + * @author MCD Application Team + * @brief Header for app_ethernet.c module + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2017 STMicroelectronics International N.V. + * All rights reserved.

+ * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted, provided that the following conditions are met: + * + * 1. Redistribution of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of other + * contributors to this software may be used to endorse or promote products + * derived from this software without specific written permission. + * 4. This software, including modifications and/or derivative works of this + * software, must execute solely and exclusively on microcontroller or + * microprocessor devices manufactured by or for STMicroelectronics. + * 5. Redistribution and use of this software other than as permitted under + * this license is void and will automatically terminate your rights under + * this license. + * + * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY + * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT + * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef EXAMPLE_COMMON_APP_ETHERNET_H #define EXAMPLE_COMMON_APP_ETHERNET_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -65,7 +65,7 @@ namespace networking { void ethernetLinkStatusUpdated(struct netif *netif); void ethernetLinkPeriodicHandle(struct netif *netif); -} +} // namespace networking #ifdef __cplusplus } @@ -73,6 +73,4 @@ void ethernetLinkPeriodicHandle(struct netif *netif); #endif /* EXAMPLE_COMMON_APP_ETHERNET_H */ - /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ - diff --git a/stm32h7/networking/ethernetif.c b/stm32h7/networking/ethernetif.c index e3de288..8cc50b8 100644 --- a/stm32h7/networking/ethernetif.c +++ b/stm32h7/networking/ethernetif.c @@ -1,59 +1,60 @@ /** - ****************************************************************************** - * @file LwIP/LwIP_UDP_Echo_Client/Src/ethernetif.c - * @author MCD Application Team - * @brief This file implements Ethernet network interface drivers for lwIP - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2017 STMicroelectronics International N.V. - * All rights reserved.

- * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted, provided that the following conditions are met: - * - * 1. Redistribution of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of other - * contributors to this software may be used to endorse or promote products - * derived from this software without specific written permission. - * 4. This software, including modifications and/or derivative works of this - * software, must execute solely and exclusively on microcontroller or - * microprocessor devices manufactured by or for STMicroelectronics. - * 5. Redistribution and use of this software other than as permitted under - * this license is void and will automatically terminate your rights under - * this license. - * - * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY - * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT - * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file LwIP/LwIP_UDP_Echo_Client/Src/ethernetif.c + * @author MCD Application Team + * @brief This file implements Ethernet network interface drivers for lwIP + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2017 STMicroelectronics International N.V. + * All rights reserved.

+ * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted, provided that the following conditions are met: + * + * 1. Redistribution of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of other + * contributors to this software may be used to endorse or promote products + * derived from this software without specific written permission. + * 4. This software, including modifications and/or derivative works of this + * software, must execute solely and exclusively on microcontroller or + * microprocessor devices manufactured by or for STMicroelectronics. + * 5. Redistribution and use of this software other than as permitted under + * this license is void and will automatically terminate your rights under + * this license. + * + * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY + * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT + * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ /* Includes ------------------------------------------------------------------*/ -#include "fsfw/FSFW.h" #include "ethernetif.h" -#include #include -#include #include #include #include #include +#include +#include + +#include "fsfw/FSFW.h" #ifdef FSFW_OSAL_RTEMS #include @@ -69,17 +70,17 @@ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ -/* +/* @Note: This interface is implemented to operate in zero-copy mode only: - Rx buffers are allocated statically and passed directly to the LwIP stack they will return back to DMA after been processed by the stack. - - Tx Buffers will be allocated from LwIP stack memory heap, + - Tx Buffers will be allocated from LwIP stack memory heap, then passed to ETH HAL driver. -@Notes: - 1.a. ETH DMA Rx descriptors must be contiguous, the default count is 4, +@Notes: + 1.a. ETH DMA Rx descriptors must be contiguous, the default count is 4, to customize it please redefine ETH_RX_DESC_CNT in stm32xxxx_hal_conf.h - 1.b. ETH DMA Tx descriptors must be contiguous, the default count is 4, + 1.b. ETH DMA Tx descriptors must be contiguous, the default count is 4, to customize it please redefine ETH_TX_DESC_CNT in stm32xxxx_hal_conf.h 2.a. Rx Buffers number must be between ETH_RX_DESC_CNT and 2*ETH_RX_DESC_CNT @@ -87,35 +88,45 @@ passed to ETH DMA in the init field (EthHandle.Init.RxBuffLen) */ -#if defined ( __ICCARM__ ) /*!< IAR Compiler */ +#if defined(__ICCARM__) /*!< IAR Compiler */ -#pragma location=0x30040000 -ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT]; /* Ethernet Rx DMA Descriptors */ -#pragma location=0x30040060 -ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT]; /* Ethernet Tx DMA Descriptors */ -#pragma location=0x30040200 +#pragma location = 0x30040000 +ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT]; /* Ethernet Rx DMA Descriptors */ +#pragma location = 0x30040060 +ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT]; /* Ethernet Tx DMA Descriptors */ +#pragma location = 0x30040200 uint8_t Rx_Buff[ETH_RX_DESC_CNT][ETH_RX_BUFFER_SIZE]; /* Ethernet Receive Buffers */ -#elif defined ( __CC_ARM ) /* MDK ARM Compiler */ +#elif defined(__CC_ARM) /* MDK ARM Compiler */ -__attribute__((section(".RxDecripSection"))) ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT]; /* Ethernet Rx DMA Descriptors */ -__attribute__((section(".TxDecripSection"))) ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT]; /* Ethernet Tx DMA Descriptors */ -__attribute__((section(".RxArraySection"))) uint8_t Rx_Buff[ETH_RX_DESC_CNT][ETH_RX_BUFFER_SIZE]; /* Ethernet Receive Buffer */ +__attribute__((section(".RxDecripSection"))) +ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT]; /* Ethernet Rx DMA Descriptors */ +__attribute__((section(".TxDecripSection"))) +ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT]; /* Ethernet Tx DMA Descriptors */ +__attribute__((section(".RxArraySection"))) +uint8_t Rx_Buff[ETH_RX_DESC_CNT][ETH_RX_BUFFER_SIZE]; /* Ethernet Receive Buffer */ -#elif defined ( __GNUC__ ) /* GNU Compiler */ +#elif defined(__GNUC__) /* GNU Compiler */ #ifdef FSFW_OSAL_RTEMS /* Put into special RTEMS section and align correctly */ -ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT] __attribute__((section(".bsp_nocache"), __aligned__(DMA_DESCRIPTOR_ALIGNMENT))); /* Ethernet Rx DMA Descriptors */ +ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT] + __attribute__((section(".bsp_nocache"), + __aligned__(DMA_DESCRIPTOR_ALIGNMENT))); /* Ethernet Rx DMA Descriptors */ /* Put into special RTEMS section and align correctly */ -ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT] __attribute__((section(".bsp_nocache"), __aligned__(DMA_DESCRIPTOR_ALIGNMENT))); /* Ethernet Tx DMA Descriptors */ +ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT] + __attribute__((section(".bsp_nocache"), + __aligned__(DMA_DESCRIPTOR_ALIGNMENT))); /* Ethernet Tx DMA Descriptors */ /* Ethernet Receive Buffers. Just place somewhere is BSS instead of explicitely placing it */ uint8_t Rx_Buff[ETH_RX_DESC_CNT][ETH_RX_BUFFER_SIZE]; #elif defined FSFW_OSAL_FREERTOS /* Placement and alignment specified in linker script here */ -ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT] __attribute__((section(".RxDecripSection"))); /* Ethernet Rx DMA Descriptors */ -ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT] __attribute__((section(".TxDecripSection"))); /* Ethernet Tx DMA Descriptors */ -uint8_t Rx_Buff[ETH_RX_DESC_CNT][ETH_RX_BUFFER_SIZE] __attribute__((section(".RxArraySection"))); /* Ethernet Receive Buffers */ +ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT] + __attribute__((section(".RxDecripSection"))); /* Ethernet Rx DMA Descriptors */ +ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT] + __attribute__((section(".TxDecripSection"))); /* Ethernet Tx DMA Descriptors */ +uint8_t Rx_Buff[ETH_RX_DESC_CNT][ETH_RX_BUFFER_SIZE] + __attribute__((section(".RxArraySection"))); /* Ethernet Receive Buffers */ #endif /* FSFW_FREERTOS */ #endif /* defined ( __GNUC__ ) */ @@ -124,10 +135,10 @@ uint8_t Rx_Buff[ETH_RX_DESC_CNT][ETH_RX_BUFFER_SIZE] __attribute__((section(".Rx bool ethernet_cable_connected; struct pbuf_custom rx_pbuf[ETH_RX_DESC_CNT]; -uint32_t current_pbuf_idx =0; +uint32_t current_pbuf_idx = 0; ETH_HandleTypeDef EthHandle; -ETH_TxPacketConfig TxConfig; +ETH_TxPacketConfig TxConfig; lan8742_Object_t LAN8742; @@ -136,71 +147,66 @@ u32_t sys_now(void); void pbuf_free_custom(struct pbuf *p); int32_t ETH_PHY_IO_Init(void); -int32_t ETH_PHY_IO_DeInit (void); +int32_t ETH_PHY_IO_DeInit(void); int32_t ETH_PHY_IO_ReadReg(uint32_t DevAddr, uint32_t RegAddr, uint32_t *pRegVal); int32_t ETH_PHY_IO_WriteReg(uint32_t DevAddr, uint32_t RegAddr, uint32_t RegVal); int32_t ETH_PHY_IO_GetTick(void); - -lan8742_IOCtx_t LAN8742_IOCtx = {ETH_PHY_IO_Init, - ETH_PHY_IO_DeInit, - ETH_PHY_IO_WriteReg, - ETH_PHY_IO_ReadReg, - ETH_PHY_IO_GetTick}; +lan8742_IOCtx_t LAN8742_IOCtx = {ETH_PHY_IO_Init, ETH_PHY_IO_DeInit, ETH_PHY_IO_WriteReg, + ETH_PHY_IO_ReadReg, ETH_PHY_IO_GetTick}; /* Private functions ---------------------------------------------------------*/ /******************************************************************************* - LL Driver Interface ( LwIP stack --> ETH) + LL Driver Interface ( LwIP stack --> ETH) *******************************************************************************/ /** - * @brief In this function, the hardware should be initialized. - * Called from ethernetif_init(). - * - * @param netif the already initialized lwip network interface structure - * for this ethernetif - */ -static void low_level_init(struct netif *netif) -{ + * @brief In this function, the hardware should be initialized. + * Called from ethernetif_init(). + * + * @param netif the already initialized lwip network interface structure + * for this ethernetif + */ +static void low_level_init(struct netif *netif) { uint32_t idx = 0; - uint8_t macaddress[6]= {ETH_MAC_ADDR0, ETH_MAC_ADDR1, ETH_MAC_ADDR2, ETH_MAC_ADDR3, ETH_MAC_ADDR4, ETH_MAC_ADDR5}; - - EthHandle.Instance = ETH; + uint8_t macaddress[6] = {ETH_MAC_ADDR0, ETH_MAC_ADDR1, ETH_MAC_ADDR2, + ETH_MAC_ADDR3, ETH_MAC_ADDR4, ETH_MAC_ADDR5}; + + EthHandle.Instance = ETH; EthHandle.Init.MACAddr = macaddress; EthHandle.Init.MediaInterface = HAL_ETH_RMII_MODE; EthHandle.Init.RxDesc = DMARxDscrTab; EthHandle.Init.TxDesc = DMATxDscrTab; EthHandle.Init.RxBuffLen = ETH_RX_BUFFER_SIZE; - + /* configure ethernet peripheral (GPIOs, clocks, MAC, DMA) */ HAL_ETH_Init(&EthHandle); /* set MAC hardware address length */ netif->hwaddr_len = ETHARP_HWADDR_LEN; - + /* set MAC hardware address */ - netif->hwaddr[0] = 0x02; - netif->hwaddr[1] = 0x00; - netif->hwaddr[2] = 0x00; - netif->hwaddr[3] = 0x00; - netif->hwaddr[4] = 0x00; - netif->hwaddr[5] = 0x00; - + netif->hwaddr[0] = 0x02; + netif->hwaddr[1] = 0x00; + netif->hwaddr[2] = 0x00; + netif->hwaddr[3] = 0x00; + netif->hwaddr[4] = 0x00; + netif->hwaddr[5] = 0x00; + /* maximum transfer unit */ netif->mtu = ETH_MAX_PAYLOAD; - + /* device capabilities */ /* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */ netif->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP; - - for(idx = 0; idx < ETH_RX_DESC_CNT; idx ++) - { + + for (idx = 0; idx < ETH_RX_DESC_CNT; idx++) { HAL_ETH_DescAssignMemory(&EthHandle, idx, Rx_Buff[idx], NULL); - + /* Set Custom pbuf free function */ rx_pbuf[idx].custom_free_function = pbuf_free_custom; } - + /* Set Tx packet config common parameters */ - memset(&TxConfig, 0 , sizeof(ETH_TxPacketConfig)); + memset(&TxConfig, 0, sizeof(ETH_TxPacketConfig)); TxConfig.Attributes = ETH_TX_PACKETS_FEATURES_CSUM | ETH_TX_PACKETS_FEATURES_CRCPAD; TxConfig.ChecksumCtrl = ETH_CHECKSUM_IPHDR_PAYLOAD_INSERT_PHDR_CALC; TxConfig.CRCPadCtrl = ETH_CRC_PAD_INSERT; @@ -212,47 +218,41 @@ static void low_level_init(struct netif *netif) LAN8742_Init(&LAN8742); ethernet_link_check_state(netif); - } /** - * @brief This function should do the actual transmission of the packet. The packet is - * contained in the pbuf that is passed to the function. This pbuf - * might be chained. - * - * @param netif the lwip network interface structure for this ethernetif - * @param p the MAC packet to send (e.g. IP packet including MAC addresses and type) - * @return ERR_OK if the packet could be sent - * an err_t value if the packet couldn't be sent - * - * @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to - * strange results. You might consider waiting for space in the DMA queue - * to become availale since the stack doesn't retry to send a packet - * dropped because of memory failure (except for the TCP timers). - */ -static err_t low_level_output(struct netif *netif, struct pbuf *p) -{ - uint32_t i=0, framelen = 0; + * @brief This function should do the actual transmission of the packet. The packet is + * contained in the pbuf that is passed to the function. This pbuf + * might be chained. + * + * @param netif the lwip network interface structure for this ethernetif + * @param p the MAC packet to send (e.g. IP packet including MAC addresses and type) + * @return ERR_OK if the packet could be sent + * an err_t value if the packet couldn't be sent + * + * @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to + * strange results. You might consider waiting for space in the DMA queue + * to become availale since the stack doesn't retry to send a packet + * dropped because of memory failure (except for the TCP timers). + */ +static err_t low_level_output(struct netif *netif, struct pbuf *p) { + uint32_t i = 0, framelen = 0; struct pbuf *q; err_t errval = ERR_OK; ETH_BufferTypeDef Txbuffer[ETH_TX_DESC_CNT]; - - for(q = p; q != NULL; q = q->next) - { - if(i >= ETH_TX_DESC_CNT) - return ERR_IF; - + + for (q = p; q != NULL; q = q->next) { + if (i >= ETH_TX_DESC_CNT) return ERR_IF; + Txbuffer[i].buffer = q->payload; Txbuffer[i].len = q->len; framelen += q->len; - - if(i>0) - { - Txbuffer[i-1].next = &Txbuffer[i]; + + if (i > 0) { + Txbuffer[i - 1].next = &Txbuffer[i]; } - - if(q->next == NULL) - { + + if (q->next == NULL) { Txbuffer[i].next = NULL; } @@ -264,67 +264,60 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p) HAL_StatusTypeDef ret = HAL_ETH_Transmit(&EthHandle, &TxConfig, 20); - if(ret != HAL_OK) { - printf("low_level_output: Could not transmit ethernet packet, code %d!\n\r", ret); + if (ret != HAL_OK) { + printf("low_level_output: Could not transmit ethernet packet, code %d!\n\r", ret); } - + return errval; } /** - * @brief Should allocate a pbuf and transfer the bytes of the incoming - * packet from the interface into the pbuf. - * - * @param netif the lwip network interface structure for this ethernetif - * @return a pbuf filled with the received packet (including MAC header) - * NULL on memory error - */ -static struct pbuf * low_level_input(struct netif *netif) -{ + * @brief Should allocate a pbuf and transfer the bytes of the incoming + * packet from the interface into the pbuf. + * + * @param netif the lwip network interface structure for this ethernetif + * @return a pbuf filled with the received packet (including MAC header) + * NULL on memory error + */ +static struct pbuf *low_level_input(struct netif *netif) { struct pbuf *p = NULL; ETH_BufferTypeDef RxBuff; uint32_t framelength = 0; - if (HAL_ETH_IsRxDataAvailable(&EthHandle)) - { + if (HAL_ETH_IsRxDataAvailable(&EthHandle)) { HAL_ETH_GetRxDataBuffer(&EthHandle, &RxBuff); HAL_ETH_GetRxDataLength(&EthHandle, &framelength); - + /* Invalidate data cache for ETH Rx Buffers */ - SCB_InvalidateDCache_by_Addr((uint32_t *)Rx_Buff, (ETH_RX_DESC_CNT*ETH_RX_BUFFER_SIZE)); - - p = pbuf_alloced_custom(PBUF_RAW, framelength, PBUF_POOL, &rx_pbuf[current_pbuf_idx], RxBuff.buffer, ETH_RX_BUFFER_SIZE); - if(current_pbuf_idx < (ETH_RX_DESC_CNT -1)) - { + SCB_InvalidateDCache_by_Addr((uint32_t *)Rx_Buff, (ETH_RX_DESC_CNT * ETH_RX_BUFFER_SIZE)); + + p = pbuf_alloced_custom(PBUF_RAW, framelength, PBUF_POOL, &rx_pbuf[current_pbuf_idx], + RxBuff.buffer, ETH_RX_BUFFER_SIZE); + if (current_pbuf_idx < (ETH_RX_DESC_CNT - 1)) { current_pbuf_idx++; - } - else - { + } else { current_pbuf_idx = 0; } return p; - } - else - { + } else { return NULL; } } /** - * @brief This function is the ethernetif_input task, it is processed when a packet - * is ready to be read from the interface. It uses the function low_level_input() - * that should handle the actual reception of bytes from the network - * interface. Then the type of the received packet is determined and - * the appropriate input function is called. - * - * @param netif the lwip network interface structure for this ethernetif - */ -void ethernetif_input(struct netif *netif) -{ + * @brief This function is the ethernetif_input task, it is processed when a packet + * is ready to be read from the interface. It uses the function low_level_input() + * that should handle the actual reception of bytes from the network + * interface. Then the type of the received packet is determined and + * the appropriate input function is called. + * + * @param netif the lwip network interface structure for this ethernetif + */ +void ethernetif_input(struct netif *netif) { err_t err; struct pbuf *p; - + /* move received packet into a new pbuf */ p = low_level_input(netif); @@ -334,8 +327,7 @@ void ethernetif_input(struct netif *netif) /* entry point to the LwIP stack */ err = netif->input(p, netif); - if (err != ERR_OK) - { + if (err != ERR_OK) { LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n")); pbuf_free(p); p = NULL; @@ -345,19 +337,18 @@ void ethernetif_input(struct netif *netif) } /** - * @brief Should be called at the beginning of the program to set up the - * network interface. It calls the function low_level_init() to do the - * actual setup of the hardware. - * - * This function should be passed as a parameter to netif_add(). - * - * @param netif the lwip network interface structure for this ethernetif - * @return ERR_OK if the loopif is initialized - * ERR_MEM if private data couldn't be allocated - * any other err_t on error - */ -err_t ethernetif_init(struct netif *netif) -{ + * @brief Should be called at the beginning of the program to set up the + * network interface. It calls the function low_level_init() to do the + * actual setup of the hardware. + * + * This function should be passed as a parameter to netif_add(). + * + * @param netif the lwip network interface structure for this ethernetif + * @return ERR_OK if the loopif is initialized + * ERR_MEM if private data couldn't be allocated + * any other err_t on error + */ +err_t ethernetif_init(struct netif *netif) { LWIP_ASSERT("netif != NULL", (netif != NULL)); #if LWIP_NETIF_HOSTNAME @@ -381,14 +372,12 @@ err_t ethernetif_init(struct netif *netif) } /** - * @brief Custom Rx pbuf free callback - * @param pbuf: pbuf to be freed - * @retval None - */ -void pbuf_free_custom(struct pbuf *p) -{ - if(p != NULL) - { + * @brief Custom Rx pbuf free callback + * @param pbuf: pbuf to be freed + * @retval None + */ +void pbuf_free_custom(struct pbuf *p) { + if (p != NULL) { p->flags = 0; p->next = NULL; p->len = p->tot_len = 0; @@ -398,37 +387,33 @@ void pbuf_free_custom(struct pbuf *p) } /** - * @brief Returns the current time in milliseconds - * when LWIP_TIMERS == 1 and NO_SYS == 1 - * @param None - * @retval Current Time value - */ -u32_t sys_now(void) -{ - return HAL_GetTick(); -} + * @brief Returns the current time in milliseconds + * when LWIP_TIMERS == 1 and NO_SYS == 1 + * @param None + * @retval Current Time value + */ +u32_t sys_now(void) { return HAL_GetTick(); } /******************************************************************************* Ethernet MSP Routines *******************************************************************************/ /** - * @brief Initializes the ETH MSP. - * @param heth: ETH handle - * @retval None -*/ -void HAL_ETH_MspInit(ETH_HandleTypeDef *heth) -{ + * @brief Initializes the ETH MSP. + * @param heth: ETH handle + * @retval None + */ +void HAL_ETH_MspInit(ETH_HandleTypeDef *heth) { GPIO_InitTypeDef GPIO_InitStructure; - + /* Ethernett MSP init: RMII Mode */ - + /* Enable GPIOs clocks */ __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOG_CLK_ENABLE(); -/* Ethernet pins configuration ************************************************/ + /* Ethernet pins configuration ************************************************/ /* RMII_REF_CLK ----------------------> PA1 RMII_MDIO -------------------------> PA2 @@ -445,29 +430,29 @@ void HAL_ETH_MspInit(ETH_HandleTypeDef *heth) /* Configure PA1, PA2 and PA7 */ GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH; GPIO_InitStructure.Mode = GPIO_MODE_AF_PP; - GPIO_InitStructure.Pull = GPIO_NOPULL; + GPIO_InitStructure.Pull = GPIO_NOPULL; GPIO_InitStructure.Alternate = GPIO_AF11_ETH; GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_7; HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); - + /* Configure PB13 */ GPIO_InitStructure.Pin = GPIO_PIN_13; HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); - + /* Configure PC1, PC4 and PC5 */ GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5; HAL_GPIO_Init(GPIOC, &GPIO_InitStructure); /* Configure PG2, PG11, PG13 and PG14 */ - GPIO_InitStructure.Pin = GPIO_PIN_2 | GPIO_PIN_11 | GPIO_PIN_13; - HAL_GPIO_Init(GPIOG, &GPIO_InitStructure); - + GPIO_InitStructure.Pin = GPIO_PIN_2 | GPIO_PIN_11 | GPIO_PIN_13; + HAL_GPIO_Init(GPIOG, &GPIO_InitStructure); + #if NO_SYS == 0 /* Enable the Ethernet global Interrupt */ HAL_NVIC_SetPriority(ETH_IRQn, 0x7, 0); HAL_NVIC_EnableIRQ(ETH_IRQn); #endif - + /* Enable Ethernet clocks */ __HAL_RCC_ETH1MAC_CLK_ENABLE(); __HAL_RCC_ETH1TX_CLK_ENABLE(); @@ -478,123 +463,106 @@ void HAL_ETH_MspInit(ETH_HandleTypeDef *heth) PHI IO Functions *******************************************************************************/ /** - * @brief Initializes the MDIO interface GPIO and clocks. - * @param None - * @retval 0 if OK, -1 if ERROR - */ -int32_t ETH_PHY_IO_Init(void) -{ + * @brief Initializes the MDIO interface GPIO and clocks. + * @param None + * @retval 0 if OK, -1 if ERROR + */ +int32_t ETH_PHY_IO_Init(void) { /* We assume that MDIO GPIO configuration is already done - in the ETH_MspInit() else it should be done here + in the ETH_MspInit() else it should be done here */ - + /* Configure the MDIO Clock */ HAL_ETH_SetMDIOClockRange(&EthHandle); - + return 0; } /** - * @brief De-Initializes the MDIO interface . - * @param None - * @retval 0 if OK, -1 if ERROR - */ -int32_t ETH_PHY_IO_DeInit (void) -{ - return 0; -} + * @brief De-Initializes the MDIO interface . + * @param None + * @retval 0 if OK, -1 if ERROR + */ +int32_t ETH_PHY_IO_DeInit(void) { return 0; } /** - * @brief Read a PHY register through the MDIO interface. - * @param DevAddr: PHY port address - * @param RegAddr: PHY register address - * @param pRegVal: pointer to hold the register value - * @retval 0 if OK -1 if Error - */ -int32_t ETH_PHY_IO_ReadReg(uint32_t DevAddr, uint32_t RegAddr, uint32_t *pRegVal) -{ - if(HAL_ETH_ReadPHYRegister(&EthHandle, DevAddr, RegAddr, pRegVal) != HAL_OK) - { + * @brief Read a PHY register through the MDIO interface. + * @param DevAddr: PHY port address + * @param RegAddr: PHY register address + * @param pRegVal: pointer to hold the register value + * @retval 0 if OK -1 if Error + */ +int32_t ETH_PHY_IO_ReadReg(uint32_t DevAddr, uint32_t RegAddr, uint32_t *pRegVal) { + if (HAL_ETH_ReadPHYRegister(&EthHandle, DevAddr, RegAddr, pRegVal) != HAL_OK) { return -1; } - + return 0; } /** - * @brief Write a value to a PHY register through the MDIO interface. - * @param DevAddr: PHY port address - * @param RegAddr: PHY register address - * @param RegVal: Value to be written - * @retval 0 if OK -1 if Error - */ -int32_t ETH_PHY_IO_WriteReg(uint32_t DevAddr, uint32_t RegAddr, uint32_t RegVal) -{ - if(HAL_ETH_WritePHYRegister(&EthHandle, DevAddr, RegAddr, RegVal) != HAL_OK) - { + * @brief Write a value to a PHY register through the MDIO interface. + * @param DevAddr: PHY port address + * @param RegAddr: PHY register address + * @param RegVal: Value to be written + * @retval 0 if OK -1 if Error + */ +int32_t ETH_PHY_IO_WriteReg(uint32_t DevAddr, uint32_t RegAddr, uint32_t RegVal) { + if (HAL_ETH_WritePHYRegister(&EthHandle, DevAddr, RegAddr, RegVal) != HAL_OK) { return -1; } - + return 0; } /** - * @brief Get the time in millisecons used for internal PHY driver process. - * @retval Time value - */ -int32_t ETH_PHY_IO_GetTick(void) -{ - return HAL_GetTick(); -} + * @brief Get the time in millisecons used for internal PHY driver process. + * @retval Time value + */ +int32_t ETH_PHY_IO_GetTick(void) { return HAL_GetTick(); } /** - * @brief - * @retval None - */ -void ethernet_link_check_state(struct netif *netif) -{ + * @brief + * @retval None + */ +void ethernet_link_check_state(struct netif *netif) { ETH_MACConfigTypeDef MACConf; uint32_t PHYLinkState; - uint32_t linkchanged = 0, speed = 0, duplex =0; - + uint32_t linkchanged = 0, speed = 0, duplex = 0; + PHYLinkState = LAN8742_GetLinkState(&LAN8742); - if(netif_is_link_up(netif) && (PHYLinkState <= LAN8742_STATUS_LINK_DOWN)) - { + if (netif_is_link_up(netif) && (PHYLinkState <= LAN8742_STATUS_LINK_DOWN)) { HAL_ETH_Stop(&EthHandle); netif_set_down(netif); netif_set_link_down(netif); - } - else if(!netif_is_link_up(netif) && (PHYLinkState > LAN8742_STATUS_LINK_DOWN)) - { - switch (PHYLinkState) - { - case LAN8742_STATUS_100MBITS_FULLDUPLEX: - duplex = ETH_FULLDUPLEX_MODE; - speed = ETH_SPEED_100M; - linkchanged = 1; - break; - case LAN8742_STATUS_100MBITS_HALFDUPLEX: - duplex = ETH_HALFDUPLEX_MODE; - speed = ETH_SPEED_100M; - linkchanged = 1; - break; - case LAN8742_STATUS_10MBITS_FULLDUPLEX: - duplex = ETH_FULLDUPLEX_MODE; - speed = ETH_SPEED_10M; - linkchanged = 1; - break; - case LAN8742_STATUS_10MBITS_HALFDUPLEX: - duplex = ETH_HALFDUPLEX_MODE; - speed = ETH_SPEED_10M; - linkchanged = 1; - break; - default: - break; + } else if (!netif_is_link_up(netif) && (PHYLinkState > LAN8742_STATUS_LINK_DOWN)) { + switch (PHYLinkState) { + case LAN8742_STATUS_100MBITS_FULLDUPLEX: + duplex = ETH_FULLDUPLEX_MODE; + speed = ETH_SPEED_100M; + linkchanged = 1; + break; + case LAN8742_STATUS_100MBITS_HALFDUPLEX: + duplex = ETH_HALFDUPLEX_MODE; + speed = ETH_SPEED_100M; + linkchanged = 1; + break; + case LAN8742_STATUS_10MBITS_FULLDUPLEX: + duplex = ETH_FULLDUPLEX_MODE; + speed = ETH_SPEED_10M; + linkchanged = 1; + break; + case LAN8742_STATUS_10MBITS_HALFDUPLEX: + duplex = ETH_HALFDUPLEX_MODE; + speed = ETH_SPEED_10M; + linkchanged = 1; + break; + default: + break; } - if(linkchanged) - { + if (linkchanged) { /* Get MAC Config MAC */ HAL_ETH_GetMACConfig(&EthHandle, &MACConf); MACConf.DuplexMode = duplex; @@ -607,8 +575,6 @@ void ethernet_link_check_state(struct netif *netif) } } -ETH_HandleTypeDef* getEthernetHandle() { - return &EthHandle; -} +ETH_HandleTypeDef *getEthernetHandle() { return &EthHandle; } /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/stm32h7/networking/ethernetif.h b/stm32h7/networking/ethernetif.h index 44a3ceb..85f70b8 100644 --- a/stm32h7/networking/ethernetif.h +++ b/stm32h7/networking/ethernetif.h @@ -1,65 +1,66 @@ /** - ****************************************************************************** - * @file LwIP/LwIP_HTTP_Server_Netconn_RTOS/Inc/ethernetif.h - * @author MCD Application Team - * @brief Header for ethernetif.c module - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2017 STMicroelectronics International N.V. - * All rights reserved.

- * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted, provided that the following conditions are met: - * - * 1. Redistribution of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of other - * contributors to this software may be used to endorse or promote products - * derived from this software without specific written permission. - * 4. This software, including modifications and/or derivative works of this - * software, must execute solely and exclusively on microcontroller or - * microprocessor devices manufactured by or for STMicroelectronics. - * 5. Redistribution and use of this software other than as permitted under - * this license is void and will automatically terminate your rights under - * this license. - * - * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY - * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT - * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file LwIP/LwIP_HTTP_Server_Netconn_RTOS/Inc/ethernetif.h + * @author MCD Application Team + * @brief Header for ethernetif.c module + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2017 STMicroelectronics International N.V. + * All rights reserved.

+ * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted, provided that the following conditions are met: + * + * 1. Redistribution of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of other + * contributors to this software may be used to endorse or promote products + * derived from this software without specific written permission. + * 4. This software, including modifications and/or derivative works of this + * software, must execute solely and exclusively on microcontroller or + * microprocessor devices manufactured by or for STMicroelectronics. + * 5. Redistribution and use of this software other than as permitted under + * this license is void and will automatically terminate your rights under + * this license. + * + * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY + * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT + * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ #ifndef __ETHERNETIF_H__ #define __ETHERNETIF_H__ +#include +#include + #include "lwip/err.h" #include "lwip/netif.h" -#include -#include #ifdef __cplusplus extern "C" { #endif -#define ETH_RX_BUFFER_SIZE (1536UL) +#define ETH_RX_BUFFER_SIZE (1536UL) /* Exported types ------------------------------------------------------------*/ -ETH_HandleTypeDef* getEthernetHandle(); +ETH_HandleTypeDef *getEthernetHandle(); err_t ethernetif_init(struct netif *netif); void ethernetif_input(struct netif *netif); void ethernet_link_check_state(struct netif *netif); diff --git a/stm32h7/networking/networking.cpp b/stm32h7/networking/networking.cpp index ad3e90b..0c4df6e 100644 --- a/stm32h7/networking/networking.cpp +++ b/stm32h7/networking/networking.cpp @@ -1,19 +1,15 @@ -#include "udp_config.h" #include "networking.h" +#include "udp_config.h" + bool ethernetCableConnected = false; -void networking::setEthCableConnected(bool status) { - ethernetCableConnected = status; -} +void networking::setEthCableConnected(bool status) { ethernetCableConnected = status; } -bool networking::getEthCableConnected() { - return ethernetCableConnected; -} +bool networking::getEthCableConnected() { return ethernetCableConnected; } void networking::setLwipAddresses(ip_addr_t* ipaddr, ip_addr_t* netmask, ip_addr_t* gw) { - IP4_ADDR(ipaddr, IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3); - IP4_ADDR(netmask, NETMASK_ADDR0, NETMASK_ADDR1 , - NETMASK_ADDR2, NETMASK_ADDR3); - IP4_ADDR(gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3); + IP4_ADDR(ipaddr, IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3); + IP4_ADDR(netmask, NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3); + IP4_ADDR(gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3); } diff --git a/stm32h7/networking/networking.h b/stm32h7/networking/networking.h index 5bb0745..a0f9221 100644 --- a/stm32h7/networking/networking.h +++ b/stm32h7/networking/networking.h @@ -9,6 +9,6 @@ void setEthCableConnected(bool status); bool getEthCableConnected(); void setLwipAddresses(ip_addr_t* ipaddr, ip_addr_t* netmask, ip_addr_t* gw); -} +} // namespace networking #endif /* BSP_STM32H7_RTEMS_NETWORKING_NETWORKING_H_ */ diff --git a/stm32h7/networking/udp_config.h b/stm32h7/networking/udp_config.h index e2e9b65..06b4e37 100644 --- a/stm32h7/networking/udp_config.h +++ b/stm32h7/networking/udp_config.h @@ -6,31 +6,31 @@ extern "C" { #endif /* UDP local connection port. Client needs to bind to this port */ -#define UDP_SERVER_PORT 7 +#define UDP_SERVER_PORT 7 /*Static DEST IP ADDRESS: DEST_IP_ADDR0.DEST_IP_ADDR1.DEST_IP_ADDR2.DEST_IP_ADDR3 */ -#define DEST_IP_ADDR0 ((uint8_t)169U) -#define DEST_IP_ADDR1 ((uint8_t)254U) -#define DEST_IP_ADDR2 ((uint8_t)39U) -#define DEST_IP_ADDR3 ((uint8_t)2U) +#define DEST_IP_ADDR0 ((uint8_t)169U) +#define DEST_IP_ADDR1 ((uint8_t)254U) +#define DEST_IP_ADDR2 ((uint8_t)39U) +#define DEST_IP_ADDR3 ((uint8_t)2U) /*Static IP ADDRESS*/ -#define IP_ADDR0 169 -#define IP_ADDR1 254 -#define IP_ADDR2 1 -#define IP_ADDR3 38 +#define IP_ADDR0 169 +#define IP_ADDR1 254 +#define IP_ADDR2 1 +#define IP_ADDR3 38 /*NETMASK*/ -#define NETMASK_ADDR0 255 -#define NETMASK_ADDR1 255 -#define NETMASK_ADDR2 0 -#define NETMASK_ADDR3 0 +#define NETMASK_ADDR0 255 +#define NETMASK_ADDR1 255 +#define NETMASK_ADDR2 0 +#define NETMASK_ADDR3 0 /*Gateway Address*/ -#define GW_ADDR0 192 -#define GW_ADDR1 168 -#define GW_ADDR2 178 -#define GW_ADDR3 1 +#define GW_ADDR0 192 +#define GW_ADDR1 168 +#define GW_ADDR2 178 +#define GW_ADDR3 1 #ifdef __cplusplus }