I2C Info, minor fixes, GPIO ctor for simple input pins #10

Merged
muellerr merged 6 commits from meier/master into master 2021-06-15 16:55:17 +02:00
5 changed files with 30 additions and 14 deletions

View File

@ -61,7 +61,7 @@ public:
virtual~ GpioBase() {};
/* Can be used to cast GpioBase to a concrete child implementation */
// Can be used to cast GpioBase to a concrete child implementation
gpio::GpioTypes gpioType = gpio::GpioTypes::NONE;
std::string consumer;
gpio::Direction direction = gpio::Direction::IN;
@ -70,13 +70,21 @@ public:
class GpiodRegular: public GpioBase {
public:
GpiodRegular(): GpioBase(gpio::GpioTypes::GPIO_REGULAR, std::string(),
gpio::Direction::IN, 0) {};
GpiodRegular() :
GpioBase(gpio::GpioTypes::GPIO_REGULAR, std::string(), gpio::Direction::IN, 0) {
}
;
GpiodRegular(std::string chipname_, int lineNum_, std::string consumer_,
gpio::Direction direction_, int initValue_):
gpio::Direction direction_, int initValue_) :
GpioBase(gpio::GpioTypes::GPIO_REGULAR, consumer_, direction_, initValue_),
chipname(chipname_), lineNum(lineNum_) {}
chipname(chipname_), lineNum(lineNum_) {
}
GpiodRegular(std::string chipname_, int lineNum_, std::string consumer_) :
GpioBase(gpio::GpioTypes::GPIO_REGULAR, consumer_, gpio::Direction::IN, 0),
chipname(chipname_), lineNum(lineNum_) {
}
std::string chipname;
int lineNum = 0;
struct gpiod_line* lineHandle = nullptr;

View File

@ -17,7 +17,7 @@ class GpioCookie;
class LinuxLibgpioIF : public GpioIF, public SystemObject {
public:
static const uint8_t gpioRetvalId = CLASS_ID::LINUX_LIBGPIO_IF;
static const uint8_t gpioRetvalId = CLASS_ID::HAL_GPIO;
static constexpr ReturnValue_t UNKNOWN_GPIO_ID =
HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 1);

View File

@ -38,7 +38,7 @@ ReturnValue_t I2cComIF::initializeInterface(CookieIF* cookie) {
i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress);
if(i2cDeviceMapIter == i2cDeviceMap.end()) {
size_t maxReplyLen = i2cCookie->getMaxReplyLen();
I2cInstance_t i2cInstance = {std::vector<uint8_t>(maxReplyLen), 0};
I2cInstance i2cInstance = {std::vector<uint8_t>(maxReplyLen), 0};
auto statusPair = i2cDeviceMap.emplace(i2cAddress, i2cInstance);
if (not statusPair.second) {
sif::error << "I2cComIF::initializeInterface: Failed to insert device with address " <<
@ -146,10 +146,16 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF *cookie,
uint8_t* replyBuffer = i2cDeviceMapIter->second.replyBuffer.data();
if (read(fd, replyBuffer, requestLen) != static_cast<int>(requestLen)) {
int readLen = read(fd, replyBuffer, requestLen);
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"
<< " of error: " << strerror(errno) << std::endl;
sif::error << "I2cComIF::requestReceiveMessage: Read only " << readLen << " from "
<< requestLen << " bytes" << std::endl;
#endif
i2cDeviceMapIter->second.replyLen = 0;
return HasReturnvaluesIF::RETURN_FAILED;
}

View File

@ -9,8 +9,10 @@
#include <vector>
/**
* @brief This is the communication interface for i2c devices connected
* to a system running a linux OS.
* @brief This is the communication interface for I2C devices connected
* to a system running a Linux OS.
*
* @note The Xilinx Linux kernel might not support to read more than 255 bytes at once.
*
* @author J. Meier
*/
@ -31,12 +33,12 @@ public:
private:
typedef struct I2cInstance {
struct I2cInstance {
std::vector<uint8_t> replyBuffer;
size_t replyLen;
} I2cInstance_t;
};
using I2cDeviceMap = std::unordered_map<address_t, I2cInstance_t>;
using I2cDeviceMap = std::unordered_map<address_t, I2cInstance>;
using I2cDeviceMapIter = I2cDeviceMap::iterator;
/* In this map all i2c devices will be registered with their address and

View File

@ -22,7 +22,7 @@ class SpiCookie;
*/
class SpiComIF: public DeviceCommunicationIF, public SystemObject {
public:
static constexpr uint8_t spiRetvalId = CLASS_ID::LINUX_SPI_COM_IF;
static constexpr uint8_t spiRetvalId = CLASS_ID::HAL_SPI;
static constexpr ReturnValue_t OPENING_FILE_FAILED =
HasReturnvaluesIF::makeReturnCode(spiRetvalId, 0);
/* Full duplex (ioctl) transfer failure */