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;
/** 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::OUT, gpio::LOW);
gpio::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::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);
/** 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);
// 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::OUT, gpio::LOW);
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) {
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) {
switch (gpioId) {
case(gpioIds::RTD_IC_3): {
enableDecoderTcsIc1();
selectY7();
enableDecoderTcsIc1();
break;
}
case(gpioIds::RTD_IC_4): {
enableDecoderTcsIc1();
selectY6();
enableDecoderTcsIc1();
break;
}
case(gpioIds::RTD_IC_5): {
enableDecoderTcsIc1();
selectY5();
enableDecoderTcsIc1();
break;
}
case(gpioIds::RTD_IC_6): {
enableDecoderTcsIc1();
selectY4();
enableDecoderTcsIc1();
break;
}
case(gpioIds::RTD_IC_7): {
enableDecoderTcsIc1();
selectY3();
enableDecoderTcsIc1();
break;
}
case(gpioIds::RTD_IC_8): {
enableDecoderTcsIc1();
selectY2();
enableDecoderTcsIc1();
break;
}
case(gpioIds::RTD_IC_9): {
enableDecoderTcsIc1();
selectY1();
enableDecoderTcsIc1();
break;
}
case(gpioIds::RTD_IC_10): {
enableDecoderTcsIc1();
selectY0();
enableDecoderTcsIc1();
break;
}
case(gpioIds::RTD_IC_11): {
enableDecoderTcsIc2();
selectY7();
enableDecoderTcsIc2();
break;
}
case(gpioIds::RTD_IC_12): {
enableDecoderTcsIc2();
selectY6();
enableDecoderTcsIc2();
break;
}
case(gpioIds::RTD_IC_13): {
enableDecoderTcsIc2();
selectY5();
enableDecoderTcsIc2();
break;
}
case(gpioIds::RTD_IC_14): {
enableDecoderTcsIc2();
selectY4();
enableDecoderTcsIc2();
break;
}
case(gpioIds::RTD_IC_15): {
enableDecoderTcsIc2();
selectY3();
enableDecoderTcsIc2();
break;
}
case(gpioIds::RTD_IC_16): {
enableDecoderTcsIc2();
selectY2();
enableDecoderTcsIc2();
break;
}
case(gpioIds::RTD_IC_17): {
enableDecoderTcsIc2();
selectY1();
enableDecoderTcsIc2();
break;
}
case(gpioIds::RTD_IC_18): {
enableDecoderTcsIc2();
selectY0();
enableDecoderTcsIc2();
break;
}
case(gpioIds::CS_SUS_1): {
enableDecoderInterfaceBoardIc1();
selectY0();
enableDecoderInterfaceBoardIc1();
break;
}
case(gpioIds::CS_SUS_2): {
enableDecoderInterfaceBoardIc1();
selectY1();
enableDecoderInterfaceBoardIc1();
break;
}
case(gpioIds::CS_SUS_3): {
enableDecoderInterfaceBoardIc2();
selectY0();
enableDecoderInterfaceBoardIc2();
break;
}
case(gpioIds::CS_SUS_4): {
enableDecoderInterfaceBoardIc2();
selectY1();
enableDecoderInterfaceBoardIc2();
break;
}
case(gpioIds::CS_SUS_5): {
enableDecoderInterfaceBoardIc2();
selectY2();
enableDecoderInterfaceBoardIc2();
break;
}
case(gpioIds::CS_SUS_6): {
enableDecoderInterfaceBoardIc1();
selectY2();
enableDecoderInterfaceBoardIc1();
break;
}
case(gpioIds::CS_SUS_7): {
enableDecoderInterfaceBoardIc1();
selectY3();
enableDecoderInterfaceBoardIc1();
break;
}
case(gpioIds::CS_SUS_8): {
enableDecoderInterfaceBoardIc2();
selectY3();
enableDecoderInterfaceBoardIc2();
break;
}
case(gpioIds::CS_SUS_9): {
enableDecoderInterfaceBoardIc1();
selectY4();
enableDecoderInterfaceBoardIc1();
break;
}
case(gpioIds::CS_SUS_10): {
enableDecoderInterfaceBoardIc1();
selectY5();
enableDecoderInterfaceBoardIc1();
break;
}
case(gpioIds::CS_SUS_11): {
enableDecoderInterfaceBoardIc2();
selectY4();
enableDecoderInterfaceBoardIc2();
break;
}
case(gpioIds::CS_SUS_12): {
enableDecoderInterfaceBoardIc2();
selectY5();
enableDecoderInterfaceBoardIc2();
break;
}
case(gpioIds::CS_SUS_13): {
enableDecoderInterfaceBoardIc1();
selectY6();
enableDecoderInterfaceBoardIc1();
break;
}
case(gpioIds::CS_RW1): {
enableRwDecoder();
selectY0();
enableRwDecoder();
break;
}
case(gpioIds::CS_RW2): {
enableRwDecoder();
selectY1();
enableRwDecoder();
break;
}
case(gpioIds::CS_RW3): {
enableRwDecoder();
selectY2();
enableRwDecoder();
break;
}
case(gpioIds::CS_RW4): {
enableRwDecoder();
selectY3();
enableRwDecoder();
break;
}
default:
@ -253,9 +399,9 @@ void enableDecoderTcsIc1() {
}
void enableDecoderTcsIc2() {
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2);
gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3);
}
void enableDecoderInterfaceBoardIc1() {
@ -266,17 +412,43 @@ void enableDecoderInterfaceBoardIc1() {
void enableDecoderInterfaceBoardIc2() {
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->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() {
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);
}
void disableRwDecoder() {
gpioComInterface->pullLow(gpioIds::EN_RW_CS);
}
void selectY0() {
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5);
@ -326,9 +498,9 @@ void selectY7() {
}
void disableAllDecoder() {
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2);
gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3);
gpioComInterface->pullLow(gpioIds::EN_RW_CS);
}

View File

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