eive-obsw/bsp_q7s/gpio/gpioCallbacks.cpp

505 lines
14 KiB
C++
Raw Normal View History

2021-04-01 16:21:24 +02:00
#include "gpioCallbacks.h"
2022-01-17 13:48:55 +01:00
#include <devices/gpioIds.h>
2021-03-13 14:42:30 +01:00
#include <fsfw/serviceinterface/ServiceInterface.h>
2022-01-17 13:48:55 +01:00
#include <fsfw_hal/common/gpio/GpioCookie.h>
#include <fsfw_hal/linux/gpio/LinuxLibgpioIF.h>
2021-03-13 14:42:30 +01:00
2022-01-17 13:48:55 +01:00
#include "busConf.h"
2021-03-13 14:42:30 +01:00
namespace gpioCallbacks {
GpioIF* gpioComInterface;
2021-05-03 11:59:33 +02:00
void initSpiCsDecoder(GpioIF* gpioComIF) {
2022-01-17 13:48:55 +01:00
ReturnValue_t result;
if (gpioComIF == nullptr) {
sif::debug << "initSpiCsDecoder: Invalid gpioComIF" << std::endl;
return;
}
gpioComInterface = gpioComIF;
GpioCookie* spiMuxGpios = new GpioCookie;
GpiodRegularByLineName* spiMuxBit = nullptr;
/** Setting mux bit 1 to low will disable IC21 on the interface board */
spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_1_PIN, "SPI Mux Bit 1",
gpio::DIR_OUT, gpio::HIGH);
spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_1, spiMuxBit);
/** Setting mux bit 2 to low disables IC1 on the TCS board */
spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_2_PIN, "SPI Mux Bit 2",
gpio::DIR_OUT, gpio::HIGH);
spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_2, spiMuxBit);
/** Setting mux bit 3 to low disables IC2 on the TCS board and IC22 on the interface board */
spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_3_PIN, "SPI Mux Bit 3",
gpio::DIR_OUT, gpio::LOW);
spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_3, spiMuxBit);
// spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_1_PIN, "SPI Mux Bit 1",
// gpio::OUT, gpio::LOW);
// spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_1, spiMuxBit);
// /** Setting mux bit 2 to low disables IC1 on the TCS board */
// spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_2_PIN, "SPI Mux Bit 2",
// gpio::OUT, gpio::HIGH); spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_2, spiMuxBit);
// /** Setting mux bit 3 to low disables IC2 on the TCS board and IC22 on the interface board
// */ spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_3_PIN, "SPI Mux Bit
// 3", gpio::OUT, gpio::LOW); spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_3, spiMuxBit);
/** The following gpios can take arbitrary initial values */
spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_4_PIN, "SPI Mux Bit 4",
gpio::DIR_OUT, gpio::LOW);
spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_4, spiMuxBit);
spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_5_PIN, "SPI Mux Bit 5",
gpio::DIR_OUT, gpio::LOW);
spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_5, spiMuxBit);
spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_6_PIN, "SPI Mux Bit 6",
gpio::DIR_OUT, gpio::LOW);
spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_6, spiMuxBit);
GpiodRegularByLineName* enRwDecoder =
new GpiodRegularByLineName(q7s::gpioNames::EN_RW_CS, "EN_RW_CS", gpio::DIR_OUT, gpio::HIGH);
spiMuxGpios->addGpio(gpioIds::EN_RW_CS, enRwDecoder);
result = gpioComInterface->addGpios(spiMuxGpios);
if (result != HasReturnvaluesIF::RETURN_OK) {
sif::error << "initSpiCsDecoder: Failed to add mux bit gpios to gpioComIF" << std::endl;
return;
}
2021-03-13 14:42:30 +01:00
}
2021-09-27 10:51:47 +02:00
void spiCsDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, gpio::Levels value,
2022-01-17 13:48:55 +01:00
void* args) {
if (gpioComInterface == nullptr) {
sif::debug << "spiCsDecoderCallback: No gpioComIF specified. Call initSpiCsDecoder "
<< "to specify gpioComIF" << std::endl;
return;
}
/* Reading is not supported by the callback function */
if (gpioOp == gpio::GpioOperation::READ) {
return;
}
if (value == gpio::HIGH) {
switch (gpioId) {
case (gpioIds::RTD_IC_3): {
disableDecoderTcsIc1();
break;
}
case (gpioIds::RTD_IC_4): {
disableDecoderTcsIc1();
break;
}
case (gpioIds::RTD_IC_5): {
disableDecoderTcsIc1();
break;
}
case (gpioIds::RTD_IC_6): {
disableDecoderTcsIc1();
break;
}
case (gpioIds::RTD_IC_7): {
disableDecoderTcsIc1();
break;
}
case (gpioIds::RTD_IC_8): {
disableDecoderTcsIc1();
break;
}
case (gpioIds::RTD_IC_9): {
disableDecoderTcsIc1();
break;
}
case (gpioIds::RTD_IC_10): {
disableDecoderTcsIc1();
break;
}
case (gpioIds::RTD_IC_11): {
disableDecoderTcsIc2();
break;
}
case (gpioIds::RTD_IC_12): {
disableDecoderTcsIc2();
break;
}
case (gpioIds::RTD_IC_13): {
disableDecoderTcsIc2();
break;
}
case (gpioIds::RTD_IC_14): {
disableDecoderTcsIc2();
break;
}
case (gpioIds::RTD_IC_15): {
disableDecoderTcsIc2();
break;
}
case (gpioIds::RTD_IC_16): {
disableDecoderTcsIc2();
break;
}
case (gpioIds::RTD_IC_17): {
disableDecoderTcsIc2();
break;
}
case (gpioIds::RTD_IC_18): {
disableDecoderTcsIc2();
break;
}
case (gpioIds::CS_SUS_1): {
disableDecoderInterfaceBoardIc1();
break;
}
case (gpioIds::CS_SUS_2): {
disableDecoderInterfaceBoardIc1();
break;
}
case (gpioIds::CS_SUS_3): {
disableDecoderInterfaceBoardIc2();
break;
}
case (gpioIds::CS_SUS_4): {
disableDecoderInterfaceBoardIc2();
break;
}
case (gpioIds::CS_SUS_5): {
disableDecoderInterfaceBoardIc2();
break;
}
case (gpioIds::CS_SUS_6): {
disableDecoderInterfaceBoardIc1();
break;
}
case (gpioIds::CS_SUS_7): {
disableDecoderInterfaceBoardIc1();
break;
}
case (gpioIds::CS_SUS_8): {
disableDecoderInterfaceBoardIc2();
break;
}
case (gpioIds::CS_SUS_9): {
disableDecoderInterfaceBoardIc1();
break;
}
case (gpioIds::CS_SUS_10): {
disableDecoderInterfaceBoardIc1();
break;
}
case (gpioIds::CS_SUS_11): {
disableDecoderInterfaceBoardIc2();
break;
}
case (gpioIds::CS_SUS_12): {
disableDecoderInterfaceBoardIc2();
break;
}
case (gpioIds::CS_SUS_13): {
disableDecoderInterfaceBoardIc1();
break;
}
case (gpioIds::CS_RW1): {
disableRwDecoder();
break;
}
case (gpioIds::CS_RW2): {
disableRwDecoder();
break;
}
case (gpioIds::CS_RW3): {
disableRwDecoder();
break;
}
case (gpioIds::CS_RW4): {
disableRwDecoder();
break;
}
default:
sif::debug << "spiCsDecoderCallback: Invalid gpio id " << gpioId << std::endl;
2021-03-13 14:42:30 +01:00
}
2022-01-17 13:48:55 +01:00
} else if (value == gpio::LOW) {
switch (gpioId) {
case (gpioIds::RTD_IC_3): {
selectY7();
enableDecoderTcsIc1();
break;
}
case (gpioIds::RTD_IC_4): {
selectY6();
enableDecoderTcsIc1();
break;
}
case (gpioIds::RTD_IC_5): {
selectY5();
enableDecoderTcsIc1();
break;
}
case (gpioIds::RTD_IC_6): {
selectY4();
enableDecoderTcsIc1();
break;
}
case (gpioIds::RTD_IC_7): {
selectY3();
enableDecoderTcsIc1();
break;
}
case (gpioIds::RTD_IC_8): {
selectY2();
enableDecoderTcsIc1();
break;
}
case (gpioIds::RTD_IC_9): {
selectY1();
enableDecoderTcsIc1();
break;
}
case (gpioIds::RTD_IC_10): {
selectY0();
enableDecoderTcsIc1();
break;
}
case (gpioIds::RTD_IC_11): {
selectY7();
enableDecoderTcsIc2();
break;
}
case (gpioIds::RTD_IC_12): {
selectY6();
enableDecoderTcsIc2();
break;
}
case (gpioIds::RTD_IC_13): {
selectY5();
enableDecoderTcsIc2();
break;
}
case (gpioIds::RTD_IC_14): {
selectY4();
enableDecoderTcsIc2();
break;
}
case (gpioIds::RTD_IC_15): {
selectY3();
enableDecoderTcsIc2();
break;
}
case (gpioIds::RTD_IC_16): {
selectY2();
enableDecoderTcsIc2();
break;
}
case (gpioIds::RTD_IC_17): {
selectY1();
enableDecoderTcsIc2();
break;
}
case (gpioIds::RTD_IC_18): {
selectY0();
enableDecoderTcsIc2();
break;
}
case (gpioIds::CS_SUS_1): {
selectY0();
enableDecoderInterfaceBoardIc1();
break;
}
case (gpioIds::CS_SUS_2): {
selectY1();
enableDecoderInterfaceBoardIc1();
break;
}
case (gpioIds::CS_SUS_3): {
selectY0();
enableDecoderInterfaceBoardIc2();
break;
}
case (gpioIds::CS_SUS_4): {
selectY1();
enableDecoderInterfaceBoardIc2();
break;
}
case (gpioIds::CS_SUS_5): {
selectY2();
enableDecoderInterfaceBoardIc2();
break;
}
case (gpioIds::CS_SUS_6): {
selectY2();
enableDecoderInterfaceBoardIc1();
break;
}
case (gpioIds::CS_SUS_7): {
selectY3();
enableDecoderInterfaceBoardIc1();
break;
}
case (gpioIds::CS_SUS_8): {
selectY3();
enableDecoderInterfaceBoardIc2();
break;
}
case (gpioIds::CS_SUS_9): {
selectY4();
enableDecoderInterfaceBoardIc1();
break;
}
case (gpioIds::CS_SUS_10): {
selectY5();
enableDecoderInterfaceBoardIc1();
break;
}
case (gpioIds::CS_SUS_11): {
selectY4();
enableDecoderInterfaceBoardIc2();
break;
}
case (gpioIds::CS_SUS_12): {
selectY5();
enableDecoderInterfaceBoardIc2();
break;
}
case (gpioIds::CS_SUS_13): {
selectY6();
enableDecoderInterfaceBoardIc1();
break;
}
case (gpioIds::CS_RW1): {
selectY0();
enableRwDecoder();
break;
}
case (gpioIds::CS_RW2): {
selectY1();
enableRwDecoder();
break;
}
case (gpioIds::CS_RW3): {
selectY2();
enableRwDecoder();
break;
}
case (gpioIds::CS_RW4): {
selectY3();
enableRwDecoder();
break;
}
default:
sif::debug << "spiCsDecoderCallback: Invalid gpio id " << gpioId << std::endl;
2021-03-13 14:42:30 +01:00
}
2022-01-17 13:48:55 +01:00
} else {
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() {
2022-01-17 13:48:55 +01: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() {
2022-01-17 13:48:55 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2);
2021-05-02 13:48:39 +02:00
}
2021-05-07 18:48:42 +02:00
void enableDecoderInterfaceBoardIc1() {
2022-01-17 13:48:55 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3);
2021-05-02 13:48:39 +02:00
}
2021-05-07 18:48:42 +02:00
void enableDecoderInterfaceBoardIc2() {
2022-01-17 13:48:55 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2);
2021-05-02 13:48:39 +02:00
}
2021-10-29 19:13:48 +02:00
void disableDecoderTcsIc1() {
2022-01-17 13:48:55 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3);
2021-10-29 19:13:48 +02:00
}
void disableDecoderTcsIc2() {
2022-01-17 13:48:55 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2);
2021-10-29 19:13:48 +02:00
}
void disableDecoderInterfaceBoardIc1() {
2022-01-17 13:48:55 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3);
2021-10-29 19:13:48 +02:00
}
void disableDecoderInterfaceBoardIc2() {
2022-01-17 13:48:55 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3);
2021-10-29 19:13:48 +02:00
}
2022-01-17 13:48:55 +01:00
void enableRwDecoder() { gpioComInterface->pullHigh(gpioIds::EN_RW_CS); }
2021-10-29 19:13:48 +02:00
2022-01-17 13:48:55 +01:00
void disableRwDecoder() { gpioComInterface->pullLow(gpioIds::EN_RW_CS); }
2021-06-21 17:15:19 +02:00
2021-05-02 13:48:39 +02:00
void selectY0() {
2022-01-17 13:48:55 +01:00
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6);
2021-05-02 13:48:39 +02:00
}
void selectY1() {
2022-01-17 13:48:55 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6);
2021-05-02 13:48:39 +02:00
}
void selectY2() {
2022-01-17 13:48:55 +01:00
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6);
2021-05-02 13:48:39 +02:00
}
void selectY3() {
2022-01-17 13:48:55 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6);
2021-05-02 13:48:39 +02:00
}
void selectY4() {
2022-01-17 13:48:55 +01:00
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6);
2021-05-02 13:48:39 +02:00
}
void selectY5() {
2022-01-17 13:48:55 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6);
2021-05-02 13:48:39 +02:00
}
void selectY6() {
2022-01-17 13:48:55 +01:00
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6);
2021-05-02 13:48:39 +02:00
}
void selectY7() {
2022-01-17 13:48:55 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6);
2021-05-02 13:48:39 +02:00
}
2021-05-07 18:48:42 +02:00
void disableAllDecoder() {
2022-01-17 13:48:55 +01:00
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2);
gpioComInterface->pullLow(gpioIds::EN_RW_CS);
2021-05-07 18:48:42 +02:00
}
2022-01-17 13:48:55 +01:00
} // namespace gpioCallbacks