added service 20
This commit is contained in:
@ -6,11 +6,8 @@ target_sources(${TARGET_NAME} PUBLIC
|
||||
|
||||
add_subdirectory(boardconfig)
|
||||
add_subdirectory(boardtest)
|
||||
|
||||
# wiringPi is deprecated unfortunately..
|
||||
#target_link_libraries(${TARGET_NAME} PRIVATE
|
||||
# wiringPi
|
||||
#)
|
||||
add_subdirectory(gpio)
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,6 +1,12 @@
|
||||
#include "InitMission.h"
|
||||
#include "ObjectFactory.h"
|
||||
|
||||
#include <fsfwconfig/objects/systemObjectList.h>
|
||||
#include <fsfwconfig/OBSWConfig.h>
|
||||
#include <fsfwconfig/pollingsequence/PollingSequenceFactory.h>
|
||||
|
||||
#include <mission/utility/InitMission.h>
|
||||
|
||||
#include <fsfw/objectmanager/ObjectManagerIF.h>
|
||||
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <fsfw/serviceinterface/ServiceInterfaceStream.h>
|
||||
@ -8,9 +14,6 @@
|
||||
#include <fsfw/tasks/FixedTimeslotTaskIF.h>
|
||||
#include <fsfw/tasks/PeriodicTaskIF.h>
|
||||
#include <fsfw/tasks/TaskFactory.h>
|
||||
#include <fsfwconfig/objects/systemObjectList.h>
|
||||
#include <fsfwconfig/OBSWConfig.h>
|
||||
#include <fsfwconfig/pollingsequence/PollingSequenceFactory.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@ -34,127 +37,129 @@ void InitMission::initMission() {
|
||||
|
||||
void InitMission::initTasks(){
|
||||
/* TMTC Distribution */
|
||||
PeriodicTaskIF* TmTcDistributor = TaskFactory::instance()->
|
||||
PeriodicTaskIF* tmTcDistributor = TaskFactory::instance()->
|
||||
createPeriodicTask("DIST", 40, PeriodicTaskIF::MINIMUM_STACK_SIZE,
|
||||
0.100, nullptr);
|
||||
ReturnValue_t result = TmTcDistributor->addComponent(
|
||||
ReturnValue_t result = tmTcDistributor->addComponent(
|
||||
objects::CCSDS_PACKET_DISTRIBUTOR);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
sif::error << "Object add component failed" << std::endl;
|
||||
}
|
||||
result = TmTcDistributor->addComponent(objects::PUS_PACKET_DISTRIBUTOR);
|
||||
result = tmTcDistributor->addComponent(objects::PUS_PACKET_DISTRIBUTOR);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
sif::error << "Object add component failed" << std::endl;
|
||||
}
|
||||
result = TmTcDistributor->addComponent(objects::TM_FUNNEL);
|
||||
result = tmTcDistributor->addComponent(objects::TM_FUNNEL);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "Object add component failed" << std::endl;
|
||||
}
|
||||
|
||||
/* UDP bridge */
|
||||
PeriodicTaskIF* UdpBridgeTask = TaskFactory::instance()->createPeriodicTask(
|
||||
PeriodicTaskIF* udpBridgeTask = TaskFactory::instance()->createPeriodicTask(
|
||||
"UDP_UNIX_BRIDGE", 50, PeriodicTaskIF::MINIMUM_STACK_SIZE,
|
||||
0.2, nullptr);
|
||||
result = UdpBridgeTask->addComponent(objects::UDP_BRIDGE);
|
||||
result = udpBridgeTask->addComponent(objects::UDP_BRIDGE);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "Add component UDP Unix Bridge failed" << std::endl;
|
||||
}
|
||||
PeriodicTaskIF* UdpPollingTask = TaskFactory::instance()->
|
||||
PeriodicTaskIF* udpPollingTask = TaskFactory::instance()->
|
||||
createPeriodicTask("UDP_POLLING", 80,
|
||||
PeriodicTaskIF::MINIMUM_STACK_SIZE, 2.0, nullptr);
|
||||
result = UdpPollingTask->addComponent(objects::UDP_POLLING_TASK);
|
||||
result = udpPollingTask->addComponent(objects::UDP_POLLING_TASK);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "Add component UDP Polling failed" << std::endl;
|
||||
}
|
||||
|
||||
/* PUS Services */
|
||||
PeriodicTaskIF* PusVerification = TaskFactory::instance()->
|
||||
createPeriodicTask("PUS_VERIF_1", 40,
|
||||
PeriodicTaskIF* pusVerification = TaskFactory::instance()->
|
||||
createPeriodicTask("PUS_VERIF", 40,
|
||||
PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.200, nullptr);
|
||||
result = PusVerification->addComponent(objects::PUS_SERVICE_1_VERIFICATION);
|
||||
result = pusVerification->addComponent(objects::PUS_SERVICE_1_VERIFICATION);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
sif::error << "Object add component failed" << std::endl;
|
||||
}
|
||||
|
||||
PeriodicTaskIF* PusEvents = TaskFactory::instance()->
|
||||
createPeriodicTask("PUS_VERIF_1", 60,
|
||||
PeriodicTaskIF* pusEvents = TaskFactory::instance()->
|
||||
createPeriodicTask("PUS_EVENTS", 60,
|
||||
PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.200, nullptr);
|
||||
result = PusVerification->addComponent(objects::PUS_SERVICE_5_EVENT_REPORTING);
|
||||
result = pusVerification->addComponent(objects::PUS_SERVICE_5_EVENT_REPORTING);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
sif::error << "Object add component failed" << std::endl;
|
||||
InitMission::printAddObjectError("PUS5", objects::PUS_SERVICE_5_EVENT_REPORTING);
|
||||
}
|
||||
|
||||
PeriodicTaskIF* PusHighPrio = TaskFactory::instance()->
|
||||
PeriodicTaskIF* pusHighPrio = TaskFactory::instance()->
|
||||
createPeriodicTask("PUS_HIGH_PRIO", 50,
|
||||
PeriodicTaskIF::MINIMUM_STACK_SIZE,
|
||||
0.200, nullptr);
|
||||
result = PusHighPrio->addComponent(objects::PUS_SERVICE_2_DEVICE_ACCESS);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
sif::error << "Object add component failed" << std::endl;
|
||||
result = pusHighPrio->addComponent(objects::PUS_SERVICE_2_DEVICE_ACCESS);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
InitMission::printAddObjectError("PUS2", objects::PUS_SERVICE_2_DEVICE_ACCESS);
|
||||
}
|
||||
result = PusHighPrio->addComponent(objects::PUS_SERVICE_9_TIME_MGMT);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
sif::error << "Object add component failed" << std::endl;
|
||||
result = pusHighPrio->addComponent(objects::PUS_SERVICE_9_TIME_MGMT);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
InitMission::printAddObjectError("PUS9", objects::PUS_SERVICE_9_TIME_MGMT);
|
||||
}
|
||||
|
||||
PeriodicTaskIF* PusMedPrio = TaskFactory::instance()->
|
||||
PeriodicTaskIF* pusMedPrio = TaskFactory::instance()->
|
||||
createPeriodicTask("PUS_HIGH_PRIO", 40,
|
||||
PeriodicTaskIF::MINIMUM_STACK_SIZE,
|
||||
0.8, nullptr);
|
||||
result = PusMedPrio->addComponent(objects::PUS_SERVICE_8_FUNCTION_MGMT);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
sif::error << "Object add component failed" << std::endl;
|
||||
}
|
||||
result = PusMedPrio->addComponent(objects::PUS_SERVICE_200_MODE_MGMT);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
sif::error << "Object add component failed" << std::endl;
|
||||
}
|
||||
|
||||
PeriodicTaskIF* PusLowPrio = TaskFactory::instance()->
|
||||
createPeriodicTask("PUSB", 30, PeriodicTaskIF::MINIMUM_STACK_SIZE,
|
||||
1.6, nullptr);
|
||||
result = PusLowPrio->addComponent(objects::PUS_SERVICE_17_TEST);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
sif::error << "Object add component failed" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
#if OBSW_ADD_TEST_CODE == 1
|
||||
FixedTimeslotTaskIF* TestTimeslotTask = TaskFactory::instance()->
|
||||
createFixedTimeslotTask("PST_TEST_TASK", 10,
|
||||
PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.0, nullptr);
|
||||
result = pst::pollingSequenceTestFunction(TestTimeslotTask);
|
||||
result = pusMedPrio->addComponent(objects::PUS_SERVICE_8_FUNCTION_MGMT);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "InitMission::createTasks: Test PST initialization "
|
||||
<< "failed!" << std::endl;
|
||||
InitMission::printAddObjectError("PUS8", objects::PUS_SERVICE_8_FUNCTION_MGMT);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
PeriodicTaskIF* SpiTestTask = TaskFactory::instance()->
|
||||
createPeriodicTask("SPI_TEST", 40, PeriodicTaskIF::MINIMUM_STACK_SIZE,
|
||||
2.0, nullptr);
|
||||
result = SpiTestTask->addComponent(objects::SPI_TEST);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
sif::error << "Object add SPI test failed" << std::endl;
|
||||
result = pusMedPrio->addComponent(objects::PUS_SERVICE_200_MODE_MGMT);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
InitMission::printAddObjectError("PUS200", objects::PUS_SERVICE_200_MODE_MGMT);
|
||||
}
|
||||
result = pusMedPrio->addComponent(objects::PUS_SERVICE_20_PARAMETERS);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
InitMission::printAddObjectError("PUS20", objects::PUS_SERVICE_20_PARAMETERS);
|
||||
}
|
||||
|
||||
//Main thread sleep
|
||||
PeriodicTaskIF* pusLowPrio = TaskFactory::instance()->
|
||||
createPeriodicTask("PUS_LOW_PRIO", 30, PeriodicTaskIF::MINIMUM_STACK_SIZE,
|
||||
1.6, nullptr);
|
||||
result = pusLowPrio->addComponent(objects::PUS_SERVICE_17_TEST);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
InitMission::printAddObjectError("PUS17", objects::PUS_SERVICE_17_TEST);
|
||||
}
|
||||
|
||||
PeriodicTaskIF* testTask = TaskFactory::instance()->
|
||||
createPeriodicTask("SPI_TEST", 40, PeriodicTaskIF::MINIMUM_STACK_SIZE,
|
||||
2.0, nullptr);
|
||||
#if OBSW_ADD_TEST_CODE == 1
|
||||
result = testTask->addComponent(objects::TEST_TASK);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
InitMission::printAddObjectError("TEST_TASK", objects::TEST_TASK);
|
||||
}
|
||||
#endif /* OBSW_ADD_TEST_CODE == 1 */
|
||||
#if RPI_ADD_SPI_TEST == 1
|
||||
result = testTask->addComponent(objects::SPI_TEST);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
InitMission::printAddObjectError("SPI_TEST", objects::SPI_TEST);
|
||||
}
|
||||
#endif /* RPI_ADD_SPI_TEST == 1 */
|
||||
#if RPI_ADD_GPIO_TEST == 1
|
||||
result = testTask->addComponent(objects::LIBGPIOD_TEST);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
InitMission::printAddObjectError("GPIOD_TEST", objects::LIBGPIOD_TEST);
|
||||
}
|
||||
#endif /* RPI_ADD_GPIO_TEST == 1 */
|
||||
|
||||
sif::info << "Starting tasks.." << std::endl;
|
||||
TmTcDistributor->startTask();
|
||||
UdpBridgeTask->startTask();
|
||||
UdpPollingTask->startTask();
|
||||
tmTcDistributor->startTask();
|
||||
udpBridgeTask->startTask();
|
||||
udpPollingTask->startTask();
|
||||
|
||||
PusVerification->startTask();
|
||||
PusEvents->startTask();
|
||||
PusHighPrio->startTask();
|
||||
PusMedPrio->startTask();
|
||||
PusLowPrio->startTask();
|
||||
|
||||
SpiTestTask->startTask();
|
||||
pusVerification->startTask();
|
||||
pusEvents->startTask();
|
||||
pusHighPrio->startTask();
|
||||
pusMedPrio->startTask();
|
||||
pusLowPrio->startTask();
|
||||
|
||||
#if OBSW_ADD_TEST_CODE == 1
|
||||
TestTimeslotTask->startTask();
|
||||
#endif
|
||||
testTask->startTask();
|
||||
#endif /* OBSW_ADD_TEST_CODE == 1 */
|
||||
sif::info << "Tasks started.." << std::endl;
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
#include "ObjectFactory.h"
|
||||
#include <bsp_rpi/boardtest/SpiTest.h>
|
||||
#include <bsp_rpi/gpio/GPIORPi.h>
|
||||
|
||||
#include <objects/systemObjectList.h>
|
||||
#include <devices/gpioIds.h>
|
||||
#include <OBSWConfig.h>
|
||||
#include <tmtc/apid.h>
|
||||
#include <tmtc/pusIds.h>
|
||||
@ -47,11 +49,23 @@ void ObjectFactory::produce(){
|
||||
objects::TM_STORE, objects::TC_STORE);
|
||||
new TcUnixUdpPollingTask(objects::UDP_POLLING_TASK, objects::UDP_BRIDGE);
|
||||
|
||||
new SpiTest(objects::SPI_TEST);
|
||||
new LinuxLibgpioIF(objects::GPIO_IF);
|
||||
new LinuxLibgpioIF(objects::GPIO_IF);
|
||||
|
||||
#if RPI_TEST_GPIO == 1
|
||||
#if RPI_ADD_SPI_TEST == 1
|
||||
new SpiTest(objects::SPI_TEST);
|
||||
#endif
|
||||
|
||||
#if RPI_LOOPBACK_TEST_GPIO == 1
|
||||
GpioCookie* gpioCookie = new GpioCookie();
|
||||
/* Loopback pins. Adapt according to setup */
|
||||
gpioId_t gpioIdSender = gpioIds::TEST_ID_0;
|
||||
int bcmPinSender = 26;
|
||||
gpioId_t gpioIdReader = gpioIds::TEST_ID_1;
|
||||
int bcmPinReader = 16;
|
||||
gpio::createRpiGpioConfig(gpioCookie, gpioIdSender, bcmPinSender, "GPIO_LB_SENDER",
|
||||
gpio::Direction::OUT, 0);
|
||||
gpio::createRpiGpioConfig(gpioCookie, gpioIdReader, bcmPinReader, "GPIO_LB_READER",
|
||||
gpio::Direction::IN, 0);
|
||||
new LibgpiodTest(objects::LIBGPIOD_TEST, objects::GPIO_IF, gpioCookie);
|
||||
#endif
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
#ifndef BSP_RPI_BOARDCONFIG_RPI_CONFIG_H_
|
||||
#define BSP_RPI_BOARDCONFIG_RPI_CONFIG_H_
|
||||
|
||||
#define RPI_TEST_GPIO 1
|
||||
#define RPI_ADD_GPIO_TEST 1
|
||||
#define RPI_ADD_SPI_TEST 1
|
||||
#define RPI_LOOPBACK_TEST_GPIO 1
|
||||
|
||||
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
SpiTest.cpp
|
||||
RPiGPIO.cpp
|
||||
)
|
||||
|
||||
|
||||
|
@ -1,123 +0,0 @@
|
||||
#include "RPiGPIO.h"
|
||||
|
||||
#include <fsfw/serviceinterface/ServiceInterface.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
int RPiGPIO::enablePin(int pin) {
|
||||
char buffer[BUFFER_MAX];
|
||||
ssize_t bytes_written;
|
||||
int fd;
|
||||
|
||||
fd = open("/sys/class/gpio/export", O_WRONLY);
|
||||
if (fd == -1) {
|
||||
sif::error << "Failed to open export of pin " << pin << " for writing!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
bytes_written = snprintf(buffer, BUFFER_MAX, "%d", pin);
|
||||
write(fd, buffer, bytes_written);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int RPiGPIO::disablePin(int pin) {
|
||||
char buffer[BUFFER_MAX];
|
||||
ssize_t bytes_written;
|
||||
int fd;
|
||||
|
||||
fd = open("/sys/class/gpio/unexport", O_WRONLY);
|
||||
if (fd == -1) {
|
||||
sif::error << "Failed to open unexport of pin " << pin << " for writing!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
bytes_written = snprintf(buffer, BUFFER_MAX, "%d", pin);
|
||||
write(fd, buffer, bytes_written);
|
||||
close(fd);
|
||||
return(0);
|
||||
}
|
||||
|
||||
int RPiGPIO::pinDirection(int pin, Directions dir) {
|
||||
|
||||
char path[DIRECTION_MAX];
|
||||
|
||||
snprintf(path, DIRECTION_MAX, "/sys/class/gpio/gpio%d/direction", pin);
|
||||
int fd = open(path, O_WRONLY);
|
||||
if (fd == -1) {
|
||||
sif::error << "Failed to open gpio " << pin << " direction for writing!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
if(dir == Directions::IN) {
|
||||
result = write(fd, "in", IN_WRITE_SIZE);
|
||||
}
|
||||
else {
|
||||
result = write(fd, "out", OUT_WRITE_SIZE);
|
||||
}
|
||||
|
||||
if (result != 0) {
|
||||
sif::error << "Failed to set direction!" << std::endl;
|
||||
return -2;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int RPiGPIO::readPin(int pin) {
|
||||
char path[VALUE_MAX];
|
||||
char value_str[3];
|
||||
|
||||
snprintf(path, VALUE_MAX, "/sys/class/gpio/gpio%d/value", pin);
|
||||
int fd = open(path, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
sif::error << "RPiGPIO::readPin: Failed to open GPIO pin " << pin << "!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (read(fd, value_str, 3) == -1) {
|
||||
sif::error << "Failed to read value!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
char* endPtr = nullptr;
|
||||
|
||||
return strtol(value_str, &endPtr, 10);
|
||||
}
|
||||
|
||||
int RPiGPIO::writePin(int pin, States state) {
|
||||
|
||||
char path[VALUE_MAX];
|
||||
int fd;
|
||||
|
||||
snprintf(path, VALUE_MAX, "/sys/class/gpio/gpio%d/value", pin);
|
||||
fd = open(path, O_WRONLY);
|
||||
if (fd == -1) {
|
||||
sif::error << "RPiGPIO::writePin: Failed to open GPIO pin " << pin << "!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
if(state == States::LOW) {
|
||||
result = write(fd, "0", 1);
|
||||
}
|
||||
else {
|
||||
result = write(fd, "1", 1);
|
||||
}
|
||||
|
||||
|
||||
if (result != 0) {
|
||||
sif::error << "Failed to write pin " << pin << " value to " << static_cast<int>(state)
|
||||
<< "!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
#ifndef BSP_RPI_BOARDTEST_RPIGPIO_H_
|
||||
#define BSP_RPI_BOARDTEST_RPIGPIO_H_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
/**
|
||||
* @brief Really simple C++ GPIO wrapper for the Raspberry Pi, using the sysfs interface.
|
||||
* Use BCM pins notation (https://pinout.xyz/#)
|
||||
*
|
||||
*/
|
||||
class RPiGPIO {
|
||||
public:
|
||||
enum Directions {
|
||||
IN = 0,
|
||||
OUT = 1
|
||||
};
|
||||
|
||||
enum States {
|
||||
LOW = 0,
|
||||
HIGH = 1
|
||||
};
|
||||
|
||||
static int enablePin(int pin);
|
||||
static int disablePin(int pin);
|
||||
static int pinDirection(int pin, Directions dir);
|
||||
static int readPin(int pin);
|
||||
static int writePin(int pin, States state);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
static constexpr uint8_t BUFFER_MAX = 3;
|
||||
static constexpr uint8_t DIRECTION_MAX = 35;
|
||||
static constexpr uint8_t VALUE_MAX = 30;
|
||||
|
||||
static constexpr uint8_t IN_WRITE_SIZE = 3;
|
||||
static constexpr uint8_t OUT_WRITE_SIZE = 4;
|
||||
};
|
||||
|
||||
|
||||
#endif /* BSP_RPI_BOARDTEST_RPIGPIO_H_ */
|
9
bsp_rpi/gpio/CMakeLists.txt
Normal file
9
bsp_rpi/gpio/CMakeLists.txt
Normal file
@ -0,0 +1,9 @@
|
||||
target_sources(${TARGET_NAME} PUBLIC
|
||||
GPIORPi.cpp
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
36
bsp_rpi/gpio/GPIORPi.cpp
Normal file
36
bsp_rpi/gpio/GPIORPi.cpp
Normal 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
26
bsp_rpi/gpio/GPIORPi.h
Normal 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_ */
|
Reference in New Issue
Block a user