#include "SpiTestClass.h" #include #include #include #include #include #include #include #include #include SpiTestClass::SpiTestClass(object_id_t objectId, GpioIF* gpioIF): TestTask(objectId), gpioIF(gpioIF) { if(gpioIF == nullptr) { sif::error << "SpiTestClass::SpiTestClass: Invalid GPIO ComIF!" << std::endl; } testMode = TestModes::MGM_RM3100; spiTransferStruct.rx_buf = reinterpret_cast<__u64>(recvBuffer.data()); spiTransferStruct.tx_buf = reinterpret_cast<__u64>(sendBuffer.data()); } ReturnValue_t SpiTestClass::performOneShotAction() { switch(testMode) { case(TestModes::MGM_LIS3MDL): { break; } case(TestModes::MGM_RM3100): { performRm3100Test(); break; } case(TestModes::GYRO_L3GD20H): { break; } } return HasReturnvaluesIF::RETURN_OK; } ReturnValue_t SpiTestClass::performPeriodicAction() { return HasReturnvaluesIF::RETURN_OK; } void SpiTestClass::performRm3100Test() { /* Configure all SPI chip selects and pull them high */ acsInit(); /* Adapt accordingly */ uint8_t chipSelectPin = mgm1Rm3100ChipSelect; uint32_t rm3100Speed = 3'900'000; uint8_t rm3100whoAmIReg = 0b0000'1111; int rm3100mode = SPI_MODE_3; #ifdef RASPBERRY_PI std::string deviceName = "spidev0.0"; #else #endif int fileDescriptor = 0; utility::UnixFileHelper fileHelper(deviceName, &fileDescriptor, O_RDWR, "SpiComIF::initializeInterface: "); if(fileHelper.getOpenResult()) { sif::error << "SpiTestClass::performRm3100Test: File descriptor could not be opened!" << std::endl; return; } int retval = ioctl(fileDescriptor, SPI_IOC_WR_MODE, rm3100mode); if(retval != 0) { utility::handleIoctlError("SpiTestClass::performRm3100Test: Setting SPI mode failed!"); } retval = ioctl(fileDescriptor, SPI_IOC_WR_MAX_SPEED_HZ, rm3100Speed); if(retval != 0) { utility::handleIoctlError("SpiTestClass::performRm3100Test: Setting SPI speed failed!"); } } void SpiTestClass::acsInit() { GpioCookie* gpioCookie = new GpioCookie(); std::string rpiGpioName = "gpiochip0"; { GpiodRegular gpio(rpiGpioName.c_str(), mgm0Lis3ChipSelect, "MGM_0_LIS3", gpio::Direction::OUT, 1); gpioCookie->addGpio(gpioIds::MGM_0_LIS3_CS, gpio); } { GpiodRegular gpio(rpiGpioName.c_str(), mgm1Rm3100ChipSelect, "MGM_1_RM3100", gpio::Direction::OUT, 1); gpioCookie->addGpio(gpioIds::MGM_1_RM3100_CS, gpio); } { GpiodRegular gpio(rpiGpioName.c_str(), gyro0AdisChipSelect, "GYRO_0_ADIS", gpio::Direction::OUT, 1); gpioCookie->addGpio(gpioIds::GYRO_0_ADIS_CS, gpio); } { GpiodRegular gpio(rpiGpioName.c_str(), gyro1L3gd20ChipSelect, "GYRO_1_L3G", gpio::Direction::OUT, 1); gpioCookie->addGpio(gpioIds::GYRO_1_L3G_CS, gpio); } { GpiodRegular gpio(rpiGpioName.c_str(), gyro2L3gd20ChipSelect, "GYRO_2_L3G", gpio::Direction::OUT, 1); gpioCookie->addGpio(gpioIds::GYRO_2_L3G_CS, gpio); } { GpiodRegular gpio(rpiGpioName.c_str(), mgm2Lis3mdlChipSelect, "MGM_2_LIS3", gpio::Direction::OUT, 1); gpioCookie->addGpio(gpioIds::MGM_2_LIS3_CS, gpio); } { GpiodRegular gpio(rpiGpioName.c_str(), mgm3Rm3100ChipSelect, "MGM_3_RM3100", gpio::Direction::OUT, 1); gpioCookie->addGpio(gpioIds::MGM_3_RM3100_CS, gpio); } if(gpioIF != nullptr) { gpioIF->addGpios(gpioCookie); } }