eive-obsw/bsp_q7s/gpio/gpioCallbacks.cpp

341 lines
10 KiB
C++
Raw Normal View History

2021-04-01 16:21:24 +02:00
#include "gpioCallbacks.h"
2021-09-20 17:47:29 +02:00
#include "busConf.h"
2021-04-01 16:21:24 +02:00
#include <devices/gpioIds.h>
2021-08-03 15:58:01 +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
2021-09-21 17:31:55 +02:00
GpiodRegularByLabel* spiMuxBit = nullptr;
2021-05-02 13:48:39 +02:00
/** Setting mux bit 1 to low will disable IC21 on the interface board */
2021-09-21 17:31:55 +02:00
spiMuxBit = new GpiodRegularByLabel(q7s::GPIO_3V3_OBC1C, q7s::SPI_MUX_BIT_1,
"SPI Mux Bit 1", gpio::OUT, gpio::LOW);
spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_1, spiMuxBit);
2021-05-02 13:48:39 +02:00
/** Setting mux bit 2 to low disables IC1 on the TCS board */
2021-09-21 17:31:55 +02:00
spiMuxBit = new GpiodRegularByLabel(q7s::GPIO_3V3_OBC1C, q7s::SPI_MUX_BIT_2,
"SPI Mux Bit 2", gpio::OUT, gpio::LOW);
spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_2, spiMuxBit);
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-09-21 17:31:55 +02:00
spiMuxBit = new GpiodRegularByLabel(q7s::GPIO_3V3_OBC1C, q7s::SPI_MUX_BIT_3,
"SPI Mux Bit 3", gpio::OUT, gpio::LOW);
spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_3, spiMuxBit);
2021-05-02 13:48:39 +02:00
/** The following gpios can take arbitrary initial values */
2021-09-21 17:31:55 +02:00
spiMuxBit = new GpiodRegularByLabel(q7s::GPIO_3V3_OBC1C, q7s::SPI_MUX_BIT_4,
"SPI Mux Bit 4", gpio::OUT, gpio::LOW);
spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_4, spiMuxBit);
spiMuxBit = new GpiodRegularByLabel(q7s::GPIO_3V3_OBC1C, q7s::SPI_MUX_BIT_5,
"SPI Mux Bit 5", gpio::OUT, gpio::LOW);
spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_5, spiMuxBit);
spiMuxBit = new GpiodRegularByLabel(q7s::GPIO_3V3_OBC1C, q7s::SPI_MUX_BIT_6,
"SPI Mux Bit 6", gpio::OUT, gpio::LOW);
spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_6, spiMuxBit);
GpiodRegularByLabel* enRwDecoder = new GpiodRegularByLabel(q7s::GPIO_FLEX_OBC1F_B1,
q7s::EN_RW_CS, "EN_RW_CS", gpio::OUT, gpio::HIGH);
2021-06-21 17:15:19 +02:00
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-24 12:04:36 +02:00
case(gpioIds::CS_RW1): {
2021-06-21 17:15:19 +02:00
enableRwDecoder();
selectY0();
break;
}
2021-06-24 12:04:36 +02:00
case(gpioIds::CS_RW2): {
2021-06-21 17:15:19 +02:00
enableRwDecoder();
selectY1();
break;
}
2021-06-24 12:04:36 +02:00
case(gpioIds::CS_RW3): {
2021-06-21 17:15:19 +02:00
enableRwDecoder();
2021-06-29 09:50:50 +02:00
selectY2();
2021-06-21 17:15:19 +02:00
break;
}
2021-06-24 12:04:36 +02:00
case(gpioIds::CS_RW4): {
2021-06-21 17:15:19 +02:00
enableRwDecoder();
2021-06-29 09:50:50 +02:00
selectY3();
2021-06-21 17:15:19 +02:00
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
}