2021-07-13 19:19:25 +02:00
|
|
|
#ifndef LINUX_GPIO_LINUXLIBGPIOIF_H_
|
|
|
|
#define LINUX_GPIO_LINUXLIBGPIOIF_H_
|
|
|
|
|
2021-09-27 10:51:31 +02:00
|
|
|
#include "fsfw/returnvalues/FwClassIds.h"
|
|
|
|
#include "fsfw_hal/common/gpio/GpioIF.h"
|
|
|
|
#include "fsfw/objectmanager/SystemObject.h"
|
2021-07-13 19:19:25 +02:00
|
|
|
|
|
|
|
class GpioCookie;
|
2021-09-21 17:31:03 +02:00
|
|
|
class GpiodRegularIF;
|
2021-07-13 19:19:25 +02:00
|
|
|
|
|
|
|
/**
|
2021-09-27 10:51:31 +02:00
|
|
|
* @brief This class implements the GpioIF for a linux based system.
|
|
|
|
* @details
|
|
|
|
* 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 2019.1.
|
2021-07-13 19:19:25 +02:00
|
|
|
*/
|
|
|
|
class LinuxLibgpioIF : public GpioIF, public SystemObject {
|
|
|
|
public:
|
|
|
|
|
|
|
|
static const uint8_t gpioRetvalId = CLASS_ID::HAL_GPIO;
|
|
|
|
|
|
|
|
static constexpr ReturnValue_t UNKNOWN_GPIO_ID =
|
|
|
|
HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 1);
|
|
|
|
static constexpr ReturnValue_t DRIVE_GPIO_FAILURE =
|
|
|
|
HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 2);
|
|
|
|
static constexpr ReturnValue_t GPIO_TYPE_FAILURE =
|
|
|
|
HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 3);
|
|
|
|
static constexpr ReturnValue_t GPIO_INVALID_INSTANCE =
|
|
|
|
HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 4);
|
2021-09-27 10:38:47 +02:00
|
|
|
static constexpr ReturnValue_t GPIO_DUPLICATE_DETECTED =
|
|
|
|
HasReturnvaluesIF::makeReturnCode(gpioRetvalId, 5);
|
2021-07-13 19:19:25 +02:00
|
|
|
|
|
|
|
LinuxLibgpioIF(object_id_t objectId);
|
|
|
|
virtual ~LinuxLibgpioIF();
|
|
|
|
|
|
|
|
ReturnValue_t addGpios(GpioCookie* gpioCookie) override;
|
|
|
|
ReturnValue_t pullHigh(gpioId_t gpioId) override;
|
|
|
|
ReturnValue_t pullLow(gpioId_t gpioId) override;
|
|
|
|
ReturnValue_t readGpio(gpioId_t gpioId, int* gpioState) override;
|
|
|
|
|
|
|
|
private:
|
2021-09-23 17:54:41 +02:00
|
|
|
|
|
|
|
static const size_t MAX_CHIPNAME_LENGTH = 11;
|
|
|
|
static const int LINE_NOT_EXISTS = 0;
|
|
|
|
static const int LINE_ERROR = -1;
|
|
|
|
static const int LINE_FOUND = 1;
|
|
|
|
|
2021-09-27 10:51:31 +02:00
|
|
|
// Holds the information and configuration of all used GPIOs
|
2021-07-13 19:19:25 +02:00
|
|
|
GpioUnorderedMap gpioMap;
|
|
|
|
GpioUnorderedMapIter gpioMapIter;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This functions drives line of a GPIO specified by the GPIO ID.
|
|
|
|
*
|
|
|
|
* @param gpioId The GPIO ID of the GPIO to drive.
|
|
|
|
* @param logiclevel The logic level to set. O or 1.
|
|
|
|
*/
|
2021-09-21 17:31:03 +02:00
|
|
|
ReturnValue_t driveGpio(gpioId_t gpioId, GpiodRegularBase& regularGpio,
|
|
|
|
gpio::Levels logicLevel);
|
2021-07-13 19:19:25 +02:00
|
|
|
|
2021-09-21 17:31:03 +02:00
|
|
|
ReturnValue_t configureGpioByLabel(gpioId_t gpioId, GpiodRegularByLabel& gpioByLabel);
|
|
|
|
ReturnValue_t configureGpioByChip(gpioId_t gpioId, GpiodRegularByChip& gpioByChip);
|
2021-09-23 17:54:41 +02:00
|
|
|
ReturnValue_t configureGpioByLineName(gpioId_t gpioId,
|
|
|
|
GpiodRegularByLineName &gpioByLineName);
|
|
|
|
ReturnValue_t configureRegularGpio(gpioId_t gpioId, struct gpiod_chip* chip,
|
|
|
|
GpiodRegularBase& regularGpio, std::string failOutput);
|
2021-07-13 19:19:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This function checks if GPIOs are already registered and whether
|
|
|
|
* there exists a conflict in the GPIO configuration. E.g. the
|
|
|
|
* direction.
|
|
|
|
*
|
|
|
|
* @param mapToAdd The GPIOs which shall be added to the gpioMap.
|
|
|
|
*
|
|
|
|
* @return RETURN_OK if successful, otherwise RETURN_FAILED
|
|
|
|
*/
|
|
|
|
ReturnValue_t checkForConflicts(GpioMap& mapToAdd);
|
|
|
|
|
2021-09-27 10:38:47 +02:00
|
|
|
ReturnValue_t checkForConflictsById(gpioId_t gpiodId, gpio::GpioTypes type,
|
2021-07-13 19:19:25 +02:00
|
|
|
GpioMap& mapToAdd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Performs the initial configuration of all GPIOs specified in the GpioMap mapToAdd.
|
|
|
|
*/
|
|
|
|
ReturnValue_t configureGpios(GpioMap& mapToAdd);
|
|
|
|
|
2021-09-23 17:54:41 +02:00
|
|
|
void parseFindeLineResult(int result, std::string& lineName);
|
2021-07-13 19:19:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* LINUX_GPIO_LINUXLIBGPIOIF_H_ */
|