lis 3 basic test code
This commit is contained in:
parent
93aafb4344
commit
6b982ce5cd
2
fsfw
2
fsfw
@ -1 +1 @@
|
||||
Subproject commit f3cc664d4f9fdadc2f6e2ebf814dd0c924e5ae33
|
||||
Subproject commit 92f249dc62cf02a5052fee4e9877bc89b2be1ab5
|
@ -101,12 +101,14 @@ ReturnValue_t pst::pollingSequenceAcsTest(FixedTimeslotTaskIF *thisSequence) {
|
||||
|
||||
thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0,
|
||||
DeviceHandlerIF::PERFORM_OPERATION);
|
||||
thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.25,
|
||||
DeviceHandlerIF::PERFORM_OPERATION);
|
||||
thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.5,
|
||||
DeviceHandlerIF::PERFORM_OPERATION);
|
||||
thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.75,
|
||||
DeviceHandlerIF::PERFORM_OPERATION);
|
||||
thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.2,
|
||||
DeviceHandlerIF::SEND_WRITE);
|
||||
thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.4,
|
||||
DeviceHandlerIF::GET_WRITE);
|
||||
thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.6,
|
||||
DeviceHandlerIF::SEND_READ);
|
||||
thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.8,
|
||||
DeviceHandlerIF::GET_READ);
|
||||
if (thisSequence->checkSequence() != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "Initialization of ACS Board PST failed" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
|
@ -19,7 +19,7 @@ SpiTestClass::SpiTestClass(object_id_t objectId, GpioIF* gpioIF): TestTask(objec
|
||||
if(gpioIF == nullptr) {
|
||||
sif::error << "SpiTestClass::SpiTestClass: Invalid GPIO ComIF!" << std::endl;
|
||||
}
|
||||
testMode = TestModes::NONE;
|
||||
testMode = TestModes::MGM_LIS3MDL;
|
||||
spiTransferStruct.rx_buf = reinterpret_cast<__u64>(recvBuffer.data());
|
||||
spiTransferStruct.tx_buf = reinterpret_cast<__u64>(sendBuffer.data());
|
||||
}
|
||||
@ -30,6 +30,7 @@ ReturnValue_t SpiTestClass::performOneShotAction() {
|
||||
break;
|
||||
}
|
||||
case(TestModes::MGM_LIS3MDL): {
|
||||
performLis3MdlTest(mgm0Lis3ChipSelect);
|
||||
break;
|
||||
}
|
||||
case(TestModes::MGM_RM3100): {
|
||||
@ -89,6 +90,47 @@ void SpiTestClass::performRm3100Test(uint8_t mgmId) {
|
||||
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";
|
||||
|
@ -31,6 +31,8 @@ private:
|
||||
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();
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include <fsfw/ipc/MutexFactory.h>
|
||||
#include <fsfw/ipc/MutexHelper.h>
|
||||
#include <fsfw/globalfunctions/arrayprinter.h>
|
||||
|
||||
#include <linux/spi/spidev.h>
|
||||
#include <fcntl.h>
|
||||
@ -170,6 +171,23 @@ ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, s
|
||||
}
|
||||
|
||||
bool fullDuplex = spiCookie->isFullDuplex();
|
||||
if(fullDuplex) {
|
||||
uint8_t* readBuf = nullptr;
|
||||
ReturnValue_t result = getReadBuffer(spiCookie->getSpiAddress(), &readBuf);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
#if FSFW_VERBOSE_LEVEL >= 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "SpiComIF::sendMessage: Could not get read buffer!" <<
|
||||
std::endl;
|
||||
#else
|
||||
sif::printWarning("SpiComIF::sendMessage: Could not get read buffer!\n");
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
|
||||
return result;
|
||||
}
|
||||
spiCookie->assignReadBuffer(readBuf);
|
||||
}
|
||||
|
||||
int retval = 0;
|
||||
|
||||
gpioId_t gpioId = spiCookie->getChipSelectPin();
|
||||
@ -182,7 +200,7 @@ ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, s
|
||||
if(fullDuplex) {
|
||||
/* Initiate a full duplex SPI transfer. */
|
||||
retval = ioctl(fileDescriptor, SPI_IOC_MESSAGE(1), spiCookie->getTransferStructHandle());
|
||||
if(retval != 0) {
|
||||
if(retval < 0) {
|
||||
utility::handleIoctlError("SpiComIF::sendMessage: ioctl error.");
|
||||
result = FULL_DUPLEX_TRANSFER_FAILED;
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ MGMHandlerLIS3MDL::MGMHandlerLIS3MDL(object_id_t objectId,
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
debugDivider = new PeriodicOperationDivider(10);
|
||||
#endif
|
||||
// Set to default values right away.
|
||||
/* Set to default values right away. */
|
||||
registers[0] = MGMLIS3MDL::CTRL_REG1_DEFAULT;
|
||||
registers[1] = MGMLIS3MDL::CTRL_REG2_DEFAULT;
|
||||
registers[2] = MGMLIS3MDL::CTRL_REG3_DEFAULT;
|
||||
@ -37,7 +37,7 @@ void MGMHandlerLIS3MDL::doStartUp() {
|
||||
break;
|
||||
|
||||
case(InternalState::STATE_CHECK_REGISTERS): {
|
||||
// Set up cached registers which will be used to configure the MGM.
|
||||
/* Set up cached registers which will be used to configure the MGM. */
|
||||
if(commandExecuted) {
|
||||
commandExecuted = false;
|
||||
setMode(_MODE_TO_ON);
|
||||
@ -73,11 +73,17 @@ ReturnValue_t MGMHandlerLIS3MDL::buildTransitionDeviceCommand(
|
||||
*id = MGMLIS3MDL::READ_CONFIG_AND_DATA;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// might be a configuration error.
|
||||
sif::debug << "GyroHandler::buildTransitionDeviceCommand: Unknown "
|
||||
<< "internal state!" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
default: {
|
||||
/* might be a configuration error. */
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "GyroHandler::buildTransitionDeviceCommand: Unknown internal state!" <<
|
||||
std::endl;
|
||||
#else
|
||||
sif::printWarning("GyroHandler::buildTransitionDeviceCommand: Unknown internal state!\n");
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
}
|
||||
return buildCommandFromCommand(*id, NULL, 0);
|
||||
}
|
||||
@ -185,6 +191,9 @@ ReturnValue_t MGMHandlerLIS3MDL::scanForReply(const uint8_t *start,
|
||||
if (start[1] != registers[0] or start[2] != registers[1] or
|
||||
start[3] != registers[2] or start[4] != registers[3] or
|
||||
start[5] != registers[4]) {
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
sif::warning << "MGMHandlerLIS3MDL::scanForReply: Invalid registers!" << std::endl;
|
||||
#endif
|
||||
return DeviceHandlerIF::INVALID_DATA;
|
||||
}
|
||||
if(mode == _MODE_START_UP) {
|
||||
@ -228,7 +237,7 @@ ReturnValue_t MGMHandlerLIS3MDL::interpretDeviceReply(DeviceCommandId_t id,
|
||||
break;
|
||||
}
|
||||
case MGMLIS3MDL::READ_CONFIG_AND_DATA: {
|
||||
// TODO: Store configuration and sensor values in new local datasets.
|
||||
// TODO: Store configuration in new local datasets.
|
||||
|
||||
uint8_t scale = getFullScale(registers[2]);
|
||||
float sensitivityFactor = getSensitivityFactor(scale);
|
||||
@ -240,7 +249,7 @@ ReturnValue_t MGMHandlerLIS3MDL::interpretDeviceReply(DeviceCommandId_t id,
|
||||
int16_t mgmMeasurementRawZ = packet[MGMLIS3MDL::Z_HIGHBYTE_IDX] << 8
|
||||
| packet[MGMLIS3MDL::Z_LOWBYTE_IDX] ;
|
||||
|
||||
// Target value in microtesla
|
||||
/* Target value in microtesla */
|
||||
float mgmX = static_cast<float>(mgmMeasurementRawX) * sensitivityFactor
|
||||
* MGMLIS3MDL::GAUSS_TO_MICROTESLA_FACTOR;
|
||||
float mgmY = static_cast<float>(mgmMeasurementRawY) * sensitivityFactor
|
||||
@ -252,7 +261,7 @@ ReturnValue_t MGMHandlerLIS3MDL::interpretDeviceReply(DeviceCommandId_t id,
|
||||
if(debugDivider->checkAndIncrement()) {
|
||||
sif::info << "MGMHandlerLIS3: Magnetic field strength in"
|
||||
" microtesla:" << std::endl;
|
||||
// Set terminal to utf-8 if there is an issue with micro printout.
|
||||
/* Set terminal to utf-8 if there is an issue with micro printout. */
|
||||
sif::info << "X: " << mgmX << " \xC2\xB5T" << std::endl;
|
||||
sif::info << "Y: " << mgmY << " \xC2\xB5T" << std::endl;
|
||||
sif::info << "Z: " << mgmZ << " \xC2\xB5T" << std::endl;
|
||||
@ -273,9 +282,8 @@ ReturnValue_t MGMHandlerLIS3MDL::interpretDeviceReply(DeviceCommandId_t id,
|
||||
float tempValue = 25.0 + ((static_cast<float>(tempValueRaw)) / 8.0);
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
if(debugDivider->check()) {
|
||||
// Set terminal to utf-8 if there is an issue with micro printout.
|
||||
sif::info << "MGMHandlerLIS3: Temperature: " << tempValue<< " °C"
|
||||
<< std::endl;
|
||||
/* Set terminal to utf-8 if there is an issue with micro printout. */
|
||||
sif::info << "MGMHandlerLIS3: Temperature: " << tempValue<< " °C" << std::endl;
|
||||
}
|
||||
#endif
|
||||
ReturnValue_t result = dataset.read();
|
||||
@ -397,7 +405,6 @@ void MGMHandlerLIS3MDL::fillCommandAndReplyMap() {
|
||||
}
|
||||
|
||||
ReturnValue_t MGMHandlerLIS3MDL::prepareCtrlRegisterWrite() {
|
||||
|
||||
commandBuffer[0] = writeCommand(MGMLIS3MDL::CTRL_REG1, true);
|
||||
|
||||
for (size_t i = 0; i < MGMLIS3MDL::NR_OF_CTRL_REGISTERS; i++) {
|
||||
@ -406,7 +413,7 @@ ReturnValue_t MGMHandlerLIS3MDL::prepareCtrlRegisterWrite() {
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = MGMLIS3MDL::NR_OF_CTRL_REGISTERS + 1;
|
||||
|
||||
// We dont have to check if this is working because we just did it
|
||||
/* We dont have to check if this is working because we just did it */
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
@ -415,7 +422,7 @@ void MGMHandlerLIS3MDL::doTransition(Mode_t modeFrom, Submode_t subModeFrom) {
|
||||
}
|
||||
|
||||
uint32_t MGMHandlerLIS3MDL::getTransitionDelayMs(Mode_t from, Mode_t to) {
|
||||
return 5000;
|
||||
return 30000;
|
||||
}
|
||||
|
||||
void MGMHandlerLIS3MDL::modeChanged(void) {
|
||||
@ -434,3 +441,6 @@ ReturnValue_t MGMHandlerLIS3MDL::initializeLocalDataPool(
|
||||
new PoolEntry<float>({0.0}));
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void MGMHandlerLIS3MDL::performOperationHook() {
|
||||
}
|
||||
|
@ -161,6 +161,8 @@ private:
|
||||
PeriodicOperationDivider* debugDivider;
|
||||
#endif
|
||||
|
||||
void performOperationHook() override;
|
||||
|
||||
};
|
||||
|
||||
#endif /* MISSION_DEVICES_MGMLIS3MDLHANDLER_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user