eive-obsw/bsp_q7s/callbacks/gpioCallbacks.cpp

488 lines
13 KiB
C++
Raw Normal View History

2021-04-01 16:21:24 +02:00
#include "gpioCallbacks.h"
2022-01-17 15:58:27 +01:00
#include <devices/gpioIds.h>
2021-03-13 14:42:30 +01:00
#include <fsfw/serviceinterface/ServiceInterface.h>
2022-01-17 15:58:27 +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 15:58:27 +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-02-28 15:19:13 +01:00
using namespace gpio;
2022-01-17 15:58:27 +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 */
2022-02-14 18:38:35 +01:00
spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_0_PIN, "SPI Mux Bit 1",
2022-02-28 15:19:13 +01:00
Direction::OUT, Levels::HIGH);
2022-02-14 18:38:35 +01:00
spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_0, spiMuxBit);
2022-01-17 15:58:27 +01:00
/** Setting mux bit 2 to low disables IC1 on the TCS board */
2022-02-14 18:38:35 +01:00
spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_1_PIN, "SPI Mux Bit 2",
2022-02-28 15:19:13 +01:00
Direction::OUT, Levels::HIGH);
2022-02-14 18:38:35 +01:00
spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_1, spiMuxBit);
2022-01-17 15:58:27 +01:00
/** Setting mux bit 3 to low disables IC2 on the TCS board and IC22 on the interface board */
2022-02-14 18:38:35 +01:00
spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_2_PIN, "SPI Mux Bit 3",
2022-02-28 15:19:13 +01:00
Direction::OUT, Levels::LOW);
2022-02-14 18:38:35 +01:00
spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_2, spiMuxBit);
2022-01-17 15:58:27 +01:00
/** The following gpios can take arbitrary initial values */
2022-02-14 18:38:35 +01:00
spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_3_PIN, "SPI Mux Bit 4",
2022-02-28 15:19:13 +01:00
Direction::OUT, Levels::LOW);
2022-02-14 18:38:35 +01:00
spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_3, spiMuxBit);
spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_4_PIN, "SPI Mux Bit 5",
2022-02-28 15:19:13 +01:00
Direction::OUT, Levels::LOW);
2022-01-17 15:58:27 +01:00
spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_4, spiMuxBit);
2022-02-14 18:38:35 +01:00
spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_5_PIN, "SPI Mux Bit 6",
2022-02-28 15:19:13 +01:00
Direction::OUT, Levels::LOW);
2022-01-17 15:58:27 +01:00
spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_5, spiMuxBit);
2022-02-28 15:19:13 +01:00
GpiodRegularByLineName* enRwDecoder = new GpiodRegularByLineName(
q7s::gpioNames::EN_RW_CS, "EN_RW_CS", Direction::OUT, Levels::HIGH);
2022-01-17 15:58:27 +01:00
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 15:58:27 +01:00
void* args) {
2022-02-28 15:19:13 +01:00
using namespace gpio;
2022-01-17 15:58:27 +01:00
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;
}
2022-02-28 15:19:13 +01:00
if (value == Levels::HIGH) {
2022-01-17 15:58:27 +01:00
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;
}
2022-02-11 17:38:02 +01:00
case (gpioIds::CS_SUS_0): {
disableDecoderInterfaceBoardIc1();
break;
}
2022-01-17 15:58:27 +01:00
case (gpioIds::CS_SUS_1): {
disableDecoderInterfaceBoardIc1();
break;
}
case (gpioIds::CS_SUS_2): {
2022-02-15 20:40:44 +01:00
disableDecoderInterfaceBoardIc1();
2022-01-17 15:58:27 +01:00
break;
}
case (gpioIds::CS_SUS_3): {
2022-02-15 20:40:44 +01:00
disableDecoderInterfaceBoardIc1();
2022-01-17 15:58:27 +01:00
break;
}
case (gpioIds::CS_SUS_4): {
2022-02-15 20:40:44 +01:00
disableDecoderInterfaceBoardIc1();
2022-01-17 15:58:27 +01:00
break;
}
case (gpioIds::CS_SUS_5): {
2022-02-11 17:38:02 +01:00
disableDecoderInterfaceBoardIc1();
2022-01-17 15:58:27 +01:00
break;
}
case (gpioIds::CS_SUS_6): {
2022-02-15 20:40:44 +01:00
disableDecoderInterfaceBoardIc2();
2022-01-17 15:58:27 +01:00
break;
}
case (gpioIds::CS_SUS_7): {
2022-02-11 17:38:02 +01:00
disableDecoderInterfaceBoardIc2();
2022-01-17 15:58:27 +01:00
break;
}
case (gpioIds::CS_SUS_8): {
2022-02-15 20:40:44 +01:00
disableDecoderInterfaceBoardIc2();
2022-01-17 15:58:27 +01:00
break;
}
case (gpioIds::CS_SUS_9): {
2022-02-15 20:40:44 +01:00
disableDecoderInterfaceBoardIc2();
2022-01-17 15:58:27 +01:00
break;
}
case (gpioIds::CS_SUS_10): {
disableDecoderInterfaceBoardIc2();
break;
}
2022-02-11 17:38:02 +01:00
case (gpioIds::CS_SUS_11): {
2022-01-17 15:58:27 +01:00
disableDecoderInterfaceBoardIc2();
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-02-28 15:19:13 +01:00
} else if (value == Levels::LOW) {
2022-01-17 15:58:27 +01:00
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;
}
2022-02-11 17:38:02 +01:00
case (gpioIds::CS_SUS_0): {
2022-01-17 15:58:27 +01:00
selectY0();
enableDecoderInterfaceBoardIc1();
break;
}
2022-02-11 17:38:02 +01:00
case (gpioIds::CS_SUS_1): {
2022-01-17 15:58:27 +01:00
selectY1();
enableDecoderInterfaceBoardIc1();
break;
}
2022-02-11 17:38:02 +01:00
case (gpioIds::CS_SUS_2): {
2022-02-14 18:38:35 +01:00
selectY2();
enableDecoderInterfaceBoardIc1();
2022-01-17 15:58:27 +01:00
break;
}
2022-02-11 17:38:02 +01:00
case (gpioIds::CS_SUS_3): {
2022-02-14 18:38:35 +01:00
selectY3();
enableDecoderInterfaceBoardIc1();
2022-01-17 15:58:27 +01:00
break;
}
2022-02-11 17:38:02 +01:00
case (gpioIds::CS_SUS_4): {
2022-02-14 18:38:35 +01:00
selectY4();
enableDecoderInterfaceBoardIc1();
2022-01-17 15:58:27 +01:00
break;
}
2022-02-11 17:38:02 +01:00
case (gpioIds::CS_SUS_5): {
2022-02-14 18:38:35 +01:00
selectY5();
2022-01-17 15:58:27 +01:00
enableDecoderInterfaceBoardIc1();
break;
}
2022-02-11 17:38:02 +01:00
case (gpioIds::CS_SUS_6): {
2022-02-14 18:38:35 +01:00
selectY0();
enableDecoderInterfaceBoardIc2();
2022-01-17 15:58:27 +01:00
break;
}
2022-02-11 17:38:02 +01:00
case (gpioIds::CS_SUS_7): {
2022-02-14 18:38:35 +01:00
selectY1();
2022-01-17 15:58:27 +01:00
enableDecoderInterfaceBoardIc2();
break;
}
2022-02-11 17:38:02 +01:00
case (gpioIds::CS_SUS_8): {
2022-02-14 18:38:35 +01:00
selectY2();
enableDecoderInterfaceBoardIc2();
2022-01-17 15:58:27 +01:00
break;
}
2022-02-11 17:38:02 +01:00
case (gpioIds::CS_SUS_9): {
2022-02-14 18:38:35 +01:00
selectY3();
enableDecoderInterfaceBoardIc2();
2022-01-17 15:58:27 +01:00
break;
}
2022-02-11 17:38:02 +01:00
case (gpioIds::CS_SUS_10): {
2022-01-17 15:58:27 +01:00
selectY4();
enableDecoderInterfaceBoardIc2();
break;
}
2022-02-11 17:38:02 +01:00
case (gpioIds::CS_SUS_11): {
2022-01-17 15:58:27 +01:00
selectY5();
enableDecoderInterfaceBoardIc2();
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 15:58:27 +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-02-14 18:38:35 +01:00
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_0);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2);
2021-05-02 13:48:39 +02:00
}
void enableDecoderTcsIc2() {
2022-01-17 15:58:27 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2);
2022-02-14 18:38:35 +01:00
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_0);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1);
2021-05-02 13:48:39 +02:00
}
2021-05-07 18:48:42 +02:00
void enableDecoderInterfaceBoardIc1() {
2022-02-14 18:38:35 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_0);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1);
2022-01-17 15:58:27 +01:00
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2);
2021-05-02 13:48:39 +02:00
}
2021-05-07 18:48:42 +02:00
void enableDecoderInterfaceBoardIc2() {
2022-02-14 18:38:35 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_0);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1);
2022-01-17 15:58:27 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2);
2021-05-02 13:48:39 +02:00
}
2021-10-29 19:13:48 +02:00
void disableDecoderTcsIc1() {
2022-02-14 18:38:35 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_0);
2022-01-17 15:58:27 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1);
2022-02-14 18:38:35 +01:00
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2);
2021-10-29 19:13:48 +02:00
}
void disableDecoderTcsIc2() {
2022-02-14 18:38:35 +01:00
// DO NOT CHANGE THE ORDER HERE
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_0);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2);
2022-01-17 15:58:27 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1);
2021-10-29 19:13:48 +02:00
}
void disableDecoderInterfaceBoardIc1() {
2022-02-14 18:38:35 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_0);
2022-01-17 15:58:27 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1);
2022-02-14 18:38:35 +01:00
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2);
2021-10-29 19:13:48 +02:00
}
void disableDecoderInterfaceBoardIc2() {
2022-02-14 18:38:35 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_0);
2022-01-17 15:58:27 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1);
2022-02-14 18:38:35 +01:00
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2);
2021-10-29 19:13:48 +02:00
}
2022-01-17 15:58:27 +01:00
void enableRwDecoder() { gpioComInterface->pullHigh(gpioIds::EN_RW_CS); }
2021-10-29 19:13:48 +02:00
2022-01-17 15:58:27 +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-02-14 18:38:35 +01:00
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3);
2022-01-17 15:58:27 +01:00
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5);
2021-05-02 13:48:39 +02:00
}
void selectY1() {
2022-02-14 18:38:35 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4);
2022-01-17 15:58:27 +01:00
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5);
2021-05-02 13:48:39 +02:00
}
void selectY2() {
2022-02-14 18:38:35 +01:00
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5);
2021-05-02 13:48:39 +02:00
}
void selectY3() {
2022-02-14 18:38:35 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3);
2022-01-17 15:58:27 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4);
2022-02-14 18:38:35 +01:00
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5);
2021-05-02 13:48:39 +02:00
}
void selectY4() {
2022-02-14 18:38:35 +01:00
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3);
2022-01-17 15:58:27 +01:00
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4);
2022-02-14 18:38:35 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5);
2021-05-02 13:48:39 +02:00
}
void selectY5() {
2022-02-14 18:38:35 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5);
2021-05-02 13:48:39 +02:00
}
void selectY6() {
2022-02-14 18:38:35 +01:00
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4);
2022-01-17 15:58:27 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5);
2021-05-02 13:48:39 +02:00
}
void selectY7() {
2022-02-14 18:38:35 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3);
2022-01-17 15:58:27 +01:00
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5);
2021-05-02 13:48:39 +02:00
}
2021-05-07 18:48:42 +02:00
void disableAllDecoder() {
2022-01-17 15:58:27 +01:00
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2);
2022-02-14 18:38:35 +01:00
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_0);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1);
2022-01-17 15:58:27 +01:00
gpioComInterface->pullLow(gpioIds::EN_RW_CS);
2021-05-07 18:48:42 +02:00
}
2022-01-17 15:58:27 +01:00
} // namespace gpioCallbacks