improved chip select decoding

This commit is contained in:
Jakob Meier 2021-10-29 19:13:48 +02:00
parent 017e02e513
commit ca8e3f685a
2 changed files with 221 additions and 43 deletions

View File

@ -27,14 +27,25 @@ void initSpiCsDecoder(GpioIF* gpioComIF) {
GpiodRegularByLineName* spiMuxBit = nullptr; GpiodRegularByLineName* spiMuxBit = nullptr;
/** Setting mux bit 1 to low will disable IC21 on the interface board */ /** 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", spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_1_PIN, "SPI Mux Bit 1",
gpio::OUT, gpio::LOW); gpio::OUT, gpio::HIGH);
spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_1, spiMuxBit); spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_1, spiMuxBit);
/** Setting mux bit 2 to low disables IC1 on the TCS board */ /** 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::LOW); 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); 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 */ /** 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); 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); 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 */ /** The following gpios can take arbitrary initial values */
spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_4_PIN, "SPI Mux Bit 4", gpio::OUT, gpio::LOW); spiMuxBit = new GpiodRegularByLineName(q7s::gpioNames::SPI_MUX_BIT_4_PIN, "SPI Mux Bit 4", gpio::OUT, gpio::LOW);
spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_4, spiMuxBit); spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_4, spiMuxBit);
@ -68,173 +79,308 @@ void spiCsDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, gpio::Lev
} }
if (value == gpio::HIGH) { if (value == gpio::HIGH) {
disableAllDecoder(); 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;
}
} }
else if (value == gpio::LOW) { else if (value == gpio::LOW) {
switch (gpioId) { switch (gpioId) {
case(gpioIds::RTD_IC_3): { case(gpioIds::RTD_IC_3): {
enableDecoderTcsIc1();
selectY7(); selectY7();
enableDecoderTcsIc1();
break; break;
} }
case(gpioIds::RTD_IC_4): { case(gpioIds::RTD_IC_4): {
enableDecoderTcsIc1();
selectY6(); selectY6();
enableDecoderTcsIc1();
break; break;
} }
case(gpioIds::RTD_IC_5): { case(gpioIds::RTD_IC_5): {
enableDecoderTcsIc1();
selectY5(); selectY5();
enableDecoderTcsIc1();
break; break;
} }
case(gpioIds::RTD_IC_6): { case(gpioIds::RTD_IC_6): {
enableDecoderTcsIc1();
selectY4(); selectY4();
enableDecoderTcsIc1();
break; break;
} }
case(gpioIds::RTD_IC_7): { case(gpioIds::RTD_IC_7): {
enableDecoderTcsIc1();
selectY3(); selectY3();
enableDecoderTcsIc1();
break; break;
} }
case(gpioIds::RTD_IC_8): { case(gpioIds::RTD_IC_8): {
enableDecoderTcsIc1();
selectY2(); selectY2();
enableDecoderTcsIc1();
break; break;
} }
case(gpioIds::RTD_IC_9): { case(gpioIds::RTD_IC_9): {
enableDecoderTcsIc1();
selectY1(); selectY1();
enableDecoderTcsIc1();
break; break;
} }
case(gpioIds::RTD_IC_10): { case(gpioIds::RTD_IC_10): {
enableDecoderTcsIc1();
selectY0(); selectY0();
enableDecoderTcsIc1();
break; break;
} }
case(gpioIds::RTD_IC_11): { case(gpioIds::RTD_IC_11): {
enableDecoderTcsIc2();
selectY7(); selectY7();
enableDecoderTcsIc2();
break; break;
} }
case(gpioIds::RTD_IC_12): { case(gpioIds::RTD_IC_12): {
enableDecoderTcsIc2();
selectY6(); selectY6();
enableDecoderTcsIc2();
break; break;
} }
case(gpioIds::RTD_IC_13): { case(gpioIds::RTD_IC_13): {
enableDecoderTcsIc2();
selectY5(); selectY5();
enableDecoderTcsIc2();
break; break;
} }
case(gpioIds::RTD_IC_14): { case(gpioIds::RTD_IC_14): {
enableDecoderTcsIc2();
selectY4(); selectY4();
enableDecoderTcsIc2();
break; break;
} }
case(gpioIds::RTD_IC_15): { case(gpioIds::RTD_IC_15): {
enableDecoderTcsIc2();
selectY3(); selectY3();
enableDecoderTcsIc2();
break; break;
} }
case(gpioIds::RTD_IC_16): { case(gpioIds::RTD_IC_16): {
enableDecoderTcsIc2();
selectY2(); selectY2();
enableDecoderTcsIc2();
break; break;
} }
case(gpioIds::RTD_IC_17): { case(gpioIds::RTD_IC_17): {
enableDecoderTcsIc2();
selectY1(); selectY1();
enableDecoderTcsIc2();
break; break;
} }
case(gpioIds::RTD_IC_18): { case(gpioIds::RTD_IC_18): {
enableDecoderTcsIc2();
selectY0(); selectY0();
enableDecoderTcsIc2();
break; break;
} }
case(gpioIds::CS_SUS_1): { case(gpioIds::CS_SUS_1): {
enableDecoderInterfaceBoardIc1();
selectY0(); selectY0();
enableDecoderInterfaceBoardIc1();
break; break;
} }
case(gpioIds::CS_SUS_2): { case(gpioIds::CS_SUS_2): {
enableDecoderInterfaceBoardIc1();
selectY1(); selectY1();
enableDecoderInterfaceBoardIc1();
break; break;
} }
case(gpioIds::CS_SUS_3): { case(gpioIds::CS_SUS_3): {
enableDecoderInterfaceBoardIc2();
selectY0(); selectY0();
enableDecoderInterfaceBoardIc2();
break; break;
} }
case(gpioIds::CS_SUS_4): { case(gpioIds::CS_SUS_4): {
enableDecoderInterfaceBoardIc2();
selectY1(); selectY1();
enableDecoderInterfaceBoardIc2();
break; break;
} }
case(gpioIds::CS_SUS_5): { case(gpioIds::CS_SUS_5): {
enableDecoderInterfaceBoardIc2();
selectY2(); selectY2();
enableDecoderInterfaceBoardIc2();
break; break;
} }
case(gpioIds::CS_SUS_6): { case(gpioIds::CS_SUS_6): {
enableDecoderInterfaceBoardIc1();
selectY2(); selectY2();
enableDecoderInterfaceBoardIc1();
break; break;
} }
case(gpioIds::CS_SUS_7): { case(gpioIds::CS_SUS_7): {
enableDecoderInterfaceBoardIc1();
selectY3(); selectY3();
enableDecoderInterfaceBoardIc1();
break; break;
} }
case(gpioIds::CS_SUS_8): { case(gpioIds::CS_SUS_8): {
enableDecoderInterfaceBoardIc2();
selectY3(); selectY3();
enableDecoderInterfaceBoardIc2();
break; break;
} }
case(gpioIds::CS_SUS_9): { case(gpioIds::CS_SUS_9): {
enableDecoderInterfaceBoardIc1();
selectY4(); selectY4();
enableDecoderInterfaceBoardIc1();
break; break;
} }
case(gpioIds::CS_SUS_10): { case(gpioIds::CS_SUS_10): {
enableDecoderInterfaceBoardIc1();
selectY5(); selectY5();
enableDecoderInterfaceBoardIc1();
break; break;
} }
case(gpioIds::CS_SUS_11): { case(gpioIds::CS_SUS_11): {
enableDecoderInterfaceBoardIc2();
selectY4(); selectY4();
enableDecoderInterfaceBoardIc2();
break; break;
} }
case(gpioIds::CS_SUS_12): { case(gpioIds::CS_SUS_12): {
enableDecoderInterfaceBoardIc2();
selectY5(); selectY5();
enableDecoderInterfaceBoardIc2();
break; break;
} }
case(gpioIds::CS_SUS_13): { case(gpioIds::CS_SUS_13): {
enableDecoderInterfaceBoardIc1();
selectY6(); selectY6();
enableDecoderInterfaceBoardIc1();
break; break;
} }
case(gpioIds::CS_RW1): { case(gpioIds::CS_RW1): {
enableRwDecoder();
selectY0(); selectY0();
enableRwDecoder();
break; break;
} }
case(gpioIds::CS_RW2): { case(gpioIds::CS_RW2): {
enableRwDecoder();
selectY1(); selectY1();
enableRwDecoder();
break; break;
} }
case(gpioIds::CS_RW3): { case(gpioIds::CS_RW3): {
enableRwDecoder();
selectY2(); selectY2();
enableRwDecoder();
break; break;
} }
case(gpioIds::CS_RW4): { case(gpioIds::CS_RW4): {
enableRwDecoder();
selectY3(); selectY3();
enableRwDecoder();
break; break;
} }
default: default:
@ -253,9 +399,9 @@ void enableDecoderTcsIc1() {
} }
void enableDecoderTcsIc2() { void enableDecoderTcsIc2() {
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3);
} }
void enableDecoderInterfaceBoardIc1() { void enableDecoderInterfaceBoardIc1() {
@ -266,17 +412,43 @@ void enableDecoderInterfaceBoardIc1() {
void enableDecoderInterfaceBoardIc2() { void enableDecoderInterfaceBoardIc2() {
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1); gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2); gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2);
}
void disableDecoderTcsIc1() {
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3);
}
void disableDecoderTcsIc2() {
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2);
}
void disableDecoderInterfaceBoardIc1() {
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3);
}
void disableDecoderInterfaceBoardIc2() {
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3);
} }
void enableRwDecoder() { 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); gpioComInterface->pullHigh(gpioIds::EN_RW_CS);
} }
void disableRwDecoder() {
gpioComInterface->pullLow(gpioIds::EN_RW_CS);
}
void selectY0() { void selectY0() {
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5);
@ -326,9 +498,9 @@ void selectY7() {
} }
void disableAllDecoder() { void disableAllDecoder() {
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2); gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3);
gpioComInterface->pullLow(gpioIds::EN_RW_CS); gpioComInterface->pullLow(gpioIds::EN_RW_CS);
} }

View File

@ -44,10 +44,16 @@ namespace gpioCallbacks {
*/ */
void enableDecoderInterfaceBoardIc2(); void enableDecoderInterfaceBoardIc2();
void disableDecoderTcsIc1();
void disableDecoderTcsIc2();
void disableDecoderInterfaceBoardIc1();
void disableDecoderInterfaceBoardIc2();
/** /**
* @brief Enables the reaction wheel chip select decoder (IC3). * @brief Enables the reaction wheel chip select decoder (IC3).
*/ */
void enableRwDecoder(); void enableRwDecoder();
void disableRwDecoder();
/** /**
* @brief This function disables all decoder. * @brief This function disables all decoder.