From f4b67945cc7e724cda6958859bc68b7a2510bcec Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" <–meierj@irs.uni-stuttgart.de> Date: Wed, 28 Jul 2021 19:34:10 +0200 Subject: [PATCH] wipe mram command --- mission/devices/PlocSupervisorHandler.cpp | 32 ++++++ mission/devices/PlocSupervisorHandler.h | 6 +- .../PlocSupervisorDefinitions.h | 102 ++++++++++++++++++ 3 files changed, 139 insertions(+), 1 deletion(-) diff --git a/mission/devices/PlocSupervisorHandler.cpp b/mission/devices/PlocSupervisorHandler.cpp index e45f7f45..a86993b0 100644 --- a/mission/devices/PlocSupervisorHandler.cpp +++ b/mission/devices/PlocSupervisorHandler.cpp @@ -185,6 +185,15 @@ ReturnValue_t PlocSupervisorHandler::buildCommandFromCommand( prepareSelectNvmCmd(commandData); result = RETURN_OK; break; + } + case(PLOC_SPV::RUN_AUTO_EM_TESTS): { + result = prepareRunAutoEmTest(commandData); + break; + } + case(PLOC_SPV::WIPE_MRAM): { + prepareWipeMramCmd(commandData); + result = RETURN_OK; + break; } default: sif::debug << "PlocSupervisorHandler::buildCommandFromCommand: Command not implemented" @@ -231,6 +240,8 @@ void PlocSupervisorHandler::fillCommandAndReplyMap() { this->insertInCommandMap(PLOC_SPV::COPY_ADC_DATA_TO_MRAM); this->insertInCommandMap(PLOC_SPV::ENABLE_NVMS); this->insertInCommandMap(PLOC_SPV::SELECT_NVM); + this->insertInCommandMap(PLOC_SPV::RUN_AUTO_EM_TESTS); + this->insertInCommandMap(PLOC_SPV::WIPE_MRAM); this->insertInReplyMap(PLOC_SPV::ACK_REPORT, 3, nullptr, PLOC_SPV::SIZE_ACK_REPORT); this->insertInReplyMap(PLOC_SPV::EXE_REPORT, 3, nullptr, PLOC_SPV::SIZE_EXE_REPORT); this->insertInReplyMap(PLOC_SPV::HK_REPORT, 3, &hkset, PLOC_SPV::SIZE_HK_REPORT); @@ -1067,6 +1078,27 @@ void PlocSupervisorHandler::prepareSelectNvmCmd(const uint8_t* commandData) { packetToOutBuffer(packet.getWholeData(), packet.getFullSize()); } +ReturnValue_t PlocSupervisorHandler::prepareRunAutoEmTest(const uint8_t* commandData) { + uint8_t test = *commandData; + if (test != 1 && test != 2) { + return INVALID_TEST_PARAM; + } + PLOC_SPV::RunAutoEmTests packet(test); + packetToOutBuffer(packet.getWholeData(), packet.getFullSize()); + return RETURN_OK; +} + +void PlocSupervisorHandler::prepareWipeMramCmd(const uint8_t* commandData) { + uint8_t offset = 0; + uint32_t start = *(commandData + offset) << 24 | *(commandData + offset + 1) << 16 + | *(commandData + offset + 2) << 8 | *(commandData + offset + 3); + offset += 4; + uint32_t stop = *(commandData + offset) << 24 | *(commandData + offset + 1) << 16 + | *(commandData + offset + 2) << 8 | *(commandData + offset + 3); + PLOC_SPV::MramCmd packet(start, stop, PLOC_SPV::MramCmd::MramAction::WIPE); + packetToOutBuffer(packet.getWholeData(), packet.getFullSize()); +} + void PlocSupervisorHandler::packetToOutBuffer(uint8_t* packetData, size_t fullSize) { memcpy(commandBuffer, packetData, fullSize); rawPacket = commandBuffer; diff --git a/mission/devices/PlocSupervisorHandler.h b/mission/devices/PlocSupervisorHandler.h index f1c29554..723f8cfe 100644 --- a/mission/devices/PlocSupervisorHandler.h +++ b/mission/devices/PlocSupervisorHandler.h @@ -70,7 +70,9 @@ private: //! [EXPORT] : [COMMENT] Received latchup config command with invalid latchup ID static const ReturnValue_t INVALID_LATCHUP_ID = MAKE_RETURN_CODE(0xA8); //! [EXPORT] : [COMMENT] Received set adc sweep period command with invalid sweep period. Must be larger than 21. - static const ReturnValue_t SWEEP_PERIOD_TOO_SMALL = MAKE_RETURN_CODE(0x9); + static const ReturnValue_t SWEEP_PERIOD_TOO_SMALL = MAKE_RETURN_CODE(0xA9); + //! [EXPORT] : [COMMENT] Receive auto EM test command with invalid test param. Valid params are 1 and 2. + static const ReturnValue_t INVALID_TEST_PARAM = MAKE_RETURN_CODE(0xAA); static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PLOC_SUPERVISOR_HANDLER; @@ -233,6 +235,8 @@ private: void prepareSetAdcThresholdCmd(const uint8_t* commandData); void prepareEnableNvmsCmd(const uint8_t* commandData); void prepareSelectNvmCmd(const uint8_t* commandData); + ReturnValue_t prepareRunAutoEmTest(const uint8_t* commandData); + void prepareWipeMramCmd(const uint8_t* commandData); /** diff --git a/mission/devices/devicedefinitions/PlocSupervisorDefinitions.h b/mission/devices/devicedefinitions/PlocSupervisorDefinitions.h index 10486b24..ce1400be 100644 --- a/mission/devices/devicedefinitions/PlocSupervisorDefinitions.h +++ b/mission/devices/devicedefinitions/PlocSupervisorDefinitions.h @@ -1049,6 +1049,108 @@ private: } }; +/** + * @brief This class packages the space packet to run auto EM tests. + */ +class RunAutoEmTests: public SpacePacket { +public: + + /** + * @brief Constructor + * + * @param test 1 - complete EM test, 2 - Short test (only memory readback NVM0,1,3) + */ + RunAutoEmTests(uint8_t test) : + SpacePacket(DATA_FIELD_LENGTH - 1, true, APID_RUN_AUTO_EM_TESTS, + DEFAULT_SEQUENCE_COUNT), test(test) { + initPacket(); + } + +private: + + static const uint16_t DATA_FIELD_LENGTH = 3; + static const uint16_t DEFAULT_SEQUENCE_COUNT = 1; + + static const uint16_t CRC_OFFSET = DATA_FIELD_LENGTH - 2; + + uint8_t test = 0; + + void initPacket() { + size_t serializedSize = 0; + uint8_t* data_field_ptr = this->localData.fields.buffer; + SerializeAdapter::serialize(&test, &data_field_ptr, &serializedSize, + sizeof(test), SerializeIF::Endianness::BIG); + serializedSize = 0; + uint16_t crc = CRC::crc16ccitt(this->localData.byteStream, + sizeof(CCSDSPrimaryHeader) + DATA_FIELD_LENGTH - 2); + uint8_t* crcPos = this->localData.fields.buffer + CRC_OFFSET; + SerializeAdapter::serialize(&crc, &crcPos, &serializedSize, sizeof(crc), + SerializeIF::Endianness::BIG); + } +}; + +/** + * @brief This class packages the space packet to wipe or dump parts of the MRAM. + */ +class MramCmd: public SpacePacket { +public: + + enum class MramAction { + WIPE, + DUMP + }; + + /** + * @brief Constructor + * + * @param start Start address of the MRAM section to wipe or dump + * @param stop End address of the MRAM section to wipe or dump + * @param action Dump or wipe MRAM + */ + MramCmd(uint32_t start, uint32_t stop, MramAction action) : + SpacePacket(DATA_FIELD_LENGTH - 1, true, APID_IDLE_PACKET, + DEFAULT_SEQUENCE_COUNT), start(start), stop(stop) { + if(action == MramAction::WIPE) { + this->setAPID(APID_WIPE_MRAM); + } + else if (action == MramAction::DUMP) { + this->setAPID(APID_DUMP_MRAM); + } + else { + sif::debug << "WipeMram: Invalid action specified"; + } + initPacket(); + } + +private: + + static const uint16_t DATA_FIELD_LENGTH = 8; + static const uint16_t DEFAULT_SEQUENCE_COUNT = 1; + + static const uint16_t CRC_OFFSET = DATA_FIELD_LENGTH - 2; + + uint32_t start = 0; + uint32_t stop = 0; + + void initPacket() { + uint8_t concatBuffer[6]; + concatBuffer[0] = static_cast(start >> 16); + concatBuffer[1] = static_cast(start >> 8); + concatBuffer[2] = static_cast(start); + concatBuffer[3] = static_cast(stop >> 16); + concatBuffer[4] = static_cast(stop >> 8); + concatBuffer[5] = static_cast(stop); + uint8_t* data_field_ptr = this->localData.fields.buffer; + std::memcpy(data_field_ptr, concatBuffer, sizeof(concatBuffer)); + size_t serializedSize = 0; + uint16_t crc = CRC::crc16ccitt(this->localData.byteStream, + sizeof(CCSDSPrimaryHeader) + DATA_FIELD_LENGTH - 2); + uint8_t* crcPos = this->localData.fields.buffer + CRC_OFFSET; + SerializeAdapter::serialize(&crc, &crcPos, &serializedSize, sizeof(crc), + SerializeIF::Endianness::BIG); + } +}; + /** * @brief This dataset stores the boot status report of the supervisor. */