added more max1227 tests
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good

This commit is contained in:
Robin Müller 2022-02-16 18:56:38 +01:00
parent 3387a71399
commit c06ef5d6b5
10 changed files with 242 additions and 23 deletions

View File

@ -57,12 +57,12 @@ static constexpr char HEATER_6[] = "heater6";
static constexpr char HEATER_7[] = "heater7";
static constexpr char SA_DPL_PIN_0[] = "sa_dpl_0";
static constexpr char SA_DPL_PIN_1[] = "sa_dpl_1";
static constexpr char SPI_MUX_BIT_0_PIN[] = "spi_mux_bit_1";
static constexpr char SPI_MUX_BIT_1_PIN[] = "spi_mux_bit_2";
static constexpr char SPI_MUX_BIT_2_PIN[] = "spi_mux_bit_3";
static constexpr char SPI_MUX_BIT_3_PIN[] = "spi_mux_bit_4";
static constexpr char SPI_MUX_BIT_4_PIN[] = "spi_mux_bit_5";
static constexpr char SPI_MUX_BIT_5_PIN[] = "spi_mux_bit_6";
static constexpr char SPI_MUX_BIT_0_PIN[] = "spi_mux_bit_0";
static constexpr char SPI_MUX_BIT_1_PIN[] = "spi_mux_bit_1";
static constexpr char SPI_MUX_BIT_2_PIN[] = "spi_mux_bit_2";
static constexpr char SPI_MUX_BIT_3_PIN[] = "spi_mux_bit_3";
static constexpr char SPI_MUX_BIT_4_PIN[] = "spi_mux_bit_4";
static constexpr char SPI_MUX_BIT_5_PIN[] = "spi_mux_bit_5";
static constexpr char EN_RW_CS[] = "en_rw_cs";
static constexpr char EN_RW_1[] = "enable_rw_1";
static constexpr char EN_RW_2[] = "enable_rw_2";

View File

@ -303,7 +303,12 @@ void ObjectFactory::createRadSensorComponent(LinuxLibgpioIF* gpioComIF) {
SpiCookie* spiCookieRadSensor = new SpiCookie(
addresses::RAD_SENSOR, gpioIds::CS_RAD_SENSOR, std::string(q7s::SPI_DEFAULT_DEV),
RAD_SENSOR::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED);
new RadiationSensorHandler(objects::RAD_SENSOR, objects::SPI_COM_IF, spiCookieRadSensor);
auto radSensor =
new RadiationSensorHandler(objects::RAD_SENSOR, objects::SPI_COM_IF, spiCookieRadSensor);
#if OBSW_TEST_RADIATION_SENSOR_HANDLER == 1
radSensor->setStartUpImmediately();
radSensor->setToGoToNormalModeImmediately();
#endif
}
void ObjectFactory::createSunSensorComponents(LinuxLibgpioIF* gpioComIF, SpiComIF* spiComIF) {

View File

@ -27,7 +27,7 @@ static constexpr spi::SpiModes DEFAULT_L3G_MODE = spi::SpiModes::MODE_3;
* Some MAX1227 could not be reached with frequencies around 4 MHz. Maybe this is caused by
* the decoder and buffer circuits. Thus frequency is here defined to 1 MHz.
*/
static const uint32_t SUS_MAX1227_SPI_FREQ = 1'000'000;
static const uint32_t SUS_MAX1227_SPI_FREQ = 976'000;
static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 976'000;
static constexpr spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_3;

2
fsfw

@ -1 +1 @@
Subproject commit 0d6d44f72fb28ba480482f5d8b2eee6f78d664ce
Subproject commit 9e92afbf076b57df843a1ee526bd63c3303995a5

View File

@ -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!");
}

View File

@ -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();

View File

