92 lines
2.8 KiB
C++
92 lines
2.8 KiB
C++
#include "SpiTestClass.h"
|
|
|
|
#include <fsfwconfig/devices/gpioIds.h>
|
|
#include <fsfw/serviceinterface/ServiceInterface.h>
|
|
|
|
#include <linux/spi/spidev.h>
|
|
#include <fcntl.h>
|
|
#include <linux/gpio/gpioDefinitions.h>
|
|
#include <linux/gpio/GpioCookie.h>
|
|
#include <unistd.h>
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
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() {
|
|
/* Adapt accordingly */
|
|
uint8_t chipSelectPin = mgm1Rm3100ChipSelect;
|
|
acsInit();
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|