From e048d6d7ecef04a812ebe0b4cd77031ec3d97387 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Sat, 13 Mar 2021 14:42:30 +0100 Subject: [PATCH] rtd handler compiled --- bsp_hosted/fsfwconfig/devices/gpioIds.h | 26 ++- bsp_q7s/CMakeLists.txt | 1 + bsp_q7s/ObjectFactory.cpp | 48 +++- bsp_q7s/gpio/CMakeLists.txt | 3 + bsp_q7s/gpio/gpioCallbacks.cpp | 220 ++++++++++++++++++ bsp_q7s/gpio/gpioCallbacks.h | 23 ++ fsfwconfig/devices/addresses.h | 19 ++ fsfwconfig/devices/gpioIds.h | 26 ++- fsfwconfig/objects/systemObjectList.h | 20 ++ linux/boardtest/SpiTestClass.cpp | 14 +- linux/gpio/GpioCookie.cpp | 8 +- linux/gpio/GpioCookie.h | 2 +- linux/gpio/LinuxLibgpioIF.cpp | 2 +- linux/spi/SpiCookie.h | 1 + mission/devices/CMakeLists.txt | 1 + mission/devices/Max31865PT1000Handler.cpp | 53 ++--- ...PT100Handler.h => Max31865PT1000Handler.h} | 10 +- ...alSensorPacket.h => Max31865Definitions.h} | 24 +- 18 files changed, 431 insertions(+), 70 deletions(-) create mode 100644 bsp_q7s/gpio/CMakeLists.txt create mode 100644 bsp_q7s/gpio/gpioCallbacks.cpp create mode 100644 bsp_q7s/gpio/gpioCallbacks.h rename mission/devices/{Max31865PT100Handler.h => Max31865PT1000Handler.h} (92%) rename mission/devices/devicedefinitions/{ThermalSensorPacket.h => Max31865Definitions.h} (65%) diff --git a/bsp_hosted/fsfwconfig/devices/gpioIds.h b/bsp_hosted/fsfwconfig/devices/gpioIds.h index 8963bd20..df49c0b7 100644 --- a/bsp_hosted/fsfwconfig/devices/gpioIds.h +++ b/bsp_hosted/fsfwconfig/devices/gpioIds.h @@ -25,7 +25,31 @@ namespace gpioIds { MGM_3_RM3100_CS, TEST_ID_0, - TEST_ID_1 + TEST_ID_1, + + RTD_IC3, + RTD_IC4, + RTD_IC5, + RTD_IC6, + RTD_IC7, + RTD_IC8, + RTD_IC9, + RTD_IC10, + RTD_IC11, + RTD_IC12, + RTD_IC13, + RTD_IC14, + RTD_IC15, + RTD_IC16, + RTD_IC17, + RTD_IC18, + + SPI_MUX_BIT_1, + SPI_MUX_BIT_2, + SPI_MUX_BIT_3, + SPI_MUX_BIT_4, + SPI_MUX_BIT_5, + SPI_MUX_BIT_6 }; } diff --git a/bsp_q7s/CMakeLists.txt b/bsp_q7s/CMakeLists.txt index 7b985558..e567628e 100644 --- a/bsp_q7s/CMakeLists.txt +++ b/bsp_q7s/CMakeLists.txt @@ -8,6 +8,7 @@ add_subdirectory(boardconfig) add_subdirectory(comIF) add_subdirectory(devices) add_subdirectory(boardtest) +add_subdirectory(gpio) diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 13f27f96..143bf6fb 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -16,6 +17,8 @@ #include #include #include +#include +#include #include #include @@ -31,6 +34,8 @@ #include #include #include +#include +#include #include #include @@ -77,10 +82,13 @@ void ObjectFactory::produce(){ I2cCookie* i2cCookieTmp1075tcs2 = new I2cCookie(addresses::TMP1075_TCS_2, TMP1075::MAX_REPLY_LENGTH, std::string("/dev/i2c-1")); #endif + LinuxLibgpioIF* gpioComIF = new LinuxLibgpioIF(objects::GPIO_IF); + /* Communication interfaces */ new CspComIF(objects::CSP_COM_IF); new I2cComIF(objects::I2C_COM_IF); new UartComIF(objects::UART_COM_IF); + new SpiComIF(objects::SPI_COM_IF, gpioComIF); #if TE0720 == 0 CspCookie* p60DockCspCookie = new CspCookie(P60Dock::MAX_REPLY_LENGTH, @@ -123,42 +131,41 @@ void ObjectFactory::produce(){ tmp1075Handler_2->setStartUpImmediately(); GpioCookie* heaterGpiosCookie = new GpioCookie; - new LinuxLibgpioIF(objects::GPIO_IF); #if TE0720 == 0 /* Pin H2-11 on stack connector */ GpiodRegular gpioConfigHeater0(std::string("gpiochip7"), 16, std::string("Heater0"), gpio::OUT, 0); - heaterGpiosCookie->addGpio(gpioIds::HEATER_0, gpioConfigHeater0); + heaterGpiosCookie->addGpio(gpioIds::HEATER_0, &gpioConfigHeater0); /* Pin H2-12 on stack connector */ GpiodRegular gpioConfigHeater1(std::string("gpiochip7"), 12, std::string("Heater1"), gpio::OUT, 0); - heaterGpiosCookie->addGpio(gpioIds::HEATER_1, gpioConfigHeater1); + heaterGpiosCookie->addGpio(gpioIds::HEATER_1, &gpioConfigHeater1); /* Pin H2-13 on stack connector */ GpiodRegular gpioConfigHeater2(std::string("gpiochip7"), 7, std::string("Heater2"), gpio::OUT, 0); - heaterGpiosCookie->addGpio(gpioIds::HEATER_2, gpioConfigHeater2); + heaterGpiosCookie->addGpio(gpioIds::HEATER_2, &gpioConfigHeater2); GpiodRegular gpioConfigHeater3(std::string("gpiochip7"), 5, std::string("Heater3"), gpio::OUT, 0); - heaterGpiosCookie->addGpio(gpioIds::HEATER_3, gpioConfigHeater3); + heaterGpiosCookie->addGpio(gpioIds::HEATER_3, &gpioConfigHeater3); GpiodRegular gpioConfigHeater4(std::string("gpiochip7"), 3, std::string("Heater4"), gpio::OUT, 0); - heaterGpiosCookie->addGpio(gpioIds::HEATER_4, gpioConfigHeater4); + heaterGpiosCookie->addGpio(gpioIds::HEATER_4, &gpioConfigHeater4); GpiodRegular gpioConfigHeater5(std::string("gpiochip7"), 0, std::string("Heater5"), gpio::OUT, 0); - heaterGpiosCookie->addGpio(gpioIds::HEATER_5, gpioConfigHeater5); + heaterGpiosCookie->addGpio(gpioIds::HEATER_5, &gpioConfigHeater5); GpiodRegular gpioConfigHeater6(std::string("gpiochip7"), 1, std::string("Heater6"), gpio::OUT, 0); - heaterGpiosCookie->addGpio(gpioIds::HEATER_6, gpioConfigHeater6); + heaterGpiosCookie->addGpio(gpioIds::HEATER_6, &gpioConfigHeater6); GpiodRegular gpioConfigHeater7(std::string("gpiochip7"), 11, std::string("Heater7"), gpio::OUT, 0); - heaterGpiosCookie->addGpio(gpioIds::HEATER_7, gpioConfigHeater7); + heaterGpiosCookie->addGpio(gpioIds::HEATER_7, &gpioConfigHeater7); new HeaterHandler(objects::HEATER_HANDLER, objects::GPIO_IF, heaterGpiosCookie, objects::PCDU_HANDLER, pcduSwitches::TCS_BOARD_8V_HEATER_IN); @@ -167,10 +174,10 @@ void ObjectFactory::produce(){ GpiodRegular gpioConfigDeplSA0(std::string("gpiochip7"), 4, std::string("DeplSA1"), gpio::OUT, 0); - solarArrayDeplCookie->addGpio(gpioIds::DEPLSA1, gpioConfigDeplSA0); + solarArrayDeplCookie->addGpio(gpioIds::DEPLSA1, &gpioConfigDeplSA0); GpiodRegular gpioConfigDeplSA1(std::string("gpiochip7"), 2, std::string("DeplSA2"), gpio::OUT, 0); - solarArrayDeplCookie->addGpio(gpioIds::DEPLSA2, gpioConfigDeplSA1); + solarArrayDeplCookie->addGpio(gpioIds::DEPLSA2, &gpioConfigDeplSA1); //TODO: Find out burn time. For now set to 1000 ms. new SolarArrayDeploymentHandler(objects::SOLAR_ARRAY_DEPL_HANDLER, objects::GPIO_IF, @@ -185,6 +192,25 @@ void ObjectFactory::produce(){ objects::UART_COM_IF, syrlinksUartCookie); syrlinksHkHandler->setModeNormal(); + GpioCookie* rtdGpioCookie = new GpioCookie; + + gpioCallbacks::initTcsBoardDecoder(gpioComIF); + GpioCallback gpioRtdIc3(std::string("Chip select RTD IC3"), gpio::OUT, 1, + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + rtdGpioCookie->addGpio(gpioIds::RTD_IC3, &gpioRtdIc3); + GpioCallback gpioRtdIc4(std::string("Chip select RTD IC4"), gpio::OUT, 1, + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + rtdGpioCookie->addGpio(gpioIds::RTD_IC4, &gpioRtdIc4); + + SpiCookie* spiRtdIc3 = new SpiCookie(addresses::RTD_IC3, gpioIds::RTD_IC3, + std::string("/dev/spidev2.0"), Max31865Definitions::MAX_REPLY_SIZE, + spi::SpiMode::MODE_1, 2000000); + SpiCookie* spiRtdIc4 = new SpiCookie(addresses::RTD_IC4, gpioIds::RTD_IC4, + std::string("/dev/spidev2.0"), Max31865Definitions::MAX_REPLY_SIZE, + spi::SpiMode::MODE_1, 2000000); + new Max31865PT1000Handler(objects::RTD_IC3, objects::SPI_COM_IF, spiRtdIc3, 0); // 0 is switchId + new Max31865PT1000Handler(objects::RTD_IC4, objects::SPI_COM_IF, spiRtdIc4, 0); + #endif new TmTcUnixUdpBridge(objects::UDP_BRIDGE, diff --git a/bsp_q7s/gpio/CMakeLists.txt b/bsp_q7s/gpio/CMakeLists.txt new file mode 100644 index 00000000..dd657546 --- /dev/null +++ b/bsp_q7s/gpio/CMakeLists.txt @@ -0,0 +1,3 @@ +target_sources(${TARGET_NAME} PRIVATE + gpioCallbacks.cpp +) diff --git a/bsp_q7s/gpio/gpioCallbacks.cpp b/bsp_q7s/gpio/gpioCallbacks.cpp new file mode 100644 index 00000000..8c0f0662 --- /dev/null +++ b/bsp_q7s/gpio/gpioCallbacks.cpp @@ -0,0 +1,220 @@ +#include +#include +#include +#include +#include + + +namespace gpioCallbacks { + +GpioIF* gpioComInterface; + +void initTcsBoardDecoder(GpioIF* gpioComIF) { + + ReturnValue_t result; + + if (gpioComIF == nullptr) { + sif::debug << "initTcsBoardDecoder: Invalid gpioComIF" << std::endl; + return; + } + + gpioComInterface = gpioComIF; + + GpioCookie* spiMuxGpios = new GpioCookie; + /** + * Initial values of the spi mux gpios can all be set to an arbitrary value expect for spi mux + * bit 1. Setting spi mux bit 1 to high will pull all decoder outputs to high voltage level. + */ + GpiodRegular spiMuxBit1(std::string("gpiochip7"), 13, std::string("SPI Mux Bit 1"), gpio::OUT, + 1); + spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_1, &spiMuxBit1); + GpiodRegular spiMuxBit2(std::string("gpiochip7"), 14, std::string("SPI Mux Bit 2"), gpio::OUT, + 0); + spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_2, &spiMuxBit2); + GpiodRegular spiMuxBit3(std::string("gpiochip7"), 15, std::string("SPI Mux Bit 3"), gpio::OUT, + 0); + spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_3, &spiMuxBit3); + GpiodRegular spiMuxBit4(std::string("gpiochip7"), 16, std::string("SPI Mux Bit 4"), gpio::OUT, + 0); + spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_4, &spiMuxBit4); + GpiodRegular spiMuxBit5(std::string("gpiochip7"), 17, std::string("SPI Mux Bit 5"), gpio::OUT, + 0); + spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_5, &spiMuxBit5); + GpiodRegular spiMuxBit6(std::string("gpiochip7"), 18, std::string("SPI Mux Bit 6"), gpio::OUT, + 0); + spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_6, &spiMuxBit6); + + result = gpioComInterface->addGpios(spiMuxGpios); + if (result != HasReturnvaluesIF::RETURN_OK) { + sif::error << "initTcsBoardDecoder: Failed to add mux bit gpios to gpioComIF" + << std::endl; + return; + } +} + +void tcsBoardDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int value, + void* args) { + + if (gpioComInterface == nullptr) { + sif::debug << "tcsBoardDecoderCallback: No gpioComIF specified. Call initTcsBoardDecoder " + << "to specify gpioComIF" << std::endl; + return; + } + + /* Read is not supported by the callback function */ + if (gpioOp == gpio::GpioOperation::READ) { + return; + } + + if (value == 1) { + /* This will pull all 16 decoder outputs to high */ + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1); + } + else if (value == 0) { + switch (gpioId) { + case(gpioIds::RTD_IC3): { + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); + break; + } + case(gpioIds::RTD_IC4): { + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); + break; + } + case(gpioIds::RTD_IC5): { + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); + break; + } + case(gpioIds::RTD_IC6): { + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); + break; + } + case(gpioIds::RTD_IC7): { + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); + break; + } + case(gpioIds::RTD_IC8): { + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); + break; + } + case(gpioIds::RTD_IC9): { + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); + break; + } + case(gpioIds::RTD_IC10): { + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); + break; + } + case(gpioIds::RTD_IC11): { + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); + break; + } + case(gpioIds::RTD_IC12): { + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); + break; + } + case(gpioIds::RTD_IC13): { + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); + break; + } + case(gpioIds::RTD_IC14): { + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); + break; + } + case(gpioIds::RTD_IC15): { + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); + break; + } + case(gpioIds::RTD_IC16): { + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); + break; + } + case(gpioIds::RTD_IC17): { + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); + break; + } + case(gpioIds::RTD_IC18): { + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); + break; + } + default: + sif::debug << "tcsBoardDecoderCallback: Invalid gpioid " << gpioId << std::endl; + } + } + else { + sif::debug << "tcsBoardDecoderCallback: Invalid value. Must be 0 or 1" << std::endl; + } +} + +} diff --git a/bsp_q7s/gpio/gpioCallbacks.h b/bsp_q7s/gpio/gpioCallbacks.h new file mode 100644 index 00000000..7654e548 --- /dev/null +++ b/bsp_q7s/gpio/gpioCallbacks.h @@ -0,0 +1,23 @@ +#ifndef LINUX_GPIO_GPIOCALLBACKS_H_ +#define LINUX_GPIO_GPIOCALLBACKS_H_ + +#include +#include + + +namespace gpioCallbacks { + + /** + * @brief This function initializes the GPIOs used to control the SN74LVC138APWR decoders on + * the TCS Board. + */ + void initTcsBoardDecoder(GpioIF* gpioComIF); + + /** + * @brief This function implements the decoding to multiply gpios by using the two decoder + * chips SN74LVC138APWR on the TCS board. + */ + void tcsBoardDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int value, void* args); +} + +#endif /* LINUX_GPIO_GPIOCALLBACKS_H_ */ diff --git a/fsfwconfig/devices/addresses.h b/fsfwconfig/devices/addresses.h index cd0b9d29..6a13908d 100644 --- a/fsfwconfig/devices/addresses.h +++ b/fsfwconfig/devices/addresses.h @@ -30,6 +30,25 @@ namespace addresses { TMP1075_TCS_2 = 73, }; + enum spiAddresses: address_t { + RTD_IC3, + RTD_IC4, + RTD_IC5, + RTD_IC6, + RTD_IC7, + RTD_IC8, + RTD_IC9, + RTD_IC10, + RTD_IC11, + RTD_IC12, + RTD_IC13, + RTD_IC14, + RTD_IC15, + RTD_IC16, + RTD_IC17, + RTD_IC18 + }; + /* Addresses of devices supporting the CSP protocol */ enum cspAddresses: uint8_t { P60DOCK = 4, diff --git a/fsfwconfig/devices/gpioIds.h b/fsfwconfig/devices/gpioIds.h index 8963bd20..df49c0b7 100644 --- a/fsfwconfig/devices/gpioIds.h +++ b/fsfwconfig/devices/gpioIds.h @@ -25,7 +25,31 @@ namespace gpioIds { MGM_3_RM3100_CS, TEST_ID_0, - TEST_ID_1 + TEST_ID_1, + + RTD_IC3, + RTD_IC4, + RTD_IC5, + RTD_IC6, + RTD_IC7, + RTD_IC8, + RTD_IC9, + RTD_IC10, + RTD_IC11, + RTD_IC12, + RTD_IC13, + RTD_IC14, + RTD_IC15, + RTD_IC16, + RTD_IC17, + RTD_IC18, + + SPI_MUX_BIT_1, + SPI_MUX_BIT_2, + SPI_MUX_BIT_3, + SPI_MUX_BIT_4, + SPI_MUX_BIT_5, + SPI_MUX_BIT_6 }; } diff --git a/fsfwconfig/objects/systemObjectList.h b/fsfwconfig/objects/systemObjectList.h index f05becbe..8bbd9c2d 100644 --- a/fsfwconfig/objects/systemObjectList.h +++ b/fsfwconfig/objects/systemObjectList.h @@ -59,6 +59,26 @@ namespace objects { /* 0x54 ('T') for thermal objects */ HEATER_HANDLER = 0x54000003, + /** + * Not yet specified which pt1000 will measure which device/location in the satellite. + * Therefore object ids are named according to the IC naming of the RTDs in the schematic. + */ + RTD_IC3 = 0x54000004, + RTD_IC4 = 0x54000005, + RTD_IC5 = 0x54000006, + RTD_IC6 = 0x54000007, + RTD_IC7 = 0x54000008, + RTD_IC8 = 0x54000009, + RTD_IC9 = 0x5400000A, + RTD_IC10 = 0x5400000B, + RTD_IC11 = 0x5400000C, + RTD_IC12 = 0x5400000D, + RTD_IC13 = 0x5400000E, + RTD_IC14 = 0x5400000F, + RTD_IC15 = 0x5400001F, + RTD_IC16 = 0x5400002F, + RTD_IC17 = 0x5400003F, + RTD_IC18 = 0x5400004F, /* 0x54 ('T') for test handlers */ TEST_TASK = 0x54694269, diff --git a/linux/boardtest/SpiTestClass.cpp b/linux/boardtest/SpiTestClass.cpp index df32ec5b..2f68bea0 100644 --- a/linux/boardtest/SpiTestClass.cpp +++ b/linux/boardtest/SpiTestClass.cpp @@ -137,37 +137,37 @@ void SpiTestClass::acsInit() { { GpiodRegular gpio(rpiGpioName, mgm0Lis3ChipSelect, "MGM_0_LIS3", gpio::Direction::OUT, 1); - gpioCookie->addGpio(gpioIds::MGM_0_LIS3_CS, gpio); + gpioCookie->addGpio(gpioIds::MGM_0_LIS3_CS, &gpio); } { GpiodRegular gpio(rpiGpioName, mgm1Rm3100ChipSelect, "MGM_1_RM3100", gpio::Direction::OUT, 1); - gpioCookie->addGpio(gpioIds::MGM_1_RM3100_CS, gpio); + gpioCookie->addGpio(gpioIds::MGM_1_RM3100_CS, &gpio); } { GpiodRegular gpio(rpiGpioName, gyro0AdisChipSelect, "GYRO_0_ADIS", gpio::Direction::OUT, 1); - gpioCookie->addGpio(gpioIds::GYRO_0_ADIS_CS, gpio); + gpioCookie->addGpio(gpioIds::GYRO_0_ADIS_CS, &gpio); } { GpiodRegular gpio(rpiGpioName, gyro1L3gd20ChipSelect, "GYRO_1_L3G", gpio::Direction::OUT, 1); - gpioCookie->addGpio(gpioIds::GYRO_1_L3G_CS, gpio); + gpioCookie->addGpio(gpioIds::GYRO_1_L3G_CS, &gpio); } { GpiodRegular gpio(rpiGpioName, gyro2L3gd20ChipSelect, "GYRO_2_L3G", gpio::Direction::OUT, 1); - gpioCookie->addGpio(gpioIds::GYRO_2_L3G_CS, gpio); + gpioCookie->addGpio(gpioIds::GYRO_2_L3G_CS, &gpio); } { GpiodRegular gpio(rpiGpioName, mgm2Lis3mdlChipSelect, "MGM_2_LIS3", gpio::Direction::OUT, 1); - gpioCookie->addGpio(gpioIds::MGM_2_LIS3_CS, gpio); + gpioCookie->addGpio(gpioIds::MGM_2_LIS3_CS, &gpio); } { GpiodRegular gpio(rpiGpioName, mgm3Rm3100ChipSelect, "MGM_3_RM3100", gpio::Direction::OUT, 1); - gpioCookie->addGpio(gpioIds::MGM_3_RM3100_CS, gpio); + gpioCookie->addGpio(gpioIds::MGM_3_RM3100_CS, &gpio); } if(gpioIF != nullptr) { gpioIF->addGpios(gpioCookie); diff --git a/linux/gpio/GpioCookie.cpp b/linux/gpio/GpioCookie.cpp index f957d070..50b42307 100644 --- a/linux/gpio/GpioCookie.cpp +++ b/linux/gpio/GpioCookie.cpp @@ -4,10 +4,14 @@ GpioCookie::GpioCookie() { } -ReturnValue_t GpioCookie::addGpio(gpioId_t gpioId, GpiodRegular& gpioConfig){ +ReturnValue_t GpioCookie::addGpio(gpioId_t gpioId, GpioBase* gpioConfig){ + if (gpioConfig == nullptr) { + sif::debug << "GpioCookie::addGpio: gpioConfig is nullpointer" << std::endl; + return HasReturnvaluesIF::RETURN_FAILED; + } auto gpioMapIter = gpioMap.find(gpioId); if(gpioMapIter == gpioMap.end()) { - auto statusPair = gpioMap.emplace(gpioId, new GpiodRegular(gpioConfig)); + auto statusPair = gpioMap.emplace(gpioId, gpioConfig); if (statusPair.second == false) { #if FSFW_VERBOSE_LEVEL >= 1 sif::error << "GpioCookie::addGpio: Failed to add GPIO " << gpioId << diff --git a/linux/gpio/GpioCookie.h b/linux/gpio/GpioCookie.h index c7721a98..3f8531ee 100644 --- a/linux/gpio/GpioCookie.h +++ b/linux/gpio/GpioCookie.h @@ -23,7 +23,7 @@ public: virtual ~GpioCookie(); - ReturnValue_t addGpio(gpioId_t gpioId, GpiodRegular& gpioConfig); + ReturnValue_t addGpio(gpioId_t gpioId, GpioBase* gpioConfig); /** * @brief Get map with registered GPIOs. */ diff --git a/linux/gpio/LinuxLibgpioIF.cpp b/linux/gpio/LinuxLibgpioIF.cpp index cdf22a45..0711a1a2 100644 --- a/linux/gpio/LinuxLibgpioIF.cpp +++ b/linux/gpio/LinuxLibgpioIF.cpp @@ -60,7 +60,7 @@ ReturnValue_t LinuxLibgpioIF::configureGpios(GpioMap& mapToAdd) { if(gpioCallback->callback == nullptr) { return GPIO_INVALID_INSTANCE; } - gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::READ, + gpioCallback->callback(gpioMapIter->first, gpio::GpioOperation::WRITE, gpioCallback->initValue, gpioCallback->callbackArgs); } } diff --git a/linux/spi/SpiCookie.h b/linux/spi/SpiCookie.h index 42004993..1efbc0bd 100644 --- a/linux/spi/SpiCookie.h +++ b/linux/spi/SpiCookie.h @@ -17,6 +17,7 @@ public: * @param chipSelect Chip select. gpio::NO_GPIO can be used for hardware slave selects. * @param spiDev * @param maxSize + * @param spieSpeed SPI clock frequency in Hz. */ SpiCookie(address_t spiAddress, gpioId_t chipSelect, std::string spiDev, const size_t maxReplySize, spi::SpiMode spiMode, uint32_t spiSpeed); diff --git a/mission/devices/CMakeLists.txt b/mission/devices/CMakeLists.txt index 906b172b..a1617d07 100644 --- a/mission/devices/CMakeLists.txt +++ b/mission/devices/CMakeLists.txt @@ -11,6 +11,7 @@ target_sources(${TARGET_NAME} PUBLIC PDU2Handler.cpp ACUHandler.cpp SyrlinksHkHandler.cpp + Max31865PT1000Handler.cpp ) diff --git a/mission/devices/Max31865PT1000Handler.cpp b/mission/devices/Max31865PT1000Handler.cpp index ddf12d2f..c6d98c0a 100644 --- a/mission/devices/Max31865PT1000Handler.cpp +++ b/mission/devices/Max31865PT1000Handler.cpp @@ -1,6 +1,7 @@ +#include "Max31865PT1000Handler.h" + #include #include -#include "Max31865PT100Handler.h" Max31865PT1000Handler::Max31865PT1000Handler(object_id_t objectId, object_id_t comIF, CookieIF *comCookie, uint8_t switchId): @@ -53,11 +54,11 @@ void Max31865PT1000Handler::doShutDown() { ReturnValue_t Max31865PT1000Handler::buildNormalDeviceCommand( DeviceCommandId_t *id) { if(internalState == InternalState::RUNNING) { - *id = TSensorDefinitions::REQUEST_RTD; + *id = Max31865Definitions::REQUEST_RTD; return buildCommandFromCommand(*id, nullptr, 0); } else if(internalState == InternalState::REQUEST_FAULT_BYTE) { - *id = TSensorDefinitions::REQUEST_FAULT_BYTE; + *id = Max31865Definitions::REQUEST_FAULT_BYTE; return buildCommandFromCommand(*id, nullptr, 0); } else { @@ -73,12 +74,12 @@ ReturnValue_t Max31865PT1000Handler::buildTransitionDeviceCommand( case(InternalState::RUNNING): return DeviceHandlerBase::NOTHING_TO_SEND; case(InternalState::CONFIGURE): { - *id = TSensorDefinitions::CONFIG_CMD; + *id = Max31865Definitions::CONFIG_CMD; uint8_t config[1] = {DEFAULT_CONFIG}; return buildCommandFromCommand(*id, config, 1); } case(InternalState::REQUEST_CONFIG): { - *id = TSensorDefinitions::REQUEST_CONFIG; + *id = Max31865Definitions::REQUEST_CONFIG; return buildCommandFromCommand(*id, nullptr, 0); } @@ -96,8 +97,8 @@ ReturnValue_t Max31865PT1000Handler::buildCommandFromCommand( DeviceCommandId_t deviceCommand, const uint8_t *commandData, size_t commandDataLen) { switch(deviceCommand) { - case(TSensorDefinitions::CONFIG_CMD) : { - commandBuffer[0] = static_cast(TSensorDefinitions::CONFIG_CMD); + case(Max31865Definitions::CONFIG_CMD) : { + commandBuffer[0] = static_cast(Max31865Definitions::CONFIG_CMD); if(commandDataLen == 1) { commandBuffer[1] = commandData[0]; DeviceHandlerBase::rawPacketLen = 2; @@ -108,17 +109,17 @@ ReturnValue_t Max31865PT1000Handler::buildCommandFromCommand( return DeviceHandlerIF::NO_COMMAND_DATA; } } - case(TSensorDefinitions::REQUEST_CONFIG): { + case(Max31865Definitions::REQUEST_CONFIG): { commandBuffer[0] = 0x00; // dummy byte commandBuffer[1] = static_cast( - TSensorDefinitions::REQUEST_CONFIG); + Max31865Definitions::REQUEST_CONFIG); DeviceHandlerBase::rawPacketLen = 2; DeviceHandlerBase::rawPacket = commandBuffer.data(); return HasReturnvaluesIF::RETURN_OK; } - case(TSensorDefinitions::REQUEST_RTD): { + case(Max31865Definitions::REQUEST_RTD): { commandBuffer[0] = static_cast( - TSensorDefinitions::REQUEST_RTD); + Max31865Definitions::REQUEST_RTD); // two dummy bytes commandBuffer[1] = 0x00; commandBuffer[2] = 0x00; @@ -126,9 +127,9 @@ ReturnValue_t Max31865PT1000Handler::buildCommandFromCommand( DeviceHandlerBase::rawPacket = commandBuffer.data(); return HasReturnvaluesIF::RETURN_OK; } - case(TSensorDefinitions::REQUEST_FAULT_BYTE): { + case(Max31865Definitions::REQUEST_FAULT_BYTE): { commandBuffer[0] = static_cast( - TSensorDefinitions::REQUEST_FAULT_BYTE); + Max31865Definitions::REQUEST_FAULT_BYTE); commandBuffer[1] = 0x00; DeviceHandlerBase::rawPacketLen = 2; DeviceHandlerBase::rawPacket = commandBuffer.data(); @@ -141,11 +142,11 @@ ReturnValue_t Max31865PT1000Handler::buildCommandFromCommand( } void Max31865PT1000Handler::fillCommandAndReplyMap() { - insertInCommandAndReplyMap(TSensorDefinitions::CONFIG_CMD, 3); - insertInCommandAndReplyMap(TSensorDefinitions::REQUEST_CONFIG, 3); - insertInCommandAndReplyMap(TSensorDefinitions::REQUEST_RTD, 3, + insertInCommandAndReplyMap(Max31865Definitions::CONFIG_CMD, 3); + insertInCommandAndReplyMap(Max31865Definitions::REQUEST_CONFIG, 3); + insertInCommandAndReplyMap(Max31865Definitions::REQUEST_RTD, 3, &sensorDataset); - insertInCommandAndReplyMap(TSensorDefinitions::REQUEST_FAULT_BYTE, 3); + insertInCommandAndReplyMap(Max31865Definitions::REQUEST_FAULT_BYTE, 3); } ReturnValue_t Max31865PT1000Handler::scanForReply(const uint8_t *start, @@ -155,7 +156,7 @@ ReturnValue_t Max31865PT1000Handler::scanForReply(const uint8_t *start, if(remainingSize == rtdReplySize and internalState == InternalState::RUNNING) { - *foundId = TSensorDefinitions::REQUEST_RTD; + *foundId = Max31865Definitions::REQUEST_RTD; *foundLen = rtdReplySize; } @@ -163,15 +164,15 @@ ReturnValue_t Max31865PT1000Handler::scanForReply(const uint8_t *start, if(internalState == InternalState::CONFIGURE) { commandExecuted = true; *foundLen = configReplySize; - *foundId = TSensorDefinitions::CONFIG_CMD; + *foundId = Max31865Definitions::CONFIG_CMD; } else if(internalState == InternalState::REQUEST_FAULT_BYTE) { - *foundId = TSensorDefinitions::REQUEST_FAULT_BYTE; + *foundId = Max31865Definitions::REQUEST_FAULT_BYTE; *foundLen = 2; internalState = InternalState::RUNNING; } else { - *foundId = TSensorDefinitions::REQUEST_CONFIG; + *foundId = Max31865Definitions::REQUEST_CONFIG; *foundLen = configReplySize; } } @@ -182,7 +183,7 @@ ReturnValue_t Max31865PT1000Handler::scanForReply(const uint8_t *start, ReturnValue_t Max31865PT1000Handler::interpretDeviceReply( DeviceCommandId_t id, const uint8_t *packet) { switch(id) { - case(TSensorDefinitions::REQUEST_CONFIG): { + case(Max31865Definitions::REQUEST_CONFIG): { if(packet[1] != DEFAULT_CONFIG) { #if FSFW_CPP_OSTREAM_ENABLED == 1 // it propably would be better if we at least try one restart.. @@ -202,7 +203,7 @@ ReturnValue_t Max31865PT1000Handler::interpretDeviceReply( } break; } - case(TSensorDefinitions::REQUEST_RTD): { + case(Max31865Definitions::REQUEST_RTD): { // first bit of LSB reply byte is the fault bit uint8_t faultBit = packet[2] & 0b0000'0001; if(faultBit == 1) { @@ -272,7 +273,7 @@ ReturnValue_t Max31865PT1000Handler::interpretDeviceReply( break; } - case(TSensorDefinitions::REQUEST_FAULT_BYTE): { + case(Max31865Definitions::REQUEST_FAULT_BYTE): { faultByte = packet[1]; #if OBSW_VERBOSE_LEVEL >= 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -343,9 +344,9 @@ void Max31865PT1000Handler::doTransition(Mode_t modeFrom, ReturnValue_t Max31865PT1000Handler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, LocalDataPoolManager& poolManager) { - localDataPoolMap.emplace(TSensorDefinitions::PoolIds::TEMPERATURE_C, + localDataPoolMap.emplace(Max31865Definitions::PoolIds::TEMPERATURE_C, new PoolEntry({0}, 1, true)); - localDataPoolMap.emplace(TSensorDefinitions::PoolIds::FAULT_BYTE, + localDataPoolMap.emplace(Max31865Definitions::PoolIds::FAULT_BYTE, new PoolEntry({0})); poolManager.subscribeForPeriodicPacket(sensorDatasetSid, false, 4.0, false); diff --git a/mission/devices/Max31865PT100Handler.h b/mission/devices/Max31865PT1000Handler.h similarity index 92% rename from mission/devices/Max31865PT100Handler.h rename to mission/devices/Max31865PT1000Handler.h index 9375eee9..19780df2 100644 --- a/mission/devices/Max31865PT100Handler.h +++ b/mission/devices/Max31865PT1000Handler.h @@ -1,7 +1,6 @@ -#ifndef MISSION_DEVICES_MAX31865PT100HANDLER_H_ -#define MISSION_DEVICES_MAX31865PT100HANDLER_H_ +#ifndef MISSION_DEVICES_MAX31865PT1000HANDLER_H_ +#define MISSION_DEVICES_MAX31865PT1000HANDLER_H_ -#include "devicedefinitions/ThermalSensorPacket.h" #include #include @@ -9,6 +8,7 @@ #include #include +#include "devicedefinitions/Max31865Definitions.h" /** * @brief Device Handler for the thermal sensors @@ -92,7 +92,7 @@ private: uint8_t faultByte = 0; std::array commandBuffer { 0 }; - TSensorDefinitions::ThermalSensorDataset sensorDataset; + Max31865Definitions::Max31865Set sensorDataset; sid_t sensorDatasetSid; #if OBSW_VERBOSE_LEVEL >= 1 @@ -100,5 +100,5 @@ private: #endif }; -#endif /* MISSION_DEVICES_MAX31865PT100HANDLER_H_ */ +#endif /* MISSION_DEVICES_MAX31865PT1000HANDLER_H_ */ diff --git a/mission/devices/devicedefinitions/ThermalSensorPacket.h b/mission/devices/devicedefinitions/Max31865Definitions.h similarity index 65% rename from mission/devices/devicedefinitions/ThermalSensorPacket.h rename to mission/devices/devicedefinitions/Max31865Definitions.h index ba6f2d13..d21f41e4 100644 --- a/mission/devices/devicedefinitions/ThermalSensorPacket.h +++ b/mission/devices/devicedefinitions/Max31865Definitions.h @@ -6,15 +6,7 @@ #include #include -namespace TSensorDefinitions { - -enum ObjIds: object_id_t { - TEST_HKB_HANDLER = objects::SPI_Test_PT1000, - SYRLINKS_HANDLER = objects::PT1000_Syrlinks_DEC1_O1, - MGT_1_HANDLER = objects::PT1000_MGT1_DEC2, - PLOC_HANDLER = objects::PT1000_PLOC_DEC4, - MESHCAM_HANDLER = objects::PT1000_Camera_DEC1_O2 -}; +namespace Max31865Definitions { enum PoolIds: lp_id_t { TEMPERATURE_C, @@ -26,9 +18,11 @@ static constexpr DeviceCommandId_t REQUEST_CONFIG = 0x00; static constexpr DeviceCommandId_t REQUEST_RTD = 0x01; static constexpr DeviceCommandId_t REQUEST_FAULT_BYTE = 0x07; -static constexpr uint32_t THERMAL_SENSOR_SET_ID = REQUEST_RTD; +static constexpr uint32_t MAX31865_SET_ID = REQUEST_RTD; -class ThermalSensorDataset: +static constexpr size_t MAX_REPLY_SIZE = 5; + +class Max31865Set: public StaticLocalDataSet { public: /** @@ -36,16 +30,16 @@ public: * @param owner * @param setId */ - ThermalSensorDataset(HasLocalDataPoolIF* owner): - StaticLocalDataSet(owner, THERMAL_SENSOR_SET_ID) { + Max31865Set(HasLocalDataPoolIF* owner): + StaticLocalDataSet(owner, MAX31865_SET_ID) { } /** * Constructor used by data users like controllers. * @param sid */ - ThermalSensorDataset(object_id_t objectId): - StaticLocalDataSet(sid_t(objectId, THERMAL_SENSOR_SET_ID)) { + Max31865Set(object_id_t objectId): + StaticLocalDataSet(sid_t(objectId, MAX31865_SET_ID)) { } lp_var_t temperatureCelcius = lp_var_t(sid.objectId,