Merge remote-tracking branch 'origin/master' into mueller/fmt-log
This commit is contained in:
commit
b8e06cba99
@ -1,9 +1,7 @@
|
||||
add_subdirectory(config)
|
||||
add_subdirectory(example)
|
||||
|
||||
target_include_directories(${TARGET_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
if(TGT_BSP MATCHES "arm/stm32h743zi-nucleo")
|
||||
add_subdirectory(stm32h7)
|
||||
|
45
cmake/BuildType.cmake
Normal file
45
cmake/BuildType.cmake
Normal file
@ -0,0 +1,45 @@
|
||||
function(set_build_type)
|
||||
|
||||
message(STATUS "Used build generator: ${CMAKE_GENERATOR}")
|
||||
|
||||
# Set a default build type if none was specified
|
||||
set(DEFAULT_BUILD_TYPE "RelWithDebInfo")
|
||||
if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
|
||||
set(DEFAULT_BUILD_TYPE "Debug")
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
||||
message(STATUS
|
||||
"Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified."
|
||||
)
|
||||
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE
|
||||
STRING "Choose the type of build." FORCE
|
||||
)
|
||||
# Set the possible values of build type for cmake-gui
|
||||
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
|
||||
"Debug" "Release" "MinSizeRel" "RelWithDebInfo"
|
||||
)
|
||||
endif()
|
||||
|
||||
if(${CMAKE_BUILD_TYPE} MATCHES "Debug")
|
||||
message(STATUS
|
||||
"Building Debug application with flags: ${CMAKE_C_FLAGS_DEBUG}"
|
||||
)
|
||||
elseif(${CMAKE_BUILD_TYPE} MATCHES "RelWithDebInfo")
|
||||
message(STATUS
|
||||
"Building Release (Debug) application with "
|
||||
"flags: ${CMAKE_C_FLAGS_RELWITHDEBINFO}"
|
||||
)
|
||||
elseif(${CMAKE_BUILD_TYPE} MATCHES "MinSizeRel")
|
||||
message(STATUS
|
||||
"Building Release (Size) application with "
|
||||
"flags: ${CMAKE_C_FLAGS_MINSIZEREL}"
|
||||
)
|
||||
else()
|
||||
message(STATUS
|
||||
"Building Release (Speed) application with "
|
||||
"flags: ${CMAKE_C_FLAGS_RELEASE}"
|
||||
)
|
||||
endif()
|
||||
|
||||
endfunction()
|
42
cmake/common.cmake
Normal file
42
cmake/common.cmake
Normal file
@ -0,0 +1,42 @@
|
||||
function(get_common_build_flags TGT_NAME)
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
set(COMMON_COMPILE_OPTS
|
||||
-ffunction-sections
|
||||
-fdata-sections
|
||||
PARENT_SCOPE)
|
||||
set(COMMON_LINK_OPTS
|
||||
-Wl,--gc-sections
|
||||
-Wl,-Map=${TARGET_NAME}.map
|
||||
PARENT_SCOPE)
|
||||
set(COMMON_WARNING_FLAGS
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wimplicit-fallthrough=1
|
||||
-Wno-unused-parameter
|
||||
-Wno-psabi
|
||||
-Wduplicated-cond # check for duplicate conditions
|
||||
-Wduplicated-branches # check for duplicate branches
|
||||
-Wlogical-op # Search for bitwise operations instead of logical
|
||||
-Wnull-dereference # Search for NULL dereference
|
||||
-Wundef # Warn if undefind marcos are used
|
||||
-Wformat=2 # Format string problem detection
|
||||
-Wformat-overflow=2 # Formatting issues in printf
|
||||
-Wformat-truncation=2 # Formatting issues in printf
|
||||
-Wformat-security # Search for dangerous printf operations
|
||||
-Wstrict-overflow=3 # Warn if integer overflows might happen
|
||||
-Warray-bounds=2 # Some array bounds violations will be found
|
||||
-Wshift-overflow=2 # Search for bit left shift overflows (<c++14)
|
||||
-Wcast-qual # Warn if the constness is cast away
|
||||
-Wstringop-overflow=4
|
||||
# -Wstack-protector # Emits a few false positives for low level access
|
||||
# -Wconversion # Creates many false positives -Warith-conversion # Use
|
||||
# with Wconversion to find more implicit conversions -fanalyzer # Should
|
||||
# be used to look through problems
|
||||
PARENT_SCOPE)
|
||||
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||
add_compile_options(/permissive- /d2SSAOptimizer-)
|
||||
# To avoid nameclashes with min and max macro
|
||||
add_compile_definitions(NOMINMAX)
|
||||
endif()
|
||||
|
||||
endfunction()
|
@ -1,7 +1,3 @@
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
commonPollingSequenceFactory.cpp
|
||||
)
|
||||
target_sources(${TARGET_NAME} PRIVATE commonPollingSequenceFactory.cpp)
|
||||
|
||||
target_include_directories(${TARGET_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
21
config/common/definitions.h
Normal file
21
config/common/definitions.h
Normal file
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
/**
|
||||
* Enumerations for used PUS service IDs.
|
||||
*/
|
||||
namespace pus {
|
||||
enum ServiceIds : uint8_t {
|
||||
PUS_SERVICE_1 = 1,
|
||||
PUS_SERVICE_2 = 2,
|
||||
PUS_SERVICE_3 = 3,
|
||||
PUS_SERVICE_5 = 5,
|
||||
PUS_SERVICE_8 = 8,
|
||||
PUS_SERVICE_9 = 9,
|
||||
PUS_SERVICE_11 = 11,
|
||||
PUS_SERVICE_17 = 17,
|
||||
PUS_SERVICE_20 = 20,
|
||||
PUS_SERVICE_200 = 200
|
||||
};
|
||||
}
|
@ -10,7 +10,7 @@
|
||||
|
||||
//! Specify the debug output verbose level
|
||||
#define OBSW_VERBOSE_LEVEL 1
|
||||
|
||||
#define OBSW_TCPIP_UDP_WIRETAPPING 0
|
||||
#define OBSW_PRINT_MISSED_DEADLINES 0
|
||||
|
||||
//! Perform internal unit testd at application startup
|
||||
@ -44,24 +44,10 @@ static const uint16_t COMMON_APID = 0xEF;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <fsfw/events/fwSubsystemIdRanges.h>
|
||||
#include <fsfw/returnvalues/FwClassIds.h>
|
||||
namespace cfg {
|
||||
|
||||
static constexpr uint32_t OBSW_MAX_SCHEDULED_TCS = @OBSW_MAX_SCHEDULED_TCS@;
|
||||
|
||||
/**
|
||||
* Enumerations for used PUS service IDs.
|
||||
*/
|
||||
namespace pus {
|
||||
enum ServiceIds: uint8_t {
|
||||
PUS_SERVICE_1 = 1,
|
||||
PUS_SERVICE_2 = 2,
|
||||
PUS_SERVICE_3 = 3,
|
||||
PUS_SERVICE_5 = 5,
|
||||
PUS_SERVICE_8 = 8,
|
||||
PUS_SERVICE_9 = 9,
|
||||
PUS_SERVICE_17 = 17,
|
||||
PUS_SERVICE_20 = 20,
|
||||
PUS_SERVICE_200 = 200
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
@ -9,9 +9,12 @@
|
||||
ReturnValue_t pst::pollingSequenceExamples(FixedTimeslotTaskIF *thisSequence) {
|
||||
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);
|
||||
@ -20,9 +23,12 @@ ReturnValue_t pst::pollingSequenceExamples(FixedTimeslotTaskIF* thisSequence) {
|
||||
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;
|
||||
@ -35,20 +41,30 @@ ReturnValue_t pst::pollingSequenceExamples(FixedTimeslotTaskIF* thisSequence) {
|
||||
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;
|
||||
|
@ -1,3 +1 @@
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
FsfwTestController.cpp
|
||||
)
|
||||
target_sources(${TARGET_NAME} PRIVATE FsfwTestController.cpp)
|
||||
|
@ -2,22 +2,21 @@
|
||||
|
||||
#include <fsfw/datapool/PoolReadGuard.h>
|
||||
|
||||
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) {}
|
||||
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) {}
|
||||
|
||||
FsfwTestController::~FsfwTestController() {}
|
||||
|
||||
ReturnValue_t FsfwTestController::handleCommandMessage(CommandMessage* message) {
|
||||
ReturnValue_t
|
||||
FsfwTestController::handleCommandMessage(CommandMessage *message) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t FsfwTestController::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||
LocalDataPoolManager& poolManager) {
|
||||
ReturnValue_t FsfwTestController::initializeLocalDataPool(
|
||||
localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
@ -64,13 +63,14 @@ ReturnValue_t FsfwTestController::initializeAfterTaskCreation() {
|
||||
FSFW_LOGW("initializeAfterTaskCreation: Test device handler 0 handle invalid\n");
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
ProvidesDataPoolSubscriptionIF* subscriptionIF = device0->getSubscriptionInterface();
|
||||
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(),
|
||||
subscriptionIF->subscribeForSetUpdateMessage(td::TEST_SET_ID, getObjectId(),
|
||||
getCommandQueue(), false);
|
||||
subscriptionIF->subscribeForVariableUpdateMessage(
|
||||
td::PoolIds::TEST_UINT8_ID, getObjectId(), getCommandQueue(), false);
|
||||
}
|
||||
|
||||
auto* device1 =
|
||||
@ -82,22 +82,26 @@ ReturnValue_t FsfwTestController::initializeAfterTaskCreation() {
|
||||
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(),
|
||||
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,
|
||||
ReturnValue_t FsfwTestController::checkModeCommand(Mode_t mode,
|
||||
Submode_t submode,
|
||||
uint32_t *msToReachTheMode) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void FsfwTestController::handleChangedDataset(sid_t sid, store_address_t storeId,
|
||||
void FsfwTestController::handleChangedDataset(sid_t sid,
|
||||
store_address_t storeId,
|
||||
bool *clearMessage) {
|
||||
using namespace std;
|
||||
|
||||
@ -132,7 +136,8 @@ void FsfwTestController::handleChangedDataset(sid_t sid, store_address_t storeId
|
||||
}
|
||||
}
|
||||
|
||||
void FsfwTestController::handleChangedPoolVariable(gp_id_t globPoolId, store_address_t storeId,
|
||||
void FsfwTestController::handleChangedPoolVariable(gp_id_t globPoolId,
|
||||
store_address_t storeId,
|
||||
bool *clearMessage) {
|
||||
using namespace std;
|
||||
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
class FsfwTestController : public TestController {
|
||||
public:
|
||||
FsfwTestController(object_id_t objectId, object_id_t device0, object_id_t device1,
|
||||
uint8_t verboseLevel = 0);
|
||||
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;
|
||||
|
||||
@ -31,10 +31,12 @@ class FsfwTestController : public TestController {
|
||||
TraceTypes currentTraceType = TraceTypes::NONE;
|
||||
|
||||
ReturnValue_t initializeAfterTaskCreation() override;
|
||||
void handleChangedDataset(sid_t sid, store_address_t storeId, bool* clearMessage) 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,
|
||||
ReturnValue_t
|
||||
initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||
LocalDataPoolManager &poolManager) override;
|
||||
LocalPoolDataSetBase *getDataSetHandle(sid_t sid) override;
|
||||
ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
|
||||
|
@ -1,3 +1 @@
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
GenericFactory.cpp
|
||||
)
|
||||
target_sources(${TARGET_NAME} PRIVATE GenericFactory.cpp)
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "GenericFactory.h"
|
||||
|
||||
#include "OBSWConfig.h"
|
||||
#include "common/definitions.h"
|
||||
#include "example/test/FsfwExampleTask.h"
|
||||
#include "example/test/FsfwReaderTask.h"
|
||||
#include "example/utility/TmFunnel.h"
|
||||
@ -10,6 +11,7 @@
|
||||
#include "fsfw/health/HealthTable.h"
|
||||
#include "fsfw/internalerror/InternalErrorReporter.h"
|
||||
#include "fsfw/pus/CService200ModeCommanding.h"
|
||||
#include "fsfw/pus/Service11TelecommandScheduling.h"
|
||||
#include "fsfw/pus/Service17Test.h"
|
||||
#include "fsfw/pus/Service1TelecommandVerification.h"
|
||||
#include "fsfw/pus/Service20ParameterManagement.h"
|
||||
@ -30,7 +32,6 @@
|
||||
#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
|
||||
@ -39,26 +40,37 @@ void ObjectFactory::produceGenericObjects() {
|
||||
new HealthTable(objects::HEALTH_TABLE);
|
||||
new InternalErrorReporter(objects::INTERNAL_ERROR_REPORTER);
|
||||
new TimeStamper(objects::TIME_STAMPER);
|
||||
auto *ccsdsDistrib =
|
||||
new CCSDSDistributor(apid::APID, objects::CCSDS_DISTRIBUTOR);
|
||||
new PUSDistributor(apid::APID, objects::PUS_DISTRIBUTOR, 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 */
|
||||
#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 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);
|
||||
#if OBSW_ADD_CORE_COMPONENTS == 1
|
||||
new Service11TelecommandScheduling<cfg::OBSW_MAX_SCHEDULED_TCS>(
|
||||
objects::PUS_SERVICE_11_TC_SCHEDULER, apid::APID, pus::PUS_SERVICE_11,
|
||||
ccsdsDistrib);
|
||||
#endif
|
||||
new CService200ModeCommanding(objects::PUS_SERVICE_200_MODE_MGMT, apid::APID,
|
||||
pus::PUS_SERVICE_200);
|
||||
#endif /* OBSW_ADD_PUS_STACK == 1 */
|
||||
@ -86,17 +98,22 @@ void ObjectFactory::produceGenericObjects() {
|
||||
|
||||
/* Demo device handler object */
|
||||
size_t expectedMaxReplyLen = 64;
|
||||
CookieIF* testCookie = new TestCookie(static_cast<address_t>(testdevice::DeviceIndex::DEVICE_0),
|
||||
CookieIF *testCookie =
|
||||
new TestCookie(static_cast<address_t>(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<address_t>(testdevice::DeviceIndex::DEVICE_1),
|
||||
new TestDevice(objects::TEST_DEVICE_HANDLER_0, objects::TEST_ECHO_COM_IF,
|
||||
testCookie, testdevice::DeviceIndex::DEVICE_0,
|
||||
enableInfoPrintout);
|
||||
testCookie =
|
||||
new TestCookie(static_cast<address_t>(testdevice::DeviceIndex::DEVICE_1),
|
||||
expectedMaxReplyLen);
|
||||
new TestDevice(objects::TEST_DEVICE_HANDLER_1, objects::TEST_ECHO_COM_IF, testCookie,
|
||||
testdevice::DeviceIndex::DEVICE_1, enableInfoPrintout);
|
||||
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,
|
||||
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 */
|
||||
|
@ -0,0 +1 @@
|
||||
|
@ -1,9 +1,5 @@
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
FsfwReaderTask.cpp
|
||||
FsfwExampleTask.cpp
|
||||
MutexExample.cpp
|
||||
FsfwTestTask.cpp
|
||||
)
|
||||
target_sources(${TARGET_NAME} PRIVATE FsfwReaderTask.cpp FsfwExampleTask.cpp
|
||||
MutexExample.cpp FsfwTestTask.cpp)
|
||||
|
||||
if(OBSW_ADD_FMT_TESTS)
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
|
@ -7,15 +7,15 @@
|
||||
#include <fsfw/tasks/TaskFactory.h>
|
||||
|
||||
#include "OBSWConfig.h"
|
||||
#include "commonSystemObjects.h"
|
||||
#include "commonObjects.h"
|
||||
#include "objects/systemObjectList.h"
|
||||
|
||||
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);
|
||||
: 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() {}
|
||||
@ -86,7 +86,8 @@ ReturnValue_t FsfwExampleTask::initialize() {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
// we need a private copy of the previous dataset.. or we use the shared dataset.
|
||||
// we need a private copy of the previous dataset.. or we use the shared
|
||||
// dataset.
|
||||
senderSet = new FsfwDemoSet(senderIF);
|
||||
if (senderSet == nullptr) {
|
||||
FSFW_LOGE("initialize: Sender dataset invalid\n");
|
||||
@ -99,25 +100,37 @@ ReturnValue_t FsfwExampleTask::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; }
|
||||
|
||||
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,
|
||||
ReturnValue_t
|
||||
FsfwExampleTask::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||
LocalDataPoolManager &poolManager) {
|
||||
localDataPoolMap.emplace(FsfwDemoSet::PoolIds::VARIABLE, new PoolEntry<uint32_t>({0}));
|
||||
localDataPoolMap.emplace(FsfwDemoSet::PoolIds::VARIABLE_LIMIT, new PoolEntry<uint16_t>({0}));
|
||||
localDataPoolMap.emplace(FsfwDemoSet::PoolIds::VARIABLE,
|
||||
new PoolEntry<uint32_t>({0}));
|
||||
localDataPoolMap.emplace(FsfwDemoSet::PoolIds::VARIABLE_LIMIT,
|
||||
new PoolEntry<uint16_t>({0}));
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t FsfwExampleTask::performMonitoringDemo() {
|
||||
ReturnValue_t result = demoSet.variableLimit.read(MutexIF::TimeoutType::WAITING, 20);
|
||||
ReturnValue_t result =
|
||||
demoSet.variableLimit.read(MutexIF::TimeoutType::WAITING, 20);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
/* Configuration error */
|
||||
FSFW_LOGE("DummyObject::performOperation: Could not read variableLimit\n");
|
||||
@ -180,8 +193,9 @@ ReturnValue_t FsfwExampleTask::performReceiveOperation() {
|
||||
#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;
|
||||
<< receivedMessage.getSender() << " ObjectId "
|
||||
<< receivedMessage.getParameter() << " Queue "
|
||||
<< receivedMessage.getParameter2() << std::endl;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -204,6 +218,10 @@ ReturnValue_t FsfwExampleTask::performReceiveOperation() {
|
||||
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;
|
||||
}
|
||||
|
@ -24,7 +24,9 @@ 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 {
|
||||
class FsfwExampleTask : public ExecutableObjectIF,
|
||||
public SystemObject,
|
||||
public HasLocalDataPoolIF {
|
||||
public:
|
||||
enum OpCodes { SEND_RAND_NUM, RECEIVE_RAND_NUM, DELAY_SHORT };
|
||||
|
||||
@ -90,7 +92,8 @@ class FsfwExampleTask : public ExecutableObjectIF, public SystemObject, public H
|
||||
MessageQueueId_t getCommandQueue() const override;
|
||||
LocalPoolDataSetBase *getDataSetHandle(sid_t sid) override;
|
||||
uint32_t getPeriodicOperationFrequency() const override;
|
||||
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||
ReturnValue_t
|
||||
initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||
LocalDataPoolManager &poolManager) override;
|
||||
LocalDataPoolManager *getHkManagerHandle() override;
|
||||
|
||||
|
@ -7,13 +7,13 @@
|
||||
#include <fsfw/timemanager/Stopwatch.h>
|
||||
|
||||
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),
|
||||
: 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 */
|
||||
/* Special protection for set reading because each variable is read from a
|
||||
* different pool */
|
||||
readSet.setReadCommitProtectionBehaviour(true);
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,8 @@ class FsfwTestTask : public TestTask {
|
||||
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);
|
||||
static constexpr Event TEST_EVENT =
|
||||
event::makeEvent(subsystemId, 0, severity::INFO);
|
||||
};
|
||||
|
||||
#endif /* EXAMPLE_COMMON_EXAMPLE_TEST_FSFWTESTTASK_H_ */
|
||||
|
@ -7,7 +7,8 @@ void MutexExample::example() {
|
||||
MutexIF *mutex = MutexFactory::instance()->createMutex();
|
||||
MutexIF *mutex2 = MutexFactory::instance()->createMutex();
|
||||
|
||||
ReturnValue_t result = mutex->lockMutex(MutexIF::TimeoutType::WAITING, 2 * 60 * 1000);
|
||||
ReturnValue_t result =
|
||||
mutex->lockMutex(MutexIF::TimeoutType::WAITING, 2 * 60 * 1000);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
FSFW_LOGET("MutexExample::example: Lock Failed with {}\n", result);
|
||||
}
|
||||
|
@ -17,12 +17,13 @@ class FsfwDemoSet : public StaticLocalDataSet<3> {
|
||||
|
||||
enum PoolIds { VARIABLE, VARIABLE_LIMIT };
|
||||
|
||||
FsfwDemoSet(HasLocalDataPoolIF* hkOwner) : StaticLocalDataSet(hkOwner, DEMO_SET_ID) {}
|
||||
FsfwDemoSet(HasLocalDataPoolIF *hkOwner)
|
||||
: StaticLocalDataSet(hkOwner, DEMO_SET_ID) {}
|
||||
|
||||
lp_var_t<uint32_t> variableRead =
|
||||
lp_var_t<uint32_t>(sid.objectId, PoolIds::VARIABLE, this, pool_rwm_t::VAR_READ);
|
||||
lp_var_t<uint32_t> variableWrite =
|
||||
lp_var_t<uint32_t>(sid.objectId, PoolIds::VARIABLE, this, pool_rwm_t::VAR_WRITE);
|
||||
lp_var_t<uint32_t> variableRead = lp_var_t<uint32_t>(
|
||||
sid.objectId, PoolIds::VARIABLE, this, pool_rwm_t::VAR_READ);
|
||||
lp_var_t<uint32_t> variableWrite = lp_var_t<uint32_t>(
|
||||
sid.objectId, PoolIds::VARIABLE, this, pool_rwm_t::VAR_WRITE);
|
||||
lp_var_t<uint16_t> variableLimit =
|
||||
lp_var_t<uint16_t>(sid.objectId, PoolIds::VARIABLE_LIMIT, this);
|
||||
|
||||
@ -38,7 +39,8 @@ 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)
|
||||
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),
|
||||
|
@ -1,4 +1 @@
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
utility.cpp
|
||||
TmFunnel.cpp
|
||||
)
|
||||
target_sources(${TARGET_NAME} PRIVATE utility.cpp TmFunnel.cpp)
|
||||
|
@ -10,8 +10,8 @@ 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);
|
||||
tmQueue = QueueFactory::instance()->createMessageQueue(
|
||||
messageDepth, MessageQueueMessage::MAX_MESSAGE_SIZE);
|
||||
storageQueue = QueueFactory::instance()->createMessageQueue(
|
||||
messageDepth, MessageQueueMessage::MAX_MESSAGE_SIZE);
|
||||
}
|
||||
@ -43,20 +43,22 @@ ReturnValue_t TmFunnel::performOperation(uint8_t operationCode) {
|
||||
ReturnValue_t TmFunnel::handlePacket(TmTcMessage *message) {
|
||||
uint8_t *packetData = nullptr;
|
||||
size_t size = 0;
|
||||
ReturnValue_t result = tmPool->modifyData(message->getStorageId(), &packetData, &size);
|
||||
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;
|
||||
sourceSequenceCount =
|
||||
sourceSequenceCount % SpacePacketBase::LIMIT_SEQUENCE_COUNT;
|
||||
packet.setErrorControl();
|
||||
|
||||
result = tmQueue->sendToDefault(message);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
tmPool->deleteData(message->getStorageId());
|
||||
FSFW_LOGET("{}", "handlePacket: Error sending to downlink handler\n");
|
||||
FSFW_LOGET("handlePacket: Error sending to downlink handler\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -64,7 +66,7 @@ ReturnValue_t TmFunnel::handlePacket(TmTcMessage* message) {
|
||||
result = storageQueue->sendToDefault(message);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
tmPool->deleteData(message->getStorageId());
|
||||
FSFW_LOGET("{}", "handlePacket: Error sending to storage handler\n");
|
||||
FSFW_LOGET("handlePacket: Error sending to storage handler\n");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -99,7 +101,8 @@ ReturnValue_t TmFunnel::initialize() {
|
||||
AcceptsTelemetryIF *storageTarget =
|
||||
ObjectManager::instance()->get<AcceptsTelemetryIF>(storageDestination);
|
||||
if (storageTarget != nullptr) {
|
||||
storageQueue->setDefaultDestination(storageTarget->getReportReceptionQueue());
|
||||
storageQueue->setDefaultDestination(
|
||||
storageTarget->getReportReceptionQueue());
|
||||
}
|
||||
|
||||
return SystemObject::initialize();
|
||||
|
@ -19,14 +19,17 @@ void setStaticFrameworkObjectIds();
|
||||
* @ingroup utility
|
||||
* @author J. Meier
|
||||
*/
|
||||
class TmFunnel : public AcceptsTelemetryIF, public ExecutableObjectIF, public SystemObject {
|
||||
class TmFunnel : public AcceptsTelemetryIF,
|
||||
public ExecutableObjectIF,
|
||||
public SystemObject {
|
||||
friend void(Factory::setStaticFrameworkObjectIds)();
|
||||
|
||||
public:
|
||||
TmFunnel(object_id_t objectId, uint32_t messageDepth = 20);
|
||||
virtual ~TmFunnel();
|
||||
|
||||
virtual MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel = 0) override;
|
||||
virtual MessageQueueId_t
|
||||
getReportReceptionQueue(uint8_t virtualChannel = 0) override;
|
||||
virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override;
|
||||
virtual ReturnValue_t initialize() override;
|
||||
|
||||
|
@ -13,11 +13,13 @@
|
||||
*
|
||||
* 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!
|
||||
* Careful: __TIME__ is the local time of the computer, NOT the UTC time in
|
||||
* general!
|
||||
*
|
||||
*/
|
||||
|
||||
@ -62,29 +64,36 @@
|
||||
|
||||
// Days in February
|
||||
#define _UNIX_TIMESTAMP_FDAY(year) \
|
||||
(((year) % 400) == 0UL ? 29UL \
|
||||
(((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))
|
||||
(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)
|
||||
/* 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__))
|
||||
(_UNIX_TIMESTAMP(__TIME_YEARS__, __TIME_MONTH__, __TIME_DAYS__, \
|
||||
__TIME_HOURS__, __TIME_MINUTES__, __TIME_SECONDS__))
|
||||
|
||||
#endif
|
||||
|
@ -8,9 +8,25 @@ void utility::commonInitPrint(const char* const os, const char* const board) {
|
||||
if (os == nullptr or board == nullptr) {
|
||||
return;
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
fmt::print("-- FSFW Example ({}) v{}.{}.{} --\n", os, FSFW_EXAMPLE_VERSION,
|
||||
FSFW_EXAMPLE_SUBVERSION, FSFW_EXAMPLE_REVISION);
|
||||
fmt::print("-- Compiled for {}\n", board);
|
||||
fmt::print("-- Compiled on {} {}\n", __DATE__, __TIME__);
|
||||
sif::initialize();
|
||||
=======
|
||||
#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;
|
||||
#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__);
|
||||
#endif
|
||||
>>>>>>> origin/master
|
||||
}
|
||||
|
44
scripts/auto-formatter.sh
Executable file
44
scripts/auto-formatter.sh
Executable file
@ -0,0 +1,44 @@
|
||||
#!/bin/bash
|
||||
counter=0
|
||||
common_example_dir="example_common"
|
||||
while [ ${counter} -lt 5 ]
|
||||
do
|
||||
if [ ! -d ${common_example_dir} ];then
|
||||
break
|
||||
fi
|
||||
counter=$((counter=counter + 1))
|
||||
cd ..
|
||||
done
|
||||
|
||||
if [ "${counter}" -ge 5 ];then
|
||||
echo "${common_example_dir} not found in upper directories!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
folder_list=(
|
||||
"./bsp_hosted"
|
||||
"./example_common"
|
||||
)
|
||||
|
||||
cmake_fmt="cmake-format"
|
||||
file_selectors="-iname CMakeLists.txt"
|
||||
if command -v ${cmake_fmt} &> /dev/null; then
|
||||
echo "Auto-formatting all CMakeLists.txt files"
|
||||
${cmake_fmt} -i CMakeLists.txt
|
||||
for dir in ${folder_list[@]}; do
|
||||
find ${dir} ${file_selectors} | xargs ${cmake_fmt} -i
|
||||
done
|
||||
else
|
||||
echo "No ${cmake_fmt} tool found, not formatting CMake files"
|
||||
fi
|
||||
|
||||
cpp_format="clang-format"
|
||||
file_selectors="-iname *.h -o -iname *.cpp -o -iname *.c -o -iname *.tpp"
|
||||
if command -v ${cpp_format} &> /dev/null; then
|
||||
for dir in ${folder_list[@]}; do
|
||||
echo "Auto-formatting C/C++ files in ${dir} recursively"
|
||||
find ${dir} ${file_selectors} | xargs ${cpp_format} --style=file -i
|
||||
done
|
||||
else
|
||||
echo "No ${cpp_format} tool found, not formatting C++/C files"
|
||||
fi
|
@ -1,6 +1,4 @@
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
STM32TestTask.cpp
|
||||
)
|
||||
target_sources(${TARGET_NAME} PRIVATE STM32TestTask.cpp)
|
||||
|
||||
option(STM32_ADD_NETWORKING_CODE "Add networking code requiring lwIP" ON)
|
||||
|
||||
|
@ -3,16 +3,25 @@
|
||||
#include "OBSWConfig.h"
|
||||
#include "stm32h7xx_nucleo.h"
|
||||
|
||||
STM32TestTask::STM32TestTask(object_id_t objectId, bool enablePrintout, bool blinkyLed)
|
||||
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::initialize() {
|
||||
if (testSpi) {
|
||||
spiComIF = new SpiComIF(objects::SPI_COM_IF);
|
||||
spiTest = new SpiTest(*spiComIF);
|
||||
}
|
||||
return TestTask::initialize();
|
||||
}
|
||||
|
||||
ReturnValue_t STM32TestTask::performPeriodicAction() {
|
||||
if (blinkyLed) {
|
||||
#if OBSW_ETHERNET_USE_LEDS == 0
|
||||
#if OBSW_ETHERNET_USE_LED1_LED2 == 0
|
||||
BSP_LED_Toggle(LED1);
|
||||
BSP_LED_Toggle(LED2);
|
||||
#endif
|
||||
@ -23,11 +32,3 @@ ReturnValue_t STM32TestTask::performPeriodicAction() {
|
||||
}
|
||||
return TestTask::performPeriodicAction();
|
||||
}
|
||||
|
||||
ReturnValue_t STM32TestTask::initialize() {
|
||||
if (testSpi) {
|
||||
spiComIF = new SpiComIF(objects::SPI_COM_IF);
|
||||
spiTest = new SpiTest(*spiComIF);
|
||||
}
|
||||
return TestTask::initialize();
|
||||
}
|
||||
|
@ -6,7 +6,8 @@
|
||||
|
||||
class STM32TestTask : public TestTask {
|
||||
public:
|
||||
STM32TestTask(object_id_t objectId, bool enablePrintout, bool blinkyLed = true);
|
||||
STM32TestTask(object_id_t objectId, bool enablePrintout,
|
||||
bool blinkyLed = true);
|
||||
|
||||
ReturnValue_t initialize() override;
|
||||
ReturnValue_t performPeriodicAction() override;
|
||||
@ -16,7 +17,7 @@ class STM32TestTask : public TestTask {
|
||||
SpiTest *spiTest = nullptr;
|
||||
|
||||
bool blinkyLed = false;
|
||||
bool testSpi = true;
|
||||
bool testSpi = false;
|
||||
};
|
||||
|
||||
#endif /* BSP_STM32_BOARDTEST_STM32TESTTASK_H_ */
|
||||
|
@ -1,14 +1,8 @@
|
||||
# These are part of the RTEMS BSP for RTEMS
|
||||
if(FSFW_OSAL MATCHES freertos)
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
ethernetif.c
|
||||
)
|
||||
target_sources(${TARGET_NAME} PRIVATE ethernetif.c)
|
||||
endif()
|
||||
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
UdpTcLwIpPollingTask.cpp
|
||||
TmTcLwIpUdpBridge.cpp
|
||||
networking.cpp
|
||||
app_dhcp.cpp
|
||||
app_ethernet.cpp
|
||||
)
|
||||
target_sources(
|
||||
${TARGET_NAME} PRIVATE UdpTcLwIpPollingTask.cpp TmTcLwIpUdpBridge.cpp
|
||||
networking.cpp app_dhcp.cpp app_ethernet.cpp)
|
||||
|
@ -1,21 +1,22 @@
|
||||
#include "TmTcLwIpUdpBridge.h"
|
||||
|
||||
#include <OBSWConfig.h>
|
||||
|
||||
#include <fsfw/ipc/MutexGuard.h>
|
||||
#include <fsfw/serialize/EndianConverter.h>
|
||||
#include <fsfw/serviceinterface/ServiceInterface.h>
|
||||
|
||||
#include "app_ethernet.h"
|
||||
#include "ethernetif.h"
|
||||
#include "udp_config.h"
|
||||
|
||||
TmTcLwIpUdpBridge::TmTcLwIpUdpBridge(object_id_t objectId, object_id_t ccsdsPacketDistributor,
|
||||
object_id_t tmStoreId, object_id_t tcStoreId)
|
||||
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() {}
|
||||
TmTcLwIpUdpBridge::~TmTcLwIpUdpBridge() = default;
|
||||
|
||||
ReturnValue_t TmTcLwIpUdpBridge::initialize() {
|
||||
TmTcBridge::initialize();
|
||||
@ -27,18 +28,20 @@ ReturnValue_t TmTcLwIpUdpBridge::initialize() {
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t TmTcLwIpUdpBridge::udp_server_init(void) {
|
||||
ReturnValue_t TmTcLwIpUdpBridge::udp_server_init() {
|
||||
err_t err;
|
||||
/* Create a new UDP control block */
|
||||
TmTcLwIpUdpBridge::upcb = udp_new();
|
||||
if (TmTcLwIpUdpBridge::upcb) {
|
||||
sif::printInfo("Opening UDP server on port %d\n", UDP_SERVER_PORT);
|
||||
/* 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);
|
||||
udp_recv(TmTcLwIpUdpBridge::upcb, &udp_server_receive_callback,
|
||||
(void *)this);
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
udp_remove(TmTcLwIpUdpBridge::upcb);
|
||||
@ -52,7 +55,7 @@ ReturnValue_t TmTcLwIpUdpBridge::udp_server_init(void) {
|
||||
ReturnValue_t TmTcLwIpUdpBridge::performOperation(uint8_t operationCode) {
|
||||
TmTcBridge::performOperation();
|
||||
|
||||
#if TCPIP_RECV_WIRETAPPING == 1
|
||||
#if OBSW_TCPIP_UDP_WIRETAPPING == 1
|
||||
if (connectFlag) {
|
||||
uint32_t ipAddress = ((ip4_addr *)&lastAdd)->addr;
|
||||
int ipAddress1 = (ipAddress & 0xFF000000) >> 24;
|
||||
@ -61,13 +64,15 @@ ReturnValue_t TmTcLwIpUdpBridge::performOperation(uint8_t operationCode) {
|
||||
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;
|
||||
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 Port " << (int)portSwapped
|
||||
<< std::endl;
|
||||
#else
|
||||
sif::printInfo("TmTcLwIpUdpBridge: Client IP Address %d.%d.%d.%d\n", ipAddress4, ipAddress3,
|
||||
ipAddress2, ipAddress1);
|
||||
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
|
||||
@ -81,9 +86,10 @@ ReturnValue_t TmTcLwIpUdpBridge::performOperation(uint8_t operationCode) {
|
||||
|
||||
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)) {
|
||||
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);
|
||||
err_t err = pbuf_take(p_tx, (const char *)data, dataLen);
|
||||
if (err != ERR_OK) {
|
||||
pbuf_free(p_tx);
|
||||
return err;
|
||||
@ -109,23 +115,26 @@ ReturnValue_t TmTcLwIpUdpBridge::sendTm(const uint8_t* data, size_t dataLen) {
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
void TmTcLwIpUdpBridge::udp_server_receive_callback(void* arg, struct udp_pcb* upcb_,
|
||||
struct pbuf* p, const ip_addr_t* addr,
|
||||
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<TmTcLwIpUdpBridge *>(arg);
|
||||
if (udpBridge == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "TmTcLwIpUdpBridge::udp_server_receive_callback: Invalid UDP bridge!"
|
||||
sif::warning
|
||||
<< "TmTcLwIpUdpBridge::udp_server_receive_callback: Invalid UDP bridge!"
|
||||
<< std::endl;
|
||||
#else
|
||||
sif::printWarning("TmTcLwIpUdpBridge::udp_server_receive_callback: Invalid UDP bridge!\n");
|
||||
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);
|
||||
struct pbuf *p_tx = pbuf_alloc(PBUF_TRANSPORT, p->len, PBUF_RAM);
|
||||
|
||||
if (p_tx != NULL) {
|
||||
if (p_tx != nullptr) {
|
||||
if (udpBridge != nullptr) {
|
||||
MutexGuard lg(udpBridge->bridgeLock);
|
||||
udpBridge->upcb = upcb_;
|
||||
@ -133,7 +142,7 @@ void TmTcLwIpUdpBridge::udp_server_receive_callback(void* arg, struct udp_pcb* u
|
||||
udpBridge->lastPort = port;
|
||||
if (not udpBridge->comLinkUp()) {
|
||||
udpBridge->registerCommConnect();
|
||||
#if TCPIP_RECV_WIRETAPPING == 1
|
||||
#if OBSW_TCPIP_UDP_WIRETAPPING == 1
|
||||
udpBridge->connectFlag = true;
|
||||
#endif
|
||||
/* This should have already been done, but we will still do it */
|
||||
@ -145,13 +154,13 @@ void TmTcLwIpUdpBridge::udp_server_receive_callback(void* arg, struct udp_pcb* u
|
||||
char *data = reinterpret_cast<char *>(p_tx->payload);
|
||||
*(data + p_tx->len) = '\0';
|
||||
|
||||
#if TCPIP_RECV_WIRETAPPING == 1
|
||||
udpBridge->printData(p, data);
|
||||
#if OBSW_TCPIP_UDP_WIRETAPPING == 1
|
||||
udpBridge->printData(reinterpret_cast<uint8_t *>(p->payload), p->len);
|
||||
#endif
|
||||
|
||||
store_address_t storeId;
|
||||
ReturnValue_t returnValue =
|
||||
udpBridge->tcStore->addData(&storeId, reinterpret_cast<uint8_t*>(p->payload), p->len);
|
||||
ReturnValue_t returnValue = udpBridge->tcStore->addData(
|
||||
&storeId, reinterpret_cast<uint8_t *>(p->payload), p->len);
|
||||
if (returnValue != RETURN_OK) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "UDP Server: Data storage failed" << std::endl;
|
||||
@ -178,8 +187,8 @@ 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! */
|
||||
/* 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;
|
||||
|
@ -1,24 +1,25 @@
|
||||
#ifndef BSP_STM32_RTEMS_NETWORKING_TMTCUDPBRIDGE_H_
|
||||
#define BSP_STM32_RTEMS_NETWORKING_TMTCUDPBRIDGE_H_
|
||||
|
||||
#include <fsfw/tmtcservices/TmTcBridge.h>
|
||||
#include "fsfw/tmtcservices/TmTcBridge.h"
|
||||
#include "commonConfig.h"
|
||||
|
||||
#include <lwip/ip_addr.h>
|
||||
#include <lwip/udp.h>
|
||||
|
||||
#define TCPIP_RECV_WIRETAPPING 0
|
||||
|
||||
/**
|
||||
* This bridge is used to forward TMTC packets received via LwIP UDP to the internal software bus.
|
||||
* 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();
|
||||
TmTcLwIpUdpBridge(object_id_t objectId, object_id_t ccsdsPacketDistributor,
|
||||
object_id_t tmStoreId, object_id_t tcStoreId);
|
||||
~TmTcLwIpUdpBridge() override;
|
||||
|
||||
virtual ReturnValue_t initialize() override;
|
||||
ReturnValue_t initialize() override;
|
||||
ReturnValue_t udp_server_init();
|
||||
|
||||
/**
|
||||
@ -26,14 +27,14 @@ class TmTcLwIpUdpBridge : public TmTcBridge {
|
||||
* @param operationCode
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override;
|
||||
ReturnValue_t performOperation(uint8_t operationCode) override;
|
||||
|
||||
/** 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;
|
||||
ReturnValue_t sendTm(const uint8_t *data, size_t dataLen) override;
|
||||
|
||||
/**
|
||||
* @brief This function is called when an UDP datagram has been
|
||||
@ -44,32 +45,33 @@ class TmTcLwIpUdpBridge : public TmTcBridge {
|
||||
* @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);
|
||||
static void udp_server_receive_callback(void *arg, struct udp_pcb *upcb_,
|
||||
struct pbuf *p, const ip_addr_t *addr,
|
||||
u16_t port);
|
||||
|
||||
/**
|
||||
* Check whether the communication link is up.
|
||||
* Caller must ensure thread-safety by using the bridge lock.
|
||||
* @return
|
||||
*/
|
||||
bool comLinkUp() const;
|
||||
[[nodiscard]] bool comLinkUp() const;
|
||||
|
||||
private:
|
||||
struct udp_pcb *upcb = nullptr;
|
||||
ip_addr_t lastAdd;
|
||||
ip_addr_t lastAdd{};
|
||||
u16_t lastPort = 0;
|
||||
bool physicalConnection = false;
|
||||
MutexIF *bridgeLock = nullptr;
|
||||
|
||||
#if TCPIP_RECV_WIRETAPPING == 1
|
||||
#if OBSW_TCPIP_UDP_WIRETAPPING == 1
|
||||
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.
|
||||
* 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);
|
||||
};
|
||||
|
@ -1,7 +1,5 @@
|
||||
#include "UdpTcLwIpPollingTask.h"
|
||||
|
||||
#include <hardware_init.h>
|
||||
|
||||
#include "TmTcLwIpUdpBridge.h"
|
||||
#include "app_dhcp.h"
|
||||
#include "app_ethernet.h"
|
||||
@ -12,11 +10,13 @@
|
||||
#include "lwip/timeouts.h"
|
||||
#include "networking.h"
|
||||
|
||||
UdpTcLwIpPollingTask::UdpTcLwIpPollingTask(object_id_t objectId, object_id_t bridgeId,
|
||||
UdpTcLwIpPollingTask::UdpTcLwIpPollingTask(object_id_t objectId,
|
||||
object_id_t bridgeId,
|
||||
struct netif *gnetif)
|
||||
: SystemObject(objectId), periodicHandleCounter(0), bridgeId(bridgeId), gnetif(gnetif) {}
|
||||
: SystemObject(objectId), periodicHandleCounter(0), bridgeId(bridgeId),
|
||||
gnetif(gnetif) {}
|
||||
|
||||
UdpTcLwIpPollingTask::~UdpTcLwIpPollingTask() {}
|
||||
UdpTcLwIpPollingTask::~UdpTcLwIpPollingTask() = default;
|
||||
|
||||
ReturnValue_t UdpTcLwIpPollingTask::initialize() {
|
||||
udpBridge = ObjectManager::instance()->get<TmTcLwIpUdpBridge>(bridgeId);
|
||||
@ -47,7 +47,8 @@ ReturnValue_t UdpTcLwIpPollingTask::performOperation(uint8_t operationCode) {
|
||||
/* In case ethernet cable is disconnected */
|
||||
if (not networking::getEthCableConnected() and udpBridge->comLinkUp()) {
|
||||
udpBridge->physicalConnectStatusChange(false);
|
||||
} else if (networking::getEthCableConnected() and not udpBridge->comLinkUp()) {
|
||||
} else if (networking::getEthCableConnected() and
|
||||
not udpBridge->comLinkUp()) {
|
||||
udpBridge->physicalConnectStatusChange(true);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef BSP_STM32_RTEMS_EMACPOLLINGTASK_H_
|
||||
#define BSP_STM32_RTEMS_EMACPOLLINGTASK_H_
|
||||
#pragma once
|
||||
|
||||
#include <fsfw/objectmanager/SystemObject.h>
|
||||
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||
@ -16,17 +15,18 @@ class UdpTcLwIpPollingTask : public SystemObject,
|
||||
public ExecutableObjectIF,
|
||||
public HasReturnvaluesIF {
|
||||
public:
|
||||
UdpTcLwIpPollingTask(object_id_t objectId, object_id_t bridgeId, struct netif* gnetif);
|
||||
virtual ~UdpTcLwIpPollingTask();
|
||||
UdpTcLwIpPollingTask(object_id_t objectId, object_id_t bridgeId,
|
||||
struct netif *gnetif);
|
||||
~UdpTcLwIpPollingTask() override;
|
||||
|
||||
virtual ReturnValue_t initialize() override;
|
||||
ReturnValue_t initialize() override;
|
||||
|
||||
/**
|
||||
* Executed periodically.
|
||||
* @param operationCode
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override;
|
||||
ReturnValue_t performOperation(uint8_t operationCode) override;
|
||||
|
||||
private:
|
||||
static const uint8_t PERIODIC_HANDLE_TRIGGER = 5;
|
||||
@ -35,5 +35,3 @@ class UdpTcLwIpPollingTask : public SystemObject,
|
||||
TmTcLwIpUdpBridge *udpBridge = nullptr;
|
||||
struct netif *gnetif = nullptr;
|
||||
};
|
||||
|
||||
#endif /* BSP_STM32_RTEMS_EMACPOLLINGTASK_H_ */
|
||||
|
@ -1,8 +1,6 @@
|
||||
#include "app_dhcp.h"
|
||||
|
||||
#include "OBSWConfig.h"
|
||||
#include "app_ethernet.h"
|
||||
#include "ethernetif.h"
|
||||
#include "lwip/dhcp.h"
|
||||
#include "networking.h"
|
||||
#include "stm32h7xx_nucleo.h"
|
||||
@ -24,7 +22,7 @@ void handle_dhcp_down(struct netif* netif);
|
||||
* @retval None
|
||||
*/
|
||||
void DHCP_Process(struct netif *netif) {
|
||||
struct dhcp* dhcp = NULL;
|
||||
struct dhcp *dhcp = nullptr;
|
||||
switch (DHCP_state) {
|
||||
case DHCP_START: {
|
||||
handle_dhcp_start(netif);
|
||||
@ -109,7 +107,8 @@ void handle_dhcp_start(struct netif* netif) {
|
||||
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("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
|
||||
@ -118,7 +117,8 @@ void handle_dhcp_wait(struct netif* netif, struct dhcp** dhcp) {
|
||||
#endif
|
||||
#endif
|
||||
} else {
|
||||
*dhcp = (struct dhcp*)netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP);
|
||||
*dhcp = static_cast<struct dhcp *>(netif_get_client_data(
|
||||
netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP));
|
||||
|
||||
/* DHCP timeout */
|
||||
if ((*dhcp)->tries > MAX_DHCP_TRIES) {
|
||||
@ -128,6 +128,7 @@ void handle_dhcp_wait(struct netif* netif, struct dhcp** dhcp) {
|
||||
}
|
||||
|
||||
void handle_dhcp_down(struct netif *netif) {
|
||||
static_cast<void>(netif);
|
||||
DHCP_state = DHCP_OFF;
|
||||
#if OBSW_ETHERNET_TMTC_COMMANDING == 1
|
||||
printf("DHCP_Process: The network cable is not connected.\n\r");
|
||||
|
@ -47,8 +47,8 @@ void handle_status_change(struct netif* netif, bool link_up) {
|
||||
#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);
|
||||
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);
|
||||
|
@ -44,16 +44,16 @@
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/timeouts.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "netif/etharp.h"
|
||||
#include "ethernetif.h"
|
||||
|
||||
#include <lan8742.h>
|
||||
#include <lwip/netif.h>
|
||||
#include <lwip/opt.h>
|
||||
#include <lwip/timeouts.h>
|
||||
#include <netif/etharp.h>
|
||||
#include <stm32h7xx_hal.h>
|
||||
#include "lan8742.h"
|
||||
#include <string.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "fsfw/FSFW.h"
|
||||
|
||||
#ifdef FSFW_OSAL_RTEMS
|
||||
@ -66,14 +66,20 @@
|
||||
#define IFNAME0 's'
|
||||
#define IFNAME1 't'
|
||||
|
||||
#define ETH_DMA_TRANSMIT_TIMEOUT (20U)
|
||||
|
||||
#define ETH_RX_BUFFER_SIZE 1536U
|
||||
#define ETH_RX_BUFFER_CNT 12U
|
||||
#define ETH_TX_BUFFER_MAX ((ETH_TX_DESC_CNT) * 2U)
|
||||
|
||||
#define DMA_DESCRIPTOR_ALIGNMENT 0x20
|
||||
|
||||
/* 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.
|
||||
- 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,
|
||||
then passed to ETH HAL driver.
|
||||
|
||||
@ -87,74 +93,97 @@
|
||||
2.b. Rx Buffers must have the same size: ETH_RX_BUFFER_SIZE, this value must
|
||||
passed to ETH DMA in the init field (EthHandle.Init.RxBuffLen)
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
RX_ALLOC_OK = 0x00,
|
||||
RX_ALLOC_ERROR = 0x01
|
||||
} RxAllocStatusTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
struct pbuf_custom pbuf_custom;
|
||||
uint8_t buff[(ETH_RX_BUFFER_SIZE + 31) & ~31] __ALIGNED(32);
|
||||
} RxBuff_t;
|
||||
|
||||
#if defined(__ICCARM__) /*!< IAR Compiler */
|
||||
|
||||
#pragma location = 0x30040000
|
||||
#pragma location=0x30000000
|
||||
ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT]; /* Ethernet Rx DMA Descriptors */
|
||||
#pragma location = 0x30040060
|
||||
#pragma location=0x30000200
|
||||
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 */
|
||||
|
||||
__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 */
|
||||
|
||||
#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"),
|
||||
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"),
|
||||
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 */
|
||||
/* 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 */
|
||||
#endif /* FSFW_FREERTOS */
|
||||
|
||||
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 */
|
||||
|
||||
#endif /* FSFW_OSAL_RTEMS */
|
||||
|
||||
#endif /* defined ( __GNUC__ ) */
|
||||
|
||||
/* Memory Pool Declaration */
|
||||
LWIP_MEMPOOL_DECLARE(RX_POOL, ETH_RX_BUFFER_CNT, sizeof(RxBuff_t), "Zero-copy RX PBUF pool");
|
||||
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma location = 0x30000400
|
||||
extern u8_t memp_memory_RX_POOL_base[];
|
||||
|
||||
#elif defined ( __CC_ARM ) /* MDK ARM Compiler */
|
||||
__attribute__((section(".Rx_PoolSection"))) extern u8_t memp_memory_RX_POOL_base[];
|
||||
|
||||
#elif defined ( __GNUC__ ) /* GNU Compiler */
|
||||
__attribute__((section(".Rx_PoolSection"))) extern u8_t memp_memory_RX_POOL_base[];
|
||||
|
||||
#endif
|
||||
|
||||
/* Global boolean to track ethernet connection */
|
||||
bool ethernet_cable_connected;
|
||||
|
||||
struct pbuf_custom rx_pbuf[ETH_RX_DESC_CNT];
|
||||
uint32_t current_pbuf_idx = 0;
|
||||
/* Variable Definitions */
|
||||
static uint8_t RxAllocStatus;
|
||||
|
||||
/* Global Ethernet handle*/
|
||||
ETH_HandleTypeDef EthHandle;
|
||||
ETH_TxPacketConfig TxConfig;
|
||||
|
||||
lan8742_Object_t LAN8742;
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
u32_t sys_now(void);
|
||||
void pbuf_free_custom(struct pbuf *p);
|
||||
|
||||
extern void Error_Handler(void);
|
||||
int32_t ETH_PHY_IO_Init(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_Object_t LAN8742;
|
||||
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 ---------------------------------------------------------*/
|
||||
void pbuf_free_custom(struct pbuf *p);
|
||||
/*******************************************************************************
|
||||
LL Driver Interface ( LwIP stack --> ETH)
|
||||
*******************************************************************************/
|
||||
@ -166,9 +195,7 @@ lan8742_IOCtx_t LAN8742_IOCtx = {ETH_PHY_IO_Init, ETH_PHY_IO_DeInit, ETH_PHY_IO_
|
||||
* 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};
|
||||
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;
|
||||
@ -181,15 +208,15 @@ static void low_level_init(struct netif *netif) {
|
||||
HAL_ETH_Init(&EthHandle);
|
||||
|
||||
/* set MAC hardware address length */
|
||||
netif->hwaddr_len = ETHARP_HWADDR_LEN;
|
||||
netif->hwaddr_len = ETH_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] = ETH_MAC_ADDR0;
|
||||
netif->hwaddr[1] = ETH_MAC_ADDR1;
|
||||
netif->hwaddr[2] = ETH_MAC_ADDR2;
|
||||
netif->hwaddr[3] = ETH_MAC_ADDR3;
|
||||
netif->hwaddr[4] = ETH_MAC_ADDR4;
|
||||
netif->hwaddr[5] = ETH_MAC_ADDR5;
|
||||
|
||||
/* maximum transfer unit */
|
||||
netif->mtu = ETH_MAX_PAYLOAD;
|
||||
@ -198,12 +225,8 @@ static void low_level_init(struct netif *netif) {
|
||||
/* 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++) {
|
||||
HAL_ETH_DescAssignMemory(&EthHandle, idx, Rx_Buff[idx], NULL);
|
||||
|
||||
/* Set Custom pbuf free function */
|
||||
rx_pbuf[idx].custom_free_function = pbuf_free_custom;
|
||||
}
|
||||
/* Initialize the RX POOL */
|
||||
LWIP_MEMPOOL_INIT(RX_POOL);
|
||||
|
||||
/* Set Tx packet config common parameters */
|
||||
memset(&TxConfig, 0 , sizeof(ETH_TxPacketConfig));
|
||||
@ -221,12 +244,13 @@ static void low_level_init(struct netif *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
|
||||
* @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)
|
||||
* @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
|
||||
*
|
||||
@ -236,38 +260,43 @@ static void low_level_init(struct netif *netif) {
|
||||
* 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;
|
||||
uint32_t i = 0U;
|
||||
struct pbuf *q = NULL;
|
||||
err_t errval = ERR_OK;
|
||||
ETH_BufferTypeDef Txbuffer[ETH_TX_DESC_CNT];
|
||||
ETH_BufferTypeDef Txbuffer[ETH_TX_DESC_CNT] = {0};
|
||||
|
||||
for (q = p; q != NULL; q = q->next) {
|
||||
if (i >= ETH_TX_DESC_CNT) return ERR_IF;
|
||||
memset(Txbuffer, 0 , ETH_TX_DESC_CNT*sizeof(ETH_BufferTypeDef));
|
||||
|
||||
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) {
|
||||
if(i>0)
|
||||
{
|
||||
Txbuffer[i-1].next = &Txbuffer[i];
|
||||
}
|
||||
|
||||
if (q->next == NULL) {
|
||||
if(q->next == NULL)
|
||||
{
|
||||
Txbuffer[i].next = NULL;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
TxConfig.Length = framelen;
|
||||
TxConfig.Length = p->tot_len;
|
||||
TxConfig.TxBuffer = Txbuffer;
|
||||
TxConfig.pData = p;
|
||||
|
||||
HAL_StatusTypeDef ret = HAL_ETH_Transmit(&EthHandle, &TxConfig, 20);
|
||||
|
||||
HAL_StatusTypeDef ret = HAL_ETH_Transmit(&EthHandle, &TxConfig, ETH_DMA_TRANSMIT_TIMEOUT);
|
||||
if (ret != HAL_OK) {
|
||||
printf("low_level_output: Could not transmit ethernet packet, code %d!\n\r", ret);
|
||||
printf("low_level_output: Could not transmit ethernet packet, code %d!\n\r",
|
||||
ret);
|
||||
}
|
||||
|
||||
return errval;
|
||||
}
|
||||
|
||||
@ -281,59 +310,40 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p) {
|
||||
*/
|
||||
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)) {
|
||||
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)) {
|
||||
current_pbuf_idx++;
|
||||
} else {
|
||||
current_pbuf_idx = 0;
|
||||
if(RxAllocStatus == RX_ALLOC_OK)
|
||||
{
|
||||
HAL_ETH_ReadData(&EthHandle, (void **)&p);
|
||||
}
|
||||
|
||||
return p;
|
||||
} 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.
|
||||
* @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;
|
||||
struct pbuf *p = NULL;
|
||||
|
||||
/* move received packet into a new pbuf */
|
||||
do
|
||||
{
|
||||
p = low_level_input( netif );
|
||||
|
||||
/* no packet could be read, silently ignore this */
|
||||
if (p == NULL) return;
|
||||
|
||||
/* entry point to the LwIP stack */
|
||||
err = netif->input(p, netif);
|
||||
|
||||
if (err != ERR_OK) {
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
|
||||
if (p != NULL)
|
||||
{
|
||||
if (netif->input( p, netif) != ERR_OK )
|
||||
{
|
||||
pbuf_free(p);
|
||||
p = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
HAL_ETH_BuildRxDescriptors(&EthHandle);
|
||||
} while(p!=NULL);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -358,6 +368,7 @@ err_t ethernetif_init(struct netif *netif) {
|
||||
|
||||
netif->name[0] = IFNAME0;
|
||||
netif->name[1] = IFNAME1;
|
||||
|
||||
/* We directly use etharp_output() here to save a function call.
|
||||
* You can instead declare your own function an call etharp_output()
|
||||
* from it if you have to do some checks before sending (e.g. if link
|
||||
@ -377,12 +388,13 @@ err_t ethernetif_init(struct netif *netif) {
|
||||
* @retval None
|
||||
*/
|
||||
void pbuf_free_custom(struct pbuf *p) {
|
||||
if (p != NULL) {
|
||||
p->flags = 0;
|
||||
p->next = NULL;
|
||||
p->len = p->tot_len = 0;
|
||||
p->ref = 0;
|
||||
p->payload = NULL;
|
||||
struct pbuf_custom* custom_pbuf = (struct pbuf_custom*)p;
|
||||
LWIP_MEMPOOL_FREE(RX_POOL, custom_pbuf);
|
||||
/* If the Rx Buffer Pool was exhausted, signal the ethernetif_input task to
|
||||
* call HAL_ETH_GetRxDataBuffer to rebuild the Rx descriptors. */
|
||||
if (RxAllocStatus == RX_ALLOC_ERROR)
|
||||
{
|
||||
RxAllocStatus = RX_ALLOC_OK;
|
||||
}
|
||||
}
|
||||
|
||||
@ -413,7 +425,8 @@ void HAL_ETH_MspInit(ETH_HandleTypeDef *heth) {
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
||||
|
||||
/* Ethernet pins configuration ************************************************/
|
||||
/* Ethernet pins configuration
|
||||
* ************************************************/
|
||||
/*
|
||||
RMII_REF_CLK ----------------------> PA1
|
||||
RMII_MDIO -------------------------> PA2
|
||||
@ -492,8 +505,10 @@ int32_t ETH_PHY_IO_DeInit(void) { return 0; }
|
||||
* @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) {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -507,8 +522,10 @@ int32_t ETH_PHY_IO_ReadReg(uint32_t DevAddr, uint32_t RegAddr, uint32_t *pRegVal
|
||||
* @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) {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -526,18 +543,22 @@ int32_t ETH_PHY_IO_GetTick(void) { return HAL_GetTick(); }
|
||||
* @retval None
|
||||
*/
|
||||
void ethernet_link_check_state(struct netif *netif) {
|
||||
ETH_MACConfigTypeDef MACConf;
|
||||
uint32_t PHYLinkState;
|
||||
uint32_t linkchanged = 0, speed = 0, duplex = 0;
|
||||
ETH_MACConfigTypeDef MACConf = {0};
|
||||
int32_t PHYLinkState = 0U;
|
||||
uint32_t linkchanged = 0U, speed = 0U, duplex = 0U;
|
||||
|
||||
PHYLinkState = LAN8742_GetLinkState(&LAN8742);
|
||||
|
||||
if (netif_is_link_up(netif) && (PHYLinkState <= LAN8742_STATUS_LINK_DOWN)) {
|
||||
HAL_ETH_Stop(&EthHandle);
|
||||
if(netif_is_link_up(netif) && (PHYLinkState <= LAN8742_STATUS_LINK_DOWN))
|
||||
{
|
||||
HAL_ETH_Stop_IT(&EthHandle);
|
||||
netif_set_down(netif);
|
||||
netif_set_link_down(netif);
|
||||
} else if (!netif_is_link_up(netif) && (PHYLinkState > LAN8742_STATUS_LINK_DOWN)) {
|
||||
switch (PHYLinkState) {
|
||||
}
|
||||
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;
|
||||
@ -562,19 +583,81 @@ void ethernet_link_check_state(struct netif *netif) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (linkchanged) {
|
||||
if(linkchanged)
|
||||
{
|
||||
/* Get MAC Config MAC */
|
||||
HAL_ETH_GetMACConfig(&EthHandle, &MACConf);
|
||||
MACConf.DuplexMode = duplex;
|
||||
MACConf.Speed = speed;
|
||||
HAL_ETH_SetMACConfig(&EthHandle, &MACConf);
|
||||
HAL_ETH_Start(&EthHandle);
|
||||
HAL_ETH_Start_IT(&EthHandle);
|
||||
netif_set_up(netif);
|
||||
netif_set_link_up(netif);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_ETH_RxAllocateCallback(uint8_t **buff)
|
||||
{
|
||||
struct pbuf_custom *p = LWIP_MEMPOOL_ALLOC(RX_POOL);
|
||||
if (p)
|
||||
{
|
||||
/* Get the buff from the struct pbuf address. */
|
||||
*buff = (uint8_t *)p + offsetof(RxBuff_t, buff);
|
||||
p->custom_free_function = pbuf_free_custom;
|
||||
/* Initialize the struct pbuf.
|
||||
* This must be performed whenever a buffer's allocated because it may be
|
||||
* changed by lwIP or the app, e.g., pbuf_free decrements ref. */
|
||||
pbuf_alloced_custom(PBUF_RAW, 0, PBUF_REF, p, *buff, ETH_RX_BUFFER_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
RxAllocStatus = RX_ALLOC_ERROR;
|
||||
*buff = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_ETH_RxLinkCallback(void **pStart, void **pEnd, uint8_t *buff, uint16_t Length)
|
||||
{
|
||||
struct pbuf **ppStart = (struct pbuf **)pStart;
|
||||
struct pbuf **ppEnd = (struct pbuf **)pEnd;
|
||||
struct pbuf *p = NULL;
|
||||
|
||||
/* Get the struct pbuf from the buff address. */
|
||||
p = (struct pbuf *)(buff - offsetof(RxBuff_t, buff));
|
||||
p->next = NULL;
|
||||
p->tot_len = 0;
|
||||
p->len = Length;
|
||||
|
||||
/* Chain the buffer. */
|
||||
if (!*ppStart)
|
||||
{
|
||||
/* The first buffer of the packet. */
|
||||
*ppStart = p;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Chain the buffer to the end of the packet. */
|
||||
(*ppEnd)->next = p;
|
||||
}
|
||||
*ppEnd = p;
|
||||
|
||||
/* Update the total length of all the buffers of the chain. Each pbuf in the chain should have its tot_len
|
||||
* set to its own length, plus the length of all the following pbufs in the chain. */
|
||||
for (p = *ppStart; p != NULL; p = p->next)
|
||||
{
|
||||
p->tot_len += Length;
|
||||
}
|
||||
|
||||
/* Invalidate data cache because Rx DMA's writing to physical memory makes it stale. */
|
||||
SCB_InvalidateDCache_by_Addr((uint32_t *)buff, Length);
|
||||
}
|
||||
|
||||
void HAL_ETH_TxFreeCallback(uint32_t * buff)
|
||||
{
|
||||
pbuf_free((struct pbuf *)buff);
|
||||
}
|
||||
|
||||
ETH_HandleTypeDef *getEthernetHandle() { return &EthHandle; }
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
@ -46,7 +46,6 @@
|
||||
#ifndef __ETHERNETIF_H__
|
||||
#define __ETHERNETIF_H__
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stm32h7xx_hal.h>
|
||||
|
||||
#include "lwip/err.h"
|
||||
@ -56,8 +55,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ETH_RX_BUFFER_SIZE (1536UL)
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
ETH_HandleTypeDef *getEthernetHandle();
|
||||
@ -67,7 +64,6 @@ void ethernet_link_check_state(struct netif *netif);
|
||||
|
||||
extern ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT];
|
||||
extern ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT];
|
||||
extern uint8_t Rx_Buff[ETH_RX_DESC_CNT][ETH_RX_BUFFER_SIZE];
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -4,11 +4,14 @@
|
||||
|
||||
bool ethernetCableConnected = false;
|
||||
|
||||
void networking::setEthCableConnected(bool status) { ethernetCableConnected = status; }
|
||||
void networking::setEthCableConnected(bool status) {
|
||||
ethernetCableConnected = status;
|
||||
}
|
||||
|
||||
bool networking::getEthCableConnected() { return ethernetCableConnected; }
|
||||
|
||||
void networking::setLwipAddresses(ip_addr_t* ipaddr, ip_addr_t* netmask, ip_addr_t* gw) {
|
||||
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);
|
||||
|
@ -8,7 +8,8 @@ extern "C" {
|
||||
/* UDP local connection port. Client needs to bind to this port */
|
||||
#define UDP_SERVER_PORT 7
|
||||
|
||||
/*Static DEST IP ADDRESS: DEST_IP_ADDR0.DEST_IP_ADDR1.DEST_IP_ADDR2.DEST_IP_ADDR3 */
|
||||
/*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)
|
||||
|
Loading…
Reference in New Issue
Block a user