some fixes and updates for RW poling
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good

This commit is contained in:
Robin Müller 2023-02-16 14:32:23 +01:00
parent 39f83937c5
commit bc2a0d875f
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
2 changed files with 16 additions and 10 deletions

View File

@ -32,12 +32,20 @@ ReturnValue_t RwPollingTask::performOperation(uint8_t operationCode) {
ipcLock->unlockMutex();
semaphore->acquire();
int fd = 0;
for (auto& skip : skipCommandingForRw) {
skip = false;
}
ReturnValue_t result = openSpi(O_RDWR, fd);
if (result != returnvalue::OK) {
continue;
}
for (unsigned idx = 0; idx < rwCookies.size(); idx++) {
if (rwCookies[idx]->setSpeed) {
if (rwCookies[idx]->specialRequest == rws::SpecialRwRequest::RESET_MCU) {
prepareSimpleCommand(rws::RESET_MCU);
// No point in commanding that specific RW for the cycle.
skipCommandingForRw[idx] = true;
writeOneRwCmd(idx, fd);
} else if (rwCookies[idx]->setSpeed) {
prepareSetSpeedCmd(idx);
if (writeOneRwCmd(idx, fd) != returnvalue::OK) {
continue;
@ -163,6 +171,9 @@ ReturnValue_t RwPollingTask::writeAndReadAllRws(DeviceCommandId_t id) {
return result;
}
for (unsigned idx = 0; idx < rwCookies.size(); idx++) {
if (skipCommandingForRw[idx]) {
continue;
}
ReturnValue_t result = sendOneMessage(fd, *rwCookies[idx]);
if (result != returnvalue::OK) {
closeSpi(fd);
@ -307,32 +318,26 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
ReturnValue_t RwPollingTask::writeOneRwCmd(uint8_t rwIdx, int fd) {
ReturnValue_t result = sendOneMessage(fd, *rwCookies[rwIdx]);
if (result != returnvalue::OK) {
closeSpi(fd);
return returnvalue::FAILED;
}
return returnvalue::OK;
}
ReturnValue_t RwPollingTask::readAllRws(int fd, DeviceCommandId_t id) {
ReturnValue_t result = openSpi(O_RDWR, fd);
if (result != returnvalue::OK) {
return result;
}
// SPI dev will be opened in readNextReply on demand.
for (unsigned idx = 0; idx < rwCookies.size(); idx++) {
if (id == rws::SET_SPEED and !rwCookies[idx]->setSpeed) {
if (((id == rws::SET_SPEED) and !rwCookies[idx]->setSpeed) or skipCommandingForRw[idx]) {
continue;
}
if (spiLock == nullptr) {
sif::debug << "rwSpiCallback::spiCallback: Mutex or GPIO interface invalid" << std::endl;
return returnvalue::FAILED;
}
// TODO: Fix buffer to write to
uint8_t* replyBuf;
size_t maxReadLen = idAndIdxToReadBuffer(id, idx, &replyBuf);
readNextReply(*rwCookies[idx], replyBuf, maxReadLen);
}
closeSpi(fd);
// SPI is closed in readNextReply as well.
return returnvalue::OK;
}

View File

@ -44,6 +44,7 @@ class RwPollingTask : public SystemObject, public ExecutableObjectIF, public Dev
MutexIF* spiLock;
const char* spiDev;
SpiComIF* spiIF;
std::array<bool, 4> skipCommandingForRw;
std::array<RwCookie*, 4> rwCookies;
std::array<uint8_t, rws::MAX_CMD_SIZE> writeBuffer;
std::array<uint8_t, rws::MAX_CMD_SIZE * 2> encodedBuffer;