From 9e6ad8807a469d971b5b6dae2c2bc810f355a0db Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 15 Dec 2021 11:20:28 +0100 Subject: [PATCH] clear fault bit for max31865 devies --- bsp_q7s/core/InitMission.cpp | 2 +- fsfw | 2 +- mission/devices/Max31865PT1000Handler.cpp | 24 ++++++++++++++++++- mission/devices/Max31865PT1000Handler.h | 4 +++- .../devicedefinitions/Max31865Definitions.h | 4 ++++ tmtc | 2 +- 6 files changed, 33 insertions(+), 5 deletions(-) diff --git a/bsp_q7s/core/InitMission.cpp b/bsp_q7s/core/InitMission.cpp index 81d972b1..411fbd8d 100644 --- a/bsp_q7s/core/InitMission.cpp +++ b/bsp_q7s/core/InitMission.cpp @@ -199,7 +199,7 @@ void initmission::createPstTasks(TaskFactory& factory, /* Polling Sequence Table Default */ #if OBSW_ADD_SPI_TEST_CODE == 0 FixedTimeslotTaskIF* spiPst = factory.createFixedTimeslotTask( - "PST_TASK_DEFAULT", 70, PeriodicTaskIF::MINIMUM_STACK_SIZE * 4, 3.0, + "PST_TASK_DEFAULT", 70, PeriodicTaskIF::MINIMUM_STACK_SIZE * 4, 2.0, missedDeadlineFunc); result = pst::pstSpi(spiPst); if (result != HasReturnvaluesIF::RETURN_OK) { diff --git a/fsfw b/fsfw index e428568a..54e56ec5 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit e428568a00494c3e3ceb6d0b314baae97d4d8731 +Subproject commit 54e56ec522f485525de7b17458b22132003c5047 diff --git a/mission/devices/Max31865PT1000Handler.cpp b/mission/devices/Max31865PT1000Handler.cpp index ba9c8e08..4cdc75b3 100644 --- a/mission/devices/Max31865PT1000Handler.cpp +++ b/mission/devices/Max31865PT1000Handler.cpp @@ -91,6 +91,10 @@ ReturnValue_t Max31865PT1000Handler::buildNormalDeviceCommand( *id = Max31865Definitions::REQUEST_FAULT_BYTE; return buildCommandFromCommand(*id, nullptr, 0); } + else if(internalState == InternalState::CLEAR_FAULT_BYTE) { + *id = Max31865Definitions::CLEAR_FAULT_BYTE; + return buildCommandFromCommand(*id, nullptr, 0); + } else { return DeviceHandlerBase::NOTHING_TO_SEND; } @@ -155,6 +159,13 @@ ReturnValue_t Max31865PT1000Handler::buildCommandFromCommand( return DeviceHandlerIF::NO_COMMAND_DATA; } } + case(Max31865Definitions::CLEAR_FAULT_BYTE): { + commandBuffer[0] = static_cast(Max31865Definitions::CONFIG_CMD); + commandBuffer[1] = Max31865Definitions::CLEAR_FAULT_BIT_VAL; + DeviceHandlerBase::rawPacketLen = 2; + DeviceHandlerBase::rawPacket = commandBuffer.data(); + return HasReturnvaluesIF::RETURN_OK; + } case(Max31865Definitions::REQUEST_CONFIG): { commandBuffer[0] = static_cast( Max31865Definitions::REQUEST_CONFIG); @@ -233,6 +244,7 @@ void Max31865PT1000Handler::fillCommandAndReplyMap() { insertInCommandAndReplyMap(Max31865Definitions::REQUEST_RTD, 3, &sensorDataset); insertInCommandAndReplyMap(Max31865Definitions::REQUEST_FAULT_BYTE, 3); + insertInCommandAndReplyMap(Max31865Definitions::CLEAR_FAULT_BYTE, 3); } ReturnValue_t Max31865PT1000Handler::scanForReply(const uint8_t *start, @@ -290,6 +302,11 @@ ReturnValue_t Max31865PT1000Handler::scanForReply(const uint8_t *start, *foundLen = 2; internalState = InternalState::RUNNING; } + else if(internalState == InternalState::CLEAR_FAULT_BYTE) { + *foundId = Max31865Definitions::CLEAR_FAULT_BYTE; + *foundLen = 2; + internalState = InternalState::RUNNING; + } else { *foundId = Max31865Definitions::REQUEST_CONFIG; *foundLen = configReplySize; @@ -360,9 +377,14 @@ ReturnValue_t Max31865PT1000Handler::interpretDeviceReply( case(Max31865Definitions::REQUEST_RTD): { // first bit of LSB reply byte is the fault bit uint8_t faultBit = packet[2] & 0b0000'0001; - if(faultBit == 1) { + if(resetFaultBit) { + internalState = InternalState::CLEAR_FAULT_BYTE; + resetFaultBit = false; + } + else if(faultBit == 1) { // Maybe we should attempt to restart it? internalState = InternalState::REQUEST_FAULT_BYTE; + resetFaultBit = true; } // RTD value consists of last seven bits of the LSB reply byte and diff --git a/mission/devices/Max31865PT1000Handler.h b/mission/devices/Max31865PT1000Handler.h index b33ddbe0..60fd2904 100644 --- a/mission/devices/Max31865PT1000Handler.h +++ b/mission/devices/Max31865PT1000Handler.h @@ -96,12 +96,14 @@ private: REQUEST_LOW_THRESHOLD, REQUEST_CONFIG, RUNNING, - REQUEST_FAULT_BYTE + REQUEST_FAULT_BYTE, + CLEAR_FAULT_BYTE }; InternalState internalState = InternalState::NONE; bool commandExecuted = false; + bool resetFaultBit = false; dur_millis_t startTime = 0; uint8_t faultByte = 0; std::array commandBuffer { 0 }; diff --git a/mission/devices/devicedefinitions/Max31865Definitions.h b/mission/devices/devicedefinitions/Max31865Definitions.h index 9b2aa3a2..c9c8255e 100644 --- a/mission/devices/devicedefinitions/Max31865Definitions.h +++ b/mission/devices/devicedefinitions/Max31865Definitions.h @@ -17,13 +17,17 @@ enum PoolIds: lp_id_t { static constexpr DeviceCommandId_t CONFIG_CMD = 0x80; static constexpr DeviceCommandId_t WRITE_HIGH_THRESHOLD = 0x83; static constexpr DeviceCommandId_t WRITE_LOW_THRESHOLD = 0x85; + static constexpr DeviceCommandId_t REQUEST_CONFIG = 0x00; static constexpr DeviceCommandId_t REQUEST_RTD = 0x01; static constexpr DeviceCommandId_t REQUEST_HIGH_THRESHOLD = 0x03; static constexpr DeviceCommandId_t REQUEST_LOW_THRESHOLD = 0x05; static constexpr DeviceCommandId_t REQUEST_FAULT_BYTE = 0x07; +static constexpr DeviceCommandId_t CLEAR_FAULT_BYTE = 0x08; + static constexpr uint32_t MAX31865_SET_ID = REQUEST_RTD; +static constexpr uint8_t CLEAR_FAULT_BIT_VAL = 0b0000'0010; static constexpr size_t MAX_REPLY_SIZE = 5; diff --git a/tmtc b/tmtc index f6a3f792..eca5bba1 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit f6a3f792203bc1f00b10c9760b99a8e83ae2535c +Subproject commit eca5bba1d8df6576a19547d356e676b0fb164d87