added more max1227 tests
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good
This commit is contained in:
@ -24,7 +24,7 @@ SpiTestClass::SpiTestClass(object_id_t objectId, GpioIF *gpioIF)
|
||||
if (gpioIF == nullptr) {
|
||||
sif::error << "SpiTestClass::SpiTestClass: Invalid GPIO ComIF!" << std::endl;
|
||||
}
|
||||
testMode = TestModes::MGM_LIS3MDL;
|
||||
testMode = TestModes::SUS_0;
|
||||
spiTransferStruct[0].rx_buf = reinterpret_cast<__u64>(recvBuffer.data());
|
||||
spiTransferStruct[0].tx_buf = reinterpret_cast<__u64>(sendBuffer.data());
|
||||
}
|
||||
@ -47,7 +47,7 @@ ReturnValue_t SpiTestClass::performOneShotAction() {
|
||||
break;
|
||||
}
|
||||
case (TestModes::SUS_0): {
|
||||
performSusTest();
|
||||
performMax1227Test();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -279,14 +279,19 @@ void SpiTestClass::performL3gTest(uint8_t l3gId) {
|
||||
sif::info << "Z: " << angVelocZ << std::endl;
|
||||
}
|
||||
|
||||
void SpiTestClass::performSusTest() {
|
||||
void SpiTestClass::performMax1227Test() {
|
||||
using namespace max1227;
|
||||
bool testRadSensor = false;
|
||||
bool extConversion = true;
|
||||
bool intConversion = false;
|
||||
#ifdef XIPHOS_Q7S
|
||||
std::string deviceName = q7s::SPI_DEFAULT_DEV;
|
||||
#elif defined(RASPBERRY_PI)
|
||||
std::string deviceName = "";
|
||||
#endif
|
||||
int fileDescriptor = 0;
|
||||
UnixFileGuard fileHelper(deviceName, &fileDescriptor, O_RDWR, "SpiComIF::initializeInterface");
|
||||
int fd = 0;
|
||||
int retval = 0;
|
||||
UnixFileGuard fileHelper(deviceName, &fd, O_RDWR, "SpiComIF::initializeInterface");
|
||||
if (fileHelper.getOpenResult()) {
|
||||
sif::error << "SpiTestClass::performLis3Mdl3100Test: File descriptor could not be opened!"
|
||||
<< std::endl;
|
||||
@ -294,9 +299,152 @@ void SpiTestClass::performSusTest() {
|
||||
}
|
||||
uint32_t spiSpeed = 1'000'000;
|
||||
spi::SpiModes spiMode = spi::SpiModes::MODE_3;
|
||||
setSpiSpeedAndMode(fileDescriptor, spiMode, spiSpeed);
|
||||
setSpiSpeedAndMode(fd, spiMode, spiSpeed);
|
||||
|
||||
if (testRadSensor) {
|
||||
sendBuffer[0] = max1227::buildResetByte(true);
|
||||
sendBuffer[1] = max1227::buildSetupByte(ClkSel::EXT_CONV_EXT_TIMED, RefSel::INT_REF_NO_WAKEUP,
|
||||
DiffSel::NONE_0);
|
||||
spiTransferStruct[0].len = 2;
|
||||
ReturnValue_t result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
}
|
||||
retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
||||
if (retval < 0) {
|
||||
utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
||||
}
|
||||
|
||||
result = gpioIF->pullHigh(gpioIds::CS_RAD_SENSOR);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
}
|
||||
max1227::prepareExternallyClockedSingleChannelRead(sendBuffer.data(), 0,
|
||||
spiTransferStruct[0].len);
|
||||
result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
}
|
||||
retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
||||
if (retval < 0) {
|
||||
utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
||||
}
|
||||
arrayprinter::print(recvBuffer.data(), 3);
|
||||
result = gpioIF->pullHigh(gpioIds::CS_RAD_SENSOR);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
}
|
||||
|
||||
max1227::prepareExternallyClockedRead0ToN(sendBuffer.data(), 5, spiTransferStruct[0].len);
|
||||
result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
}
|
||||
retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
||||
if (retval < 0) {
|
||||
utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
||||
}
|
||||
result = gpioIF->pullHigh(gpioIds::CS_RAD_SENSOR);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
}
|
||||
arrayprinter::print(recvBuffer.data(), 13., OutputType::DEC);
|
||||
}
|
||||
if (extConversion) {
|
||||
sendBuffer[0] = max1227::buildResetByte(false);
|
||||
spiTransferStruct[0].len = 1;
|
||||
retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
||||
if (retval < 0) {
|
||||
utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
||||
}
|
||||
|
||||
usleep(65);
|
||||
sendBuffer[0] = max1227::buildSetupByte(ClkSel::EXT_CONV_EXT_TIMED, RefSel::INT_REF_NO_WAKEUP,
|
||||
DiffSel::NONE_0);
|
||||
spiTransferStruct[0].len = 1;
|
||||
retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
||||
if (retval < 0) {
|
||||
utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
||||
}
|
||||
|
||||
// usleep(4);
|
||||
// max1227::prepareExternallyClockedSingleChannelRead(sendBuffer.data(), 0,
|
||||
// spiTransferStruct[0].len);
|
||||
// retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
||||
// if (retval < 0) {
|
||||
// utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
||||
// }
|
||||
// arrayprinter::print(recvBuffer.data(), 3);
|
||||
|
||||
max1227::prepareExternallyClockedRead0ToN(sendBuffer.data(), 5, spiTransferStruct[0].len);
|
||||
retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
||||
if (retval < 0) {
|
||||
utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
||||
}
|
||||
uint16_t adcRaw[6] = {};
|
||||
adcRaw[0] = (recvBuffer[1] << 8) | recvBuffer[2];
|
||||
adcRaw[1] = (recvBuffer[3] << 8) | recvBuffer[4];
|
||||
adcRaw[2] = (recvBuffer[5] << 8) | recvBuffer[6];
|
||||
adcRaw[3] = (recvBuffer[7] << 8) | recvBuffer[8];
|
||||
adcRaw[4] = (recvBuffer[9] << 8) | recvBuffer[10];
|
||||
adcRaw[5] = (recvBuffer[11] << 8) | recvBuffer[12];
|
||||
arrayprinter::print(recvBuffer.data(), 13, OutputType::HEX);
|
||||
for (int idx = 0; idx < 6; idx++) {
|
||||
sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl;
|
||||
}
|
||||
}
|
||||
if (intConversion) {
|
||||
sendBuffer[0] = max1227::buildResetByte(false);
|
||||
spiTransferStruct[0].len = 1;
|
||||
retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
||||
if (retval < 0) {
|
||||
utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
||||
}
|
||||
|
||||
usleep(65);
|
||||
// Now use internal conversion
|
||||
sendBuffer[0] = max1227::buildSetupByte(ClkSel::INT_CONV_INT_TIMED_CNVST_AS_AIN,
|
||||
RefSel::INT_REF_NO_WAKEUP, DiffSel::NONE_0);
|
||||
spiTransferStruct[0].len = 1;
|
||||
retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
||||
if (retval < 0) {
|
||||
utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
||||
}
|
||||
usleep(10);
|
||||
sendBuffer[0] = buildConvByte(ScanModes::CHANNELS_0_TO_N, 5, true);
|
||||
spiTransferStruct[0].len = 1;
|
||||
retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
||||
if (retval < 0) {
|
||||
utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
||||
}
|
||||
|
||||
usleep(65);
|
||||
spiTransferStruct[0].len = 14;
|
||||
// Shift out zeros
|
||||
spiTransferStruct[0].tx_buf = 0;
|
||||
retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
||||
if (retval < 0) {
|
||||
utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
||||
}
|
||||
arrayprinter::print(recvBuffer.data(), 14);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* sendBuffer[0] = buildConvByte(ScanModes::N_ONCE, 0, false);
|
||||
spiTransferStruct[0].len = 1;
|
||||
uint8_t reply0 = 0x00;
|
||||
uint8_t reply1 = 0x00;
|
||||
spiTransferStruct[1].tx_buf = 0;
|
||||
spiTransferStruct[1].rx_buf = reinterpret_cast<__u64>(&reply0);
|
||||
spiTransferStruct[1].len = 1;
|
||||
// Shift out zeros
|
||||
spiTransferStruct[2].tx_buf = 0;
|
||||
spiTransferStruct[2].rx_buf = reinterpret_cast<__u64>(&reply1);
|
||||
spiTransferStruct[2].len = 1;
|
||||
retval = ioctl(fd, SPI_IOC_MESSAGE(3), spiTransferStruct);
|
||||
if (retval < 0) {
|
||||
utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
||||
}
|
||||
recvBuffer[1] = reply0;
|
||||
recvBuffer[2] = reply1;
|
||||
arrayprinter::print(recvBuffer.data(), 3);
|
||||
*/
|
||||
|
||||
void SpiTestClass::acsInit() {
|
||||
GpioCookie *gpioCookie = new GpioCookie();
|
||||
|
||||
@ -372,8 +520,27 @@ void SpiTestClass::acsInit() {
|
||||
}
|
||||
|
||||
void SpiTestClass::setSpiSpeedAndMode(int spiFd, spi::SpiModes mode, uint32_t speed) {
|
||||
int mode_test = SPI_MODE_3;
|
||||
int retval = ioctl(spiFd, SPI_IOC_WR_MODE, &mode_test); // reinterpret_cast<uint8_t*>(&mode));
|
||||
int modeUnix = 0;
|
||||
switch (mode) {
|
||||
case (spi::SpiModes::MODE_0): {
|
||||
modeUnix = SPI_MODE_0;
|
||||
break;
|
||||
}
|
||||
case (spi::SpiModes::MODE_1): {
|
||||
modeUnix = SPI_MODE_1;
|
||||
break;
|
||||
}
|
||||
case (spi::SpiModes::MODE_2): {
|
||||
modeUnix = SPI_MODE_2;
|
||||
break;
|
||||
}
|
||||
case (spi::SpiModes::MODE_3): {
|
||||
modeUnix = SPI_MODE_3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int retval = ioctl(spiFd, SPI_IOC_WR_MODE, &modeUnix); // reinterpret_cast<uint8_t*>(&mode));
|
||||
if (retval != 0) {
|
||||
utility::handleIoctlError("SpiTestClass::performRm3100Test: Setting SPI mode failed!");
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ class SpiTestClass : public TestTask {
|
||||
void performRm3100Test(uint8_t mgmId);
|
||||
void performLis3MdlTest(uint8_t lis3Id);
|
||||
void performL3gTest(uint8_t l3gId);
|
||||
void performSusTest();
|
||||
void performMax1227Test();
|
||||
|
||||
/* ACS board specific code which pulls all GPIOs high */
|
||||
void acsInit();
|
||||
|
Reference in New Issue
Block a user