v1.10.0 #220
@ -283,15 +283,15 @@ void SpiTestClass::performMax1227Test() {
|
|||||||
using namespace max1227;
|
using namespace max1227;
|
||||||
bool testRadSensorExtConv = false;
|
bool testRadSensorExtConv = false;
|
||||||
bool testRadSensorIntConv = false;
|
bool testRadSensorIntConv = false;
|
||||||
bool extConversion = false;
|
bool susExtConversion = false;
|
||||||
bool intConversion = true;
|
bool susIntConversion = false;
|
||||||
|
bool plPcduAdcExtConv = false;
|
||||||
#ifdef XIPHOS_Q7S
|
#ifdef XIPHOS_Q7S
|
||||||
std::string deviceName = q7s::SPI_DEFAULT_DEV;
|
std::string deviceName = q7s::SPI_DEFAULT_DEV;
|
||||||
#elif defined(RASPBERRY_PI)
|
#elif defined(RASPBERRY_PI)
|
||||||
std::string deviceName = "";
|
std::string deviceName = "";
|
||||||
#endif
|
#endif
|
||||||
int fd = 0;
|
int fd = 0;
|
||||||
int retval = 0;
|
|
||||||
UnixFileGuard fileHelper(deviceName, &fd, O_RDWR, "SpiComIF::initializeInterface");
|
UnixFileGuard fileHelper(deviceName, &fd, O_RDWR, "SpiComIF::initializeInterface");
|
||||||
if (fileHelper.getOpenResult()) {
|
if (fileHelper.getOpenResult()) {
|
||||||
sif::error << "SpiTestClass::performLis3Mdl3100Test: File descriptor could not be opened!"
|
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,
|
sendBuffer[1] = max1227::buildSetupByte(ClkSel::EXT_CONV_EXT_TIMED, RefSel::INT_REF_NO_WAKEUP,
|
||||||
DiffSel::NONE_0);
|
DiffSel::NONE_0);
|
||||||
spiTransferStruct[0].len = 2;
|
spiTransferStruct[0].len = 2;
|
||||||
ReturnValue_t result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR);
|
transfer(fd, 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");
|
|
||||||
}
|
|
||||||
|
|
||||||
max1227::prepareExternallyClockedRead0ToN(sendBuffer.data(), 7, spiTransferStruct[0].len);
|
max1227::prepareExternallyClockedRead0ToN(sendBuffer.data(), 7, spiTransferStruct[0].len);
|
||||||
result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR);
|
transfer(fd, 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::HEX);
|
arrayprinter::print(recvBuffer.data(), 13, OutputType::HEX);
|
||||||
uint16_t adcRaw[8] = {};
|
uint16_t adcRaw[8] = {};
|
||||||
adcRaw[0] = (recvBuffer[1] << 8) | recvBuffer[2];
|
adcRaw[0] = (recvBuffer[1] << 8) | recvBuffer[2];
|
||||||
@ -344,60 +329,24 @@ void SpiTestClass::performMax1227Test() {
|
|||||||
if (testRadSensorIntConv) {
|
if (testRadSensorIntConv) {
|
||||||
sendBuffer[0] = max1227::buildResetByte(false);
|
sendBuffer[0] = max1227::buildResetByte(false);
|
||||||
spiTransferStruct[0].len = 1;
|
spiTransferStruct[0].len = 1;
|
||||||
ReturnValue_t result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR);
|
transfer(fd, 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) {
|
|
||||||
}
|
|
||||||
usleep(65);
|
usleep(65);
|
||||||
|
|
||||||
// Now use internal conversion
|
// Now use internal conversion
|
||||||
sendBuffer[0] = max1227::buildSetupByte(ClkSel::INT_CONV_INT_TIMED_CNVST_AS_AIN,
|
sendBuffer[0] = max1227::buildSetupByte(ClkSel::INT_CONV_INT_TIMED_CNVST_AS_AIN,
|
||||||
RefSel::INT_REF_NO_WAKEUP, DiffSel::NONE_0);
|
RefSel::INT_REF_NO_WAKEUP, DiffSel::NONE_0);
|
||||||
spiTransferStruct[0].len = 1;
|
spiTransferStruct[0].len = 1;
|
||||||
result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR);
|
transfer(fd, 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) {
|
|
||||||
}
|
|
||||||
usleep(10);
|
usleep(10);
|
||||||
sendBuffer[0] = buildConvByte(ScanModes::CHANNELS_0_TO_N, 7, true);
|
sendBuffer[0] = buildConvByte(ScanModes::CHANNELS_0_TO_N, 7, true);
|
||||||
spiTransferStruct[0].len = 1;
|
spiTransferStruct[0].len = 1;
|
||||||
result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR);
|
transfer(fd, 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) {
|
|
||||||
}
|
|
||||||
|
|
||||||
usleep(65);
|
usleep(65);
|
||||||
spiTransferStruct[0].len = 18;
|
spiTransferStruct[0].len = 18;
|
||||||
// Shift out zeros
|
// Shift out zeros
|
||||||
spiTransferStruct[0].tx_buf = 0;
|
spiTransferStruct[0].tx_buf = 0;
|
||||||
result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR);
|
transfer(fd, 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(), 14);
|
arrayprinter::print(recvBuffer.data(), 14);
|
||||||
uint16_t adcRaw[8] = {};
|
uint16_t adcRaw[8] = {};
|
||||||
@ -416,28 +365,19 @@ void SpiTestClass::performMax1227Test() {
|
|||||||
sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl;
|
sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (extConversion) {
|
if (susExtConversion) {
|
||||||
sendBuffer[0] = max1227::buildResetByte(false);
|
sendBuffer[0] = max1227::buildResetByte(false);
|
||||||
spiTransferStruct[0].len = 1;
|
spiTransferStruct[0].len = 1;
|
||||||
retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
transfer(fd, gpio::NO_GPIO);
|
||||||
if (retval < 0) {
|
|
||||||
utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
usleep(65);
|
usleep(65);
|
||||||
sendBuffer[0] = max1227::buildSetupByte(ClkSel::EXT_CONV_EXT_TIMED, RefSel::INT_REF_NO_WAKEUP,
|
sendBuffer[0] = max1227::buildSetupByte(ClkSel::EXT_CONV_EXT_TIMED, RefSel::INT_REF_NO_WAKEUP,
|
||||||
DiffSel::NONE_0);
|
DiffSel::NONE_0);
|
||||||
spiTransferStruct[0].len = 1;
|
spiTransferStruct[0].len = 1;
|
||||||
retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
transfer(fd, gpio::NO_GPIO);
|
||||||
if (retval < 0) {
|
|
||||||
utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
max1227::prepareExternallyClockedRead0ToN(sendBuffer.data(), 5, spiTransferStruct[0].len);
|
max1227::prepareExternallyClockedRead0ToN(sendBuffer.data(), 5, spiTransferStruct[0].len);
|
||||||
retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
transfer(fd, gpio::NO_GPIO);
|
||||||
if (retval < 0) {
|
|
||||||
utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
|
||||||
}
|
|
||||||
uint16_t adcRaw[6] = {};
|
uint16_t adcRaw[6] = {};
|
||||||
adcRaw[0] = (recvBuffer[1] << 8) | recvBuffer[2];
|
adcRaw[0] = (recvBuffer[1] << 8) | recvBuffer[2];
|
||||||
adcRaw[1] = (recvBuffer[3] << 8) | recvBuffer[4];
|
adcRaw[1] = (recvBuffer[3] << 8) | recvBuffer[4];
|
||||||
@ -450,39 +390,26 @@ void SpiTestClass::performMax1227Test() {
|
|||||||
sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl;
|
sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (intConversion) {
|
if (susIntConversion) {
|
||||||
sendBuffer[0] = max1227::buildResetByte(false);
|
sendBuffer[0] = max1227::buildResetByte(false);
|
||||||
spiTransferStruct[0].len = 1;
|
spiTransferStruct[0].len = 1;
|
||||||
retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
transfer(fd, gpio::NO_GPIO);
|
||||||
if (retval < 0) {
|
|
||||||
utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
usleep(65);
|
usleep(65);
|
||||||
// Now use internal conversion
|
// Now use internal conversion
|
||||||
sendBuffer[0] = max1227::buildSetupByte(ClkSel::INT_CONV_INT_TIMED_CNVST_AS_AIN,
|
sendBuffer[0] = max1227::buildSetupByte(ClkSel::INT_CONV_INT_TIMED_CNVST_AS_AIN,
|
||||||
RefSel::INT_REF_NO_WAKEUP, DiffSel::NONE_0);
|
RefSel::INT_REF_NO_WAKEUP, DiffSel::NONE_0);
|
||||||
spiTransferStruct[0].len = 1;
|
spiTransferStruct[0].len = 1;
|
||||||
retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
transfer(fd, gpio::NO_GPIO);
|
||||||
if (retval < 0) {
|
|
||||||
utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
|
||||||
}
|
|
||||||
usleep(10);
|
usleep(10);
|
||||||
sendBuffer[0] = buildConvByte(ScanModes::CHANNELS_0_TO_N, 5, true);
|
sendBuffer[0] = buildConvByte(ScanModes::CHANNELS_0_TO_N, 5, true);
|
||||||
spiTransferStruct[0].len = 1;
|
spiTransferStruct[0].len = 1;
|
||||||
retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
transfer(fd, gpio::NO_GPIO);
|
||||||
if (retval < 0) {
|
|
||||||
utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
usleep(65);
|
usleep(65);
|
||||||
spiTransferStruct[0].len = 14;
|
spiTransferStruct[0].len = 14;
|
||||||
// Shift out zeros
|
// Shift out zeros
|
||||||
spiTransferStruct[0].tx_buf = 0;
|
spiTransferStruct[0].tx_buf = 0;
|
||||||
retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
transfer(fd, gpio::NO_GPIO);
|
||||||
if (retval < 0) {
|
|
||||||
utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
|
||||||
}
|
|
||||||
arrayprinter::print(recvBuffer.data(), 14);
|
arrayprinter::print(recvBuffer.data(), 14);
|
||||||
float temp = static_cast<int16_t>(((recvBuffer[0] & 0x0f) << 8) | recvBuffer[1]) * 0.125;
|
float temp = static_cast<int16_t>(((recvBuffer[0] & 0x0f) << 8) | recvBuffer[1]) * 0.125;
|
||||||
sif::info << "Temperature: " << temp << " C" << std::endl;
|
sif::info << "Temperature: " << temp << " C" << std::endl;
|
||||||
@ -497,28 +424,30 @@ void SpiTestClass::performMax1227Test() {
|
|||||||
sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl;
|
sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (plPcduAdcExtConv) {
|
||||||
|
// This enables the ADC
|
||||||
/*
|
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT0);
|
||||||
* sendBuffer[0] = buildConvByte(ScanModes::N_ONCE, 0, false);
|
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT1);
|
||||||
|
sendBuffer[0] = max1227::buildResetByte(true);
|
||||||
spiTransferStruct[0].len = 1;
|
spiTransferStruct[0].len = 1;
|
||||||
uint8_t reply0 = 0x00;
|
transfer(fd, gpioIds::PLPCDU_ADC_CS);
|
||||||
uint8_t reply1 = 0x00;
|
sendBuffer[0] = max1227::buildSetupByte(ClkSel::EXT_CONV_EXT_TIMED, RefSel::INT_REF_NO_WAKEUP,
|
||||||
spiTransferStruct[1].tx_buf = 0;
|
DiffSel::NONE_0);
|
||||||
spiTransferStruct[1].rx_buf = reinterpret_cast<__u64>(&reply0);
|
spiTransferStruct[0].len = 1;
|
||||||
spiTransferStruct[1].len = 1;
|
transfer(fd, gpioIds::PLPCDU_ADC_CS);
|
||||||
// Shift out zeros
|
uint8_t n = 11;
|
||||||
spiTransferStruct[2].tx_buf = 0;
|
max1227::prepareExternallyClockedRead0ToN(sendBuffer.data(), n, spiTransferStruct[0].len);
|
||||||
spiTransferStruct[2].rx_buf = reinterpret_cast<__u64>(&reply1);
|
transfer(fd, gpioIds::PLPCDU_ADC_CS);
|
||||||
spiTransferStruct[2].len = 1;
|
uint16_t adcRaw[n + 1] = {};
|
||||||
retval = ioctl(fd, SPI_IOC_MESSAGE(3), spiTransferStruct);
|
for(uint8_t idx = 0; idx < n + 1; idx++) {
|
||||||
if (retval < 0) {
|
adcRaw[idx] = (recvBuffer[idx * 2 + 1] << 8) | recvBuffer[idx * 2 + 2];
|
||||||
utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
}
|
||||||
|
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() {
|
void SpiTestClass::acsInit() {
|
||||||
GpioCookie *gpioCookie = new GpioCookie();
|
GpioCookie *gpioCookie = new GpioCookie();
|
||||||
@ -747,3 +676,28 @@ uint8_t SpiTestClass::readRegister(int fd, gpioId_t chipSelect, uint8_t reg) {
|
|||||||
}
|
}
|
||||||
return recvBuffer[1];
|
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,
|
void writeMultipleRegisters(int fd, gpioId_t chipSelect, uint8_t reg, uint8_t* values,
|
||||||
size_t len);
|
size_t len);
|
||||||
void writeRegister(int fd, gpioId_t chipSelect, uint8_t reg, uint8_t value);
|
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 readRm3100Register(int fd, gpioId_t chipSelect, uint8_t reg);
|
||||||
uint8_t readStmRegister(int fd, gpioId_t chipSelect, uint8_t reg, bool autoIncrement);
|
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
|
* 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.
|
* the first byte (first conversion byte) the the rest of the SPI buffer.
|
||||||
* @param spiBuf
|
* @param spiBuf
|
||||||
* @param n
|
* @param n Channel number. Example: If the ADC has 6 channels, n will be 5
|
||||||
* @param sz
|
* @param sz
|
||||||
*/
|
*/
|
||||||
void prepareExternallyClockedRead0ToN(uint8_t* spiBuf, uint8_t n, size_t& sz);
|
void prepareExternallyClockedRead0ToN(uint8_t* spiBuf, uint8_t n, size_t& sz);
|
||||||
|
Loading…
Reference in New Issue
Block a user