PLOC SUPV Update to newer firmware #316

Merged
muellerr merged 99 commits from mueller/tas_ploc_supv_update into develop 2022-11-18 14:27:13 +01:00
5 changed files with 66 additions and 81 deletions
Showing only changes of commit 32865d1834 - Show all commits

View File

@ -15,21 +15,20 @@
namespace supv { namespace supv {
typedef struct typedef struct {
{ // The most significant bit of msec value is set to 0x80 to indicate that full
// The most significant bit of msec value is set to 0x80 to indicate that full // time and data information is transmitted, when the time has been synced with
// time and data information is transmitted, when the time has been synced with // the reference. If the time has not been synced with reference, then the most
// the reference. If the time has not been synced with reference, then the most // significant bit is set to 0x00. Only the most significant bit is used for
// significant bit is set to 0x00. Only the most significant bit is used for // this purpose (bit 15 of the field tm_msec)
// this purpose (bit 15 of the field tm_msec) uint16_t tm_msec; // miliseconds 0-999;
uint16_t tm_msec; // miliseconds 0-999; uint8_t tm_sec; // seconds after the minute, 0 to 60
uint8_t tm_sec; // seconds after the minute, 0 to 60
// (0 - 60 allows for the occasional leap second) // (0 - 60 allows for the occasional leap second)
uint8_t tm_min; // minutes after the hour, 0 to 59 uint8_t tm_min; // minutes after the hour, 0 to 59
uint8_t tm_hour; // hours since midnight, 0 to 23 uint8_t tm_hour; // hours since midnight, 0 to 23
uint8_t tm_mday; // day of the month, 1 to 31 uint8_t tm_mday; // day of the month, 1 to 31
uint8_t tm_mon; // months 1 to 12 uint8_t tm_mon; // months 1 to 12
uint8_t tm_year; // years since 1900 uint8_t tm_year; // years since 1900
} tas_time_t; } tas_time_t;
/** Command IDs */ /** Command IDs */
@ -130,23 +129,23 @@ static constexpr uint16_t APID_MEM_MAN = 0x05;
static constexpr uint16_t APID_DATA_LOGGER = 0x06; static constexpr uint16_t APID_DATA_LOGGER = 0x06;
static constexpr uint16_t APID_WDOG_MAN = 0x07; static constexpr uint16_t APID_WDOG_MAN = 0x07;
enum class HkServiceIds: uint8_t { enum class HkServiceIds : uint8_t {
ENABLE = 0x01, ENABLE = 0x01,
SET_PERIOD = 0x02, SET_PERIOD = 0x02,
GET_REPORT = 0x03, GET_REPORT = 0x03,
GET_HARDFAULTS_REPORT = 0x04, GET_HARDFAULTS_REPORT = 0x04,
}; };
enum class TmtcServiceIds: uint8_t { enum class TmtcServiceIds : uint8_t {
TIME_REF = 0x03, TIME_REF = 0x03,
GET_SUPV_VERSION = 0x05, GET_SUPV_VERSION = 0x05,
RUN_AUTO_EM_TEST = 0x08, RUN_AUTO_EM_TEST = 0x08,
SET_GPIO = 0x0E, SET_GPIO = 0x0E,
READ_GPIO = 0x0F, READ_GPIO = 0x0F,
GET_MPSOC_POWER_INFO = 0x10 GET_MPSOC_POWER_INFO = 0x10
}; };
enum class BootManServiceIds: uint8_t { enum class BootManServiceIds : uint8_t {
START_MPSOC = 0x01, START_MPSOC = 0x01,
SHUTDOWN_MPSOC = 0x02, SHUTDOWN_MPSOC = 0x02,
SELECT_IMAGE = 0x03, SELECT_IMAGE = 0x03,
@ -160,7 +159,7 @@ enum class BootManServiceIds: uint8_t {
FACTORY_FLASH = 0x0C FACTORY_FLASH = 0x0C
}; };
enum class LatchupMonServiceIds: uint8_t { enum class LatchupMonServiceIds : uint8_t {
ENABLE = 0x01, ENABLE = 0x01,
DISABLE = 0x02, DISABLE = 0x02,
SET_ALERT_LIMIT = 0x04, SET_ALERT_LIMIT = 0x04,
@ -169,15 +168,13 @@ enum class LatchupMonServiceIds: uint8_t {
// Right now, none of the commands seem to be implemented, but still // Right now, none of the commands seem to be implemented, but still
// keep the enum here in case some are added // keep the enum here in case some are added
enum class AdcMonServiceIds: uint8_t {}; enum class AdcMonServiceIds : uint8_t {};
enum class DataLoggerServiceIds: uint8_t { enum class DataLoggerServiceIds : uint8_t { FACTORY_RESET = 0x07 };
FACTORY_RESET = 0x07
};
// Right now, none of the commands seem to be implemented, but still // Right now, none of the commands seem to be implemented, but still
// keep the enum here in case some are added // keep the enum here in case some are added
enum class WdogManServiceIds: uint8_t {}; enum class WdogManServiceIds : uint8_t {};
static const uint16_t APID_START_MPSOC = 0xA1; static const uint16_t APID_START_MPSOC = 0xA1;
static const uint16_t APID_SHUTWOWN_MPSOC = 0xA2; static const uint16_t APID_SHUTWOWN_MPSOC = 0xA2;
@ -378,9 +375,7 @@ class SupvTcBase : public ploc::SpTcBase {
SupvTcBase(SupvTcParams params) : ploc::SpTcBase(params) {} SupvTcBase(SupvTcParams params) : ploc::SpTcBase(params) {}
SupvTcBase(SupvTcParams params, uint16_t apid, uint16_t seqCount) SupvTcBase(SupvTcParams params, uint16_t apid, uint16_t seqCount)
: ploc::SpTcBase(params, apid, seqCount) { : ploc::SpTcBase(params, apid, seqCount) {}
}
private: private:
}; };

View File

@ -1,4 +1,4 @@
target_sources( target_sources(
${OBSW_NAME} ${OBSW_NAME}
PRIVATE PlocSupervisorHandler.cpp PlocMemoryDumper.cpp PlocMPSoCHandler.cpp PRIVATE PlocSupervisorHandler.cpp PlocMemoryDumper.cpp PlocMPSoCHandler.cpp
PlocMPSoCHelper.cpp PlocSupvHelper.cpp) PlocMPSoCHelper.cpp PlocSupvUartMan.cpp)

View File

@ -1,8 +1,9 @@
#ifndef MISSION_DEVICES_PLOCSUPERVISORHANDLER_H_ #ifndef MISSION_DEVICES_PLOCSUPERVISORHANDLER_H_
#define MISSION_DEVICES_PLOCSUPERVISORHANDLER_H_ #define MISSION_DEVICES_PLOCSUPERVISORHANDLER_H_
#include <linux/devices/ploc/PlocSupvUartMan.h>
#include "OBSWConfig.h" #include "OBSWConfig.h"
#include "PlocSupvHelper.h"
#include "bsp_q7s/fs/SdCardManager.h" #include "bsp_q7s/fs/SdCardManager.h"
#include "devices/powerSwitcherList.h" #include "devices/powerSwitcherList.h"
#include "fsfw/devicehandlers/DeviceHandlerBase.h" #include "fsfw/devicehandlers/DeviceHandlerBase.h"

View File

@ -1,9 +1,8 @@
#include "PlocSupvHelper.h"
#include <etl/crc16_ccitt.h> #include <etl/crc16_ccitt.h>
#include <fcntl.h> // Contains file controls like O_RDWR #include <fcntl.h> // Contains file controls like O_RDWR
#include <fsfw/filesystem/HasFileSystemIF.h> #include <fsfw/filesystem/HasFileSystemIF.h>
#include <fsfw/tasks/SemaphoreFactory.h> #include <fsfw/tasks/SemaphoreFactory.h>
#include <linux/devices/ploc/PlocSupvUartMan.h>
#include <unistd.h> #include <unistd.h>
#include <cmath> #include <cmath>
@ -90,36 +89,37 @@ ReturnValue_t PlocSupvHelper::initialize() {
} }
ReturnValue_t PlocSupvHelper::performOperation(uint8_t operationCode) { ReturnValue_t PlocSupvHelper::performOperation(uint8_t operationCode) {
lock->lockMutex();
state = InternalState::IDLE;
lock->unlockMutex();
bool putTaskToSleep = false; bool putTaskToSleep = false;
while (true) { while (true) {
semaphore->acquire(); semaphore->acquire();
while (true) { while (true) {
putTaskToSleep = handleUartReception(); putTaskToSleep = handleUartReception();
if (putTaskToSleep) { if (putTaskToSleep) {
performUartShutdown();
break; break;
} }
lock->lockMutex(); lock->lockMutex();
InternalState currentState = state; InternalState currentState = state;
lock->unlockMutex(); lock->unlockMutex();
switch (currentState) { switch (currentState) {
case InternalState::IDLE: { case InternalState::SLEEPING:
case InternalState::GO_TO_SLEEP: {
putTaskToSleep = true; putTaskToSleep = true;
break; break;
} }
case InternalState::FINISH: { case InternalState::LONGER_REQUEST: {
state = InternalState::IDLE; if (handleRunningLongerRequest() == REQUEST_DONE) {
putTaskToSleep = true; MutexGuard mg(lock);
state = InternalState::DEFAULT;
}
break; break;
} }
case InternalState::RUNNING: { case InternalState::DEFAULT: {
putTaskToSleep = handleRunningRequest();
break; break;
} }
} }
if (putTaskToSleep) { if (putTaskToSleep) {
performUartShutdown();
break; break;
} }
} }
@ -133,10 +133,7 @@ bool PlocSupvHelper::handleUartReception() {
if (bytesRead == 0) { if (bytesRead == 0) {
{ {
MutexGuard mg(lock); MutexGuard mg(lock);
if (state == InternalState::FINISH) { if (state == InternalState::GO_TO_SLEEP) {
// Flush received and unread data
tcflush(serialPort, TCIOFLUSH);
state = InternalState::IDLE;
return true; return true;
} }
} }
@ -869,23 +866,15 @@ void PlocSupvHelper::resetSpParams() { spParams.buf = commandBuffer; }
ReturnValue_t PlocSupvHelper::sendMessage(CookieIF* cookie, const uint8_t* sendData, ReturnValue_t PlocSupvHelper::sendMessage(CookieIF* cookie, const uint8_t* sendData,
size_t sendLen) { size_t sendLen) {
ReturnValue_t result;
if (sendData == nullptr or sendLen == 0) { if (sendData == nullptr or sendLen == 0) {
return FAILED; return FAILED;
} }
lock->lockMutex(); lock->lockMutex();
if (state != InternalState::IDLE) { if (state == InternalState::SLEEPING or state == InternalState::LONGER_REQUEST) {
lock->unlockMutex(); lock->unlockMutex();
return FAILED; return FAILED;
} }
tcflush(serialPort, TCIFLUSH);
state = InternalState::RUNNING;
lock->unlockMutex(); lock->unlockMutex();
result = semaphore->release();
if (result != OK) {
std::cout << "PlocSupvHelper::sendMessage: Releasing semaphore failed" << std::endl;
}
return encodeAndSendPacket(sendData, sendLen); return encodeAndSendPacket(sendData, sendLen);
} }
@ -895,7 +884,7 @@ ReturnValue_t PlocSupvHelper::requestReceiveMessage(CookieIF* cookie, size_t req
return returnvalue::OK; return returnvalue::OK;
} }
bool PlocSupvHelper::handleRunningRequest() { ReturnValue_t PlocSupvHelper::handleRunningLongerRequest() {
ReturnValue_t result = OK; ReturnValue_t result = OK;
switch (request) { switch (request) {
case Request::UPDATE: { case Request::UPDATE: {
@ -907,15 +896,11 @@ bool PlocSupvHelper::handleRunningRequest() {
} else { } else {
triggerEvent(SUPV_UPDATE_FAILED, result); triggerEvent(SUPV_UPDATE_FAILED, result);
} }
MutexGuard mg(lock); break;
state = InternalState::IDLE;
return true;
} }
case Request::CHECK_MEMORY: { case Request::CHECK_MEMORY: {
executeFullCheckMemoryCommand(); executeFullCheckMemoryCommand();
MutexGuard mg(lock); break;
state = InternalState::IDLE;
return true;
} }
case Request::CONTINUE_UPDATE: { case Request::CONTINUE_UPDATE: {
result = continueUpdate(); result = continueUpdate();
@ -926,9 +911,7 @@ bool PlocSupvHelper::handleRunningRequest() {
} else { } else {
triggerEvent(SUPV_CONTINUE_UPDATE_FAILED, result); triggerEvent(SUPV_CONTINUE_UPDATE_FAILED, result);
} }
MutexGuard mg(lock); break;
state = InternalState::IDLE;
return true;
} }
case Request::REQUEST_EVENT_BUFFER: { case Request::REQUEST_EVENT_BUFFER: {
result = performEventBufferRequest(); result = performEventBufferRequest();
@ -940,11 +923,9 @@ bool PlocSupvHelper::handleRunningRequest() {
} else { } else {
triggerEvent(SUPV_EVENT_BUFFER_REQUEST_FAILED, result); triggerEvent(SUPV_EVENT_BUFFER_REQUEST_FAILED, result);
} }
MutexGuard mg(lock); break;
state = InternalState::IDLE;
return true;
} }
case Request::HANDLER_DRIVEN: { case Request::DEFAULT: {
break; break;
} }
} }
@ -1037,3 +1018,8 @@ ReturnValue_t PlocSupvHelper::parseRecRingBufForHdlc(size_t& readSize) {
} }
return NO_PACKET_FOUND; return NO_PACKET_FOUND;
} }
void PlocSupvHelper::performUartShutdown() {
tcflush(serialPort, TCIOFLUSH);
state = InternalState::GO_TO_SLEEP;
}

View File

@ -158,11 +158,12 @@ class PlocSupvHelper : public DeviceCommunicationIF,
static uint32_t buildProgParams1(uint8_t percent, uint16_t seqCount); static uint32_t buildProgParams1(uint8_t percent, uint16_t seqCount);
private: private:
static constexpr ReturnValue_t NO_PACKET_FOUND = returnvalue::makeCode(1, 0); static constexpr ReturnValue_t REQUEST_DONE = returnvalue::makeCode(1, 0);
static constexpr ReturnValue_t DECODE_BUF_TOO_SMALL = returnvalue::makeCode(1, 1); static constexpr ReturnValue_t NO_PACKET_FOUND = returnvalue::makeCode(1, 1);
static constexpr ReturnValue_t DECODE_BUF_TOO_SMALL = returnvalue::makeCode(1, 2);
static constexpr ReturnValue_t POSSIBLE_PACKET_LOSS_CONSECUTIVE_START = static constexpr ReturnValue_t POSSIBLE_PACKET_LOSS_CONSECUTIVE_START =
returnvalue::makeCode(1, 2); returnvalue::makeCode(1, 3);
static constexpr ReturnValue_t POSSIBLE_PACKET_LOSS_CONSECUTIVE_END = returnvalue::makeCode(1, 3); static constexpr ReturnValue_t POSSIBLE_PACKET_LOSS_CONSECUTIVE_END = returnvalue::makeCode(1, 4);
static const uint16_t CRC16_INIT = 0xFFFF; static const uint16_t CRC16_INIT = 0xFFFF;
// Event buffer reply will carry 24 space packets with 1016 bytes and one space packet with // Event buffer reply will carry 24 space packets with 1016 bytes and one space packet with
@ -211,17 +212,17 @@ class PlocSupvHelper : public DeviceCommunicationIF,
EventBufferRequest eventBufferReq; EventBufferRequest eventBufferReq;
enum class InternalState { IDLE, RUNNING, FINISH }; enum class InternalState { SLEEPING, DEFAULT, LONGER_REQUEST, GO_TO_SLEEP };
enum class Request { enum class Request {
HANDLER_DRIVEN, DEFAULT,
UPDATE, UPDATE,
CONTINUE_UPDATE, CONTINUE_UPDATE,
REQUEST_EVENT_BUFFER, REQUEST_EVENT_BUFFER,
CHECK_MEMORY, CHECK_MEMORY,
}; };
InternalState state = InternalState::IDLE; InternalState state = InternalState::SLEEPING;
Request request = Request::HANDLER_DRIVEN; Request request = Request::DEFAULT;
#ifdef XIPHOS_Q7S #ifdef XIPHOS_Q7S
SdCardManager* sdcMan = nullptr; SdCardManager* sdcMan = nullptr;
@ -255,7 +256,7 @@ class PlocSupvHelper : public DeviceCommunicationIF,
// Remembers APID to know at which command a procedure failed // Remembers APID to know at which command a procedure failed
uint16_t rememberApid = 0; uint16_t rememberApid = 0;
bool handleRunningRequest(); ReturnValue_t handleRunningLongerRequest();
bool handleUartReception(); bool handleUartReception();
ReturnValue_t encodeAndSendPacket(const uint8_t* sendData, size_t sendLen); ReturnValue_t encodeAndSendPacket(const uint8_t* sendData, size_t sendLen);
@ -367,6 +368,8 @@ class PlocSupvHelper : public DeviceCommunicationIF,
*/ */
ReturnValue_t requestReceiveMessage(CookieIF* cookie, size_t requestLen) override; ReturnValue_t requestReceiveMessage(CookieIF* cookie, size_t requestLen) override;
ReturnValue_t readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) override; ReturnValue_t readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) override;
void performUartShutdown();
}; };
#endif /* BSP_Q7S_DEVICES_PLOCSUPVHELPER_H_ */ #endif /* BSP_Q7S_DEVICES_PLOCSUPVHELPER_H_ */