Merge remote-tracking branch 'origin/development' into mueller/update-changelog

This commit is contained in:
Robin Müller 2022-02-02 10:40:25 +01:00
commit 51add8a8ad
809 changed files with 52010 additions and 56052 deletions

View File

@ -1,8 +1,8 @@
#include "fsfw_hal/common/gpio/GpioCookie.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
GpioCookie::GpioCookie() {
}
GpioCookie::GpioCookie() {}
ReturnValue_t GpioCookie::addGpio(gpioId_t gpioId, GpioBase* gpioConfig) {
if (gpioConfig == nullptr) {
@ -14,13 +14,13 @@ ReturnValue_t GpioCookie::addGpio(gpioId_t gpioId, GpioBase* gpioConfig) {
return HasReturnvaluesIF::RETURN_FAILED;
}
auto gpioMapIter = gpioMap.find(gpioId);
if(gpioMapIter == gpioMap.end()) {
if (gpioMapIter == gpioMap.end()) {
auto statusPair = gpioMap.emplace(gpioId, gpioConfig);
if (statusPair.second == false) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "GpioCookie::addGpio: Failed to add GPIO " << gpioId <<
" to GPIO map" << std::endl;
sif::warning << "GpioCookie::addGpio: Failed to add GPIO " << gpioId << " to GPIO map"
<< std::endl;
#else
sif::printWarning("GpioCookie::addGpio: Failed to add GPIO %d to GPIO map\n", gpioId);
#endif
@ -39,12 +39,10 @@ ReturnValue_t GpioCookie::addGpio(gpioId_t gpioId, GpioBase* gpioConfig) {
return HasReturnvaluesIF::RETURN_FAILED;
}
GpioMap GpioCookie::getGpioMap() const {
return gpioMap;
}
GpioMap GpioCookie::getGpioMap() const { return gpioMap; }
GpioCookie::~GpioCookie() {
for(auto& config: gpioMap) {
delete(config.second);
for (auto& config : gpioMap) {
delete (config.second);
}
}

View File

@ -1,12 +1,12 @@
#ifndef COMMON_GPIO_GPIOCOOKIE_H_
#define COMMON_GPIO_GPIOCOOKIE_H_
#include "GpioIF.h"
#include "gpioDefinitions.h"
#include <fsfw/devicehandlers/CookieIF.h>
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
#include "GpioIF.h"
#include "gpioDefinitions.h"
/**
* @brief Cookie for the GpioIF. Allows the GpioIF to determine which
* GPIOs to initialize and whether they should be configured as in- or
@ -17,9 +17,8 @@
*
* @author J. Meier
*/
class GpioCookie: public CookieIF {
public:
class GpioCookie : public CookieIF {
public:
GpioCookie();
virtual ~GpioCookie();
@ -31,7 +30,7 @@ public:
*/
GpioMap getGpioMap() const;
private:
private:
/**
* Returns a copy of the internal GPIO map.
*/

View File

@ -1,9 +1,10 @@
#ifndef COMMON_GPIO_GPIOIF_H_
#define COMMON_GPIO_GPIOIF_H_
#include "gpioDefinitions.h"
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
#include <fsfw/devicehandlers/CookieIF.h>
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
#include "gpioDefinitions.h"
class GpioCookie;
@ -13,9 +14,8 @@ class GpioCookie;
* @author J. Meier
*/
class GpioIF : public HasReturnvaluesIF {
public:
virtual ~GpioIF() {};
public:
virtual ~GpioIF(){};
/**
* @brief Called by the GPIO using object.

View File

@ -1,29 +1,19 @@
#ifndef COMMON_GPIO_GPIODEFINITIONS_H_
#define COMMON_GPIO_GPIODEFINITIONS_H_
#include <map>
#include <string>
#include <unordered_map>
#include <map>
using gpioId_t = uint16_t;
namespace gpio {
enum Levels: uint8_t {
LOW = 0,
HIGH = 1,
NONE = 99
};
enum Levels : uint8_t { LOW = 0, HIGH = 1, NONE = 99 };
enum Direction: uint8_t {
IN = 0,
OUT = 1
};
enum Direction : uint8_t { IN = 0, OUT = 1 };
enum GpioOperation {
READ,
WRITE
};
enum GpioOperation { READ, WRITE };
enum class GpioTypes {
NONE,
@ -35,10 +25,10 @@ enum class GpioTypes {
static constexpr gpioId_t NO_GPIO = -1;
using gpio_cb_t = void (*) (gpioId_t gpioId, gpio::GpioOperation gpioOp, gpio::Levels value,
using gpio_cb_t = void (*)(gpioId_t gpioId, gpio::GpioOperation gpioOp, gpio::Levels value,
void* args);
}
} // namespace gpio
/**
* @brief Struct containing information about the GPIO to use. This is
@ -55,15 +45,14 @@ using gpio_cb_t = void (*) (gpioId_t gpioId, gpio::GpioOperation gpioOp, gpio::L
* pointer.
*/
class GpioBase {
public:
public:
GpioBase() = default;
GpioBase(gpio::GpioTypes gpioType, std::string consumer, gpio::Direction direction,
gpio::Levels initValue):
gpioType(gpioType), consumer(consumer),direction(direction), initValue(initValue) {}
gpio::Levels initValue)
: gpioType(gpioType), consumer(consumer), direction(direction), initValue(initValue) {}
virtual~ GpioBase() {};
virtual ~GpioBase(){};
// Can be used to cast GpioBase to a concrete child implementation
gpio::GpioTypes gpioType = gpio::GpioTypes::NONE;
@ -72,59 +61,53 @@ public:
gpio::Levels initValue = gpio::Levels::NONE;
};
class GpiodRegularBase: public GpioBase {
public:
class GpiodRegularBase : public GpioBase {
public:
GpiodRegularBase(gpio::GpioTypes gpioType, std::string consumer, gpio::Direction direction,
gpio::Levels initValue, int lineNum):
GpioBase(gpioType, consumer, direction, initValue), lineNum(lineNum) {
}
gpio::Levels initValue, int lineNum)
: GpioBase(gpioType, consumer, direction, initValue), lineNum(lineNum) {}
// line number will be configured at a later point for the open by line name configuration
GpiodRegularBase(gpio::GpioTypes gpioType, std::string consumer, gpio::Direction direction,
gpio::Levels initValue): GpioBase(gpioType, consumer, direction, initValue) {
}
gpio::Levels initValue)
: GpioBase(gpioType, consumer, direction, initValue) {}
int lineNum = 0;
struct gpiod_line* lineHandle = nullptr;
};
class GpiodRegularByChip: public GpiodRegularBase {
public:
GpiodRegularByChip() :
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP,
std::string(), gpio::Direction::IN, gpio::LOW, 0) {
}
class GpiodRegularByChip : public GpiodRegularBase {
public:
GpiodRegularByChip()
: GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP, std::string(), gpio::Direction::IN,
gpio::LOW, 0) {}
GpiodRegularByChip(std::string chipname_, int lineNum_, std::string consumer_,
gpio::Direction direction_, gpio::Levels initValue_) :
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP,
consumer_, direction_, initValue_, lineNum_),
chipname(chipname_){
}
gpio::Direction direction_, gpio::Levels initValue_)
: GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP, consumer_, direction_, initValue_,
lineNum_),
chipname(chipname_) {}
GpiodRegularByChip(std::string chipname_, int lineNum_, std::string consumer_) :
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP, consumer_,
gpio::Direction::IN, gpio::LOW, lineNum_),
chipname(chipname_) {
}
GpiodRegularByChip(std::string chipname_, int lineNum_, std::string consumer_)
: GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP, consumer_, gpio::Direction::IN,
gpio::LOW, lineNum_),
chipname(chipname_) {}
std::string chipname;
};
class GpiodRegularByLabel: public GpiodRegularBase {
public:
class GpiodRegularByLabel : public GpiodRegularBase {
public:
GpiodRegularByLabel(std::string label_, int lineNum_, std::string consumer_,
gpio::Direction direction_, gpio::Levels initValue_) :
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL, consumer_,
direction_, initValue_, lineNum_),
label(label_) {
}
gpio::Direction direction_, gpio::Levels initValue_)
: GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL, consumer_, direction_, initValue_,
lineNum_),
label(label_) {}
GpiodRegularByLabel(std::string label_, int lineNum_, std::string consumer_) :
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL, consumer_,
gpio::Direction::IN, gpio::LOW, lineNum_),
label(label_) {
}
GpiodRegularByLabel(std::string label_, int lineNum_, std::string consumer_)
: GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL, consumer_, gpio::Direction::IN,
gpio::LOW, lineNum_),
label(label_) {}
std::string label;
};
@ -134,34 +117,34 @@ public:
* line name. This line name can be set in the device tree and must be unique. Otherwise
* the driver will open the first line with the given name.
*/
class GpiodRegularByLineName: public GpiodRegularBase {
public:
class GpiodRegularByLineName : public GpiodRegularBase {
public:
GpiodRegularByLineName(std::string lineName_, std::string consumer_, gpio::Direction direction_,
gpio::Levels initValue_) :
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME, consumer_, direction_,
initValue_), lineName(lineName_) {
}
gpio::Levels initValue_)
: GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME, consumer_, direction_,
initValue_),
lineName(lineName_) {}
GpiodRegularByLineName(std::string lineName_, std::string consumer_) :
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME, consumer_,
gpio::Direction::IN, gpio::LOW), lineName(lineName_) {
}
GpiodRegularByLineName(std::string lineName_, std::string consumer_)
: GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME, consumer_, gpio::Direction::IN,
gpio::LOW),
lineName(lineName_) {}
std::string lineName;
};
class GpioCallback: public GpioBase {
public:
class GpioCallback : public GpioBase {
public:
GpioCallback(std::string consumer, gpio::Direction direction_, gpio::Levels initValue_,
gpio::gpio_cb_t callback, void* callbackArgs):
GpioBase(gpio::GpioTypes::CALLBACK, consumer, direction_, initValue_),
callback(callback), callbackArgs(callbackArgs) {}
gpio::gpio_cb_t callback, void* callbackArgs)
: GpioBase(gpio::GpioTypes::CALLBACK, consumer, direction_, initValue_),
callback(callback),
callbackArgs(callbackArgs) {}
gpio::gpio_cb_t callback = nullptr;
void* callbackArgs = nullptr;
};
using GpioMap = std::map<gpioId_t, GpioBase*>;
using GpioUnorderedMap = std::unordered_map<gpioId_t, GpioBase*>;
using GpioMapIter = GpioMap::iterator;

View File

@ -5,12 +5,7 @@
namespace spi {
enum SpiModes: uint8_t {
MODE_0,
MODE_1,
MODE_2,
MODE_3
};
enum SpiModes : uint8_t { MODE_0, MODE_1, MODE_2, MODE_3 };
}

View File

@ -1,13 +1,14 @@
#include "GyroL3GD20Handler.h"
#include "fsfw/datapool/PoolReadGuard.h"
#include <cmath>
#include "fsfw/datapool/PoolReadGuard.h"
GyroHandlerL3GD20H::GyroHandlerL3GD20H(object_id_t objectId, object_id_t deviceCommunication,
CookieIF *comCookie, uint32_t transitionDelayMs):
DeviceHandlerBase(objectId, deviceCommunication, comCookie),
transitionDelayMs(transitionDelayMs), dataset(this) {
CookieIF *comCookie, uint32_t transitionDelayMs)
: DeviceHandlerBase(objectId, deviceCommunication, comCookie),
transitionDelayMs(transitionDelayMs),
dataset(this) {
#if FSFW_HAL_L3GD20_GYRO_DEBUG == 1
debugDivider = new PeriodicOperationDivider(3);
#endif
@ -16,24 +17,23 @@ GyroHandlerL3GD20H::GyroHandlerL3GD20H(object_id_t objectId, object_id_t deviceC
GyroHandlerL3GD20H::~GyroHandlerL3GD20H() {}
void GyroHandlerL3GD20H::doStartUp() {
if(internalState == InternalState::NONE) {
if (internalState == InternalState::NONE) {
internalState = InternalState::CONFIGURE;
}
if(internalState == InternalState::CONFIGURE) {
if(commandExecuted) {
if (internalState == InternalState::CONFIGURE) {
if (commandExecuted) {
internalState = InternalState::CHECK_REGS;
commandExecuted = false;
}
}
if(internalState == InternalState::CHECK_REGS) {
if(commandExecuted) {
if (internalState == InternalState::CHECK_REGS) {
if (commandExecuted) {
internalState = InternalState::NORMAL;
if(goNormalModeImmediately) {
if (goNormalModeImmediately) {
setMode(MODE_NORMAL);
}
else {
} else {
setMode(_MODE_TO_ON);
}
commandExecuted = false;
@ -41,19 +41,17 @@ void GyroHandlerL3GD20H::doStartUp() {
}
}
void GyroHandlerL3GD20H::doShutDown() {
setMode(_MODE_POWER_DOWN);
}
void GyroHandlerL3GD20H::doShutDown() { setMode(_MODE_POWER_DOWN); }
ReturnValue_t GyroHandlerL3GD20H::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
switch(internalState) {
case(InternalState::NONE):
case(InternalState::NORMAL): {
switch (internalState) {
case (InternalState::NONE):
case (InternalState::NORMAL): {
return NOTHING_TO_SEND;
}
case(InternalState::CONFIGURE): {
case (InternalState::CONFIGURE): {
*id = L3GD20H::CONFIGURE_CTRL_REGS;
uint8_t command [5];
uint8_t command[5];
command[0] = L3GD20H::CTRL_REG_1_VAL;
command[1] = L3GD20H::CTRL_REG_2_VAL;
command[2] = L3GD20H::CTRL_REG_3_VAL;
@ -61,7 +59,7 @@ ReturnValue_t GyroHandlerL3GD20H::buildTransitionDeviceCommand(DeviceCommandId_t
command[4] = L3GD20H::CTRL_REG_5_VAL;
return buildCommandFromCommand(*id, command, 5);
}
case(InternalState::CHECK_REGS): {
case (InternalState::CHECK_REGS): {
*id = L3GD20H::READ_REGS;
return buildCommandFromCommand(*id, nullptr, 0);
}
@ -69,9 +67,11 @@ ReturnValue_t GyroHandlerL3GD20H::buildTransitionDeviceCommand(DeviceCommandId_t
#if FSFW_CPP_OSTREAM_ENABLED == 1
/* Might be a configuration error. */
sif::warning << "GyroL3GD20Handler::buildTransitionDeviceCommand: "
"Unknown internal state!" << std::endl;
"Unknown internal state!"
<< std::endl;
#else
sif::printDebug("GyroL3GD20Handler::buildTransitionDeviceCommand: "
sif::printDebug(
"GyroL3GD20Handler::buildTransitionDeviceCommand: "
"Unknown internal state!\n");
#endif
return HasReturnvaluesIF::RETURN_OK;
@ -84,20 +84,20 @@ ReturnValue_t GyroHandlerL3GD20H::buildNormalDeviceCommand(DeviceCommandId_t *id
return buildCommandFromCommand(*id, nullptr, 0);
}
ReturnValue_t GyroHandlerL3GD20H::buildCommandFromCommand(
DeviceCommandId_t deviceCommand, const uint8_t *commandData,
ReturnValue_t GyroHandlerL3GD20H::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
const uint8_t *commandData,
size_t commandDataLen) {
switch(deviceCommand) {
case(L3GD20H::READ_REGS): {
switch (deviceCommand) {
case (L3GD20H::READ_REGS): {
commandBuffer[0] = L3GD20H::READ_START | L3GD20H::AUTO_INCREMENT_MASK | L3GD20H::READ_MASK;
std::memset(commandBuffer + 1, 0, L3GD20H::READ_LEN);
rawPacket = commandBuffer;
rawPacketLen = L3GD20H::READ_LEN + 1;
break;
}
case(L3GD20H::CONFIGURE_CTRL_REGS): {
case (L3GD20H::CONFIGURE_CTRL_REGS): {
commandBuffer[0] = L3GD20H::CTRL_REG_1 | L3GD20H::AUTO_INCREMENT_MASK;
if(commandData == nullptr or commandDataLen != 5) {
if (commandData == nullptr or commandDataLen != 5) {
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
}
@ -110,13 +110,11 @@ ReturnValue_t GyroHandlerL3GD20H::buildCommandFromCommand(
bool fsH = ctrlReg4Value & L3GD20H::SET_FS_1;
bool fsL = ctrlReg4Value & L3GD20H::SET_FS_0;
if(not fsH and not fsL) {
if (not fsH and not fsL) {
sensitivity = L3GD20H::SENSITIVITY_00;
}
else if(not fsH and fsL) {
} else if (not fsH and fsL) {
sensitivity = L3GD20H::SENSITIVITY_01;
}
else {
} else {
sensitivity = L3GD20H::SENSITIVITY_11;
}
@ -130,9 +128,8 @@ ReturnValue_t GyroHandlerL3GD20H::buildCommandFromCommand(
rawPacketLen = 6;
break;
}
case(L3GD20H::READ_CTRL_REGS): {
commandBuffer[0] = L3GD20H::READ_START | L3GD20H::AUTO_INCREMENT_MASK |
L3GD20H::READ_MASK;
case (L3GD20H::READ_CTRL_REGS): {
commandBuffer[0] = L3GD20H::READ_START | L3GD20H::AUTO_INCREMENT_MASK | L3GD20H::READ_MASK;
std::memset(commandBuffer + 1, 0, 5);
rawPacket = commandBuffer;
@ -157,32 +154,30 @@ ReturnValue_t GyroHandlerL3GD20H::scanForReply(const uint8_t *start, size_t len,
ReturnValue_t GyroHandlerL3GD20H::interpretDeviceReply(DeviceCommandId_t id,
const uint8_t *packet) {
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
switch(id) {
case(L3GD20H::CONFIGURE_CTRL_REGS): {
switch (id) {
case (L3GD20H::CONFIGURE_CTRL_REGS): {
commandExecuted = true;
break;
}
case(L3GD20H::READ_CTRL_REGS): {
if(packet[1] == ctrlReg1Value and packet[2] == ctrlReg2Value and
case (L3GD20H::READ_CTRL_REGS): {
if (packet[1] == ctrlReg1Value and packet[2] == ctrlReg2Value and
packet[3] == ctrlReg3Value and packet[4] == ctrlReg4Value and
packet[5] == ctrlReg5Value) {
commandExecuted = true;
}
else {
} else {
// Attempt reconfiguration
internalState = InternalState::CONFIGURE;
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
}
break;
}
case(L3GD20H::READ_REGS): {
if(packet[1] != ctrlReg1Value and packet[2] != ctrlReg2Value and
case (L3GD20H::READ_REGS): {
if (packet[1] != ctrlReg1Value and packet[2] != ctrlReg2Value and
packet[3] != ctrlReg3Value and packet[4] != ctrlReg4Value and
packet[5] != ctrlReg5Value) {
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
}
else {
if(internalState == InternalState::CHECK_REGS) {
} else {
if (internalState == InternalState::CHECK_REGS) {
commandExecuted = true;
}
}
@ -199,7 +194,7 @@ ReturnValue_t GyroHandlerL3GD20H::interpretDeviceReply(DeviceCommandId_t id,
int8_t temperaturOffset = (-1) * packet[L3GD20H::TEMPERATURE_IDX];
float temperature = 25.0 + temperaturOffset;
#if FSFW_HAL_L3GD20_GYRO_DEBUG == 1
if(debugDivider->checkAndIncrement()) {
if (debugDivider->checkAndIncrement()) {
/* Set terminal to utf-8 if there is an issue with micro printout. */
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "GyroHandlerL3GD20H: Angular velocities (deg/s):" << std::endl;
@ -216,28 +211,25 @@ ReturnValue_t GyroHandlerL3GD20H::interpretDeviceReply(DeviceCommandId_t id,
#endif
PoolReadGuard readSet(&dataset);
if(readSet.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
if(std::abs(angVelocX) < this->absLimitX) {
if (readSet.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
if (std::abs(angVelocX) < this->absLimitX) {
dataset.angVelocX = angVelocX;
dataset.angVelocX.setValid(true);
}
else {
} else {
dataset.angVelocX.setValid(false);
}
if(std::abs(angVelocY) < this->absLimitY) {
if (std::abs(angVelocY) < this->absLimitY) {
dataset.angVelocY = angVelocY;
dataset.angVelocY.setValid(true);
}
else {
} else {
dataset.angVelocY.setValid(false);
}
if(std::abs(angVelocZ) < this->absLimitZ) {
if (std::abs(angVelocZ) < this->absLimitZ) {
dataset.angVelocZ = angVelocZ;
dataset.angVelocZ.setValid(true);
}
else {
} else {
dataset.angVelocZ.setValid(false);
}
@ -252,17 +244,14 @@ ReturnValue_t GyroHandlerL3GD20H::interpretDeviceReply(DeviceCommandId_t id,
return result;
}
uint32_t GyroHandlerL3GD20H::getTransitionDelayMs(Mode_t from, Mode_t to) {
return this->transitionDelayMs;
}
void GyroHandlerL3GD20H::setToGoToNormalMode(bool enable) {
this->goNormalModeImmediately = true;
}
void GyroHandlerL3GD20H::setToGoToNormalMode(bool enable) { this->goNormalModeImmediately = true; }
ReturnValue_t GyroHandlerL3GD20H::initializeLocalDataPool(
localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) {
ReturnValue_t GyroHandlerL3GD20H::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
LocalDataPoolManager &poolManager) {
localDataPoolMap.emplace(L3GD20H::ANG_VELOC_X, new PoolEntry<float>({0.0}));
localDataPoolMap.emplace(L3GD20H::ANG_VELOC_Y, new PoolEntry<float>({0.0}));
localDataPoolMap.emplace(L3GD20H::ANG_VELOC_Z, new PoolEntry<float>({0.0}));
@ -276,9 +265,7 @@ void GyroHandlerL3GD20H::fillCommandAndReplyMap() {
insertInCommandAndReplyMap(L3GD20H::READ_CTRL_REGS, 1);
}
void GyroHandlerL3GD20H::modeChanged() {
internalState = InternalState::NONE;
}
void GyroHandlerL3GD20H::modeChanged() { internalState = InternalState::NONE; }
void GyroHandlerL3GD20H::setAbsoluteLimits(float limitX, float limitY, float limitZ) {
this->absLimitX = limitX;

View File

@ -1,12 +1,12 @@
#ifndef MISSION_DEVICES_GYROL3GD20HANDLER_H_
#define MISSION_DEVICES_GYROL3GD20HANDLER_H_
#include "fsfw/FSFW.h"
#include "devicedefinitions/GyroL3GD20Definitions.h"
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
#include <fsfw/globalfunctions/PeriodicOperationDivider.h>
#include "devicedefinitions/GyroL3GD20Definitions.h"
#include "fsfw/FSFW.h"
/**
* @brief Device Handler for the L3GD20H gyroscope sensor
* (https://www.st.com/en/mems-and-sensors/l3gd20h.html)
@ -16,10 +16,10 @@
*
* Data is read big endian with the smallest possible range of 245 degrees per second.
*/
class GyroHandlerL3GD20H: public DeviceHandlerBase {
public:
GyroHandlerL3GD20H(object_id_t objectId, object_id_t deviceCommunication,
CookieIF* comCookie, uint32_t transitionDelayMs);
class GyroHandlerL3GD20H : public DeviceHandlerBase {
public:
GyroHandlerL3GD20H(object_id_t objectId, object_id_t deviceCommunication, CookieIF *comCookie,
uint32_t transitionDelayMs);
virtual ~GyroHandlerL3GD20H();
/**
@ -35,22 +35,18 @@ public:
* @brief Configure device handler to go to normal mode immediately
*/
void setToGoToNormalMode(bool enable);
protected:
protected:
/* DeviceHandlerBase overrides */
ReturnValue_t buildTransitionDeviceCommand(
DeviceCommandId_t *id) override;
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t *id) override;
void doStartUp() override;
void doShutDown() override;
ReturnValue_t buildNormalDeviceCommand(
DeviceCommandId_t *id) override;
ReturnValue_t buildCommandFromCommand(
DeviceCommandId_t deviceCommand, const uint8_t *commandData,
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id) override;
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t *commandData,
size_t commandDataLen) override;
ReturnValue_t scanForReply(const uint8_t *start, size_t len,
DeviceCommandId_t *foundId, size_t *foundLen) override;
virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id,
const uint8_t *packet) override;
ReturnValue_t scanForReply(const uint8_t *start, size_t len, DeviceCommandId_t *foundId,
size_t *foundLen) override;
virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) override;
void fillCommandAndReplyMap() override;
void modeChanged() override;
@ -58,7 +54,7 @@ protected:
ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
LocalDataPoolManager &poolManager) override;
private:
private:
uint32_t transitionDelayMs = 0;
GyroPrimaryDataset dataset;
@ -66,12 +62,7 @@ private:
float absLimitY = L3GD20H::RANGE_DPS_00;
float absLimitZ = L3GD20H::RANGE_DPS_00;
enum class InternalState {
NONE,
CONFIGURE,
CHECK_REGS,
NORMAL
};
enum class InternalState { NONE, CONFIGURE, CHECK_REGS, NORMAL };
InternalState internalState = InternalState::NONE;
bool commandExecuted = false;
@ -90,10 +81,8 @@ private:
float sensitivity = L3GD20H::SENSITIVITY_00;
#if FSFW_HAL_L3GD20_GYRO_DEBUG == 1
PeriodicOperationDivider* debugDivider = nullptr;
PeriodicOperationDivider *debugDivider = nullptr;
#endif
};
#endif /* MISSION_DEVICES_GYROL3GD20HANDLER_H_ */

View File

@ -8,9 +8,10 @@
#include <cmath>
MgmLIS3MDLHandler::MgmLIS3MDLHandler(object_id_t objectId, object_id_t deviceCommunication,
CookieIF* comCookie, uint32_t transitionDelay):
DeviceHandlerBase(objectId, deviceCommunication, comCookie),
dataset(this), transitionDelay(transitionDelay) {
CookieIF *comCookie, uint32_t transitionDelay)
: DeviceHandlerBase(objectId, deviceCommunication, comCookie),
dataset(this),
transitionDelay(transitionDelay) {
#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1
debugDivider = new PeriodicOperationDivider(3);
#endif
@ -20,39 +21,35 @@ MgmLIS3MDLHandler::MgmLIS3MDLHandler(object_id_t objectId, object_id_t deviceCom
registers[2] = MGMLIS3MDL::CTRL_REG3_DEFAULT;
registers[3] = MGMLIS3MDL::CTRL_REG4_DEFAULT;
registers[4] = MGMLIS3MDL::CTRL_REG5_DEFAULT;
}
MgmLIS3MDLHandler::~MgmLIS3MDLHandler() {
}
MgmLIS3MDLHandler::~MgmLIS3MDLHandler() {}
void MgmLIS3MDLHandler::doStartUp() {
switch (internalState) {
case(InternalState::STATE_NONE): {
case (InternalState::STATE_NONE): {
internalState = InternalState::STATE_FIRST_CONTACT;
break;
}
case(InternalState::STATE_FIRST_CONTACT): {
case (InternalState::STATE_FIRST_CONTACT): {
/* Will be set by checking device ID (WHO AM I register) */
if(commandExecuted) {
if (commandExecuted) {
commandExecuted = false;
internalState = InternalState::STATE_SETUP;
}
break;
}
case(InternalState::STATE_SETUP): {
case (InternalState::STATE_SETUP): {
internalState = InternalState::STATE_CHECK_REGISTERS;
break;
}
case(InternalState::STATE_CHECK_REGISTERS): {
case (InternalState::STATE_CHECK_REGISTERS): {
/* Set up cached registers which will be used to configure the MGM. */
if(commandExecuted) {
if (commandExecuted) {
commandExecuted = false;
if(goToNormalMode) {
if (goToNormalMode) {
setMode(MODE_NORMAL);
}
else {
} else {
setMode(_MODE_TO_ON);
}
}
@ -61,43 +58,38 @@ void MgmLIS3MDLHandler::doStartUp() {
default:
break;
}
}
void MgmLIS3MDLHandler::doShutDown() {
setMode(_MODE_POWER_DOWN);
}
void MgmLIS3MDLHandler::doShutDown() { setMode(_MODE_POWER_DOWN); }
ReturnValue_t MgmLIS3MDLHandler::buildTransitionDeviceCommand(
DeviceCommandId_t *id) {
ReturnValue_t MgmLIS3MDLHandler::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
switch (internalState) {
case(InternalState::STATE_NONE):
case(InternalState::STATE_NORMAL): {
case (InternalState::STATE_NONE):
case (InternalState::STATE_NORMAL): {
return DeviceHandlerBase::NOTHING_TO_SEND;
}
case(InternalState::STATE_FIRST_CONTACT): {
case (InternalState::STATE_FIRST_CONTACT): {
*id = MGMLIS3MDL::IDENTIFY_DEVICE;
break;
}
case(InternalState::STATE_SETUP): {
case (InternalState::STATE_SETUP): {
*id = MGMLIS3MDL::SETUP_MGM;
break;
}
case(InternalState::STATE_CHECK_REGISTERS): {
case (InternalState::STATE_CHECK_REGISTERS): {
*id = MGMLIS3MDL::READ_CONFIG_AND_DATA;
break;
}
default: {
/* might be a configuration error. */
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "GyroHandler::buildTransitionDeviceCommand: Unknown internal state!" <<
std::endl;
sif::warning << "GyroHandler::buildTransitionDeviceCommand: Unknown internal state!"
<< std::endl;
#else
sif::printWarning("GyroHandler::buildTransitionDeviceCommand: Unknown internal state!\n");
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
return HasReturnvaluesIF::RETURN_OK;
}
}
return buildCommandFromCommand(*id, NULL, 0);
}
@ -119,7 +111,6 @@ uint8_t MgmLIS3MDLHandler::writeCommand(uint8_t command, bool continuousCom) {
}
void MgmLIS3MDLHandler::setupMgm() {
registers[0] = MGMLIS3MDL::CTRL_REG1_DEFAULT;
registers[1] = MGMLIS3MDL::CTRL_REG2_DEFAULT;
registers[2] = MGMLIS3MDL::CTRL_REG3_DEFAULT;
@ -129,27 +120,24 @@ void MgmLIS3MDLHandler::setupMgm() {
prepareCtrlRegisterWrite();
}
ReturnValue_t MgmLIS3MDLHandler::buildNormalDeviceCommand(
DeviceCommandId_t *id) {
ReturnValue_t MgmLIS3MDLHandler::buildNormalDeviceCommand(DeviceCommandId_t *id) {
// Data/config register will be read in an alternating manner.
if(communicationStep == CommunicationStep::DATA) {
if (communicationStep == CommunicationStep::DATA) {
*id = MGMLIS3MDL::READ_CONFIG_AND_DATA;
communicationStep = CommunicationStep::TEMPERATURE;
return buildCommandFromCommand(*id, NULL, 0);
}
else {
} else {
*id = MGMLIS3MDL::READ_TEMPERATURE;
communicationStep = CommunicationStep::DATA;
return buildCommandFromCommand(*id, NULL, 0);
}
}
ReturnValue_t MgmLIS3MDLHandler::buildCommandFromCommand(
DeviceCommandId_t deviceCommand, const uint8_t *commandData,
ReturnValue_t MgmLIS3MDLHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
const uint8_t *commandData,
size_t commandDataLen) {
switch(deviceCommand) {
case(MGMLIS3MDL::READ_CONFIG_AND_DATA): {
switch (deviceCommand) {
case (MGMLIS3MDL::READ_CONFIG_AND_DATA): {
std::memset(commandBuffer, 0, sizeof(commandBuffer));
commandBuffer[0] = readCommand(MGMLIS3MDL::CTRL_REG1, true);
@ -157,7 +145,7 @@ ReturnValue_t MgmLIS3MDLHandler::buildCommandFromCommand(
rawPacketLen = MGMLIS3MDL::NR_OF_DATA_AND_CFG_REGISTERS + 1;
return RETURN_OK;
}
case(MGMLIS3MDL::READ_TEMPERATURE): {
case (MGMLIS3MDL::READ_TEMPERATURE): {
std::memset(commandBuffer, 0, 3);
commandBuffer[0] = readCommand(MGMLIS3MDL::TEMP_LOWBYTE, true);
@ -165,17 +153,17 @@ ReturnValue_t MgmLIS3MDLHandler::buildCommandFromCommand(
rawPacketLen = 3;
return RETURN_OK;
}
case(MGMLIS3MDL::IDENTIFY_DEVICE): {
case (MGMLIS3MDL::IDENTIFY_DEVICE): {
return identifyDevice();
}
case(MGMLIS3MDL::TEMP_SENSOR_ENABLE): {
case (MGMLIS3MDL::TEMP_SENSOR_ENABLE): {
return enableTemperatureSensor(commandData, commandDataLen);
}
case(MGMLIS3MDL::SETUP_MGM): {
case (MGMLIS3MDL::SETUP_MGM): {
setupMgm();
return HasReturnvaluesIF::RETURN_OK;
}
case(MGMLIS3MDL::ACCURACY_OP_MODE_SET): {
case (MGMLIS3MDL::ACCURACY_OP_MODE_SET): {
return setOperatingMode(commandData, commandDataLen);
}
default:
@ -195,16 +183,15 @@ ReturnValue_t MgmLIS3MDLHandler::identifyDevice() {
return RETURN_OK;
}
ReturnValue_t MgmLIS3MDLHandler::scanForReply(const uint8_t *start,
size_t len, DeviceCommandId_t *foundId, size_t *foundLen) {
ReturnValue_t MgmLIS3MDLHandler::scanForReply(const uint8_t *start, size_t len,
DeviceCommandId_t *foundId, size_t *foundLen) {
*foundLen = len;
if (len == MGMLIS3MDL::NR_OF_DATA_AND_CFG_REGISTERS + 1) {
*foundLen = len;
*foundId = MGMLIS3MDL::READ_CONFIG_AND_DATA;
// Check validity by checking config registers
if (start[1] != registers[0] or start[2] != registers[1] or
start[3] != registers[2] or start[4] != registers[3] or
start[5] != registers[4]) {
if (start[1] != registers[0] or start[2] != registers[1] or start[3] != registers[2] or
start[4] != registers[3] or start[5] != registers[4]) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "MGMHandlerLIS3MDL::scanForReply: Invalid registers!" << std::endl;
@ -214,57 +201,51 @@ ReturnValue_t MgmLIS3MDLHandler::scanForReply(const uint8_t *start,
#endif
return DeviceHandlerIF::INVALID_DATA;
}
if(mode == _MODE_START_UP) {
if (mode == _MODE_START_UP) {
commandExecuted = true;
}
}
else if(len == MGMLIS3MDL::TEMPERATURE_REPLY_LEN) {
} else if (len == MGMLIS3MDL::TEMPERATURE_REPLY_LEN) {
*foundLen = len;
*foundId = MGMLIS3MDL::READ_TEMPERATURE;
}
else if (len == MGMLIS3MDL::SETUP_REPLY_LEN) {
} else if (len == MGMLIS3MDL::SETUP_REPLY_LEN) {
*foundLen = len;
*foundId = MGMLIS3MDL::SETUP_MGM;
}
else if (len == SINGLE_COMMAND_ANSWER_LEN) {
} else if (len == SINGLE_COMMAND_ANSWER_LEN) {
*foundLen = len;
*foundId = getPendingCommand();
if(*foundId == MGMLIS3MDL::IDENTIFY_DEVICE) {
if(start[1] != MGMLIS3MDL::DEVICE_ID) {
if (*foundId == MGMLIS3MDL::IDENTIFY_DEVICE) {
if (start[1] != MGMLIS3MDL::DEVICE_ID) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "MGMHandlerLIS3MDL::scanForReply: "
"Device identification failed!" << std::endl;
"Device identification failed!"
<< std::endl;
#else
sif::printWarning("MGMHandlerLIS3MDL::scanForReply: "
sif::printWarning(
"MGMHandlerLIS3MDL::scanForReply: "
"Device identification failed!\n");
#endif
#endif
return DeviceHandlerIF::INVALID_DATA;
}
if(mode == _MODE_START_UP) {
if (mode == _MODE_START_UP) {
commandExecuted = true;
}
}
}
else {
} else {
return DeviceHandlerIF::INVALID_DATA;
}
/* Data with SPI Interface always has this answer */
if (start[0] == 0b11111111) {
return RETURN_OK;
}
else {
} else {
return DeviceHandlerIF::INVALID_DATA;
}
}
ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id,
const uint8_t *packet) {
ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) {
switch (id) {
case MGMLIS3MDL::IDENTIFY_DEVICE: {
break;
@ -276,26 +257,27 @@ ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id,
// TODO: Store configuration in new local datasets.
float sensitivityFactor = getSensitivityFactor(getSensitivity(registers[2]));
int16_t mgmMeasurementRawX = packet[MGMLIS3MDL::X_HIGHBYTE_IDX] << 8
| packet[MGMLIS3MDL::X_LOWBYTE_IDX] ;
int16_t mgmMeasurementRawY = packet[MGMLIS3MDL::Y_HIGHBYTE_IDX] << 8
| packet[MGMLIS3MDL::Y_LOWBYTE_IDX] ;
int16_t mgmMeasurementRawZ = packet[MGMLIS3MDL::Z_HIGHBYTE_IDX] << 8
| packet[MGMLIS3MDL::Z_LOWBYTE_IDX] ;
int16_t mgmMeasurementRawX =
packet[MGMLIS3MDL::X_HIGHBYTE_IDX] << 8 | packet[MGMLIS3MDL::X_LOWBYTE_IDX];
int16_t mgmMeasurementRawY =
packet[MGMLIS3MDL::Y_HIGHBYTE_IDX] << 8 | packet[MGMLIS3MDL::Y_LOWBYTE_IDX];
int16_t mgmMeasurementRawZ =
packet[MGMLIS3MDL::Z_HIGHBYTE_IDX] << 8 | packet[MGMLIS3MDL::Z_LOWBYTE_IDX];
/* Target value in microtesla */
float mgmX = static_cast<float>(mgmMeasurementRawX) * sensitivityFactor
* MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR;
float mgmY = static_cast<float>(mgmMeasurementRawY) * sensitivityFactor
* MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR;
float mgmZ = static_cast<float>(mgmMeasurementRawZ) * sensitivityFactor
* MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR;
float mgmX = static_cast<float>(mgmMeasurementRawX) * sensitivityFactor *
MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR;
float mgmY = static_cast<float>(mgmMeasurementRawY) * sensitivityFactor *
MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR;
float mgmZ = static_cast<float>(mgmMeasurementRawZ) * sensitivityFactor *
MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR;
#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1
if(debugDivider->checkAndIncrement()) {
if (debugDivider->checkAndIncrement()) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "MGMHandlerLIS3: Magnetic field strength in"
" microtesla:" << std::endl;
" microtesla:"
<< std::endl;
sif::info << "X: " << mgmX << " uT" << std::endl;
sif::info << "Y: " << mgmY << " uT" << std::endl;
sif::info << "Z: " << mgmZ << " uT" << std::endl;
@ -308,28 +290,25 @@ ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id,
}
#endif /* OBSW_VERBOSE_LEVEL >= 1 */
PoolReadGuard readHelper(&dataset);
if(readHelper.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
if(std::abs(mgmX) < absLimitX) {
if (readHelper.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
if (std::abs(mgmX) < absLimitX) {
dataset.fieldStrengthX = mgmX;
dataset.fieldStrengthX.setValid(true);
}
else {
} else {
dataset.fieldStrengthX.setValid(false);
}
if(std::abs(mgmY) < absLimitY) {
if (std::abs(mgmY) < absLimitY) {
dataset.fieldStrengthY = mgmY;
dataset.fieldStrengthY.setValid(true);
}
else {
} else {
dataset.fieldStrengthY.setValid(false);
}
if(std::abs(mgmZ) < absLimitZ) {
if (std::abs(mgmZ) < absLimitZ) {
dataset.fieldStrengthZ = mgmZ;
dataset.fieldStrengthZ.setValid(true);
}
else {
} else {
dataset.fieldStrengthZ.setValid(false);
}
}
@ -339,18 +318,17 @@ ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id,
case MGMLIS3MDL::READ_TEMPERATURE: {
int16_t tempValueRaw = packet[2] << 8 | packet[1];
float tempValue = 25.0 + ((static_cast<float>(tempValueRaw)) / 8.0);
#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1
if(debugDivider->check()) {
#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1
if (debugDivider->check()) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "MGMHandlerLIS3: Temperature: " << tempValue << " C" <<
std::endl;
sif::info << "MGMHandlerLIS3: Temperature: " << tempValue << " C" << std::endl;
#else
sif::printInfo("MGMHandlerLIS3: Temperature: %f C\n");
#endif
}
#endif
ReturnValue_t result = dataset.read();
if(result == HasReturnvaluesIF::RETURN_OK) {
if (result == HasReturnvaluesIF::RETURN_OK) {
dataset.temperature = tempValue;
dataset.commit();
}
@ -360,7 +338,6 @@ ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id,
default: {
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
}
}
return RETURN_OK;
}
@ -380,17 +357,17 @@ MGMLIS3MDL::Sensitivies MgmLIS3MDLHandler::getSensitivity(uint8_t ctrlRegister2)
}
float MgmLIS3MDLHandler::getSensitivityFactor(MGMLIS3MDL::Sensitivies sens) {
switch(sens) {
case(MGMLIS3MDL::GAUSS_4): {
switch (sens) {
case (MGMLIS3MDL::GAUSS_4): {
return MGMLIS3MDL::FIELD_LSB_PER_GAUSS_4_SENS;
}
case(MGMLIS3MDL::GAUSS_8): {
case (MGMLIS3MDL::GAUSS_8): {
return MGMLIS3MDL::FIELD_LSB_PER_GAUSS_8_SENS;
}
case(MGMLIS3MDL::GAUSS_12): {
case (MGMLIS3MDL::GAUSS_12): {
return MGMLIS3MDL::FIELD_LSB_PER_GAUSS_12_SENS;
}
case(MGMLIS3MDL::GAUSS_16): {
case (MGMLIS3MDL::GAUSS_16): {
return MGMLIS3MDL::FIELD_LSB_PER_GAUSS_16_SENS;
}
default: {
@ -400,9 +377,8 @@ float MgmLIS3MDLHandler::getSensitivityFactor(MGMLIS3MDL::Sensitivies sens) {
}
}
ReturnValue_t MgmLIS3MDLHandler::enableTemperatureSensor(
const uint8_t *commandData, size_t commandDataLen) {
ReturnValue_t MgmLIS3MDLHandler::enableTemperatureSensor(const uint8_t *commandData,
size_t commandDataLen) {
triggerEvent(CHANGE_OF_SETUP_PARAMETER);
uint32_t size = 2;
commandBuffer[0] = writeCommand(MGMLIS3MDL::CTRL_REG1);
@ -471,9 +447,7 @@ void MgmLIS3MDLHandler::fillCommandAndReplyMap() {
insertInCommandAndReplyMap(MGMLIS3MDL::ACCURACY_OP_MODE_SET, 1);
}
void MgmLIS3MDLHandler::setToGoToNormalMode(bool enable) {
this->goToNormalMode = enable;
}
void MgmLIS3MDLHandler::setToGoToNormalMode(bool enable) { this->goToNormalMode = enable; }
ReturnValue_t MgmLIS3MDLHandler::prepareCtrlRegisterWrite() {
commandBuffer[0] = writeCommand(MGMLIS3MDL::CTRL_REG1, true);
@ -488,28 +462,18 @@ ReturnValue_t MgmLIS3MDLHandler::prepareCtrlRegisterWrite() {
return RETURN_OK;
}
void MgmLIS3MDLHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) {
void MgmLIS3MDLHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) {}
}
uint32_t MgmLIS3MDLHandler::getTransitionDelayMs(Mode_t from, Mode_t to) { return transitionDelay; }
uint32_t MgmLIS3MDLHandler::getTransitionDelayMs(Mode_t from, Mode_t to) {
return transitionDelay;
}
void MgmLIS3MDLHandler::modeChanged(void) { internalState = InternalState::STATE_NONE; }
void MgmLIS3MDLHandler::modeChanged(void) {
internalState = InternalState::STATE_NONE;
}
ReturnValue_t MgmLIS3MDLHandler::initializeLocalDataPool(
localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) {
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_X,
new PoolEntry<float>({0.0}));
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Y,
new PoolEntry<float>({0.0}));
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Z,
new PoolEntry<float>({0.0}));
localDataPoolMap.emplace(MGMLIS3MDL::TEMPERATURE_CELCIUS,
new PoolEntry<float>({0.0}));
ReturnValue_t MgmLIS3MDLHandler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
LocalDataPoolManager &poolManager) {
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_X, new PoolEntry<float>({0.0}));
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Y, new PoolEntry<float>({0.0}));
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Z, new PoolEntry<float>({0.0}));
localDataPoolMap.emplace(MGMLIS3MDL::TEMPERATURE_CELCIUS, new PoolEntry<float>({0.0}));
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -1,10 +1,9 @@
#ifndef MISSION_DEVICES_MGMLIS3MDLHANDLER_H_
#define MISSION_DEVICES_MGMLIS3MDLHANDLER_H_
#include "fsfw/FSFW.h"
#include "events/subsystemIdRanges.h"
#include "devicedefinitions/MgmLIS3HandlerDefs.h"
#include "events/subsystemIdRanges.h"
#include "fsfw/FSFW.h"
#include "fsfw/devicehandlers/DeviceHandlerBase.h"
class PeriodicOperationDivider;
@ -18,19 +17,16 @@ class PeriodicOperationDivider;
* https://egit.irs.uni-stuttgart.de/redmine/projects/eive-flight-manual/wiki/LIS3MDL_MGM
* @author L. Loidold, R. Mueller
*/
class MgmLIS3MDLHandler: public DeviceHandlerBase {
public:
enum class CommunicationStep {
DATA,
TEMPERATURE
};
class MgmLIS3MDLHandler : public DeviceHandlerBase {
public:
enum class CommunicationStep { DATA, TEMPERATURE };
static const uint8_t INTERFACE_ID = CLASS_ID::MGM_LIS3MDL;
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::MGM_LIS3MDL;
//Notifies a command to change the setup parameters
// Notifies a command to change the setup parameters
static const Event CHANGE_OF_SETUP_PARAMETER = MAKE_EVENT(0, severity::LOW);
MgmLIS3MDLHandler(uint32_t objectId, object_id_t deviceCommunication, CookieIF* comCookie,
MgmLIS3MDLHandler(uint32_t objectId, object_id_t deviceCommunication, CookieIF *comCookie,
uint32_t transitionDelay);
virtual ~MgmLIS3MDLHandler();
@ -44,22 +40,18 @@ public:
void setAbsoluteLimits(float xLimit, float yLimit, float zLimit);
void setToGoToNormalMode(bool enable);
protected:
protected:
/** DeviceHandlerBase overrides */
void doShutDown() override;
void doStartUp() override;
void doTransition(Mode_t modeFrom, Submode_t subModeFrom) override;
virtual uint32_t getTransitionDelayMs(Mode_t from, Mode_t to) override;
ReturnValue_t buildCommandFromCommand(
DeviceCommandId_t deviceCommand, const uint8_t *commandData,
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t *commandData,
size_t commandDataLen) override;
ReturnValue_t buildTransitionDeviceCommand(
DeviceCommandId_t *id) override;
ReturnValue_t buildNormalDeviceCommand(
DeviceCommandId_t *id) override;
ReturnValue_t scanForReply(const uint8_t *start, size_t len,
DeviceCommandId_t *foundId, size_t *foundLen) override;
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t *id) override;
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id) override;
ReturnValue_t scanForReply(const uint8_t *start, size_t len, DeviceCommandId_t *foundId,
size_t *foundLen) override;
/**
* This implementation is tailored towards space applications and will flag values larger
* than 100 microtesla on X,Y and 150 microtesla on Z as invalid
@ -67,16 +59,15 @@ protected:
* @param packet
* @return
*/
virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id,
const uint8_t *packet) override;
virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) override;
void fillCommandAndReplyMap() override;
void modeChanged(void) override;
ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
LocalDataPoolManager &poolManager) override;
private:
private:
MGMLIS3MDL::MgmPrimaryDataset dataset;
//Length a single command SPI answer
// Length a single command SPI answer
static const uint8_t SINGLE_COMMAND_ANSWER_LEN = 2;
uint32_t transitionDelay;
@ -159,16 +150,14 @@ private:
* @param commandData On or Off
* @param length of the commandData: has to be 1
*/
virtual ReturnValue_t enableTemperatureSensor(const uint8_t *commandData,
size_t commandDataLen);
virtual ReturnValue_t enableTemperatureSensor(const uint8_t *commandData, size_t commandDataLen);
/**
* Sets the accuracy of the measurement of the axis. The noise is changing.
* @param commandData LOW, MEDIUM, HIGH, ULTRA
* @param length of the command, has to be 1
*/
virtual ReturnValue_t setOperatingMode(const uint8_t *commandData,
size_t commandDataLen);
virtual ReturnValue_t setOperatingMode(const uint8_t *commandData, size_t commandDataLen);
/**
* We always update all registers together, so this method updates
@ -179,7 +168,7 @@ private:
ReturnValue_t prepareCtrlRegisterWrite();
#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1
PeriodicOperationDivider* debugDivider;
PeriodicOperationDivider *debugDivider;
#endif
};

View File

@ -1,16 +1,16 @@
#include "MgmRM3100Handler.h"
#include "fsfw/datapool/PoolReadGuard.h"
#include "fsfw/globalfunctions/bitutility.h"
#include "fsfw/devicehandlers/DeviceHandlerMessage.h"
#include "fsfw/globalfunctions/bitutility.h"
#include "fsfw/objectmanager/SystemObjectIF.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
MgmRM3100Handler::MgmRM3100Handler(object_id_t objectId,
object_id_t deviceCommunication, CookieIF* comCookie, uint32_t transitionDelay):
DeviceHandlerBase(objectId, deviceCommunication, comCookie),
primaryDataset(this), transitionDelay(transitionDelay) {
MgmRM3100Handler::MgmRM3100Handler(object_id_t objectId, object_id_t deviceCommunication,
CookieIF *comCookie, uint32_t transitionDelay)
: DeviceHandlerBase(objectId, deviceCommunication, comCookie),
primaryDataset(this),
transitionDelay(transitionDelay) {
#if FSFW_HAL_RM3100_MGM_DEBUG == 1
debugDivider = new PeriodicOperationDivider(3);
#endif
@ -19,34 +19,33 @@ MgmRM3100Handler::MgmRM3100Handler(object_id_t objectId,
MgmRM3100Handler::~MgmRM3100Handler() {}
void MgmRM3100Handler::doStartUp() {
switch(internalState) {
case(InternalState::NONE): {
switch (internalState) {
case (InternalState::NONE): {
internalState = InternalState::CONFIGURE_CMM;
break;
}
case(InternalState::CONFIGURE_CMM): {
case (InternalState::CONFIGURE_CMM): {
internalState = InternalState::READ_CMM;
break;
}
case(InternalState::READ_CMM): {
if(commandExecuted) {
case (InternalState::READ_CMM): {
if (commandExecuted) {
internalState = InternalState::STATE_CONFIGURE_TMRC;
}
break;
}
case(InternalState::STATE_CONFIGURE_TMRC): {
if(commandExecuted) {
case (InternalState::STATE_CONFIGURE_TMRC): {
if (commandExecuted) {
internalState = InternalState::STATE_READ_TMRC;
}
break;
}
case(InternalState::STATE_READ_TMRC): {
if(commandExecuted) {
case (InternalState::STATE_READ_TMRC): {
if (commandExecuted) {
internalState = InternalState::NORMAL;
if(goToNormalModeAtStartup) {
if (goToNormalModeAtStartup) {
setMode(MODE_NORMAL);
}
else {
} else {
setMode(_MODE_TO_ON);
}
}
@ -58,33 +57,30 @@ void MgmRM3100Handler::doStartUp() {
}
}
void MgmRM3100Handler::doShutDown() {
setMode(_MODE_POWER_DOWN);
}
void MgmRM3100Handler::doShutDown() { setMode(_MODE_POWER_DOWN); }
ReturnValue_t MgmRM3100Handler::buildTransitionDeviceCommand(
DeviceCommandId_t *id) {
ReturnValue_t MgmRM3100Handler::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
size_t commandLen = 0;
switch(internalState) {
case(InternalState::NONE):
case(InternalState::NORMAL): {
switch (internalState) {
case (InternalState::NONE):
case (InternalState::NORMAL): {
return NOTHING_TO_SEND;
}
case(InternalState::CONFIGURE_CMM): {
case (InternalState::CONFIGURE_CMM): {
*id = RM3100::CONFIGURE_CMM;
break;
}
case(InternalState::READ_CMM): {
case (InternalState::READ_CMM): {
*id = RM3100::READ_CMM;
break;
}
case(InternalState::STATE_CONFIGURE_TMRC): {
case (InternalState::STATE_CONFIGURE_TMRC): {
commandBuffer[0] = RM3100::TMRC_DEFAULT_VALUE;
commandLen = 1;
*id = RM3100::CONFIGURE_TMRC;
break;
}
case(InternalState::STATE_READ_TMRC): {
case (InternalState::STATE_READ_TMRC): {
*id = RM3100::READ_TMRC;
break;
}
@ -93,9 +89,11 @@ ReturnValue_t MgmRM3100Handler::buildTransitionDeviceCommand(
#if FSFW_CPP_OSTREAM_ENABLED == 1
// Might be a configuration error
sif::warning << "MgmRM3100Handler::buildTransitionDeviceCommand: "
"Unknown internal state" << std::endl;
"Unknown internal state"
<< std::endl;
#else
sif::printWarning("MgmRM3100Handler::buildTransitionDeviceCommand: "
sif::printWarning(
"MgmRM3100Handler::buildTransitionDeviceCommand: "
"Unknown internal state\n");
#endif
#endif
@ -106,43 +104,44 @@ ReturnValue_t MgmRM3100Handler::buildTransitionDeviceCommand(
}
ReturnValue_t MgmRM3100Handler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
const uint8_t *commandData, size_t commandDataLen) {
switch(deviceCommand) {
case(RM3100::CONFIGURE_CMM): {
const uint8_t *commandData,
size_t commandDataLen) {
switch (deviceCommand) {
case (RM3100::CONFIGURE_CMM): {
commandBuffer[0] = RM3100::CMM_REGISTER;
commandBuffer[1] = RM3100::CMM_VALUE;
rawPacket = commandBuffer;
rawPacketLen = 2;
break;
}
case(RM3100::READ_CMM): {
case (RM3100::READ_CMM): {
commandBuffer[0] = RM3100::CMM_REGISTER | RM3100::READ_MASK;
commandBuffer[1] = 0;
rawPacket = commandBuffer;
rawPacketLen = 2;
break;
}
case(RM3100::CONFIGURE_TMRC): {
case (RM3100::CONFIGURE_TMRC): {
return handleTmrcConfigCommand(deviceCommand, commandData, commandDataLen);
}
case(RM3100::READ_TMRC): {
case (RM3100::READ_TMRC): {
commandBuffer[0] = RM3100::TMRC_REGISTER | RM3100::READ_MASK;
commandBuffer[1] = 0;
rawPacket = commandBuffer;
rawPacketLen = 2;
break;
}
case(RM3100::CONFIGURE_CYCLE_COUNT): {
case (RM3100::CONFIGURE_CYCLE_COUNT): {
return handleCycleCountConfigCommand(deviceCommand, commandData, commandDataLen);
}
case(RM3100::READ_CYCLE_COUNT): {
case (RM3100::READ_CYCLE_COUNT): {
commandBuffer[0] = RM3100::CYCLE_COUNT_START_REGISTER | RM3100::READ_MASK;
std::memset(commandBuffer + 1, 0, 6);
rawPacket = commandBuffer;
rawPacketLen = 7;
break;
}
case(RM3100::READ_DATA): {
case (RM3100::READ_DATA): {
commandBuffer[0] = RM3100::MEASUREMENT_REG_START | RM3100::READ_MASK;
std::memset(commandBuffer + 1, 0, 9);
rawPacketLen = 10;
@ -154,16 +153,13 @@ ReturnValue_t MgmRM3100Handler::buildCommandFromCommand(DeviceCommandId_t device
return RETURN_OK;
}
ReturnValue_t MgmRM3100Handler::buildNormalDeviceCommand(
DeviceCommandId_t *id) {
ReturnValue_t MgmRM3100Handler::buildNormalDeviceCommand(DeviceCommandId_t *id) {
*id = RM3100::READ_DATA;
return buildCommandFromCommand(*id, nullptr, 0);
}
ReturnValue_t MgmRM3100Handler::scanForReply(const uint8_t *start,
size_t len, DeviceCommandId_t *foundId,
size_t *foundLen) {
ReturnValue_t MgmRM3100Handler::scanForReply(const uint8_t *start, size_t len,
DeviceCommandId_t *foundId, size_t *foundLen) {
// For SPI, ID will always be the one of the last sent command
*foundId = this->getPendingCommand();
*foundLen = len;
@ -172,62 +168,60 @@ ReturnValue_t MgmRM3100Handler::scanForReply(const uint8_t *start,
ReturnValue_t MgmRM3100Handler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) {
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
switch(id) {
case(RM3100::CONFIGURE_CMM):
case(RM3100::CONFIGURE_CYCLE_COUNT):
case(RM3100::CONFIGURE_TMRC): {
switch (id) {
case (RM3100::CONFIGURE_CMM):
case (RM3100::CONFIGURE_CYCLE_COUNT):
case (RM3100::CONFIGURE_TMRC): {
// We can only check whether write was successful with read operation
if(mode == _MODE_START_UP) {
if (mode == _MODE_START_UP) {
commandExecuted = true;
}
break;
}
case(RM3100::READ_CMM): {
case (RM3100::READ_CMM): {
uint8_t cmmValue = packet[1];
// We clear the seventh bit in any case
// because this one is zero sometimes for some reason
bitutil::clear(&cmmValue, 6);
if(cmmValue == cmmRegValue and internalState == InternalState::READ_CMM) {
if (cmmValue == cmmRegValue and internalState == InternalState::READ_CMM) {
commandExecuted = true;
}
else {
} else {
// Attempt reconfiguration
internalState = InternalState::CONFIGURE_CMM;
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
}
break;
}
case(RM3100::READ_TMRC): {
if(packet[1] == tmrcRegValue) {
case (RM3100::READ_TMRC): {
if (packet[1] == tmrcRegValue) {
commandExecuted = true;
// Reading TMRC was commanded. Trigger event to inform ground
if(mode != _MODE_START_UP) {
if (mode != _MODE_START_UP) {
triggerEvent(tmrcSet, tmrcRegValue, 0);
}
}
else {
} else {
// Attempt reconfiguration
internalState = InternalState::STATE_CONFIGURE_TMRC;
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
}
break;
}
case(RM3100::READ_CYCLE_COUNT): {
case (RM3100::READ_CYCLE_COUNT): {
uint16_t cycleCountX = packet[1] << 8 | packet[2];
uint16_t cycleCountY = packet[3] << 8 | packet[4];
uint16_t cycleCountZ = packet[5] << 8 | packet[6];
if(cycleCountX != cycleCountRegValueX or cycleCountY != cycleCountRegValueY or
if (cycleCountX != cycleCountRegValueX or cycleCountY != cycleCountRegValueY or
cycleCountZ != cycleCountRegValueZ) {
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
}
// Reading TMRC was commanded. Trigger event to inform ground
if(mode != _MODE_START_UP) {
if (mode != _MODE_START_UP) {
uint32_t eventParam1 = (cycleCountX << 16) | cycleCountY;
triggerEvent(cycleCountersSet, eventParam1, cycleCountZ);
}
break;
}
case(RM3100::READ_DATA): {
case (RM3100::READ_DATA): {
result = handleDataReadout(packet);
break;
}
@ -239,19 +233,18 @@ ReturnValue_t MgmRM3100Handler::interpretDeviceReply(DeviceCommandId_t id, const
}
ReturnValue_t MgmRM3100Handler::handleCycleCountConfigCommand(DeviceCommandId_t deviceCommand,
const uint8_t *commandData, size_t commandDataLen) {
if(commandData == nullptr) {
const uint8_t *commandData,
size_t commandDataLen) {
if (commandData == nullptr) {
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
}
// Set cycle count
if(commandDataLen == 2) {
if (commandDataLen == 2) {
handleCycleCommand(true, commandData, commandDataLen);
}
else if(commandDataLen == 6) {
} else if (commandDataLen == 6) {
handleCycleCommand(false, commandData, commandDataLen);
}
else {
} else {
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
}
@ -264,21 +257,21 @@ ReturnValue_t MgmRM3100Handler::handleCycleCountConfigCommand(DeviceCommandId_t
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t MgmRM3100Handler::handleCycleCommand(bool oneCycleValue,
const uint8_t *commandData, size_t commandDataLen) {
ReturnValue_t MgmRM3100Handler::handleCycleCommand(bool oneCycleValue, const uint8_t *commandData,
size_t commandDataLen) {
RM3100::CycleCountCommand command(oneCycleValue);
ReturnValue_t result = command.deSerialize(&commandData, &commandDataLen,
SerializeIF::Endianness::BIG);
if(result != HasReturnvaluesIF::RETURN_OK) {
ReturnValue_t result =
command.deSerialize(&commandData, &commandDataLen, SerializeIF::Endianness::BIG);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
// Data sheet p.30 "while noise limits the useful upper range to ~400 cycle counts."
if(command.cycleCountX > 450 ) {
if (command.cycleCountX > 450) {
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
}
if(not oneCycleValue and (command.cycleCountY > 450 or command.cycleCountZ > 450)) {
if (not oneCycleValue and (command.cycleCountY > 450 or command.cycleCountZ > 450)) {
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
}
@ -289,8 +282,9 @@ ReturnValue_t MgmRM3100Handler::handleCycleCommand(bool oneCycleValue,
}
ReturnValue_t MgmRM3100Handler::handleTmrcConfigCommand(DeviceCommandId_t deviceCommand,
const uint8_t *commandData, size_t commandDataLen) {
if(commandData == nullptr or commandDataLen != 1) {
const uint8_t *commandData,
size_t commandDataLen) {
if (commandData == nullptr or commandDataLen != 1) {
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
}
@ -315,12 +309,10 @@ void MgmRM3100Handler::fillCommandAndReplyMap() {
insertInCommandAndReplyMap(RM3100::READ_DATA, 3, &primaryDataset);
}
void MgmRM3100Handler::modeChanged(void) {
internalState = InternalState::NONE;
}
void MgmRM3100Handler::modeChanged(void) { internalState = InternalState::NONE; }
ReturnValue_t MgmRM3100Handler::initializeLocalDataPool(
localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) {
ReturnValue_t MgmRM3100Handler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
LocalDataPoolManager &poolManager) {
localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_X, new PoolEntry<float>({0.0}));
localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_Y, new PoolEntry<float>({0.0}));
localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_Z, new PoolEntry<float>({0.0}));
@ -331,9 +323,7 @@ uint32_t MgmRM3100Handler::getTransitionDelayMs(Mode_t from, Mode_t to) {
return this->transitionDelay;
}
void MgmRM3100Handler::setToGoToNormalMode(bool enable) {
goToNormalModeAtStartup = enable;
}
void MgmRM3100Handler::setToGoToNormalMode(bool enable) { goToNormalModeAtStartup = enable; }
ReturnValue_t MgmRM3100Handler::handleDataReadout(const uint8_t *packet) {
// Analyze data here. The sensor generates 24 bit signed values so we need to do some bitshift
@ -348,10 +338,11 @@ ReturnValue_t MgmRM3100Handler::handleDataReadout(const uint8_t *packet) {
float fieldStrengthZ = fieldStrengthRawZ * scaleFactorX;
#if FSFW_HAL_RM3100_MGM_DEBUG == 1
if(debugDivider->checkAndIncrement()) {
if (debugDivider->checkAndIncrement()) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "MgmRM3100Handler: Magnetic field strength in"
" microtesla:" << std::endl;
" microtesla:"
<< std::endl;
sif::info << "X: " << fieldStrengthX << " uT" << std::endl;
sif::info << "Y: " << fieldStrengthY << " uT" << std::endl;
sif::info << "Z: " << fieldStrengthZ << " uT" << std::endl;
@ -366,7 +357,7 @@ ReturnValue_t MgmRM3100Handler::handleDataReadout(const uint8_t *packet) {
// TODO: Sanity check on values?
PoolReadGuard readGuard(&primaryDataset);
if(readGuard.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
if (readGuard.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
primaryDataset.fieldStrengthX = fieldStrengthX;
primaryDataset.fieldStrengthY = fieldStrengthY;
primaryDataset.fieldStrengthZ = fieldStrengthZ;

View File

@ -1,8 +1,8 @@
#ifndef MISSION_DEVICES_MGMRM3100HANDLER_H_
#define MISSION_DEVICES_MGMRM3100HANDLER_H_
#include "fsfw/FSFW.h"
#include "devicedefinitions/MgmRM3100HandlerDefs.h"
#include "fsfw/FSFW.h"
#include "fsfw/devicehandlers/DeviceHandlerBase.h"
#if FSFW_HAL_RM3100_MGM_DEBUG == 1
@ -16,22 +16,21 @@
* Flight manual:
* https://egit.irs.uni-stuttgart.de/redmine/projects/eive-flight-manual/wiki/RM3100_MGM
*/
class MgmRM3100Handler: public DeviceHandlerBase {
public:
class MgmRM3100Handler : public DeviceHandlerBase {
public:
static const uint8_t INTERFACE_ID = CLASS_ID::MGM_RM3100;
//! [EXPORT] : [COMMENT] P1: TMRC value which was set, P2: 0
static constexpr Event tmrcSet = event::makeEvent(SUBSYSTEM_ID::MGM_RM3100,
0x00, severity::INFO);
static constexpr Event tmrcSet = event::makeEvent(SUBSYSTEM_ID::MGM_RM3100, 0x00, severity::INFO);
//! [EXPORT] : [COMMENT] Cycle counter set. P1: First two bytes new Cycle Count X
//! P1: Second two bytes new Cycle Count Y
//! P2: New cycle count Z
static constexpr Event cycleCountersSet = event::makeEvent(
SUBSYSTEM_ID::MGM_RM3100, 0x01, severity::INFO);
static constexpr Event cycleCountersSet =
event::makeEvent(SUBSYSTEM_ID::MGM_RM3100, 0x01, severity::INFO);
MgmRM3100Handler(object_id_t objectId, object_id_t deviceCommunication,
CookieIF* comCookie, uint32_t transitionDelay);
MgmRM3100Handler(object_id_t objectId, object_id_t deviceCommunication, CookieIF *comCookie,
uint32_t transitionDelay);
virtual ~MgmRM3100Handler();
/**
@ -40,18 +39,16 @@ public:
*/
void setToGoToNormalMode(bool enable);
protected:
protected:
/* DeviceHandlerBase overrides */
ReturnValue_t buildTransitionDeviceCommand(
DeviceCommandId_t *id) override;
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t *id) override;
void doStartUp() override;
void doShutDown() override;
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id) override;
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand,
const uint8_t *commandData, size_t commandDataLen) override;
ReturnValue_t scanForReply(const uint8_t *start, size_t len,
DeviceCommandId_t *foundId, size_t *foundLen) override;
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t *commandData,
size_t commandDataLen) override;
ReturnValue_t scanForReply(const uint8_t *start, size_t len, DeviceCommandId_t *foundId,
size_t *foundLen) override;
ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) override;
void fillCommandAndReplyMap() override;
@ -60,8 +57,7 @@ protected:
ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
LocalDataPoolManager &poolManager) override;
private:
private:
enum class InternalState {
NONE,
CONFIGURE_CMM,
@ -94,16 +90,16 @@ private:
uint32_t transitionDelay;
ReturnValue_t handleCycleCountConfigCommand(DeviceCommandId_t deviceCommand,
const uint8_t *commandData,size_t commandDataLen);
ReturnValue_t handleCycleCommand(bool oneCycleValue,
const uint8_t *commandData, size_t commandDataLen);
ReturnValue_t handleCycleCommand(bool oneCycleValue, const uint8_t *commandData,
size_t commandDataLen);
ReturnValue_t handleTmrcConfigCommand(DeviceCommandId_t deviceCommand,
const uint8_t *commandData,size_t commandDataLen);
ReturnValue_t handleTmrcConfigCommand(DeviceCommandId_t deviceCommand, const uint8_t *commandData,
size_t commandDataLen);
ReturnValue_t handleDataReadout(const uint8_t* packet);
ReturnValue_t handleDataReadout(const uint8_t *packet);
#if FSFW_HAL_RM3100_MGM_DEBUG == 1
PeriodicOperationDivider* debugDivider;
PeriodicOperationDivider *debugDivider;
#endif
};

View File

@ -3,6 +3,7 @@
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
#include <cstdint>
namespace L3GD20H {
@ -36,8 +37,8 @@ static constexpr uint8_t SET_Z_ENABLE = 1 << 2;
static constexpr uint8_t SET_X_ENABLE = 1 << 1;
static constexpr uint8_t SET_Y_ENABLE = 1;
static constexpr uint8_t CTRL_REG_1_VAL = SET_POWER_NORMAL_MODE | SET_Z_ENABLE |
SET_Y_ENABLE | SET_X_ENABLE;
static constexpr uint8_t CTRL_REG_1_VAL =
SET_POWER_NORMAL_MODE | SET_Z_ENABLE | SET_Y_ENABLE | SET_X_ENABLE;
/* Register 2 */
static constexpr uint8_t EXTERNAL_EDGE_ENB = 1 << 7;
@ -104,40 +105,29 @@ static constexpr DeviceCommandId_t READ_CTRL_REGS = 2;
static constexpr uint32_t GYRO_DATASET_ID = READ_REGS;
enum GyroPoolIds: lp_id_t {
ANG_VELOC_X,
ANG_VELOC_Y,
ANG_VELOC_Z,
TEMPERATURE
};
enum GyroPoolIds : lp_id_t { ANG_VELOC_X, ANG_VELOC_Y, ANG_VELOC_Z, TEMPERATURE };
}
class GyroPrimaryDataset: public StaticLocalDataSet<5> {
public:
} // namespace L3GD20H
class GyroPrimaryDataset : public StaticLocalDataSet<5> {
public:
/** Constructor for data users like controllers */
GyroPrimaryDataset(object_id_t mgmId):
StaticLocalDataSet(sid_t(mgmId, L3GD20H::GYRO_DATASET_ID)) {
GyroPrimaryDataset(object_id_t mgmId)
: StaticLocalDataSet(sid_t(mgmId, L3GD20H::GYRO_DATASET_ID)) {
setAllVariablesReadOnly();
}
/* Angular velocities in degrees per second (DPS) */
lp_var_t<float> angVelocX = lp_var_t<float>(sid.objectId,
L3GD20H::ANG_VELOC_X, this);
lp_var_t<float> angVelocY = lp_var_t<float>(sid.objectId,
L3GD20H::ANG_VELOC_Y, this);
lp_var_t<float> angVelocZ = lp_var_t<float>(sid.objectId,
L3GD20H::ANG_VELOC_Z, this);
lp_var_t<float> temperature = lp_var_t<float>(sid.objectId,
L3GD20H::TEMPERATURE, this);
private:
lp_var_t<float> angVelocX = lp_var_t<float>(sid.objectId, L3GD20H::ANG_VELOC_X, this);
lp_var_t<float> angVelocY = lp_var_t<float>(sid.objectId, L3GD20H::ANG_VELOC_Y, this);
lp_var_t<float> angVelocZ = lp_var_t<float>(sid.objectId, L3GD20H::ANG_VELOC_Z, this);
lp_var_t<float> temperature = lp_var_t<float>(sid.objectId, L3GD20H::TEMPERATURE, this);
private:
friend class GyroHandlerL3GD20H;
/** Constructor for the data creator */
GyroPrimaryDataset(HasLocalDataPoolIF* hkOwner):
StaticLocalDataSet(hkOwner, L3GD20H::GYRO_DATASET_ID) {}
GyroPrimaryDataset(HasLocalDataPoolIF* hkOwner)
: StaticLocalDataSet(hkOwner, L3GD20H::GYRO_DATASET_ID) {}
};
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_GYROL3GD20DEFINITIONS_H_ */

View File

@ -1,26 +1,18 @@
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_MGMLIS3HANDLERDEFS_H_
#define MISSION_DEVICES_DEVICEDEFINITIONS_MGMLIS3HANDLERDEFS_H_
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
#include <fsfw/datapoollocal/LocalPoolVariable.h>
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
#include <cstdint>
namespace MGMLIS3MDL {
enum Set {
ON, OFF
};
enum OpMode {
LOW, MEDIUM, HIGH, ULTRA
};
enum Set { ON, OFF };
enum OpMode { LOW, MEDIUM, HIGH, ULTRA };
enum Sensitivies: uint8_t {
GAUSS_4 = 4,
GAUSS_8 = 8,
GAUSS_12 = 12,
GAUSS_16 = 16
};
enum Sensitivies : uint8_t { GAUSS_4 = 4, GAUSS_8 = 8, GAUSS_12 = 12, GAUSS_16 = 16 };
/* Actually 15, we just round up a bit */
static constexpr size_t MAX_BUFFER_SIZE = 16;
@ -114,65 +106,58 @@ static const uint8_t DO2 = 4; // Output data rate bit 4
static const uint8_t OM0 = 5; // XY operating mode bit 5
static const uint8_t OM1 = 6; // XY operating mode bit 6
static const uint8_t TEMP_EN = 7; // Temperature sensor enable enabled = 1
static const uint8_t CTRL_REG1_DEFAULT = (1 << TEMP_EN) | (1 << OM1) |
(1 << DO0) | (1 << DO1) | (1 << DO2);
static const uint8_t CTRL_REG1_DEFAULT =
(1 << TEMP_EN) | (1 << OM1) | (1 << DO0) | (1 << DO1) | (1 << DO2);
/* CTRL_REG2 bits */
//reset configuration registers and user registers
// reset configuration registers and user registers
static const uint8_t SOFT_RST = 2;
static const uint8_t REBOOT = 3; //reboot memory content
static const uint8_t FSO = 5; //full-scale selection bit 5
static const uint8_t FS1 = 6; //full-scale selection bit 6
static const uint8_t REBOOT = 3; // reboot memory content
static const uint8_t FSO = 5; // full-scale selection bit 5
static const uint8_t FS1 = 6; // full-scale selection bit 6
static const uint8_t CTRL_REG2_DEFAULT = 0;
/* CTRL_REG3 bits */
static const uint8_t MD0 = 0; //Operating mode bit 0
static const uint8_t MD1 = 1; //Operating mode bit 1
//SPI serial interface mode selection enabled = 3-wire-mode
static const uint8_t MD0 = 0; // Operating mode bit 0
static const uint8_t MD1 = 1; // Operating mode bit 1
// SPI serial interface mode selection enabled = 3-wire-mode
static const uint8_t SIM = 2;
static const uint8_t LP = 5; //low-power mode
static const uint8_t LP = 5; // low-power mode
static const uint8_t CTRL_REG3_DEFAULT = 0;
/* CTRL_REG4 bits */
//big/little endian data selection enabled = MSb at lower adress
// big/little endian data selection enabled = MSb at lower adress
static const uint8_t BLE = 1;
static const uint8_t OMZ0 = 2; //Z operating mode bit 2
static const uint8_t OMZ1 = 3; //Z operating mode bit 3
static const uint8_t OMZ0 = 2; // Z operating mode bit 2
static const uint8_t OMZ1 = 3; // Z operating mode bit 3
static const uint8_t CTRL_REG4_DEFAULT = (1 << OMZ1);
/* CTRL_REG5 bits */
static const uint8_t BDU = 6; //Block data update
static const uint8_t FAST_READ = 7; //Fast read enabled = 1
static const uint8_t BDU = 6; // Block data update
static const uint8_t FAST_READ = 7; // Fast read enabled = 1
static const uint8_t CTRL_REG5_DEFAULT = 0;
static const uint32_t MGM_DATA_SET_ID = READ_CONFIG_AND_DATA;
enum MgmPoolIds: lp_id_t {
enum MgmPoolIds : lp_id_t {
FIELD_STRENGTH_X,
FIELD_STRENGTH_Y,
FIELD_STRENGTH_Z,
TEMPERATURE_CELCIUS
};
class MgmPrimaryDataset: public StaticLocalDataSet<4> {
public:
MgmPrimaryDataset(HasLocalDataPoolIF* hkOwner):
StaticLocalDataSet(hkOwner, MGM_DATA_SET_ID) {}
class MgmPrimaryDataset : public StaticLocalDataSet<4> {
public:
MgmPrimaryDataset(HasLocalDataPoolIF* hkOwner) : StaticLocalDataSet(hkOwner, MGM_DATA_SET_ID) {}
MgmPrimaryDataset(object_id_t mgmId):
StaticLocalDataSet(sid_t(mgmId, MGM_DATA_SET_ID)) {}
MgmPrimaryDataset(object_id_t mgmId) : StaticLocalDataSet(sid_t(mgmId, MGM_DATA_SET_ID)) {}
lp_var_t<float> fieldStrengthX = lp_var_t<float>(sid.objectId,
FIELD_STRENGTH_X, this);
lp_var_t<float> fieldStrengthY = lp_var_t<float>(sid.objectId,
FIELD_STRENGTH_Y, this);
lp_var_t<float> fieldStrengthZ = lp_var_t<float>(sid.objectId,
FIELD_STRENGTH_Z, this);
lp_var_t<float> temperature = lp_var_t<float>(sid.objectId,
TEMPERATURE_CELCIUS, this);
lp_var_t<float> fieldStrengthX = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_X, this);
lp_var_t<float> fieldStrengthY = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_Y, this);
lp_var_t<float> fieldStrengthZ = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_Z, this);
lp_var_t<float> temperature = lp_var_t<float>(sid.objectId, TEMPERATURE_CELCIUS, this);
};
}
} // namespace MGMLIS3MDL
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_MGMLIS3HANDLERDEFS_H_ */

View File

@ -1,10 +1,11 @@
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERRM3100DEFINITIONS_H_
#define MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERRM3100DEFINITIONS_H_
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
#include <fsfw/datapoollocal/LocalPoolVariable.h>
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
#include <fsfw/serialize/SerialLinkedListAdapter.h>
#include <cstdint>
namespace RM3100 {
@ -24,8 +25,8 @@ static constexpr uint8_t SET_CMM_DRDM = 1 << 2;
static constexpr uint8_t SET_CMM_START = 1;
static constexpr uint8_t CMM_REGISTER = 0x01;
static constexpr uint8_t CMM_VALUE = SET_CMM_CMZ | SET_CMM_CMY | SET_CMM_CMX |
SET_CMM_DRDM | SET_CMM_START;
static constexpr uint8_t CMM_VALUE =
SET_CMM_CMZ | SET_CMM_CMY | SET_CMM_CMX | SET_CMM_DRDM | SET_CMM_START;
/*----------------------------------------------------------------------------*/
/* Cycle count register */
@ -33,8 +34,7 @@ static constexpr uint8_t CMM_VALUE = SET_CMM_CMZ | SET_CMM_CMY | SET_CMM_CMX |
// Default value (200)
static constexpr uint8_t CYCLE_COUNT_VALUE = 0xC8;
static constexpr float DEFAULT_GAIN = static_cast<float>(CYCLE_COUNT_VALUE) /
100 * 38;
static constexpr float DEFAULT_GAIN = static_cast<float>(CYCLE_COUNT_VALUE) / 100 * 38;
static constexpr uint8_t CYCLE_COUNT_START_REGISTER = 0x04;
/*----------------------------------------------------------------------------*/
@ -67,17 +67,16 @@ static constexpr DeviceCommandId_t READ_TMRC = 4;
static constexpr DeviceCommandId_t CONFIGURE_CYCLE_COUNT = 5;
static constexpr DeviceCommandId_t READ_CYCLE_COUNT = 6;
class CycleCountCommand: public SerialLinkedListAdapter<SerializeIF> {
public:
CycleCountCommand(bool oneCycleCount = true): oneCycleCount(oneCycleCount) {
class CycleCountCommand : public SerialLinkedListAdapter<SerializeIF> {
public:
CycleCountCommand(bool oneCycleCount = true) : oneCycleCount(oneCycleCount) {
setLinks(oneCycleCount);
}
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) override {
ReturnValue_t result = SerialLinkedListAdapter::deSerialize(buffer,
size, streamEndianness);
if(oneCycleCount) {
ReturnValue_t result = SerialLinkedListAdapter::deSerialize(buffer, size, streamEndianness);
if (oneCycleCount) {
cycleCountY = cycleCountX;
cycleCountZ = cycleCountX;
}
@ -88,10 +87,10 @@ public:
SerializeElement<uint16_t> cycleCountY;
SerializeElement<uint16_t> cycleCountZ;
private:
private:
void setLinks(bool oneCycleCount) {
setStart(&cycleCountX);
if(not oneCycleCount) {
if (not oneCycleCount) {
cycleCountX.setNext(&cycleCountY);
cycleCountY.setNext(&cycleCountZ);
}
@ -102,31 +101,24 @@ private:
static constexpr uint32_t MGM_DATASET_ID = READ_DATA;
enum MgmPoolIds: lp_id_t {
enum MgmPoolIds : lp_id_t {
FIELD_STRENGTH_X,
FIELD_STRENGTH_Y,
FIELD_STRENGTH_Z,
};
class Rm3100PrimaryDataset: public StaticLocalDataSet<3> {
public:
Rm3100PrimaryDataset(HasLocalDataPoolIF* hkOwner):
StaticLocalDataSet(hkOwner, MGM_DATASET_ID) {}
class Rm3100PrimaryDataset : public StaticLocalDataSet<3> {
public:
Rm3100PrimaryDataset(HasLocalDataPoolIF* hkOwner) : StaticLocalDataSet(hkOwner, MGM_DATASET_ID) {}
Rm3100PrimaryDataset(object_id_t mgmId):
StaticLocalDataSet(sid_t(mgmId, MGM_DATASET_ID)) {}
Rm3100PrimaryDataset(object_id_t mgmId) : StaticLocalDataSet(sid_t(mgmId, MGM_DATASET_ID)) {}
// Field strengths in micro Tesla.
lp_var_t<float> fieldStrengthX = lp_var_t<float>(sid.objectId,
FIELD_STRENGTH_X, this);
lp_var_t<float> fieldStrengthY = lp_var_t<float>(sid.objectId,
FIELD_STRENGTH_Y, this);
lp_var_t<float> fieldStrengthZ = lp_var_t<float>(sid.objectId,
FIELD_STRENGTH_Z, this);
lp_var_t<float> fieldStrengthX = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_X, this);
lp_var_t<float> fieldStrengthY = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_Y, this);
lp_var_t<float> fieldStrengthZ = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_Z, this);
};
}
} // namespace RM3100
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERRM3100DEFINITIONS_H_ */

View File

@ -1,50 +1,47 @@
#include "CommandExecutor.h"
#include "fsfw/serviceinterface.h"
#include "fsfw/container/SimpleRingBuffer.h"
#include "fsfw/container/DynamicFIFO.h"
#include <unistd.h>
#include <cstring>
CommandExecutor::CommandExecutor(const size_t maxSize):
readVec(maxSize) {
#include "fsfw/container/DynamicFIFO.h"
#include "fsfw/container/SimpleRingBuffer.h"
#include "fsfw/serviceinterface.h"
CommandExecutor::CommandExecutor(const size_t maxSize) : readVec(maxSize) {
waiter.events = POLLIN;
}
ReturnValue_t CommandExecutor::load(std::string command, bool blocking, bool printOutput) {
if(state == States::PENDING) {
if (state == States::PENDING) {
return COMMAND_PENDING;
}
currentCmd = command;
this->blocking = blocking;
this->printOutput = printOutput;
if(state == States::IDLE) {
if (state == States::IDLE) {
state = States::COMMAND_LOADED;
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t CommandExecutor::execute() {
if(state == States::IDLE) {
if (state == States::IDLE) {
return NO_COMMAND_LOADED_OR_PENDING;
}
else if(state == States::PENDING) {
} else if (state == States::PENDING) {
return COMMAND_PENDING;
}
currentCmdFile = popen(currentCmd.c_str(), "r");
if(currentCmdFile == nullptr) {
if (currentCmdFile == nullptr) {
lastError = errno;
return HasReturnvaluesIF::RETURN_FAILED;
}
if(blocking) {
if (blocking) {
ReturnValue_t result = executeBlocking();
state = States::IDLE;
return result;
}
else {
} else {
currentFd = fileno(currentCmdFile);
waiter.fd = currentFd;
}
@ -53,9 +50,9 @@ ReturnValue_t CommandExecutor::execute() {
}
ReturnValue_t CommandExecutor::close() {
if(state == States::PENDING) {
if (state == States::PENDING) {
// Attempt to close process, irrespective of if it is running or not
if(currentCmdFile != nullptr) {
if (currentCmdFile != nullptr) {
pclose(currentCmdFile);
}
}
@ -63,59 +60,59 @@ ReturnValue_t CommandExecutor::close() {
}
void CommandExecutor::printLastError(std::string funcName) const {
if(lastError != 0) {
if (lastError != 0) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << funcName << " pclose failed with code " << lastError << ": " <<
strerror(lastError) << std::endl;
sif::warning << funcName << " pclose failed with code " << lastError << ": "
<< strerror(lastError) << std::endl;
#else
sif::printError("%s pclose failed with code %d: %s\n",
funcName, lastError, strerror(lastError));
sif::printError("%s pclose failed with code %d: %s\n", funcName, lastError,
strerror(lastError));
#endif
}
}
void CommandExecutor::setRingBuffer(SimpleRingBuffer *ringBuffer,
void CommandExecutor::setRingBuffer(SimpleRingBuffer* ringBuffer,
DynamicFIFO<uint16_t>* sizesFifo) {
this->ringBuffer = ringBuffer;
this->sizesFifo = sizesFifo;
}
ReturnValue_t CommandExecutor::check(bool& replyReceived) {
if(blocking) {
if (blocking) {
return HasReturnvaluesIF::RETURN_OK;
}
switch(state) {
case(States::IDLE):
case(States::COMMAND_LOADED): {
switch (state) {
case (States::IDLE):
case (States::COMMAND_LOADED): {
return NO_COMMAND_LOADED_OR_PENDING;
}
case(States::PENDING): {
case (States::PENDING): {
break;
}
}
int result = poll(&waiter, 1, 0);
switch(result) {
case(0): {
switch (result) {
case (0): {
return HasReturnvaluesIF::RETURN_OK;
break;
}
case(1): {
case (1): {
if (waiter.revents & POLLIN) {
ssize_t readBytes = read(currentFd, readVec.data(), readVec.size());
if(readBytes == 0) {
if (readBytes == 0) {
// Should not happen
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "CommandExecutor::check: No bytes read "
"after poll event.." << std::endl;
"after poll event.."
<< std::endl;
#else
sif::printWarning("CommandExecutor::check: No bytes read after poll event..\n");
#endif
break;
}
else if(readBytes > 0) {
} else if (readBytes > 0) {
replyReceived = true;
if(printOutput) {
if (printOutput) {
// It is assumed the command output is line terminated
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << currentCmd << " | " << readVec.data();
@ -123,27 +120,25 @@ ReturnValue_t CommandExecutor::check(bool& replyReceived) {
sif::printInfo("%s | %s", currentCmd, readVec.data());
#endif
}
if(ringBuffer != nullptr) {
ringBuffer->writeData(reinterpret_cast<const uint8_t*>(
readVec.data()), readBytes);
if (ringBuffer != nullptr) {
ringBuffer->writeData(reinterpret_cast<const uint8_t*>(readVec.data()), readBytes);
}
if(sizesFifo != nullptr) {
if(not sizesFifo->full()) {
if (sizesFifo != nullptr) {
if (not sizesFifo->full()) {
sizesFifo->insert(readBytes);
}
}
}
else {
} else {
// Should also not happen
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "CommandExecutor::check: Error " << errno << ": " <<
strerror(errno) << std::endl;
sif::warning << "CommandExecutor::check: Error " << errno << ": " << strerror(errno)
<< std::endl;
#else
sif::printWarning("CommandExecutor::check: Error %d: %s\n", errno, strerror(errno));
#endif
}
}
if(waiter.revents & POLLERR) {
if (waiter.revents & POLLERR) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "CommandExecuter::check: Poll error" << std::endl;
#else
@ -151,10 +146,10 @@ ReturnValue_t CommandExecutor::check(bool& replyReceived) {
#endif
return COMMAND_ERROR;
}
if(waiter.revents & POLLHUP) {
if (waiter.revents & POLLHUP) {
result = pclose(currentCmdFile);
ReturnValue_t retval = EXECUTION_FINISHED;
if(result != 0) {
if (result != 0) {
lastError = result;
retval = HasReturnvaluesIF::RETURN_FAILED;
}
@ -177,35 +172,34 @@ void CommandExecutor::reset() {
}
int CommandExecutor::getLastError() const {
// See: https://stackoverflow.com/questions/808541/any-benefit-in-using-wexitstatus-macro-in-c-over-division-by-256-on-exit-statu
// See:
// https://stackoverflow.com/questions/808541/any-benefit-in-using-wexitstatus-macro-in-c-over-division-by-256-on-exit-statu
return WEXITSTATUS(this->lastError);
}
CommandExecutor::States CommandExecutor::getCurrentState() const {
return state;
}
CommandExecutor::States CommandExecutor::getCurrentState() const { return state; }
ReturnValue_t CommandExecutor::executeBlocking() {
while(fgets(readVec.data(), readVec.size(), currentCmdFile) != nullptr) {
while (fgets(readVec.data(), readVec.size(), currentCmdFile) != nullptr) {
std::string output(readVec.data());
if(printOutput) {
if (printOutput) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << currentCmd << " | " << output;
#else
sif::printInfo("%s | %s", currentCmd, output);
#endif
}
if(ringBuffer != nullptr) {
if (ringBuffer != nullptr) {
ringBuffer->writeData(reinterpret_cast<const uint8_t*>(output.data()), output.size());
}
if(sizesFifo != nullptr) {
if(not sizesFifo->full()) {
if (sizesFifo != nullptr) {
if (not sizesFifo->full()) {
sizesFifo->insert(output.size());
}
}
}
int result = pclose(currentCmdFile);
if(result != 0) {
if (result != 0) {
lastError = result;
return HasReturnvaluesIF::RETURN_FAILED;
}

View File

@ -1,16 +1,17 @@
#ifndef FSFW_SRC_FSFW_OSAL_LINUX_COMMANDEXECUTOR_H_
#define FSFW_SRC_FSFW_OSAL_LINUX_COMMANDEXECUTOR_H_
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include "fsfw/returnvalues/FwClassIds.h"
#include <poll.h>
#include <string>
#include <vector>
#include "fsfw/returnvalues/FwClassIds.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
class SimpleRingBuffer;
template <typename T> class DynamicFIFO;
template <typename T>
class DynamicFIFO;
/**
* @brief Helper class to execute shell commands in blocking and non-blocking mode
@ -24,12 +25,8 @@ template <typename T> class DynamicFIFO;
* has finished
*/
class CommandExecutor {
public:
enum class States {
IDLE,
COMMAND_LOADED,
PENDING
};
public:
enum class States { IDLE, COMMAND_LOADED, PENDING };
static constexpr uint8_t CLASS_ID = CLASS_ID::LINUX_OSAL;
@ -39,19 +36,15 @@ public:
//! [EXPORT] : [COMMENT] Command is pending. This will also be returned if the user tries
//! to load another command but a command is still pending
static constexpr ReturnValue_t COMMAND_PENDING =
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 1);
static constexpr ReturnValue_t COMMAND_PENDING = HasReturnvaluesIF::makeReturnCode(CLASS_ID, 1);
//! [EXPORT] : [COMMENT] Some bytes have been read from the executing process
static constexpr ReturnValue_t BYTES_READ =
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 2);
static constexpr ReturnValue_t BYTES_READ = HasReturnvaluesIF::makeReturnCode(CLASS_ID, 2);
//! [EXPORT] : [COMMENT] Command execution failed
static constexpr ReturnValue_t COMMAND_ERROR =
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 3);
static constexpr ReturnValue_t COMMAND_ERROR = HasReturnvaluesIF::makeReturnCode(CLASS_ID, 3);
//! [EXPORT] : [COMMENT]
static constexpr ReturnValue_t NO_COMMAND_LOADED_OR_PENDING =
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 4);
static constexpr ReturnValue_t PCLOSE_CALL_ERROR =
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 6);
static constexpr ReturnValue_t PCLOSE_CALL_ERROR = HasReturnvaluesIF::makeReturnCode(CLASS_ID, 6);
/**
* Constructor. Is initialized with maximum size of internal buffer to read data from the
@ -115,7 +108,8 @@ public:
* commands can be loaded and executed
*/
void reset();
private:
private:
std::string currentCmd;
bool blocking = true;
FILE* currentCmdFile = nullptr;

View File

@ -1,25 +1,26 @@
#include "fsfw/FSFW.h"
#include "fsfw/serviceinterface.h"
#include "fsfw_hal/linux/UnixFileGuard.h"
#include <cerrno>
#include <cstring>
#include "fsfw/FSFW.h"
#include "fsfw/serviceinterface.h"
UnixFileGuard::UnixFileGuard(std::string device, int* fileDescriptor, int flags,
std::string diagnosticPrefix):
fileDescriptor(fileDescriptor) {
if(fileDescriptor == nullptr) {
std::string diagnosticPrefix)
: fileDescriptor(fileDescriptor) {
if (fileDescriptor == nullptr) {
return;
}
*fileDescriptor = open(device.c_str(), flags);
if (*fileDescriptor < 0) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << diagnosticPrefix << ": Opening device failed with error code " <<
errno << ": " << strerror(errno) << std::endl;
sif::warning << diagnosticPrefix << ": Opening device failed with error code " << errno << ": "
<< strerror(errno) << std::endl;
#else
sif::printWarning("%s: Opening device failed with error code %d: %s\n",
diagnosticPrefix, errno, strerror(errno));
sif::printWarning("%s: Opening device failed with error code %d: %s\n", diagnosticPrefix, errno,
strerror(errno));
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
openStatus = OPEN_FILE_FAILED;
@ -27,11 +28,9 @@ UnixFileGuard::UnixFileGuard(std::string device, int* fileDescriptor, int flags,
}
UnixFileGuard::~UnixFileGuard() {
if(fileDescriptor != nullptr) {
if (fileDescriptor != nullptr) {
close(*fileDescriptor);
}
}
ReturnValue_t UnixFileGuard::getOpenResult() const {
return openStatus;
}
ReturnValue_t UnixFileGuard::getOpenResult() const { return openStatus; }

View File

@ -1,16 +1,14 @@
#ifndef LINUX_UTILITY_UNIXFILEGUARD_H_
#define LINUX_UTILITY_UNIXFILEGUARD_H_
#include <fcntl.h>
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
#include <unistd.h>
#include <string>
#include <fcntl.h>
#include <unistd.h>
class UnixFileGuard {
public:
public:
static constexpr int READ_WRITE_FLAG = O_RDWR;
static constexpr int READ_ONLY_FLAG = O_RDONLY;
static constexpr int NON_BLOCKING_IO_FLAG = O_NONBLOCK;
@ -20,14 +18,13 @@ public:
UnixFileGuard(std::string device, int* fileDescriptor, int flags,
std::string diagnosticPrefix = "");
virtual~ UnixFileGuard();
virtual ~UnixFileGuard();
ReturnValue_t getOpenResult() const;
private:
private:
int* fileDescriptor = nullptr;
ReturnValue_t openStatus = HasReturnvaluesIF::RETURN_OK;
};
#endif /* LINUX_UTILITY_UNIXFILEGUARD_H_ */

View File

@ -1,26 +1,25 @@
#include "LinuxLibgpioIF.h"
#include "fsfw_hal/common/gpio/gpioDefinitions.h"
#include "fsfw_hal/common/gpio/GpioCookie.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include <gpiod.h>
#include <unistd.h>
#include <utility>
#include <unistd.h>
#include <gpiod.h>
LinuxLibgpioIF::LinuxLibgpioIF(object_id_t objectId) : SystemObject(objectId) {
}
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw_hal/common/gpio/GpioCookie.h"
#include "fsfw_hal/common/gpio/gpioDefinitions.h"
LinuxLibgpioIF::LinuxLibgpioIF(object_id_t objectId) : SystemObject(objectId) {}
LinuxLibgpioIF::~LinuxLibgpioIF() {
for(auto& config: gpioMap) {
delete(config.second);
for (auto& config : gpioMap) {
delete (config.second);
}
}
ReturnValue_t LinuxLibgpioIF::addGpios(GpioCookie* gpioCookie) {
ReturnValue_t result;
if(gpioCookie == nullptr) {
if (gpioCookie == nullptr) {
sif::error << "LinuxLibgpioIF::addGpios: Invalid cookie" << std::endl;
return RETURN_FAILED;
}
@ -29,7 +28,7 @@ ReturnValue_t LinuxLibgpioIF::addGpios(GpioCookie* gpioCookie) {
/* Check whether this ID already exists in the map and remove duplicates */
result = checkForConflicts(mapToAdd);
if (result != RETURN_OK){
if (result != RETURN_OK) {
return result;
}
@ -45,39 +44,39 @@ ReturnValue_t LinuxLibgpioIF::addGpios(GpioCookie* gpioCookie) {
}
ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap& mapToAdd) {
for(auto& gpioConfig: mapToAdd) {
for (auto& gpioConfig : mapToAdd) {
auto& gpioType = gpioConfig.second->gpioType;
switch(gpioType) {
case(gpio::GpioTypes::NONE): {
switch (gpioType) {
case (gpio::GpioTypes::NONE): {
return GPIO_INVALID_INSTANCE;
}
case(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP): {
case (gpio::GpioTypes::GPIO_REGULAR_BY_CHIP): {
auto regularGpio = dynamic_cast<GpiodRegularByChip*>(gpioConfig.second);
if(regularGpio == nullptr) {
if (regularGpio == nullptr) {
return GPIO_INVALID_INSTANCE;
}
configureGpioByChip(gpioConfig.first, *regularGpio);
break;
}
case(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL):{
case (gpio::GpioTypes::GPIO_REGULAR_BY_LABEL): {
auto regularGpio = dynamic_cast<GpiodRegularByLabel*>(gpioConfig.second);
if(regularGpio == nullptr) {
if (regularGpio == nullptr) {
return GPIO_INVALID_INSTANCE;
}
configureGpioByLabel(gpioConfig.first, *regularGpio);
break;
}
case(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME):{
case (gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME): {
auto regularGpio = dynamic_cast<GpiodRegularByLineName*>(gpioConfig.second);
if(regularGpio == nullptr) {
if (regularGpio == nullptr) {
return GPIO_INVALID_INSTANCE;
}
configureGpioByLineName(gpioConfig.first, *regularGpio);
break;
}
case(gpio::GpioTypes::CALLBACK): {
case (gpio::GpioTypes::CALLBACK): {
auto gpioCallback = dynamic_cast<GpioCallback*>(gpioConfig.second);
if(gpioCallback->callback == nullptr) {
if (gpioCallback->callback == nullptr) {
return GPIO_INVALID_INSTANCE;
}
gpioCallback->callback(gpioConfig.first, gpio::GpioOperation::WRITE,
@ -89,26 +88,24 @@ ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap& mapToAdd) {
}
ReturnValue_t LinuxLibgpioIF::configureGpioByLabel(gpioId_t gpioId,
GpiodRegularByLabel &gpioByLabel) {
GpiodRegularByLabel& gpioByLabel) {
std::string& label = gpioByLabel.label;
struct gpiod_chip* chip = gpiod_chip_open_by_label(label.c_str());
if (chip == nullptr) {
sif::warning << "LinuxLibgpioIF::configureGpioByLabel: Failed to open gpio from gpio "
<< "group with label " << label << ". Gpio ID: " << gpioId << std::endl;
return RETURN_FAILED;
}
std::string failOutput = "label: " + label;
return configureRegularGpio(gpioId, chip, gpioByLabel, failOutput);
}
ReturnValue_t LinuxLibgpioIF::configureGpioByChip(gpioId_t gpioId,
GpiodRegularByChip &gpioByChip) {
ReturnValue_t LinuxLibgpioIF::configureGpioByChip(gpioId_t gpioId, GpiodRegularByChip& gpioByChip) {
std::string& chipname = gpioByChip.chipname;
struct gpiod_chip* chip = gpiod_chip_open_by_name(chipname.c_str());
if (chip == nullptr) {
sif::warning << "LinuxLibgpioIF::configureGpioByChip: Failed to open chip "
<< chipname << ". Gpio ID: " << gpioId << std::endl;
sif::warning << "LinuxLibgpioIF::configureGpioByChip: Failed to open chip " << chipname
<< ". Gpio ID: " << gpioId << std::endl;
return RETURN_FAILED;
}
std::string failOutput = "chipname: " + chipname;
@ -116,13 +113,13 @@ ReturnValue_t LinuxLibgpioIF::configureGpioByChip(gpioId_t gpioId,
}
ReturnValue_t LinuxLibgpioIF::configureGpioByLineName(gpioId_t gpioId,
GpiodRegularByLineName &gpioByLineName) {
GpiodRegularByLineName& gpioByLineName) {
std::string& lineName = gpioByLineName.lineName;
char chipname[MAX_CHIPNAME_LENGTH];
unsigned int lineOffset;
int result = gpiod_ctxless_find_line(lineName.c_str(), chipname, MAX_CHIPNAME_LENGTH,
&lineOffset);
int result =
gpiod_ctxless_find_line(lineName.c_str(), chipname, MAX_CHIPNAME_LENGTH, &lineOffset);
if (result != LINE_FOUND) {
parseFindeLineResult(result, lineName);
return RETURN_FAILED;
@ -132,8 +129,8 @@ ReturnValue_t LinuxLibgpioIF::configureGpioByLineName(gpioId_t gpioId,
struct gpiod_chip* chip = gpiod_chip_open_by_name(chipname);
if (chip == nullptr) {
sif::warning << "LinuxLibgpioIF::configureGpioByLineName: Failed to open chip "
<< chipname << ". <Gpio ID: " << gpioId << std::endl;
sif::warning << "LinuxLibgpioIF::configureGpioByLineName: Failed to open chip " << chipname
<< ". <Gpio ID: " << gpioId << std::endl;
return RETURN_FAILED;
}
std::string failOutput = "line name: " + lineName;
@ -141,19 +138,20 @@ ReturnValue_t LinuxLibgpioIF::configureGpioByLineName(gpioId_t gpioId,
}
ReturnValue_t LinuxLibgpioIF::configureRegularGpio(gpioId_t gpioId, struct gpiod_chip* chip,
GpiodRegularBase& regularGpio, std::string failOutput) {
GpiodRegularBase& regularGpio,
std::string failOutput) {
unsigned int lineNum;
gpio::Direction direction;
std::string consumer;
struct gpiod_line *lineHandle;
struct gpiod_line* lineHandle;
int result = 0;
lineNum = regularGpio.lineNum;
lineHandle = gpiod_chip_get_line(chip, lineNum);
if (!lineHandle) {
sif::warning << "LinuxLibgpioIF::configureRegularGpio: Failed to open line " << std::endl;
sif::warning << "GPIO ID: " << gpioId << ", line number: " << lineNum <<
", " << failOutput << std::endl;
sif::warning << "GPIO ID: " << gpioId << ", line number: " << lineNum << ", " << failOutput
<< std::endl;
sif::warning << "Check if Linux GPIO configuration has changed. " << std::endl;
gpiod_chip_close(chip);
return RETURN_FAILED;
@ -163,33 +161,32 @@ ReturnValue_t LinuxLibgpioIF::configureRegularGpio(gpioId_t gpioId, struct gpiod
consumer = regularGpio.consumer;
/* Configure direction and add a description to the GPIO */
switch (direction) {
case(gpio::OUT): {
result = gpiod_line_request_output(lineHandle, consumer.c_str(),
regularGpio.initValue);
case (gpio::OUT): {
result = gpiod_line_request_output(lineHandle, consumer.c_str(), regularGpio.initValue);
break;
}
case(gpio::IN): {
case (gpio::IN): {
result = gpiod_line_request_input(lineHandle, consumer.c_str());
break;
}
default: {
sif::error << "LinuxLibgpioIF::configureGpios: Invalid direction specified"
<< std::endl;
sif::error << "LinuxLibgpioIF::configureGpios: Invalid direction specified" << std::endl;
return GPIO_INVALID_INSTANCE;
}
if (result < 0) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "LinuxLibgpioIF::configureRegularGpio: Failed to request line " <<
lineNum << " from GPIO instance with ID: " << gpioId << std::endl;
sif::error << "LinuxLibgpioIF::configureRegularGpio: Failed to request line " << lineNum
<< " from GPIO instance with ID: " << gpioId << std::endl;
#else
sif::printError("LinuxLibgpioIF::configureRegularGpio: "
"Failed to request line %d from GPIO instance with ID: %d\n", lineNum, gpioId);
sif::printError(
"LinuxLibgpioIF::configureRegularGpio: "
"Failed to request line %d from GPIO instance with ID: %d\n",
lineNum, gpioId);
#endif
gpiod_line_release(lineHandle);
return RETURN_FAILED;
}
}
/**
* Write line handle to GPIO configuration instance so it can later be used to set or
@ -207,22 +204,21 @@ ReturnValue_t LinuxLibgpioIF::pullHigh(gpioId_t gpioId) {
}
auto gpioType = gpioMapIter->second->gpioType;
if (gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP
or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL
or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME) {
if (gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP or
gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL or
gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME) {
auto regularGpio = dynamic_cast<GpiodRegularBase*>(gpioMapIter->second);
if(regularGpio == nullptr) {
if (regularGpio == nullptr) {
return GPIO_TYPE_FAILURE;
}
return driveGpio(gpioId, *regularGpio, gpio::HIGH);
}
else {
} else {
auto gpioCallback = dynamic_cast<GpioCallback*>(gpioMapIter->second);
if(gpioCallback->callback == nullptr) {
if (gpioCallback->callback == nullptr) {
return GPIO_INVALID_INSTANCE;
}
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE,
gpio::Levels::HIGH, gpioCallback->callbackArgs);
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE, gpio::Levels::HIGH,
gpioCallback->callbackArgs);
return RETURN_OK;
}
return GPIO_TYPE_FAILURE;
@ -240,37 +236,38 @@ ReturnValue_t LinuxLibgpioIF::pullLow(gpioId_t gpioId) {
}
auto& gpioType = gpioMapIter->second->gpioType;
if (gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP
or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL
or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME) {
if (gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP or
gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL or
gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME) {
auto regularGpio = dynamic_cast<GpiodRegularBase*>(gpioMapIter->second);
if(regularGpio == nullptr) {
if (regularGpio == nullptr) {
return GPIO_TYPE_FAILURE;
}
return driveGpio(gpioId, *regularGpio, gpio::LOW);
}
else {
} else {
auto gpioCallback = dynamic_cast<GpioCallback*>(gpioMapIter->second);
if(gpioCallback->callback == nullptr) {
if (gpioCallback->callback == nullptr) {
return GPIO_INVALID_INSTANCE;
}
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE,
gpio::Levels::LOW, gpioCallback->callbackArgs);
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE, gpio::Levels::LOW,
gpioCallback->callbackArgs);
return RETURN_OK;
}
return GPIO_TYPE_FAILURE;
}
ReturnValue_t LinuxLibgpioIF::driveGpio(gpioId_t gpioId,
GpiodRegularBase& regularGpio, gpio::Levels logicLevel) {
ReturnValue_t LinuxLibgpioIF::driveGpio(gpioId_t gpioId, GpiodRegularBase& regularGpio,
gpio::Levels logicLevel) {
int result = gpiod_line_set_value(regularGpio.lineHandle, logicLevel);
if (result < 0) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "LinuxLibgpioIF::driveGpio: Failed to pull GPIO with ID " << gpioId <<
" to logic level " << logicLevel << std::endl;
sif::warning << "LinuxLibgpioIF::driveGpio: Failed to pull GPIO with ID " << gpioId
<< " to logic level " << logicLevel << std::endl;
#else
sif::printWarning("LinuxLibgpioIF::driveGpio: Failed to pull GPIO with ID %d to "
"logic level %d\n", gpioId, logicLevel);
sif::printWarning(
"LinuxLibgpioIF::driveGpio: Failed to pull GPIO with ID %d to "
"logic level %d\n",
gpioId, logicLevel);
#endif
return DRIVE_GPIO_FAILURE;
}
@ -280,7 +277,7 @@ ReturnValue_t LinuxLibgpioIF::driveGpio(gpioId_t gpioId,
ReturnValue_t LinuxLibgpioIF::readGpio(gpioId_t gpioId, int* gpioState) {
gpioMapIter = gpioMap.find(gpioId);
if (gpioMapIter == gpioMap.end()){
if (gpioMapIter == gpioMap.end()) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "LinuxLibgpioIF::readGpio: Unknown GPIOD ID " << gpioId << std::endl;
#else
@ -290,63 +287,60 @@ ReturnValue_t LinuxLibgpioIF::readGpio(gpioId_t gpioId, int* gpioState) {
}
auto gpioType = gpioMapIter->second->gpioType;
if (gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP
or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL
or gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME) {
if (gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_CHIP or
gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LABEL or
gpioType == gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME) {
auto regularGpio = dynamic_cast<GpiodRegularBase*>(gpioMapIter->second);
if(regularGpio == nullptr) {
if (regularGpio == nullptr) {
return GPIO_TYPE_FAILURE;
}
*gpioState = gpiod_line_get_value(regularGpio->lineHandle);
}
else {
} else {
auto gpioCallback = dynamic_cast<GpioCallback*>(gpioMapIter->second);
if(gpioCallback->callback == nullptr) {
if (gpioCallback->callback == nullptr) {
return GPIO_INVALID_INSTANCE;
}
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::READ,
gpio::Levels::NONE, gpioCallback->callbackArgs);
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::READ, gpio::Levels::NONE,
gpioCallback->callbackArgs);
return RETURN_OK;
}
return RETURN_OK;
}
ReturnValue_t LinuxLibgpioIF::checkForConflicts(GpioMap& mapToAdd){
ReturnValue_t LinuxLibgpioIF::checkForConflicts(GpioMap& mapToAdd) {
ReturnValue_t status = HasReturnvaluesIF::RETURN_OK;
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
for(auto& gpioConfig: mapToAdd) {
switch(gpioConfig.second->gpioType) {
case(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP):
case(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL):
case(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME): {
for (auto& gpioConfig : mapToAdd) {
switch (gpioConfig.second->gpioType) {
case (gpio::GpioTypes::GPIO_REGULAR_BY_CHIP):
case (gpio::GpioTypes::GPIO_REGULAR_BY_LABEL):
case (gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME): {
auto regularGpio = dynamic_cast<GpiodRegularBase*>(gpioConfig.second);
if(regularGpio == nullptr) {
if (regularGpio == nullptr) {
return GPIO_TYPE_FAILURE;
}
// Check for conflicts and remove duplicates if necessary
result = checkForConflictsById(gpioConfig.first, gpioConfig.second->gpioType, mapToAdd);
if(result != HasReturnvaluesIF::RETURN_OK) {
if (result != HasReturnvaluesIF::RETURN_OK) {
status = result;
}
break;
}
case(gpio::GpioTypes::CALLBACK): {
case (gpio::GpioTypes::CALLBACK): {
auto callbackGpio = dynamic_cast<GpioCallback*>(gpioConfig.second);
if(callbackGpio == nullptr) {
if (callbackGpio == nullptr) {
return GPIO_TYPE_FAILURE;
}
// Check for conflicts and remove duplicates if necessary
result = checkForConflictsById(gpioConfig.first,
gpioConfig.second->gpioType, mapToAdd);
if(result != HasReturnvaluesIF::RETURN_OK) {
result = checkForConflictsById(gpioConfig.first, gpioConfig.second->gpioType, mapToAdd);
if (result != HasReturnvaluesIF::RETURN_OK) {
status = result;
}
break;
}
default: {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "Invalid GPIO type detected for GPIO ID " << gpioConfig.first
<< std::endl;
sif::warning << "Invalid GPIO type detected for GPIO ID " << gpioConfig.first << std::endl;
#else
sif::printWarning("Invalid GPIO type detected for GPIO ID %d\n", gpioConfig.first);
#endif
@ -358,38 +352,41 @@ ReturnValue_t LinuxLibgpioIF::checkForConflicts(GpioMap& mapToAdd){
}
ReturnValue_t LinuxLibgpioIF::checkForConflictsById(gpioId_t gpioIdToCheck,
gpio::GpioTypes expectedType, GpioMap& mapToAdd) {
gpio::GpioTypes expectedType,
GpioMap& mapToAdd) {
// Cross check with private map
gpioMapIter = gpioMap.find(gpioIdToCheck);
if(gpioMapIter != gpioMap.end()) {
if (gpioMapIter != gpioMap.end()) {
auto& gpioType = gpioMapIter->second->gpioType;
bool eraseDuplicateDifferentType = false;
switch(expectedType) {
case(gpio::GpioTypes::NONE): {
switch (expectedType) {
case (gpio::GpioTypes::NONE): {
break;
}
case(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP):
case(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL):
case(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME): {
if(gpioType == gpio::GpioTypes::NONE or gpioType == gpio::GpioTypes::CALLBACK) {
case (gpio::GpioTypes::GPIO_REGULAR_BY_CHIP):
case (gpio::GpioTypes::GPIO_REGULAR_BY_LABEL):
case (gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME): {
if (gpioType == gpio::GpioTypes::NONE or gpioType == gpio::GpioTypes::CALLBACK) {
eraseDuplicateDifferentType = true;
}
break;
}
case(gpio::GpioTypes::CALLBACK): {
if(gpioType != gpio::GpioTypes::CALLBACK) {
case (gpio::GpioTypes::CALLBACK): {
if (gpioType != gpio::GpioTypes::CALLBACK) {
eraseDuplicateDifferentType = true;
}
}
}
if(eraseDuplicateDifferentType) {
if (eraseDuplicateDifferentType) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "LinuxLibgpioIF::checkForConflicts: ID already exists for "
"different GPIO type " << gpioIdToCheck <<
". Removing duplicate from map to add" << std::endl;
"different GPIO type "
<< gpioIdToCheck << ". Removing duplicate from map to add" << std::endl;
#else
sif::printWarning("LinuxLibgpioIF::checkForConflicts: ID already exists for "
"different GPIO type %d. Removing duplicate from map to add\n", gpioIdToCheck);
sif::printWarning(
"LinuxLibgpioIF::checkForConflicts: ID already exists for "
"different GPIO type %d. Removing duplicate from map to add\n",
gpioIdToCheck);
#endif
mapToAdd.erase(gpioIdToCheck);
return GPIO_DUPLICATE_DETECTED;
@ -398,11 +395,14 @@ ReturnValue_t LinuxLibgpioIF::checkForConflictsById(gpioId_t gpioIdToCheck,
// Remove element from map to add because a entry for this GPIO already exists
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "LinuxLibgpioIF::checkForConflictsRegularGpio: Duplicate GPIO "
"definition with ID " << gpioIdToCheck << " detected. " <<
"Duplicate will be removed from map to add" << std::endl;
"definition with ID "
<< gpioIdToCheck << " detected. "
<< "Duplicate will be removed from map to add" << std::endl;
#else
sif::printWarning("LinuxLibgpioIF::checkForConflictsRegularGpio: Duplicate GPIO definition "
"with ID %d detected. Duplicate will be removed from map to add\n", gpioIdToCheck);
sif::printWarning(
"LinuxLibgpioIF::checkForConflictsRegularGpio: Duplicate GPIO definition "
"with ID %d detected. Duplicate will be removed from map to add\n",
gpioIdToCheck);
#endif
mapToAdd.erase(gpioIdToCheck);
return GPIO_DUPLICATE_DETECTED;
@ -415,28 +415,32 @@ void LinuxLibgpioIF::parseFindeLineResult(int result, std::string& lineName) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
case LINE_NOT_EXISTS:
case LINE_ERROR: {
sif::warning << "LinuxLibgpioIF::parseFindeLineResult: Line with name " << lineName <<
" does not exist" << std::endl;
sif::warning << "LinuxLibgpioIF::parseFindeLineResult: Line with name " << lineName
<< " does not exist" << std::endl;
break;
}
default: {
sif::warning << "LinuxLibgpioIF::parseFindeLineResult: Unknown return code for line "
"with name " << lineName << std::endl;
"with name "
<< lineName << std::endl;
break;
}
#else
case LINE_NOT_EXISTS:
case LINE_ERROR: {
sif::printWarning("LinuxLibgpioIF::parseFindeLineResult: Line with name %s "
"does not exist\n", lineName);
sif::printWarning(
"LinuxLibgpioIF::parseFindeLineResult: Line with name %s "
"does not exist\n",
lineName);
break;
}
default: {
sif::printWarning("LinuxLibgpioIF::parseFindeLineResult: Unknown return code for line "
"with name %s\n", lineName);
sif::printWarning(
"LinuxLibgpioIF::parseFindeLineResult: Unknown return code for line "
"with name %s\n",
lineName);
break;
}
#endif
}
}

View File

@ -1,9 +1,9 @@
#ifndef LINUX_GPIO_LINUXLIBGPIOIF_H_
#define LINUX_GPIO_LINUXLIBGPIOIF_H_
#include "fsfw/objectmanager/SystemObject.h"
#include "fsfw/returnvalues/FwClassIds.h"
#include "fsfw_hal/common/gpio/GpioIF.h"
#include "fsfw/objectmanager/SystemObject.h"
class GpioCookie;
class GpiodRegularIF;
@ -16,8 +16,7 @@ class GpiodRegularIF;
* The Petalinux SDK from Xilinx supports libgpiod since Petalinux 2019.1.
*/
class LinuxLibgpioIF : public GpioIF, public SystemObject {
public:
public:
static const uint8_t gpioRetvalId = CLASS_ID::HAL_GPIO;
static constexpr ReturnValue_t UNKNOWN_GPIO_ID =
@ -39,8 +38,7 @@ public:
ReturnValue_t pullLow(gpioId_t gpioId) override;
ReturnValue_t readGpio(gpioId_t gpioId, int* gpioState) override;
private:
private:
static const size_t MAX_CHIPNAME_LENGTH = 11;
static const int LINE_NOT_EXISTS = 0;
static const int LINE_ERROR = -1;
@ -56,13 +54,11 @@ private:
* @param gpioId The GPIO ID of the GPIO to drive.
* @param logiclevel The logic level to set. O or 1.
*/
ReturnValue_t driveGpio(gpioId_t gpioId, GpiodRegularBase& regularGpio,
gpio::Levels logicLevel);
ReturnValue_t driveGpio(gpioId_t gpioId, GpiodRegularBase& regularGpio, gpio::Levels logicLevel);
ReturnValue_t configureGpioByLabel(gpioId_t gpioId, GpiodRegularByLabel& gpioByLabel);
ReturnValue_t configureGpioByChip(gpioId_t gpioId, GpiodRegularByChip& gpioByChip);
ReturnValue_t configureGpioByLineName(gpioId_t gpioId,
GpiodRegularByLineName &gpioByLineName);
ReturnValue_t configureGpioByLineName(gpioId_t gpioId, GpiodRegularByLineName& gpioByLineName);
ReturnValue_t configureRegularGpio(gpioId_t gpioId, struct gpiod_chip* chip,
GpiodRegularBase& regularGpio, std::string failOutput);
@ -77,8 +73,7 @@ private:
*/
ReturnValue_t checkForConflicts(GpioMap& mapToAdd);
ReturnValue_t checkForConflictsById(gpioId_t gpiodId, gpio::GpioTypes type,
GpioMap& mapToAdd);
ReturnValue_t checkForConflictsById(gpioId_t gpiodId, gpio::GpioTypes type, GpioMap& mapToAdd);
/**
* @brief Performs the initial configuration of all GPIOs specified in the GpioMap mapToAdd.

View File

@ -1,38 +1,34 @@
#include "fsfw/FSFW.h"
#include "fsfw_hal/linux/i2c/I2cComIF.h"
#include "fsfw_hal/linux/utility.h"
#include "fsfw_hal/linux/UnixFileGuard.h"
#include "fsfw/serviceinterface.h"
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/i2c-dev.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/i2c-dev.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <cstring>
#include "fsfw/FSFW.h"
#include "fsfw/serviceinterface.h"
#include "fsfw_hal/linux/UnixFileGuard.h"
#include "fsfw_hal/linux/utility.h"
I2cComIF::I2cComIF(object_id_t objectId): SystemObject(objectId){
}
I2cComIF::I2cComIF(object_id_t objectId) : SystemObject(objectId) {}
I2cComIF::~I2cComIF() {}
ReturnValue_t I2cComIF::initializeInterface(CookieIF* cookie) {
address_t i2cAddress;
std::string deviceFile;
if(cookie == nullptr) {
if (cookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "I2cComIF::initializeInterface: Invalid cookie!" << std::endl;
#endif
return NULLPOINTER;
}
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
if(i2cCookie == nullptr) {
if (i2cCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "I2cComIF::initializeInterface: Invalid I2C cookie!" << std::endl;
#endif
@ -42,14 +38,15 @@ ReturnValue_t I2cComIF::initializeInterface(CookieIF* cookie) {
i2cAddress = i2cCookie->getAddress();
i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress);
if(i2cDeviceMapIter == i2cDeviceMap.end()) {
if (i2cDeviceMapIter == i2cDeviceMap.end()) {
size_t maxReplyLen = i2cCookie->getMaxReplyLen();
I2cInstance i2cInstance = {std::vector<uint8_t>(maxReplyLen), 0};
auto statusPair = i2cDeviceMap.emplace(i2cAddress, i2cInstance);
if (not statusPair.second) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "I2cComIF::initializeInterface: Failed to insert device with address " <<
i2cAddress << "to I2C device " << "map" << std::endl;
sif::error << "I2cComIF::initializeInterface: Failed to insert device with address "
<< i2cAddress << "to I2C device "
<< "map" << std::endl;
#endif
return HasReturnvaluesIF::RETURN_FAILED;
}
@ -57,33 +54,30 @@ ReturnValue_t I2cComIF::initializeInterface(CookieIF* cookie) {
}
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "I2cComIF::initializeInterface: Device with address " << i2cAddress <<
"already in use" << std::endl;
sif::error << "I2cComIF::initializeInterface: Device with address " << i2cAddress
<< "already in use" << std::endl;
#endif
return HasReturnvaluesIF::RETURN_FAILED;
}
ReturnValue_t I2cComIF::sendMessage(CookieIF *cookie,
const uint8_t *sendData, size_t sendLen) {
ReturnValue_t I2cComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) {
ReturnValue_t result;
int fd;
std::string deviceFile;
if(sendData == nullptr) {
if (sendData == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "I2cComIF::sendMessage: Send Data is nullptr"
<< std::endl;
sif::error << "I2cComIF::sendMessage: Send Data is nullptr" << std::endl;
#endif
return HasReturnvaluesIF::RETURN_FAILED;
}
if(sendLen == 0) {
if (sendLen == 0) {
return HasReturnvaluesIF::RETURN_OK;
}
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
if(i2cCookie == nullptr) {
if (i2cCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "I2cComIF::sendMessage: Invalid I2C Cookie!" << std::endl;
#endif
@ -102,31 +96,28 @@ ReturnValue_t I2cComIF::sendMessage(CookieIF *cookie,
deviceFile = i2cCookie->getDeviceFile();
UnixFileGuard fileHelper(deviceFile, &fd, O_RDWR, "I2cComIF::sendMessage");
if(fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
if (fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
return fileHelper.getOpenResult();
}
result = openDevice(deviceFile, i2cAddress, &fd);
if (result != HasReturnvaluesIF::RETURN_OK){
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if (write(fd, sendData, sendLen) != static_cast<int>(sendLen)) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "I2cComIF::sendMessage: Failed to send data to I2C "
"device with error code " << errno << ". Error description: "
<< strerror(errno) << std::endl;
"device with error code "
<< errno << ". Error description: " << strerror(errno) << std::endl;
#endif
return HasReturnvaluesIF::RETURN_FAILED;
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t I2cComIF::getSendSuccess(CookieIF *cookie) {
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t I2cComIF::getSendSuccess(CookieIF* cookie) { return HasReturnvaluesIF::RETURN_OK; }
ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF *cookie,
size_t requestLen) {
ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLen) {
ReturnValue_t result;
int fd;
std::string deviceFile;
@ -136,7 +127,7 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF *cookie,
}
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
if(i2cCookie == nullptr) {
if (i2cCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "I2cComIF::requestReceiveMessage: Invalid I2C Cookie!" << std::endl;
#endif
@ -157,11 +148,11 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF *cookie,
deviceFile = i2cCookie->getDeviceFile();
UnixFileGuard fileHelper(deviceFile, &fd, O_RDWR, "I2cComIF::requestReceiveMessage");
if(fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
if (fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
return fileHelper.getOpenResult();
}
result = openDevice(deviceFile, i2cAddress, &fd);
if (result != HasReturnvaluesIF::RETURN_OK){
if (result != HasReturnvaluesIF::RETURN_OK) {
i2cDeviceMapIter->second.replyLen = 0;
return result;
}
@ -172,14 +163,15 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF *cookie,
if (readLen != static_cast<int>(requestLen)) {
#if FSFW_VERBOSE_LEVEL >= 1 and FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "I2cComIF::requestReceiveMessage: Reading from I2C "
<< "device failed with error code " << errno <<". Description"
<< "device failed with error code " << errno << ". Description"
<< " of error: " << strerror(errno) << std::endl;
sif::error << "I2cComIF::requestReceiveMessage: Read only " << readLen << " from "
<< requestLen << " bytes" << std::endl;
sif::error << "I2cComIF::requestReceiveMessage: Read only " << readLen << " from " << requestLen
<< " bytes" << std::endl;
#endif
i2cDeviceMapIter->second.replyLen = 0;
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "I2cComIF::requestReceiveMessage: Read " << readLen << " of " << requestLen << " bytes" << std::endl;
sif::debug << "I2cComIF::requestReceiveMessage: Read " << readLen << " of " << requestLen
<< " bytes" << std::endl;
#endif
return HasReturnvaluesIF::RETURN_FAILED;
}
@ -188,10 +180,9 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF *cookie,
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t I2cComIF::readReceivedMessage(CookieIF *cookie,
uint8_t **buffer, size_t* size) {
ReturnValue_t I2cComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) {
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
if(i2cCookie == nullptr) {
if (i2cCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "I2cComIF::readReceivedMessage: Invalid I2C Cookie!" << std::endl;
#endif
@ -213,9 +204,8 @@ ReturnValue_t I2cComIF::readReceivedMessage(CookieIF *cookie,
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t I2cComIF::openDevice(std::string deviceFile,
address_t i2cAddress, int* fileDescriptor) {
ReturnValue_t I2cComIF::openDevice(std::string deviceFile, address_t i2cAddress,
int* fileDescriptor) {
if (ioctl(*fileDescriptor, I2C_SLAVE, i2cAddress) < 0) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1

View File

@ -1,13 +1,14 @@
#ifndef LINUX_I2C_I2COMIF_H_
#define LINUX_I2C_I2COMIF_H_
#include "I2cCookie.h"
#include <fsfw/objectmanager/SystemObject.h>
#include <fsfw/devicehandlers/DeviceCommunicationIF.h>
#include <fsfw/objectmanager/SystemObject.h>
#include <unordered_map>
#include <vector>
#include "I2cCookie.h"
/**
* @brief This is the communication interface for I2C devices connected
* to a system running a Linux OS.
@ -16,23 +17,19 @@
*
* @author J. Meier
*/
class I2cComIF: public DeviceCommunicationIF, public SystemObject {
public:
class I2cComIF : public DeviceCommunicationIF, public SystemObject {
public:
I2cComIF(object_id_t objectId);
virtual ~I2cComIF();
ReturnValue_t initializeInterface(CookieIF * cookie) override;
ReturnValue_t sendMessage(CookieIF *cookie,const uint8_t *sendData,
size_t sendLen) override;
ReturnValue_t initializeInterface(CookieIF *cookie) override;
ReturnValue_t sendMessage(CookieIF *cookie, const uint8_t *sendData, size_t sendLen) override;
ReturnValue_t getSendSuccess(CookieIF *cookie) override;
ReturnValue_t requestReceiveMessage(CookieIF *cookie,
size_t requestLen) override;
ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
size_t *size) override;
private:
ReturnValue_t requestReceiveMessage(CookieIF *cookie, size_t requestLen) override;
ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) override;
private:
struct I2cInstance {
std::vector<uint8_t> replyBuffer;
size_t replyLen;
@ -54,8 +51,7 @@ private:
* @param fileDescriptor Pointer to device descriptor.
* @return RETURN_OK if successful, otherwise RETURN_FAILED.
*/
ReturnValue_t openDevice(std::string deviceFile,
address_t i2cAddress, int* fileDescriptor);
ReturnValue_t openDevice(std::string deviceFile, address_t i2cAddress, int *fileDescriptor);
};
#endif /* LINUX_I2C_I2COMIF_H_ */

View File

@ -1,20 +1,12 @@
#include "fsfw_hal/linux/i2c/I2cCookie.h"
I2cCookie::I2cCookie(address_t i2cAddress_, size_t maxReplyLen_,
std::string deviceFile_) :
i2cAddress(i2cAddress_), maxReplyLen(maxReplyLen_), deviceFile(deviceFile_) {
}
I2cCookie::I2cCookie(address_t i2cAddress_, size_t maxReplyLen_, std::string deviceFile_)
: i2cAddress(i2cAddress_), maxReplyLen(maxReplyLen_), deviceFile(deviceFile_) {}
address_t I2cCookie::getAddress() const {
return i2cAddress;
}
address_t I2cCookie::getAddress() const { return i2cAddress; }
size_t I2cCookie::getMaxReplyLen() const {
return maxReplyLen;
}
size_t I2cCookie::getMaxReplyLen() const { return maxReplyLen; }
std::string I2cCookie::getDeviceFile() const {
return deviceFile;
}
std::string I2cCookie::getDeviceFile() const { return deviceFile; }
I2cCookie::~I2cCookie() {}

View File

@ -2,6 +2,7 @@
#define LINUX_I2C_I2CCOOKIE_H_
#include <fsfw/devicehandlers/CookieIF.h>
#include <string>
/**
@ -9,9 +10,8 @@
*
* @author J. Meier
*/
class I2cCookie: public CookieIF {
public:
class I2cCookie : public CookieIF {
public:
/**
* @brief Constructor for the I2C cookie.
* @param i2cAddress_ The i2c address of the target device.
@ -19,8 +19,7 @@ public:
* target device.
* @param devicFile_ The device file specifying the i2c interface to use. E.g. "/dev/i2c-0".
*/
I2cCookie(address_t i2cAddress_, size_t maxReplyLen_,
std::string deviceFile_);
I2cCookie(address_t i2cAddress_, size_t maxReplyLen_, std::string deviceFile_);
virtual ~I2cCookie();
@ -28,8 +27,7 @@ public:
size_t getMaxReplyLen() const;
std::string getDeviceFile() const;
private:
private:
address_t i2cAddress = 0;
size_t maxReplyLen = 0;
std::string deviceFile;

View File

@ -1,14 +1,14 @@
#include "fsfw/FSFW.h"
#include "fsfw_hal/linux/rpi/GpioRPi.h"
#include "fsfw_hal/common/gpio/GpioCookie.h"
#include <fsfw/serviceinterface/ServiceInterface.h>
#include "fsfw/FSFW.h"
#include "fsfw_hal/common/gpio/GpioCookie.h"
ReturnValue_t gpio::createRpiGpioConfig(GpioCookie* cookie, gpioId_t gpioId, int bcmPin,
std::string consumer, gpio::Direction direction, int initValue) {
if(cookie == nullptr) {
std::string consumer, gpio::Direction direction,
int initValue) {
if (cookie == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED;
}
@ -22,7 +22,7 @@ ReturnValue_t gpio::createRpiGpioConfig(GpioCookie* cookie, gpioId_t gpioId, int
config->initValue = initValue;
/* Sanity check for the BCM pins before assigning it */
if(bcmPin > 27) {
if (bcmPin > 27) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "createRpiGpioConfig: BCM pin " << bcmPin << " invalid!" << std::endl;

View File

@ -2,6 +2,7 @@
#define BSP_RPI_GPIO_GPIORPI_H_
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
#include "../../common/gpio/gpioDefinitions.h"
class GpioCookie;
@ -21,6 +22,6 @@ namespace gpio {
*/
ReturnValue_t createRpiGpioConfig(GpioCookie* cookie, gpioId_t gpioId, int bcmPin,
std::string consumer, gpio::Direction direction, int initValue);
}
} // namespace gpio
#endif /* BSP_RPI_GPIO_GPIORPI_H_ */

View File

@ -1,23 +1,23 @@
#include "fsfw/FSFW.h"
#include "fsfw_hal/linux/spi/SpiComIF.h"
#include "fsfw_hal/linux/spi/SpiCookie.h"
#include "fsfw_hal/linux/utility.h"
#include "fsfw_hal/linux/UnixFileGuard.h"
#include <fsfw/ipc/MutexFactory.h>
#include <fsfw/globalfunctions/arrayprinter.h>
#include <linux/spi/spidev.h>
#include <fcntl.h>
#include <unistd.h>
#include <fsfw/globalfunctions/arrayprinter.h>
#include <fsfw/ipc/MutexFactory.h>
#include <linux/spi/spidev.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <cerrno>
#include <cstring>
SpiComIF::SpiComIF(object_id_t objectId, GpioIF* gpioComIF):
SystemObject(objectId), gpioComIF(gpioComIF) {
if(gpioComIF == nullptr) {
#include "fsfw/FSFW.h"
#include "fsfw_hal/linux/UnixFileGuard.h"
#include "fsfw_hal/linux/spi/SpiCookie.h"
#include "fsfw_hal/linux/utility.h"
SpiComIF::SpiComIF(object_id_t objectId, GpioIF* gpioComIF)
: SystemObject(objectId), gpioComIF(gpioComIF) {
if (gpioComIF == nullptr) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "SpiComIF::SpiComIF: GPIO communication interface invalid!" << std::endl;
@ -30,28 +30,30 @@ SpiComIF::SpiComIF(object_id_t objectId, GpioIF* gpioComIF):
spiMutex = MutexFactory::instance()->createMutex();
}
ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
ReturnValue_t SpiComIF::initializeInterface(CookieIF* cookie) {
int retval = 0;
SpiCookie* spiCookie = dynamic_cast<SpiCookie*>(cookie);
if(spiCookie == nullptr) {
if (spiCookie == nullptr) {
return NULLPOINTER;
}
address_t spiAddress = spiCookie->getSpiAddress();
auto iter = spiDeviceMap.find(spiAddress);
if(iter == spiDeviceMap.end()) {
if (iter == spiDeviceMap.end()) {
size_t bufferSize = spiCookie->getMaxBufferSize();
SpiInstance spiInstance(bufferSize);
auto statusPair = spiDeviceMap.emplace(spiAddress, spiInstance);
if (not statusPair.second) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "SpiComIF::initializeInterface: Failed to insert device with address " <<
spiAddress << "to SPI device map" << std::endl;
sif::error << "SpiComIF::initializeInterface: Failed to insert device with address "
<< spiAddress << "to SPI device map" << std::endl;
#else
sif::printError("SpiComIF::initializeInterface: Failed to insert device with address "
"%lu to SPI device map\n", static_cast<unsigned long>(spiAddress));
sif::printError(
"SpiComIF::initializeInterface: Failed to insert device with address "
"%lu to SPI device map\n",
static_cast<unsigned long>(spiAddress));
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
return HasReturnvaluesIF::RETURN_FAILED;
@ -59,8 +61,7 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
/* Now we emplaced the read buffer in the map, we still need to assign that location
to the SPI driver transfer struct */
spiCookie->assignReadBuffer(statusPair.first->second.replyBuffer.data());
}
else {
} else {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "SpiComIF::initializeInterface: SPI address already exists!" << std::endl;
@ -73,7 +74,7 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
/* Pull CS high in any case to be sure that device is inactive */
gpioId_t gpioId = spiCookie->getChipSelectPin();
if(gpioId != gpio::NO_GPIO) {
if (gpioId != gpio::NO_GPIO) {
gpioComIF->pullHigh(gpioId);
}
@ -86,91 +87,94 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
int fileDescriptor = 0;
UnixFileGuard fileHelper(spiCookie->getSpiDevice(), &fileDescriptor, O_RDWR,
"SpiComIF::initializeInterface");
if(fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
if (fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
return fileHelper.getOpenResult();
}
/* These flags are rather uncommon */
if(params.threeWireSpi or params.noCs or params.csHigh) {
if (params.threeWireSpi or params.noCs or params.csHigh) {
uint32_t currentMode = 0;
retval = ioctl(fileDescriptor, SPI_IOC_RD_MODE32, &currentMode);
if(retval != 0) {
if (retval != 0) {
utility::handleIoctlError("SpiComIF::initialiezInterface: Could not read full mode!");
}
if(params.threeWireSpi) {
if (params.threeWireSpi) {
currentMode |= SPI_3WIRE;
}
if(params.noCs) {
if (params.noCs) {
/* Some drivers like the Raspberry Pi ignore this flag in any case */
currentMode |= SPI_NO_CS;
}
if(params.csHigh) {
if (params.csHigh) {
currentMode |= SPI_CS_HIGH;
}
/* Write adapted mode */
retval = ioctl(fileDescriptor, SPI_IOC_WR_MODE32, &currentMode);
if(retval != 0) {
if (retval != 0) {
utility::handleIoctlError("SpiComIF::initialiezInterface: Could not write full mode!");
}
}
if(params.lsbFirst) {
if (params.lsbFirst) {
retval = ioctl(fileDescriptor, SPI_IOC_WR_LSB_FIRST, &params.lsbFirst);
if(retval != 0) {
if (retval != 0) {
utility::handleIoctlError("SpiComIF::initializeInterface: Setting LSB first failed");
}
}
if(params.bitsPerWord != 8) {
if (params.bitsPerWord != 8) {
retval = ioctl(fileDescriptor, SPI_IOC_WR_BITS_PER_WORD, &params.bitsPerWord);
if(retval != 0) {
utility::handleIoctlError("SpiComIF::initializeInterface: "
if (retval != 0) {
utility::handleIoctlError(
"SpiComIF::initializeInterface: "
"Could not write bits per word!");
}
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, size_t sendLen) {
ReturnValue_t SpiComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) {
SpiCookie* spiCookie = dynamic_cast<SpiCookie*>(cookie);
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
if(spiCookie == nullptr) {
if (spiCookie == nullptr) {
return NULLPOINTER;
}
if(sendLen > spiCookie->getMaxBufferSize()) {
if (sendLen > spiCookie->getMaxBufferSize()) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "SpiComIF::sendMessage: Too much data sent, send length " << sendLen <<
"larger than maximum buffer length " << spiCookie->getMaxBufferSize() << std::endl;
sif::warning << "SpiComIF::sendMessage: Too much data sent, send length " << sendLen
<< "larger than maximum buffer length " << spiCookie->getMaxBufferSize()
<< std::endl;
#else
sif::printWarning("SpiComIF::sendMessage: Too much data sent, send length %lu larger "
"than maximum buffer length %lu!\n", static_cast<unsigned long>(sendLen),
sif::printWarning(
"SpiComIF::sendMessage: Too much data sent, send length %lu larger "
"than maximum buffer length %lu!\n",
static_cast<unsigned long>(sendLen),
static_cast<unsigned long>(spiCookie->getMaxBufferSize()));
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
return DeviceCommunicationIF::TOO_MUCH_DATA;
}
if(spiCookie->getComIfMode() == spi::SpiComIfModes::REGULAR) {
if (spiCookie->getComIfMode() == spi::SpiComIfModes::REGULAR) {
result = performRegularSendOperation(spiCookie, sendData, sendLen);
}
else if(spiCookie->getComIfMode() == spi::SpiComIfModes::CALLBACK) {
} else if (spiCookie->getComIfMode() == spi::SpiComIfModes::CALLBACK) {
spi::send_callback_function_t sendFunc = nullptr;
void* funcArgs = nullptr;
spiCookie->getCallback(&sendFunc, &funcArgs);
if(sendFunc != nullptr) {
if (sendFunc != nullptr) {
result = sendFunc(this, spiCookie, sendData, sendLen, funcArgs);
}
}
return result;
}
ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie *spiCookie, const uint8_t *sendData,
ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie* spiCookie, const uint8_t* sendData,
size_t sendLen) {
address_t spiAddress = spiCookie->getSpiAddress();
auto iter = spiDeviceMap.find(spiAddress);
if(iter != spiDeviceMap.end()) {
if (iter != spiDeviceMap.end()) {
spiCookie->assignReadBuffer(iter->second.replyBuffer.data());
}
@ -180,7 +184,7 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie *spiCookie, const
int fileDescriptor = 0;
std::string device = spiCookie->getSpiDevice();
UnixFileGuard fileHelper(device, &fileDescriptor, O_RDWR, "SpiComIF::sendMessage");
if(fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
if (fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
return OPENING_FILE_FAILED;
}
spi::SpiModes spiMode = spi::SpiModes::MODE_0;
@ -194,7 +198,7 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie *spiCookie, const
gpioId_t gpioId = spiCookie->getChipSelectPin();
/* Pull SPI CS low. For now, no support for active high given */
if(gpioId != gpio::NO_GPIO) {
if (gpioId != gpio::NO_GPIO) {
result = spiMutex->lockMutex(timeoutType, timeoutMs);
if (result != RETURN_OK) {
#if FSFW_VERBOSE_LEVEL >= 1
@ -207,7 +211,7 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie *spiCookie, const
return result;
}
ReturnValue_t result = gpioComIF->pullLow(gpioId);
if(result != HasReturnvaluesIF::RETURN_OK) {
if (result != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "SpiComIF::sendMessage: Pulling low CS pin failed" << std::endl;
@ -220,24 +224,22 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie *spiCookie, const
}
/* Execute transfer */
if(fullDuplex) {
if (fullDuplex) {
/* Initiate a full duplex SPI transfer. */
retval = ioctl(fileDescriptor, SPI_IOC_MESSAGE(1), spiCookie->getTransferStructHandle());
if(retval < 0) {
if (retval < 0) {
utility::handleIoctlError("SpiComIF::sendMessage: ioctl error.");
result = FULL_DUPLEX_TRANSFER_FAILED;
}
#if FSFW_HAL_SPI_WIRETAPPING == 1
performSpiWiretapping(spiCookie);
#endif /* FSFW_LINUX_SPI_WIRETAPPING == 1 */
}
else {
} else {
/* We write with a blocking half-duplex transfer here */
if (write(fileDescriptor, sendData, sendLen) != static_cast<ssize_t>(sendLen)) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "SpiComIF::sendMessage: Half-Duplex write operation failed!" <<
std::endl;
sif::warning << "SpiComIF::sendMessage: Half-Duplex write operation failed!" << std::endl;
#else
sif::printWarning("SpiComIF::sendMessage: Half-Duplex write operation failed!\n");
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
@ -246,7 +248,7 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie *spiCookie, const
}
}
if(gpioId != gpio::NO_GPIO) {
if (gpioId != gpio::NO_GPIO) {
gpioComIF->pullHigh(gpioId);
result = spiMutex->unlockMutex();
if (result != RETURN_OK) {
@ -259,43 +261,39 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie *spiCookie, const
return result;
}
ReturnValue_t SpiComIF::getSendSuccess(CookieIF *cookie) {
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t SpiComIF::getSendSuccess(CookieIF* cookie) { return HasReturnvaluesIF::RETURN_OK; }
ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF *cookie, size_t requestLen) {
ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLen) {
SpiCookie* spiCookie = dynamic_cast<SpiCookie*>(cookie);
if(spiCookie == nullptr) {
if (spiCookie == nullptr) {
return NULLPOINTER;
}
if(spiCookie->isFullDuplex()) {
if (spiCookie->isFullDuplex()) {
return HasReturnvaluesIF::RETURN_OK;
}
return performHalfDuplexReception(spiCookie);
}
ReturnValue_t SpiComIF::performHalfDuplexReception(SpiCookie* spiCookie) {
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
std::string device = spiCookie->getSpiDevice();
int fileDescriptor = 0;
UnixFileGuard fileHelper(device, &fileDescriptor, O_RDWR,
"SpiComIF::requestReceiveMessage");
if(fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
UnixFileGuard fileHelper(device, &fileDescriptor, O_RDWR, "SpiComIF::requestReceiveMessage");
if (fileHelper.getOpenResult() != HasReturnvaluesIF::RETURN_OK) {
return OPENING_FILE_FAILED;
}
uint8_t* rxBuf = nullptr;
size_t readSize = spiCookie->getCurrentTransferSize();
result = getReadBuffer(spiCookie->getSpiAddress(), &rxBuf);
if(result != HasReturnvaluesIF::RETURN_OK) {
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
gpioId_t gpioId = spiCookie->getChipSelectPin();
if(gpioId != gpio::NO_GPIO) {
if (gpioId != gpio::NO_GPIO) {
result = spiMutex->lockMutex(timeoutType, timeoutMs);
if (result != RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
@ -306,7 +304,7 @@ ReturnValue_t SpiComIF::performHalfDuplexReception(SpiCookie* spiCookie) {
gpioComIF->pullLow(gpioId);
}
if(read(fileDescriptor, rxBuf, readSize) != static_cast<ssize_t>(readSize)) {
if (read(fileDescriptor, rxBuf, readSize) != static_cast<ssize_t>(readSize)) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "SpiComIF::sendMessage: Half-Duplex read operation failed!" << std::endl;
@ -317,7 +315,7 @@ ReturnValue_t SpiComIF::performHalfDuplexReception(SpiCookie* spiCookie) {
result = HALF_DUPLEX_TRANSFER_FAILED;
}
if(gpioId != gpio::NO_GPIO) {
if (gpioId != gpio::NO_GPIO) {
gpioComIF->pullHigh(gpioId);
result = spiMutex->unlockMutex();
if (result != RETURN_OK) {
@ -331,14 +329,14 @@ ReturnValue_t SpiComIF::performHalfDuplexReception(SpiCookie* spiCookie) {
return result;
}
ReturnValue_t SpiComIF::readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) {
ReturnValue_t SpiComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) {
SpiCookie* spiCookie = dynamic_cast<SpiCookie*>(cookie);
if(spiCookie == nullptr) {
if (spiCookie == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED;
}
uint8_t* rxBuf = nullptr;
ReturnValue_t result = getReadBuffer(spiCookie->getSpiAddress(), &rxBuf);
if(result != HasReturnvaluesIF::RETURN_OK) {
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
@ -349,17 +347,17 @@ ReturnValue_t SpiComIF::readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
}
MutexIF* SpiComIF::getMutex(MutexIF::TimeoutType* timeoutType, uint32_t* timeoutMs) {
if(timeoutType != nullptr) {
if (timeoutType != nullptr) {
*timeoutType = this->timeoutType;
}
if(timeoutMs != nullptr) {
if (timeoutMs != nullptr) {
*timeoutMs = this->timeoutMs;
}
return spiMutex;
}
void SpiComIF::performSpiWiretapping(SpiCookie* spiCookie) {
if(spiCookie == nullptr) {
if (spiCookie == nullptr) {
return;
}
size_t dataLen = spiCookie->getTransferStructHandle()->len;
@ -378,12 +376,12 @@ void SpiComIF::performSpiWiretapping(SpiCookie* spiCookie) {
}
ReturnValue_t SpiComIF::getReadBuffer(address_t spiAddress, uint8_t** buffer) {
if(buffer == nullptr) {
if (buffer == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED;
}
auto iter = spiDeviceMap.find(spiAddress);
if(iter == spiDeviceMap.end()) {
if (iter == spiDeviceMap.end()) {
return HasReturnvaluesIF::RETURN_FAILED;
}
@ -391,18 +389,16 @@ ReturnValue_t SpiComIF::getReadBuffer(address_t spiAddress, uint8_t** buffer) {
return HasReturnvaluesIF::RETURN_OK;
}
GpioIF* SpiComIF::getGpioInterface() {
return gpioComIF;
}
GpioIF* SpiComIF::getGpioInterface() { return gpioComIF; }
void SpiComIF::setSpiSpeedAndMode(int spiFd, spi::SpiModes mode, uint32_t speed) {
int retval = ioctl(spiFd, SPI_IOC_WR_MODE, reinterpret_cast<uint8_t*>(&mode));
if(retval != 0) {
if (retval != 0) {
utility::handleIoctlError("SpiComIF::setSpiSpeedAndMode: Setting SPI mode failed");
}
retval = ioctl(spiFd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
if(retval != 0) {
if (retval != 0) {
utility::handleIoctlError("SpiComIF::setSpiSpeedAndMode: Setting SPI speed failed");
}
}

View File

@ -1,16 +1,15 @@
#ifndef LINUX_SPI_SPICOMIF_H_
#define LINUX_SPI_SPICOMIF_H_
#include "fsfw/FSFW.h"
#include "spiDefinitions.h"
#include "returnvalues/classIds.h"
#include "fsfw_hal/common/gpio/GpioIF.h"
#include <unordered_map>
#include <vector>
#include "fsfw/FSFW.h"
#include "fsfw/devicehandlers/DeviceCommunicationIF.h"
#include "fsfw/objectmanager/SystemObject.h"
#include <vector>
#include <unordered_map>
#include "fsfw_hal/common/gpio/GpioIF.h"
#include "returnvalues/classIds.h"
#include "spiDefinitions.h"
class SpiCookie;
@ -21,8 +20,8 @@ class SpiCookie;
* are contained in the SPI cookie.
* @author R. Mueller
*/
class SpiComIF: public DeviceCommunicationIF, public SystemObject {
public:
class SpiComIF : public DeviceCommunicationIF, public SystemObject {
public:
static constexpr uint8_t spiRetvalId = CLASS_ID::HAL_SPI;
static constexpr ReturnValue_t OPENING_FILE_FAILED =
HasReturnvaluesIF::makeReturnCode(spiRetvalId, 0);
@ -35,14 +34,11 @@ public:
SpiComIF(object_id_t objectId, GpioIF* gpioComIF);
ReturnValue_t initializeInterface(CookieIF * cookie) override;
ReturnValue_t sendMessage(CookieIF *cookie,const uint8_t *sendData,
size_t sendLen) override;
ReturnValue_t getSendSuccess(CookieIF *cookie) override;
ReturnValue_t requestReceiveMessage(CookieIF *cookie,
size_t requestLen) override;
ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
size_t *size) override;
ReturnValue_t initializeInterface(CookieIF* cookie) override;
ReturnValue_t sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) override;
ReturnValue_t getSendSuccess(CookieIF* cookie) override;
ReturnValue_t requestReceiveMessage(CookieIF* cookie, size_t requestLen) override;
ReturnValue_t readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) override;
/**
* @brief This function returns the mutex which can be used to protect the spi bus when
@ -58,7 +54,7 @@ public:
* @param sendLen
* @return
*/
ReturnValue_t performRegularSendOperation(SpiCookie* spiCookie, const uint8_t *sendData,
ReturnValue_t performRegularSendOperation(SpiCookie* spiCookie, const uint8_t* sendData,
size_t sendLen);
GpioIF* getGpioInterface();
@ -67,10 +63,9 @@ public:
ReturnValue_t getReadBuffer(address_t spiAddress, uint8_t** buffer);
private:
private:
struct SpiInstance {
SpiInstance(size_t maxRecvSize): replyBuffer(std::vector<uint8_t>(maxRecvSize)) {}
SpiInstance(size_t maxRecvSize) : replyBuffer(std::vector<uint8_t>(maxRecvSize)) {}
std::vector<uint8_t> replyBuffer;
};

View File

@ -1,42 +1,41 @@
#include "fsfw_hal/linux/spi/SpiCookie.h"
SpiCookie::SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev,
const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed):
SpiCookie(spi::SpiComIfModes::REGULAR, spiAddress, chipSelect, spiDev, maxSize, spiMode,
spiSpeed, nullptr, nullptr) {
}
const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed)
: SpiCookie(spi::SpiComIfModes::REGULAR, spiAddress, chipSelect, spiDev, maxSize, spiMode,
spiSpeed, nullptr, nullptr) {}
SpiCookie::SpiCookie(address_t spiAddress, std::string spiDev, const size_t maxSize,
spi::SpiModes spiMode, uint32_t spiSpeed):
SpiCookie(spiAddress, gpio::NO_GPIO, spiDev, maxSize, spiMode, spiSpeed) {
}
spi::SpiModes spiMode, uint32_t spiSpeed)
: SpiCookie(spiAddress, gpio::NO_GPIO, spiDev, maxSize, spiMode, spiSpeed) {}
SpiCookie::SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev,
const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed,
spi::send_callback_function_t callback, void *args):
SpiCookie(spi::SpiComIfModes::CALLBACK, spiAddress, chipSelect, spiDev, maxSize,
spiMode, spiSpeed, callback, args) {
}
spi::send_callback_function_t callback, void* args)
: SpiCookie(spi::SpiComIfModes::CALLBACK, spiAddress, chipSelect, spiDev, maxSize, spiMode,
spiSpeed, callback, args) {}
SpiCookie::SpiCookie(spi::SpiComIfModes comIfMode, address_t spiAddress, gpioId_t chipSelect,
std::string spiDev, const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed,
spi::send_callback_function_t callback, void* args):
spiAddress(spiAddress), chipSelectPin(chipSelect), spiDevice(spiDev),
comIfMode(comIfMode), maxSize(maxSize), spiMode(spiMode), spiSpeed(spiSpeed),
sendCallback(callback), callbackArgs(args) {
}
std::string spiDev, const size_t maxSize, spi::SpiModes spiMode,
uint32_t spiSpeed, spi::send_callback_function_t callback, void* args)
: spiAddress(spiAddress),
chipSelectPin(chipSelect),
spiDevice(spiDev),
comIfMode(comIfMode),
maxSize(maxSize),
spiMode(spiMode),
spiSpeed(spiSpeed),
sendCallback(callback),
callbackArgs(args) {}
spi::SpiComIfModes SpiCookie::getComIfMode() const {
return this->comIfMode;
}
spi::SpiComIfModes SpiCookie::getComIfMode() const { return this->comIfMode; }
void SpiCookie::getSpiParameters(spi::SpiModes& spiMode, uint32_t& spiSpeed,
UncommonParameters* parameters) const {
spiMode = this->spiMode;
spiSpeed = this->spiSpeed;
if(parameters != nullptr) {
if (parameters != nullptr) {
parameters->threeWireSpi = uncommonParameters.threeWireSpi;
parameters->lsbFirst = uncommonParameters.lsbFirst;
parameters->noCs = uncommonParameters.noCs;
@ -45,41 +44,25 @@ void SpiCookie::getSpiParameters(spi::SpiModes& spiMode, uint32_t& spiSpeed,
}
}
gpioId_t SpiCookie::getChipSelectPin() const {
return chipSelectPin;
}
gpioId_t SpiCookie::getChipSelectPin() const { return chipSelectPin; }
size_t SpiCookie::getMaxBufferSize() const {
return maxSize;
}
size_t SpiCookie::getMaxBufferSize() const { return maxSize; }
address_t SpiCookie::getSpiAddress() const {
return spiAddress;
}
address_t SpiCookie::getSpiAddress() const { return spiAddress; }
std::string SpiCookie::getSpiDevice() const {
return spiDevice;
}
std::string SpiCookie::getSpiDevice() const { return spiDevice; }
void SpiCookie::setThreeWireSpi(bool enable) {
uncommonParameters.threeWireSpi = enable;
}
void SpiCookie::setThreeWireSpi(bool enable) { uncommonParameters.threeWireSpi = enable; }
void SpiCookie::setLsbFirst(bool enable) {
uncommonParameters.lsbFirst = enable;
}
void SpiCookie::setLsbFirst(bool enable) { uncommonParameters.lsbFirst = enable; }
void SpiCookie::setNoCs(bool enable) {
uncommonParameters.noCs = enable;
}
void SpiCookie::setNoCs(bool enable) { uncommonParameters.noCs = enable; }
void SpiCookie::setBitsPerWord(uint8_t bitsPerWord) {
uncommonParameters.bitsPerWord = bitsPerWord;
}
void SpiCookie::setCsHigh(bool enable) {
uncommonParameters.csHigh = enable;
}
void SpiCookie::setCsHigh(bool enable) { uncommonParameters.csHigh = enable; }
void SpiCookie::activateCsDeselect(bool deselectCs, uint16_t delayUsecs) {
spiTransferStruct.cs_change = deselectCs;
@ -87,58 +70,40 @@ void SpiCookie::activateCsDeselect(bool deselectCs, uint16_t delayUsecs) {
}
void SpiCookie::assignReadBuffer(uint8_t* rx) {
if(rx != nullptr) {
if (rx != nullptr) {
spiTransferStruct.rx_buf = reinterpret_cast<__u64>(rx);
}
}
void SpiCookie::assignWriteBuffer(const uint8_t* tx) {
if(tx != nullptr) {
if (tx != nullptr) {
spiTransferStruct.tx_buf = reinterpret_cast<__u64>(tx);
}
}
void SpiCookie::setCallbackMode(spi::send_callback_function_t callback,
void *args) {
void SpiCookie::setCallbackMode(spi::send_callback_function_t callback, void* args) {
this->comIfMode = spi::SpiComIfModes::CALLBACK;
this->sendCallback = callback;
this->callbackArgs = args;
}
void SpiCookie::setCallbackArgs(void *args) {
this->callbackArgs = args;
}
void SpiCookie::setCallbackArgs(void* args) { this->callbackArgs = args; }
spi_ioc_transfer* SpiCookie::getTransferStructHandle() {
return &spiTransferStruct;
}
spi_ioc_transfer* SpiCookie::getTransferStructHandle() { return &spiTransferStruct; }
void SpiCookie::setFullOrHalfDuplex(bool halfDuplex) {
this->halfDuplex = halfDuplex;
}
void SpiCookie::setFullOrHalfDuplex(bool halfDuplex) { this->halfDuplex = halfDuplex; }
bool SpiCookie::isFullDuplex() const {
return not this->halfDuplex;
}
bool SpiCookie::isFullDuplex() const { return not this->halfDuplex; }
void SpiCookie::setTransferSize(size_t transferSize) {
spiTransferStruct.len = transferSize;
}
void SpiCookie::setTransferSize(size_t transferSize) { spiTransferStruct.len = transferSize; }
size_t SpiCookie::getCurrentTransferSize() const {
return spiTransferStruct.len;
}
size_t SpiCookie::getCurrentTransferSize() const { return spiTransferStruct.len; }
void SpiCookie::setSpiSpeed(uint32_t newSpeed) {
this->spiSpeed = newSpeed;
}
void SpiCookie::setSpiSpeed(uint32_t newSpeed) { this->spiSpeed = newSpeed; }
void SpiCookie::setSpiMode(spi::SpiModes newMode) {
this->spiMode = newMode;
}
void SpiCookie::setSpiMode(spi::SpiModes newMode) { this->spiMode = newMode; }
void SpiCookie::getCallback(spi::send_callback_function_t *callback,
void **args) {
void SpiCookie::getCallback(spi::send_callback_function_t* callback, void** args) {
*callback = this->sendCallback;
*args = this->callbackArgs;
}

View File

@ -1,13 +1,12 @@
#ifndef LINUX_SPI_SPICOOKIE_H_
#define LINUX_SPI_SPICOOKIE_H_
#include "spiDefinitions.h"
#include "../../common/gpio/gpioDefinitions.h"
#include <fsfw/devicehandlers/CookieIF.h>
#include <linux/spi/spidev.h>
#include "../../common/gpio/gpioDefinitions.h"
#include "spiDefinitions.h"
/**
* @brief This cookie class is passed to the SPI communication interface
* @details
@ -19,8 +18,8 @@
* special requirements like expander slave select switching (e.g. GPIO or I2C expander)
* or special timing related requirements.
*/
class SpiCookie: public CookieIF {
public:
class SpiCookie : public CookieIF {
public:
/**
* Each SPI device will have a corresponding cookie. The cookie is used by the communication
* interface and contains device specific information like the largest expected size to be
@ -30,8 +29,8 @@ public:
* @param spiDev
* @param maxSize
*/
SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev,
const size_t maxSize, spi::SpiModes spiMode, uint32_t spiSpeed);
SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev, const size_t maxSize,
spi::SpiModes spiMode, uint32_t spiSpeed);
/**
* Like constructor above, but without a dedicated GPIO CS. Can be used for hardware
@ -46,7 +45,7 @@ public:
*/
SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev, const size_t maxSize,
spi::SpiModes spiMode, uint32_t spiSpeed, spi::send_callback_function_t callback,
void *args);
void* args);
/**
* Get the callback function
@ -141,8 +140,8 @@ public:
void activateCsDeselect(bool deselectCs, uint16_t delayUsecs);
spi_ioc_transfer* getTransferStructHandle();
private:
private:
/**
* Internal constructor which initializes every field
* @param spiAddress
@ -178,6 +177,4 @@ private:
UncommonParameters uncommonParameters;
};
#endif /* LINUX_SPI_SPICOOKIE_H_ */

View File

@ -1,28 +1,25 @@
#ifndef LINUX_SPI_SPIDEFINITONS_H_
#define LINUX_SPI_SPIDEFINITONS_H_
#include "../../common/gpio/gpioDefinitions.h"
#include "../../common/spi/spiCommon.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include <linux/spi/spidev.h>
#include <cstdint>
#include "../../common/gpio/gpioDefinitions.h"
#include "../../common/spi/spiCommon.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
class SpiCookie;
class SpiComIF;
namespace spi {
enum SpiComIfModes {
REGULAR,
CALLBACK
};
enum SpiComIfModes { REGULAR, CALLBACK };
using send_callback_function_t = ReturnValue_t (*)(SpiComIF* comIf, SpiCookie* cookie,
const uint8_t* sendData, size_t sendLen,
void* args);
using send_callback_function_t = ReturnValue_t (*) (SpiComIF* comIf, SpiCookie *cookie,
const uint8_t *sendData, size_t sendLen, void* args);
}
} // namespace spi
#endif /* LINUX_SPI_SPIDEFINITONS_H_ */

View File

@ -1,26 +1,25 @@
#include "UartComIF.h"
#include "fsfw/FSFW.h"
#include "fsfw_hal/linux/utility.h"
#include "fsfw/serviceinterface.h"
#include <cstring>
#include <fcntl.h>
#include <errno.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
UartComIF::UartComIF(object_id_t objectId): SystemObject(objectId){
}
#include <cstring>
#include "fsfw/FSFW.h"
#include "fsfw/serviceinterface.h"
#include "fsfw_hal/linux/utility.h"
UartComIF::UartComIF(object_id_t objectId) : SystemObject(objectId) {}
UartComIF::~UartComIF() {}
ReturnValue_t UartComIF::initializeInterface(CookieIF* cookie) {
std::string deviceFile;
UartDeviceMapIter uartDeviceMapIter;
if(cookie == nullptr) {
if (cookie == nullptr) {
return NULLPOINTER;
}
@ -35,7 +34,7 @@ ReturnValue_t UartComIF::initializeInterface(CookieIF* cookie) {
deviceFile = uartCookie->getDeviceFile();
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
if(uartDeviceMapIter == uartDeviceMap.end()) {
if (uartDeviceMapIter == uartDeviceMap.end()) {
int fileDescriptor = configureUartPort(uartCookie);
if (fileDescriptor < 0) {
return RETURN_FAILED;
@ -45,16 +44,15 @@ ReturnValue_t UartComIF::initializeInterface(CookieIF* cookie) {
auto status = uartDeviceMap.emplace(deviceFile, uartElements);
if (status.second == false) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::initializeInterface: Failed to insert device " <<
deviceFile << "to UART device map" << std::endl;
sif::warning << "UartComIF::initializeInterface: Failed to insert device " << deviceFile
<< "to UART device map" << std::endl;
#endif
return RETURN_FAILED;
}
}
else {
} else {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::initializeInterface: UART device " << deviceFile <<
" already in use" << std::endl;
sif::warning << "UartComIF::initializeInterface: UART device " << deviceFile
<< " already in use" << std::endl;
#endif
return RETURN_FAILED;
}
@ -63,12 +61,11 @@ ReturnValue_t UartComIF::initializeInterface(CookieIF* cookie) {
}
int UartComIF::configureUartPort(UartCookie* uartCookie) {
struct termios options = {};
std::string deviceFile = uartCookie->getDeviceFile();
int flags = O_RDWR;
if(uartCookie->getUartMode() == UartModes::CANONICAL) {
if (uartCookie->getUartMode() == UartModes::CANONICAL) {
// In non-canonical mode, don't specify O_NONBLOCK because these properties will be
// controlled by the VTIME and VMIN parameters and O_NONBLOCK would override this
flags |= O_NONBLOCK;
@ -77,17 +74,17 @@ int UartComIF::configureUartPort(UartCookie* uartCookie) {
if (fd < 0) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::configureUartPort: Failed to open uart " << deviceFile <<
"with error code " << errno << strerror(errno) << std::endl;
sif::warning << "UartComIF::configureUartPort: Failed to open uart " << deviceFile
<< "with error code " << errno << strerror(errno) << std::endl;
#endif
return fd;
}
/* Read in existing settings */
if(tcgetattr(fd, &options) != 0) {
if (tcgetattr(fd, &options) != 0) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::configureUartPort: Error " << errno << "from tcgetattr: "
<< strerror(errno) << std::endl;
sif::warning << "UartComIF::configureUartPort: Error " << errno
<< "from tcgetattr: " << strerror(errno) << std::endl;
#endif
return fd;
}
@ -97,7 +94,7 @@ int UartComIF::configureUartPort(UartCookie* uartCookie) {
setDatasizeOptions(&options, uartCookie);
setFixedOptions(&options);
setUartMode(&options, *uartCookie);
if(uartCookie->getInputShouldBeFlushed()) {
if (uartCookie->getInputShouldBeFlushed()) {
tcflush(fd, TCIFLUSH);
}
@ -110,8 +107,8 @@ int UartComIF::configureUartPort(UartCookie* uartCookie) {
/* Save option settings */
if (tcsetattr(fd, TCSANOW, &options) != 0) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::configureUartPort: Failed to set options with error " <<
errno << ": " << strerror(errno);
sif::warning << "UartComIF::configureUartPort: Failed to set options with error " << errno
<< ": " << strerror(errno);
#endif
return fd;
}
@ -187,7 +184,7 @@ void UartComIF::setFixedOptions(struct termios* options) {
/* Turn off s/w flow ctrl */
options->c_iflag &= ~(IXON | IXOFF | IXANY);
/* Disable any special handling of received bytes */
options->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL);
options->c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL);
/* Prevent special interpretation of output bytes (e.g. newline chars) */
options->c_oflag &= ~OPOST;
/* Prevent conversion of newline to carriage return/line feed */
@ -280,17 +277,16 @@ void UartComIF::configureBaudrate(struct termios* options, UartCookie* uartCooki
}
}
ReturnValue_t UartComIF::sendMessage(CookieIF *cookie,
const uint8_t *sendData, size_t sendLen) {
ReturnValue_t UartComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) {
int fd = 0;
std::string deviceFile;
UartDeviceMapIter uartDeviceMapIter;
if(sendLen == 0) {
if (sendLen == 0) {
return RETURN_OK;
}
if(sendData == nullptr) {
if (sendData == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::sendMessage: Send data is nullptr" << std::endl;
#endif
@ -298,7 +294,7 @@ ReturnValue_t UartComIF::sendMessage(CookieIF *cookie,
}
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
if(uartCookie == nullptr) {
if (uartCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::sendMessasge: Invalid UART Cookie!" << std::endl;
#endif
@ -309,8 +305,8 @@ ReturnValue_t UartComIF::sendMessage(CookieIF *cookie,
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
if (uartDeviceMapIter == uartDeviceMap.end()) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "UartComIF::sendMessage: Device file " << deviceFile <<
"not in UART map" << std::endl;
sif::debug << "UartComIF::sendMessage: Device file " << deviceFile << "not in UART map"
<< std::endl;
#endif
return RETURN_FAILED;
}
@ -319,8 +315,8 @@ ReturnValue_t UartComIF::sendMessage(CookieIF *cookie,
if (write(fd, sendData, sendLen) != static_cast<int>(sendLen)) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "UartComIF::sendMessage: Failed to send data with error code " <<
errno << ": Error description: " << strerror(errno) << std::endl;
sif::error << "UartComIF::sendMessage: Failed to send data with error code " << errno
<< ": Error description: " << strerror(errno) << std::endl;
#endif
return RETURN_FAILED;
}
@ -328,16 +324,14 @@ ReturnValue_t UartComIF::sendMessage(CookieIF *cookie,
return RETURN_OK;
}
ReturnValue_t UartComIF::getSendSuccess(CookieIF *cookie) {
return RETURN_OK;
}
ReturnValue_t UartComIF::getSendSuccess(CookieIF* cookie) { return RETURN_OK; }
ReturnValue_t UartComIF::requestReceiveMessage(CookieIF *cookie, size_t requestLen) {
ReturnValue_t UartComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLen) {
std::string deviceFile;
UartDeviceMapIter uartDeviceMapIter;
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
if(uartCookie == nullptr) {
if (uartCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "UartComIF::requestReceiveMessage: Invalid Uart Cookie!" << std::endl;
#endif
@ -348,7 +342,7 @@ ReturnValue_t UartComIF::requestReceiveMessage(CookieIF *cookie, size_t requestL
deviceFile = uartCookie->getDeviceFile();
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
if(uartMode == UartModes::NON_CANONICAL and requestLen == 0) {
if (uartMode == UartModes::NON_CANONICAL and requestLen == 0) {
return RETURN_OK;
}
@ -362,11 +356,9 @@ ReturnValue_t UartComIF::requestReceiveMessage(CookieIF *cookie, size_t requestL
if (uartMode == UartModes::CANONICAL) {
return handleCanonicalRead(*uartCookie, uartDeviceMapIter, requestLen);
}
else if (uartMode == UartModes::NON_CANONICAL) {
} else if (uartMode == UartModes::NON_CANONICAL) {
return handleNoncanonicalRead(*uartCookie, uartDeviceMapIter, requestLen);
}
else {
} else {
return HasReturnvaluesIF::RETURN_FAILED;
}
}
@ -384,7 +376,7 @@ ReturnValue_t UartComIF::handleCanonicalRead(UartCookie& uartCookie, UartDeviceM
iter->second.replyLen = 0;
do {
size_t allowedReadSize = 0;
if(currentBytesRead >= maxReplySize) {
if (currentBytesRead >= maxReplySize) {
// Overflow risk. Emit warning, trigger event and break. If this happens,
// the reception buffer is not large enough or data is not polled often enough.
#if FSFW_VERBOSE_LEVEL >= 1
@ -392,56 +384,56 @@ ReturnValue_t UartComIF::handleCanonicalRead(UartCookie& uartCookie, UartDeviceM
sif::warning << "UartComIF::requestReceiveMessage: Next read would cause overflow!"
<< std::endl;
#else
sif::printWarning("UartComIF::requestReceiveMessage: "
sif::printWarning(
"UartComIF::requestReceiveMessage: "
"Next read would cause overflow!");
#endif
#endif
result = UART_RX_BUFFER_TOO_SMALL;
break;
}
else {
} else {
allowedReadSize = maxReplySize - currentBytesRead;
}
bytesRead = read(fd, bufferPtr, allowedReadSize);
if (bytesRead < 0) {
// EAGAIN: No data available in non-blocking mode
if(errno != EAGAIN) {
if (errno != EAGAIN) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::handleCanonicalRead: read failed with code" <<
errno << ": " << strerror(errno) << std::endl;
sif::warning << "UartComIF::handleCanonicalRead: read failed with code" << errno << ": "
<< strerror(errno) << std::endl;
#else
sif::printWarning("UartComIF::handleCanonicalRead: read failed with code %d: %s\n",
errno, strerror(errno));
sif::printWarning("UartComIF::handleCanonicalRead: read failed with code %d: %s\n", errno,
strerror(errno));
#endif
#endif
return RETURN_FAILED;
}
}
else if(bytesRead > 0) {
} else if (bytesRead > 0) {
iter->second.replyLen += bytesRead;
bufferPtr += bytesRead;
currentBytesRead += bytesRead;
}
currentReadCycles++;
} while(bytesRead > 0 and currentReadCycles < maxReadCycles);
} while (bytesRead > 0 and currentReadCycles < maxReadCycles);
return result;
}
ReturnValue_t UartComIF::handleNoncanonicalRead(UartCookie &uartCookie, UartDeviceMapIter &iter,
ReturnValue_t UartComIF::handleNoncanonicalRead(UartCookie& uartCookie, UartDeviceMapIter& iter,
size_t requestLen) {
int fd = iter->second.fileDescriptor;
auto bufferPtr = iter->second.replyBuffer.data();
// Size check to prevent buffer overflow
if(requestLen > uartCookie.getMaxReplyLen()) {
if (requestLen > uartCookie.getMaxReplyLen()) {
#if OBSW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::requestReceiveMessage: Next read would cause overflow!"
<< std::endl;
#else
sif::printWarning("UartComIF::requestReceiveMessage: "
sif::printWarning(
"UartComIF::requestReceiveMessage: "
"Next read would cause overflow!");
#endif
#endif
@ -450,12 +442,11 @@ ReturnValue_t UartComIF::handleNoncanonicalRead(UartCookie &uartCookie, UartDevi
int bytesRead = read(fd, bufferPtr, requestLen);
if (bytesRead < 0) {
return RETURN_FAILED;
}
else if (bytesRead != static_cast<int>(requestLen)) {
if(uartCookie.isReplySizeFixed()) {
} else if (bytesRead != static_cast<int>(requestLen)) {
if (uartCookie.isReplySizeFixed()) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::requestReceiveMessage: Only read " << bytesRead <<
" of " << requestLen << " bytes" << std::endl;
sif::warning << "UartComIF::requestReceiveMessage: Only read " << bytesRead << " of "
<< requestLen << " bytes" << std::endl;
#endif
return RETURN_FAILED;
}
@ -464,14 +455,12 @@ ReturnValue_t UartComIF::handleNoncanonicalRead(UartCookie &uartCookie, UartDevi
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t UartComIF::readReceivedMessage(CookieIF *cookie,
uint8_t **buffer, size_t* size) {
ReturnValue_t UartComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) {
std::string deviceFile;
UartDeviceMapIter uartDeviceMapIter;
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
if(uartCookie == nullptr) {
if (uartCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "UartComIF::readReceivedMessage: Invalid uart cookie!" << std::endl;
#endif
@ -482,8 +471,8 @@ ReturnValue_t UartComIF::readReceivedMessage(CookieIF *cookie,
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
if (uartDeviceMapIter == uartDeviceMap.end()) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "UartComIF::readReceivedMessage: Device file " << deviceFile <<
" not in uart map" << std::endl;
sif::debug << "UartComIF::readReceivedMessage: Device file " << deviceFile << " not in uart map"
<< std::endl;
#endif
return RETURN_FAILED;
}
@ -497,11 +486,11 @@ ReturnValue_t UartComIF::readReceivedMessage(CookieIF *cookie,
return RETURN_OK;
}
ReturnValue_t UartComIF::flushUartRxBuffer(CookieIF *cookie) {
ReturnValue_t UartComIF::flushUartRxBuffer(CookieIF* cookie) {
std::string deviceFile;
UartDeviceMapIter uartDeviceMapIter;
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
if(uartCookie == nullptr) {
if (uartCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::flushUartRxBuffer: Invalid uart cookie!" << std::endl;
#endif
@ -509,7 +498,7 @@ ReturnValue_t UartComIF::flushUartRxBuffer(CookieIF *cookie) {
}
deviceFile = uartCookie->getDeviceFile();
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
if(uartDeviceMapIter != uartDeviceMap.end()) {
if (uartDeviceMapIter != uartDeviceMap.end()) {
int fd = uartDeviceMapIter->second.fileDescriptor;
tcflush(fd, TCIFLUSH);
return RETURN_OK;
@ -517,11 +506,11 @@ ReturnValue_t UartComIF::flushUartRxBuffer(CookieIF *cookie) {
return RETURN_FAILED;
}
ReturnValue_t UartComIF::flushUartTxBuffer(CookieIF *cookie) {
ReturnValue_t UartComIF::flushUartTxBuffer(CookieIF* cookie) {
std::string deviceFile;
UartDeviceMapIter uartDeviceMapIter;
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
if(uartCookie == nullptr) {
if (uartCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::flushUartTxBuffer: Invalid uart cookie!" << std::endl;
#endif
@ -529,7 +518,7 @@ ReturnValue_t UartComIF::flushUartTxBuffer(CookieIF *cookie) {
}
deviceFile = uartCookie->getDeviceFile();
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
if(uartDeviceMapIter != uartDeviceMap.end()) {
if (uartDeviceMapIter != uartDeviceMap.end()) {
int fd = uartDeviceMapIter->second.fileDescriptor;
tcflush(fd, TCOFLUSH);
return RETURN_OK;
@ -537,11 +526,11 @@ ReturnValue_t UartComIF::flushUartTxBuffer(CookieIF *cookie) {
return RETURN_FAILED;
}
ReturnValue_t UartComIF::flushUartTxAndRxBuf(CookieIF *cookie) {
ReturnValue_t UartComIF::flushUartTxAndRxBuf(CookieIF* cookie) {
std::string deviceFile;
UartDeviceMapIter uartDeviceMapIter;
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie);
if(uartCookie == nullptr) {
if (uartCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::flushUartTxAndRxBuf: Invalid uart cookie!" << std::endl;
#endif
@ -549,7 +538,7 @@ ReturnValue_t UartComIF::flushUartTxAndRxBuf(CookieIF *cookie) {
}
deviceFile = uartCookie->getDeviceFile();
uartDeviceMapIter = uartDeviceMap.find(deviceFile);
if(uartDeviceMapIter != uartDeviceMap.end()) {
if (uartDeviceMapIter != uartDeviceMap.end()) {
int fd = uartDeviceMapIter->second.fileDescriptor;
tcflush(fd, TCIOFLUSH);
return RETURN_OK;
@ -557,13 +546,12 @@ ReturnValue_t UartComIF::flushUartTxAndRxBuf(CookieIF *cookie) {
return RETURN_FAILED;
}
void UartComIF::setUartMode(struct termios *options, UartCookie &uartCookie) {
void UartComIF::setUartMode(struct termios* options, UartCookie& uartCookie) {
UartModes uartMode = uartCookie.getUartMode();
if(uartMode == UartModes::NON_CANONICAL) {
if (uartMode == UartModes::NON_CANONICAL) {
/* Disable canonical mode */
options->c_lflag &= ~ICANON;
}
else if(uartMode == UartModes::CANONICAL) {
} else if (uartMode == UartModes::CANONICAL) {
options->c_lflag |= ICANON;
}
}

View File

@ -1,13 +1,14 @@
#ifndef BSP_Q7S_COMIF_UARTCOMIF_H_
#define BSP_Q7S_COMIF_UARTCOMIF_H_
#include "UartCookie.h"
#include <fsfw/objectmanager/SystemObject.h>
#include <fsfw/devicehandlers/DeviceCommunicationIF.h>
#include <fsfw/objectmanager/SystemObject.h>
#include <unordered_map>
#include <vector>
#include "UartCookie.h"
/**
* @brief This is the communication interface to access serial ports on linux based operating
* systems.
@ -17,8 +18,8 @@
*
* @author J. Meier
*/
class UartComIF: public DeviceCommunicationIF, public SystemObject {
public:
class UartComIF : public DeviceCommunicationIF, public SystemObject {
public:
static constexpr uint8_t uartRetvalId = CLASS_ID::HAL_UART;
static constexpr ReturnValue_t UART_READ_FAILURE =
@ -32,32 +33,28 @@ public:
virtual ~UartComIF();
ReturnValue_t initializeInterface(CookieIF * cookie) override;
ReturnValue_t sendMessage(CookieIF *cookie,const uint8_t *sendData,
size_t sendLen) override;
ReturnValue_t getSendSuccess(CookieIF *cookie) override;
ReturnValue_t requestReceiveMessage(CookieIF *cookie,
size_t requestLen) override;
ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
size_t *size) override;
ReturnValue_t initializeInterface(CookieIF* cookie) override;
ReturnValue_t sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) override;
ReturnValue_t getSendSuccess(CookieIF* cookie) override;
ReturnValue_t requestReceiveMessage(CookieIF* cookie, size_t requestLen) override;
ReturnValue_t readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) override;
/**
* @brief This function discards all data received but not read in the UART buffer.
*/
ReturnValue_t flushUartRxBuffer(CookieIF *cookie);
ReturnValue_t flushUartRxBuffer(CookieIF* cookie);
/**
* @brief This function discards all data in the transmit buffer of the UART driver.
*/
ReturnValue_t flushUartTxBuffer(CookieIF *cookie);
ReturnValue_t flushUartTxBuffer(CookieIF* cookie);
/**
* @brief This function discards both data in the transmit and receive buffer of the UART.
*/
ReturnValue_t flushUartTxAndRxBuf(CookieIF *cookie);
private:
ReturnValue_t flushUartTxAndRxBuf(CookieIF* cookie);
private:
using UartDeviceFile_t = std::string;
struct UartElements {
@ -119,7 +116,6 @@ private:
size_t requestLen);
ReturnValue_t handleNoncanonicalRead(UartCookie& uartCookie, UartDeviceMapIter& iter,
size_t requestLen);
};
#endif /* BSP_Q7S_COMIF_UARTCOMIF_H_ */

View File

@ -3,39 +3,29 @@
#include <fsfw/serviceinterface.h>
UartCookie::UartCookie(object_id_t handlerId, std::string deviceFile, UartModes uartMode,
uint32_t baudrate, size_t maxReplyLen):
handlerId(handlerId), deviceFile(deviceFile), uartMode(uartMode),
baudrate(baudrate), maxReplyLen(maxReplyLen) {
}
uint32_t baudrate, size_t maxReplyLen)
: handlerId(handlerId),
deviceFile(deviceFile),
uartMode(uartMode),
baudrate(baudrate),
maxReplyLen(maxReplyLen) {}
UartCookie::~UartCookie() {}
uint32_t UartCookie::getBaudrate() const {
return baudrate;
}
uint32_t UartCookie::getBaudrate() const { return baudrate; }
size_t UartCookie::getMaxReplyLen() const {
return maxReplyLen;
}
size_t UartCookie::getMaxReplyLen() const { return maxReplyLen; }
std::string UartCookie::getDeviceFile() const {
return deviceFile;
}
std::string UartCookie::getDeviceFile() const { return deviceFile; }
void UartCookie::setParityOdd() {
parity = Parity::ODD;
}
void UartCookie::setParityOdd() { parity = Parity::ODD; }
void UartCookie::setParityEven() {
parity = Parity::EVEN;
}
void UartCookie::setParityEven() { parity = Parity::EVEN; }
Parity UartCookie::getParity() const {
return parity;
}
Parity UartCookie::getParity() const { return parity; }
void UartCookie::setBitsPerWord(uint8_t bitsPerWord_) {
switch(bitsPerWord_) {
switch (bitsPerWord_) {
case 5:
case 6:
case 7:
@ -50,50 +40,26 @@ void UartCookie::setBitsPerWord(uint8_t bitsPerWord_) {
bitsPerWord = bitsPerWord_;
}
uint8_t UartCookie::getBitsPerWord() const {
return bitsPerWord;
}
uint8_t UartCookie::getBitsPerWord() const { return bitsPerWord; }
StopBits UartCookie::getStopBits() const {
return stopBits;
}
StopBits UartCookie::getStopBits() const { return stopBits; }
void UartCookie::setTwoStopBits() {
stopBits = StopBits::TWO_STOP_BITS;
}
void UartCookie::setTwoStopBits() { stopBits = StopBits::TWO_STOP_BITS; }
void UartCookie::setOneStopBit() {
stopBits = StopBits::ONE_STOP_BIT;
}
void UartCookie::setOneStopBit() { stopBits = StopBits::ONE_STOP_BIT; }
UartModes UartCookie::getUartMode() const {
return uartMode;
}
UartModes UartCookie::getUartMode() const { return uartMode; }
void UartCookie::setReadCycles(uint8_t readCycles) {
this->readCycles = readCycles;
}
void UartCookie::setReadCycles(uint8_t readCycles) { this->readCycles = readCycles; }
void UartCookie::setToFlushInput(bool enable) {
this->flushInput = enable;
}
void UartCookie::setToFlushInput(bool enable) { this->flushInput = enable; }
uint8_t UartCookie::getReadCycles() const {
return readCycles;
}
uint8_t UartCookie::getReadCycles() const { return readCycles; }
bool UartCookie::getInputShouldBeFlushed() {
return this->flushInput;
}
bool UartCookie::getInputShouldBeFlushed() { return this->flushInput; }
object_id_t UartCookie::getHandlerId() const {
return this->handlerId;
}
object_id_t UartCookie::getHandlerId() const { return this->handlerId; }
void UartCookie::setNoFixedSizeReply() {
replySizeFixed = false;
}
void UartCookie::setNoFixedSizeReply() { replySizeFixed = false; }
bool UartCookie::isReplySizeFixed() {
return replySizeFixed;
}
bool UartCookie::isReplySizeFixed() { return replySizeFixed; }

View File

@ -6,21 +6,11 @@
#include <string>
enum class Parity {
NONE,
EVEN,
ODD
};
enum class Parity { NONE, EVEN, ODD };
enum class StopBits {
ONE_STOP_BIT,
TWO_STOP_BITS
};
enum class StopBits { ONE_STOP_BIT, TWO_STOP_BITS };
enum class UartModes {
CANONICAL,
NON_CANONICAL
};
enum class UartModes { CANONICAL, NON_CANONICAL };
/**
* @brief Cookie for the UartComIF. There are many options available to configure the UART driver.
@ -29,9 +19,8 @@ enum class UartModes {
*
* @author J. Meier
*/
class UartCookie: public CookieIF {
public:
class UartCookie : public CookieIF {
public:
/**
* @brief Constructor for the uart cookie.
* @param deviceFile The device file specifying the uart to use, e.g. "/dev/ttyPS1"
@ -47,8 +36,8 @@ public:
* 8 databits (number of bits transfered with one uart frame)
* One stop bit
*/
UartCookie(object_id_t handlerId, std::string deviceFile, UartModes uartMode,
uint32_t baudrate, size_t maxReplyLen);
UartCookie(object_id_t handlerId, std::string deviceFile, UartModes uartMode, uint32_t baudrate,
size_t maxReplyLen);
virtual ~UartCookie();
@ -103,8 +92,7 @@ public:
bool isReplySizeFixed();
private:
private:
const object_id_t handlerId;
std::string deviceFile;
const UartModes uartMode;

View File

@ -1,26 +1,23 @@
#include "fsfw/FSFW.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw_hal/linux/utility.h"
#include <cerrno>
#include <cstring>
#include "fsfw/FSFW.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
void utility::handleIoctlError(const char* const customPrintout) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
if(customPrintout != nullptr) {
if (customPrintout != nullptr) {
sif::warning << customPrintout << std::endl;
}
sif::warning << "handleIoctlError: Error code " << errno << ", "<< strerror(errno) <<
std::endl;
sif::warning << "handleIoctlError: Error code " << errno << ", " << strerror(errno) << std::endl;
#else
if(customPrintout != nullptr) {
if (customPrintout != nullptr) {
sif::printWarning("%s\n", customPrintout);
}
sif::printWarning("handleIoctlError: Error code %d, %s\n", errno, strerror(errno));
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
}

View File

@ -2,6 +2,7 @@
#define FSFW_HAL_STM32H7_DEFINITIONS_H_
#include <utility>
#include "stm32h7xx.h"
namespace stm32h7 {
@ -11,15 +12,15 @@ namespace stm32h7 {
* and the second entry is the pin number
*/
struct GpioCfg {
GpioCfg(): port(nullptr), pin(0), altFnc(0) {};
GpioCfg() : port(nullptr), pin(0), altFnc(0){};
GpioCfg(GPIO_TypeDef* port, uint16_t pin, uint8_t altFnc = 0):
port(port), pin(pin), altFnc(altFnc) {};
GpioCfg(GPIO_TypeDef* port, uint16_t pin, uint8_t altFnc = 0)
: port(port), pin(pin), altFnc(altFnc){};
GPIO_TypeDef* port;
uint16_t pin;
uint8_t altFnc;
};
}
} // namespace stm32h7
#endif /* #ifndef FSFW_HAL_STM32H7_DEFINITIONS_H_ */

View File

@ -1,51 +1,47 @@
#include "fsfw_hal/stm32h7/devicetest/GyroL3GD20H.h"
#include "fsfw_hal/stm32h7/spi/mspInit.h"
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
#include "fsfw_hal/stm32h7/spi/spiCore.h"
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
#include "fsfw_hal/stm32h7/spi/stm32h743zi.h"
#include "fsfw/tasks/TaskFactory.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "stm32h7xx_hal_spi.h"
#include "stm32h7xx_hal_rcc.h"
#include <cstring>
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/tasks/TaskFactory.h"
#include "fsfw_hal/stm32h7/spi/mspInit.h"
#include "fsfw_hal/stm32h7/spi/spiCore.h"
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
#include "fsfw_hal/stm32h7/spi/stm32h743zi.h"
#include "stm32h7xx_hal_rcc.h"
#include "stm32h7xx_hal_spi.h"
alignas(32) std::array<uint8_t, GyroL3GD20H::recvBufferSize> GyroL3GD20H::rxBuffer;
alignas(32) std::array<uint8_t, GyroL3GD20H::txBufferSize>
GyroL3GD20H::txBuffer __attribute__((section(".dma_buffer")));
alignas(32) std::array<uint8_t, GyroL3GD20H::txBufferSize> GyroL3GD20H::txBuffer
__attribute__((section(".dma_buffer")));
TransferStates transferState = TransferStates::IDLE;
spi::TransferModes GyroL3GD20H::transferMode = spi::TransferModes::POLLING;
GyroL3GD20H::GyroL3GD20H(SPI_HandleTypeDef *spiHandle, spi::TransferModes transferMode_):
spiHandle(spiHandle) {
GyroL3GD20H::GyroL3GD20H(SPI_HandleTypeDef *spiHandle, spi::TransferModes transferMode_)
: spiHandle(spiHandle) {
txDmaHandle = new DMA_HandleTypeDef();
rxDmaHandle = new DMA_HandleTypeDef();
spi::setSpiHandle(spiHandle);
spi::assignSpiUserArgs(spi::SpiBus::SPI_1, spiHandle);
transferMode = transferMode_;
if(transferMode == spi::TransferModes::DMA) {
if (transferMode == spi::TransferModes::DMA) {
mspCfg = new spi::MspDmaConfigStruct();
auto typedCfg = dynamic_cast<spi::MspDmaConfigStruct*>(mspCfg);
auto typedCfg = dynamic_cast<spi::MspDmaConfigStruct *>(mspCfg);
spi::setDmaHandles(txDmaHandle, rxDmaHandle);
stm32h7::h743zi::standardDmaCfg(*typedCfg, IrqPriorities::HIGHEST_FREERTOS,
IrqPriorities::HIGHEST_FREERTOS, IrqPriorities::HIGHEST_FREERTOS);
IrqPriorities::HIGHEST_FREERTOS,
IrqPriorities::HIGHEST_FREERTOS);
spi::setSpiDmaMspFunctions(typedCfg);
}
else if(transferMode == spi::TransferModes::INTERRUPT) {
} else if (transferMode == spi::TransferModes::INTERRUPT) {
mspCfg = new spi::MspIrqConfigStruct();
auto typedCfg = dynamic_cast<spi::MspIrqConfigStruct*>(mspCfg);
auto typedCfg = dynamic_cast<spi::MspIrqConfigStruct *>(mspCfg);
stm32h7::h743zi::standardInterruptCfg(*typedCfg, IrqPriorities::HIGHEST_FREERTOS);
spi::setSpiIrqMspFunctions(typedCfg);
}
else if(transferMode == spi::TransferModes::POLLING) {
} else if (transferMode == spi::TransferModes::POLLING) {
mspCfg = new spi::MspPollingConfigStruct();
auto typedCfg = dynamic_cast<spi::MspPollingConfigStruct*>(mspCfg);
auto typedCfg = dynamic_cast<spi::MspPollingConfigStruct *>(mspCfg);
stm32h7::h743zi::standardPollingCfg(*typedCfg);
spi::setSpiPollingMspFunctions(typedCfg);
}
@ -64,7 +60,7 @@ GyroL3GD20H::GyroL3GD20H(SPI_HandleTypeDef *spiHandle, spi::TransferModes transf
GyroL3GD20H::~GyroL3GD20H() {
delete txDmaHandle;
delete rxDmaHandle;
if(mspCfg != nullptr) {
if (mspCfg != nullptr) {
delete mspCfg;
}
}
@ -86,7 +82,7 @@ ReturnValue_t GyroL3GD20H::initialize() {
// Recommended setting to avoid glitches
spiHandle->Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_ENABLE;
spiHandle->Init.Mode = SPI_MODE_MASTER;
if(HAL_SPI_Init(spiHandle) != HAL_OK) {
if (HAL_SPI_Init(spiHandle) != HAL_OK) {
sif::printWarning("Error initializing SPI\n");
return HasReturnvaluesIF::RETURN_FAILED;
}
@ -99,14 +95,14 @@ ReturnValue_t GyroL3GD20H::initialize() {
txBuffer[0] = WHO_AM_I_REG | STM_READ_MASK;
txBuffer[1] = 0;
switch(transferMode) {
case(spi::TransferModes::DMA): {
switch (transferMode) {
case (spi::TransferModes::DMA): {
return handleDmaTransferInit();
}
case(spi::TransferModes::INTERRUPT): {
case (spi::TransferModes::INTERRUPT): {
return handleInterruptTransferInit();
}
case(spi::TransferModes::POLLING): {
case (spi::TransferModes::POLLING): {
return handlePollingTransferInit();
}
default: {
@ -118,14 +114,14 @@ ReturnValue_t GyroL3GD20H::initialize() {
}
ReturnValue_t GyroL3GD20H::performOperation() {
switch(transferMode) {
case(spi::TransferModes::DMA): {
switch (transferMode) {
case (spi::TransferModes::DMA): {
return handleDmaSensorRead();
}
case(spi::TransferModes::POLLING): {
case (spi::TransferModes::POLLING): {
return handlePollingSensorRead();
}
case(spi::TransferModes::INTERRUPT): {
case (spi::TransferModes::INTERRUPT): {
return handleInterruptSensorRead();
}
default: {
@ -141,7 +137,7 @@ ReturnValue_t GyroL3GD20H::handleDmaTransferInit() {
in case it overlaps cacheline */
// See https://community.st.com/s/article/FAQ-DMA-is-not-working-on-STM32H7-devices
HAL_StatusTypeDef result = performDmaTransfer(2);
if(result != HAL_OK) {
if (result != HAL_OK) {
// Transfer error in transmission process
sif::printWarning("GyroL3GD20H::initialize: Error transmitting SPI with DMA\n");
}
@ -151,17 +147,19 @@ ReturnValue_t GyroL3GD20H::handleDmaTransferInit() {
TaskFactory::delayTask(1);
}
switch(transferState) {
case(TransferStates::SUCCESS): {
switch (transferState) {
case (TransferStates::SUCCESS): {
uint8_t whoAmIVal = rxBuffer[1];
if(whoAmIVal != EXPECTED_WHO_AM_I_VAL) {
sif::printDebug("GyroL3GD20H::initialize: "
"Read WHO AM I value %d not equal to expected value!\n", whoAmIVal);
if (whoAmIVal != EXPECTED_WHO_AM_I_VAL) {
sif::printDebug(
"GyroL3GD20H::initialize: "
"Read WHO AM I value %d not equal to expected value!\n",
whoAmIVal);
}
transferState = TransferStates::IDLE;
break;
}
case(TransferStates::FAILURE): {
case (TransferStates::FAILURE): {
sif::printWarning("Transfer failure\n");
transferState = TransferStates::FAILURE;
return HasReturnvaluesIF::RETURN_FAILED;
@ -177,7 +175,7 @@ ReturnValue_t GyroL3GD20H::handleDmaTransferInit() {
prepareConfigRegs(configRegs);
result = performDmaTransfer(6);
if(result != HAL_OK) {
if (result != HAL_OK) {
// Transfer error in transmission process
sif::printWarning("Error transmitting SPI with DMA\n");
}
@ -187,13 +185,13 @@ ReturnValue_t GyroL3GD20H::handleDmaTransferInit() {
TaskFactory::delayTask(1);
}
switch(transferState) {
case(TransferStates::SUCCESS): {
switch (transferState) {
case (TransferStates::SUCCESS): {
sif::printInfo("GyroL3GD20H::initialize: Configuration transfer success\n");
transferState = TransferStates::IDLE;
break;
}
case(TransferStates::FAILURE): {
case (TransferStates::FAILURE): {
sif::printWarning("GyroL3GD20H::initialize: Configuration transfer failure\n");
transferState = TransferStates::FAILURE;
return HasReturnvaluesIF::RETURN_FAILED;
@ -203,11 +201,10 @@ ReturnValue_t GyroL3GD20H::handleDmaTransferInit() {
}
}
txBuffer[0] = CTRL_REG_1 | STM_AUTO_INCREMENT_MASK | STM_READ_MASK;
std::memset(txBuffer.data() + 1, 0 , 5);
std::memset(txBuffer.data() + 1, 0, 5);
result = performDmaTransfer(6);
if(result != HAL_OK) {
if (result != HAL_OK) {
// Transfer error in transmission process
sif::printWarning("Error transmitting SPI with DMA\n");
}
@ -216,20 +213,19 @@ ReturnValue_t GyroL3GD20H::handleDmaTransferInit() {
TaskFactory::delayTask(1);
}
switch(transferState) {
case(TransferStates::SUCCESS): {
if(rxBuffer[1] != configRegs[0] or rxBuffer[2] != configRegs[1] or
switch (transferState) {
case (TransferStates::SUCCESS): {
if (rxBuffer[1] != configRegs[0] or rxBuffer[2] != configRegs[1] or
rxBuffer[3] != configRegs[2] or rxBuffer[4] != configRegs[3] or
rxBuffer[5] != configRegs[4]) {
sif::printWarning("GyroL3GD20H::initialize: Configuration failure\n");
}
else {
} else {
sif::printInfo("GyroL3GD20H::initialize: Configuration success\n");
}
transferState = TransferStates::IDLE;
break;
}
case(TransferStates::FAILURE): {
case (TransferStates::FAILURE): {
sif::printWarning("GyroL3GD20H::initialize: Configuration transfer failure\n");
transferState = TransferStates::FAILURE;
return HasReturnvaluesIF::RETURN_FAILED;
@ -243,10 +239,10 @@ ReturnValue_t GyroL3GD20H::handleDmaTransferInit() {
ReturnValue_t GyroL3GD20H::handleDmaSensorRead() {
txBuffer[0] = CTRL_REG_1 | STM_AUTO_INCREMENT_MASK | STM_READ_MASK;
std::memset(txBuffer.data() + 1, 0 , 14);
std::memset(txBuffer.data() + 1, 0, 14);
HAL_StatusTypeDef result = performDmaTransfer(15);
if(result != HAL_OK) {
if (result != HAL_OK) {
// Transfer error in transmission process
sif::printDebug("GyroL3GD20H::handleDmaSensorRead: Error transmitting SPI with DMA\n");
}
@ -255,12 +251,12 @@ ReturnValue_t GyroL3GD20H::handleDmaSensorRead() {
TaskFactory::delayTask(1);
}
switch(transferState) {
case(TransferStates::SUCCESS): {
switch (transferState) {
case (TransferStates::SUCCESS): {
handleSensorReadout();
break;
}
case(TransferStates::FAILURE): {
case (TransferStates::FAILURE): {
sif::printWarning("GyroL3GD20H::handleDmaSensorRead: Sensor read failure\n");
transferState = TransferStates::FAILURE;
return HasReturnvaluesIF::RETURN_FAILED;
@ -275,8 +271,8 @@ ReturnValue_t GyroL3GD20H::handleDmaSensorRead() {
HAL_StatusTypeDef GyroL3GD20H::performDmaTransfer(size_t sendSize) {
transferState = TransferStates::WAIT;
#if STM_USE_PERIPHERAL_TX_BUFFER_MPU_PROTECTION == 0
SCB_CleanDCache_by_Addr((uint32_t*)(((uint32_t)txBuffer.data()) & ~(uint32_t)0x1F),
txBuffer.size()+32);
SCB_CleanDCache_by_Addr((uint32_t *)(((uint32_t)txBuffer.data()) & ~(uint32_t)0x1F),
txBuffer.size() + 32);
#endif
// Start SPI transfer via DMA
@ -288,21 +284,23 @@ ReturnValue_t GyroL3GD20H::handlePollingTransferInit() {
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
auto result = HAL_SPI_TransmitReceive(spiHandle, txBuffer.data(), rxBuffer.data(), 2, 1000);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
switch(result) {
case(HAL_OK): {
switch (result) {
case (HAL_OK): {
sif::printInfo("GyroL3GD20H::initialize: Polling transfer success\n");
uint8_t whoAmIVal = rxBuffer[1];
if(whoAmIVal != EXPECTED_WHO_AM_I_VAL) {
sif::printDebug("GyroL3GD20H::performOperation: "
"Read WHO AM I value %d not equal to expected value!\n", whoAmIVal);
if (whoAmIVal != EXPECTED_WHO_AM_I_VAL) {
sif::printDebug(
"GyroL3GD20H::performOperation: "
"Read WHO AM I value %d not equal to expected value!\n",
whoAmIVal);
}
break;
}
case(HAL_TIMEOUT): {
case (HAL_TIMEOUT): {
sif::printDebug("GyroL3GD20H::initialize: Polling transfer timeout\n");
return HasReturnvaluesIF::RETURN_FAILED;
}
case(HAL_ERROR): {
case (HAL_ERROR): {
sif::printDebug("GyroL3GD20H::initialize: Polling transfer failure\n");
return HasReturnvaluesIF::RETURN_FAILED;
}
@ -319,15 +317,15 @@ ReturnValue_t GyroL3GD20H::handlePollingTransferInit() {
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
result = HAL_SPI_TransmitReceive(spiHandle, txBuffer.data(), rxBuffer.data(), 6, 1000);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
switch(result) {
case(HAL_OK): {
switch (result) {
case (HAL_OK): {
break;
}
case(HAL_TIMEOUT): {
case (HAL_TIMEOUT): {
sif::printDebug("GyroL3GD20H::initialize: Polling transfer timeout\n");
return HasReturnvaluesIF::RETURN_FAILED;
}
case(HAL_ERROR): {
case (HAL_ERROR): {
sif::printDebug("GyroL3GD20H::initialize: Polling transfer failure\n");
return HasReturnvaluesIF::RETURN_FAILED;
}
@ -337,28 +335,27 @@ ReturnValue_t GyroL3GD20H::handlePollingTransferInit() {
}
txBuffer[0] = CTRL_REG_1 | STM_AUTO_INCREMENT_MASK | STM_READ_MASK;
std::memset(txBuffer.data() + 1, 0 , 5);
std::memset(txBuffer.data() + 1, 0, 5);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
result = HAL_SPI_TransmitReceive(spiHandle, txBuffer.data(), rxBuffer.data(), 6, 1000);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
switch(result) {
case(HAL_OK): {
if(rxBuffer[1] != configRegs[0] or rxBuffer[2] != configRegs[1] or
switch (result) {
case (HAL_OK): {
if (rxBuffer[1] != configRegs[0] or rxBuffer[2] != configRegs[1] or
rxBuffer[3] != configRegs[2] or rxBuffer[4] != configRegs[3] or
rxBuffer[5] != configRegs[4]) {
sif::printWarning("GyroL3GD20H::initialize: Configuration failure\n");
}
else {
} else {
sif::printInfo("GyroL3GD20H::initialize: Configuration success\n");
}
break;
}
case(HAL_TIMEOUT): {
case (HAL_TIMEOUT): {
sif::printDebug("GyroL3GD20H::initialize: Polling transfer timeout\n");
return HasReturnvaluesIF::RETURN_FAILED;
}
case(HAL_ERROR): {
case (HAL_ERROR): {
sif::printDebug("GyroL3GD20H::initialize: Polling transfer failure\n");
return HasReturnvaluesIF::RETURN_FAILED;
}
@ -371,21 +368,21 @@ ReturnValue_t GyroL3GD20H::handlePollingTransferInit() {
ReturnValue_t GyroL3GD20H::handlePollingSensorRead() {
txBuffer[0] = CTRL_REG_1 | STM_AUTO_INCREMENT_MASK | STM_READ_MASK;
std::memset(txBuffer.data() + 1, 0 , 14);
std::memset(txBuffer.data() + 1, 0, 14);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
auto result = HAL_SPI_TransmitReceive(spiHandle, txBuffer.data(), rxBuffer.data(), 15, 1000);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
switch(result) {
case(HAL_OK): {
switch (result) {
case (HAL_OK): {
handleSensorReadout();
break;
}
case(HAL_TIMEOUT): {
case (HAL_TIMEOUT): {
sif::printDebug("GyroL3GD20H::initialize: Polling transfer timeout\n");
return HasReturnvaluesIF::RETURN_FAILED;
}
case(HAL_ERROR): {
case (HAL_ERROR): {
sif::printDebug("GyroL3GD20H::initialize: Polling transfer failure\n");
return HasReturnvaluesIF::RETURN_FAILED;
}
@ -398,8 +395,8 @@ ReturnValue_t GyroL3GD20H::handlePollingSensorRead() {
ReturnValue_t GyroL3GD20H::handleInterruptTransferInit() {
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
switch(HAL_SPI_TransmitReceive_IT(spiHandle, txBuffer.data(), rxBuffer.data(), 2)) {
case(HAL_OK): {
switch (HAL_SPI_TransmitReceive_IT(spiHandle, txBuffer.data(), rxBuffer.data(), 2)) {
case (HAL_OK): {
sif::printInfo("GyroL3GD20H::initialize: Interrupt transfer success\n");
// Wait for the transfer to complete
while (transferState == TransferStates::WAIT) {
@ -407,15 +404,17 @@ ReturnValue_t GyroL3GD20H::handleInterruptTransferInit() {
}
uint8_t whoAmIVal = rxBuffer[1];
if(whoAmIVal != EXPECTED_WHO_AM_I_VAL) {
sif::printDebug("GyroL3GD20H::initialize: "
"Read WHO AM I value %d not equal to expected value!\n", whoAmIVal);
if (whoAmIVal != EXPECTED_WHO_AM_I_VAL) {
sif::printDebug(
"GyroL3GD20H::initialize: "
"Read WHO AM I value %d not equal to expected value!\n",
whoAmIVal);
}
break;
}
case(HAL_BUSY):
case(HAL_ERROR):
case(HAL_TIMEOUT): {
case (HAL_BUSY):
case (HAL_ERROR):
case (HAL_TIMEOUT): {
sif::printDebug("GyroL3GD20H::initialize: Initialization failure using interrupts\n");
return HasReturnvaluesIF::RETURN_FAILED;
}
@ -427,45 +426,44 @@ ReturnValue_t GyroL3GD20H::handleInterruptTransferInit() {
uint8_t configRegs[5];
prepareConfigRegs(configRegs);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
switch(HAL_SPI_TransmitReceive_IT(spiHandle, txBuffer.data(), rxBuffer.data(), 6)) {
case(HAL_OK): {
switch (HAL_SPI_TransmitReceive_IT(spiHandle, txBuffer.data(), rxBuffer.data(), 6)) {
case (HAL_OK): {
// Wait for the transfer to complete
while (transferState == TransferStates::WAIT) {
TaskFactory::delayTask(1);
}
break;
}
case(HAL_BUSY):
case(HAL_ERROR):
case(HAL_TIMEOUT): {
case (HAL_BUSY):
case (HAL_ERROR):
case (HAL_TIMEOUT): {
sif::printDebug("GyroL3GD20H::initialize: Initialization failure using interrupts\n");
return HasReturnvaluesIF::RETURN_FAILED;
}
}
txBuffer[0] = CTRL_REG_1 | STM_AUTO_INCREMENT_MASK | STM_READ_MASK;
std::memset(txBuffer.data() + 1, 0 , 5);
std::memset(txBuffer.data() + 1, 0, 5);
transferState = TransferStates::WAIT;
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
switch(HAL_SPI_TransmitReceive_IT(spiHandle, txBuffer.data(), rxBuffer.data(), 6)) {
case(HAL_OK): {
switch (HAL_SPI_TransmitReceive_IT(spiHandle, txBuffer.data(), rxBuffer.data(), 6)) {
case (HAL_OK): {
// Wait for the transfer to complete
while (transferState == TransferStates::WAIT) {
TaskFactory::delayTask(1);
}
if(rxBuffer[1] != configRegs[0] or rxBuffer[2] != configRegs[1] or
if (rxBuffer[1] != configRegs[0] or rxBuffer[2] != configRegs[1] or
rxBuffer[3] != configRegs[2] or rxBuffer[4] != configRegs[3] or
rxBuffer[5] != configRegs[4]) {
sif::printWarning("GyroL3GD20H::initialize: Configuration failure\n");
}
else {
} else {
sif::printInfo("GyroL3GD20H::initialize: Configuration success\n");
}
break;
}
case(HAL_BUSY):
case(HAL_ERROR):
case(HAL_TIMEOUT): {
case (HAL_BUSY):
case (HAL_ERROR):
case (HAL_TIMEOUT): {
sif::printDebug("GyroL3GD20H::initialize: Initialization failure using interrupts\n");
return HasReturnvaluesIF::RETURN_FAILED;
}
@ -476,10 +474,10 @@ ReturnValue_t GyroL3GD20H::handleInterruptTransferInit() {
ReturnValue_t GyroL3GD20H::handleInterruptSensorRead() {
transferState = TransferStates::WAIT;
txBuffer[0] = CTRL_REG_1 | STM_AUTO_INCREMENT_MASK | STM_READ_MASK;
std::memset(txBuffer.data() + 1, 0 , 14);
std::memset(txBuffer.data() + 1, 0, 14);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
switch(HAL_SPI_TransmitReceive_IT(spiHandle, txBuffer.data(), rxBuffer.data(), 15)) {
case(HAL_OK): {
switch (HAL_SPI_TransmitReceive_IT(spiHandle, txBuffer.data(), rxBuffer.data(), 15)) {
case (HAL_OK): {
// Wait for the transfer to complete
while (transferState == TransferStates::WAIT) {
TaskFactory::delayTask(1);
@ -487,9 +485,9 @@ ReturnValue_t GyroL3GD20H::handleInterruptSensorRead() {
handleSensorReadout();
break;
}
case(HAL_BUSY):
case(HAL_ERROR):
case(HAL_TIMEOUT): {
case (HAL_BUSY):
case (HAL_ERROR):
case (HAL_TIMEOUT): {
sif::printDebug("GyroL3GD20H::initialize: Sensor read failure using interrupts\n");
return HasReturnvaluesIF::RETURN_FAILED;
}
@ -497,7 +495,7 @@ ReturnValue_t GyroL3GD20H::handleInterruptSensorRead() {
return HasReturnvaluesIF::RETURN_OK;
}
void GyroL3GD20H::prepareConfigRegs(uint8_t* configRegs) {
void GyroL3GD20H::prepareConfigRegs(uint8_t *configRegs) {
// Enable sensor
configRegs[0] = 0b00001111;
configRegs[1] = 0b00000000;
@ -516,7 +514,8 @@ uint8_t GyroL3GD20H::readRegPolling(uint8_t reg) {
txBuf[0] = reg | STM_READ_MASK;
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
auto result = HAL_SPI_TransmitReceive(spiHandle, txBuf, rxBuf, 2, 1000);
if(result) {};
if (result) {
};
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
return rxBuf[1];
}
@ -535,13 +534,12 @@ void GyroL3GD20H::handleSensorReadout() {
sif::printInfo("Gyro Z: %f\n", gyroZ);
}
void GyroL3GD20H::spiTransferCompleteCallback(SPI_HandleTypeDef *hspi, void* args) {
void GyroL3GD20H::spiTransferCompleteCallback(SPI_HandleTypeDef *hspi, void *args) {
transferState = TransferStates::SUCCESS;
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
if(GyroL3GD20H::transferMode == spi::TransferModes::DMA) {
if (GyroL3GD20H::transferMode == spi::TransferModes::DMA) {
// Invalidate cache prior to access by CPU
SCB_InvalidateDCache_by_Addr ((uint32_t *)GyroL3GD20H::rxBuffer.data(),
SCB_InvalidateDCache_by_Addr((uint32_t *)GyroL3GD20H::rxBuffer.data(),
GyroL3GD20H::recvBufferSize);
}
}
@ -553,6 +551,6 @@ void GyroL3GD20H::spiTransferCompleteCallback(SPI_HandleTypeDef *hspi, void* arg
* add your own implementation.
* @retval None
*/
void GyroL3GD20H::spiTransferErrorCallback(SPI_HandleTypeDef *hspi, void* args) {
void GyroL3GD20H::spiTransferErrorCallback(SPI_HandleTypeDef *hspi, void *args) {
transferState = TransferStates::FAILURE;
}

View File

@ -1,33 +1,26 @@
#ifndef FSFW_HAL_STM32H7_DEVICETEST_GYRO_L3GD20H_H_
#define FSFW_HAL_STM32H7_DEVICETEST_GYRO_L3GD20H_H_
#include "stm32h7xx_hal.h"
#include "stm32h7xx_hal_spi.h"
#include <array>
#include <cstdint>
#include "../spi/mspInit.h"
#include "../spi/spiDefinitions.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include "stm32h7xx_hal.h"
#include "stm32h7xx_hal_spi.h"
#include <cstdint>
#include <array>
enum class TransferStates {
IDLE,
WAIT,
SUCCESS,
FAILURE
};
enum class TransferStates { IDLE, WAIT, SUCCESS, FAILURE };
class GyroL3GD20H {
public:
public:
GyroL3GD20H(SPI_HandleTypeDef* spiHandle, spi::TransferModes transferMode);
~GyroL3GD20H();
ReturnValue_t initialize();
ReturnValue_t performOperation();
private:
private:
const uint8_t WHO_AM_I_REG = 0b00001111;
const uint8_t STM_READ_MASK = 0b10000000;
const uint8_t STM_AUTO_INCREMENT_MASK = 0b01000000;
@ -54,14 +47,12 @@ private:
uint8_t readRegPolling(uint8_t reg);
static void spiTransferCompleteCallback(SPI_HandleTypeDef *hspi, void* args);
static void spiTransferErrorCallback(SPI_HandleTypeDef *hspi, void* args);
static void spiTransferCompleteCallback(SPI_HandleTypeDef* hspi, void* args);
static void spiTransferErrorCallback(SPI_HandleTypeDef* hspi, void* args);
void prepareConfigRegs(uint8_t* configRegs);
void handleSensorReadout();
DMA_HandleTypeDef* txDmaHandle = {};
DMA_HandleTypeDef* rxDmaHandle = {};
spi::MspCfgBase* mspCfg = {};

View File

@ -1,7 +1,7 @@
#include <fsfw_hal/stm32h7/dma.h>
#include <cstdint>
#include <cstddef>
#include <cstdint>
user_handler_t DMA_1_USER_HANDLERS[8];
user_args_t DMA_1_USER_ARGS[8];
@ -11,11 +11,10 @@ user_args_t DMA_2_USER_ARGS[8];
void dma::assignDmaUserHandler(DMAIndexes dma_idx, DMAStreams stream_idx,
user_handler_t user_handler, user_args_t user_args) {
if(dma_idx == DMA_1) {
if (dma_idx == DMA_1) {
DMA_1_USER_HANDLERS[stream_idx] = user_handler;
DMA_1_USER_ARGS[stream_idx] = user_args;
}
else if(dma_idx == DMA_2) {
} else if (dma_idx == DMA_2) {
DMA_2_USER_HANDLERS[stream_idx] = user_handler;
DMA_2_USER_ARGS[stream_idx] = user_args;
}
@ -27,58 +26,26 @@ void dma::assignDmaUserHandler(DMAIndexes dma_idx, DMAStreams stream_idx,
defined in the startup_stm32h743xx.s files! */
#define GENERIC_DMA_IRQ_HANDLER(DMA_IDX, STREAM_IDX) \
if(DMA_##DMA_IDX##_USER_HANDLERS[STREAM_IDX] != NULL) { \
if (DMA_##DMA_IDX##_USER_HANDLERS[STREAM_IDX] != NULL) { \
DMA_##DMA_IDX##_USER_HANDLERS[STREAM_IDX](DMA_##DMA_IDX##_USER_ARGS[STREAM_IDX]); \
return; \
} \
Default_Handler() \
Default_Handler()
extern"C" void DMA1_Stream0_IRQHandler() {
GENERIC_DMA_IRQ_HANDLER(1, 0);
}
extern"C" void DMA1_Stream1_IRQHandler() {
GENERIC_DMA_IRQ_HANDLER(1, 1);
}
extern"C" void DMA1_Stream2_IRQHandler() {
GENERIC_DMA_IRQ_HANDLER(1, 2);
}
extern"C" void DMA1_Stream3_IRQHandler() {
GENERIC_DMA_IRQ_HANDLER(1, 3);
}
extern"C" void DMA1_Stream4_IRQHandler() {
GENERIC_DMA_IRQ_HANDLER(1, 4);
}
extern"C" void DMA1_Stream5_IRQHandler() {
GENERIC_DMA_IRQ_HANDLER(1, 5);
}
extern"C" void DMA1_Stream6_IRQHandler() {
GENERIC_DMA_IRQ_HANDLER(1, 6);
}
extern"C" void DMA1_Stream7_IRQHandler() {
GENERIC_DMA_IRQ_HANDLER(1, 7);
}
extern "C" void DMA1_Stream0_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(1, 0); }
extern "C" void DMA1_Stream1_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(1, 1); }
extern "C" void DMA1_Stream2_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(1, 2); }
extern "C" void DMA1_Stream3_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(1, 3); }
extern "C" void DMA1_Stream4_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(1, 4); }
extern "C" void DMA1_Stream5_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(1, 5); }
extern "C" void DMA1_Stream6_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(1, 6); }
extern "C" void DMA1_Stream7_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(1, 7); }
extern"C" void DMA2_Stream0_IRQHandler() {
GENERIC_DMA_IRQ_HANDLER(2, 0);
}
extern"C" void DMA2_Stream1_IRQHandler() {
GENERIC_DMA_IRQ_HANDLER(2, 1);
}
extern"C" void DMA2_Stream2_IRQHandler() {
GENERIC_DMA_IRQ_HANDLER(2, 2);
}
extern"C" void DMA2_Stream3_IRQHandler() {
GENERIC_DMA_IRQ_HANDLER(2, 3);
}
extern"C" void DMA2_Stream4_IRQHandler() {
GENERIC_DMA_IRQ_HANDLER(2, 4);
}
extern"C" void DMA2_Stream5_IRQHandler() {
GENERIC_DMA_IRQ_HANDLER(2, 5);
}
extern"C" void DMA2_Stream6_IRQHandler() {
GENERIC_DMA_IRQ_HANDLER(2, 6);
}
extern"C" void DMA2_Stream7_IRQHandler() {
GENERIC_DMA_IRQ_HANDLER(2, 7);
}
extern "C" void DMA2_Stream0_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(2, 0); }
extern "C" void DMA2_Stream1_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(2, 1); }
extern "C" void DMA2_Stream2_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(2, 2); }
extern "C" void DMA2_Stream3_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(2, 3); }
extern "C" void DMA2_Stream4_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(2, 4); }
extern "C" void DMA2_Stream5_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(2, 5); }
extern "C" void DMA2_Stream6_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(2, 6); }
extern "C" void DMA2_Stream7_IRQHandler() { GENERIC_DMA_IRQ_HANDLER(2, 7); }

View File

@ -5,20 +5,15 @@
extern "C" {
#endif
#include "interrupts.h"
#include <cstdint>
#include "interrupts.h"
namespace dma {
enum DMAType {
TX = 0,
RX = 1
};
enum DMAType { TX = 0, RX = 1 };
enum DMAIndexes: uint8_t {
DMA_1 = 1,
DMA_2 = 2
};
enum DMAIndexes : uint8_t { DMA_1 = 1, DMA_2 = 2 };
enum DMAStreams {
STREAM_0 = 0,
@ -29,7 +24,7 @@ enum DMAStreams {
STREAM_5 = 5,
STREAM_6 = 6,
STREAM_7 = 7,
} ;
};
/**
* Assign user interrupt handlers for DMA streams, allowing to pass an
@ -37,10 +32,10 @@ enum DMAStreams {
* @param user_handler
* @param user_args
*/
void assignDmaUserHandler(DMAIndexes dma_idx, DMAStreams stream_idx,
user_handler_t user_handler, user_args_t user_args);
void assignDmaUserHandler(DMAIndexes dma_idx, DMAStreams stream_idx, user_handler_t user_handler,
user_args_t user_args);
}
} // namespace dma
#ifdef __cplusplus
}

View File

@ -4,67 +4,67 @@
void gpio::initializeGpioClock(GPIO_TypeDef* gpioPort) {
#ifdef GPIOA
if(gpioPort == GPIOA) {
if (gpioPort == GPIOA) {
__HAL_RCC_GPIOA_CLK_ENABLE();
}
#endif
#ifdef GPIOB
if(gpioPort == GPIOB) {
if (gpioPort == GPIOB) {
__HAL_RCC_GPIOB_CLK_ENABLE();
}
#endif
#ifdef GPIOC
if(gpioPort == GPIOC) {
if (gpioPort == GPIOC) {
__HAL_RCC_GPIOC_CLK_ENABLE();
}
#endif
#ifdef GPIOD
if(gpioPort == GPIOD) {
if (gpioPort == GPIOD) {
__HAL_RCC_GPIOD_CLK_ENABLE();
}
#endif
#ifdef GPIOE
if(gpioPort == GPIOE) {
if (gpioPort == GPIOE) {
__HAL_RCC_GPIOE_CLK_ENABLE();
}
#endif
#ifdef GPIOF
if(gpioPort == GPIOF) {
if (gpioPort == GPIOF) {
__HAL_RCC_GPIOF_CLK_ENABLE();
}
#endif
#ifdef GPIOG
if(gpioPort == GPIOG) {
if (gpioPort == GPIOG) {
__HAL_RCC_GPIOG_CLK_ENABLE();
}
#endif
#ifdef GPIOH
if(gpioPort == GPIOH) {
if (gpioPort == GPIOH) {
__HAL_RCC_GPIOH_CLK_ENABLE();
}
#endif
#ifdef GPIOI
if(gpioPort == GPIOI) {
if (gpioPort == GPIOI) {
__HAL_RCC_GPIOI_CLK_ENABLE();
}
#endif
#ifdef GPIOJ
if(gpioPort == GPIOJ) {
if (gpioPort == GPIOJ) {
__HAL_RCC_GPIOJ_CLK_ENABLE();
}
#endif
#ifdef GPIOK
if(gpioPort == GPIOK) {
if (gpioPort == GPIOK) {
__HAL_RCC_GPIOK_CLK_ENABLE();
}
#endif

View File

@ -12,14 +12,10 @@ extern "C" {
*/
extern void Default_Handler();
typedef void (*user_handler_t) (void*);
typedef void (*user_handler_t)(void*);
typedef void* user_args_t;
enum IrqPriorities: uint8_t {
HIGHEST = 0,
HIGHEST_FREERTOS = 6,
LOWEST = 15
};
enum IrqPriorities : uint8_t { HIGHEST = 0, HIGHEST_FREERTOS = 6, LOWEST = 15 };
#ifdef __cplusplus
}

View File

@ -1,11 +1,11 @@
#include "fsfw_hal/stm32h7/spi/SpiComIF.h"
#include "fsfw_hal/stm32h7/spi/SpiCookie.h"
#include "fsfw/tasks/SemaphoreFactory.h"
#include "fsfw_hal/stm32h7/gpio/gpio.h"
#include "fsfw_hal/stm32h7/spi/SpiCookie.h"
#include "fsfw_hal/stm32h7/spi/mspInit.h"
#include "fsfw_hal/stm32h7/spi/spiCore.h"
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
#include "fsfw_hal/stm32h7/spi/mspInit.h"
#include "fsfw_hal/stm32h7/gpio/gpio.h"
// FreeRTOS required special Semaphore handling from an ISR. Therefore, we use the concrete
// instance here, because RTEMS and FreeRTOS are the only relevant OSALs currently
@ -13,14 +13,14 @@
#if defined FSFW_OSAL_RTEMS
#include "fsfw/osal/rtems/BinarySemaphore.h"
#elif defined FSFW_OSAL_FREERTOS
#include "fsfw/osal/freertos/TaskManagement.h"
#include "fsfw/osal/freertos/BinarySemaphore.h"
#include "fsfw/osal/freertos/TaskManagement.h"
#endif
#include "stm32h7xx_hal_gpio.h"
SpiComIF::SpiComIF(object_id_t objectId): SystemObject(objectId) {
void* irqArgsVoided = reinterpret_cast<void*>(&irqArgs);
SpiComIF::SpiComIF(object_id_t objectId) : SystemObject(objectId) {
void *irqArgsVoided = reinterpret_cast<void *>(&irqArgs);
spi::assignTransferRxTxCompleteCallback(&spiTransferCompleteCallback, irqArgsVoided);
spi::assignTransferRxCompleteCallback(&spiTransferRxCompleteCallback, irqArgsVoided);
spi::assignTransferTxCompleteCallback(&spiTransferTxCompleteCallback, irqArgsVoided);
@ -35,13 +35,11 @@ void SpiComIF::addDmaHandles(DMA_HandleTypeDef *txHandle, DMA_HandleTypeDef *rxH
spi::setDmaHandles(txHandle, rxHandle);
}
ReturnValue_t SpiComIF::initialize() {
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t SpiComIF::initialize() { return HasReturnvaluesIF::RETURN_OK; }
ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
SpiCookie* spiCookie = dynamic_cast<SpiCookie*>(cookie);
if(spiCookie == nullptr) {
SpiCookie *spiCookie = dynamic_cast<SpiCookie *>(cookie);
if (spiCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error < "SpiComIF::initializeInterface: Invalid cookie" << std::endl;
#else
@ -51,32 +49,34 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
}
auto transferMode = spiCookie->getTransferMode();
if(transferMode == spi::TransferModes::DMA) {
if (transferMode == spi::TransferModes::DMA) {
DMA_HandleTypeDef *txHandle = nullptr;
DMA_HandleTypeDef *rxHandle = nullptr;
spi::getDmaHandles(&txHandle, &rxHandle);
if(txHandle == nullptr or rxHandle == nullptr) {
if (txHandle == nullptr or rxHandle == nullptr) {
sif::printError("SpiComIF::initialize: DMA handles not set!\n");
return HasReturnvaluesIF::RETURN_FAILED;
}
}
// This semaphore ensures thread-safety for a given bus
spiSemaphore = dynamic_cast<BinarySemaphore*>(
SemaphoreFactory::instance()->createBinarySemaphore());
spiSemaphore =
dynamic_cast<BinarySemaphore *>(SemaphoreFactory::instance()->createBinarySemaphore());
address_t spiAddress = spiCookie->getDeviceAddress();
auto iter = spiDeviceMap.find(spiAddress);
if(iter == spiDeviceMap.end()) {
if (iter == spiDeviceMap.end()) {
size_t bufferSize = spiCookie->getMaxRecvSize();
auto statusPair = spiDeviceMap.emplace(spiAddress, SpiInstance(bufferSize));
if (not statusPair.second) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "SpiComIF::initializeInterface: Failed to insert device with address " <<
spiAddress << "to SPI device map" << std::endl;
sif::error << "SpiComIF::initializeInterface: Failed to insert device with address "
<< spiAddress << "to SPI device map" << std::endl;
#else
sif::printError("SpiComIF::initializeInterface: Failed to insert device with address "
"%lu to SPI device map\n", static_cast<unsigned long>(spiAddress));
sif::printError(
"SpiComIF::initializeInterface: Failed to insert device with address "
"%lu to SPI device map\n",
static_cast<unsigned long>(spiAddress));
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
return HasReturnvaluesIF::RETURN_FAILED;
@ -85,60 +85,56 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
auto gpioPin = spiCookie->getChipSelectGpioPin();
auto gpioPort = spiCookie->getChipSelectGpioPort();
SPI_HandleTypeDef& spiHandle = spiCookie->getSpiHandle();
SPI_HandleTypeDef &spiHandle = spiCookie->getSpiHandle();
auto spiIdx = spiCookie->getSpiIdx();
if(spiIdx == spi::SpiBus::SPI_1) {
if (spiIdx == spi::SpiBus::SPI_1) {
#ifdef SPI1
spiHandle.Instance = SPI1;
#endif
}
else if(spiIdx == spi::SpiBus::SPI_2) {
} else if (spiIdx == spi::SpiBus::SPI_2) {
#ifdef SPI2
spiHandle.Instance = SPI2;
#endif
}
else {
} else {
printCfgError("SPI Bus Index");
return HasReturnvaluesIF::RETURN_FAILED;
}
auto mspCfg = spiCookie->getMspCfg();
if(transferMode == spi::TransferModes::POLLING) {
auto typedCfg = dynamic_cast<spi::MspPollingConfigStruct*>(mspCfg);
if(typedCfg == nullptr) {
if (transferMode == spi::TransferModes::POLLING) {
auto typedCfg = dynamic_cast<spi::MspPollingConfigStruct *>(mspCfg);
if (typedCfg == nullptr) {
printCfgError("Polling MSP");
return HasReturnvaluesIF::RETURN_FAILED;
}
spi::setSpiPollingMspFunctions(typedCfg);
}
else if(transferMode == spi::TransferModes::INTERRUPT) {
auto typedCfg = dynamic_cast<spi::MspIrqConfigStruct*>(mspCfg);
if(typedCfg == nullptr) {
} else if (transferMode == spi::TransferModes::INTERRUPT) {
auto typedCfg = dynamic_cast<spi::MspIrqConfigStruct *>(mspCfg);
if (typedCfg == nullptr) {
printCfgError("IRQ MSP");
return HasReturnvaluesIF::RETURN_FAILED;
}
spi::setSpiIrqMspFunctions(typedCfg);
}
else if(transferMode == spi::TransferModes::DMA) {
auto typedCfg = dynamic_cast<spi::MspDmaConfigStruct*>(mspCfg);
if(typedCfg == nullptr) {
} else if (transferMode == spi::TransferModes::DMA) {
auto typedCfg = dynamic_cast<spi::MspDmaConfigStruct *>(mspCfg);
if (typedCfg == nullptr) {
printCfgError("DMA MSP");
return HasReturnvaluesIF::RETURN_FAILED;
}
// Check DMA handles
DMA_HandleTypeDef* txHandle = nullptr;
DMA_HandleTypeDef* rxHandle = nullptr;
DMA_HandleTypeDef *txHandle = nullptr;
DMA_HandleTypeDef *rxHandle = nullptr;
spi::getDmaHandles(&txHandle, &rxHandle);
if(txHandle == nullptr or rxHandle == nullptr) {
if (txHandle == nullptr or rxHandle == nullptr) {
printCfgError("DMA Handle");
return HasReturnvaluesIF::RETURN_FAILED;
}
spi::setSpiDmaMspFunctions(typedCfg);
}
if(gpioPort != nullptr) {
if (gpioPort != nullptr) {
gpio::initializeGpioClock(gpioPort);
GPIO_InitTypeDef chipSelect = {};
chipSelect.Pin = gpioPin;
@ -147,7 +143,7 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_SET);
}
if(HAL_SPI_Init(&spiHandle) != HAL_OK) {
if (HAL_SPI_Init(&spiHandle) != HAL_OK) {
sif::printWarning("SpiComIF::initialize: Error initializing SPI\n");
return HasReturnvaluesIF::RETURN_FAILED;
}
@ -158,42 +154,42 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
}
ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, size_t sendLen) {
SpiCookie* spiCookie = dynamic_cast<SpiCookie*>(cookie);
if(spiCookie == nullptr) {
SpiCookie *spiCookie = dynamic_cast<SpiCookie *>(cookie);
if (spiCookie == nullptr) {
return NULLPOINTER;
}
SPI_HandleTypeDef& spiHandle = spiCookie->getSpiHandle();
SPI_HandleTypeDef &spiHandle = spiCookie->getSpiHandle();
auto iter = spiDeviceMap.find(spiCookie->getDeviceAddress());
if(iter == spiDeviceMap.end()) {
if (iter == spiDeviceMap.end()) {
return HasReturnvaluesIF::RETURN_FAILED;
}
iter->second.currentTransferLen = sendLen;
auto transferMode = spiCookie->getTransferMode();
switch(spiCookie->getTransferState()) {
case(spi::TransferStates::IDLE): {
switch (spiCookie->getTransferState()) {
case (spi::TransferStates::IDLE): {
break;
}
case(spi::TransferStates::WAIT):
case(spi::TransferStates::FAILURE):
case(spi::TransferStates::SUCCESS):
case (spi::TransferStates::WAIT):
case (spi::TransferStates::FAILURE):
case (spi::TransferStates::SUCCESS):
default: {
return HasReturnvaluesIF::RETURN_FAILED;
}
}
switch(transferMode) {
case(spi::TransferModes::POLLING): {
switch (transferMode) {
case (spi::TransferModes::POLLING): {
return handlePollingSendOperation(iter->second.replyBuffer.data(), spiHandle, *spiCookie,
sendData, sendLen);
}
case(spi::TransferModes::INTERRUPT): {
case (spi::TransferModes::INTERRUPT): {
return handleInterruptSendOperation(iter->second.replyBuffer.data(), spiHandle, *spiCookie,
sendData, sendLen);
}
case(spi::TransferModes::DMA): {
case (spi::TransferModes::DMA): {
return handleDmaSendOperation(iter->second.replyBuffer.data(), spiHandle, *spiCookie,
sendData, sendLen);
}
@ -201,23 +197,21 @@ ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, s
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t SpiComIF::getSendSuccess(CookieIF *cookie) {
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t SpiComIF::getSendSuccess(CookieIF *cookie) { return HasReturnvaluesIF::RETURN_OK; }
ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF *cookie, size_t requestLen) {
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t SpiComIF::readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) {
SpiCookie* spiCookie = dynamic_cast<SpiCookie*>(cookie);
if(spiCookie == nullptr) {
SpiCookie *spiCookie = dynamic_cast<SpiCookie *>(cookie);
if (spiCookie == nullptr) {
return NULLPOINTER;
}
switch(spiCookie->getTransferState()) {
case(spi::TransferStates::SUCCESS): {
switch (spiCookie->getTransferState()) {
case (spi::TransferStates::SUCCESS): {
auto iter = spiDeviceMap.find(spiCookie->getDeviceAddress());
if(iter == spiDeviceMap.end()) {
if (iter == spiDeviceMap.end()) {
return HasReturnvaluesIF::RETURN_FAILED;
}
*buffer = iter->second.replyBuffer.data();
@ -225,7 +219,7 @@ ReturnValue_t SpiComIF::readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
spiCookie->setTransferState(spi::TransferStates::IDLE);
break;
}
case(spi::TransferStates::FAILURE): {
case (spi::TransferStates::FAILURE): {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "SpiComIF::readReceivedMessage: Transfer failure" << std::endl;
@ -236,8 +230,8 @@ ReturnValue_t SpiComIF::readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
spiCookie->setTransferState(spi::TransferStates::IDLE);
return HasReturnvaluesIF::RETURN_FAILED;
}
case(spi::TransferStates::WAIT):
case(spi::TransferStates::IDLE): {
case (spi::TransferStates::WAIT):
case (spi::TransferStates::IDLE): {
break;
}
default: {
@ -252,35 +246,36 @@ void SpiComIF::setDefaultPollingTimeout(dur_millis_t timeout) {
this->defaultPollingTimeout = timeout;
}
ReturnValue_t SpiComIF::handlePollingSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle,
SpiCookie& spiCookie, const uint8_t *sendData, size_t sendLen) {
ReturnValue_t SpiComIF::handlePollingSendOperation(uint8_t *recvPtr, SPI_HandleTypeDef &spiHandle,
SpiCookie &spiCookie, const uint8_t *sendData,
size_t sendLen) {
auto gpioPort = spiCookie.getChipSelectGpioPort();
auto gpioPin = spiCookie.getChipSelectGpioPin();
auto returnval = spiSemaphore->acquire(timeoutType, timeoutMs);
if(returnval != HasReturnvaluesIF::RETURN_OK) {
if (returnval != HasReturnvaluesIF::RETURN_OK) {
return returnval;
}
spiCookie.setTransferState(spi::TransferStates::WAIT);
if(gpioPort != nullptr) {
if (gpioPort != nullptr) {
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_RESET);
}
auto result = HAL_SPI_TransmitReceive(&spiHandle, const_cast<uint8_t*>(sendData),
recvPtr, sendLen, defaultPollingTimeout);
if(gpioPort != nullptr) {
auto result = HAL_SPI_TransmitReceive(&spiHandle, const_cast<uint8_t *>(sendData), recvPtr,
sendLen, defaultPollingTimeout);
if (gpioPort != nullptr) {
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_SET);
}
spiSemaphore->release();
switch(result) {
case(HAL_OK): {
switch (result) {
case (HAL_OK): {
spiCookie.setTransferState(spi::TransferStates::SUCCESS);
break;
}
case(HAL_TIMEOUT): {
case (HAL_TIMEOUT): {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "SpiComIF::sendMessage: Polling Mode | Timeout for SPI device" <<
spiCookie->getDeviceAddress() << std::endl;
sif::warning << "SpiComIF::sendMessage: Polling Mode | Timeout for SPI device"
<< spiCookie->getDeviceAddress() << std::endl;
#else
sif::printWarning("SpiComIF::sendMessage: Polling Mode | Timeout for SPI device %d\n",
spiCookie.getDeviceAddress());
@ -289,12 +284,12 @@ ReturnValue_t SpiComIF::handlePollingSendOperation(uint8_t* recvPtr, SPI_HandleT
spiCookie.setTransferState(spi::TransferStates::FAILURE);
return spi::HAL_TIMEOUT_RETVAL;
}
case(HAL_ERROR):
case (HAL_ERROR):
default: {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "SpiComIF::sendMessage: Polling Mode | HAL error for SPI device" <<
spiCookie->getDeviceAddress() << std::endl;
sif::warning << "SpiComIF::sendMessage: Polling Mode | HAL error for SPI device"
<< spiCookie->getDeviceAddress() << std::endl;
#else
sif::printWarning("SpiComIF::sendMessage: Polling Mode | HAL error for SPI device %d\n",
spiCookie.getDeviceAddress());
@ -307,41 +302,42 @@ ReturnValue_t SpiComIF::handlePollingSendOperation(uint8_t* recvPtr, SPI_HandleT
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t SpiComIF::handleInterruptSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle,
SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen) {
ReturnValue_t SpiComIF::handleInterruptSendOperation(uint8_t *recvPtr, SPI_HandleTypeDef &spiHandle,
SpiCookie &spiCookie, const uint8_t *sendData,
size_t sendLen) {
return handleIrqSendOperation(recvPtr, spiHandle, spiCookie, sendData, sendLen);
}
ReturnValue_t SpiComIF::handleDmaSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle,
SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen) {
ReturnValue_t SpiComIF::handleDmaSendOperation(uint8_t *recvPtr, SPI_HandleTypeDef &spiHandle,
SpiCookie &spiCookie, const uint8_t *sendData,
size_t sendLen) {
return handleIrqSendOperation(recvPtr, spiHandle, spiCookie, sendData, sendLen);
}
ReturnValue_t SpiComIF::handleIrqSendOperation(uint8_t *recvPtr, SPI_HandleTypeDef& spiHandle,
SpiCookie& spiCookie, const uint8_t *sendData, size_t sendLen) {
ReturnValue_t SpiComIF::handleIrqSendOperation(uint8_t *recvPtr, SPI_HandleTypeDef &spiHandle,
SpiCookie &spiCookie, const uint8_t *sendData,
size_t sendLen) {
ReturnValue_t result = genericIrqSendSetup(recvPtr, spiHandle, spiCookie, sendData, sendLen);
if(result != HasReturnvaluesIF::RETURN_OK) {
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
// yet another HAL driver which is not const-correct..
HAL_StatusTypeDef status = HAL_OK;
auto transferMode = spiCookie.getTransferMode();
if(transferMode == spi::TransferModes::DMA) {
if(cacheMaintenanceOnTxBuffer) {
if (transferMode == spi::TransferModes::DMA) {
if (cacheMaintenanceOnTxBuffer) {
/* Clean D-cache. Make sure the address is 32-byte aligned and add 32-bytes to length,
in case it overlaps cacheline */
SCB_CleanDCache_by_Addr((uint32_t*)(((uint32_t) sendData ) & ~(uint32_t)0x1F),
sendLen + 32);
SCB_CleanDCache_by_Addr((uint32_t *)(((uint32_t)sendData) & ~(uint32_t)0x1F), sendLen + 32);
}
status = HAL_SPI_TransmitReceive_DMA(&spiHandle, const_cast<uint8_t*>(sendData),
status = HAL_SPI_TransmitReceive_DMA(&spiHandle, const_cast<uint8_t *>(sendData),
currentRecvPtr, sendLen);
} else {
status = HAL_SPI_TransmitReceive_IT(&spiHandle, const_cast<uint8_t *>(sendData), currentRecvPtr,
sendLen);
}
else {
status = HAL_SPI_TransmitReceive_IT(&spiHandle, const_cast<uint8_t*>(sendData),
currentRecvPtr, sendLen);
}
switch(status) {
case(HAL_OK): {
switch (status) {
case (HAL_OK): {
break;
}
default: {
@ -353,22 +349,20 @@ ReturnValue_t SpiComIF::handleIrqSendOperation(uint8_t *recvPtr, SPI_HandleTypeD
ReturnValue_t SpiComIF::halErrorHandler(HAL_StatusTypeDef status, spi::TransferModes transferMode) {
char modeString[10];
if(transferMode == spi::TransferModes::DMA) {
if (transferMode == spi::TransferModes::DMA) {
std::snprintf(modeString, sizeof(modeString), "Dma");
}
else {
} else {
std::snprintf(modeString, sizeof(modeString), "Interrupt");
}
sif::printWarning("SpiComIF::handle%sSendOperation: HAL error %d occured\n", modeString,
status);
switch(status) {
case(HAL_BUSY): {
sif::printWarning("SpiComIF::handle%sSendOperation: HAL error %d occured\n", modeString, status);
switch (status) {
case (HAL_BUSY): {
return spi::HAL_BUSY_RETVAL;
}
case(HAL_ERROR): {
case (HAL_ERROR): {
return spi::HAL_ERROR_RETVAL;
}
case(HAL_TIMEOUT): {
case (HAL_TIMEOUT): {
return spi::HAL_TIMEOUT_RETVAL;
}
default: {
@ -377,18 +371,20 @@ ReturnValue_t SpiComIF::halErrorHandler(HAL_StatusTypeDef status, spi::TransferM
}
}
ReturnValue_t SpiComIF::genericIrqSendSetup(uint8_t *recvPtr, SPI_HandleTypeDef& spiHandle,
SpiCookie& spiCookie, const uint8_t *sendData, size_t sendLen) {
ReturnValue_t SpiComIF::genericIrqSendSetup(uint8_t *recvPtr, SPI_HandleTypeDef &spiHandle,
SpiCookie &spiCookie, const uint8_t *sendData,
size_t sendLen) {
currentRecvPtr = recvPtr;
currentRecvBuffSize = sendLen;
// Take the semaphore which will be released by a callback when the transfer is complete
ReturnValue_t result = spiSemaphore->acquire(SemaphoreIF::TimeoutType::WAITING, timeoutMs);
if(result != HasReturnvaluesIF::RETURN_OK) {
if (result != HasReturnvaluesIF::RETURN_OK) {
// Configuration error
sif::printWarning("SpiComIF::handleInterruptSendOperation: Semaphore "
"could not be acquired after %d ms\n", timeoutMs);
sif::printWarning(
"SpiComIF::handleInterruptSendOperation: Semaphore "
"could not be acquired after %d ms\n",
timeoutMs);
return result;
}
// Cache the current SPI handle in any case
@ -398,8 +394,8 @@ ReturnValue_t SpiComIF::genericIrqSendSetup(uint8_t *recvPtr, SPI_HandleTypeDef&
irqArgs.spiCookie = &spiCookie;
// The SPI handle is passed to the default SPI callback as a void argument. This callback
// is different from the user callbacks specified above!
spi::assignSpiUserArgs(spiCookie.getSpiIdx(), reinterpret_cast<void*>(&spiHandle));
if(spiCookie.getChipSelectGpioPort() != nullptr) {
spi::assignSpiUserArgs(spiCookie.getSpiIdx(), reinterpret_cast<void *>(&spiHandle));
if (spiCookie.getChipSelectGpioPort() != nullptr) {
HAL_GPIO_WritePin(spiCookie.getChipSelectGpioPort(), spiCookie.getChipSelectGpioPin(),
GPIO_PIN_RESET);
}
@ -423,48 +419,46 @@ void SpiComIF::spiTransferErrorCallback(SPI_HandleTypeDef *hspi, void *args) {
}
void SpiComIF::genericIrqHandler(void *irqArgsVoid, spi::TransferStates targetState) {
IrqArgs* irqArgs = reinterpret_cast<IrqArgs*>(irqArgsVoid);
if(irqArgs == nullptr) {
IrqArgs *irqArgs = reinterpret_cast<IrqArgs *>(irqArgsVoid);
if (irqArgs == nullptr) {
return;
}
SpiCookie* spiCookie = irqArgs->spiCookie;
SpiComIF* comIF = irqArgs->comIF;
if(spiCookie == nullptr or comIF == nullptr) {
SpiCookie *spiCookie = irqArgs->spiCookie;
SpiComIF *comIF = irqArgs->comIF;
if (spiCookie == nullptr or comIF == nullptr) {
return;
}
spiCookie->setTransferState(targetState);
if(spiCookie->getChipSelectGpioPort() != nullptr) {
if (spiCookie->getChipSelectGpioPort() != nullptr) {
// Pull CS pin high again
HAL_GPIO_WritePin(spiCookie->getChipSelectGpioPort(), spiCookie->getChipSelectGpioPin(),
GPIO_PIN_SET);
}
#if defined FSFW_OSAL_FREERTOS
// Release the task semaphore
BaseType_t taskWoken = pdFALSE;
ReturnValue_t result = BinarySemaphore::releaseFromISR(comIF->spiSemaphore->getSemaphore(),
&taskWoken);
ReturnValue_t result =
BinarySemaphore::releaseFromISR(comIF->spiSemaphore->getSemaphore(), &taskWoken);
#elif defined FSFW_OSAL_RTEMS
ReturnValue_t result = comIF->spiSemaphore->release();
#endif
if(result != HasReturnvaluesIF::RETURN_OK) {
if (result != HasReturnvaluesIF::RETURN_OK) {
// Configuration error
printf("SpiComIF::genericIrqHandler: Failure releasing Semaphore!\n");
}
// Perform cache maintenance operation for DMA transfers
if(spiCookie->getTransferMode() == spi::TransferModes::DMA) {
if (spiCookie->getTransferMode() == spi::TransferModes::DMA) {
// Invalidate cache prior to access by CPU
SCB_InvalidateDCache_by_Addr ((uint32_t *) comIF->currentRecvPtr,
comIF->currentRecvBuffSize);
SCB_InvalidateDCache_by_Addr((uint32_t *)comIF->currentRecvPtr, comIF->currentRecvBuffSize);
}
#if defined FSFW_OSAL_FREERTOS
/* Request a context switch if the SPI ComIF task was woken up and has a higher priority
than the currently running task */
if(taskWoken == pdTRUE) {
if (taskWoken == pdTRUE) {
TaskManagement::requestContextSwitch(CallContext::ISR);
}
#endif

View File

@ -1,16 +1,15 @@
#ifndef FSFW_HAL_STM32H7_SPI_SPICOMIF_H_
#define FSFW_HAL_STM32H7_SPI_SPICOMIF_H_
#include "fsfw/tasks/SemaphoreIF.h"
#include <map>
#include <vector>
#include "fsfw/devicehandlers/DeviceCommunicationIF.h"
#include "fsfw/objectmanager/SystemObject.h"
#include "fsfw/tasks/SemaphoreIF.h"
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
#include "stm32h7xx_hal_spi.h"
#include "stm32h743xx.h"
#include <vector>
#include <map>
#include "stm32h7xx_hal_spi.h"
class SpiCookie;
class BinarySemaphore;
@ -28,10 +27,8 @@ class BinarySemaphore;
* implementation limits the transfer mode for a given SPI bus.
* @author R. Mueller
*/
class SpiComIF:
public SystemObject,
public DeviceCommunicationIF {
public:
class SpiComIF : public SystemObject, public DeviceCommunicationIF {
public:
/**
* Create a SPI communication interface for the given SPI peripheral (spiInstance)
* @param objectId
@ -62,19 +59,17 @@ public:
ReturnValue_t initialize() override;
// DeviceCommunicationIF overrides
virtual ReturnValue_t initializeInterface(CookieIF * cookie) override;
virtual ReturnValue_t sendMessage(CookieIF *cookie,
const uint8_t * sendData, size_t sendLen) override;
virtual ReturnValue_t getSendSuccess(CookieIF *cookie) override;
virtual ReturnValue_t requestReceiveMessage(CookieIF *cookie,
size_t requestLen) override;
virtual ReturnValue_t readReceivedMessage(CookieIF *cookie,
uint8_t **buffer, size_t *size) override;
protected:
virtual ReturnValue_t initializeInterface(CookieIF* cookie) override;
virtual ReturnValue_t sendMessage(CookieIF* cookie, const uint8_t* sendData,
size_t sendLen) override;
virtual ReturnValue_t getSendSuccess(CookieIF* cookie) override;
virtual ReturnValue_t requestReceiveMessage(CookieIF* cookie, size_t requestLen) override;
virtual ReturnValue_t readReceivedMessage(CookieIF* cookie, uint8_t** buffer,
size_t* size) override;
protected:
struct SpiInstance {
SpiInstance(size_t maxRecvSize): replyBuffer(std::vector<uint8_t>(maxRecvSize)) {}
SpiInstance(size_t maxRecvSize) : replyBuffer(std::vector<uint8_t>(maxRecvSize)) {}
std::vector<uint8_t> replyBuffer;
size_t currentTransferLen = 0;
};
@ -103,27 +98,29 @@ protected:
SpiDeviceMap spiDeviceMap;
ReturnValue_t handlePollingSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle,
SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen);
SpiCookie& spiCookie, const uint8_t* sendData,
size_t sendLen);
ReturnValue_t handleInterruptSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle,
SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen);
SpiCookie& spiCookie, const uint8_t* sendData,
size_t sendLen);
ReturnValue_t handleDmaSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle,
SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen);
SpiCookie& spiCookie, const uint8_t* sendData,
size_t sendLen);
ReturnValue_t handleIrqSendOperation(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle,
SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen);
SpiCookie& spiCookie, const uint8_t* sendData,
size_t sendLen);
ReturnValue_t genericIrqSendSetup(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle,
SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen);
SpiCookie& spiCookie, const uint8_t* sendData, size_t sendLen);
ReturnValue_t halErrorHandler(HAL_StatusTypeDef status, spi::TransferModes transferMode);
static void spiTransferTxCompleteCallback(SPI_HandleTypeDef *hspi, void* args);
static void spiTransferRxCompleteCallback(SPI_HandleTypeDef *hspi, void* args);
static void spiTransferCompleteCallback(SPI_HandleTypeDef *hspi, void* args);
static void spiTransferErrorCallback(SPI_HandleTypeDef *hspi, void* args);
static void spiTransferTxCompleteCallback(SPI_HandleTypeDef* hspi, void* args);
static void spiTransferRxCompleteCallback(SPI_HandleTypeDef* hspi, void* args);
static void spiTransferCompleteCallback(SPI_HandleTypeDef* hspi, void* args);
static void spiTransferErrorCallback(SPI_HandleTypeDef* hspi, void* args);
static void genericIrqHandler(void* irqArgs, spi::TransferStates targetState);
void printCfgError(const char* const type);
};
#endif /* FSFW_HAL_STM32H7_SPI_SPICOMIF_H_ */

View File

@ -1,12 +1,16 @@
#include "fsfw_hal/stm32h7/spi/SpiCookie.h"
SpiCookie::SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferModes transferMode,
spi::MspCfgBase* mspCfg, uint32_t spiSpeed, spi::SpiModes spiMode,
size_t maxRecvSize, stm32h7::GpioCfg csGpio):
deviceAddress(deviceAddress), spiIdx(spiIdx), spiSpeed(spiSpeed), spiMode(spiMode),
transferMode(transferMode), csGpio(csGpio),
mspCfg(mspCfg), maxRecvSize(maxRecvSize) {
size_t maxRecvSize, stm32h7::GpioCfg csGpio)
: deviceAddress(deviceAddress),
spiIdx(spiIdx),
spiSpeed(spiSpeed),
spiMode(spiMode),
transferMode(transferMode),
csGpio(csGpio),
mspCfg(mspCfg),
maxRecvSize(maxRecvSize) {
spiHandle.Init.DataSize = SPI_DATASIZE_8BIT;
spiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB;
spiHandle.Init.TIMode = SPI_TIMODE_DISABLE;
@ -23,56 +27,34 @@ SpiCookie::SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferM
spiHandle.Init.BaudRatePrescaler = spi::getPrescaler(HAL_RCC_GetHCLKFreq(), spiSpeed);
}
uint16_t SpiCookie::getChipSelectGpioPin() const {
return csGpio.pin;
}
uint16_t SpiCookie::getChipSelectGpioPin() const { return csGpio.pin; }
GPIO_TypeDef* SpiCookie::getChipSelectGpioPort() {
return csGpio.port;
}
GPIO_TypeDef* SpiCookie::getChipSelectGpioPort() { return csGpio.port; }
address_t SpiCookie::getDeviceAddress() const {
return deviceAddress;
}
address_t SpiCookie::getDeviceAddress() const { return deviceAddress; }
spi::SpiBus SpiCookie::getSpiIdx() const {
return spiIdx;
}
spi::SpiBus SpiCookie::getSpiIdx() const { return spiIdx; }
spi::SpiModes SpiCookie::getSpiMode() const {
return spiMode;
}
spi::SpiModes SpiCookie::getSpiMode() const { return spiMode; }
uint32_t SpiCookie::getSpiSpeed() const {
return spiSpeed;
}
uint32_t SpiCookie::getSpiSpeed() const { return spiSpeed; }
size_t SpiCookie::getMaxRecvSize() const {
return maxRecvSize;
}
size_t SpiCookie::getMaxRecvSize() const { return maxRecvSize; }
SPI_HandleTypeDef& SpiCookie::getSpiHandle() {
return spiHandle;
}
SPI_HandleTypeDef& SpiCookie::getSpiHandle() { return spiHandle; }
spi::MspCfgBase* SpiCookie::getMspCfg() {
return mspCfg;
}
spi::MspCfgBase* SpiCookie::getMspCfg() { return mspCfg; }
void SpiCookie::deleteMspCfg() {
if(mspCfg != nullptr) {
if (mspCfg != nullptr) {
delete mspCfg;
}
}
spi::TransferModes SpiCookie::getTransferMode() const {
return transferMode;
}
spi::TransferModes SpiCookie::getTransferMode() const { return transferMode; }
void SpiCookie::setTransferState(spi::TransferStates transferState) {
this->transferState = transferState;
}
spi::TransferStates SpiCookie::getTransferState() const {
return this->transferState;
}
spi::TransferStates SpiCookie::getTransferState() const { return this->transferState; }

View File

@ -1,16 +1,14 @@
#ifndef FSFW_HAL_STM32H7_SPI_SPICOOKIE_H_
#define FSFW_HAL_STM32H7_SPI_SPICOOKIE_H_
#include "spiDefinitions.h"
#include "mspInit.h"
#include "../definitions.h"
#include "fsfw/devicehandlers/CookieIF.h"
#include "stm32h743xx.h"
#include <utility>
#include "../definitions.h"
#include "fsfw/devicehandlers/CookieIF.h"
#include "mspInit.h"
#include "spiDefinitions.h"
#include "stm32h743xx.h"
/**
* @brief SPI cookie implementation for the STM32H7 device family
* @details
@ -18,10 +16,10 @@
* SPI communication interface
* @author R. Mueller
*/
class SpiCookie: public CookieIF {
class SpiCookie : public CookieIF {
friend class SpiComIF;
public:
public:
/**
* Allows construction of a SPI cookie for a connected SPI device
* @param deviceAddress
@ -39,8 +37,8 @@ public:
* @param csGpio Optional CS GPIO definition.
*/
SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferModes transferMode,
spi::MspCfgBase* mspCfg, uint32_t spiSpeed, spi::SpiModes spiMode,
size_t maxRecvSize, stm32h7::GpioCfg csGpio = stm32h7::GpioCfg(nullptr, 0, 0));
spi::MspCfgBase* mspCfg, uint32_t spiSpeed, spi::SpiModes spiMode, size_t maxRecvSize,
stm32h7::GpioCfg csGpio = stm32h7::GpioCfg(nullptr, 0, 0));
uint16_t getChipSelectGpioPin() const;
GPIO_TypeDef* getChipSelectGpioPort();
@ -52,7 +50,7 @@ public:
size_t getMaxRecvSize() const;
SPI_HandleTypeDef& getSpiHandle();
private:
private:
address_t deviceAddress;
SPI_HandleTypeDef spiHandle = {};
spi::SpiBus spiIdx;
@ -75,6 +73,4 @@ private:
spi::TransferStates getTransferState() const;
};
#endif /* FSFW_HAL_STM32H7_SPI_SPICOOKIE_H_ */

View File

@ -1,15 +1,15 @@
#include "fsfw_hal/stm32h7/dma.h"
#include "fsfw_hal/stm32h7/spi/mspInit.h"
#include "fsfw_hal/stm32h7/spi/spiCore.h"
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
#include "stm32h743xx.h"
#include "stm32h7xx_hal_spi.h"
#include "stm32h7xx_hal_dma.h"
#include "stm32h7xx_hal_def.h"
#include <cstdio>
#include "fsfw_hal/stm32h7/dma.h"
#include "fsfw_hal/stm32h7/spi/spiCore.h"
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
#include "stm32h743xx.h"
#include "stm32h7xx_hal_def.h"
#include "stm32h7xx_hal_dma.h"
#include "stm32h7xx_hal_spi.h"
spi::msp_func_t mspInitFunc = nullptr;
spi::MspCfgBase* mspInitArgs = nullptr;
@ -28,7 +28,7 @@ spi::MspCfgBase* mspDeinitArgs = nullptr;
*/
void spi::halMspInitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
auto cfg = dynamic_cast<MspDmaConfigStruct*>(cfgBase);
if(hspi == nullptr or cfg == nullptr) {
if (hspi == nullptr or cfg == nullptr) {
return;
}
setSpiHandle(hspi);
@ -36,7 +36,7 @@ void spi::halMspInitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
DMA_HandleTypeDef* hdma_tx = nullptr;
DMA_HandleTypeDef* hdma_rx = nullptr;
spi::getDmaHandles(&hdma_tx, &hdma_rx);
if(hdma_tx == nullptr or hdma_rx == nullptr) {
if (hdma_tx == nullptr or hdma_rx == nullptr) {
printf("HAL_SPI_MspInit: Invalid DMA handles. Make sure to call setDmaHandles!\n");
return;
}
@ -44,14 +44,14 @@ void spi::halMspInitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
spi::halMspInitInterrupt(hspi, cfg);
// DMA setup
if(cfg->dmaClkEnableWrapper == nullptr) {
if (cfg->dmaClkEnableWrapper == nullptr) {
mspErrorHandler("spi::halMspInitDma", "DMA Clock init invalid");
}
cfg->dmaClkEnableWrapper();
// Configure the DMA
/* Configure the DMA handler for Transmission process */
if(hdma_tx->Instance == nullptr) {
if (hdma_tx->Instance == nullptr) {
// Assume it was not configured properly
mspErrorHandler("spi::halMspInitDma", "DMA TX handle invalid");
}
@ -73,8 +73,7 @@ void spi::halMspInitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
/* NVIC configuration for DMA transfer complete interrupt (SPI1_TX) */
// Assign the interrupt handler
dma::assignDmaUserHandler(cfg->txDmaIndex, cfg->txDmaStream,
&spi::dmaTxIrqHandler, hdma_tx);
dma::assignDmaUserHandler(cfg->txDmaIndex, cfg->txDmaStream, &spi::dmaTxIrqHandler, hdma_tx);
HAL_NVIC_SetPriority(cfg->txDmaIrqNumber, cfg->txPreEmptPriority, cfg->txSubpriority);
HAL_NVIC_EnableIRQ(cfg->txDmaIrqNumber);
}
@ -89,17 +88,16 @@ void spi::halMspInitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
*/
void spi::halMspDeinitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
auto cfg = dynamic_cast<MspDmaConfigStruct*>(cfgBase);
if(hspi == nullptr or cfg == nullptr) {
if (hspi == nullptr or cfg == nullptr) {
return;
}
spi::halMspDeinitInterrupt(hspi, cfgBase);
DMA_HandleTypeDef* hdma_tx = NULL;
DMA_HandleTypeDef* hdma_rx = NULL;
spi::getDmaHandles(&hdma_tx, &hdma_rx);
if(hdma_tx == NULL || hdma_rx == NULL) {
if (hdma_tx == NULL || hdma_rx == NULL) {
printf("HAL_SPI_MspInit: Invalid DMA handles. Make sure to call setDmaHandles!\n");
}
else {
} else {
// Disable the DMA
/* De-Initialize the DMA associated to transmission process */
HAL_DMA_DeInit(hdma_tx);
@ -110,7 +108,6 @@ void spi::halMspDeinitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
// Disable the NVIC for DMA
HAL_NVIC_DisableIRQ(cfg->txDmaIrqNumber);
HAL_NVIC_DisableIRQ(cfg->rxDmaIrqNumber);
}
void spi::halMspInitPolling(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
@ -156,7 +153,7 @@ void spi::halMspDeinitPolling(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
void spi::halMspInitInterrupt(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
auto cfg = dynamic_cast<MspIrqConfigStruct*>(cfgBase);
if(cfg == nullptr or hspi == nullptr) {
if (cfg == nullptr or hspi == nullptr) {
return;
}
@ -175,28 +172,20 @@ void spi::halMspDeinitInterrupt(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
}
void spi::getMspInitFunction(msp_func_t* init_func, MspCfgBase** args) {
if(init_func != NULL && args != NULL) {
if (init_func != NULL && args != NULL) {
*init_func = mspInitFunc;
*args = mspInitArgs;
}
}
void spi::getMspDeinitFunction(msp_func_t* deinit_func, MspCfgBase** args) {
if(deinit_func != NULL && args != NULL) {
if (deinit_func != NULL && args != NULL) {
*deinit_func = mspDeinitFunc;
*args = mspDeinitArgs;
}
}
void spi::setSpiDmaMspFunctions(MspDmaConfigStruct* cfg,
msp_func_t initFunc, msp_func_t deinitFunc) {
mspInitFunc = initFunc;
mspDeinitFunc = deinitFunc;
mspInitArgs = cfg;
mspDeinitArgs = cfg;
}
void spi::setSpiIrqMspFunctions(MspIrqConfigStruct *cfg, msp_func_t initFunc,
void spi::setSpiDmaMspFunctions(MspDmaConfigStruct* cfg, msp_func_t initFunc,
msp_func_t deinitFunc) {
mspInitFunc = initFunc;
mspDeinitFunc = deinitFunc;
@ -204,7 +193,15 @@ void spi::setSpiIrqMspFunctions(MspIrqConfigStruct *cfg, msp_func_t initFunc,
mspDeinitArgs = cfg;
}
void spi::setSpiPollingMspFunctions(MspPollingConfigStruct *cfg, msp_func_t initFunc,
void spi::setSpiIrqMspFunctions(MspIrqConfigStruct* cfg, msp_func_t initFunc,
msp_func_t deinitFunc) {
mspInitFunc = initFunc;
mspDeinitFunc = deinitFunc;
mspInitArgs = cfg;
mspDeinitArgs = cfg;
}
void spi::setSpiPollingMspFunctions(MspPollingConfigStruct* cfg, msp_func_t initFunc,
msp_func_t deinitFunc) {
mspInitFunc = initFunc;
mspDeinitFunc = deinitFunc;
@ -222,11 +219,10 @@ void spi::setSpiPollingMspFunctions(MspPollingConfigStruct *cfg, msp_func_t init
* @param hspi: SPI handle pointer
* @retval None
*/
extern "C" void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi) {
if(mspInitFunc != NULL) {
extern "C" void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) {
if (mspInitFunc != NULL) {
mspInitFunc(hspi, mspInitArgs);
}
else {
} else {
printf("HAL_SPI_MspInit: Please call set_msp_functions to assign SPI MSP functions\n");
}
}
@ -239,15 +235,14 @@ extern "C" void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi) {
* @param hspi: SPI handle pointer
* @retval None
*/
extern "C" void HAL_SPI_MspDeInit(SPI_HandleTypeDef *hspi) {
if(mspDeinitFunc != NULL) {
extern "C" void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) {
if (mspDeinitFunc != NULL) {
mspDeinitFunc(hspi, mspDeinitArgs);
}
else {
} else {
printf("HAL_SPI_MspDeInit: Please call set_msp_functions to assign SPI MSP functions\n");
}
}
void spi::mspErrorHandler(const char* const function, const char *const message) {
void spi::mspErrorHandler(const char* const function, const char* const message) {
printf("%s failure: %s\n", function, message);
}

View File

@ -1,19 +1,18 @@
#ifndef FSFW_HAL_STM32H7_SPI_MSPINIT_H_
#define FSFW_HAL_STM32H7_SPI_MSPINIT_H_
#include "spiDefinitions.h"
#include <cstdint>
#include "../definitions.h"
#include "../dma.h"
#include "spiDefinitions.h"
#include "stm32h7xx_hal_spi.h"
#include <cstdint>
#ifdef __cplusplus
extern "C" {
#endif
using mspCb = void (*) (void);
using mspCb = void (*)(void);
/**
* @brief This file provides MSP implementation for DMA, IRQ and Polling mode for the
@ -24,9 +23,8 @@ namespace spi {
struct MspCfgBase {
MspCfgBase();
MspCfgBase(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso,
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr):
sck(sck), mosi(mosi), miso(miso), cleanupCb(cleanupCb),
setupCb(setupCb) {}
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr)
: sck(sck), mosi(mosi), miso(miso), cleanupCb(cleanupCb), setupCb(setupCb) {}
virtual ~MspCfgBase() = default;
@ -38,20 +36,20 @@ struct MspCfgBase {
mspCb setupCb = nullptr;
};
struct MspPollingConfigStruct: public MspCfgBase {
MspPollingConfigStruct(): MspCfgBase() {};
struct MspPollingConfigStruct : public MspCfgBase {
MspPollingConfigStruct() : MspCfgBase(){};
MspPollingConfigStruct(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso,
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr):
MspCfgBase(sck, mosi, miso, cleanupCb, setupCb) {}
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr)
: MspCfgBase(sck, mosi, miso, cleanupCb, setupCb) {}
};
/* A valid instance of this struct must be passed to the MSP initialization function as a void*
argument */
struct MspIrqConfigStruct: public MspPollingConfigStruct {
MspIrqConfigStruct(): MspPollingConfigStruct() {};
struct MspIrqConfigStruct : public MspPollingConfigStruct {
MspIrqConfigStruct() : MspPollingConfigStruct(){};
MspIrqConfigStruct(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso,
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr):
MspPollingConfigStruct(sck, mosi, miso, cleanupCb, setupCb) {}
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr)
: MspPollingConfigStruct(sck, mosi, miso, cleanupCb, setupCb) {}
SpiBus spiBus = SpiBus::SPI_1;
user_handler_t spiIrqHandler = nullptr;
@ -65,12 +63,12 @@ struct MspIrqConfigStruct: public MspPollingConfigStruct {
/* A valid instance of this struct must be passed to the MSP initialization function as a void*
argument */
struct MspDmaConfigStruct: public MspIrqConfigStruct {
MspDmaConfigStruct(): MspIrqConfigStruct() {};
struct MspDmaConfigStruct : public MspIrqConfigStruct {
MspDmaConfigStruct() : MspIrqConfigStruct(){};
MspDmaConfigStruct(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso,
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr):
MspIrqConfigStruct(sck, mosi, miso, cleanupCb, setupCb) {}
void (* dmaClkEnableWrapper) (void) = nullptr;
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr)
: MspIrqConfigStruct(sck, mosi, miso, cleanupCb, setupCb) {}
void (*dmaClkEnableWrapper)(void) = nullptr;
dma::DMAIndexes txDmaIndex = dma::DMAIndexes::DMA_1;
dma::DMAIndexes rxDmaIndex = dma::DMAIndexes::DMA_1;
@ -85,11 +83,10 @@ struct MspDmaConfigStruct: public MspIrqConfigStruct {
IrqPriorities rxSubpriority = IrqPriorities::LOWEST;
};
using msp_func_t = void (*) (SPI_HandleTypeDef* hspi, MspCfgBase* cfg);
using msp_func_t = void (*)(SPI_HandleTypeDef* hspi, MspCfgBase* cfg);
void getMspInitFunction(msp_func_t* init_func, MspCfgBase **args);
void getMspDeinitFunction(msp_func_t* deinit_func, MspCfgBase **args);
void getMspInitFunction(msp_func_t* init_func, MspCfgBase** args);
void getMspDeinitFunction(msp_func_t* deinit_func, MspCfgBase** args);
void halMspInitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfg);
void halMspDeinitDma(SPI_HandleTypeDef* hspi, MspCfgBase* cfg);
@ -107,23 +104,17 @@ void halMspDeinitPolling(SPI_HandleTypeDef* hspi, MspCfgBase* cfg);
* @param deinit_func
* @param deinit_args
*/
void setSpiDmaMspFunctions(MspDmaConfigStruct* cfg,
msp_func_t initFunc = &spi::halMspInitDma,
msp_func_t deinitFunc= &spi::halMspDeinitDma
);
void setSpiIrqMspFunctions(MspIrqConfigStruct* cfg,
msp_func_t initFunc = &spi::halMspInitInterrupt,
msp_func_t deinitFunc= &spi::halMspDeinitInterrupt
);
void setSpiDmaMspFunctions(MspDmaConfigStruct* cfg, msp_func_t initFunc = &spi::halMspInitDma,
msp_func_t deinitFunc = &spi::halMspDeinitDma);
void setSpiIrqMspFunctions(MspIrqConfigStruct* cfg, msp_func_t initFunc = &spi::halMspInitInterrupt,
msp_func_t deinitFunc = &spi::halMspDeinitInterrupt);
void setSpiPollingMspFunctions(MspPollingConfigStruct* cfg,
msp_func_t initFunc = &spi::halMspInitPolling,
msp_func_t deinitFunc= &spi::halMspDeinitPolling
);
msp_func_t deinitFunc = &spi::halMspDeinitPolling);
void mspErrorHandler(const char* const function, const char *const message);
}
void mspErrorHandler(const char* const function, const char* const message);
} // namespace spi
#ifdef __cplusplus
}

View File

@ -1,8 +1,9 @@
#include "fsfw_hal/stm32h7/spi/spiCore.h"
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
#include <cstdio>
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
SPI_HandleTypeDef* spiHandle = nullptr;
DMA_HandleTypeDef* hdmaTx = nullptr;
DMA_HandleTypeDef* hdmaRx = nullptr;
@ -18,19 +19,18 @@ void* errorArgs = nullptr;
void mapIndexAndStream(DMA_HandleTypeDef* handle, dma::DMAType dmaType, dma::DMAIndexes dmaIdx,
dma::DMAStreams dmaStream, IRQn_Type* dmaIrqNumber);
void mapSpiBus(DMA_HandleTypeDef *handle, dma::DMAType dmaType, spi::SpiBus spiBus);
void mapSpiBus(DMA_HandleTypeDef* handle, dma::DMAType dmaType, spi::SpiBus spiBus);
void spi::configureDmaHandle(DMA_HandleTypeDef *handle, spi::SpiBus spiBus, dma::DMAType dmaType,
dma::DMAIndexes dmaIdx, dma::DMAStreams dmaStream, IRQn_Type* dmaIrqNumber,
uint32_t dmaMode, uint32_t dmaPriority) {
void spi::configureDmaHandle(DMA_HandleTypeDef* handle, spi::SpiBus spiBus, dma::DMAType dmaType,
dma::DMAIndexes dmaIdx, dma::DMAStreams dmaStream,
IRQn_Type* dmaIrqNumber, uint32_t dmaMode, uint32_t dmaPriority) {
using namespace dma;
mapIndexAndStream(handle, dmaType, dmaIdx, dmaStream, dmaIrqNumber);
mapSpiBus(handle, dmaType, spiBus);
if(dmaType == DMAType::TX) {
if (dmaType == DMAType::TX) {
handle->Init.Direction = DMA_MEMORY_TO_PERIPH;
}
else {
} else {
handle->Init.Direction = DMA_PERIPH_TO_MEMORY;
}
@ -58,48 +58,43 @@ void spi::getDmaHandles(DMA_HandleTypeDef** txHandle, DMA_HandleTypeDef** rxHand
*rxHandle = hdmaRx;
}
void spi::setSpiHandle(SPI_HandleTypeDef *spiHandle_) {
if(spiHandle_ == NULL) {
void spi::setSpiHandle(SPI_HandleTypeDef* spiHandle_) {
if (spiHandle_ == NULL) {
return;
}
spiHandle = spiHandle_;
}
void spi::assignTransferRxTxCompleteCallback(spi_transfer_cb_t callback, void *userArgs) {
void spi::assignTransferRxTxCompleteCallback(spi_transfer_cb_t callback, void* userArgs) {
rxTxCb = callback;
rxTxArgs = userArgs;
}
void spi::assignTransferRxCompleteCallback(spi_transfer_cb_t callback, void *userArgs) {
void spi::assignTransferRxCompleteCallback(spi_transfer_cb_t callback, void* userArgs) {
rxCb = callback;
rxArgs = userArgs;
}
void spi::assignTransferTxCompleteCallback(spi_transfer_cb_t callback, void *userArgs) {
void spi::assignTransferTxCompleteCallback(spi_transfer_cb_t callback, void* userArgs) {
txCb = callback;
txArgs = userArgs;
}
void spi::assignTransferErrorCallback(spi_transfer_cb_t callback, void *userArgs) {
void spi::assignTransferErrorCallback(spi_transfer_cb_t callback, void* userArgs) {
errorCb = callback;
errorArgs = userArgs;
}
SPI_HandleTypeDef* spi::getSpiHandle() {
return spiHandle;
}
SPI_HandleTypeDef* spi::getSpiHandle() { return spiHandle; }
/**
* @brief TxRx Transfer completed callback.
* @param hspi: SPI handle
*/
extern "C" void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi) {
if(rxTxCb != NULL) {
extern "C" void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef* hspi) {
if (rxTxCb != NULL) {
rxTxCb(hspi, rxTxArgs);
}
else {
} else {
printf("HAL_SPI_TxRxCpltCallback: No user callback specified\n");
}
}
@ -108,11 +103,10 @@ extern "C" void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi) {
* @brief TxRx Transfer completed callback.
* @param hspi: SPI handle
*/
extern "C" void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi) {
if(txCb != NULL) {
extern "C" void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef* hspi) {
if (txCb != NULL) {
txCb(hspi, txArgs);
}
else {
} else {
printf("HAL_SPI_TxCpltCallback: No user callback specified\n");
}
}
@ -121,11 +115,10 @@ extern "C" void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi) {
* @brief TxRx Transfer completed callback.
* @param hspi: SPI handle
*/
extern "C" void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi) {
if(rxCb != nullptr) {
extern "C" void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef* hspi) {
if (rxCb != nullptr) {
rxCb(hspi, rxArgs);
}
else {
} else {
printf("HAL_SPI_RxCpltCallback: No user callback specified\n");
}
}
@ -137,11 +130,10 @@ extern "C" void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi) {
* add your own implementation.
* @retval None
*/
extern "C" void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi) {
if(errorCb != nullptr) {
extern "C" void HAL_SPI_ErrorCallback(SPI_HandleTypeDef* hspi) {
if (errorCb != nullptr) {
errorCb(hspi, rxArgs);
}
else {
} else {
printf("HAL_SPI_ErrorCallback: No user callback specified\n");
}
}
@ -149,160 +141,159 @@ extern "C" void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi) {
void mapIndexAndStream(DMA_HandleTypeDef* handle, dma::DMAType dmaType, dma::DMAIndexes dmaIdx,
dma::DMAStreams dmaStream, IRQn_Type* dmaIrqNumber) {
using namespace dma;
if(dmaIdx == DMAIndexes::DMA_1) {
if (dmaIdx == DMAIndexes::DMA_1) {
#ifdef DMA1
switch(dmaStream) {
case(DMAStreams::STREAM_0): {
switch (dmaStream) {
case (DMAStreams::STREAM_0): {
#ifdef DMA1_Stream0
handle->Instance = DMA1_Stream0;
if(dmaIrqNumber != nullptr) {
if (dmaIrqNumber != nullptr) {
*dmaIrqNumber = DMA1_Stream0_IRQn;
}
#endif
break;
}
case(DMAStreams::STREAM_1): {
case (DMAStreams::STREAM_1): {
#ifdef DMA1_Stream1
handle->Instance = DMA1_Stream1;
if(dmaIrqNumber != nullptr) {
if (dmaIrqNumber != nullptr) {
*dmaIrqNumber = DMA1_Stream1_IRQn;
}
#endif
break;
}
case(DMAStreams::STREAM_2): {
case (DMAStreams::STREAM_2): {
#ifdef DMA1_Stream2
handle->Instance = DMA1_Stream2;
if(dmaIrqNumber != nullptr) {
if (dmaIrqNumber != nullptr) {
*dmaIrqNumber = DMA1_Stream2_IRQn;
}
#endif
break;
}
case(DMAStreams::STREAM_3): {
case (DMAStreams::STREAM_3): {
#ifdef DMA1_Stream3
handle->Instance = DMA1_Stream3;
if(dmaIrqNumber != nullptr) {
if (dmaIrqNumber != nullptr) {
*dmaIrqNumber = DMA1_Stream3_IRQn;
}
#endif
break;
}
case(DMAStreams::STREAM_4): {
case (DMAStreams::STREAM_4): {
#ifdef DMA1_Stream4
handle->Instance = DMA1_Stream4;
if(dmaIrqNumber != nullptr) {
if (dmaIrqNumber != nullptr) {
*dmaIrqNumber = DMA1_Stream4_IRQn;
}
#endif
break;
}
case(DMAStreams::STREAM_5): {
case (DMAStreams::STREAM_5): {
#ifdef DMA1_Stream5
handle->Instance = DMA1_Stream5;
if(dmaIrqNumber != nullptr) {
if (dmaIrqNumber != nullptr) {
*dmaIrqNumber = DMA1_Stream5_IRQn;
}
#endif
break;
}
case(DMAStreams::STREAM_6): {
case (DMAStreams::STREAM_6): {
#ifdef DMA1_Stream6
handle->Instance = DMA1_Stream6;
if(dmaIrqNumber != nullptr) {
if (dmaIrqNumber != nullptr) {
*dmaIrqNumber = DMA1_Stream6_IRQn;
}
#endif
break;
}
case(DMAStreams::STREAM_7): {
case (DMAStreams::STREAM_7): {
#ifdef DMA1_Stream7
handle->Instance = DMA1_Stream7;
if(dmaIrqNumber != nullptr) {
if (dmaIrqNumber != nullptr) {
*dmaIrqNumber = DMA1_Stream7_IRQn;
}
#endif
break;
}
}
if(dmaType == DMAType::TX) {
if (dmaType == DMAType::TX) {
handle->Init.Request = DMA_REQUEST_SPI1_TX;
}
else {
} else {
handle->Init.Request = DMA_REQUEST_SPI1_RX;
}
#endif /* DMA1 */
}
if(dmaIdx == DMAIndexes::DMA_2) {
if (dmaIdx == DMAIndexes::DMA_2) {
#ifdef DMA2
switch(dmaStream) {
case(DMAStreams::STREAM_0): {
switch (dmaStream) {
case (DMAStreams::STREAM_0): {
#ifdef DMA2_Stream0
handle->Instance = DMA2_Stream0;
if(dmaIrqNumber != nullptr) {
if (dmaIrqNumber != nullptr) {
*dmaIrqNumber = DMA2_Stream0_IRQn;
}
#endif
break;
}
case(DMAStreams::STREAM_1): {
case (DMAStreams::STREAM_1): {
#ifdef DMA2_Stream1
handle->Instance = DMA2_Stream1;
if(dmaIrqNumber != nullptr) {
if (dmaIrqNumber != nullptr) {
*dmaIrqNumber = DMA2_Stream1_IRQn;
}
#endif
break;
}
case(DMAStreams::STREAM_2): {
case (DMAStreams::STREAM_2): {
#ifdef DMA2_Stream2
handle->Instance = DMA2_Stream2;
if(dmaIrqNumber != nullptr) {
if (dmaIrqNumber != nullptr) {
*dmaIrqNumber = DMA2_Stream2_IRQn;
}
#endif
break;
}
case(DMAStreams::STREAM_3): {
case (DMAStreams::STREAM_3): {
#ifdef DMA2_Stream3
handle->Instance = DMA2_Stream3;
if(dmaIrqNumber != nullptr) {
if (dmaIrqNumber != nullptr) {
*dmaIrqNumber = DMA2_Stream3_IRQn;
}
#endif
break;
}
case(DMAStreams::STREAM_4): {
case (DMAStreams::STREAM_4): {
#ifdef DMA2_Stream4
handle->Instance = DMA2_Stream4;
if(dmaIrqNumber != nullptr) {
if (dmaIrqNumber != nullptr) {
*dmaIrqNumber = DMA2_Stream4_IRQn;
}
#endif
break;
}
case(DMAStreams::STREAM_5): {
case (DMAStreams::STREAM_5): {
#ifdef DMA2_Stream5
handle->Instance = DMA2_Stream5;
if(dmaIrqNumber != nullptr) {
if (dmaIrqNumber != nullptr) {
*dmaIrqNumber = DMA2_Stream5_IRQn;
}
#endif
break;
}
case(DMAStreams::STREAM_6): {
case (DMAStreams::STREAM_6): {
#ifdef DMA2_Stream6
handle->Instance = DMA2_Stream6;
if(dmaIrqNumber != nullptr) {
if (dmaIrqNumber != nullptr) {
*dmaIrqNumber = DMA2_Stream6_IRQn;
}
#endif
break;
}
case(DMAStreams::STREAM_7): {
case (DMAStreams::STREAM_7): {
#ifdef DMA2_Stream7
handle->Instance = DMA2_Stream7;
if(dmaIrqNumber != nullptr) {
if (dmaIrqNumber != nullptr) {
*dmaIrqNumber = DMA2_Stream7_IRQn;
}
#endif
@ -313,26 +304,23 @@ void mapIndexAndStream(DMA_HandleTypeDef* handle, dma::DMAType dmaType, dma::DMA
}
}
void mapSpiBus(DMA_HandleTypeDef *handle, dma::DMAType dmaType, spi::SpiBus spiBus) {
if(dmaType == dma::DMAType::TX) {
if(spiBus == spi::SpiBus::SPI_1) {
void mapSpiBus(DMA_HandleTypeDef* handle, dma::DMAType dmaType, spi::SpiBus spiBus) {
if (dmaType == dma::DMAType::TX) {
if (spiBus == spi::SpiBus::SPI_1) {
#ifdef DMA_REQUEST_SPI1_TX
handle->Init.Request = DMA_REQUEST_SPI1_TX;
#endif
}
else if(spiBus == spi::SpiBus::SPI_2) {
} else if (spiBus == spi::SpiBus::SPI_2) {
#ifdef DMA_REQUEST_SPI2_TX
handle->Init.Request = DMA_REQUEST_SPI2_TX;
#endif
}
}
else {
if(spiBus == spi::SpiBus::SPI_1) {
} else {
if (spiBus == spi::SpiBus::SPI_1) {
#ifdef DMA_REQUEST_SPI1_RX
handle->Init.Request = DMA_REQUEST_SPI1_RX;
#endif
}
else if(spiBus == spi::SpiBus::SPI_2) {
} else if (spiBus == spi::SpiBus::SPI_2) {
#ifdef DMA_REQUEST_SPI2_RX
handle->Init.Request = DMA_REQUEST_SPI2_RX;
#endif

View File

@ -3,7 +3,6 @@
#include "fsfw_hal/stm32h7/dma.h"
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
#include "stm32h7xx_hal.h"
#include "stm32h7xx_hal_dma.h"
@ -11,14 +10,13 @@
extern "C" {
#endif
using spi_transfer_cb_t = void (*) (SPI_HandleTypeDef *hspi, void* userArgs);
using spi_transfer_cb_t = void (*)(SPI_HandleTypeDef* hspi, void* userArgs);
namespace spi {
void configureDmaHandle(DMA_HandleTypeDef* handle, spi::SpiBus spiBus,
dma::DMAType dmaType, dma::DMAIndexes dmaIdx,
dma::DMAStreams dmaStream, IRQn_Type* dmaIrqNumber, uint32_t dmaMode = DMA_NORMAL,
uint32_t dmaPriority = DMA_PRIORITY_LOW);
void configureDmaHandle(DMA_HandleTypeDef* handle, spi::SpiBus spiBus, dma::DMAType dmaType,
dma::DMAIndexes dmaIdx, dma::DMAStreams dmaStream, IRQn_Type* dmaIrqNumber,
uint32_t dmaMode = DMA_NORMAL, uint32_t dmaPriority = DMA_PRIORITY_LOW);
/**
* Assign DMA handles. Required to use DMA for SPI transfers.
@ -32,7 +30,7 @@ void getDmaHandles(DMA_HandleTypeDef** txHandle, DMA_HandleTypeDef** rxHandle);
* Assign SPI handle. Needs to be done before using the SPI
* @param spiHandle
*/
void setSpiHandle(SPI_HandleTypeDef *spiHandle);
void setSpiHandle(SPI_HandleTypeDef* spiHandle);
void assignTransferRxTxCompleteCallback(spi_transfer_cb_t callback, void* userArgs);
void assignTransferRxCompleteCallback(spi_transfer_cb_t callback, void* userArgs);
@ -45,7 +43,7 @@ void assignTransferErrorCallback(spi_transfer_cb_t callback, void* userArgs);
*/
SPI_HandleTypeDef* getSpiHandle();
}
} // namespace spi
#ifdef __cplusplus
}

View File

@ -1,23 +1,23 @@
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
void spi::assignSpiMode(SpiModes spiMode, SPI_HandleTypeDef& spiHandle) {
switch(spiMode) {
case(SpiModes::MODE_0): {
switch (spiMode) {
case (SpiModes::MODE_0): {
spiHandle.Init.CLKPolarity = SPI_POLARITY_LOW;
spiHandle.Init.CLKPhase = SPI_PHASE_1EDGE;
break;
}
case(SpiModes::MODE_1): {
case (SpiModes::MODE_1): {
spiHandle.Init.CLKPolarity = SPI_POLARITY_LOW;
spiHandle.Init.CLKPhase = SPI_PHASE_2EDGE;
break;
}
case(SpiModes::MODE_2): {
case (SpiModes::MODE_2): {
spiHandle.Init.CLKPolarity = SPI_POLARITY_HIGH;
spiHandle.Init.CLKPhase = SPI_PHASE_1EDGE;
break;
}
case(SpiModes::MODE_3): {
case (SpiModes::MODE_3): {
spiHandle.Init.CLKPolarity = SPI_POLARITY_HIGH;
spiHandle.Init.CLKPhase = SPI_PHASE_2EDGE;
break;
@ -30,22 +30,16 @@ uint32_t spi::getPrescaler(uint32_t clock_src_freq, uint32_t baudrate_mbps) {
uint32_t spi_clk = clock_src_freq;
uint32_t presc = 0;
static const uint32_t baudrate[] = {
SPI_BAUDRATEPRESCALER_2,
SPI_BAUDRATEPRESCALER_4,
SPI_BAUDRATEPRESCALER_8,
SPI_BAUDRATEPRESCALER_16,
SPI_BAUDRATEPRESCALER_32,
SPI_BAUDRATEPRESCALER_64,
SPI_BAUDRATEPRESCALER_128,
SPI_BAUDRATEPRESCALER_256,
SPI_BAUDRATEPRESCALER_2, SPI_BAUDRATEPRESCALER_4, SPI_BAUDRATEPRESCALER_8,
SPI_BAUDRATEPRESCALER_16, SPI_BAUDRATEPRESCALER_32, SPI_BAUDRATEPRESCALER_64,
SPI_BAUDRATEPRESCALER_128, SPI_BAUDRATEPRESCALER_256,
};
while( spi_clk > baudrate_mbps) {
while (spi_clk > baudrate_mbps) {
presc = baudrate[divisor];
if (++divisor > 7)
break;
if (++divisor > 7) break;
spi_clk = ( spi_clk >> 1);
spi_clk = (spi_clk >> 1);
}
return presc;

View File

@ -2,37 +2,24 @@
#define FSFW_HAL_STM32H7_SPI_SPIDEFINITIONS_H_
#include "../../common/spi/spiCommon.h"
#include "fsfw/returnvalues/FwClassIds.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include "stm32h7xx_hal.h"
#include "stm32h7xx_hal_spi.h"
namespace spi {
static constexpr uint8_t HAL_SPI_ID = CLASS_ID::HAL_SPI;
static constexpr ReturnValue_t HAL_TIMEOUT_RETVAL = HasReturnvaluesIF::makeReturnCode(HAL_SPI_ID, 0);
static constexpr ReturnValue_t HAL_TIMEOUT_RETVAL =
HasReturnvaluesIF::makeReturnCode(HAL_SPI_ID, 0);
static constexpr ReturnValue_t HAL_BUSY_RETVAL = HasReturnvaluesIF::makeReturnCode(HAL_SPI_ID, 1);
static constexpr ReturnValue_t HAL_ERROR_RETVAL = HasReturnvaluesIF::makeReturnCode(HAL_SPI_ID, 2);
enum class TransferStates {
IDLE,
WAIT,
SUCCESS,
FAILURE
};
enum class TransferStates { IDLE, WAIT, SUCCESS, FAILURE };
enum SpiBus {
SPI_1,
SPI_2
};
enum SpiBus { SPI_1, SPI_2 };
enum TransferModes {
POLLING,
INTERRUPT,
DMA
};
enum TransferModes { POLLING, INTERRUPT, DMA };
void assignSpiMode(SpiModes spiMode, SPI_HandleTypeDef& spiHandle);
@ -44,7 +31,6 @@ void assignSpiMode(SpiModes spiMode, SPI_HandleTypeDef& spiHandle);
*/
uint32_t getPrescaler(uint32_t clock_src_freq, uint32_t baudrate_mbps);
}
} // namespace spi
#endif /* FSFW_HAL_STM32H7_SPI_SPIDEFINITIONS_H_ */

View File

@ -1,12 +1,12 @@
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
#include "fsfw_hal/stm32h7/spi/spiCore.h"
#include <stddef.h>
#include "fsfw_hal/stm32h7/spi/spiCore.h"
#include "stm32h7xx_hal.h"
#include "stm32h7xx_hal_dma.h"
#include "stm32h7xx_hal_spi.h"
#include <stddef.h>
user_handler_t spi1UserHandler = &spi::spiIrqHandler;
user_args_t spi1UserArgs = nullptr;
@ -18,11 +18,11 @@ user_args_t spi2UserArgs = nullptr;
* @param None
* @retval None
*/
void spi::dmaRxIrqHandler(void* dmaHandle) {
if(dmaHandle == nullptr) {
void spi::dmaRxIrqHandler(void *dmaHandle) {
if (dmaHandle == nullptr) {
return;
}
HAL_DMA_IRQHandler((DMA_HandleTypeDef *) dmaHandle);
HAL_DMA_IRQHandler((DMA_HandleTypeDef *)dmaHandle);
}
/**
@ -30,11 +30,11 @@ void spi::dmaRxIrqHandler(void* dmaHandle) {
* @param None
* @retval None
*/
void spi::dmaTxIrqHandler(void* dmaHandle) {
if(dmaHandle == nullptr) {
void spi::dmaTxIrqHandler(void *dmaHandle) {
if (dmaHandle == nullptr) {
return;
}
HAL_DMA_IRQHandler((DMA_HandleTypeDef *) dmaHandle);
HAL_DMA_IRQHandler((DMA_HandleTypeDef *)dmaHandle);
}
/**
@ -42,21 +42,20 @@ void spi::dmaTxIrqHandler(void* dmaHandle) {
* @param None
* @retval None
*/
void spi::spiIrqHandler(void* spiHandle) {
if(spiHandle == nullptr) {
void spi::spiIrqHandler(void *spiHandle) {
if (spiHandle == nullptr) {
return;
}
//auto currentSpiHandle = spi::getSpiHandle();
HAL_SPI_IRQHandler((SPI_HandleTypeDef *) spiHandle);
// auto currentSpiHandle = spi::getSpiHandle();
HAL_SPI_IRQHandler((SPI_HandleTypeDef *)spiHandle);
}
void spi::assignSpiUserHandler(spi::SpiBus spiIdx, user_handler_t userHandler,
user_args_t userArgs) {
if(spiIdx == spi::SpiBus::SPI_1) {
if (spiIdx == spi::SpiBus::SPI_1) {
spi1UserHandler = userHandler;
spi1UserArgs = userArgs;
}
else {
} else {
spi2UserHandler = userHandler;
spi2UserArgs = userArgs;
}
@ -64,24 +63,22 @@ void spi::assignSpiUserHandler(spi::SpiBus spiIdx, user_handler_t userHandler,
void spi::getSpiUserHandler(spi::SpiBus spiBus, user_handler_t *userHandler,
user_args_t *userArgs) {
if(userHandler == nullptr or userArgs == nullptr) {
if (userHandler == nullptr or userArgs == nullptr) {
return;
}
if(spiBus == spi::SpiBus::SPI_1) {
if (spiBus == spi::SpiBus::SPI_1) {
*userArgs = spi1UserArgs;
*userHandler = spi1UserHandler;
}
else {
} else {
*userArgs = spi2UserArgs;
*userHandler = spi2UserHandler;
}
}
void spi::assignSpiUserArgs(spi::SpiBus spiBus, user_args_t userArgs) {
if(spiBus == spi::SpiBus::SPI_1) {
if (spiBus == spi::SpiBus::SPI_1) {
spi1UserArgs = userArgs;
}
else {
} else {
spi2UserArgs = userArgs;
}
}
@ -90,7 +87,7 @@ void spi::assignSpiUserArgs(spi::SpiBus spiBus, user_args_t userArgs) {
defined in the startup_stm32h743xx.s files! */
extern "C" void SPI1_IRQHandler() {
if(spi1UserHandler != NULL) {
if (spi1UserHandler != NULL) {
spi1UserHandler(spi1UserArgs);
return;
}
@ -98,7 +95,7 @@ extern "C" void SPI1_IRQHandler() {
}
extern "C" void SPI2_IRQHandler() {
if(spi2UserHandler != nullptr) {
if (spi2UserHandler != nullptr) {
spi2UserHandler(spi2UserArgs);
return;
}

View File

@ -18,10 +18,8 @@ void assignSpiUserArgs(spi::SpiBus spiBus, user_args_t userArgs);
* @param user_handler
* @param user_args
*/
void assignSpiUserHandler(spi::SpiBus spiBus, user_handler_t user_handler,
user_args_t user_args);
void getSpiUserHandler(spi::SpiBus spiBus, user_handler_t* user_handler,
user_args_t* user_args);
void assignSpiUserHandler(spi::SpiBus spiBus, user_handler_t user_handler, user_args_t user_args);
void getSpiUserHandler(spi::SpiBus spiBus, user_handler_t* user_handler, user_args_t* user_args);
/**
* Generic interrupt handlers supplied for convenience. Do not call these directly! Set them
@ -32,7 +30,7 @@ void dmaRxIrqHandler(void* dma_handle);
void dmaTxIrqHandler(void* dma_handle);
void spiIrqHandler(void* spi_handle);
}
} // namespace spi
#ifdef __cplusplus
}

View File

@ -1,12 +1,12 @@
#include "fsfw_hal/stm32h7/spi/stm32h743zi.h"
#include "fsfw_hal/stm32h7/spi/spiCore.h"
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
#include "stm32h7xx_hal.h"
#include "stm32h7xx_hal_rcc.h"
#include <cstdio>
#include "fsfw_hal/stm32h7/spi/spiCore.h"
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
#include "stm32h7xx_hal.h"
#include "stm32h7xx_hal_rcc.h"
void spiSetupWrapper() {
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
@ -18,9 +18,7 @@ void spiCleanUpWrapper() {
__HAL_RCC_SPI1_RELEASE_RESET();
}
void spiDmaClockEnableWrapper() {
__HAL_RCC_DMA2_CLK_ENABLE();
}
void spiDmaClockEnableWrapper() { __HAL_RCC_DMA2_CLK_ENABLE(); }
void stm32h7::h743zi::standardPollingCfg(spi::MspPollingConfigStruct& cfg) {
cfg.setupCb = &spiSetupWrapper;
@ -46,7 +44,7 @@ void stm32h7::h743zi::standardInterruptCfg(spi::MspIrqConfigStruct& cfg, IrqPrio
user_handler_t spiUserHandler = nullptr;
user_args_t spiUserArgs = nullptr;
getSpiUserHandler(spi::SpiBus::SPI_1, &spiUserHandler, &spiUserArgs);
if(spiUserHandler == nullptr) {
if (spiUserHandler == nullptr) {
printf("spi::h743zi::standardInterruptCfg: Invalid SPI user handlers\n");
return;
}
@ -56,8 +54,9 @@ void stm32h7::h743zi::standardInterruptCfg(spi::MspIrqConfigStruct& cfg, IrqPrio
}
void stm32h7::h743zi::standardDmaCfg(spi::MspDmaConfigStruct& cfg, IrqPriorities spiIrqPrio,
IrqPriorities txIrqPrio, IrqPriorities rxIrqPrio, IrqPriorities spiSubprio,
IrqPriorities txSubprio, IrqPriorities rxSubprio) {
IrqPriorities txIrqPrio, IrqPriorities rxIrqPrio,
IrqPriorities spiSubprio, IrqPriorities txSubprio,
IrqPriorities rxSubprio) {
cfg.dmaClkEnableWrapper = &spiDmaClockEnableWrapper;
cfg.rxDmaIndex = dma::DMAIndexes::DMA_2;
cfg.txDmaIndex = dma::DMAIndexes::DMA_2;
@ -66,7 +65,7 @@ void stm32h7::h743zi::standardDmaCfg(spi::MspDmaConfigStruct& cfg, IrqPriorities
DMA_HandleTypeDef* txHandle;
DMA_HandleTypeDef* rxHandle;
spi::getDmaHandles(&txHandle, &rxHandle);
if(txHandle == nullptr or rxHandle == nullptr) {
if (txHandle == nullptr or rxHandle == nullptr) {
printf("spi::h743zi::standardDmaCfg: Invalid DMA handles\n");
return;
}

View File

@ -10,13 +10,11 @@ namespace h743zi {
void standardPollingCfg(spi::MspPollingConfigStruct& cfg);
void standardInterruptCfg(spi::MspIrqConfigStruct& cfg, IrqPriorities spiIrqPrio,
IrqPriorities spiSubprio = HIGHEST);
void standardDmaCfg(spi::MspDmaConfigStruct& cfg, IrqPriorities spiIrqPrio,
IrqPriorities txIrqPrio, IrqPriorities rxIrqPrio,
IrqPriorities spiSubprio = HIGHEST, IrqPriorities txSubPrio = HIGHEST,
IrqPriorities rxSubprio = HIGHEST);
void standardDmaCfg(spi::MspDmaConfigStruct& cfg, IrqPriorities spiIrqPrio, IrqPriorities txIrqPrio,
IrqPriorities rxIrqPrio, IrqPriorities spiSubprio = HIGHEST,
IrqPriorities txSubPrio = HIGHEST, IrqPriorities rxSubprio = HIGHEST);
}
}
} // namespace h743zi
} // namespace stm32h7
#endif /* FSFW_HAL_STM32H7_SPI_STM32H743ZISPI_H_ */

View File

@ -4,8 +4,8 @@
#include "fsfw/action/ActionHelper.h"
#include "fsfw/action/ActionMessage.h"
#include "fsfw/action/CommandActionHelper.h"
#include "fsfw/action/HasActionsIF.h"
#include "fsfw/action/CommandsActionsIF.h"
#include "fsfw/action/HasActionsIF.h"
#include "fsfw/action/SimpleActionHelper.h"
#endif /* FSFW_INC_FSFW_ACTION_H_ */

View File

@ -1,22 +1,17 @@
#include "fsfw/action.h"
#include "fsfw/ipc/MessageQueueSenderIF.h"
#include "fsfw/objectmanager/ObjectManager.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
ActionHelper::ActionHelper(HasActionsIF* setOwner,
MessageQueueIF* useThisQueue) :
owner(setOwner), queueToUse(useThisQueue) {
}
ActionHelper::ActionHelper(HasActionsIF* setOwner, MessageQueueIF* useThisQueue)
: owner(setOwner), queueToUse(useThisQueue) {}
ActionHelper::~ActionHelper() {
}
ActionHelper::~ActionHelper() {}
ReturnValue_t ActionHelper::handleActionMessage(CommandMessage* command) {
if (command->getCommand() == ActionMessage::EXECUTE_ACTION) {
ActionId_t currentAction = ActionMessage::getActionId(command);
prepareExecution(command->getSender(), currentAction,
ActionMessage::getStoreId(command));
prepareExecution(command->getSender(), currentAction, ActionMessage::getStoreId(command));
return HasReturnvaluesIF::RETURN_OK;
} else {
return CommandMessage::UNKNOWN_COMMAND;
@ -28,11 +23,11 @@ ReturnValue_t ActionHelper::initialize(MessageQueueIF* queueToUse_) {
if (ipcStore == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED;
}
if(queueToUse_ != nullptr) {
if (queueToUse_ != nullptr) {
setQueueToUse(queueToUse_);
}
if(queueToUse == nullptr) {
if (queueToUse == nullptr) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "ActionHelper::initialize: No queue set" << std::endl;
@ -46,8 +41,8 @@ ReturnValue_t ActionHelper::initialize(MessageQueueIF* queueToUse_) {
return HasReturnvaluesIF::RETURN_OK;
}
void ActionHelper::step(uint8_t step, MessageQueueId_t reportTo,
ActionId_t commandId, ReturnValue_t result) {
void ActionHelper::step(uint8_t step, MessageQueueId_t reportTo, ActionId_t commandId,
ReturnValue_t result) {
CommandMessage reply;
ActionMessage::setStepReply(&reply, commandId, step + STEP_OFFSET, result);
queueToUse->sendMessage(reportTo, &reply);
@ -60,12 +55,10 @@ void ActionHelper::finish(bool success, MessageQueueId_t reportTo, ActionId_t co
queueToUse->sendMessage(reportTo, &reply);
}
void ActionHelper::setQueueToUse(MessageQueueIF* queue) {
queueToUse = queue;
}
void ActionHelper::setQueueToUse(MessageQueueIF* queue) { queueToUse = queue; }
void ActionHelper::prepareExecution(MessageQueueId_t commandedBy,
ActionId_t actionId, store_address_t dataAddress) {
void ActionHelper::prepareExecution(MessageQueueId_t commandedBy, ActionId_t actionId,
store_address_t dataAddress) {
const uint8_t* dataPtr = NULL;
size_t size = 0;
ReturnValue_t result = ipcStore->getData(dataAddress, &dataPtr, &size);
@ -77,7 +70,7 @@ void ActionHelper::prepareExecution(MessageQueueId_t commandedBy,
}
result = owner->executeAction(actionId, commandedBy, dataPtr, size);
ipcStore->deleteData(dataAddress);
if(result == HasActionsIF::EXECUTION_FINISHED) {
if (result == HasActionsIF::EXECUTION_FINISHED) {
CommandMessage reply;
ActionMessage::setCompletionReply(&reply, actionId, true, result);
queueToUse->sendMessage(commandedBy, &reply);
@ -90,31 +83,30 @@ void ActionHelper::prepareExecution(MessageQueueId_t commandedBy,
}
}
ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo,
ActionId_t replyId, SerializeIF* data, bool hideSender) {
ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo, ActionId_t replyId,
SerializeIF* data, bool hideSender) {
CommandMessage reply;
store_address_t storeAddress;
uint8_t *dataPtr;
uint8_t* dataPtr;
size_t maxSize = data->getSerializedSize();
if (maxSize == 0) {
/* No error, there's simply nothing to report. */
return HasReturnvaluesIF::RETURN_OK;
}
size_t size = 0;
ReturnValue_t result = ipcStore->getFreeElement(&storeAddress, maxSize,
&dataPtr);
ReturnValue_t result = ipcStore->getFreeElement(&storeAddress, maxSize, &dataPtr);
if (result != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "ActionHelper::reportData: Getting free element from IPC store failed!" <<
std::endl;
sif::warning << "ActionHelper::reportData: Getting free element from IPC store failed!"
<< std::endl;
#else
sif::printWarning("ActionHelper::reportData: Getting free element from IPC "
sif::printWarning(
"ActionHelper::reportData: Getting free element from IPC "
"store failed!\n");
#endif
return result;
}
result = data->serialize(&dataPtr, &size, maxSize,
SerializeIF::Endianness::BIG);
result = data->serialize(&dataPtr, &size, maxSize, SerializeIF::Endianness::BIG);
if (result != HasReturnvaluesIF::RETURN_OK) {
ipcStore->deleteData(storeAddress);
return result;
@ -128,23 +120,20 @@ ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo,
as unrequested reply, this will be done here. */
if (hideSender) {
result = MessageQueueSenderIF::sendMessage(reportTo, &reply);
}
else {
} else {
result = queueToUse->sendMessage(reportTo, &reply);
}
if (result != HasReturnvaluesIF::RETURN_OK){
if (result != HasReturnvaluesIF::RETURN_OK) {
ipcStore->deleteData(storeAddress);
}
return result;
}
void ActionHelper::resetHelper() {
}
void ActionHelper::resetHelper() {}
ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo,
ActionId_t replyId, const uint8_t *data, size_t dataSize,
bool hideSender) {
ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo, ActionId_t replyId,
const uint8_t* data, size_t dataSize, bool hideSender) {
CommandMessage reply;
store_address_t storeAddress;
ReturnValue_t result = ipcStore->addData(&storeAddress, data, dataSize);
@ -165,8 +154,7 @@ ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo,
as unrequested reply, this will be done here. */
if (hideSender) {
result = MessageQueueSenderIF::sendMessage(reportTo, &reply);
}
else {
} else {
result = queueToUse->sendMessage(reportTo, &reply);
}

View File

@ -1,9 +1,9 @@
#ifndef FSFW_ACTION_ACTIONHELPER_H_
#define FSFW_ACTION_ACTIONHELPER_H_
#include "ActionMessage.h"
#include "../serialize/SerializeIF.h"
#include "../ipc/MessageQueueIF.h"
#include "../serialize/SerializeIF.h"
#include "ActionMessage.h"
/**
* @brief Action Helper is a helper class which handles action messages
*
@ -17,7 +17,7 @@
class HasActionsIF;
class ActionHelper {
public:
public:
/**
* Constructor of the action helper
* @param setOwner Pointer to the owner of the interface
@ -57,8 +57,7 @@ public:
* @param commandId ID of the executed command
* @param result Result of the execution
*/
void step(uint8_t step, MessageQueueId_t reportTo,
ActionId_t commandId,
void step(uint8_t step, MessageQueueId_t reportTo, ActionId_t commandId,
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK);
/**
* Function to be called by the owner to send a action completion message
@ -78,8 +77,8 @@ public:
* @param data Pointer to the data
* @return Returns RETURN_OK if successful, otherwise failure code
*/
ReturnValue_t reportData(MessageQueueId_t reportTo, ActionId_t replyId,
SerializeIF* data, bool hideSender = false);
ReturnValue_t reportData(MessageQueueId_t reportTo, ActionId_t replyId, SerializeIF* data,
bool hideSender = false);
/**
* Function to be called by the owner if an action does report data.
* Takes the raw data and writes it into the IPC store.
@ -89,16 +88,17 @@ public:
* @param data Pointer to the data
* @return Returns RETURN_OK if successful, otherwise failure code
*/
ReturnValue_t reportData(MessageQueueId_t reportTo, ActionId_t replyId,
const uint8_t* data, size_t dataSize, bool hideSender = false);
ReturnValue_t reportData(MessageQueueId_t reportTo, ActionId_t replyId, const uint8_t* data,
size_t dataSize, bool hideSender = false);
/**
* Function to setup the MessageQueueIF* of the helper. Can be used to
* set the MessageQueueIF* if message queue is unavailable at construction
* and initialize but must be setup before first call of other functions.
* @param queue Queue to be used by the helper
*/
void setQueueToUse(MessageQueueIF *queue);
protected:
void setQueueToUse(MessageQueueIF* queue);
protected:
//! Increase of value of this per step
static const uint8_t STEP_OFFSET = 1;
//! Pointer to the owner
@ -115,8 +115,8 @@ protected:
* @param actionId ID of action to be done
* @param dataAddress Address of additional data in IPC Store
*/
virtual void prepareExecution(MessageQueueId_t commandedBy,
ActionId_t actionId, store_address_t dataAddress);
virtual void prepareExecution(MessageQueueId_t commandedBy, ActionId_t actionId,
store_address_t dataAddress);
/**
* @brief Default implementation is empty.
*/

View File

@ -1,13 +1,10 @@
#include "fsfw/action.h"
#include "fsfw/objectmanager/ObjectManager.h"
#include "fsfw/storagemanager/StorageManagerIF.h"
ActionMessage::ActionMessage() {
}
ActionMessage::ActionMessage() {}
ActionMessage::~ActionMessage() {
}
ActionMessage::~ActionMessage() {}
void ActionMessage::setCommand(CommandMessage* message, ActionId_t fid,
store_address_t parameters) {
@ -52,12 +49,11 @@ void ActionMessage::setDataReply(CommandMessage* message, ActionId_t actionId,
message->setParameter2(data.raw);
}
void ActionMessage::setCompletionReply(CommandMessage* message,
ActionId_t fid, bool success, ReturnValue_t result) {
void ActionMessage::setCompletionReply(CommandMessage* message, ActionId_t fid, bool success,
ReturnValue_t result) {
if (success) {
message->setCommand(COMPLETION_SUCCESS);
}
else {
} else {
message->setCommand(COMPLETION_FAILED);
}
message->setParameter(fid);
@ -65,11 +61,11 @@ void ActionMessage::setCompletionReply(CommandMessage* message,
}
void ActionMessage::clear(CommandMessage* message) {
switch(message->getCommand()) {
switch (message->getCommand()) {
case EXECUTE_ACTION:
case DATA_REPLY: {
StorageManagerIF *ipcStore = ObjectManager::instance()->get<StorageManagerIF>(
objects::IPC_STORE);
StorageManagerIF* ipcStore =
ObjectManager::instance()->get<StorageManagerIF>(objects::IPC_STORE);
if (ipcStore != NULL) {
ipcStore->deleteData(getStoreId(message));
}

View File

@ -14,9 +14,10 @@ using ActionId_t = uint32_t;
* ActionHelper are able to process these messages.
*/
class ActionMessage {
private:
private:
ActionMessage();
public:
public:
static const uint8_t MESSAGE_ID = messagetypes::ACTION;
static const Command_t EXECUTE_ACTION = MAKE_COMMAND_ID(1);
static const Command_t STEP_SUCCESS = MAKE_COMMAND_ID(2);
@ -26,20 +27,18 @@ public:
static const Command_t COMPLETION_FAILED = MAKE_COMMAND_ID(6);
virtual ~ActionMessage();
static void setCommand(CommandMessage* message, ActionId_t fid,
store_address_t parameters);
static void setCommand(CommandMessage* message, ActionId_t fid, store_address_t parameters);
static ActionId_t getActionId(const CommandMessage* message );
static ActionId_t getActionId(const CommandMessage* message);
static store_address_t getStoreId(const CommandMessage* message);
static void setStepReply(CommandMessage* message, ActionId_t fid,
uint8_t step, ReturnValue_t result = HasReturnvaluesIF::RETURN_OK);
static uint8_t getStep(const CommandMessage* message );
static ReturnValue_t getReturnCode(const CommandMessage* message );
static void setDataReply(CommandMessage* message, ActionId_t actionId,
store_address_t data);
static void setCompletionReply(CommandMessage* message, ActionId_t fid,
bool success, ReturnValue_t result = HasReturnvaluesIF::RETURN_OK);
static void setStepReply(CommandMessage* message, ActionId_t fid, uint8_t step,
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK);
static uint8_t getStep(const CommandMessage* message);
static ReturnValue_t getReturnCode(const CommandMessage* message);
static void setDataReply(CommandMessage* message, ActionId_t actionId, store_address_t data);
static void setCompletionReply(CommandMessage* message, ActionId_t fid, bool success,
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK);
static void clear(CommandMessage* message);
};

View File

@ -1,17 +1,13 @@
#include "fsfw/action.h"
#include "fsfw/objectmanager/ObjectManager.h"
CommandActionHelper::CommandActionHelper(CommandsActionsIF *setOwner) :
owner(setOwner), queueToUse(NULL), ipcStore(
NULL), commandCount(0), lastTarget(0) {
}
CommandActionHelper::CommandActionHelper(CommandsActionsIF *setOwner)
: owner(setOwner), queueToUse(NULL), ipcStore(NULL), commandCount(0), lastTarget(0) {}
CommandActionHelper::~CommandActionHelper() {
}
CommandActionHelper::~CommandActionHelper() {}
ReturnValue_t CommandActionHelper::commandAction(object_id_t commandTo,
ActionId_t actionId, SerializeIF *data) {
ReturnValue_t CommandActionHelper::commandAction(object_id_t commandTo, ActionId_t actionId,
SerializeIF *data) {
HasActionsIF *receiver = ObjectManager::instance()->get<HasActionsIF>(commandTo);
if (receiver == NULL) {
return CommandsActionsIF::OBJECT_HAS_NO_FUNCTIONS;
@ -19,25 +15,23 @@ ReturnValue_t CommandActionHelper::commandAction(object_id_t commandTo,
store_address_t storeId;
uint8_t *storePointer;
size_t maxSize = data->getSerializedSize();
ReturnValue_t result = ipcStore->getFreeElement(&storeId, maxSize,
&storePointer);
ReturnValue_t result = ipcStore->getFreeElement(&storeId, maxSize, &storePointer);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
size_t size = 0;
result = data->serialize(&storePointer, &size, maxSize,
SerializeIF::Endianness::BIG);
result = data->serialize(&storePointer, &size, maxSize, SerializeIF::Endianness::BIG);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return sendCommand(receiver->getCommandQueue(), actionId, storeId);
}
ReturnValue_t CommandActionHelper::commandAction(object_id_t commandTo,
ActionId_t actionId, const uint8_t *data, uint32_t size) {
// if (commandCount != 0) {
// return CommandsFunctionsIF::ALREADY_COMMANDING;
// }
ReturnValue_t CommandActionHelper::commandAction(object_id_t commandTo, ActionId_t actionId,
const uint8_t *data, uint32_t size) {
// if (commandCount != 0) {
// return CommandsFunctionsIF::ALREADY_COMMANDING;
// }
HasActionsIF *receiver = ObjectManager::instance()->get<HasActionsIF>(commandTo);
if (receiver == NULL) {
return CommandsActionsIF::OBJECT_HAS_NO_FUNCTIONS;
@ -50,8 +44,8 @@ ReturnValue_t CommandActionHelper::commandAction(object_id_t commandTo,
return sendCommand(receiver->getCommandQueue(), actionId, storeId);
}
ReturnValue_t CommandActionHelper::sendCommand(MessageQueueId_t queueId,
ActionId_t actionId, store_address_t storeId) {
ReturnValue_t CommandActionHelper::sendCommand(MessageQueueId_t queueId, ActionId_t actionId,
store_address_t storeId) {
CommandMessage command;
ActionMessage::setCommand(&command, actionId, storeId);
ReturnValue_t result = queueToUse->sendMessage(queueId, &command);
@ -96,25 +90,21 @@ ReturnValue_t CommandActionHelper::handleReply(CommandMessage *reply) {
return HasReturnvaluesIF::RETURN_OK;
case ActionMessage::STEP_FAILED:
commandCount--;
owner->stepFailedReceived(ActionMessage::getActionId(reply),
ActionMessage::getStep(reply),
owner->stepFailedReceived(ActionMessage::getActionId(reply), ActionMessage::getStep(reply),
ActionMessage::getReturnCode(reply));
return HasReturnvaluesIF::RETURN_OK;
case ActionMessage::DATA_REPLY:
extractDataForOwner(ActionMessage::getActionId(reply),
ActionMessage::getStoreId(reply));
extractDataForOwner(ActionMessage::getActionId(reply), ActionMessage::getStoreId(reply));
return HasReturnvaluesIF::RETURN_OK;
default:
return HasReturnvaluesIF::RETURN_FAILED;
}
}
uint8_t CommandActionHelper::getCommandCount() const {
return commandCount;
}
uint8_t CommandActionHelper::getCommandCount() const { return commandCount; }
void CommandActionHelper::extractDataForOwner(ActionId_t actionId, store_address_t storeId) {
const uint8_t * data = NULL;
const uint8_t *data = NULL;
size_t size = 0;
ReturnValue_t result = ipcStore->getData(storeId, &data, &size);
if (result != HasReturnvaluesIF::RETURN_OK) {

View File

@ -2,35 +2,35 @@
#define COMMANDACTIONHELPER_H_
#include "ActionMessage.h"
#include "fsfw/ipc/MessageQueueIF.h"
#include "fsfw/objectmanager/ObjectManagerIF.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include "fsfw/serialize/SerializeIF.h"
#include "fsfw/storagemanager/StorageManagerIF.h"
#include "fsfw/ipc/MessageQueueIF.h"
class CommandsActionsIF;
class CommandActionHelper {
friend class CommandsActionsIF;
public:
public:
CommandActionHelper(CommandsActionsIF* owner);
virtual ~CommandActionHelper();
ReturnValue_t commandAction(object_id_t commandTo,
ActionId_t actionId, const uint8_t* data, uint32_t size);
ReturnValue_t commandAction(object_id_t commandTo,
ActionId_t actionId, SerializeIF* data);
ReturnValue_t commandAction(object_id_t commandTo, ActionId_t actionId, const uint8_t* data,
uint32_t size);
ReturnValue_t commandAction(object_id_t commandTo, ActionId_t actionId, SerializeIF* data);
ReturnValue_t initialize();
ReturnValue_t handleReply(CommandMessage* reply);
uint8_t getCommandCount() const;
private:
private:
CommandsActionsIF* owner;
MessageQueueIF* queueToUse;
StorageManagerIF* ipcStore;
uint8_t commandCount;
MessageQueueId_t lastTarget;
void extractDataForOwner(ActionId_t actionId, store_address_t storeId);
ReturnValue_t sendCommand(MessageQueueId_t queueId, ActionId_t actionId,
store_address_t storeId);
ReturnValue_t sendCommand(MessageQueueId_t queueId, ActionId_t actionId, store_address_t storeId);
};
#endif /* COMMANDACTIONHELPER_H_ */

View File

@ -1,9 +1,9 @@
#ifndef FSFW_ACTION_COMMANDSACTIONSIF_H_
#define FSFW_ACTION_COMMANDSACTIONSIF_H_
#include "CommandActionHelper.h"
#include "../returnvalues/HasReturnvaluesIF.h"
#include "../ipc/MessageQueueIF.h"
#include "../returnvalues/HasReturnvaluesIF.h"
#include "CommandActionHelper.h"
/**
* Interface to separate commanding actions of other objects.
@ -16,22 +16,20 @@
*/
class CommandsActionsIF {
friend class CommandActionHelper;
public:
public:
static const uint8_t INTERFACE_ID = CLASS_ID::COMMANDS_ACTIONS_IF;
static const ReturnValue_t OBJECT_HAS_NO_FUNCTIONS = MAKE_RETURN_CODE(1);
static const ReturnValue_t ALREADY_COMMANDING = MAKE_RETURN_CODE(2);
virtual ~CommandsActionsIF() {}
virtual MessageQueueIF* getCommandQueuePtr() = 0;
protected:
protected:
virtual void stepSuccessfulReceived(ActionId_t actionId, uint8_t step) = 0;
virtual void stepFailedReceived(ActionId_t actionId, uint8_t step,
ReturnValue_t returnCode) = 0;
virtual void dataReceived(ActionId_t actionId, const uint8_t* data,
uint32_t size) = 0;
virtual void stepFailedReceived(ActionId_t actionId, uint8_t step, ReturnValue_t returnCode) = 0;
virtual void dataReceived(ActionId_t actionId, const uint8_t* data, uint32_t size) = 0;
virtual void completionSuccessfulReceived(ActionId_t actionId) = 0;
virtual void completionFailedReceived(ActionId_t actionId,
ReturnValue_t returnCode) = 0;
virtual void completionFailedReceived(ActionId_t actionId, ReturnValue_t returnCode) = 0;
};
#endif /* FSFW_ACTION_COMMANDSACTIONSIF_H_ */

View File

@ -1,11 +1,11 @@
#ifndef FSFW_ACTION_HASACTIONSIF_H_
#define FSFW_ACTION_HASACTIONSIF_H_
#include "../ipc/MessageQueueIF.h"
#include "../returnvalues/HasReturnvaluesIF.h"
#include "ActionHelper.h"
#include "ActionMessage.h"
#include "SimpleActionHelper.h"
#include "../returnvalues/HasReturnvaluesIF.h"
#include "../ipc/MessageQueueIF.h"
/**
* @brief
@ -34,13 +34,13 @@
* @ingroup interfaces
*/
class HasActionsIF {
public:
public:
static const uint8_t INTERFACE_ID = CLASS_ID::HAS_ACTIONS_IF;
static const ReturnValue_t IS_BUSY = MAKE_RETURN_CODE(1);
static const ReturnValue_t INVALID_PARAMETERS = MAKE_RETURN_CODE(2);
static const ReturnValue_t EXECUTION_FINISHED = MAKE_RETURN_CODE(3);
static const ReturnValue_t INVALID_ACTION_ID = MAKE_RETURN_CODE(4);
virtual ~HasActionsIF() { }
virtual ~HasActionsIF() {}
/**
* Function to get the MessageQueueId_t of the implementing object
* @return MessageQueueId_t of the object
@ -55,9 +55,8 @@ public:
* -@c EXECUTION_FINISHED Finish reply will be generated
* -@c Not RETURN_OK Step failure reply will be generated
*/
virtual ReturnValue_t executeAction(ActionId_t actionId,
MessageQueueId_t commandedBy, const uint8_t* data, size_t size) = 0;
virtual ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
const uint8_t* data, size_t size) = 0;
};
#endif /* FSFW_ACTION_HASACTIONSIF_H_ */

View File

@ -1,18 +1,14 @@
#include "fsfw/action.h"
SimpleActionHelper::SimpleActionHelper(HasActionsIF* setOwner,
MessageQueueIF* useThisQueue) :
ActionHelper(setOwner, useThisQueue), isExecuting(false) {
}
SimpleActionHelper::SimpleActionHelper(HasActionsIF* setOwner, MessageQueueIF* useThisQueue)
: ActionHelper(setOwner, useThisQueue), isExecuting(false) {}
SimpleActionHelper::~SimpleActionHelper() {
}
SimpleActionHelper::~SimpleActionHelper() {}
void SimpleActionHelper::step(ReturnValue_t result) {
// STEP_OFFESET is subtracted to compensate for adding offset in base
// method, which is not necessary here.
ActionHelper::step(stepCount - STEP_OFFSET, lastCommander, lastAction,
result);
ActionHelper::step(stepCount - STEP_OFFSET, lastCommander, lastAction, result);
if (result != HasReturnvaluesIF::RETURN_OK) {
resetHelper();
}
@ -34,13 +30,12 @@ void SimpleActionHelper::resetHelper() {
lastCommander = 0;
}
void SimpleActionHelper::prepareExecution(MessageQueueId_t commandedBy,
ActionId_t actionId, store_address_t dataAddress) {
void SimpleActionHelper::prepareExecution(MessageQueueId_t commandedBy, ActionId_t actionId,
store_address_t dataAddress) {
CommandMessage reply;
if (isExecuting) {
ipcStore->deleteData(dataAddress);
ActionMessage::setStepReply(&reply, actionId, 0,
HasActionsIF::IS_BUSY);
ActionMessage::setStepReply(&reply, actionId, 0, HasActionsIF::IS_BUSY);
queueToUse->sendMessage(commandedBy, &reply);
}
const uint8_t* dataPtr = NULL;
@ -61,8 +56,7 @@ void SimpleActionHelper::prepareExecution(MessageQueueId_t commandedBy,
stepCount++;
break;
case HasActionsIF::EXECUTION_FINISHED:
ActionMessage::setCompletionReply(&reply, actionId,
true, HasReturnvaluesIF::RETURN_OK);
ActionMessage::setCompletionReply(&reply, actionId, true, HasReturnvaluesIF::RETURN_OK);
queueToUse->sendMessage(commandedBy, &reply);
break;
default:
@ -70,5 +64,4 @@ void SimpleActionHelper::prepareExecution(MessageQueueId_t commandedBy,
queueToUse->sendMessage(commandedBy, &reply);
break;
}
}

View File

@ -8,19 +8,20 @@
* at a time but remembers last commander and last action which
* simplifies usage
*/
class SimpleActionHelper: public ActionHelper {
public:
class SimpleActionHelper : public ActionHelper {
public:
SimpleActionHelper(HasActionsIF* setOwner, MessageQueueIF* useThisQueue);
virtual ~SimpleActionHelper();
void step(ReturnValue_t result = HasReturnvaluesIF::RETURN_OK);
void finish(ReturnValue_t result = HasReturnvaluesIF::RETURN_OK);
ReturnValue_t reportData(SerializeIF* data);
protected:
protected:
void prepareExecution(MessageQueueId_t commandedBy, ActionId_t actionId,
store_address_t dataAddress);
virtual void resetHelper();
private:
private:
bool isExecuting;
MessageQueueId_t lastCommander = MessageQueueIF::NO_QUEUE;
ActionId_t lastAction = 0;

View File

@ -1,16 +1,17 @@
#include "fsfw/ipc/CommandMessage.h"
#include "fsfw/storagemanager/storeAddress.h"
#include "fsfw/cfdp/CFDPHandler.h"
#include "fsfw/cfdp/CFDPMessage.h"
#include "fsfw/tmtcservices/AcceptsTelemetryIF.h"
#include "fsfw/cfdp/CFDPMessage.h"
#include "fsfw/ipc/CommandMessage.h"
#include "fsfw/ipc/QueueFactory.h"
#include "fsfw/objectmanager/ObjectManager.h"
#include "fsfw/storagemanager/storeAddress.h"
#include "fsfw/tmtcservices/AcceptsTelemetryIF.h"
object_id_t CFDPHandler::packetSource = 0;
object_id_t CFDPHandler::packetDestination = 0;
CFDPHandler::CFDPHandler(object_id_t setObjectId, CFDPDistributor* dist) : SystemObject(setObjectId) {
CFDPHandler::CFDPHandler(object_id_t setObjectId, CFDPDistributor* dist)
: SystemObject(setObjectId) {
requestQueue = QueueFactory::instance()->createMessageQueue(CFDP_HANDLER_MAX_RECEPTION);
distributor = dist;
}
@ -35,7 +36,7 @@ ReturnValue_t CFDPHandler::handleRequest(store_address_t storeId) {
#endif /* !FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif
//TODO read out packet from store using storeId
// TODO read out packet from store using storeId
return RETURN_OK;
}
@ -51,10 +52,6 @@ ReturnValue_t CFDPHandler::performOperation(uint8_t opCode) {
return RETURN_OK;
}
uint16_t CFDPHandler::getIdentifier() {
return 0;
}
uint16_t CFDPHandler::getIdentifier() { return 0; }
MessageQueueId_t CFDPHandler::getRequestQueue() {
return this->requestQueue->getId();
}
MessageQueueId_t CFDPHandler::getRequestQueue() { return this->requestQueue->getId(); }

View File

@ -1,25 +1,24 @@
#ifndef FSFW_CFDP_CFDPHANDLER_H_
#define FSFW_CFDP_CFDPHANDLER_H_
#include "fsfw/tmtcservices/AcceptsTelecommandsIF.h"
#include "fsfw/ipc/MessageQueueIF.h"
#include "fsfw/objectmanager/SystemObject.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include "fsfw/tasks/ExecutableObjectIF.h"
#include "fsfw/tcdistribution/CFDPDistributor.h"
#include "fsfw/tmtcservices/AcceptsTelecommandsIF.h"
#include "fsfw/ipc/MessageQueueIF.h"
namespace Factory{
namespace Factory {
void setStaticFrameworkObjectIds();
}
class CFDPHandler :
public ExecutableObjectIF,
class CFDPHandler : public ExecutableObjectIF,
public AcceptsTelecommandsIF,
public SystemObject,
public HasReturnvaluesIF {
friend void (Factory::setStaticFrameworkObjectIds)();
public:
friend void(Factory::setStaticFrameworkObjectIds)();
public:
CFDPHandler(object_id_t setObjectId, CFDPDistributor* distributor);
/**
* The destructor is empty.
@ -32,6 +31,7 @@ public:
virtual uint16_t getIdentifier() override;
MessageQueueId_t getRequestQueue() override;
ReturnValue_t performOperation(uint8_t opCode) override;
protected:
/**
* This is a complete instance of the telecommand reception queue
@ -50,6 +50,7 @@ public:
static object_id_t packetSource;
static object_id_t packetDestination;
private:
/**
* This constant sets the maximum number of packets accepted per call.

View File

@ -1,13 +1,10 @@
#include "CFDPMessage.h"
CFDPMessage::CFDPMessage() {
}
CFDPMessage::CFDPMessage() {}
CFDPMessage::~CFDPMessage() {
}
CFDPMessage::~CFDPMessage() {}
void CFDPMessage::setCommand(CommandMessage *message,
store_address_t cfdpPacket) {
void CFDPMessage::setCommand(CommandMessage *message, store_address_t cfdpPacket) {
message->setParameter(cfdpPacket.raw);
}
@ -17,5 +14,4 @@ store_address_t CFDPMessage::getStoreId(const CommandMessage *message) {
return storeAddressCFDPPacket;
}
void CFDPMessage::clear(CommandMessage *message) {
}
void CFDPMessage::clear(CommandMessage *message) {}

View File

@ -6,14 +6,14 @@
#include "fsfw/storagemanager/StorageManagerIF.h"
class CFDPMessage {
private:
private:
CFDPMessage();
public:
public:
static const uint8_t MESSAGE_ID = messagetypes::CFDP;
virtual ~CFDPMessage();
static void setCommand(CommandMessage* message,
store_address_t cfdpPacket);
static void setCommand(CommandMessage* message, store_address_t cfdpPacket);
static store_address_t getStoreId(const CommandMessage* message);

View File

@ -6,27 +6,23 @@
namespace cfdp {
struct FileSize: public SerializeIF {
public:
FileSize(): largeFile(false) {};
struct FileSize : public SerializeIF {
public:
FileSize() : largeFile(false){};
FileSize(uint64_t fileSize, bool isLarge = false) {
setFileSize(fileSize, isLarge);
};
FileSize(uint64_t fileSize, bool isLarge = false) { setFileSize(fileSize, isLarge); };
ReturnValue_t serialize(bool isLarge, uint8_t **buffer, size_t *size,size_t maxSize,
ReturnValue_t serialize(bool isLarge, uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) {
this->largeFile = isLarge;
return serialize(buffer, size, maxSize, streamEndianness);
}
ReturnValue_t serialize(uint8_t **buffer, size_t *size,size_t maxSize,
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const override {
if(not largeFile) {
if (not largeFile) {
uint32_t fileSizeTyped = fileSize;
return SerializeAdapter::serialize(&fileSizeTyped, buffer, size, maxSize,
streamEndianness);
return SerializeAdapter::serialize(&fileSizeTyped, buffer, size, maxSize, streamEndianness);
}
return SerializeAdapter::serialize(&fileSize, buffer, size, maxSize, streamEndianness);
}
@ -41,13 +37,13 @@ public:
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
Endianness streamEndianness) override {
if(largeFile) {
if (largeFile) {
return SerializeAdapter::deSerialize(&size, buffer, size, streamEndianness);
} else {
uint32_t sizeTmp = 0;
ReturnValue_t result = SerializeAdapter::deSerialize(&sizeTmp, buffer, size,
streamEndianness);
if(result == HasReturnvaluesIF::RETURN_OK) {
ReturnValue_t result =
SerializeAdapter::deSerialize(&sizeTmp, buffer, size, streamEndianness);
if (result == HasReturnvaluesIF::RETURN_OK) {
fileSize = sizeTmp;
}
return result;
@ -64,20 +60,19 @@ public:
return HasReturnvaluesIF::RETURN_OK;
}
bool isLargeFile() const {
return largeFile;
}
uint64_t getSize(bool* largeFile = nullptr) const {
if(largeFile != nullptr) {
bool isLargeFile() const { return largeFile; }
uint64_t getSize(bool *largeFile = nullptr) const {
if (largeFile != nullptr) {
*largeFile = this->largeFile;
}
return fileSize;
}
private:
private:
uint64_t fileSize = 0;
bool largeFile = false;
};
}
} // namespace cfdp
#endif /* FSFW_SRC_FSFW_CFDP_FILESIZE_H_ */

View File

@ -2,10 +2,12 @@
#define FSFW_SRC_FSFW_CFDP_PDU_DEFINITIONS_H_
#include <fsfw/serialize/SerializeIF.h>
#include <cstdint>
#include <cstddef>
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include <cstdint>
#include "fsfw/returnvalues/FwClassIds.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
namespace cfdp {
@ -47,39 +49,27 @@ enum ChecksumType {
NULL_CHECKSUM = 15
};
enum PduType: bool {
FILE_DIRECTIVE = 0,
FILE_DATA = 1
};
enum PduType : bool { FILE_DIRECTIVE = 0, FILE_DATA = 1 };
enum TransmissionModes: bool {
ACKNOWLEDGED = 0,
UNACKNOWLEDGED = 1
};
enum TransmissionModes : bool { ACKNOWLEDGED = 0, UNACKNOWLEDGED = 1 };
enum SegmentMetadataFlag: bool {
NOT_PRESENT = 0,
PRESENT = 1
};
enum SegmentMetadataFlag : bool { NOT_PRESENT = 0, PRESENT = 1 };
enum Direction: bool {
TOWARDS_RECEIVER = 0,
TOWARDS_SENDER = 1
};
enum Direction : bool { TOWARDS_RECEIVER = 0, TOWARDS_SENDER = 1 };
enum SegmentationControl: bool {
enum SegmentationControl : bool {
NO_RECORD_BOUNDARIES_PRESERVATION = 0,
RECORD_BOUNDARIES_PRESERVATION = 1
};
enum WidthInBytes: uint8_t {
enum WidthInBytes : uint8_t {
// Only those are supported for now
ONE_BYTE = 1,
TWO_BYTES = 2,
FOUR_BYTES = 4,
};
enum FileDirectives: uint8_t {
enum FileDirectives : uint8_t {
INVALID_DIRECTIVE = 0x0f,
EOF_DIRECTIVE = 0x04,
FINISH = 0x05,
@ -90,7 +80,7 @@ enum FileDirectives: uint8_t {
KEEP_ALIVE = 0x0c
};
enum ConditionCode: uint8_t {
enum ConditionCode : uint8_t {
NO_CONDITION_FIELD = 0xff,
NO_ERROR = 0b0000,
POSITIVE_ACK_LIMIT_REACHED = 0b0001,
@ -114,10 +104,7 @@ enum AckTransactionStatus {
UNRECOGNIZED = 0b11
};
enum FinishedDeliveryCode {
DATA_COMPLETE = 0,
DATA_INCOMPLETE = 1
};
enum FinishedDeliveryCode { DATA_COMPLETE = 0, DATA_INCOMPLETE = 1 };
enum FinishedFileStatus {
DISCARDED_DELIBERATELY = 0,
@ -126,12 +113,9 @@ enum FinishedFileStatus {
FILE_STATUS_UNREPORTED = 3
};
enum PromptResponseRequired: bool {
PROMPT_NAK = 0,
PROMPT_KEEP_ALIVE = 1
};
enum PromptResponseRequired : bool { PROMPT_NAK = 0, PROMPT_KEEP_ALIVE = 1 };
enum TlvTypes: uint8_t {
enum TlvTypes : uint8_t {
FILESTORE_REQUEST = 0x00,
FILESTORE_RESPONSE = 0x01,
MSG_TO_USER = 0x02,
@ -148,6 +132,6 @@ enum RecordContinuationState {
CONTAINS_START_AND_END = 0b11
};
}
} // namespace cfdp
#endif /* FSFW_SRC_FSFW_CFDP_PDU_DEFINITIONS_H_ */

View File

@ -1,9 +1,11 @@
#include "AckInfo.h"
AckInfo::AckInfo(cfdp::FileDirectives ackedDirective, cfdp::ConditionCode ackedConditionCode,
cfdp::AckTransactionStatus transactionStatus, uint8_t directiveSubtypeCode):
ackedDirective(ackedDirective), ackedConditionCode(ackedConditionCode),
transactionStatus(transactionStatus), directiveSubtypeCode(directiveSubtypeCode) {
cfdp::AckTransactionStatus transactionStatus, uint8_t directiveSubtypeCode)
: ackedDirective(ackedDirective),
ackedConditionCode(ackedConditionCode),
transactionStatus(transactionStatus),
directiveSubtypeCode(directiveSubtypeCode) {
if (ackedDirective == cfdp::FileDirectives::FINISH) {
this->directiveSubtypeCode = 0b0001;
} else {
@ -11,9 +13,7 @@ AckInfo::AckInfo(cfdp::FileDirectives ackedDirective, cfdp::ConditionCode ackedC
}
}
cfdp::ConditionCode AckInfo::getAckedConditionCode() const {
return ackedConditionCode;
}
cfdp::ConditionCode AckInfo::getAckedConditionCode() const { return ackedConditionCode; }
void AckInfo::setAckedConditionCode(cfdp::ConditionCode ackedConditionCode) {
this->ackedConditionCode = ackedConditionCode;
@ -24,28 +24,21 @@ void AckInfo::setAckedConditionCode(cfdp::ConditionCode ackedConditionCode) {
}
}
cfdp::FileDirectives AckInfo::getAckedDirective() const {
return ackedDirective;
}
cfdp::FileDirectives AckInfo::getAckedDirective() const { return ackedDirective; }
void AckInfo::setAckedDirective(cfdp::FileDirectives ackedDirective) {
this->ackedDirective = ackedDirective;
}
uint8_t AckInfo::getDirectiveSubtypeCode() const {
return directiveSubtypeCode;
}
uint8_t AckInfo::getDirectiveSubtypeCode() const { return directiveSubtypeCode; }
void AckInfo::setDirectiveSubtypeCode(uint8_t directiveSubtypeCode) {
this->directiveSubtypeCode = directiveSubtypeCode;
}
cfdp::AckTransactionStatus AckInfo::getTransactionStatus() const {
return transactionStatus;
}
cfdp::AckTransactionStatus AckInfo::getTransactionStatus() const { return transactionStatus; }
AckInfo::AckInfo() {
}
AckInfo::AckInfo() {}
void AckInfo::setTransactionStatus(cfdp::AckTransactionStatus transactionStatus) {
this->transactionStatus = transactionStatus;

View File

@ -4,7 +4,7 @@
#include "../definitions.h"
class AckInfo {
public:
public:
AckInfo();
AckInfo(cfdp::FileDirectives ackedDirective, cfdp::ConditionCode ackedConditionCode,
cfdp::AckTransactionStatus transactionStatus, uint8_t directiveSubtypeCode = 0);
@ -21,13 +21,11 @@ public:
cfdp::AckTransactionStatus getTransactionStatus() const;
void setTransactionStatus(cfdp::AckTransactionStatus transactionStatus);
private:
private:
cfdp::FileDirectives ackedDirective = cfdp::FileDirectives::INVALID_DIRECTIVE;
cfdp::ConditionCode ackedConditionCode = cfdp::ConditionCode::NO_CONDITION_FIELD;
cfdp::AckTransactionStatus transactionStatus = cfdp::AckTransactionStatus::UNDEFINED;
uint8_t directiveSubtypeCode = 0;
};
#endif /* FSFW_SRC_FSFW_CFDP_PDU_ACKINFO_H_ */

View File

@ -1,19 +1,18 @@
#include "AckPduDeserializer.h"
AckPduDeserializer::AckPduDeserializer(const uint8_t *pduBuf, size_t maxSize, AckInfo& info):
FileDirectiveDeserializer(pduBuf, maxSize), info(info) {
}
AckPduDeserializer::AckPduDeserializer(const uint8_t* pduBuf, size_t maxSize, AckInfo& info)
: FileDirectiveDeserializer(pduBuf, maxSize), info(info) {}
ReturnValue_t AckPduDeserializer::parseData() {
ReturnValue_t result = FileDirectiveDeserializer::parseData();
if(result != HasReturnvaluesIF::RETURN_OK) {
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
size_t currentIdx = FileDirectiveDeserializer::getHeaderSize();
if (currentIdx + 2 > this->maxSize) {
return SerializeIF::BUFFER_TOO_SHORT;
}
if(not checkAndSetCodes(rawPtr[currentIdx], rawPtr[currentIdx + 1])) {
if (not checkAndSetCodes(rawPtr[currentIdx], rawPtr[currentIdx + 1])) {
return cfdp::INVALID_ACK_DIRECTIVE_FIELDS;
}
return HasReturnvaluesIF::RETURN_OK;
@ -22,13 +21,13 @@ ReturnValue_t AckPduDeserializer::parseData() {
bool AckPduDeserializer::checkAndSetCodes(uint8_t firstByte, uint8_t secondByte) {
uint8_t ackedDirective = static_cast<cfdp::FileDirectives>(firstByte >> 4);
if(ackedDirective != cfdp::FileDirectives::EOF_DIRECTIVE and
if (ackedDirective != cfdp::FileDirectives::EOF_DIRECTIVE and
ackedDirective != cfdp::FileDirectives::FINISH) {
return false;
}
this->info.setAckedDirective(static_cast<cfdp::FileDirectives>(ackedDirective));
uint8_t directiveSubtypeCode = firstByte & 0x0f;
if(directiveSubtypeCode != 0b0000 and directiveSubtypeCode != 0b0001) {
if (directiveSubtypeCode != 0b0000 and directiveSubtypeCode != 0b0001) {
return false;
}
this->info.setDirectiveSubtypeCode(directiveSubtypeCode);

View File

@ -1,11 +1,11 @@
#ifndef FSFW_SRC_FSFW_CFDP_PDU_ACKPDUDESERIALIZER_H_
#define FSFW_SRC_FSFW_CFDP_PDU_ACKPDUDESERIALIZER_H_
#include "fsfw/cfdp/pdu/FileDirectiveDeserializer.h"
#include "AckInfo.h"
#include "fsfw/cfdp/pdu/FileDirectiveDeserializer.h"
class AckPduDeserializer: public FileDirectiveDeserializer {
public:
class AckPduDeserializer : public FileDirectiveDeserializer {
public:
AckPduDeserializer(const uint8_t* pduBuf, size_t maxSize, AckInfo& info);
/**
@ -15,12 +15,9 @@ public:
*/
ReturnValue_t parseData();
private:
private:
bool checkAndSetCodes(uint8_t rawAckedByte, uint8_t rawAckedConditionCode);
AckInfo& info;
};
#endif /* FSFW_SRC_FSFW_CFDP_PDU_ACKPDUDESERIALIZER_H_ */

View File

@ -1,9 +1,7 @@
#include "AckPduSerializer.h"
AckPduSerializer::AckPduSerializer(AckInfo& ackInfo, PduConfig &pduConf):
FileDirectiveSerializer(pduConf, cfdp::FileDirectives::ACK, 2),
ackInfo(ackInfo) {
}
AckPduSerializer::AckPduSerializer(AckInfo &ackInfo, PduConfig &pduConf)
: FileDirectiveSerializer(pduConf, cfdp::FileDirectives::ACK, 2), ackInfo(ackInfo) {}
size_t AckPduSerializer::getSerializedSize() const {
return FileDirectiveSerializer::getWholePduSize();
@ -11,21 +9,21 @@ size_t AckPduSerializer::getSerializedSize() const {
ReturnValue_t AckPduSerializer::serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const {
ReturnValue_t result = FileDirectiveSerializer::serialize(buffer, size, maxSize,
streamEndianness);
if(result != HasReturnvaluesIF::RETURN_OK) {
ReturnValue_t result =
FileDirectiveSerializer::serialize(buffer, size, maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
cfdp::FileDirectives ackedDirective = ackInfo.getAckedDirective();
uint8_t directiveSubtypeCode = ackInfo.getDirectiveSubtypeCode();
cfdp::ConditionCode ackedConditionCode = ackInfo.getAckedConditionCode();
cfdp::AckTransactionStatus transactionStatus = ackInfo.getTransactionStatus();
if(ackedDirective != cfdp::FileDirectives::FINISH and
if (ackedDirective != cfdp::FileDirectives::FINISH and
ackedDirective != cfdp::FileDirectives::EOF_DIRECTIVE) {
// TODO: better returncode
return HasReturnvaluesIF::RETURN_FAILED;
}
if(*size + 2 > maxSize) {
if (*size + 2 > maxSize) {
return SerializeIF::BUFFER_TOO_SHORT;
}
**buffer = ackedDirective << 4 | directiveSubtypeCode;

View File

@ -5,8 +5,8 @@
#include "FileDirectiveDeserializer.h"
#include "FileDirectiveSerializer.h"
class AckPduSerializer: public FileDirectiveSerializer {
public:
class AckPduSerializer : public FileDirectiveSerializer {
public:
/**
* @brief Serializer to pack ACK PDUs
* @details
@ -23,7 +23,7 @@ public:
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const override;
private:
private:
AckInfo& ackInfo;
};

View File

@ -1,54 +1,43 @@
#include "EofInfo.h"
EofInfo::EofInfo(cfdp::ConditionCode conditionCode, uint32_t checksum, cfdp::FileSize fileSize,
EntityIdTlv* faultLoc): conditionCode(conditionCode), checksum(checksum),
fileSize(fileSize), faultLoc(faultLoc) {
}
EntityIdTlv* faultLoc)
: conditionCode(conditionCode), checksum(checksum), fileSize(fileSize), faultLoc(faultLoc) {}
EofInfo::EofInfo(EntityIdTlv *faultLoc): conditionCode(cfdp::ConditionCode::NO_CONDITION_FIELD),
checksum(0), fileSize(0), faultLoc(faultLoc) {
}
EofInfo::EofInfo(EntityIdTlv* faultLoc)
: conditionCode(cfdp::ConditionCode::NO_CONDITION_FIELD),
checksum(0),
fileSize(0),
faultLoc(faultLoc) {}
uint32_t EofInfo::getChecksum() const {
return checksum;
}
uint32_t EofInfo::getChecksum() const { return checksum; }
cfdp::ConditionCode EofInfo::getConditionCode() const {
return conditionCode;
}
cfdp::ConditionCode EofInfo::getConditionCode() const { return conditionCode; }
EntityIdTlv* EofInfo::getFaultLoc() const {
return faultLoc;
}
EntityIdTlv* EofInfo::getFaultLoc() const { return faultLoc; }
cfdp::FileSize& EofInfo::getFileSize() {
return fileSize;
}
cfdp::FileSize& EofInfo::getFileSize() { return fileSize; }
void EofInfo::setChecksum(uint32_t checksum) {
this->checksum = checksum;
}
void EofInfo::setChecksum(uint32_t checksum) { this->checksum = checksum; }
void EofInfo::setConditionCode(cfdp::ConditionCode conditionCode) {
this->conditionCode = conditionCode;
}
void EofInfo::setFaultLoc(EntityIdTlv *faultLoc) {
this->faultLoc = faultLoc;
}
void EofInfo::setFaultLoc(EntityIdTlv* faultLoc) { this->faultLoc = faultLoc; }
size_t EofInfo::getSerializedSize(bool fssLarge) {
// Condition code + spare + 4 byte checksum
size_t size = 5;
if(fssLarge) {
if (fssLarge) {
size += 8;
} else {
size += 4;
}
// Do not account for fault location if the condition code is NO_ERROR. We assume that
// a serializer will not serialize the fault location here.
if(getFaultLoc() != nullptr and getConditionCode() != cfdp::ConditionCode::NO_ERROR) {
size+= faultLoc->getSerializedSize();
if (getFaultLoc() != nullptr and getConditionCode() != cfdp::ConditionCode::NO_ERROR) {
size += faultLoc->getSerializedSize();
}
return size;
}

View File

@ -1,12 +1,12 @@
#ifndef FSFW_SRC_FSFW_CFDP_PDU_EOFINFO_H_
#define FSFW_SRC_FSFW_CFDP_PDU_EOFINFO_H_
#include "fsfw/cfdp/tlv/EntityIdTlv.h"
#include "../definitions.h"
#include "../FileSize.h"
#include "../definitions.h"
#include "fsfw/cfdp/tlv/EntityIdTlv.h"
struct EofInfo {
public:
public:
EofInfo(EntityIdTlv* faultLoc = nullptr);
EofInfo(cfdp::ConditionCode conditionCode, uint32_t checksum, cfdp::FileSize fileSize,
EntityIdTlv* faultLoc = nullptr);
@ -20,10 +20,10 @@ public:
cfdp::FileSize& getFileSize();
void setChecksum(uint32_t checksum);
void setConditionCode(cfdp::ConditionCode conditionCode);
void setFaultLoc(EntityIdTlv *faultLoc);
void setFaultLoc(EntityIdTlv* faultLoc);
ReturnValue_t setFileSize(size_t size, bool isLarge);
private:
private:
cfdp::ConditionCode conditionCode;
uint32_t checksum;
cfdp::FileSize fileSize;

View File

@ -1,25 +1,25 @@
#include "EofPduDeserializer.h"
#include "fsfw/FSFW.h"
#include "fsfw/serviceinterface.h"
EofPduDeserializer::EofPduDeserializer(const uint8_t *pduBuf, size_t maxSize, EofInfo& eofInfo):
FileDirectiveDeserializer(pduBuf, maxSize), info(eofInfo) {
}
EofPduDeserializer::EofPduDeserializer(const uint8_t* pduBuf, size_t maxSize, EofInfo& eofInfo)
: FileDirectiveDeserializer(pduBuf, maxSize), info(eofInfo) {}
ReturnValue_t EofPduDeserializer::parseData() {
ReturnValue_t result = FileDirectiveDeserializer::parseData();
if(result != HasReturnvaluesIF::RETURN_OK) {
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
const uint8_t* bufPtr = rawPtr;
size_t expectedFileFieldLen = 4;
if(this->getLargeFileFlag()) {
if (this->getLargeFileFlag()) {
expectedFileFieldLen = 8;
}
size_t currentIdx = FileDirectiveDeserializer::getHeaderSize();
size_t deserLen = maxSize;
if(maxSize < currentIdx + 5 + expectedFileFieldLen) {
if (maxSize < currentIdx + 5 + expectedFileFieldLen) {
return SerializeIF::STREAM_TOO_SHORT;
}
@ -31,32 +31,33 @@ ReturnValue_t EofPduDeserializer::parseData() {
uint32_t checksum = 0;
auto endianness = getEndianness();
result = SerializeAdapter::deSerialize(&checksum, &bufPtr, &deserLen, endianness);
if(result != HasReturnvaluesIF::RETURN_OK) {
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
info.setChecksum(checksum);
if(this->getLargeFileFlag()) {
if (this->getLargeFileFlag()) {
uint64_t fileSizeValue = 0;
result = SerializeAdapter::deSerialize(&fileSizeValue, &bufPtr, &deserLen, endianness);
info.setFileSize(fileSizeValue, true);
}
else {
} else {
uint32_t fileSizeValue = 0;
result = SerializeAdapter::deSerialize(&fileSizeValue, &bufPtr, &deserLen, endianness);
info.setFileSize(fileSizeValue, false);
}
if(result != HasReturnvaluesIF::RETURN_OK) {
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if(info.getConditionCode() != cfdp::ConditionCode::NO_ERROR) {
if (info.getConditionCode() != cfdp::ConditionCode::NO_ERROR) {
EntityIdTlv* tlvPtr = info.getFaultLoc();
if(tlvPtr == nullptr) {
if (tlvPtr == nullptr) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "EofPduDeserializer::parseData: Ca not deserialize fault location,"
" given TLV pointer invalid" << std::endl;
" given TLV pointer invalid"
<< std::endl;
#else
sif::printWarning("EofPduDeserializer::parseData: Ca not deserialize fault location,"
sif::printWarning(
"EofPduDeserializer::parseData: Ca not deserialize fault location,"
" given TLV pointer invalid");
#endif
#endif /* FSFW_VERBOSE_LEVEL >= 1 */

View File

@ -1,18 +1,17 @@
#ifndef FSFW_SRC_FSFW_CFDP_PDU_EOFPDUDESERIALIZER_H_
#define FSFW_SRC_FSFW_CFDP_PDU_EOFPDUDESERIALIZER_H_
#include "fsfw/cfdp/pdu/FileDirectiveDeserializer.h"
#include "EofInfo.h"
#include "fsfw/cfdp/pdu/FileDirectiveDeserializer.h"
class EofPduDeserializer: public FileDirectiveDeserializer {
public:
class EofPduDeserializer : public FileDirectiveDeserializer {
public:
EofPduDeserializer(const uint8_t* pduBuf, size_t maxSize, EofInfo& eofInfo);
virtual ReturnValue_t parseData() override;
private:
private:
EofInfo& info;
};
#endif /* FSFW_SRC_FSFW_CFDP_PDU_EOFPDUDESERIALIZER_H_ */

View File

@ -1,9 +1,10 @@
#include "fsfw/FSFW.h"
#include "fsfw/serviceinterface.h"
#include "EofPduSerializer.h"
EofPduSerializer::EofPduSerializer(PduConfig &conf, EofInfo& info):
FileDirectiveSerializer(conf, cfdp::FileDirectives::EOF_DIRECTIVE, 9), info(info) {
#include "fsfw/FSFW.h"
#include "fsfw/serviceinterface.h"
EofPduSerializer::EofPduSerializer(PduConfig &conf, EofInfo &info)
: FileDirectiveSerializer(conf, cfdp::FileDirectives::EOF_DIRECTIVE, 9), info(info) {
setDirectiveDataFieldLen(info.getSerializedSize(getLargeFileFlag()));
}
@ -13,12 +14,12 @@ size_t EofPduSerializer::getSerializedSize() const {
ReturnValue_t EofPduSerializer::serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const {
ReturnValue_t result = FileDirectiveSerializer::serialize(buffer, size, maxSize,
streamEndianness);
if(result != HasReturnvaluesIF::RETURN_OK) {
ReturnValue_t result =
FileDirectiveSerializer::serialize(buffer, size, maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if(*size + 1 > maxSize) {
if (*size + 1 > maxSize) {
return SerializeIF::BUFFER_TOO_SHORT;
}
**buffer = info.getConditionCode() << 4;
@ -26,20 +27,17 @@ ReturnValue_t EofPduSerializer::serialize(uint8_t **buffer, size_t *size, size_t
*size += 1;
uint32_t checksum = info.getChecksum();
result = SerializeAdapter::serialize(&checksum, buffer, size, maxSize, streamEndianness);
if(result != HasReturnvaluesIF::RETURN_OK) {
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if(info.getFileSize().isLargeFile()) {
if (info.getFileSize().isLargeFile()) {
uint64_t fileSizeValue = info.getFileSize().getSize();
result = SerializeAdapter::serialize(&fileSizeValue, buffer, size,
maxSize, streamEndianness);
}
else {
result = SerializeAdapter::serialize(&fileSizeValue, buffer, size, maxSize, streamEndianness);
} else {
uint32_t fileSizeValue = info.getFileSize().getSize();
result = SerializeAdapter::serialize(&fileSizeValue, buffer, size,
maxSize, streamEndianness);
result = SerializeAdapter::serialize(&fileSizeValue, buffer, size, maxSize, streamEndianness);
}
if(info.getFaultLoc() != nullptr and info.getConditionCode() != cfdp::ConditionCode::NO_ERROR) {
if (info.getFaultLoc() != nullptr and info.getConditionCode() != cfdp::ConditionCode::NO_ERROR) {
result = info.getFaultLoc()->serialize(buffer, size, maxSize, streamEndianness);
}
return result;

View File

@ -1,22 +1,21 @@
#ifndef FSFW_SRC_FSFW_CFDP_PDU_EOFPDUSERIALIZER_H_
#define FSFW_SRC_FSFW_CFDP_PDU_EOFPDUSERIALIZER_H_
#include "EofInfo.h"
#include "fsfw/cfdp/pdu/FileDirectiveSerializer.h"
#include "fsfw/cfdp/tlv/EntityIdTlv.h"
#include "EofInfo.h"
class EofPduSerializer: public FileDirectiveSerializer {
public:
EofPduSerializer(PduConfig &conf, EofInfo& info);
class EofPduSerializer : public FileDirectiveSerializer {
public:
EofPduSerializer(PduConfig& conf, EofInfo& info);
size_t getSerializedSize() const override;
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const override;
private:
private:
EofInfo& info;
};
#endif /* FSFW_SRC_FSFW_CFDP_PDU_EOFPDUSERIALIZER_H_ */

View File

@ -1,13 +1,12 @@
#include "FileDataDeserializer.h"
FileDataDeserializer::FileDataDeserializer(const uint8_t *pduBuf, size_t maxSize,
FileDataInfo& info):
HeaderDeserializer(pduBuf, maxSize), info(info) {
}
FileDataDeserializer::FileDataDeserializer(const uint8_t* pduBuf, size_t maxSize,
FileDataInfo& info)
: HeaderDeserializer(pduBuf, maxSize), info(info) {}
ReturnValue_t FileDataDeserializer::parseData() {
ReturnValue_t result = HeaderDeserializer::parseData();
if(result != HasReturnvaluesIF::RETURN_OK) {
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
size_t currentIdx = HeaderDeserializer::getHeaderSize();
@ -16,16 +15,15 @@ ReturnValue_t FileDataDeserializer::parseData() {
if (remSize < 1) {
return SerializeIF::STREAM_TOO_SHORT;
}
if(hasSegmentMetadataFlag()) {
if (hasSegmentMetadataFlag()) {
info.setSegmentMetadataFlag(true);
info.setRecordContinuationState(static_cast<cfdp::RecordContinuationState>(
(*buf >> 6) & 0b11));
info.setRecordContinuationState(static_cast<cfdp::RecordContinuationState>((*buf >> 6) & 0b11));
size_t segmentMetadataLen = *buf & 0b00111111;
info.setSegmentMetadataLen(segmentMetadataLen);
if(remSize < segmentMetadataLen + 1) {
if (remSize < segmentMetadataLen + 1) {
return SerializeIF::STREAM_TOO_SHORT;
}
if(segmentMetadataLen > 0) {
if (segmentMetadataLen > 0) {
buf += 1;
remSize -= 1;
info.setSegmentMetadata(buf);
@ -34,18 +32,16 @@ ReturnValue_t FileDataDeserializer::parseData() {
}
}
result = info.getOffset().deSerialize(&buf, &remSize, this->getEndianness());
if(result != HasReturnvaluesIF::RETURN_OK) {
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if(remSize > 0) {
if (remSize > 0) {
info.setFileData(buf, remSize);
}
return HasReturnvaluesIF::RETURN_OK;
}
SerializeIF::Endianness FileDataDeserializer::getEndianness() const {
return endianness;
}
SerializeIF::Endianness FileDataDeserializer::getEndianness() const { return endianness; }
void FileDataDeserializer::setEndianness(SerializeIF::Endianness endianness) {
this->endianness = endianness;

View File

@ -1,20 +1,19 @@
#ifndef FSFW_SRC_FSFW_CFDP_PDU_FILEDATADESERIALIZER_H_
#define FSFW_SRC_FSFW_CFDP_PDU_FILEDATADESERIALIZER_H_
#include "../definitions.h"
#include "FileDataInfo.h"
#include "HeaderDeserializer.h"
#include "../definitions.h"
class FileDataDeserializer: public HeaderDeserializer {
public:
class FileDataDeserializer : public HeaderDeserializer {
public:
FileDataDeserializer(const uint8_t* pduBuf, size_t maxSize, FileDataInfo& info);
ReturnValue_t parseData();
SerializeIF::Endianness getEndianness() const;
void setEndianness(SerializeIF::Endianness endianness = SerializeIF::Endianness::NETWORK);
private:
private:
SerializeIF::Endianness endianness = SerializeIF::Endianness::NETWORK;
FileDataInfo& info;
};

View File

@ -1,14 +1,12 @@
#include "FileDataInfo.h"
FileDataInfo::FileDataInfo(cfdp::FileSize &offset, const uint8_t *fileData, size_t fileSize):
offset(offset), fileData(fileData), fileSize(fileSize) {
}
FileDataInfo::FileDataInfo(cfdp::FileSize &offset, const uint8_t *fileData, size_t fileSize)
: offset(offset), fileData(fileData), fileSize(fileSize) {}
FileDataInfo::FileDataInfo(cfdp::FileSize &offset): offset(offset) {
}
FileDataInfo::FileDataInfo(cfdp::FileSize &offset) : offset(offset) {}
void FileDataInfo::setSegmentMetadataFlag(bool enable) {
if(enable) {
if (enable) {
segmentMetadataFlag = cfdp::SegmentMetadataFlag::PRESENT;
} else {
segmentMetadataFlag = cfdp::SegmentMetadataFlag::NOT_PRESENT;
@ -17,10 +15,10 @@ void FileDataInfo::setSegmentMetadataFlag(bool enable) {
size_t FileDataInfo::getSerializedSize(bool largeFile) const {
size_t sz = 0;
if(segmentMetadataFlag == cfdp::SegmentMetadataFlag::PRESENT) {
if (segmentMetadataFlag == cfdp::SegmentMetadataFlag::PRESENT) {
sz += 1 + segmentMetadataLen;
}
if(largeFile) {
if (largeFile) {
sz += 8;
} else {
sz += 4;
@ -34,7 +32,7 @@ cfdp::SegmentMetadataFlag FileDataInfo::getSegmentMetadataFlag() const {
}
bool FileDataInfo::hasSegmentMetadata() const {
if(segmentMetadataFlag == cfdp::SegmentMetadataFlag::PRESENT) {
if (segmentMetadataFlag == cfdp::SegmentMetadataFlag::PRESENT) {
return true;
}
return false;
@ -44,15 +42,14 @@ cfdp::RecordContinuationState FileDataInfo::getRecordContinuationState() const {
return this->recContState;
}
size_t FileDataInfo::getSegmentMetadataLen() const {
return segmentMetadataLen;
}
size_t FileDataInfo::getSegmentMetadataLen() const { return segmentMetadataLen; }
ReturnValue_t FileDataInfo::addSegmentMetadataInfo(cfdp::RecordContinuationState recContState,
const uint8_t* segmentMetadata, size_t segmentMetadataLen) {
const uint8_t *segmentMetadata,
size_t segmentMetadataLen) {
this->segmentMetadataFlag = cfdp::SegmentMetadataFlag::PRESENT;
this->recContState = recContState;
if(segmentMetadataLen > 63) {
if (segmentMetadataLen > 63) {
return HasReturnvaluesIF::RETURN_FAILED;
}
this->segmentMetadata = segmentMetadata;
@ -60,44 +57,36 @@ ReturnValue_t FileDataInfo::addSegmentMetadataInfo(cfdp::RecordContinuationState
return HasReturnvaluesIF::RETURN_OK;
}
const uint8_t* FileDataInfo::getFileData(size_t *fileSize) const {
if(fileSize != nullptr) {
const uint8_t *FileDataInfo::getFileData(size_t *fileSize) const {
if (fileSize != nullptr) {
*fileSize = this->fileSize;
}
return fileData;
}
const uint8_t* FileDataInfo::getSegmentMetadata(size_t *segmentMetadataLen) {
if(segmentMetadataLen != nullptr) {
const uint8_t *FileDataInfo::getSegmentMetadata(size_t *segmentMetadataLen) {
if (segmentMetadataLen != nullptr) {
*segmentMetadataLen = this->segmentMetadataLen;
}
return segmentMetadata;
}
cfdp::FileSize& FileDataInfo::getOffset() {
return offset;
}
cfdp::FileSize &FileDataInfo::getOffset() { return offset; }
void FileDataInfo::setRecordContinuationState(cfdp::RecordContinuationState recContState) {
this->recContState = recContState;
}
void FileDataInfo::setSegmentMetadataLen(size_t len) {
this->segmentMetadataLen = len;
}
void FileDataInfo::setSegmentMetadataLen(size_t len) { this->segmentMetadataLen = len; }
void FileDataInfo::setSegmentMetadata(const uint8_t *ptr) {
this->segmentMetadata = ptr;
}
void FileDataInfo::setSegmentMetadata(const uint8_t *ptr) { this->segmentMetadata = ptr; }
void FileDataInfo::setFileData(const uint8_t *fileData, size_t fileSize) {
this->fileData = fileData;
this->fileSize = fileSize;
}
cfdp::SegmentationControl FileDataInfo::getSegmentationControl() const {
return segCtrl;
}
cfdp::SegmentationControl FileDataInfo::getSegmentationControl() const { return segCtrl; }
void FileDataInfo::setSegmentationControl(cfdp::SegmentationControl segCtrl) {
this->segCtrl = segCtrl;

View File

@ -1,11 +1,11 @@
#ifndef FSFW_SRC_FSFW_CFDP_PDU_FILEDATAINFO_H_
#define FSFW_SRC_FSFW_CFDP_PDU_FILEDATAINFO_H_
#include <fsfw/cfdp/definitions.h>
#include <fsfw/cfdp/FileSize.h>
#include <fsfw/cfdp/definitions.h>
class FileDataInfo {
public:
public:
FileDataInfo(cfdp::FileSize& offset);
FileDataInfo(cfdp::FileSize& offset, const uint8_t* fileData, size_t fileSize);
@ -30,10 +30,9 @@ public:
const uint8_t* segmentMetadata, size_t segmentMetadataLen);
const uint8_t* getSegmentMetadata(size_t* segmentMetadataLen = nullptr);
private:
private:
cfdp::SegmentMetadataFlag segmentMetadataFlag = cfdp::SegmentMetadataFlag::NOT_PRESENT;
cfdp::SegmentationControl segCtrl =
cfdp::SegmentationControl::NO_RECORD_BOUNDARIES_PRESERVATION;
cfdp::SegmentationControl segCtrl = cfdp::SegmentationControl::NO_RECORD_BOUNDARIES_PRESERVATION;
cfdp::FileSize& offset;
const uint8_t* fileData = nullptr;
size_t fileSize = 0;

View File

@ -1,8 +1,9 @@
#include "FileDataSerializer.h"
#include <cstring>
FileDataSerializer::FileDataSerializer(PduConfig& conf, FileDataInfo& info):
HeaderSerializer(conf, cfdp::PduType::FILE_DATA, 0, info.getSegmentMetadataFlag()),
FileDataSerializer::FileDataSerializer(PduConfig& conf, FileDataInfo& info)
: HeaderSerializer(conf, cfdp::PduType::FILE_DATA, 0, info.getSegmentMetadataFlag()),
info(info) {
update();
}
@ -13,13 +14,13 @@ void FileDataSerializer::update() {
setPduDataFieldLen(info.getSerializedSize(this->getLargeFileFlag()));
}
ReturnValue_t FileDataSerializer::serialize(uint8_t **buffer, size_t *size, size_t maxSize,
ReturnValue_t FileDataSerializer::serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const {
ReturnValue_t result = HeaderSerializer::serialize(buffer, size, maxSize, streamEndianness);
if(result != HasReturnvaluesIF::RETURN_OK) {
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if(*size + this->getSerializedSize() > maxSize) {
if (*size + this->getSerializedSize() > maxSize) {
return SerializeIF::BUFFER_TOO_SHORT;
}
const uint8_t* readOnlyPtr = nullptr;
@ -35,12 +36,12 @@ ReturnValue_t FileDataSerializer::serialize(uint8_t **buffer, size_t *size, size
}
cfdp::FileSize& offset = info.getOffset();
result = offset.serialize(this->getLargeFileFlag(), buffer, size, maxSize, streamEndianness);
if(result != HasReturnvaluesIF::RETURN_OK) {
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
size_t fileSize = 0;
readOnlyPtr = info.getFileData(&fileSize);
if(*size + fileSize > maxSize) {
if (*size + fileSize > maxSize) {
return SerializeIF::BUFFER_TOO_SHORT;
}
std::memcpy(*buffer, readOnlyPtr, fileSize);

View File

@ -1,12 +1,12 @@
#ifndef FSFW_SRC_FSFW_CFDP_PDU_FILEDATASERIALIZER_H_
#define FSFW_SRC_FSFW_CFDP_PDU_FILEDATASERIALIZER_H_
#include "FileDataInfo.h"
#include "../definitions.h"
#include "FileDataInfo.h"
#include "HeaderSerializer.h"
class FileDataSerializer: public HeaderSerializer {
public:
class FileDataSerializer : public HeaderSerializer {
public:
FileDataSerializer(PduConfig& conf, FileDataInfo& info);
void update();
@ -16,7 +16,7 @@ public:
size_t getSerializedSize() const override;
private:
private:
FileDataInfo& info;
};

View File

@ -1,26 +1,23 @@
#include "FileDirectiveDeserializer.h"
FileDirectiveDeserializer::FileDirectiveDeserializer(const uint8_t *pduBuf, size_t maxSize):
HeaderDeserializer(pduBuf, maxSize) {
}
FileDirectiveDeserializer::FileDirectiveDeserializer(const uint8_t *pduBuf, size_t maxSize)
: HeaderDeserializer(pduBuf, maxSize) {}
cfdp::FileDirectives FileDirectiveDeserializer::getFileDirective() const {
return fileDirective;
}
cfdp::FileDirectives FileDirectiveDeserializer::getFileDirective() const { return fileDirective; }
ReturnValue_t FileDirectiveDeserializer::parseData() {
ReturnValue_t result = HeaderDeserializer::parseData();
if(result != HasReturnvaluesIF::RETURN_OK) {
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if(this->getPduDataFieldLen() < 1) {
if (this->getPduDataFieldLen() < 1) {
return cfdp::INVALID_PDU_DATAFIELD_LEN;
}
if(FileDirectiveDeserializer::getWholePduSize() > maxSize) {
if (FileDirectiveDeserializer::getWholePduSize() > maxSize) {
return SerializeIF::STREAM_TOO_SHORT;
}
size_t currentIdx = HeaderDeserializer::getHeaderSize();
if(not checkFileDirective(rawPtr[currentIdx])) {
if (not checkFileDirective(rawPtr[currentIdx])) {
return cfdp::INVALID_DIRECTIVE_FIELDS;
}
setFileDirective(static_cast<cfdp::FileDirectives>(rawPtr[currentIdx]));
@ -33,9 +30,8 @@ size_t FileDirectiveDeserializer::getHeaderSize() const {
}
bool FileDirectiveDeserializer::checkFileDirective(uint8_t rawByte) {
if(rawByte < cfdp::FileDirectives::EOF_DIRECTIVE or
(rawByte > cfdp::FileDirectives::PROMPT and
rawByte != cfdp::FileDirectives::KEEP_ALIVE)) {
if (rawByte < cfdp::FileDirectives::EOF_DIRECTIVE or
(rawByte > cfdp::FileDirectives::PROMPT and rawByte != cfdp::FileDirectives::KEEP_ALIVE)) {
// Invalid directive field. TODO: Custom returnvalue
return false;
}
@ -50,6 +46,4 @@ void FileDirectiveDeserializer::setEndianness(SerializeIF::Endianness endianness
this->endianness = endianness;
}
SerializeIF::Endianness FileDirectiveDeserializer::getEndianness() const {
return endianness;
}
SerializeIF::Endianness FileDirectiveDeserializer::getEndianness() const { return endianness; }

View File

@ -11,8 +11,8 @@
* This is a zero-copy implementation and #parseData needs to be called to ensure the data is
* valid.
*/
class FileDirectiveDeserializer: public HeaderDeserializer {
public:
class FileDirectiveDeserializer : public HeaderDeserializer {
public:
FileDirectiveDeserializer(const uint8_t* pduBuf, size_t maxSize);
/**
@ -27,15 +27,13 @@ public:
void setEndianness(SerializeIF::Endianness endianness);
SerializeIF::Endianness getEndianness() const;
protected:
protected:
bool checkFileDirective(uint8_t rawByte);
private:
private:
void setFileDirective(cfdp::FileDirectives fileDirective);
cfdp::FileDirectives fileDirective = cfdp::FileDirectives::INVALID_DIRECTIVE;
SerializeIF::Endianness endianness = SerializeIF::Endianness::NETWORK;
};
#endif /* FSFW_SRC_FSFW_CFDP_PDU_FILEDIRECTIVEDESERIALIZER_H_ */

View File

@ -1,11 +1,10 @@
#include "FileDirectiveSerializer.h"
FileDirectiveSerializer::FileDirectiveSerializer(PduConfig &pduConf,
cfdp::FileDirectives directiveCode, size_t directiveParamFieldLen):
HeaderSerializer(pduConf, cfdp::PduType::FILE_DIRECTIVE, directiveParamFieldLen + 1),
directiveCode(directiveCode) {
}
cfdp::FileDirectives directiveCode,
size_t directiveParamFieldLen)
: HeaderSerializer(pduConf, cfdp::PduType::FILE_DIRECTIVE, directiveParamFieldLen + 1),
directiveCode(directiveCode) {}
size_t FileDirectiveSerializer::getSerializedSize() const {
return HeaderSerializer::getSerializedSize() + 1;
@ -13,18 +12,18 @@ size_t FileDirectiveSerializer::getSerializedSize() const {
ReturnValue_t FileDirectiveSerializer::serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const {
if(buffer == nullptr or size == nullptr) {
if (buffer == nullptr or size == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED;
}
if(FileDirectiveSerializer::getWholePduSize() > maxSize) {
if (FileDirectiveSerializer::getWholePduSize() > maxSize) {
return BUFFER_TOO_SHORT;
}
ReturnValue_t result = HeaderSerializer::serialize(buffer, size, maxSize, streamEndianness);
if(result != HasReturnvaluesIF::RETURN_OK) {
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if(*size >= maxSize) {
if (*size >= maxSize) {
return BUFFER_TOO_SHORT;
}
**buffer = directiveCode;

View File

@ -3,8 +3,8 @@
#include "fsfw/cfdp/pdu/HeaderSerializer.h"
class FileDirectiveSerializer: public HeaderSerializer {
public:
class FileDirectiveSerializer : public HeaderSerializer {
public:
FileDirectiveSerializer(PduConfig& pduConf, cfdp::FileDirectives directiveCode,
size_t directiveParamFieldLen);
@ -20,9 +20,9 @@ public:
Endianness streamEndianness) const override;
void setDirectiveDataFieldLen(size_t len);
private:
cfdp::FileDirectives directiveCode = cfdp::FileDirectives::INVALID_DIRECTIVE;
private:
cfdp::FileDirectives directiveCode = cfdp::FileDirectives::INVALID_DIRECTIVE;
};
#endif /* FSFW_SRC_FSFW_CFDP_PDU_FILEDIRECTIVESERIALIZER_H_ */

View File

@ -1,110 +1,101 @@
#include "FinishedInfo.h"
FinishedInfo::FinishedInfo() {
}
FinishedInfo::FinishedInfo() {}
FinishedInfo::FinishedInfo(cfdp::ConditionCode conditionCode,
cfdp::FinishedDeliveryCode deliveryCode, cfdp::FinishedFileStatus fileStatus):
conditionCode(conditionCode), deliveryCode(deliveryCode), fileStatus(fileStatus) {
}
cfdp::FinishedDeliveryCode deliveryCode,
cfdp::FinishedFileStatus fileStatus)
: conditionCode(conditionCode), deliveryCode(deliveryCode), fileStatus(fileStatus) {}
size_t FinishedInfo::getSerializedSize() const {
size_t size = 1;
if(hasFsResponses()) {
for(size_t idx = 0; idx < fsResponsesLen; idx++) {
if (hasFsResponses()) {
for (size_t idx = 0; idx < fsResponsesLen; idx++) {
size += fsResponses[idx]->getSerializedSize();
}
}
if(this->faultLocation != nullptr) {
if (this->faultLocation != nullptr) {
size += faultLocation->getSerializedSize();
}
return size;
}
bool FinishedInfo::hasFsResponses() const {
if(fsResponses != nullptr and fsResponsesLen > 0) {
if (fsResponses != nullptr and fsResponsesLen > 0) {
return true;
}
return false;
}
bool FinishedInfo::canHoldFsResponses() const {
if(fsResponses != nullptr and fsResponsesMaxLen > 0) {
if (fsResponses != nullptr and fsResponsesMaxLen > 0) {
return true;
}
return false;
}
ReturnValue_t FinishedInfo::setFilestoreResponsesArray(FilestoreResponseTlv** fsResponses,
size_t* fsResponsesLen, const size_t* maxFsResponsesLen) {
size_t* fsResponsesLen,
const size_t* maxFsResponsesLen) {
this->fsResponses = fsResponses;
if(fsResponsesLen != nullptr) {
if (fsResponsesLen != nullptr) {
this->fsResponsesLen = *fsResponsesLen;
if(this->fsResponsesMaxLen < *fsResponsesLen) {
if (this->fsResponsesMaxLen < *fsResponsesLen) {
this->fsResponsesMaxLen = this->fsResponsesLen;
}
}
if(maxFsResponsesLen != nullptr) {
if (maxFsResponsesLen != nullptr) {
this->fsResponsesMaxLen = *maxFsResponsesLen;
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t FinishedInfo::getFilestoreResonses(FilestoreResponseTlv ***fsResponses,
size_t *fsResponsesLen, size_t* fsResponsesMaxLen) {
if(fsResponses == nullptr) {
ReturnValue_t FinishedInfo::getFilestoreResonses(FilestoreResponseTlv*** fsResponses,
size_t* fsResponsesLen,
size_t* fsResponsesMaxLen) {
if (fsResponses == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED;
}
*fsResponses = this->fsResponses;
if(fsResponsesLen != nullptr) {
if (fsResponsesLen != nullptr) {
*fsResponsesLen = this->fsResponsesLen;
}
if(fsResponsesMaxLen != nullptr) {
if (fsResponsesMaxLen != nullptr) {
*fsResponsesMaxLen = this->fsResponsesMaxLen;
}
return HasReturnvaluesIF::RETURN_OK;
}
void FinishedInfo::setFaultLocation(EntityIdTlv *faultLocation) {
void FinishedInfo::setFaultLocation(EntityIdTlv* faultLocation) {
this->faultLocation = faultLocation;
}
ReturnValue_t FinishedInfo::getFaultLocation(EntityIdTlv** faultLocation) {
if(this->faultLocation == nullptr) {
if (this->faultLocation == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED;
}
*faultLocation = this->faultLocation;
return HasReturnvaluesIF::RETURN_OK;
}
cfdp::ConditionCode FinishedInfo::getConditionCode() const {
return conditionCode;
}
cfdp::ConditionCode FinishedInfo::getConditionCode() const { return conditionCode; }
void FinishedInfo::setConditionCode(cfdp::ConditionCode conditionCode) {
this->conditionCode = conditionCode;
}
cfdp::FinishedDeliveryCode FinishedInfo::getDeliveryCode() const {
return deliveryCode;
}
cfdp::FinishedDeliveryCode FinishedInfo::getDeliveryCode() const { return deliveryCode; }
void FinishedInfo::setDeliveryCode(cfdp::FinishedDeliveryCode deliveryCode) {
this->deliveryCode = deliveryCode;
}
cfdp::FinishedFileStatus FinishedInfo::getFileStatus() const {
return fileStatus;
}
cfdp::FinishedFileStatus FinishedInfo::getFileStatus() const { return fileStatus; }
void FinishedInfo::setFilestoreResponsesArrayLen(size_t fsResponsesLen) {
this->fsResponsesLen = fsResponsesLen;
}
size_t FinishedInfo::getFsResponsesLen() const {
return fsResponsesLen;
}
size_t FinishedInfo::getFsResponsesLen() const { return fsResponsesLen; }
void FinishedInfo::setFileStatus(cfdp::FinishedFileStatus fileStatus) {
this->fileStatus = fileStatus;

View File

@ -1,12 +1,12 @@
#ifndef FSFW_SRC_FSFW_CFDP_PDU_FINISHINFO_H_
#define FSFW_SRC_FSFW_CFDP_PDU_FINISHINFO_H_
#include "../definitions.h"
#include "fsfw/cfdp/tlv/EntityIdTlv.h"
#include "fsfw/cfdp/tlv/FilestoreResponseTlv.h"
#include "../definitions.h"
class FinishedInfo {
public:
public:
FinishedInfo();
FinishedInfo(cfdp::ConditionCode conditionCode, cfdp::FinishedDeliveryCode deliveryCode,
cfdp::FinishedFileStatus fileStatus);
@ -20,8 +20,8 @@ public:
size_t* fsResponsesLen, const size_t* maxFsResponseLen);
void setFaultLocation(EntityIdTlv* entityId);
ReturnValue_t getFilestoreResonses(FilestoreResponseTlv ***fsResponses,
size_t *fsResponsesLen, size_t* fsResponsesMaxLen);
ReturnValue_t getFilestoreResonses(FilestoreResponseTlv*** fsResponses, size_t* fsResponsesLen,
size_t* fsResponsesMaxLen);
size_t getFsResponsesLen() const;
void setFilestoreResponsesArrayLen(size_t fsResponsesLen);
ReturnValue_t getFaultLocation(EntityIdTlv** entityId);
@ -32,7 +32,7 @@ public:
cfdp::FinishedFileStatus getFileStatus() const;
void setFileStatus(cfdp::FinishedFileStatus fileStatus);
private:
private:
cfdp::ConditionCode conditionCode = cfdp::ConditionCode::NO_CONDITION_FIELD;
cfdp::FinishedDeliveryCode deliveryCode = cfdp::FinishedDeliveryCode::DATA_COMPLETE;
cfdp::FinishedFileStatus fileStatus = cfdp::FinishedFileStatus::DISCARDED_DELIBERATELY;

View File

@ -1,12 +1,12 @@
#include "FinishedPduDeserializer.h"
FinishPduDeserializer::FinishPduDeserializer(const uint8_t *pduBuf, size_t maxSize,
FinishedInfo &info): FileDirectiveDeserializer(pduBuf, maxSize), finishedInfo(info) {
}
FinishPduDeserializer::FinishPduDeserializer(const uint8_t* pduBuf, size_t maxSize,
FinishedInfo& info)
: FileDirectiveDeserializer(pduBuf, maxSize), finishedInfo(info) {}
ReturnValue_t FinishPduDeserializer::parseData() {
ReturnValue_t result = FileDirectiveDeserializer::parseData();
if(result != HasReturnvaluesIF::RETURN_OK) {
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
size_t currentIdx = FileDirectiveDeserializer::getHeaderSize();
@ -23,18 +23,16 @@ ReturnValue_t FinishPduDeserializer::parseData() {
buf += 1;
remSize -= 1;
currentIdx += 1;
if(remSize > 0) {
if (remSize > 0) {
result = parseTlvs(remSize, currentIdx, buf, condCode);
}
return result;
}
FinishedInfo& FinishPduDeserializer::getInfo() {
return finishedInfo;
}
FinishedInfo& FinishPduDeserializer::getInfo() { return finishedInfo; }
ReturnValue_t FinishPduDeserializer::parseTlvs(size_t remLen, size_t currentIdx,
const uint8_t* buf, cfdp::ConditionCode conditionCode) {
ReturnValue_t FinishPduDeserializer::parseTlvs(size_t remLen, size_t currentIdx, const uint8_t* buf,
cfdp::ConditionCode conditionCode) {
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
size_t fsResponsesIdx = 0;
auto endianness = getEndianness();
@ -42,7 +40,7 @@ ReturnValue_t FinishPduDeserializer::parseTlvs(size_t remLen, size_t currentIdx,
size_t fsResponseMaxArrayLen = 0;
EntityIdTlv* faultLocation = nullptr;
cfdp::TlvTypes nextTlv = cfdp::TlvTypes::INVALID_TLV;
while(remLen > 0) {
while (remLen > 0) {
// Simply forward parse the TLV type. Every TLV type except the last one must be a Filestore
// Response TLV, and even the last one can be a Filestore Response TLV if the fault
// location is omitted
@ -51,34 +49,34 @@ ReturnValue_t FinishPduDeserializer::parseTlvs(size_t remLen, size_t currentIdx,
}
nextTlv = static_cast<cfdp::TlvTypes>(*buf);
if (nextTlv == cfdp::TlvTypes::FILESTORE_RESPONSE) {
if(fsResponseArray == nullptr) {
if(not finishedInfo.canHoldFsResponses()) {
if (fsResponseArray == nullptr) {
if (not finishedInfo.canHoldFsResponses()) {
return cfdp::FINISHED_CANT_PARSE_FS_RESPONSES;
}
result = finishedInfo.getFilestoreResonses(&fsResponseArray, nullptr,
&fsResponseMaxArrayLen);
result =
finishedInfo.getFilestoreResonses(&fsResponseArray, nullptr, &fsResponseMaxArrayLen);
}
if(fsResponsesIdx == fsResponseMaxArrayLen) {
if (fsResponsesIdx == fsResponseMaxArrayLen) {
return cfdp::FINISHED_CANT_PARSE_FS_RESPONSES;
}
result = fsResponseArray[fsResponsesIdx]->deSerialize(&buf, &remLen, endianness);
if(result != HasReturnvaluesIF::RETURN_OK) {
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
fsResponsesIdx += 1;
} else if(nextTlv == cfdp::TlvTypes::ENTITY_ID) {
} else if (nextTlv == cfdp::TlvTypes::ENTITY_ID) {
// This needs to be the last TLV and it should not be here if the condition code
// is "No Error" or "Unsupported Checksum Type"
if(conditionCode == cfdp::ConditionCode::NO_ERROR or
if (conditionCode == cfdp::ConditionCode::NO_ERROR or
conditionCode == cfdp::ConditionCode::UNSUPPORTED_CHECKSUM_TYPE) {
return cfdp::INVALID_TLV_TYPE;
}
result = finishedInfo.getFaultLocation(&faultLocation);
if(result != HasReturnvaluesIF::RETURN_OK) {
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = faultLocation->deSerialize(&buf, &remLen, endianness);
if(result != HasReturnvaluesIF::RETURN_OK) {
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
} else {

View File

@ -1,17 +1,18 @@
#ifndef FSFW_SRC_FSFW_CFDP_PDU_FINISHEDPDUDESERIALIZER_H_
#define FSFW_SRC_FSFW_CFDP_PDU_FINISHEDPDUDESERIALIZER_H_
#include "fsfw/cfdp/pdu/FinishedInfo.h"
#include "fsfw/cfdp/pdu/FileDirectiveDeserializer.h"
#include "fsfw/cfdp/pdu/FinishedInfo.h"
class FinishPduDeserializer: public FileDirectiveDeserializer {
public:
FinishPduDeserializer(const uint8_t *pduBuf, size_t maxSize, FinishedInfo& info);
class FinishPduDeserializer : public FileDirectiveDeserializer {
public:
FinishPduDeserializer(const uint8_t* pduBuf, size_t maxSize, FinishedInfo& info);
ReturnValue_t parseData() override;
FinishedInfo& getInfo();
private:
private:
FinishedInfo& finishedInfo;
ReturnValue_t parseTlvs(size_t remLen, size_t currentIdx, const uint8_t* buf,

Some files were not shown because too many files have changed in this diff Show More