diff --git a/hal/src/fsfw_hal/linux/CMakeLists.txt b/hal/src/fsfw_hal/linux/CMakeLists.txt index 5ec8af060..0fb2d385c 100644 --- a/hal/src/fsfw_hal/linux/CMakeLists.txt +++ b/hal/src/fsfw_hal/linux/CMakeLists.txt @@ -14,3 +14,5 @@ if(FSFW_HAL_LINUX_ADD_PERIPHERAL_DRIVERS) add_subdirectory(i2c) add_subdirectory(uart) endif() + +add_subdirectory(uio) diff --git a/hal/src/fsfw_hal/linux/uio/CMakeLists.txt b/hal/src/fsfw_hal/linux/uio/CMakeLists.txt new file mode 100644 index 000000000..e98a08657 --- /dev/null +++ b/hal/src/fsfw_hal/linux/uio/CMakeLists.txt @@ -0,0 +1,3 @@ +target_sources(${LIB_FSFW_NAME} PUBLIC + UioMapper.cpp +) diff --git a/hal/src/fsfw_hal/linux/uio/UioMapper.cpp b/hal/src/fsfw_hal/linux/uio/UioMapper.cpp new file mode 100644 index 000000000..43ca27278 --- /dev/null +++ b/hal/src/fsfw_hal/linux/uio/UioMapper.cpp @@ -0,0 +1,86 @@ +#include "UioMapper.h" + +#include +#include + +#include +#include +#include + +#include "fsfw/serviceinterface.h" + +const char UioMapper::UIO_PATH_PREFIX[] = "/sys/class/uio/"; +const char UioMapper::MAP_SUBSTR[] = "/maps/map"; +const char UioMapper::SIZE_FILE_PATH[] = "/size"; + +UioMapper::UioMapper(std::string uioFile, int mapNum) : uioFile(uioFile), mapNum(mapNum) {} + +UioMapper::~UioMapper() {} + +ReturnValue_t UioMapper::getMappedAdress(uint32_t** address, Permissions permissions) { + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + int fd = open(uioFile.c_str(), O_RDWR); + if (fd < 1) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "PtmeAxiConfig::initialize: Invalid UIO device file" << std::endl; +#endif + return HasReturnvaluesIF::RETURN_FAILED; + } + size_t size = 0; + result = getMapSize(&size); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + *address = static_cast( + mmap(NULL, size, static_cast(permissions), MAP_SHARED, fd, mapNum * getpagesize())); + + if (*address == MAP_FAILED) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "UioMapper::getMappedAdress: Failed to map physical address of uio device " + << uioFile.c_str() << " and map" << static_cast(mapNum) << std::endl; +#endif + return HasReturnvaluesIF::RETURN_FAILED; + } + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t UioMapper::getMapSize(size_t* size) { + std::stringstream namestream; + namestream << UIO_PATH_PREFIX << uioFile.substr(5, std::string::npos) << MAP_SUBSTR << mapNum + << SIZE_FILE_PATH; + FILE* fp; + fp = fopen(namestream.str().c_str(), "r"); + if (fp == nullptr) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "UioMapper::getMapSize: Failed to open file " << namestream.str() << std::endl; +#endif + return HasReturnvaluesIF::RETURN_FAILED; + } + char hexstring[SIZE_HEX_STRING] = ""; + int items = fscanf(fp, "%s", hexstring); + if (items != 1) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "UioMapper::getMapSize: Failed with error code " << errno + << " to read size " + "string from file " + << namestream.str() << std::endl; +#endif + fclose(fp); + return HasReturnvaluesIF::RETURN_FAILED; + } + uint32_t sizeTmp = 0; + items = sscanf(hexstring, "%x", &sizeTmp); + if (size != nullptr) { + *size = sizeTmp; + } + if (items != 1) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "UioMapper::getMapSize: Failed with error code " << errno << "to convert " + << "size of map" << mapNum << " to integer" << std::endl; +#endif + fclose(fp); + return HasReturnvaluesIF::RETURN_FAILED; + } + fclose(fp); + return HasReturnvaluesIF::RETURN_OK; +} diff --git a/hal/src/fsfw_hal/linux/uio/UioMapper.h b/hal/src/fsfw_hal/linux/uio/UioMapper.h new file mode 100644 index 000000000..20c90b4d2 --- /dev/null +++ b/hal/src/fsfw_hal/linux/uio/UioMapper.h @@ -0,0 +1,58 @@ +#ifndef FSFW_HAL_SRC_FSFW_HAL_LINUX_UIO_UIOMAPPER_H_ +#define FSFW_HAL_SRC_FSFW_HAL_LINUX_UIO_UIOMAPPER_H_ + +#include + +#include + +#include "fsfw/returnvalues/HasReturnvaluesIF.h" + +/** + * @brief Class to help opening uio device files and mapping the physical addresses into the user + * address space. + * + * @author J. Meier + */ +class UioMapper { + public: + enum class Permissions : int { + READ_ONLY = PROT_READ, + WRITE_ONLY = PROT_WRITE, + READ_WRITE = PROT_READ | PROT_WRITE + }; + + /** + * @brief Constructor + * + * @param uioFile The device file of the uiO to open + * @param uioMap Number of memory map. Most UIO drivers have only one map which has than 0. + */ + UioMapper(std::string uioFile, int mapNum = 0); + virtual ~UioMapper(); + + /** + * @brief Maps the physical address into user address space and returns the mapped address + * + * @address The mapped user space address + * @permissions Specifies the read/write permissions of the address region + */ + ReturnValue_t getMappedAdress(uint32_t** address, Permissions permissions); + + private: + static const char UIO_PATH_PREFIX[]; + static const char MAP_SUBSTR[]; + static const char SIZE_FILE_PATH[]; + static constexpr int SIZE_HEX_STRING = 10; + + std::string uioFile; + int mapNum = 0; + + /** + * @brief Reads the map size from the associated sysfs size file + * + * @param size The read map size + */ + ReturnValue_t getMapSize(size_t* size); +}; + +#endif /* FSFW_HAL_SRC_FSFW_HAL_LINUX_UIO_UIOMAPPER_H_ */ diff --git a/src/fsfw/datalinklayer/DataLinkLayer.h b/src/fsfw/datalinklayer/DataLinkLayer.h index edfba8a6a..8735feb68 100644 --- a/src/fsfw/datalinklayer/DataLinkLayer.h +++ b/src/fsfw/datalinklayer/DataLinkLayer.h @@ -30,7 +30,7 @@ class DataLinkLayer : public CCSDSReturnValuesIF { //! [EXPORT] : [COMMENT] A previously found Bit Lock signal was lost. P1: raw BLO state, P2: 0 static const Event BIT_LOCK_LOST = MAKE_EVENT(3, severity::INFO); // static const Event RF_CHAIN_LOST = MAKE_EVENT(4, severity::INFO); //!< The CCSDS Board - //detected that either bit lock or RF available or both are lost. No parameters. + // detected that either bit lock or RF available or both are lost. No parameters. //! [EXPORT] : [COMMENT] The CCSDS Board could not interpret a TC static const Event FRAME_PROCESSING_FAILED = MAKE_EVENT(5, severity::LOW); /** diff --git a/src/fsfw/datalinklayer/VirtualChannelReception.cpp b/src/fsfw/datalinklayer/VirtualChannelReception.cpp index 4ee0c0086..258bc1e64 100644 --- a/src/fsfw/datalinklayer/VirtualChannelReception.cpp +++ b/src/fsfw/datalinklayer/VirtualChannelReception.cpp @@ -30,9 +30,9 @@ ReturnValue_t VirtualChannelReception::mapDemultiplexing(TcTransferFrame* frame) mapChannelIterator iter = mapChannels.find(mapId); if (iter == mapChannels.end()) { // error << "VirtualChannelReception::mapDemultiplexing on VC " << std::hex << (int) - //channelId + // channelId // << ": MapChannel " << (int) mapId << std::dec << " not found." << - //std::endl; + // std::endl; return VC_NOT_FOUND; } else { return (iter->second)->extractPackets(frame); diff --git a/src/fsfw/globalfunctions/CRC.cpp b/src/fsfw/globalfunctions/CRC.cpp index 942e4a1a2..6b8140c52 100644 --- a/src/fsfw/globalfunctions/CRC.cpp +++ b/src/fsfw/globalfunctions/CRC.cpp @@ -116,8 +116,8 @@ uint16_t CRC::crc16ccitt(uint8_t const input[], uint32_t length, uint16_t starti // for (int i=0; i<16 ;i++) // { // if (xor_out[i] == true) - // crc_value = crc_value + pow(2,(15 -i)); // reverse CrC result before Final - //XOR + // crc_value = crc_value + pow(2,(15 -i)); // reverse CrC result before + //Final XOR // } // // crc_value = 0;// for debug mode diff --git a/src/fsfw/modes/ModeMessage.h b/src/fsfw/modes/ModeMessage.h index e3638ee00..84429e840 100644 --- a/src/fsfw/modes/ModeMessage.h +++ b/src/fsfw/modes/ModeMessage.h @@ -14,30 +14,30 @@ class ModeMessage { static const uint8_t MESSAGE_ID = messagetypes::MODE_COMMAND; static const Command_t CMD_MODE_COMMAND = MAKE_COMMAND_ID(0x01); //!> Command to set the specified Mode, replies are: REPLY_MODE_REPLY, - //!REPLY_WRONG_MODE_REPLY, and REPLY_REJECTED; don't add any replies, - //!as this will break the subsystem mode machine!! + //! REPLY_WRONG_MODE_REPLY, and REPLY_REJECTED; don't add any replies, + //! as this will break the subsystem mode machine!! static const Command_t CMD_MODE_COMMAND_FORCED = MAKE_COMMAND_ID( 0xF1); //!> Command to set the specified Mode, regardless of external control flag, replies - //!are: REPLY_MODE_REPLY, REPLY_WRONG_MODE_REPLY, and REPLY_REJECTED; don't add any - //!replies, as this will break the subsystem mode machine!! + //! are: REPLY_MODE_REPLY, REPLY_WRONG_MODE_REPLY, and REPLY_REJECTED; don't add any + //! replies, as this will break the subsystem mode machine!! static const Command_t REPLY_MODE_REPLY = MAKE_COMMAND_ID(0x02); //!> Reply to a CMD_MODE_COMMAND or CMD_MODE_READ static const Command_t REPLY_MODE_INFO = MAKE_COMMAND_ID(0x03); //!> Unrequested info about the current mode (used for composites to - //!inform their container of a changed mode) + //! inform their container of a changed mode) static const Command_t REPLY_CANT_REACH_MODE = MAKE_COMMAND_ID( 0x04); //!> Reply in case a mode command can't be executed. Par1: returnCode, Par2: 0 static const Command_t REPLY_WRONG_MODE_REPLY = MAKE_COMMAND_ID(0x05); //!> Reply to a CMD_MODE_COMMAND, indicating that a mode was commanded - //!and a transition started but was aborted; the parameters contain - //!the mode that was reached + //! and a transition started but was aborted; the parameters contain + //! the mode that was reached static const Command_t CMD_MODE_READ = MAKE_COMMAND_ID( 0x06); //!> Command to read the current mode and reply with a REPLY_MODE_REPLY static const Command_t CMD_MODE_ANNOUNCE = MAKE_COMMAND_ID( 0x07); //!> Command to trigger an ModeInfo Event. This command does NOT have a reply. static const Command_t CMD_MODE_ANNOUNCE_RECURSIVELY = MAKE_COMMAND_ID(0x08); //!> Command to trigger an ModeInfo Event and to send this command to - //!every child. This command does NOT have a reply. + //! every child. This command does NOT have a reply. static Mode_t getMode(const CommandMessage* message); static Submode_t getSubmode(const CommandMessage* message); diff --git a/src/fsfw/osal/linux/PeriodicPosixTask.h b/src/fsfw/osal/linux/PeriodicPosixTask.h index e2db042d0..3c9a3a0d7 100644 --- a/src/fsfw/osal/linux/PeriodicPosixTask.h +++ b/src/fsfw/osal/linux/PeriodicPosixTask.h @@ -65,8 +65,8 @@ class PeriodicPosixTask : public PosixThread, public PeriodicTaskIF { /** * @brief The function containing the actual functionality of the task. * @details The method sets and starts - * the task's period, then enters a loop that is repeated indefinitely. Within the loop, - * all performOperation methods of the added objects are called. Afterwards the task will be + * the task's period, then enters a loop that is repeated indefinitely. Within the + * loop, all performOperation methods of the added objects are called. Afterwards the task will be * blocked until the next period. On missing the deadline, the deadlineMissedFunction is executed. */ virtual void taskFunctionality(void); diff --git a/src/fsfw/osal/rtems/PeriodicTask.h b/src/fsfw/osal/rtems/PeriodicTask.h index e2643ec70..ff8617fca 100644 --- a/src/fsfw/osal/rtems/PeriodicTask.h +++ b/src/fsfw/osal/rtems/PeriodicTask.h @@ -13,8 +13,8 @@ class ExecutableObjectIF; * @brief This class represents a specialized task for periodic activities of multiple objects. * * @details MultiObjectTask is an extension to ObjectTask in the way that it is able to execute - * multiple objects that implement the ExecutableObjectIF interface. The objects must - * be added prior to starting the task. + * multiple objects that implement the ExecutableObjectIF interface. The objects + * must be added prior to starting the task. * @author baetz * @ingroup task_handling */ diff --git a/src/fsfw/osal/rtems/RTEMSTaskBase.h b/src/fsfw/osal/rtems/RTEMSTaskBase.h index 784d35946..9ae9e7552 100644 --- a/src/fsfw/osal/rtems/RTEMSTaskBase.h +++ b/src/fsfw/osal/rtems/RTEMSTaskBase.h @@ -25,8 +25,8 @@ class RTEMSTaskBase { * all other attributes are set with default values. * @param priority Sets the priority of a task. Values range from a low 0 to a high 99. * @param stack_size The stack size reserved by the operating system for the task. - * @param nam The name of the Task, as a null-terminated String. Currently max 4 chars - * supported (excluding Null-terminator), rest will be truncated + * @param nam The name of the Task, as a null-terminated String. Currently max 4 + * chars supported (excluding Null-terminator), rest will be truncated */ RTEMSTaskBase(rtems_task_priority priority, size_t stack_size, const char *name); /** diff --git a/src/fsfw/rmap/RMAP.h b/src/fsfw/rmap/RMAP.h index d46fc3188..42ee1ac5d 100644 --- a/src/fsfw/rmap/RMAP.h +++ b/src/fsfw/rmap/RMAP.h @@ -51,9 +51,9 @@ class RMAP : public HasReturnvaluesIF { // MAKE_RETURN_CODE(0xE4); //the data that was to be sent was too long for the hw to handle (write // command) or the expected len was bigger than maximal expected len (read command) command was // not sent - // replaced by DeviceCommunicationIF::NULLPOINTER static const ReturnValue_t COMMAND_NULLPOINTER - // = MAKE_RETURN_CODE(0xE5); //datalen was != 0 but data was == NULL in write command, or - // nullpointer in read command + // replaced by DeviceCommunicationIF::NULLPOINTER static const ReturnValue_t + // COMMAND_NULLPOINTER = MAKE_RETURN_CODE(0xE5); //datalen was != 0 but data was == NULL in write + // command, or nullpointer in read command static const ReturnValue_t COMMAND_CHANNEL_DEACTIVATED = MAKE_RETURN_CODE(0xE6); // the channel has no port set static const ReturnValue_t COMMAND_PORT_OUT_OF_RANGE = @@ -73,8 +73,8 @@ class RMAP : public HasReturnvaluesIF { static const ReturnValue_t REPLY_MISSMATCH = MAKE_RETURN_CODE( 0xD3); // a read command was issued, but get_write_rply called, or other way round static const ReturnValue_t REPLY_TIMEOUT = MAKE_RETURN_CODE(0xD4); // timeout - // replaced by DeviceCommunicationIF::NULLPOINTER static const ReturnValue_t REPLY_NULLPOINTER = - // MAKE_RETURN_CODE(0xD5);//one of the arguments in a read reply was NULL return values for + // replaced by DeviceCommunicationIF::NULLPOINTER static const ReturnValue_t REPLY_NULLPOINTER + // = MAKE_RETURN_CODE(0xD5);//one of the arguments in a read reply was NULL return values for // get_reply static const ReturnValue_t REPLY_INTERFACE_BUSY = MAKE_RETURN_CODE(0xC0); // Interface is busy (transmission buffer still being processed) @@ -169,8 +169,8 @@ class RMAP : public HasReturnvaluesIF { * @param buffer the data to write * @param length length of data * @return - * - @c COMMAND_NULLPOINTER datalen was != 0 but data was == NULL in write - * command + * - @c COMMAND_NULLPOINTER datalen was != 0 but data was == NULL in + * write command * - return codes of RMAPChannelIF::sendCommand() */ static ReturnValue_t sendWriteCommand(RMAPCookie *cookie, const uint8_t *buffer, size_t length); @@ -205,8 +205,8 @@ class RMAP : public HasReturnvaluesIF { * @param cookie to cookie to read from * @param expLength the expected maximum length of the reply * @return - * - @c COMMAND_NULLPOINTER datalen was != 0 but data was == NULL in write - * command, or nullpointer in read command + * - @c COMMAND_NULLPOINTER datalen was != 0 but data was == NULL in + * write command, or nullpointer in read command * - return codes of RMAPChannelIF::sendCommand() */ static ReturnValue_t sendReadCommand(RMAPCookie *cookie, uint32_t expLength); diff --git a/src/fsfw/rmap/RMAPChannelIF.h b/src/fsfw/rmap/RMAPChannelIF.h index 77b56eb9b..20dfd5f80 100644 --- a/src/fsfw/rmap/RMAPChannelIF.h +++ b/src/fsfw/rmap/RMAPChannelIF.h @@ -73,16 +73,16 @@ class RMAPChannelIF { * @param datalen length of data * @return * - @c RETURN_OK - * - @c COMMAND_NO_DESCRIPTORS_AVAILABLE no descriptors available for sending command; - * command was not sent - * - @c COMMAND_BUFFER_FULL no receiver buffer available for expected len; command - * was not sent - * - @c COMMAND_TOO_BIG the data that was to be sent was too long for the hw to - * handle (write command) or the expected len was bigger than maximal expected len (read command) + * - @c COMMAND_NO_DESCRIPTORS_AVAILABLE no descriptors available for sending + * command; command was not sent + * - @c COMMAND_BUFFER_FULL no receiver buffer available for expected len; * command was not sent + * - @c COMMAND_TOO_BIG the data that was to be sent was too long for the hw + * to handle (write command) or the expected len was bigger than maximal expected len (read + * command) command was not sent * - @c COMMAND_CHANNEL_DEACTIVATED the channel has no port set - * - @c NOT_SUPPORTED if you dont feel like implementing - * something... + * - @c NOT_SUPPORTED if you dont feel like + * implementing something... */ virtual ReturnValue_t sendCommand(RMAPCookie *cookie, uint8_t instruction, const uint8_t *data, size_t datalen) = 0; @@ -97,8 +97,8 @@ class RMAPChannelIF { * - @c REPLY_NO_REPLY no reply was received * - @c REPLY_NOT_SENT command was not sent, implies no reply * - @c REPLY_NOT_YET_SENT command is still waiting to be sent - * - @c WRITE_REPLY_INTERFACE_BUSY Interface is busy (transmission buffer still being - * processed) + * - @c WRITE_REPLY_INTERFACE_BUSY Interface is busy (transmission buffer still + * being processed) * - @c WRITE_REPLY_TRANSMISSION_ERROR Interface encountered errors during last * operation, data could not be processed. (transmission error) * - @c WRITE_REPLY_INVALID_DATA Invalid data (amount / value) diff --git a/src/fsfw/rmap/rmapStructs.h b/src/fsfw/rmap/rmapStructs.h index 44eedc16c..55e32606f 100644 --- a/src/fsfw/rmap/rmapStructs.h +++ b/src/fsfw/rmap/rmapStructs.h @@ -32,10 +32,10 @@ static const uint8_t RMAP_COMMAND_READ = ((1 << RMAP_COMMAND_BIT) | (1 << RMAP_C static const uint8_t RMAP_REPLY_WRITE = ((1 << RMAP_COMMAND_BIT_WRITE) | (1 << RMAP_COMMAND_BIT_REPLY)); static const uint8_t RMAP_REPLY_READ = ((1 << RMAP_COMMAND_BIT_REPLY)); -//#define RMAP_COMMAND_WRITE ((1<