Update Linux GPIO #20
@ -9,12 +9,13 @@ using gpioId_t = uint16_t;
|
|||||||
|
|
||||||
namespace gpio {
|
namespace gpio {
|
||||||
|
|
||||||
enum Levels {
|
enum Levels: uint8_t {
|
||||||
LOW = 0,
|
LOW = 0,
|
||||||
HIGH = 1
|
HIGH = 1,
|
||||||
|
NONE = 99
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Direction {
|
enum Direction: uint8_t {
|
||||||
IN = 0,
|
IN = 0,
|
||||||
OUT = 1
|
OUT = 1
|
||||||
};
|
};
|
||||||
@ -24,7 +25,7 @@ enum GpioOperation {
|
|||||||
WRITE
|
WRITE
|
||||||
};
|
};
|
||||||
|
|
||||||
enum GpioTypes {
|
enum class GpioTypes {
|
||||||
NONE,
|
NONE,
|
||||||
GPIO_REGULAR_BY_CHIP,
|
GPIO_REGULAR_BY_CHIP,
|
||||||
GPIO_REGULAR_BY_LABEL,
|
GPIO_REGULAR_BY_LABEL,
|
||||||
@ -34,7 +35,8 @@ enum GpioTypes {
|
|||||||
|
|
||||||
static constexpr gpioId_t NO_GPIO = -1;
|
static constexpr gpioId_t NO_GPIO = -1;
|
||||||
|
|
||||||
using gpio_cb_t = void (*) (gpioId_t gpioId, gpio::GpioOperation gpioOp, int value, void* args);
|
using gpio_cb_t = void (*) (gpioId_t gpioId, gpio::GpioOperation gpioOp, gpio::Levels value,
|
||||||
|
void* args);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +60,7 @@ public:
|
|||||||
GpioBase() = default;
|
GpioBase() = default;
|
||||||
|
|
||||||
GpioBase(gpio::GpioTypes gpioType, std::string consumer, gpio::Direction direction,
|
GpioBase(gpio::GpioTypes gpioType, std::string consumer, gpio::Direction direction,
|
||||||
int initValue):
|
gpio::Levels initValue):
|
||||||
gpioType(gpioType), consumer(consumer),direction(direction), initValue(initValue) {}
|
gpioType(gpioType), consumer(consumer),direction(direction), initValue(initValue) {}
|
||||||
|
|
||||||
virtual~ GpioBase() {};
|
virtual~ GpioBase() {};
|
||||||
@ -67,19 +69,19 @@ public:
|
|||||||
gpio::GpioTypes gpioType = gpio::GpioTypes::NONE;
|
gpio::GpioTypes gpioType = gpio::GpioTypes::NONE;
|
||||||
std::string consumer;
|
std::string consumer;
|
||||||
gpio::Direction direction = gpio::Direction::IN;
|
gpio::Direction direction = gpio::Direction::IN;
|
||||||
int initValue = 0;
|
gpio::Levels initValue = gpio::Levels::NONE;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GpiodRegularBase: public GpioBase {
|
class GpiodRegularBase: public GpioBase {
|
||||||
public:
|
public:
|
||||||
GpiodRegularBase(gpio::GpioTypes gpioType, std::string consumer, gpio::Direction direction,
|
GpiodRegularBase(gpio::GpioTypes gpioType, std::string consumer, gpio::Direction direction,
|
||||||
int initValue, int lineNum): GpioBase(gpioType, consumer, direction, initValue),
|
gpio::Levels initValue, int lineNum):
|
||||||
lineNum(lineNum) {
|
GpioBase(gpioType, consumer, direction, initValue), lineNum(lineNum) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// line number will be configured at a later point for the open by line name configuration
|
// 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,
|
GpiodRegularBase(gpio::GpioTypes gpioType, std::string consumer, gpio::Direction direction,
|
||||||
int initValue): GpioBase(gpioType, consumer, direction, initValue) {
|
gpio::Levels initValue): GpioBase(gpioType, consumer, direction, initValue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int lineNum = 0;
|
int lineNum = 0;
|
||||||
@ -94,7 +96,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
GpiodRegularByChip(std::string chipname_, int lineNum_, std::string consumer_,
|
GpiodRegularByChip(std::string chipname_, int lineNum_, std::string consumer_,
|
||||||
gpio::Direction direction_, int initValue_) :
|
gpio::Direction direction_, gpio::Levels initValue_) :
|
||||||
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP,
|
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_CHIP,
|
||||||
consumer_, direction_, initValue_, lineNum_),
|
consumer_, direction_, initValue_, lineNum_),
|
||||||
chipname(chipname_){
|
chipname(chipname_){
|
||||||
@ -112,7 +114,7 @@ public:
|
|||||||
class GpiodRegularByLabel: public GpiodRegularBase {
|
class GpiodRegularByLabel: public GpiodRegularBase {
|
||||||
public:
|
public:
|
||||||
GpiodRegularByLabel(std::string label_, int lineNum_, std::string consumer_,
|
GpiodRegularByLabel(std::string label_, int lineNum_, std::string consumer_,
|
||||||
gpio::Direction direction_, int initValue_) :
|
gpio::Direction direction_, gpio::Levels initValue_) :
|
||||||
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL, consumer_,
|
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LABEL, consumer_,
|
||||||
direction_, initValue_, lineNum_),
|
direction_, initValue_, lineNum_),
|
||||||
label(label_) {
|
label(label_) {
|
||||||
@ -135,14 +137,14 @@ public:
|
|||||||
class GpiodRegularByLineName: public GpiodRegularBase {
|
class GpiodRegularByLineName: public GpiodRegularBase {
|
||||||
public:
|
public:
|
||||||
GpiodRegularByLineName(std::string lineName_, std::string consumer_, gpio::Direction direction_,
|
GpiodRegularByLineName(std::string lineName_, std::string consumer_, gpio::Direction direction_,
|
||||||
int initValue_) :
|
gpio::Levels initValue_) :
|
||||||
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME, consumer_, direction_,
|
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME, consumer_, direction_,
|
||||||
initValue_), lineName(lineName_) {
|
initValue_), lineName(lineName_) {
|
||||||
}
|
}
|
||||||
|
|
||||||
GpiodRegularByLineName(std::string lineName_, std::string consumer_) :
|
GpiodRegularByLineName(std::string lineName_, std::string consumer_) :
|
||||||
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME, consumer_, gpio::Direction::IN,
|
GpiodRegularBase(gpio::GpioTypes::GPIO_REGULAR_BY_LINE_NAME, consumer_,
|
||||||
gpio::LOW), lineName(lineName_) {
|
gpio::Direction::IN, gpio::LOW), lineName(lineName_) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string lineName;
|
std::string lineName;
|
||||||
@ -150,7 +152,7 @@ public:
|
|||||||
|
|
||||||
class GpioCallback: public GpioBase {
|
class GpioCallback: public GpioBase {
|
||||||
public:
|
public:
|
||||||
GpioCallback(std::string consumer, gpio::Direction direction_, int initValue_,
|
GpioCallback(std::string consumer, gpio::Direction direction_, gpio::Levels initValue_,
|
||||||
gpio::gpio_cb_t callback, void* callbackArgs):
|
gpio::gpio_cb_t callback, void* callbackArgs):
|
||||||
GpioBase(gpio::GpioTypes::CALLBACK, consumer, direction_, initValue_),
|
GpioBase(gpio::GpioTypes::CALLBACK, consumer, direction_, initValue_),
|
||||||
callback(callback), callbackArgs(callbackArgs) {}
|
callback(callback), callbackArgs(callbackArgs) {}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
#include "fsfw_hal/linux/gpio/LinuxLibgpioIF.h"
|
#include "LinuxLibgpioIF.h"
|
||||||
|
|
||||||
#include "fsfw_hal/common/gpio/gpioDefinitions.h"
|
#include "fsfw_hal/common/gpio/gpioDefinitions.h"
|
||||||
#include "fsfw_hal/common/gpio/GpioCookie.h"
|
#include "fsfw_hal/common/gpio/GpioCookie.h"
|
||||||
|
|
||||||
#include <fsfw/serviceinterface/ServiceInterface.h>
|
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -221,7 +222,7 @@ ReturnValue_t LinuxLibgpioIF::pullHigh(gpioId_t gpioId) {
|
|||||||
return GPIO_INVALID_INSTANCE;
|
return GPIO_INVALID_INSTANCE;
|
||||||
}
|
}
|
||||||
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE,
|
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE,
|
||||||
1, gpioCallback->callbackArgs);
|
gpio::Levels::HIGH, gpioCallback->callbackArgs);
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
return GPIO_TYPE_FAILURE;
|
return GPIO_TYPE_FAILURE;
|
||||||
@ -254,7 +255,7 @@ ReturnValue_t LinuxLibgpioIF::pullLow(gpioId_t gpioId) {
|
|||||||
return GPIO_INVALID_INSTANCE;
|
return GPIO_INVALID_INSTANCE;
|
||||||
}
|
}
|
||||||
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE,
|
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE,
|
||||||
0, gpioCallback->callbackArgs);
|
gpio::Levels::LOW, gpioCallback->callbackArgs);
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
return GPIO_TYPE_FAILURE;
|
return GPIO_TYPE_FAILURE;
|
||||||
@ -299,10 +300,14 @@ ReturnValue_t LinuxLibgpioIF::readGpio(gpioId_t gpioId, int* gpioState) {
|
|||||||
*gpioState = gpiod_line_get_value(regularGpio->lineHandle);
|
*gpioState = gpiod_line_get_value(regularGpio->lineHandle);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
auto gpioCallback = dynamic_cast<GpioCallback*>(gpioMapIter->second);
|
||||||
|
if(gpioCallback->callback == nullptr) {
|
||||||
|
return GPIO_INVALID_INSTANCE;
|
||||||
|
}
|
||||||
|
gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::READ,
|
||||||
|
gpio::Levels::NONE, gpioCallback->callbackArgs);
|
||||||
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
#ifndef LINUX_GPIO_LINUXLIBGPIOIF_H_
|
#ifndef LINUX_GPIO_LINUXLIBGPIOIF_H_
|
||||||
#define LINUX_GPIO_LINUXLIBGPIOIF_H_
|
#define LINUX_GPIO_LINUXLIBGPIOIF_H_
|
||||||
|
|
||||||
#include "../../common/gpio/GpioIF.h"
|
#include "fsfw/returnvalues/FwClassIds.h"
|
||||||
#include <returnvalues/classIds.h>
|
#include "fsfw_hal/common/gpio/GpioIF.h"
|
||||||
#include <fsfw/objectmanager/SystemObject.h>
|
#include "fsfw/objectmanager/SystemObject.h"
|
||||||
|
|
||||||
class GpioCookie;
|
class GpioCookie;
|
||||||
class GpiodRegularIF;
|
class GpiodRegularIF;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This class implements the GpioIF for a linux based system. The
|
* @brief This class implements the GpioIF for a linux based system.
|
||||||
* implementation is based on the libgpiod lib which requires linux 4.8
|
* @details
|
||||||
* or higher.
|
* This implementation is based on the libgpiod lib which requires Linux 4.8 or higher.
|
||||||
* @note The Petalinux SDK from Xilinx supports libgpiod since Petalinux
|
* @note
|
||||||
* 2019.1.
|
* The Petalinux SDK from Xilinx supports libgpiod since Petalinux 2019.1.
|
||||||
*/
|
*/
|
||||||
class LinuxLibgpioIF : public GpioIF, public SystemObject {
|
class LinuxLibgpioIF : public GpioIF, public SystemObject {
|
||||||
public:
|
public:
|
||||||
@ -46,7 +46,7 @@ private:
|
|||||||
static const int LINE_ERROR = -1;
|
static const int LINE_ERROR = -1;
|
||||||
static const int LINE_FOUND = 1;
|
static const int LINE_FOUND = 1;
|
||||||
|
|
||||||
/* Holds the information and configuration of all used GPIOs */
|
// Holds the information and configuration of all used GPIOs
|
||||||
GpioUnorderedMap gpioMap;
|
GpioUnorderedMap gpioMap;
|
||||||
GpioUnorderedMapIter gpioMapIter;
|
GpioUnorderedMapIter gpioMapIter;
|
||||||
|
|
||||||
@ -79,7 +79,6 @@ private:
|
|||||||
|
|
||||||
ReturnValue_t checkForConflictsById(gpioId_t gpiodId, gpio::GpioTypes type,
|
ReturnValue_t checkForConflictsById(gpioId_t gpiodId, gpio::GpioTypes type,
|
||||||
GpioMap& mapToAdd);
|
GpioMap& mapToAdd);
|
||||||
//ReturnValue_t checkForConflictsCallbackGpio(gpioId_t gpiodId, GpioMap& mapToAdd);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Performs the initial configuration of all GPIOs specified in the GpioMap mapToAdd.
|
* @brief Performs the initial configuration of all GPIOs specified in the GpioMap mapToAdd.
|
||||||
|
Loading…
Reference in New Issue
Block a user