added service 20

This commit is contained in:
2021-02-22 17:36:44 +01:00
parent ac250cb4cb
commit b03420c706
24 changed files with 358 additions and 196 deletions

View File

@ -0,0 +1,9 @@
target_sources(${TARGET_NAME} PUBLIC
GPIORPi.cpp
)

36
bsp_rpi/gpio/GPIORPi.cpp Normal file
View File

@ -0,0 +1,36 @@
#include "GPIORPi.h"
#include <FSFWConfig.h>
#include <fsfw/serviceinterface/ServiceInterface.h>
#include <linux/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) {
return HasReturnvaluesIF::RETURN_FAILED;
}
GpioConfig_t config;
/* Default chipname for Raspberry Pi. There is still gpiochip1 for expansion, but most users
will not need this */
config.chipname = "gpiochip0";
config.consumer = consumer;
config.direction = direction;
config.initValue = initValue;
/* Sanity check for the BCM pins before assigning it */
if(bcmPin > 27) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "createRpiGpioConfig: BCM pin " << bcmPin << " invalid!" << std::endl;
#else
sif::printError("createRpiGpioConfig: BCM pin %d invalid!\n", bcmPin);
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
return HasReturnvaluesIF::RETURN_FAILED;
}
config.lineNum = bcmPin;
cookie->addGpio(gpioId, config);
return HasReturnvaluesIF::RETURN_OK;
}

26
bsp_rpi/gpio/GPIORPi.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef BSP_RPI_GPIO_GPIORPI_H_
#define BSP_RPI_GPIO_GPIORPI_H_
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
#include <linux/gpio/gpioDefinitions.h>
class GpioCookie;
namespace gpio {
/**
* Create a GpioConfig_t. This function does a sanity check on the BCM pin number and fails if the
* BCM pin is invalid.
* @param cookie Adds the configuration to this cookie directly
* @param gpioId ID which identifies the GPIO configuration
* @param bcmPin Raspberry Pi BCM pin
* @param consumer Information string
* @param direction GPIO direction
* @param initValue Intial value for output pins, 0 for low, 1 for high
* @return
*/
ReturnValue_t createRpiGpioConfig(GpioCookie* cookie, gpioId_t gpioId, int bcmPin,
std::string consumer, gpio::Direction direction, int initValue);
}
#endif /* BSP_RPI_GPIO_GPIORPI_H_ */