eive-obsw/bsp_q7s/gpio/gpioCallbacks.cpp

246 lines
7.2 KiB
C++
Raw Normal View History

2021-04-01 16:21:24 +02:00
#include "gpioCallbacks.h"
#include <devices/gpioIds.h>
2021-04-01 15:42:51 +02:00
#include <fsfw_hal/linux/gpio/LinuxLibgpioIF.h>
#include <fsfw_hal/common/gpio/GpioCookie.h>
2021-03-13 14:42:30 +01:00
#include <fsfw/serviceinterface/ServiceInterface.h>
namespace gpioCallbacks {
GpioIF* gpioComInterface;
void initTcsBoardDecoder(GpioIF* gpioComIF) {
ReturnValue_t result;
if (gpioComIF == nullptr) {
sif::debug << "initTcsBoardDecoder: Invalid gpioComIF" << std::endl;
return;
}
gpioComInterface = gpioComIF;
GpioCookie* spiMuxGpios = new GpioCookie;
2021-05-02 13:48:39 +02:00
/** Setting mux bit 1 to low will disable IC21 on the interface board */
2021-04-01 16:33:30 +02:00
GpiodRegular* spiMuxBit1 = new GpiodRegular(std::string("gpiochip7"), 13,
2021-05-02 13:48:39 +02:00
std::string("SPI Mux Bit 1"), gpio::OUT, 0);
2021-03-24 12:53:25 +01:00
spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_1, spiMuxBit1);
2021-05-02 13:48:39 +02:00
/** Setting mux bit 2 to low disables IC1 on the TCS board */
2021-03-24 12:53:25 +01:00
GpiodRegular* spiMuxBit2 = new GpiodRegular(std::string("gpiochip7"), 14,
std::string("SPI Mux Bit 2"), gpio::OUT, 0);
spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_2, spiMuxBit2);
2021-05-02 13:48:39 +02:00
/** Setting mux bit 3 to low disables IC2 on the TCS board and IC22 on the interface board */
2021-03-24 12:53:25 +01:00
GpiodRegular* spiMuxBit3 = new GpiodRegular(std::string("gpiochip7"), 15,
std::string("SPI Mux Bit 3"), gpio::OUT, 0);
spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_3, spiMuxBit3);
2021-05-02 13:48:39 +02:00
/** The following gpios can take arbitrary initial values */
2021-03-24 12:53:25 +01:00
GpiodRegular* spiMuxBit4 = new GpiodRegular(std::string("gpiochip7"), 16,
std::string("SPI Mux Bit 4"), gpio::OUT, 0);
spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_4, spiMuxBit4);
GpiodRegular* spiMuxBit5 = new GpiodRegular(std::string("gpiochip7"), 17,
std::string("SPI Mux Bit 5"), gpio::OUT, 0);
spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_5, spiMuxBit5);
GpiodRegular* spiMuxBit6 = new GpiodRegular(std::string("gpiochip7"), 18,
std::string("SPI Mux Bit 6"), gpio::OUT, 0);
spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_6, spiMuxBit6);
2021-03-13 14:42:30 +01:00
result = gpioComInterface->addGpios(spiMuxGpios);
if (result != HasReturnvaluesIF::RETURN_OK) {
sif::error << "initTcsBoardDecoder: Failed to add mux bit gpios to gpioComIF"
<< std::endl;
return;
}
}
void tcsBoardDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int value,
void* args) {
if (gpioComInterface == nullptr) {
sif::debug << "tcsBoardDecoderCallback: No gpioComIF specified. Call initTcsBoardDecoder "
<< "to specify gpioComIF" << std::endl;
return;
}
/* Read is not supported by the callback function */
if (gpioOp == gpio::GpioOperation::READ) {
return;
}
if (value == 1) {
/* This will pull all 16 decoder outputs to high */
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1);
}
else if (value == 0) {
switch (gpioId) {
case(gpioIds::RTD_IC3): {
2021-05-02 13:48:39 +02:00
enableDecoderTcsIc1();
selectY7();
2021-03-13 14:42:30 +01:00
break;
}
case(gpioIds::RTD_IC4): {
2021-05-02 13:48:39 +02:00
enableDecoderTcsIc1();
selectY6();
2021-03-13 14:42:30 +01:00
break;
}
case(gpioIds::RTD_IC5): {
2021-05-02 13:48:39 +02:00
enableDecoderTcsIc1();
selectY5();
2021-03-13 14:42:30 +01:00
break;
}
case(gpioIds::RTD_IC6): {
2021-05-02 13:48:39 +02:00
enableDecoderTcsIc1();
selectY4();
2021-03-13 14:42:30 +01:00
break;
}
case(gpioIds::RTD_IC7): {
2021-05-02 13:48:39 +02:00
enableDecoderTcsIc1();
selectY3();
2021-03-13 14:42:30 +01:00
break;
}
case(gpioIds::RTD_IC8): {
2021-05-02 13:48:39 +02:00
enableDecoderTcsIc1();
selectY2();
2021-03-13 14:42:30 +01:00
break;
}
case(gpioIds::RTD_IC9): {
2021-05-02 13:48:39 +02:00
enableDecoderTcsIc1();
selectY1();
2021-03-13 14:42:30 +01:00
break;
}
case(gpioIds::RTD_IC10): {
2021-05-02 13:48:39 +02:00
enableDecoderTcsIc1();
selectY0();
2021-03-13 14:42:30 +01:00
break;
}
case(gpioIds::RTD_IC11): {
2021-05-02 13:48:39 +02:00
enableDecoderTcsIc2();
selectY7();
2021-03-13 14:42:30 +01:00
break;
}
case(gpioIds::RTD_IC12): {
2021-05-02 13:48:39 +02:00
enableDecoderTcsIc2();
selectY6();
2021-03-13 14:42:30 +01:00
break;
}
case(gpioIds::RTD_IC13): {
2021-05-02 13:48:39 +02:00
enableDecoderTcsIc2();
selectY5();
2021-03-13 14:42:30 +01:00
break;
}
case(gpioIds::RTD_IC14): {
2021-05-02 13:48:39 +02:00
enableDecoderTcsIc2();
selectY4();
2021-03-13 14:42:30 +01:00
break;
}
case(gpioIds::RTD_IC15): {
2021-05-02 13:48:39 +02:00
enableDecoderTcsIc2();
selectY3();
2021-03-13 14:42:30 +01:00
break;
}
case(gpioIds::RTD_IC16): {
2021-05-02 13:48:39 +02:00
enableDecoderTcsIc2();
selectY2();
2021-03-13 14:42:30 +01:00
break;
}
case(gpioIds::RTD_IC17): {
2021-05-02 13:48:39 +02:00
enableDecoderTcsIc2();
selectY1();
2021-03-13 14:42:30 +01:00
break;
}
case(gpioIds::RTD_IC18): {
2021-05-02 13:48:39 +02:00
enableDecoderTcsIc2();
selectY0();
break;
}
case(gpioIds::CS_SUS_1): {
enableDecoderInterfaceBoardIc21();
selectY0();
break;
}
case(gpioIds::CS_SUS_2): {
enableDecoderInterfaceBoardIc21();
2021-03-13 14:42:30 +01:00
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6);
break;
}
default:
sif::debug << "tcsBoardDecoderCallback: Invalid gpioid " << gpioId << std::endl;
}
}
else {
sif::debug << "tcsBoardDecoderCallback: Invalid value. Must be 0 or 1" << std::endl;
}
}
2021-05-02 13:48:39 +02:00
void enableDecoderTcsIc1() {
}
void enableDecoderTcsIc2() {
}
void enableDecoderInterfaceBoardIc21() {
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3);
}
void enableDecoderInterfaceBoardIc22() {
}
void selectY0() {
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6);
}
void selectY1() {
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6);
}
void selectY2() {
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6);
}
void selectY3() {
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6);
}
void selectY4() {
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6);
}
void selectY5() {
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6);
}
void selectY6() {
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6);
}
void selectY7() {
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6);
}
2021-03-13 14:42:30 +01:00
}