update spi test task for PL PCDU
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:
parent
effe461380
commit
ae4d1e6db3
@ -283,15 +283,15 @@ void SpiTestClass::performMax1227Test() {
|
||||
using namespace max1227;
|
||||
bool testRadSensorExtConv = false;
|
||||
bool testRadSensorIntConv = false;
|
||||
bool extConversion = false;
|
||||
bool intConversion = true;
|
||||
bool susExtConversion = false;
|
||||
bool susIntConversion = false;
|
||||
bool plPcduAdcExtConv = false;
|
||||
#ifdef XIPHOS_Q7S
|
||||
std::string deviceName = q7s::SPI_DEFAULT_DEV;
|
||||
#elif defined(RASPBERRY_PI)
|
||||
std::string deviceName = "";
|
||||
#endif
|
||||
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!"
|
||||
@ -307,25 +307,10 @@ void SpiTestClass::performMax1227Test() {
|
||||
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");
|
||||
}
|
||||
transfer(fd, gpioIds::CS_RAD_SENSOR);
|
||||
|
||||
max1227::prepareExternallyClockedRead0ToN(sendBuffer.data(), 7, 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) {
|
||||
}
|
||||
transfer(fd, gpioIds::CS_RAD_SENSOR);
|
||||
arrayprinter::print(recvBuffer.data(), 13, OutputType::HEX);
|
||||
uint16_t adcRaw[8] = {};
|
||||
adcRaw[0] = (recvBuffer[1] << 8) | recvBuffer[2];
|
||||
@ -344,60 +329,24 @@ void SpiTestClass::performMax1227Test() {
|
||||
if (testRadSensorIntConv) {
|
||||
sendBuffer[0] = max1227::buildResetByte(false);
|
||||
spiTransferStruct[0].len = 1;
|
||||
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) {
|
||||
}
|
||||
transfer(fd, gpioIds::CS_RAD_SENSOR);
|
||||
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;
|
||||
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) {
|
||||
}
|
||||
transfer(fd, gpioIds::CS_RAD_SENSOR);
|
||||
usleep(10);
|
||||
sendBuffer[0] = buildConvByte(ScanModes::CHANNELS_0_TO_N, 7, true);
|
||||
spiTransferStruct[0].len = 1;
|
||||
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) {
|
||||
}
|
||||
transfer(fd, gpioIds::CS_RAD_SENSOR);
|
||||
|
||||
usleep(65);
|
||||
spiTransferStruct[0].len = 18;
|
||||
// Shift out zeros
|
||||
spiTransferStruct[0].tx_buf = 0;
|
||||
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) {
|
||||
}
|
||||
transfer(fd, gpioIds::CS_RAD_SENSOR);
|
||||
|
||||
arrayprinter::print(recvBuffer.data(), 14);
|
||||
uint16_t adcRaw[8] = {};
|
||||
@ -416,28 +365,19 @@ void SpiTestClass::performMax1227Test() {
|
||||
sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl;
|
||||
}
|
||||
}
|
||||
if (extConversion) {
|
||||
if (susExtConversion) {
|
||||
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");
|
||||
}
|
||||
transfer(fd, gpio::NO_GPIO);
|
||||
|
||||
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");
|
||||
}
|
||||
transfer(fd, gpio::NO_GPIO);
|
||||
|
||||
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");
|
||||
}
|
||||
transfer(fd, gpio::NO_GPIO);
|
||||
uint16_t adcRaw[6] = {};
|
||||
adcRaw[0] = (recvBuffer[1] << 8) | recvBuffer[2];
|
||||
adcRaw[1] = (recvBuffer[3] << 8) | recvBuffer[4];
|
||||
@ -450,39 +390,26 @@ void SpiTestClass::performMax1227Test() {
|
||||
sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl;
|
||||
}
|
||||
}
|
||||
if (intConversion) {
|
||||
if (susIntConversion) {
|
||||
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");
|
||||
}
|
||||
|
||||
transfer(fd, gpio::NO_GPIO);
|
||||
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");
|
||||
}
|
||||
transfer(fd, gpio::NO_GPIO);
|
||||
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");
|
||||
}
|
||||
transfer(fd, gpio::NO_GPIO);
|
||||
|
||||
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");
|
||||
}
|
||||
transfer(fd, gpio::NO_GPIO);
|
||||
arrayprinter::print(recvBuffer.data(), 14);
|
||||
float temp = static_cast<int16_t>(((recvBuffer[0] & 0x0f) << 8) | recvBuffer[1]) * 0.125;
|
||||
sif::info << "Temperature: " << temp << " C" << std::endl;
|
||||
@ -497,28 +424,30 @@ void SpiTestClass::performMax1227Test() {
|
||||
sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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");
|
||||
if (plPcduAdcExtConv) {
|
||||
// This enables the ADC
|
||||
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT0);
|
||||
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT1);
|
||||
sendBuffer[0] = max1227::buildResetByte(true);
|
||||
spiTransferStruct[0].len = 1;
|
||||
transfer(fd, gpioIds::PLPCDU_ADC_CS);
|
||||
sendBuffer[0] = max1227::buildSetupByte(ClkSel::EXT_CONV_EXT_TIMED, RefSel::INT_REF_NO_WAKEUP,
|
||||
DiffSel::NONE_0);
|
||||
spiTransferStruct[0].len = 1;
|
||||
transfer(fd, gpioIds::PLPCDU_ADC_CS);
|
||||
uint8_t n = 11;
|
||||
max1227::prepareExternallyClockedRead0ToN(sendBuffer.data(), n, spiTransferStruct[0].len);
|
||||
transfer(fd, gpioIds::PLPCDU_ADC_CS);
|
||||
uint16_t adcRaw[n + 1] = {};
|
||||
for(uint8_t idx = 0; idx < n + 1; idx++) {
|
||||
adcRaw[idx] = (recvBuffer[idx * 2 + 1] << 8) | recvBuffer[idx * 2 + 2];
|
||||
}
|
||||
arrayprinter::print(recvBuffer.data(), spiTransferStruct[0].len, OutputType::HEX);
|
||||
for (int idx = 0; idx < n + 1; idx++) {
|
||||
sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl;
|
||||
}
|
||||
}
|
||||
recvBuffer[1] = reply0;
|
||||
recvBuffer[2] = reply1;
|
||||
arrayprinter::print(recvBuffer.data(), 3);
|
||||
*/
|
||||
}
|
||||
|
||||
void SpiTestClass::acsInit() {
|
||||
GpioCookie *gpioCookie = new GpioCookie();
|
||||
@ -747,3 +676,28 @@ uint8_t SpiTestClass::readRegister(int fd, gpioId_t chipSelect, uint8_t reg) {
|
||||
}
|
||||
return recvBuffer[1];
|
||||
}
|
||||
|
||||
ReturnValue_t SpiTestClass::transfer(int fd, gpioId_t chipSelect = gpio::NO_GPIO) {
|
||||
int retval = 0;
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
if(chipSelect != gpio::NO_GPIO) {
|
||||
result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
||||
if (retval < 0) {
|
||||
utility::handleIoctlError("SpiTestClass::transfer: ioctl failed");
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
if(chipSelect != gpio::NO_GPIO) {
|
||||
result = gpioIF->pullHigh(gpioIds::CS_RAD_SENSOR);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
@ -74,6 +74,7 @@ class SpiTestClass : public TestTask {
|
||||
void writeMultipleRegisters(int fd, gpioId_t chipSelect, uint8_t reg, uint8_t* values,
|
||||
size_t len);
|
||||
void writeRegister(int fd, gpioId_t chipSelect, uint8_t reg, uint8_t value);
|
||||
ReturnValue_t transfer(int fd, gpioId_t chipSelect);
|
||||
|
||||
uint8_t readRm3100Register(int fd, gpioId_t chipSelect, uint8_t reg);
|
||||
uint8_t readStmRegister(int fd, gpioId_t chipSelect, uint8_t reg, bool autoIncrement);
|
||||
|
@ -58,7 +58,7 @@ void prepareExternallyClockedSingleChannelRead(uint8_t* spiBuf, uint8_t channel,
|
||||
* If there is a wakeup delay, there needs to be a 65 us delay between sending
|
||||
* the first byte (first conversion byte) the the rest of the SPI buffer.
|
||||
* @param spiBuf
|
||||
* @param n
|
||||
* @param n Channel number. Example: If the ADC has 6 channels, n will be 5
|
||||
* @param sz
|
||||
*/
|
||||
void prepareExternallyClockedRead0ToN(uint8_t* spiBuf, uint8_t n, size_t& sz);
|
||||
|
Loading…
Reference in New Issue
Block a user