eive-obsw/bsp_te0720_1cfa/ObjectFactory.cpp

258 lines
12 KiB
C++
Raw Normal View History

#include "ObjectFactory.h"
#include "OBSWConfig.h"
#include "busConf.h"
#include "devConf.h"
2022-05-10 07:48:36 +02:00
#include "ccsdsConfig.h"
2022-04-10 18:46:39 +02:00
#include "devices/addresses.h"
#include "devices/gpioIds.h"
#include "fsfw/datapoollocal/LocalDataPoolManager.h"
#include "fsfw/tmtcpacket/pus/tm.h"
#include "fsfw/tmtcservices/CommandingServiceBase.h"
#include "fsfw/tmtcservices/PusServiceBase.h"
2022-04-10 18:46:39 +02:00
#include "fsfw_hal/linux/i2c/I2cComIF.h"
2022-03-27 12:21:09 +02:00
#include "fsfw_hal/linux/i2c/I2cCookie.h"
2022-04-10 18:46:39 +02:00
#include "fsfw_hal/linux/uart/UartComIF.h"
#include "fsfw_hal/linux/uart/UartCookie.h"
2022-05-10 07:48:36 +02:00
#include "fsfw_hal/common/gpio/GpioCookie.h"
2022-06-08 07:16:12 +02:00
#include "linux/ObjectFactory.h"
#include "linux/devices/ploc/PlocMPSoCHandler.h"
#include "linux/devices/ploc/PlocMPSoCHelper.h"
2022-05-05 08:55:45 +02:00
#include "linux/devices/ploc/PlocMemoryDumper.h"
2022-04-10 18:46:39 +02:00
#include "linux/devices/ploc/PlocSupervisorHandler.h"
#include "linux/devices/ploc/PlocSupvHelper.h"
2022-05-10 07:48:36 +02:00
#include "linux/obc/AxiPtmeConfig.h"
#include "linux/obc/PapbVcInterface.h"
#include "linux/obc/PdecHandler.h"
#include "linux/obc/Ptme.h"
#include "linux/obc/PtmeConfig.h"
#include "mission/core/GenericFactory.h"
2022-04-10 18:46:39 +02:00
#include "mission/devices/Tmp1075Handler.h"
#include "mission/tmtc/TmFunnel.h"
2022-05-10 07:48:36 +02:00
#include "mission/tmtc/CCSDSHandler.h"
#include "mission/tmtc/VirtualChannel.h"
#include "objects/systemObjectList.h"
2022-04-10 18:46:39 +02:00
#include "test/gpio/DummyGpioIF.h"
#include "tmtc/apid.h"
#include "tmtc/pusIds.h"
void Factory::setStaticFrameworkObjectIds() {
PusServiceBase::packetSource = objects::PUS_PACKET_DISTRIBUTOR;
PusServiceBase::packetDestination = objects::TM_FUNNEL;
CommandingServiceBase::defaultPacketSource = objects::PUS_PACKET_DISTRIBUTOR;
CommandingServiceBase::defaultPacketDestination = objects::TM_FUNNEL;
TmFunnel::downlinkDestination = objects::TMTC_BRIDGE;
TmFunnel::storageDestination = objects::NO_OBJECT;
VerificationReporter::messageReceiver = objects::PUS_SERVICE_1_VERIFICATION;
TmPacketBase::timeStamperId = objects::TIME_STAMPER;
}
void ObjectFactory::produce(void* args) {
Factory::setStaticFrameworkObjectIds();
ObjectFactory::produceGenericObjects();
2022-05-10 07:48:36 +02:00
LinuxLibgpioIF* gpioComIF = new LinuxLibgpioIF(objects::GPIO_IF);;
new UartComIF(objects::UART_COM_IF);
2022-04-10 18:46:39 +02:00
#if OBSW_ADD_PLOC_MPSOC == 1
2022-04-20 21:33:39 +02:00
UartCookie* mpsocUartCookie = new UartCookie(objects::PLOC_MPSOC_HANDLER, te0720_1cfa::MPSOC_UART,
uart::PLOC_MPSOC_BAUD, mpsoc::MAX_REPLY_SIZE);
2022-03-26 20:47:25 +01:00
mpsocUartCookie->setNoFixedSizeReply();
PlocMPSoCHelper* plocMpsocHelper = new PlocMPSoCHelper(objects::PLOC_MPSOC_HELPER);
2022-03-28 09:08:11 +02:00
auto dummyGpioIF = new DummyGpioIF();
2022-04-20 21:33:39 +02:00
PlocMPSoCHandler* plocMPSoCHandler = new PlocMPSoCHandler(
objects::PLOC_MPSOC_HANDLER, objects::UART_COM_IF, mpsocUartCookie, plocMpsocHelper,
Gpio(gpioIds::ENABLE_MPSOC_UART, dummyGpioIF), objects::PLOC_SUPERVISOR_HANDLER);
plocMPSoCHandler->setStartUpImmediately();
#endif /* OBSW_ADD_PLOC_MPSOC == 1 */
2022-03-26 20:47:25 +01:00
2022-04-24 12:34:08 +02:00
#if OBSW_ADD_PLOC_SUPERVISOR == 1
UartCookie* supervisorCookie =
new UartCookie(objects::PLOC_SUPERVISOR_HANDLER, std::string("/dev/ttyPS1"),
uart::PLOC_SUPV_BAUD, supv::MAX_PACKET_SIZE * 20);
supervisorCookie->setNoFixedSizeReply();
auto supvGpioIF = new DummyGpioIF();
auto supvHelper = new PlocSupvHelper(objects::PLOC_SUPERVISOR_HELPER);
new PlocSupervisorHandler(objects::PLOC_SUPERVISOR_HANDLER, objects::UART_COM_IF,
2022-04-24 12:34:08 +02:00
supervisorCookie, Gpio(gpioIds::ENABLE_SUPV_UART, supvGpioIF),
pcdu::PDU1_CH6_PLOC_12V, supvHelper);
2022-05-05 08:55:45 +02:00
2022-04-24 12:34:08 +02:00
#endif
2022-05-10 07:48:36 +02:00
new PlocMemoryDumper(objects::PLOC_MEMORY_DUMPER);
2022-03-26 20:47:25 +01:00
#if OBSW_TEST_LIBGPIOD == 1
#if OBSW_TEST_GPIO_OPEN_BYLABEL == 1
/* Configure MIO0 as input */
GpiodRegular* testGpio = new GpiodRegular("MIO0", Direction::OUT, 0, "/amba_pl/gpio@41200000", 0);
#elif OBSW_TEST_GPIO_OPEN_BY_LINE_NAME
GpiodRegularByLineName* testGpio =
new GpiodRegularByLineName("test-name", "gpio-test", Direction::OUT, 0);
#else
/* Configure MIO0 as input */
GpiodRegular* testGpio = new GpiodRegular("gpiochip0", 0, "MIO0", gpio::IN, 0);
#endif /* OBSW_TEST_GPIO_LABEL == 1 */
GpioCookie* gpioCookie = new GpioCookie;
gpioCookie->addGpio(gpioIds::TEST_ID_0, testGpio);
new LibgpiodTest(objects::LIBGPIOD_TEST, objects::GPIO_IF, gpioCookie);
#endif
#if OBSW_TEST_SUS == 1
GpioCookie* gpioCookieSus = new GpioCookie;
GpiodRegular* chipSelectSus = new GpiodRegular(
std::string("gpiochip1"), 9, std::string("Chip Select Sus Sensor"), Direction::OUT, 1);
gpioCookieSus->addGpio(gpioIds::CS_SUS_0, chipSelectSus);
gpioComIF->addGpios(gpioCookieSus);
SpiCookie* spiCookieSus =
new SpiCookie(addresses::SUS_0, std::string("/dev/spidev1.0"), SUS::MAX_CMD_SIZE,
spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED);
new SusHandler(objects::SUS_0, objects::SPI_COM_IF, spiCookieSus, gpioComIF, gpioIds::CS_SUS_0);
#endif
#if OBSW_TEST_RAD_SENSOR == 1
GpioCookie* gpioCookieRadSensor = new GpioCookie;
GpiodRegular* chipSelectRadSensor = new GpiodRegular(
std::string("gpiochip1"), 0, std::string("Chip select radiation sensor"), Direction::OUT, 1);
gpioCookieRadSensor->addGpio(gpioIds::CS_RAD_SENSOR, chipSelectRadSensor);
gpioComIF->addGpios(gpioCookieRadSensor);
SpiCookie* spiCookieRadSensor =
new SpiCookie(addresses::RAD_SENSOR, gpioIds::CS_RAD_SENSOR, std::string("/dev/spidev1.0"),
SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED);
RadiationSensorHandler* radSensor =
new RadiationSensorHandler(objects::RAD_SENSOR, objects::SPI_COM_IF, spiCookieRadSensor);
radSensor->setStartUpImmediately();
#endif
#if OBSW_TEST_TE7020_HEATER == 1
/* Configuration for MIO0 on TE0720-03-1CFA */
GpiodRegular* heaterGpio =
new GpiodRegular(std::string("gpiochip0"), 0, std::string("MIO0"), gpio::IN, 0);
GpioCookie* gpioCookie = new GpioCookie;
gpioCookie->addGpio(gpioIds::HEATER_0, heaterGpio);
new HeaterHandler(objects::HEATER_HANDLER, objects::GPIO_IF, gpioCookie, objects::PCDU_HANDLER,
2022-04-21 16:30:23 +02:00
pcdu::TCS_BOARD_8V_HEATER_IN);
2022-03-26 20:47:25 +01:00
#endif
2022-04-10 18:46:39 +02:00
new I2cComIF(objects::I2C_COM_IF);
2022-03-27 12:32:05 +02:00
2022-04-10 18:46:39 +02:00
I2cCookie* i2cCookieTmp1075tcs1 =
new I2cCookie(addresses::TMP1075_TCS_1, TMP1075::MAX_REPLY_LENGTH, std::string("/dev/i2c-0"));
I2cCookie* i2cCookieTmp1075tcs2 =
new I2cCookie(addresses::TMP1075_TCS_2, TMP1075::MAX_REPLY_LENGTH, std::string("/dev/i2c-0"));
2022-03-27 10:56:40 +02:00
2022-04-10 18:46:39 +02:00
/* Temperature sensors */
new Tmp1075Handler(objects::TMP1075_HANDLER_1, objects::I2C_COM_IF, i2cCookieTmp1075tcs1);
new Tmp1075Handler(objects::TMP1075_HANDLER_2, objects::I2C_COM_IF, i2cCookieTmp1075tcs2);
2022-06-08 07:16:12 +02:00
#if OBSW_USE_CCSDS_IP_CORE == 1
createCcsdsComponents(gpioComIF);
#endif /* OBSW_USE_CCSDS_IP_CORE == 1 */
static_cast<void>(gpioComIF);
}
2022-05-10 07:48:36 +02:00
void ObjectFactory::createCcsdsComponents(LinuxLibgpioIF* gpioComIF) {
using namespace gpio;
// GPIO definitions of signals connected to the virtual channel interfaces of the PTME IP Core
GpioCookie* gpioCookiePtmeIp = new GpioCookie;
GpiodRegularByLineName* gpio = nullptr;
std::stringstream consumer;
consumer.str("PAPB VC0");
gpio = new GpiodRegularByLineName(te0720_1cfa::gpioNames::PAPB_BUSY_SIGNAL_VC0, consumer.str());
gpioCookiePtmeIp->addGpio(gpioIds::VC0_PAPB_BUSY, gpio);
consumer.str("PAPB VC0");
gpio = new GpiodRegularByLineName(te0720_1cfa::gpioNames::PAPB_EMPTY_SIGNAL_VC0, consumer.str());
gpioCookiePtmeIp->addGpio(gpioIds::VC0_PAPB_EMPTY, gpio);
consumer.str("PAPB VC 1");
gpio = new GpiodRegularByLineName(te0720_1cfa::gpioNames::PAPB_BUSY_SIGNAL_VC1, consumer.str());
gpioCookiePtmeIp->addGpio(gpioIds::VC1_PAPB_BUSY, gpio);
consumer.str("");
consumer.str("PAPB VC 1");
gpioCookiePtmeIp->addGpio(gpioIds::VC1_PAPB_EMPTY, gpio);
consumer.str("");
consumer.str("PAPB VC 2");
gpio = new GpiodRegularByLineName(te0720_1cfa::gpioNames::PAPB_BUSY_SIGNAL_VC2, consumer.str());
gpioCookiePtmeIp->addGpio(gpioIds::VC2_PAPB_BUSY, gpio);
consumer.str("");
consumer.str("PAPB VC 2");
gpio = new GpiodRegularByLineName(te0720_1cfa::gpioNames::PAPB_EMPTY_SIGNAL_VC2, consumer.str());
gpioCookiePtmeIp->addGpio(gpioIds::VC2_PAPB_EMPTY, gpio);
consumer.str("");
consumer.str("PAPB VC 3");
gpio = new GpiodRegularByLineName(te0720_1cfa::gpioNames::PAPB_BUSY_SIGNAL_VC3, consumer.str());
gpioCookiePtmeIp->addGpio(gpioIds::VC3_PAPB_BUSY, gpio);
consumer.str("");
consumer.str("PAPB VC 3");
gpio = new GpiodRegularByLineName(te0720_1cfa::gpioNames::PAPB_EMPTY_SIGNAL_VC3, consumer.str());
gpioCookiePtmeIp->addGpio(gpioIds::VC3_PAPB_EMPTY, gpio);
2022-06-08 07:16:12 +02:00
gpioChecker(gpioComIF->addGpios(gpioCookiePtmeIp), "PTME PAPB VCs");
2022-05-10 07:48:36 +02:00
// Creating virtual channel interfaces
VcInterfaceIF* vc0 =
new PapbVcInterface(gpioComIF, gpioIds::VC0_PAPB_BUSY, gpioIds::VC0_PAPB_EMPTY, te0720_1cfa::UIO_PTME,
2022-06-08 07:16:12 +02:00
te0720_1cfa::uiomapids::PTME_VC0);
2022-05-10 07:48:36 +02:00
VcInterfaceIF* vc1 =
new PapbVcInterface(gpioComIF, gpioIds::VC1_PAPB_BUSY, gpioIds::VC1_PAPB_EMPTY, te0720_1cfa::UIO_PTME,
2022-06-08 07:16:12 +02:00
te0720_1cfa::uiomapids::PTME_VC1);
2022-05-10 07:48:36 +02:00
VcInterfaceIF* vc2 =
new PapbVcInterface(gpioComIF, gpioIds::VC2_PAPB_BUSY, gpioIds::VC2_PAPB_EMPTY, te0720_1cfa::UIO_PTME,
2022-06-08 07:16:12 +02:00
te0720_1cfa::uiomapids::PTME_VC2);
2022-05-10 07:48:36 +02:00
VcInterfaceIF* vc3 =
new PapbVcInterface(gpioComIF, gpioIds::VC3_PAPB_BUSY, gpioIds::VC3_PAPB_EMPTY, te0720_1cfa::UIO_PTME,
2022-06-08 07:16:12 +02:00
te0720_1cfa::uiomapids::PTME_VC3);
2022-05-10 07:48:36 +02:00
// Creating ptme object and adding virtual channel interfaces
Ptme* ptme = new Ptme(objects::PTME);
ptme->addVcInterface(ccsds::VC0, vc0);
ptme->addVcInterface(ccsds::VC1, vc1);
ptme->addVcInterface(ccsds::VC2, vc2);
ptme->addVcInterface(ccsds::VC3, vc3);
2022-06-08 07:16:12 +02:00
AxiPtmeConfig* axiPtmeConfig =
new AxiPtmeConfig(objects::AXI_PTME_CONFIG, te0720_1cfa::UIO_PTME, te0720_1cfa::uiomapids::PTME_CONFIG);
2022-05-10 07:48:36 +02:00
PtmeConfig* ptmeConfig = new PtmeConfig(objects::PTME_CONFIG, axiPtmeConfig);
2022-06-08 07:16:12 +02:00
#if OBSW_ENABLE_SYRLINKS_TRANSMIT_TIMEOUT == 1
// Set to high value when not sending via syrlinks
static const uint32_t TRANSMITTER_TIMEOUT = 86400000; // 1 day
#else
static const uint32_t TRANSMITTER_TIMEOUT = 900000; // 15 minutes
#endif
// The DummyGpioIF is used here because there are no RS485 chips on the TE7020-1CFA
auto dummyGpioIF = new DummyGpioIF();
2022-05-10 07:48:36 +02:00
CCSDSHandler* ccsdsHandler = new CCSDSHandler(
objects::CCSDS_HANDLER, objects::PTME, objects::CCSDS_PACKET_DISTRIBUTOR, ptmeConfig,
2022-06-08 07:16:12 +02:00
dummyGpioIF, gpioIds::RS485_EN_TX_CLOCK, gpioIds::RS485_EN_TX_DATA, TRANSMITTER_TIMEOUT);
2022-05-10 07:48:36 +02:00
VirtualChannel* vc = nullptr;
vc = new VirtualChannel(ccsds::VC0, common::VC0_QUEUE_SIZE, objects::CCSDS_HANDLER);
ccsdsHandler->addVirtualChannel(ccsds::VC0, vc);
vc = new VirtualChannel(ccsds::VC1, common::VC1_QUEUE_SIZE, objects::CCSDS_HANDLER);
ccsdsHandler->addVirtualChannel(ccsds::VC1, vc);
vc = new VirtualChannel(ccsds::VC2, common::VC2_QUEUE_SIZE, objects::CCSDS_HANDLER);
ccsdsHandler->addVirtualChannel(ccsds::VC2, vc);
vc = new VirtualChannel(ccsds::VC3, common::VC3_QUEUE_SIZE, objects::CCSDS_HANDLER);
ccsdsHandler->addVirtualChannel(ccsds::VC3, vc);
GpioCookie* gpioCookiePdec = new GpioCookie;
consumer.str("");
consumer << "0x" << std::hex << objects::PDEC_HANDLER;
// GPIO also low after linux boot (specified by device-tree)
2022-06-08 07:16:12 +02:00
gpio = new GpiodRegularByLineName(te0720_1cfa::gpioNames::PDEC_RESET, consumer.str(),
Direction::OUT, Levels::LOW);
2022-05-10 07:48:36 +02:00
gpioCookiePdec->addGpio(gpioIds::PDEC_RESET, gpio);
2022-06-08 07:16:12 +02:00
gpioChecker(gpioComIF->addGpios(gpioCookiePdec), "PDEC");
2022-05-10 07:48:36 +02:00
new PdecHandler(objects::PDEC_HANDLER, objects::CCSDS_HANDLER, gpioComIF, gpioIds::PDEC_RESET,
te0720_1cfa::UIO_PDEC_CONFIG_MEMORY, te0720_1cfa::UIO_PDEC_RAM,
te0720_1cfa::UIO_PDEC_REGISTERS);
}