@ -14,11 +14,13 @@ RadiationSensorHandler::~RadiationSensorHandler() {}
void RadiationSensorHandler::doStartUp() {
if (internalState == InternalState::CONFIGURED) {
#if OBSW_SWITCH_TO_NORMAL_MODE_AFTER_STARTUP == 1
setMode(MODE_NORMAL);
#else
setMode(_MODE_TO_ON);
#endif
if (goToNormalMode) {
setMode(MODE_NORMAL);
}
else {
setMode(_MODE_TO_ON);
}
}
}
@ -175,3 +177,5 @@ ReturnValue_t RadiationSensorHandler::initializeLocalDataPool(localpool::DataPoo
localDataPoolMap.emplace(RAD_SENSOR::AIN7, new PoolEntry<uint16_t>({0}));
return HasReturnvaluesIF::RETURN_OK;
}
void RadiationSensorHandler::setToGoToNormalModeImmediately() { this->goToNormalMode = true; }

View File

@ -16,6 +16,7 @@ class RadiationSensorHandler : public DeviceHandlerBase {
public:
RadiationSensorHandler(object_id_t objectId, object_id_t comIF, CookieIF *comCookie);
virtual ~RadiationSensorHandler();
void setToGoToNormalModeImmediately();
protected:
void doStartUp() override;
@ -42,6 +43,7 @@ class RadiationSensorHandler : public DeviceHandlerBase {
static const uint8_t MAX_CMD_LEN = RAD_SENSOR::READ_SIZE;
bool goToNormalMode = false;
uint8_t cmdBuffer[MAX_CMD_LEN];
InternalState internalState = InternalState::SETUP;
CommunicationStep communicationStep = CommunicationStep::START_CONVERSION;

View File

@ -7,3 +7,22 @@ uint8_t max1227::buildConvByte(ScanModes scanMode, uint8_t channel, bool readTem
uint8_t max1227::buildSetupByte(ClkSel clkSel, RefSel refSel, DiffSel diffSel) {
return (1 << 6) | (clkSel << 4) | (refSel << 2) | diffSel;
}
void max1227::prepareExternallyClockedSingleChannelRead(uint8_t *spiBuf, uint8_t channel,
size_t &sz) {
spiBuf[0] = buildConvByte(ScanModes::N_ONCE, channel, false);
spiBuf[1] = 0x00;
spiBuf[2] = 0x00;
sz = 3;
}
uint8_t max1227::buildResetByte(bool fifoOnly) { return (1 << 4) | (fifoOnly << 3); }
void max1227::prepareExternallyClockedRead0ToN(uint8_t *spiBuf, uint8_t n, size_t &sz) {
for (uint8_t idx = 0; idx <= n; idx++) {
spiBuf[idx * 2] = buildConvByte(ScanModes::N_ONCE, idx, false);
spiBuf[idx * 2 + 1] = 0x00;
}
spiBuf[(n + 1) * 2] = 0x00;
sz = (n + 1) * 2 + 1;
}

View File

@ -1,6 +1,7 @@
#ifndef MISSION_DEVICES_MAX1227_H_
#define MISSION_DEVICES_MAX1227_H_
#include <cstddef>
#include <cstdint>
namespace max1227 {
@ -38,9 +39,30 @@ enum DiffSel : uint8_t {
// One bipolar config byte follows the setup byte
BIPOLAR_CFG = 0b11
};
uint8_t buildResetByte(bool fifoOnly);
uint8_t buildConvByte(ScanModes scanMode, uint8_t channel, bool readTemp);
uint8_t buildSetupByte(ClkSel clkSel, RefSel refSel, DiffSel diffSel);
/**
* If there is a wakeup delay, there needs to be a 65 us delay between sending
* the first byte (conversion byte) and the the rest of the SPI buffer.
* The raw ADC value will be located in the first and second reply byte.
* @param spiBuf
* @param n
* @param sz
*/
void prepareExternallyClockedSingleChannelRead(uint8_t* spiBuf, uint8_t channel, size_t& sz);
/**
* 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 sz
*/
void prepareExternallyClockedRead0ToN(uint8_t* spiBuf, uint8_t n, size_t& sz);
} // namespace max1227
#endif /* MISSION_DEVICES_MAX1227_H_ */