RW Refactoring #381
@ -74,16 +74,23 @@ int obsw::obsw() {
|
|||||||
|
|
||||||
scheduling::initMission();
|
scheduling::initMission();
|
||||||
|
|
||||||
#if OBSW_COMMAND_SAFE_MODE_AT_STARTUP == 1
|
|
||||||
// Command the EIVE system to safe mode
|
// Command the EIVE system to safe mode
|
||||||
auto sysQueueId = satsystem::EIVE_SYSTEM.getCommandQueue();
|
auto sysQueueId = satsystem::EIVE_SYSTEM.getCommandQueue();
|
||||||
CommandMessage msg;
|
CommandMessage msg;
|
||||||
|
#if OBSW_COMMAND_SAFE_MODE_AT_STARTUP == 1
|
||||||
ModeMessage::setCmdModeMessage(msg, acs::AcsMode::SAFE, 0);
|
ModeMessage::setCmdModeMessage(msg, acs::AcsMode::SAFE, 0);
|
||||||
ReturnValue_t result =
|
ReturnValue_t result =
|
||||||
MessageQueueSenderIF::sendMessage(sysQueueId, &msg, MessageQueueIF::NO_QUEUE, false);
|
MessageQueueSenderIF::sendMessage(sysQueueId, &msg, MessageQueueIF::NO_QUEUE, false);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
sif::error << "Sending safe mode command to EIVE system failed" << std::endl;
|
sif::error << "Sending safe mode command to EIVE system failed" << std::endl;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
ModeMessage::setModeAnnounceMessage(msg, true);
|
||||||
|
ReturnValue_t result =
|
||||||
|
MessageQueueSenderIF::sendMessage(sysQueueId, &msg, MessageQueueIF::NO_QUEUE, false);
|
||||||
|
if (result != returnvalue::OK) {
|
||||||
|
sif::error << "Sending safe mode command to EIVE system failed" << std::endl;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -59,23 +59,23 @@ ReturnValue_t RwPollingTask::performOperation(uint8_t operationCode) {
|
|||||||
if (readAllRws(rws::SET_SPEED) != returnvalue::OK) {
|
if (readAllRws(rws::SET_SPEED) != returnvalue::OK) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
prepareSimpleCommand(rws::GET_LAST_RESET_STATUS);
|
// prepareSimpleCommand(rws::GET_LAST_RESET_STATUS);
|
||||||
if (writeAndReadAllRws(rws::GET_LAST_RESET_STATUS) != returnvalue::OK) {
|
// if (writeAndReadAllRws(rws::GET_LAST_RESET_STATUS) != returnvalue::OK) {
|
||||||
continue;
|
// continue;
|
||||||
}
|
// }
|
||||||
prepareSimpleCommand(rws::GET_RW_STATUS);
|
// prepareSimpleCommand(rws::GET_RW_STATUS);
|
||||||
if (writeAndReadAllRws(rws::GET_RW_STATUS) != returnvalue::OK) {
|
// if (writeAndReadAllRws(rws::GET_RW_STATUS) != returnvalue::OK) {
|
||||||
continue;
|
// continue;
|
||||||
}
|
// }
|
||||||
prepareSimpleCommand(rws::GET_TEMPERATURE);
|
// prepareSimpleCommand(rws::GET_TEMPERATURE);
|
||||||
if (writeAndReadAllRws(rws::GET_TEMPERATURE) != returnvalue::OK) {
|
// if (writeAndReadAllRws(rws::GET_TEMPERATURE) != returnvalue::OK) {
|
||||||
continue;
|
// continue;
|
||||||
}
|
// }
|
||||||
prepareSimpleCommand(rws::CLEAR_LAST_RESET_STATUS);
|
// prepareSimpleCommand(rws::CLEAR_LAST_RESET_STATUS);
|
||||||
if (writeAndReadAllRws(rws::CLEAR_LAST_RESET_STATUS) != returnvalue::OK) {
|
// if (writeAndReadAllRws(rws::CLEAR_LAST_RESET_STATUS) != returnvalue::OK) {
|
||||||
continue;
|
// continue;
|
||||||
}
|
// }
|
||||||
handleSpecialRequests();
|
// handleSpecialRequests();
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnvalue::OK;
|
return returnvalue::OK;
|
||||||
@ -208,19 +208,20 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
|
|||||||
int fd = 0;
|
int fd = 0;
|
||||||
gpioId_t gpioId = rwCookie.getChipSelectPin();
|
gpioId_t gpioId = rwCookie.getChipSelectPin();
|
||||||
uint8_t byteRead = 0;
|
uint8_t byteRead = 0;
|
||||||
for (unsigned idx = 0; idx < MAX_RETRIES_REPLY; idx++) {
|
bool exitOuter = false;
|
||||||
result = openSpi(O_RDWR, fd);
|
for (unsigned retryIdx = 0; retryIdx < MAX_RETRIES_REPLY; retryIdx++) {
|
||||||
if (result != returnvalue::OK) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
pullCsLow(gpioId, spiLock, gpioIF);
|
|
||||||
/**
|
/**
|
||||||
* The reaction wheel responds with empty frames while preparing the reply data.
|
* The reaction wheel responds with empty frames while preparing the reply data.
|
||||||
* However, receiving more than 5 empty frames will be interpreted as an error.
|
* However, receiving more than 5 empty frames will be interpreted as an error.
|
||||||
*/
|
*/
|
||||||
for (int idx = 0; idx < 5; idx++) {
|
for (int idx = 0; idx < 5; idx++) {
|
||||||
|
result = openSpi(O_RDWR, fd);
|
||||||
|
if (result != returnvalue::OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
pullCsLow(gpioId, gpioIF);
|
||||||
if (read(fd, &byteRead, 1) != 1) {
|
if (read(fd, &byteRead, 1) != 1) {
|
||||||
sif::error << "RwPollingTask: Read failed" << std::endl;
|
sif::error << "RwPollingTask: Read failed. " << strerror(errno) << std::endl;
|
||||||
pullCsHigh(gpioId, gpioIF);
|
pullCsHigh(gpioId, gpioIF);
|
||||||
closeSpi(fd);
|
closeSpi(fd);
|
||||||
return rws::SPI_READ_FAILURE;
|
return rws::SPI_READ_FAILURE;
|
||||||
@ -235,6 +236,7 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (byteRead != rws::FRAME_DELIMITER) {
|
if (byteRead != rws::FRAME_DELIMITER) {
|
||||||
|
exitOuter = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,8 +246,11 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
|
|||||||
sif::error << "rwSpiCallback::spiCallback: Empty frame timeout" << std::endl;
|
sif::error << "rwSpiCallback::spiCallback: Empty frame timeout" << std::endl;
|
||||||
return rws::NO_REPLY;
|
return rws::NO_REPLY;
|
||||||
}
|
}
|
||||||
TaskFactory::delayTask(5);
|
|
||||||
}
|
}
|
||||||
|
if(exitOuter) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
TaskFactory::delayTask(5);
|
||||||
}
|
}
|
||||||
#if FSFW_HAL_SPI_WIRETAPPING == 1
|
#if FSFW_HAL_SPI_WIRETAPPING == 1
|
||||||
sif::info << "RW start marker detected" << std::endl;
|
sif::info << "RW start marker detected" << std::endl;
|
||||||
@ -448,7 +453,7 @@ ReturnValue_t RwPollingTask::sendOneMessage(int fd, RwCookie& rwCookie) {
|
|||||||
sif::debug << "rwSpiCallback::spiCallback: Mutex or GPIO interface invalid" << std::endl;
|
sif::debug << "rwSpiCallback::spiCallback: Mutex or GPIO interface invalid" << std::endl;
|
||||||
return returnvalue::FAILED;
|
return returnvalue::FAILED;
|
||||||
}
|
}
|
||||||
pullCsLow(gpioId, spiLock, gpioIF);
|
pullCsLow(gpioId, gpioIF);
|
||||||
// Add datalinklayer like specified in the datasheet.
|
// Add datalinklayer like specified in the datasheet.
|
||||||
size_t lenToSend = 0;
|
size_t lenToSend = 0;
|
||||||
rws::encodeHdlc(writeBuffer.data(), writeLen, encodedBuffer.data(), lenToSend);
|
rws::encodeHdlc(writeBuffer.data(), writeLen, encodedBuffer.data(), lenToSend);
|
||||||
@ -461,7 +466,7 @@ ReturnValue_t RwPollingTask::sendOneMessage(int fd, RwCookie& rwCookie) {
|
|||||||
return returnvalue::OK;
|
return returnvalue::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t RwPollingTask::pullCsLow(gpioId_t gpioId, MutexIF* spiLock, GpioIF& gpioIF) {
|
ReturnValue_t RwPollingTask::pullCsLow(gpioId_t gpioId, GpioIF& gpioIF) {
|
||||||
ReturnValue_t result = spiLock->lockMutex(TIMEOUT_TYPE, TIMEOUT_MS);
|
ReturnValue_t result = spiLock->lockMutex(TIMEOUT_TYPE, TIMEOUT_MS);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
sif::debug << "RwPollingTask::pullCsLow: Failed to lock mutex" << std::endl;
|
sif::debug << "RwPollingTask::pullCsLow: Failed to lock mutex" << std::endl;
|
||||||
|
@ -74,7 +74,7 @@ class RwPollingTask : public SystemObject, public ExecutableObjectIF, public Dev
|
|||||||
|
|
||||||
ReturnValue_t readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) override;
|
ReturnValue_t readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) override;
|
||||||
ReturnValue_t openSpi(int flags, int& fd);
|
ReturnValue_t openSpi(int flags, int& fd);
|
||||||
ReturnValue_t pullCsLow(gpioId_t gpioId, MutexIF* spiLock, GpioIF& gpioIF);
|
ReturnValue_t pullCsLow(gpioId_t gpioId, GpioIF& gpioIF);
|
||||||
void prepareSimpleCommand(DeviceCommandId_t id);
|
void prepareSimpleCommand(DeviceCommandId_t id);
|
||||||
ReturnValue_t prepareSetSpeedCmd(uint8_t rwIdx);
|
ReturnValue_t prepareSetSpeedCmd(uint8_t rwIdx);
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ static constexpr Event ERROR_STATE = MAKE_EVENT(1, severity::HIGH);
|
|||||||
static constexpr Event RESET_OCCURED = event::makeEvent(SUBSYSTEM_ID, 2, severity::LOW);
|
static constexpr Event RESET_OCCURED = event::makeEvent(SUBSYSTEM_ID, 2, severity::LOW);
|
||||||
|
|
||||||
//! Minimal delay as specified by the datasheet.
|
//! Minimal delay as specified by the datasheet.
|
||||||
static const uint32_t SPI_REPLY_DELAY = 20000; // us
|
static const uint32_t SPI_REPLY_DELAY = 70000; // us
|
||||||
|
|
||||||
enum PoolIds : lp_id_t {
|
enum PoolIds : lp_id_t {
|
||||||
TEMPERATURE_C,
|
TEMPERATURE_C,
|
||||||
|
@ -167,7 +167,7 @@ bool RwAssembly::isUseable(object_id_t object, Mode_t mode) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t RwAssembly::initialize() { return SubsystemBase::initialize(); }
|
ReturnValue_t RwAssembly::initialize() { return AssemblyBase::initialize(); }
|
||||||
|
|
||||||
void RwAssembly::handleModeTransitionFailed(ReturnValue_t result) {
|
void RwAssembly::handleModeTransitionFailed(ReturnValue_t result) {
|
||||||
if (targetMode == MODE_OFF) {
|
if (targetMode == MODE_OFF) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user