moved some files
This commit is contained in:
10
linux/boardtest/CMakeLists.txt
Normal file
10
linux/boardtest/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
LibgpiodTest.cpp
|
||||
I2cTestClass.cpp
|
||||
SpiTestClass.cpp
|
||||
UartTestClass.cpp
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
8
linux/boardtest/I2cTestClass.cpp
Normal file
8
linux/boardtest/I2cTestClass.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
#include <linux/boardtest/I2cTestClass.h>
|
||||
|
||||
I2cTestClass::I2cTestClass(object_id_t objectId): TestTask(objectId) {
|
||||
}
|
||||
|
||||
ReturnValue_t I2cTestClass::performPeriodicAction() {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
17
linux/boardtest/I2cTestClass.h
Normal file
17
linux/boardtest/I2cTestClass.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef LINUX_BOARDTEST_I2CTESTCLASS_H_
|
||||
#define LINUX_BOARDTEST_I2CTESTCLASS_H_
|
||||
|
||||
#include <test/testtasks/TestTask.h>
|
||||
|
||||
class I2cTestClass: public TestTask {
|
||||
public:
|
||||
I2cTestClass(object_id_t objectId);
|
||||
|
||||
ReturnValue_t performPeriodicAction() override;
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* LINUX_BOARDTEST_I2CTESTCLASS_H_ */
|
99
linux/boardtest/LibgpiodTest.cpp
Normal file
99
linux/boardtest/LibgpiodTest.cpp
Normal file
@ -0,0 +1,99 @@
|
||||
#include "LibgpiodTest.h"
|
||||
|
||||
#include <fsfwconfig/devices/gpioIds.h>
|
||||
#include <fsfw/serviceinterface/ServiceInterfaceStream.h>
|
||||
#include <fsfw/objectmanager/ObjectManagerIF.h>
|
||||
#include <fsfw/tasks/TaskFactory.h>
|
||||
|
||||
LibgpiodTest::LibgpiodTest(object_id_t objectId, object_id_t gpioIfobjectId,
|
||||
GpioCookie* gpioCookie):
|
||||
TestTask(objectId) {
|
||||
|
||||
gpioInterface = objectManager->get<GpioIF>(gpioIfobjectId);
|
||||
if (gpioInterface == nullptr) {
|
||||
sif::error << "LibgpiodTest::LibgpiodTest: Invalid Gpio interface." << std::endl;
|
||||
}
|
||||
gpioInterface->addGpios(gpioCookie);
|
||||
testCase = TestCases::LOOPBACK;
|
||||
}
|
||||
|
||||
LibgpiodTest::~LibgpiodTest() {
|
||||
}
|
||||
|
||||
ReturnValue_t LibgpiodTest::performPeriodicAction() {
|
||||
int gpioState;
|
||||
ReturnValue_t result;
|
||||
|
||||
switch(testCase) {
|
||||
case(TestCases::READ): {
|
||||
result = gpioInterface->readGpio(gpioIds::TEST_ID_0, &gpioState);
|
||||
if (result != RETURN_OK) {
|
||||
sif::debug << "LibgpiodTest::performPeriodicAction: Failed to read gpio "
|
||||
<< std::endl;
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
else {
|
||||
sif::debug << "LibgpiodTest::performPeriodicAction: MIO 0 state = " << gpioState
|
||||
<< std::endl;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case(TestCases::LOOPBACK): {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t LibgpiodTest::performOneShotAction() {
|
||||
int gpioState;
|
||||
ReturnValue_t result;
|
||||
|
||||
switch(testCase) {
|
||||
case(TestCases::READ): {
|
||||
break;
|
||||
}
|
||||
case(TestCases::LOOPBACK): {
|
||||
result = gpioInterface->pullHigh(gpioIds::TEST_ID_0);
|
||||
if(result == HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::info << "LibgpiodTest::performOneShotAction: "
|
||||
"GPIO pulled high successfully for loopback test" << std::endl;
|
||||
}
|
||||
else {
|
||||
sif::warning << "LibgpiodTest::performOneShotAction: Could not pull GPIO high!"
|
||||
<< std::endl;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
result = gpioInterface->readGpio(gpioIds::TEST_ID_1, &gpioState);
|
||||
if(result == HasReturnvaluesIF::RETURN_OK and gpioState == 1) {
|
||||
sif::info << "LibgpiodTest::performOneShotAction: "
|
||||
"GPIO state read successfully and is high" << std::endl;
|
||||
}
|
||||
else {
|
||||
sif::warning << "LibgpiodTest::performOneShotAction: GPIO read and is not high!"
|
||||
<< std::endl;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
result = gpioInterface->pullLow(gpioIds::TEST_ID_0);
|
||||
if(result == HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::info << "LibgpiodTest::performOneShotAction: "
|
||||
"GPIO pulled low successfully for loopback test" << std::endl;
|
||||
}
|
||||
result = gpioInterface->readGpio(gpioIds::TEST_ID_1, &gpioState);
|
||||
if(result == HasReturnvaluesIF::RETURN_OK and gpioState == 0) {
|
||||
sif::info << "LibgpiodTest::performOneShotAction: "
|
||||
"GPIO state read successfully and is low" << std::endl;
|
||||
}
|
||||
else {
|
||||
sif::warning << "LibgpiodTest::performOneShotAction: GPIO read and is not low!"
|
||||
<< std::endl;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
33
linux/boardtest/LibgpiodTest.h
Normal file
33
linux/boardtest/LibgpiodTest.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef TEST_TESTTASKS_LIBGPIODTEST_H_
|
||||
#define TEST_TESTTASKS_LIBGPIODTEST_H_
|
||||
|
||||
#include "TestTask.h"
|
||||
#include <linux/gpio/GpioIF.h>
|
||||
#include <linux/gpio/GpioCookie.h>
|
||||
#include <fsfw/objectmanager/SystemObject.h>
|
||||
|
||||
/**
|
||||
* @brief Test for the GPIO read implementation of the LinuxLibgpioIF.
|
||||
* @author J. Meier
|
||||
*/
|
||||
class LibgpiodTest: public TestTask {
|
||||
public:
|
||||
enum TestCases {
|
||||
READ = 0,
|
||||
LOOPBACK = 1
|
||||
};
|
||||
|
||||
TestCases testCase;
|
||||
|
||||
LibgpiodTest(object_id_t objectId, object_id_t gpioIfobjectId, GpioCookie* gpioCookie);
|
||||
virtual ~LibgpiodTest();
|
||||
|
||||
protected:
|
||||
ReturnValue_t performOneShotAction() override;
|
||||
ReturnValue_t performPeriodicAction() override;
|
||||
|
||||
private:
|
||||
GpioIF* gpioInterface;
|
||||
};
|
||||
|
||||
#endif /* TEST_TESTTASKS_LIBGPIODTEST_H_ */
|
231
linux/boardtest/SpiTestClass.cpp
Normal file
231
linux/boardtest/SpiTestClass.cpp
Normal file
@ -0,0 +1,231 @@
|
||||
#include "SpiTestClass.h"
|
||||
|
||||
#include <fsfwconfig/devices/gpioIds.h>
|
||||
#include <fsfw/serviceinterface/ServiceInterface.h>
|
||||
|
||||
#include <linux/spi/spidev.h>
|
||||
#include <fcntl.h>
|
||||
#include <fsfw/timemanager/Stopwatch.h>
|
||||
#include <linux/gpio/gpioDefinitions.h>
|
||||
#include <linux/gpio/GpioCookie.h>
|
||||
#include <linux/utility/Utility.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <bitset>
|
||||
|
||||
|
||||
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_LIS3MDL;
|
||||
spiTransferStruct.rx_buf = reinterpret_cast<__u64>(recvBuffer.data());
|
||||
spiTransferStruct.tx_buf = reinterpret_cast<__u64>(sendBuffer.data());
|
||||
}
|
||||
|
||||
ReturnValue_t SpiTestClass::performOneShotAction() {
|
||||
switch(testMode) {
|
||||
case(TestModes::NONE): {
|
||||
break;
|
||||
}
|
||||
case(TestModes::MGM_LIS3MDL): {
|
||||
performLis3MdlTest(mgm0Lis3ChipSelect);
|
||||
break;
|
||||
}
|
||||
case(TestModes::MGM_RM3100): {
|
||||
performRm3100Test(mgm1Rm3100ChipSelect);
|
||||
break;
|
||||
}
|
||||
case(TestModes::GYRO_L3GD20H): {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t SpiTestClass::performPeriodicAction() {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void SpiTestClass::performRm3100Test(uint8_t mgmId) {
|
||||
/* Configure all SPI chip selects and pull them high */
|
||||
acsInit();
|
||||
|
||||
/* Adapt accordingly */
|
||||
if(mgmId != mgm1Rm3100ChipSelect and mgmId != mgm3Rm3100ChipSelect) {
|
||||
sif::warning << "SpiTestClass::performRm3100Test: Invalid MGM ID!" << std::endl;
|
||||
}
|
||||
gpioId_t currentGpioId = 0;
|
||||
uint8_t chipSelectPin = mgmId;
|
||||
if(chipSelectPin == mgm1Rm3100ChipSelect) {
|
||||
currentGpioId = gpioIds::MGM_1_RM3100_CS;
|
||||
}
|
||||
else {
|
||||
currentGpioId = gpioIds::MGM_3_RM3100_CS;
|
||||
}
|
||||
uint32_t rm3100speed = 3'900'000;
|
||||
uint8_t rm3100revidReg = 0x36;
|
||||
spi::SpiMode rm3100mode = spi::SpiMode::MODE_3;
|
||||
//spiTransferStruct.speed_hz = rm3100Speed;
|
||||
#ifdef RASPBERRY_PI
|
||||
std::string deviceName = "/dev/spidev0.0";
|
||||
#else
|
||||
std::string deviceName = "placeholder";
|
||||
#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;
|
||||
}
|
||||
setSpiSpeedAndMode(fileDescriptor, rm3100mode, rm3100speed);
|
||||
|
||||
uint8_t revId = readStmRegister(fileDescriptor, currentGpioId, rm3100revidReg, false);
|
||||
sif::info << "SpiTestClass::performRm3100Test: Revision ID 0b" << std::bitset<8>(revId) <<
|
||||
std::endl;
|
||||
}
|
||||
|
||||
void SpiTestClass::performLis3MdlTest(uint8_t lis3Id) {
|
||||
/* Configure all SPI chip selects and pull them high */
|
||||
acsInit();
|
||||
|
||||
/* Adapt accordingly */
|
||||
if(lis3Id != mgm0Lis3ChipSelect and lis3Id != mgm2Lis3mdlChipSelect) {
|
||||
sif::warning << "SpiTestClass::performLis3MdlTest: Invalid MGM ID!" << std::endl;
|
||||
}
|
||||
gpioId_t currentGpioId = 0;
|
||||
uint8_t chipSelectPin = lis3Id;
|
||||
uint8_t whoAmIReg = 0b0000'1111;
|
||||
if(chipSelectPin == mgm0Lis3ChipSelect) {
|
||||
currentGpioId = gpioIds::MGM_0_LIS3_CS;
|
||||
}
|
||||
else {
|
||||
currentGpioId = gpioIds::MGM_2_LIS3_CS;
|
||||
}
|
||||
uint32_t spiSpeed = 3'900'000;
|
||||
spi::SpiMode spiMode = spi::SpiMode::MODE_3;
|
||||
#ifdef RASPBERRY_PI
|
||||
std::string deviceName = "/dev/spidev0.0";
|
||||
#else
|
||||
std::string deviceName = "placeholder";
|
||||
#endif
|
||||
int fileDescriptor = 0;
|
||||
|
||||
utility::UnixFileHelper fileHelper(deviceName, &fileDescriptor, O_RDWR,
|
||||
"SpiComIF::initializeInterface: ");
|
||||
if(fileHelper.getOpenResult()) {
|
||||
sif::error << "SpiTestClass::performLis3Mdl3100Test: File descriptor could not be opened!"
|
||||
<< std::endl;
|
||||
return;
|
||||
}
|
||||
setSpiSpeedAndMode(fileDescriptor, spiMode, spiSpeed);
|
||||
|
||||
uint8_t whoAmIRegVal = readStmRegister(fileDescriptor, currentGpioId, whoAmIReg, false);
|
||||
sif::info << "SpiTestClass::performLis3MdlTest: WHO AM I Regiter 0b" <<
|
||||
std::bitset<8>(whoAmIRegVal) << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void SpiTestClass::acsInit() {
|
||||
GpioCookie* gpioCookie = new GpioCookie();
|
||||
std::string rpiGpioName = "gpiochip0";
|
||||
{
|
||||
GpiodRegular gpio(rpiGpioName, mgm0Lis3ChipSelect, "MGM_0_LIS3",
|
||||
gpio::Direction::OUT, 1);
|
||||
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);
|
||||
}
|
||||
{
|
||||
GpiodRegular gpio(rpiGpioName, gyro0AdisChipSelect, "GYRO_0_ADIS",
|
||||
gpio::Direction::OUT, 1);
|
||||
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);
|
||||
}
|
||||
{
|
||||
GpiodRegular gpio(rpiGpioName, gyro2L3gd20ChipSelect, "GYRO_2_L3G",
|
||||
gpio::Direction::OUT, 1);
|
||||
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);
|
||||
}
|
||||
{
|
||||
GpiodRegular gpio(rpiGpioName, mgm3Rm3100ChipSelect, "MGM_3_RM3100",
|
||||
gpio::Direction::OUT, 1);
|
||||
gpioCookie->addGpio(gpioIds::MGM_3_RM3100_CS, gpio);
|
||||
}
|
||||
if(gpioIF != nullptr) {
|
||||
gpioIF->addGpios(gpioCookie);
|
||||
}
|
||||
}
|
||||
|
||||
void SpiTestClass::writeStmRegister(int fd, gpioId_t chipSelect, uint8_t reg, uint8_t value,
|
||||
bool autoIncrement) {
|
||||
if(autoIncrement) {
|
||||
reg |= STM_AUTO_INCR_MASK;
|
||||
}
|
||||
spiTransferStruct.len = 2;
|
||||
sendBuffer[0] = reg;
|
||||
sendBuffer[1] = value;
|
||||
|
||||
if(gpioIF != nullptr and chipSelect != gpio::NO_GPIO) {
|
||||
gpioIF->pullLow(chipSelect);
|
||||
}
|
||||
int retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
||||
if(retval != 0) {
|
||||
utility::handleIoctlError("SpiTestClass::writeStmRegister: Write failed");
|
||||
}
|
||||
if(gpioIF != nullptr and chipSelect != gpio::NO_GPIO) {
|
||||
gpioIF->pullHigh(chipSelect);
|
||||
}
|
||||
}
|
||||
|
||||
void SpiTestClass::setSpiSpeedAndMode(int spiFd, spi::SpiMode mode, uint32_t speed) {
|
||||
int retval = ioctl(spiFd, SPI_IOC_WR_MODE, reinterpret_cast<uint8_t*>(&mode));
|
||||
if(retval != 0) {
|
||||
utility::handleIoctlError("SpiTestClass::performRm3100Test: Setting SPI mode failed!");
|
||||
}
|
||||
|
||||
retval = ioctl(spiFd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
|
||||
if(retval != 0) {
|
||||
utility::handleIoctlError("SpiTestClass::performRm3100Test: Setting SPI speed failed!");
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t SpiTestClass::readStmRegister(int fd, gpioId_t chipSelect, uint8_t reg,
|
||||
bool autoIncrement) {
|
||||
reg |= STM_READ_MASK;
|
||||
if(autoIncrement) {
|
||||
reg |= STM_AUTO_INCR_MASK;
|
||||
}
|
||||
spiTransferStruct.len = 2;
|
||||
sendBuffer[0] = reg;
|
||||
sendBuffer[1] = 0;
|
||||
|
||||
if(gpioIF != nullptr and chipSelect != gpio::NO_GPIO) {
|
||||
gpioIF->pullLow(chipSelect);
|
||||
}
|
||||
int retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
||||
if(retval < 0) {
|
||||
utility::handleIoctlError("SpiTestClass::readStmRegiste: Read failed");
|
||||
}
|
||||
if(gpioIF != nullptr and chipSelect != gpio::NO_GPIO) {
|
||||
gpioIF->pullHigh(chipSelect);
|
||||
}
|
||||
return recvBuffer[1];
|
||||
}
|
61
linux/boardtest/SpiTestClass.h
Normal file
61
linux/boardtest/SpiTestClass.h
Normal file
@ -0,0 +1,61 @@
|
||||
#ifndef LINUX_BOARDTEST_SPITESTCLASS_H_
|
||||
#define LINUX_BOARDTEST_SPITESTCLASS_H_
|
||||
|
||||
#include <linux/gpio/GpioIF.h>
|
||||
#include <linux/spi/SpiCookie.h>
|
||||
#include <test/testtasks/TestTask.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
class SpiTestClass: public TestTask {
|
||||
public:
|
||||
enum TestModes {
|
||||
NONE,
|
||||
MGM_LIS3MDL,
|
||||
MGM_RM3100,
|
||||
GYRO_L3GD20H,
|
||||
};
|
||||
|
||||
TestModes testMode;
|
||||
|
||||
SpiTestClass(object_id_t objectId, GpioIF* gpioIF);
|
||||
|
||||
ReturnValue_t performOneShotAction() override;
|
||||
ReturnValue_t performPeriodicAction() override;
|
||||
private:
|
||||
|
||||
GpioIF* gpioIF;
|
||||
|
||||
std::array<uint8_t, 128> recvBuffer;
|
||||
std::array<uint8_t, 128> sendBuffer;
|
||||
struct spi_ioc_transfer spiTransferStruct;
|
||||
|
||||
void performRm3100Test(uint8_t mgmId);
|
||||
void performLis3MdlTest(uint8_t lis3Id);
|
||||
|
||||
/* ACS board specific code which pulls all GPIOs high */
|
||||
void acsInit();
|
||||
|
||||
/* ACS board specific variables */
|
||||
uint8_t mgm0Lis3ChipSelect = 0;
|
||||
uint8_t mgm1Rm3100ChipSelect = 1;
|
||||
uint8_t gyro0AdisChipSelect = 5;
|
||||
uint8_t gyro1L3gd20ChipSelect = 6;
|
||||
uint8_t gyro2L3gd20ChipSelect = 4;
|
||||
uint8_t mgm2Lis3mdlChipSelect = 17;
|
||||
uint8_t mgm3Rm3100ChipSelect = 27;
|
||||
|
||||
static constexpr uint8_t STM_READ_MASK = 0b1000'0000;
|
||||
static constexpr uint8_t STM_AUTO_INCR_MASK = 0b0100'0000;
|
||||
|
||||
void setSpiSpeedAndMode(int spiFd, spi::SpiMode mode, uint32_t speed);
|
||||
void writeStmRegister(int fd, gpioId_t chipSelect, uint8_t reg, uint8_t value,
|
||||
bool autoIncrement);
|
||||
uint8_t readStmRegister(int fd, gpioId_t chipSelect, uint8_t reg, bool autoIncrement);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* LINUX_BOARDTEST_SPITESTCLASS_H_ */
|
8
linux/boardtest/UartTestClass.cpp
Normal file
8
linux/boardtest/UartTestClass.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
#include <linux/boardtest/UartTestClass.h>
|
||||
|
||||
UartTestClass::UartTestClass(object_id_t objectId): TestTask(objectId) {
|
||||
}
|
||||
|
||||
ReturnValue_t UartTestClass::performPeriodicAction() {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
15
linux/boardtest/UartTestClass.h
Normal file
15
linux/boardtest/UartTestClass.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef LINUX_BOARDTEST_UARTTESTCLASS_H_
|
||||
#define LINUX_BOARDTEST_UARTTESTCLASS_H_
|
||||
|
||||
#include <test/testtasks/TestTask.h>
|
||||
|
||||
class UartTestClass: public TestTask {
|
||||
public:
|
||||
UartTestClass(object_id_t objectId);
|
||||
|
||||
ReturnValue_t performPeriodicAction() override;
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif /* LINUX_BOARDTEST_UARTTESTCLASS_H_ */
|
Reference in New Issue
Block a user