2021-07-13 19:19:25 +02:00
|
|
|
#ifndef LINUX_GPIO_LINUXLIBGPIOIF_H_
|
|
|
|
#define LINUX_GPIO_LINUXLIBGPIOIF_H_
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
#include "fsfw/objectmanager/SystemObject.h"
|
2021-10-11 19:55:37 +02:00
|
|
|
#include "fsfw/returnvalues/FwClassIds.h"
|
|
|
|
#include "fsfw_hal/common/gpio/GpioIF.h"
|
2021-07-13 19:19:25 +02:00
|
|
|
|
|
|
|
class GpioCookie;
|
2021-09-23 17:58:44 +02:00
|
|
|
class GpiodRegularIF;
|
2021-07-13 19:19:25 +02:00
|
|
|
|
|
|
|
/**
|
2021-10-11 19:55:37 +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 {
|
2022-02-02 10:29:30 +01:00
|
|
|
public:
|
|
|
|
static const uint8_t gpioRetvalId = CLASS_ID::HAL_GPIO;
|
|
|
|
|
|
|
|
static constexpr ReturnValue_t UNKNOWN_GPIO_ID =
|
2022-08-16 12:29:53 +02:00
|
|
|
returnvalue::makeCode(gpioRetvalId, 1);
|
2022-02-02 10:29:30 +01:00
|
|
|
static constexpr ReturnValue_t DRIVE_GPIO_FAILURE =
|
2022-08-16 12:29:53 +02:00
|
|
|
returnvalue::makeCode(gpioRetvalId, 2);
|
2022-02-02 10:29:30 +01:00
|
|
|
static constexpr ReturnValue_t GPIO_TYPE_FAILURE =
|
2022-08-16 12:29:53 +02:00
|
|
|
returnvalue::makeCode(gpioRetvalId, 3);
|
2022-02-02 10:29:30 +01:00
|
|
|
static constexpr ReturnValue_t GPIO_INVALID_INSTANCE =
|
2022-08-16 12:29:53 +02:00
|
|
|
returnvalue::makeCode(gpioRetvalId, 4);
|
2022-02-02 10:29:30 +01:00
|
|
|
static constexpr ReturnValue_t GPIO_DUPLICATE_DETECTED =
|
2022-08-16 12:29:53 +02:00
|
|
|
returnvalue::makeCode(gpioRetvalId, 5);
|
2022-04-25 14:32:05 +02:00
|
|
|
static constexpr ReturnValue_t GPIO_INIT_FAILED =
|
2022-08-16 12:29:53 +02:00
|
|
|
returnvalue::makeCode(gpioRetvalId, 6);
|
2022-02-02 10:29:30 +01: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:
|
|
|
|
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;
|
|
|
|
|
|
|
|
// Holds the information and configuration of all used GPIOs
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
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 configureRegularGpio(gpioId_t gpioId, struct gpiod_chip* chip,
|
|
|
|
GpiodRegularBase& regularGpio, std::string failOutput);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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.
|
|
|
|
*
|
2022-08-16 12:12:21 +02:00
|
|
|
* @return returnvalue::OK if successful, otherwise returnvalue::FAILED
|
2022-02-02 10:29:30 +01:00
|
|
|
*/
|
|
|
|
ReturnValue_t checkForConflicts(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.
|
|
|
|
*/
|
|
|
|
ReturnValue_t configureGpios(GpioMap& mapToAdd);
|
|
|
|
|
|
|
|
void parseFindeLineResult(int result, std::string& lineName);
|
2021-07-13 19:19:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* LINUX_GPIO_LINUXLIBGPIOIF_H_ */
|