commanding of HeaterHandler and GpioIF working
This commit is contained in:
@ -12,6 +12,8 @@
|
||||
#include <fsfw/tmtcpacket/pus/TmPacketStored.h>
|
||||
#include <fsfw/osal/linux/TcUnixUdpPollingTask.h>
|
||||
|
||||
#include <fsfwconfig/devices/powerSwitcherList.h>
|
||||
|
||||
#include <mission/core/GenericFactory.h>
|
||||
#include <mission/devices/PDU1Handler.h>
|
||||
#include <mission/devices/PDU2Handler.h>
|
||||
@ -19,6 +21,7 @@
|
||||
#include <mission/devices/PCDUHandler.h>
|
||||
#include <mission/devices/P60DockHandler.h>
|
||||
#include <mission/devices/Tmp1075Handler.h>
|
||||
#include <mission/devices/HeaterHandler.h>
|
||||
#include <mission/devices/devicedefinitions/GomSpacePackets.h>
|
||||
#include <mission/devices/devicedefinitions/GomspaceDefinitions.h>
|
||||
#include <mission/utility/TmFunnel.h>
|
||||
@ -102,19 +105,20 @@ void ObjectFactory::produce(){
|
||||
tmp1075Handler_2->setStartUpImmediately();
|
||||
|
||||
/* Thermal objects */
|
||||
GpioCookie gpioCookie = new GpioCookie;
|
||||
GpioCookie* gpioCookie = new GpioCookie;
|
||||
#if TE0720 == 1
|
||||
// Configuration for MIO0 on TE0720-03-1CFA
|
||||
GpioConfig_t gpioConfigForDummyHeater(std::string("gpiochip0"), 0,
|
||||
std::string("Heater0"), Gpio::OUT);
|
||||
gpioCookie.add(gpioIds::HEATER_0, gpioConfigForDummyHeater);
|
||||
gpioCookie->addGpio(gpioIds::HEATER_0, gpioConfigForDummyHeater);
|
||||
#else
|
||||
GpioConfig_t gpioConfigHeater0(std::string("gpiochip5"), 6,
|
||||
std::string("Heater0"), Gpio::OUT);
|
||||
gpioCookie.add(gpioIds::HEATER_0, gpioConfigHeater0);
|
||||
gpioCookie->addGpio(gpioIds::HEATER_0, gpioConfigHeater0);
|
||||
#endif
|
||||
LinuxLibgpioIF linuxLibgpioIF = new LinuxLibgpioIF(objects::GPIO_IF);
|
||||
new HeaterHandler(objects::HEATER_HANDLER, objects::GPIO_IF, gpioCookie);
|
||||
new LinuxLibgpioIF(objects::GPIO_IF);
|
||||
new HeaterHandler(objects::HEATER_HANDLER, objects::GPIO_IF, gpioCookie, objects::PCDU_HANDLER,
|
||||
pcduSwitches::TCS_BOARD_8V_HEATER_IN);
|
||||
|
||||
new TmTcUnixUdpBridge(objects::UDP_BRIDGE,
|
||||
objects::CCSDS_PACKET_DISTRIBUTOR,
|
||||
|
@ -14,7 +14,7 @@ typedef uint16_t gpioId_t;
|
||||
class GpioIF : public HasReturnvaluesIF{
|
||||
public:
|
||||
|
||||
virtual ~GpioIF();
|
||||
virtual ~GpioIF() {};
|
||||
|
||||
/**
|
||||
* @brief Called by the GPIO using object.
|
||||
|
@ -1,6 +1,9 @@
|
||||
#include <bsp_q7s/gpio/LinuxLibgpioIF.h>
|
||||
#include <gpio.h>
|
||||
#include <fsfw/serviceinterface/ServiceInterfaceStream.h>
|
||||
|
||||
#include <utility>
|
||||
#include <unistd.h>
|
||||
#include <gpiod.h>
|
||||
|
||||
LinuxLibgpioIF::LinuxLibgpioIF(object_id_t objectId) : SystemObject(objectId) {
|
||||
}
|
||||
@ -14,16 +17,17 @@ ReturnValue_t LinuxLibgpioIF::initialize(CookieIF * cookie){
|
||||
GpioMapIter mapToAddIter;
|
||||
|
||||
if(cookie == nullptr) {
|
||||
return NULLPOINTER;
|
||||
sif::error << "LinuxLibgpioIF::initialize: Invalid cookie" << std::endl;
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
GpioCookie* GpioCookie = dynamic_cast<GpioCookie*>(cookie);
|
||||
if(GpioCookie == nullptr) {
|
||||
GpioCookie* gpioCookie = dynamic_cast<GpioCookie*>(cookie);
|
||||
if(gpioCookie == nullptr) {
|
||||
sif::error << "LinuxLibgpioIF: Invalid Gpio Cookie!"
|
||||
<< std::endl;
|
||||
return NULLPOINTER;
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
|
||||
mapToAdd = GpioCookie->getGpioMap();
|
||||
mapToAdd = gpioCookie->getGpioMap();
|
||||
|
||||
result = checkForConflicts(mapToAdd);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK){
|
||||
@ -31,20 +35,7 @@ ReturnValue_t LinuxLibgpioIF::initialize(CookieIF * cookie){
|
||||
}
|
||||
|
||||
/* Register new GPIOs in gpioMap*/
|
||||
result = initializeAndConfigure(mapToAdd);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK){
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Register new GPIOs in gpioMap*/
|
||||
std::pair insertionResult = gpioMap.insert(mapToAdd.begin(),
|
||||
mapToAdd.end());
|
||||
if (insertionResult.second() != true) {
|
||||
sif::error << "LinuxLibgpioIF::initialize: Failed to add "
|
||||
<< "GPIO with ID " << mapToAddIter.first << " to gpioMap"
|
||||
<< std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
gpioMap.insert(mapToAdd.begin(), mapToAdd.end());
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
@ -60,41 +51,43 @@ ReturnValue_t LinuxLibgpioIF::pullLow(gpioId_t gpioId){
|
||||
ReturnValue_t LinuxLibgpioIF::driveGpio(gpioId_t gpioId,
|
||||
unsigned int logiclevel) {
|
||||
GpioMapIter gpioMapIter = gpioMap.find(gpioId);
|
||||
char *chipname;
|
||||
std::string chipname;
|
||||
unsigned int lineNum;
|
||||
struct gpiod_chip *chip;
|
||||
struct gpiod_line *line;
|
||||
int result;
|
||||
Gpio::Direction direction;
|
||||
std::string consumer;
|
||||
|
||||
/* Verify if GPIO has been configured as output */
|
||||
direction = gpioMapIter.second.direction;
|
||||
direction = gpioMapIter->second.direction;
|
||||
if (direction != Gpio::OUT) {
|
||||
sif::error << "LinuxLibgpioIF::pullHigh: GPIO with ID " << gpioId
|
||||
sif::error << "LinuxLibgpioIF::driveGpio: GPIO with ID " << gpioId
|
||||
<< "not configured as output" << std::endl;
|
||||
return CONFIGURATION_FAILURE;
|
||||
}
|
||||
|
||||
chipname = gpioMapIter.second.chipname;
|
||||
chip = gpiod_chip_open_by_name(chipname);
|
||||
chipname = gpioMapIter->second.chipname;
|
||||
chip = gpiod_chip_open_by_name(chipname.c_str());
|
||||
if (!chip) {
|
||||
sif::error << "LinuxLibgpioIF::pullHigh: Failed to open chip "
|
||||
sif::error << "LinuxLibgpioIF::driveGpio: Failed to open chip "
|
||||
<< chipname << ". Gpio ID: " << gpioId << std::endl;
|
||||
return OPEN_CHIP_FAILURE;
|
||||
}
|
||||
|
||||
lineNum = gpioMapIter.second.lineNum;
|
||||
lineNum = gpioMapIter->second.lineNum;
|
||||
line = gpiod_chip_get_line(chip, lineNum);
|
||||
if (!line) {
|
||||
sif::error << "LinuxLibgpioIF::pullHigh: Failed to open line. Gpio ID "
|
||||
sif::error << "LinuxLibgpioIF::driveGpio: Failed to open line. Gpio ID "
|
||||
<< gpioId << std::endl;
|
||||
gpiod_chip_close(chip);
|
||||
return OPEN_LINE_FAILURE;
|
||||
}
|
||||
|
||||
result = gpiod_line_request_output(line, CONSUMER, 0);
|
||||
consumer = gpioMapIter->second.consumer;
|
||||
result = gpiod_line_request_output(line, consumer.c_str(), 0);
|
||||
if (result < 0) {
|
||||
sif::error << "LinuxLibgpioIF::pullHigh: Failed to request line "
|
||||
sif::error << "LinuxLibgpioIF::driveGpio: Failed to request line "
|
||||
<< line << " from GPIO instance with ID: " << gpioId
|
||||
<< std::endl;
|
||||
gpiod_line_release(line);
|
||||
@ -103,11 +96,12 @@ ReturnValue_t LinuxLibgpioIF::driveGpio(gpioId_t gpioId,
|
||||
|
||||
result = gpiod_line_set_value(line, logiclevel);
|
||||
if (result < 0) {
|
||||
sif::error << "LinuxLibgpioIF::pullHigh: Failed to pull GPIO with ID "
|
||||
sif::error << "LinuxLibgpioIF::driveGpio: Failed to pull GPIO with ID "
|
||||
<< gpioId << "to low" << std::endl;
|
||||
gpiod_line_release(line);
|
||||
return PULLING_HIGH_FAILURE;
|
||||
}
|
||||
gpiod_line_release(line);
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
@ -116,13 +110,14 @@ ReturnValue_t LinuxLibgpioIF::checkForConflicts(GpioMap mapToAdd){
|
||||
gpioId_t gpioId;
|
||||
GpioMapIter mapToAddIter = mapToAdd.begin();
|
||||
for(; mapToAddIter != mapToAdd.end(); mapToAddIter++){
|
||||
gpio = mapToAddIter.first();
|
||||
if(gpioMapIter.find(gpioId) != mapToAdd.end()){
|
||||
gpioId = mapToAddIter->first;
|
||||
gpioMapIter = gpioMap.find(gpioId);
|
||||
if(gpioMapIter != mapToAdd.end()){
|
||||
/* An entry for this GPIO already exists. Check if configuration
|
||||
* of direction is equivalent */
|
||||
if (mapToAddIter.second.direction != gpioMapIter.second.direction){
|
||||
if (mapToAddIter->second.direction != gpioMapIter->second.direction){
|
||||
sif::error << "LinuxLibgpioIF::checkForConflicts: Detected conflict "
|
||||
<< "for GPIO " << mapToAddIter.first() << std::endl;
|
||||
<< "for GPIO " << mapToAddIter->first << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
/* Remove element from map to add because a entry for this GPIO
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <bsp_q7s/gpio/GpioIF.h>
|
||||
#include <fsfwconfig/returnvalues/classIds.h>
|
||||
#include <bsp_q7s/gpio/cookies/GpioCookie.h>
|
||||
#include <fsfw/objectmanager/SystemObject.h>
|
||||
|
||||
/**
|
||||
* @brief This class implements the GpioIF for a linux based system. The
|
||||
@ -12,9 +13,11 @@
|
||||
* @note The Petalinux SDK from Xilinx supports libgpiod since Petalinux
|
||||
* 2019.1.
|
||||
*/
|
||||
class LinuxLibgpioIF: public GpioIF, public SystemObject {
|
||||
class LinuxLibgpioIF : public GpioIF, public SystemObject {
|
||||
public:
|
||||
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::LINUX_LIBGPIO_IF;
|
||||
|
||||
static const ReturnValue_t CONFIGURATION_FAILURE = MAKE_RETURN_CODE(0x1);
|
||||
static const ReturnValue_t OPEN_CHIP_FAILURE = MAKE_RETURN_CODE(0x2);
|
||||
static const ReturnValue_t OPEN_LINE_FAILURE = MAKE_RETURN_CODE(0x3);
|
||||
@ -30,10 +33,9 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::LINUX_LIBGPIO_IF;
|
||||
|
||||
/*Holds the information and configuration of all used GPIOs */
|
||||
GpioMap gpioMap;
|
||||
GpioMapIter gpioMapIter;
|
||||
|
||||
/**
|
||||
* @brief This functions drives line of a GPIO specified by the GPIO ID.
|
||||
|
@ -1,15 +1,16 @@
|
||||
#include <bsp_q7s/gpio/cookies/GpioCookie.h>
|
||||
#include <fsfw/serviceinterface/ServiceInterfaceStream.h>
|
||||
|
||||
GpioCookie::GpioCookie() {
|
||||
}
|
||||
|
||||
void GpioCookie::addGpio(GpioMap newEntry){
|
||||
gpioMapIter = gpioMap.find(newEntry);
|
||||
void GpioCookie::addGpio(gpioId_t gpioId, GpioConfig_t gpioConfig){
|
||||
gpioMapIter = gpioMap.find(gpioId);
|
||||
if(gpioMapIter == gpioMap.end()) {
|
||||
std::pair status = gpioMap.emplace(newEntry);
|
||||
std::pair status = gpioMap.emplace(gpioId, gpioConfig);
|
||||
if (status.second == false) {
|
||||
sif::error << "GpioCookie::addGpio: Failed to add GPIO "
|
||||
<< newEntry.first << "to GPIO map" << std::endl;
|
||||
<< gpioId << "to GPIO map" << std::endl;
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -18,7 +19,7 @@ void GpioCookie::addGpio(GpioMap newEntry){
|
||||
}
|
||||
}
|
||||
|
||||
GpioMap getGpioMap() const{
|
||||
GpioMap GpioCookie::getGpioMap() const{
|
||||
return gpioMap;
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <bsp_q7s/gpio/GpioIF.h>
|
||||
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Gpio {
|
||||
enum Direction {
|
||||
@ -27,7 +28,7 @@ typedef struct GpioConfig {
|
||||
GpioConfig(std::string chipname_, int lineNum_, std::string consumer_,
|
||||
Gpio::Direction direction_) :
|
||||
chipname(chipname_), lineNum(lineNum_), consumer(consumer_), direction(
|
||||
directio_) {
|
||||
direction_) {
|
||||
}
|
||||
std::string chipname;
|
||||
int lineNum;
|
||||
@ -54,7 +55,7 @@ public:
|
||||
|
||||
virtual ~GpioCookie();
|
||||
|
||||
void addGpio(GpioMap newEntry);
|
||||
void addGpio(gpioId_t gpioId, GpioConfig_t gpioConfig);
|
||||
/**
|
||||
* @brief Get map with registered GPIOs.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user