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;
|
|
|
|
|
2021-05-03 11:59:33 +02:00
|
|
|
void initSpiCsDecoder(GpioIF* gpioComIF) {
|
2021-03-13 14:42:30 +01:00
|
|
|
|
|
|
|
ReturnValue_t result;
|
|
|
|
|
|
|
|
if (gpioComIF == nullptr) {
|
2021-05-03 11:59:33 +02:00
|
|
|
sif::debug << "initSpiCsDecoder: Invalid gpioComIF" << std::endl;
|
2021-03-13 14:42:30 +01:00
|
|
|
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-06-21 17:15:19 +02:00
|
|
|
GpiodRegular* enRwDecoder = new GpiodRegular(std::string("gpiochip5"), 17,
|
|
|
|
std::string("EN_RW_CS"), gpio::OUT, 0);
|
|
|
|
spiMuxGpios->addGpio(gpioIds::EN_RW_CS, enRwDecoder);
|
2021-03-13 14:42:30 +01:00
|
|
|
|
|
|
|
result = gpioComInterface->addGpios(spiMuxGpios);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
2021-06-21 17:15:19 +02:00
|
|
|
sif::error << "initSpiCsDecoder: Failed to add mux bit gpios to gpioComIF" << std::endl;
|
2021-03-13 14:42:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-03 11:59:33 +02:00
|
|
|
void spiCsDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int value,
|
2021-03-13 14:42:30 +01:00
|
|
|
void* args) {
|
|
|
|
|
|
|
|
if (gpioComInterface == nullptr) {
|
2021-05-07 18:48:42 +02:00
|
|
|
sif::debug << "spiCsDecoderCallback: No gpioComIF specified. Call initSpiCsDecoder "
|
2021-03-13 14:42:30 +01:00
|
|
|
<< "to specify gpioComIF" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-07 18:48:42 +02:00
|
|
|
/* Reading is not supported by the callback function */
|
2021-03-13 14:42:30 +01:00
|
|
|
if (gpioOp == gpio::GpioOperation::READ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value == 1) {
|
2021-05-07 18:48:42 +02:00
|
|
|
disableAllDecoder();
|
2021-03-13 14:42:30 +01:00
|
|
|
}
|
|
|
|
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): {
|
2021-05-07 18:48:42 +02:00
|
|
|
enableDecoderInterfaceBoardIc1();
|
2021-05-02 13:48:39 +02:00
|
|
|
selectY0();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(gpioIds::CS_SUS_2): {
|
2021-05-07 18:48:42 +02:00
|
|
|
enableDecoderInterfaceBoardIc1();
|
2021-05-03 11:59:33 +02:00
|
|
|
selectY1();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(gpioIds::CS_SUS_3): {
|
2021-05-07 18:48:42 +02:00
|
|
|
enableDecoderInterfaceBoardIc2();
|
|
|
|
selectY0();
|
2021-05-03 11:59:33 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(gpioIds::CS_SUS_4): {
|
2021-05-07 18:48:42 +02:00
|
|
|
enableDecoderInterfaceBoardIc2();
|
|
|
|
selectY1();
|
2021-05-03 11:59:33 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(gpioIds::CS_SUS_5): {
|
2021-05-07 18:48:42 +02:00
|
|
|
enableDecoderInterfaceBoardIc2();
|
|
|
|
selectY2();
|
2021-05-03 11:59:33 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(gpioIds::CS_SUS_6): {
|
2021-05-07 18:48:42 +02:00
|
|
|
enableDecoderInterfaceBoardIc1();
|
|
|
|
selectY2();
|
2021-05-03 11:59:33 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(gpioIds::CS_SUS_7): {
|
2021-05-07 18:48:42 +02:00
|
|
|
enableDecoderInterfaceBoardIc1();
|
|
|
|
selectY3();
|
2021-05-03 11:59:33 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(gpioIds::CS_SUS_8): {
|
2021-05-07 18:48:42 +02:00
|
|
|
enableDecoderInterfaceBoardIc2();
|
|
|
|
selectY3();
|
2021-05-03 11:59:33 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(gpioIds::CS_SUS_9): {
|
2021-05-07 18:48:42 +02:00
|
|
|
enableDecoderInterfaceBoardIc1();
|
|
|
|
selectY4();
|
2021-05-03 11:59:33 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(gpioIds::CS_SUS_10): {
|
2021-05-07 18:48:42 +02:00
|
|
|
enableDecoderInterfaceBoardIc1();
|
|
|
|
selectY5();
|
2021-05-03 11:59:33 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(gpioIds::CS_SUS_11): {
|
2021-05-07 18:48:42 +02:00
|
|
|
enableDecoderInterfaceBoardIc2();
|
|
|
|
selectY4();
|
2021-05-03 11:59:33 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(gpioIds::CS_SUS_12): {
|
2021-05-07 18:48:42 +02:00
|
|
|
enableDecoderInterfaceBoardIc2();
|
|
|
|
selectY5();
|
2021-05-03 11:59:33 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(gpioIds::CS_SUS_13): {
|
2021-05-07 18:48:42 +02:00
|
|
|
enableDecoderInterfaceBoardIc1();
|
|
|
|
selectY6();
|
2021-03-13 14:42:30 +01:00
|
|
|
break;
|
|
|
|
}
|
2021-06-21 17:15:19 +02:00
|
|
|
case(gpioIds::EN_RW1): {
|
|
|
|
enableRwDecoder();
|
|
|
|
selectY0();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(gpioIds::EN_RW2): {
|
|
|
|
enableRwDecoder();
|
|
|
|
selectY1();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(gpioIds::EN_RW3): {
|
|
|
|
enableRwDecoder();
|
|
|
|
selectY3();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(gpioIds::EN_RW4): {
|
|
|
|
enableRwDecoder();
|
|
|
|
selectY4();
|
|
|
|
break;
|
|
|
|
}
|
2021-03-13 14:42:30 +01:00
|
|
|
default:
|
2021-05-03 11:59:33 +02:00
|
|
|
sif::debug << "spiCsDecoderCallback: Invalid gpio id " << gpioId << std::endl;
|
2021-03-13 14:42:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2021-05-03 11:59:33 +02:00
|
|
|
sif::debug << "spiCsDecoderCallback: Invalid value. Must be 0 or 1" << std::endl;
|
2021-03-13 14:42:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-02 13:48:39 +02:00
|
|
|
void enableDecoderTcsIc1() {
|
2021-05-03 11:59:33 +02:00
|
|
|
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1);
|
|
|
|
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2);
|
|
|
|
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3);
|
2021-05-02 13:48:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void enableDecoderTcsIc2() {
|
2021-05-03 11:59:33 +02:00
|
|
|
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1);
|
|
|
|
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2);
|
|
|
|
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3);
|
2021-05-02 13:48:39 +02:00
|
|
|
}
|
|
|
|
|
2021-05-07 18:48:42 +02:00
|
|
|
void enableDecoderInterfaceBoardIc1() {
|
2021-05-02 13:48:39 +02:00
|
|
|
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1);
|
|
|
|
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2);
|
|
|
|
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3);
|
|
|
|
}
|
|
|
|
|
2021-05-07 18:48:42 +02:00
|
|
|
void enableDecoderInterfaceBoardIc2() {
|
2021-05-03 11:59:33 +02:00
|
|
|
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1);
|
|
|
|
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2);
|
|
|
|
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3);
|
2021-05-02 13:48:39 +02:00
|
|
|
}
|
|
|
|
|
2021-06-21 17:15:19 +02:00
|
|
|
void enableRwDecoder() {
|
|
|
|
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1);
|
|
|
|
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2);
|
|
|
|
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3);
|
|
|
|
gpioComInterface->pullHigh(gpioIds::EN_RW_CS);
|
|
|
|
}
|
|
|
|
|
2021-05-02 13:48:39 +02:00
|
|
|
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-05-07 18:48:42 +02:00
|
|
|
void disableAllDecoder() {
|
|
|
|
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1);
|
|
|
|
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2);
|
|
|
|
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3);
|
2021-06-21 17:15:19 +02:00
|
|
|
gpioComInterface->pullLow(gpioIds::EN_RW_CS);
|
2021-05-07 18:48:42 +02:00
|
|
|
}
|
|
|
|
|
2021-03-13 14:42:30 +01:00
|
|
|
}
|