Index: firmware/App/Monitors/Level.c =================================================================== diff -u -r2205857f59dd884c4af450239381387cfb560c2e -rc9aa3971be05f25a7b0d7124e57cc60617c90ad7 --- firmware/App/Monitors/Level.c (.../Level.c) (revision 2205857f59dd884c4af450239381387cfb560c2e) +++ firmware/App/Monitors/Level.c (.../Level.c) (revision c9aa3971be05f25a7b0d7124e57cc60617c90ad7) @@ -8,10 +8,10 @@ * @file Level.c * * @author (last) Sean Nash -* @date (last) 09-Nov-2024 +* @date (last) 19-Nov-2024 * * @author (original) Sean Nash -* @date (original) 09-Nov-2024 +* @date (original) 19-Nov-2024 * ***************************************************************************/ @@ -36,16 +36,17 @@ /// Level status structure typedef struct { - OVERRIDE_U32_T status; ///< Level status. + OVERRIDE_U32_T level; ///< Level state. + U32 PriorRawLevel; ///< Prior level state (not debounced). U32 debounceStartTime; ///< Debounce start time. U32 debounceTime; ///< Debounce time -} LEVEL_STATUS_T; +} LEVEL_STATE_REC_T; // ********** private data ********** -static U32 levelsDataPublicationCounter; ///< Level data publication counter. +static LEVEL_STATE_REC_T levelState; ///< Level state for floater level sensor. static OVERRIDE_U32_T levelsDataPublishInterval; ///< Interval (in ms) at which to publish Level data to CAN bus. -static LEVEL_STATUS_T levelsStatus[ NUM_OF_LEVELS ]; ///< Level status array. +static U32 levelsDataPublicationCounter; ///< Level data publication counter. // ********** private function prototypes ********** @@ -60,20 +61,14 @@ *************************************************************************/ void initLevels( void ) { - U32 level; - levelsDataPublicationCounter = DATA_PUBLISH_COUNTER_START_COUNT; - // Initialize all the Level - for ( level = 0; level < NUM_OF_LEVELS; level++ ) - { - levelsStatus[ level ].status.data = (U32)STATE_HIGH; - levelsStatus[ level ].status.ovData = (U32)STATE_HIGH; - levelsStatus[ level ].status.ovInitData = (U32)STATE_HIGH; - levelsStatus[ level ].status.override = OVERRIDE_RESET; - levelsStatus[ level ].debounceStartTime = 0; - levelsStatus[ level ].debounceTime = LEVEL_DEBOUNCE_TIME_MS; - } + levelState.level.data = (U32)LEVEL_STATE_HIGH; + levelState.level.ovData = (U32)LEVEL_STATE_HIGH; + levelState.level.ovInitData = (U32)LEVEL_STATE_HIGH; + levelState.level.override = OVERRIDE_RESET; + levelState.debounceStartTime = 0; + levelState.debounceTime = LEVEL_DEBOUNCE_TIME_MS; levelsDataPublishInterval.data = LEVEL_DATA_PUB_INTERVAL; levelsDataPublishInterval.ovData = LEVEL_DATA_PUB_INTERVAL; levelsDataPublishInterval.ovInitData = 0; @@ -82,103 +77,61 @@ /*********************************************************************//** * @brief - * The execLevels function executes the floater and level sensor states. - * @details \b Inputs: level sensor and floater reading from FPGA - * @details \b Outputs: levelStatus - * @details \b Alarms: ALARM_ID_RO_SOFTWARE_FAULT when invalid level sensor is set. + * The execLevels function updates and debounces the floater level sensor states. + * @details \b Inputs: level sensor reading from FPGA + * @details \b Outputs: levelState + * @details \b Message \b Sent: MSG_ID_RO_EVENT if debounced level changes state. * @return none *************************************************************************/ void execLevels( void ) { - U32 level; - U32 currentLevelStatus = 0; + U32 currentLevelState = ( getFPGAFloaterState() != 0 ? LEVEL_STATE_LOW : LEVEL_STATE_MEDIUM ); - for ( level = 0; level < NUM_OF_LEVELS; level++ ) + // Check if the current level status is not the same as the recorded data + if ( currentLevelState != levelState.level.data ) { - // Get the current level status -// switch ( level ) -// { -// // Process the status of the Level -// case FLOATER: -// currentLevelStatus = ( getFPGAFloater1Status() != 0 ? STATE_LOW : STATE_MEDIUM ); -// break; -// -//#ifndef _VECTORCAST_ -// default: -// SET_ALARM_WITH_2_U32_DATA( ALARM_ID_RO_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_LEVEL_SELECTED, level ); -// break; -//#endif -// } -// -// // Check if the current level status is not the same as the recorded data -// if ( currentLevelStatus != levelsStatus[ level ].status.data ) -// { -// // If the debounce time is 0, start the timer -// if ( 0 == levelsStatus[ level ].debounceStartTime ) -// { -// levelsStatus[ level ].debounceStartTime = getMSTimerCount(); -// } -// // If the debounce time has been elapsed, update the level sensor status to the new status -// else if ( TRUE == didTimeout( levelsStatus[ level ].debounceStartTime, levelsStatus[ level ].debounceTime ) ) -// { -// switch ( level ) -// { -// case FLOATER: -// SEND_EVENT_WITH_2_U32_DATA( DD_EVENT_FLOATER_1_LEVEL_CHANGE, (U32)levelsStatus[ level ].status.data, (U32)currentLevelStatus ); -// break; -// -//#ifndef _VECTORCAST_ -// default: -// SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_LEVEL_SELECTED, level ); -// break; -//#endif -// } -// -// levelsStatus[ level ].debounceStartTime = 0; -// levelsStatus[ level ].status.data = currentLevelStatus; -// } -// } -// else -// { -// levelsStatus[ level ].debounceStartTime = 0; -// } + // If the debounce time is 0 or the current state not same as prior state, restart the debounce timer + if ( ( 0 == levelState.debounceStartTime ) || ( currentLevelState != levelState.PriorRawLevel ) ) + { + levelState.debounceStartTime = getMSTimerCount(); + } + // If the debounce time has been elapsed, update the level sensor status to the new status + else if ( TRUE == didTimeout( levelState.debounceStartTime, levelState.debounceTime ) ) + { +// TODO SEND_EVENT_WITH_2_U32_DATA( DD_EVENT_FLOATER_1_LEVEL_CHANGE, (U32)levelState.level.data, (U32)currentLevelStatus ); + levelState.debounceStartTime = 0; + levelState.level.data = currentLevelState; + } } + else + { + levelState.debounceStartTime = 0; + } -// publishLevelsData(); + levelState.PriorRawLevel = currentLevelState; + + publishLevelsData(); } /*********************************************************************//** * @brief - * The getLevelStatus function returns the status of the called level sensor. - * @details \b Inputs: levelStatus - * @details \b Outputs: levelStatus - * @details \b Alarms: ALARM_ID_DD_SOFTWARE_FAULT when invalid level sensor - * passed. - * @param levelId which is the sensor that its status is requested - * @return level status + * The getLevelStatus function returns the level state of the floater. + * @details \b Inputs: levelState + * @details \b Outputs: levelState + * @return level state of the floater sensor *************************************************************************/ -//LEVEL_STATE_T getLevelStatus( LELVEL_T levelId ) -//{ -// U32 status = 0; -// -// if ( levelId < NUM_OF_LEVELS ) -// { -// // Assume there is no override -// status = levelsStatus[ levelId ].status.data; -// -// if ( OVERRIDE_KEY == levelsStatus[ levelId ].status.override ) -// { -// status = levelsStatus[ levelId ].status.ovData; -// } -// } -// else -// { -// SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_DD_INVALID_LEVEL_ID, (U32)levelId ) -// } -// -// return (LEVEL_STATE_T)status; -//} +LEVEL_STATE_T getLevelStatus( void ) +{ + U32 status = levelState.level.data; // Assume there is no override + if ( OVERRIDE_KEY == levelState.level.override ) + { + status = levelState.level.ovData; + } + + return (LEVEL_STATE_T)status; +} + /*********************************************************************//** * @brief * The publishLevelsData function broadcasts the level data at the @@ -189,61 +142,56 @@ * sensors data. * @return none *************************************************************************/ -//static void publishLevelsData( void ) -//{ -// if ( ++levelsDataPublicationCounter >= getU32OverrideValue( &levelsDataPublishInterval ) ) -// { -// LEVEL_DATA_T data; -// -// data.floater1Level = (U32)getLevelStatus( FLOATER_1 ); -// data.floater2Level = (U32)getLevelStatus( FLOATER_2 ); -// data.bicarbLevel = (U32)getLevelStatus( BICARB_LEVEL ); -// data.spentDialysateLevel = (U32)getLevelStatus( SPENT_DIALYSATE_LEVEL ); -// -// levelsDataPublicationCounter = 0; -// -// broadcastData( MSG_ID_DD_LEVEL_DATA, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&data, sizeof( LEVEL_DATA_T ) ); -// } -//} +static void publishLevelsData( void ) +{ + if ( ++levelsDataPublicationCounter >= getU32OverrideValue( &levelsDataPublishInterval ) ) + { + LEVEL_DATA_T data; + data.floaterLevel = (U32)getLevelStatus(); + levelsDataPublicationCounter = 0; + broadcastData( MSG_ID_RO_LEVEL_DATA, COMM_BUFFER_OUT_CAN_RO_BROADCAST, (U08*)&data, sizeof( LEVEL_DATA_T ) ); + } +} + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ /*********************************************************************//** * @brief - * The testLevelsDataPublishIntervalOverride function overrides - * the Level publish data interval. + * The testLevelsDataPublishIntervalOverride function overrides the Level + * data publish interval. * @details \b Inputs: levelsDataPublishInterval * @details \b Outputs: levelsDataPublishInterval * @param Override message from Dialin which includes the interval * (in ms) to override the level data broadcast interval to. * @return TRUE if override successful, FALSE if not *************************************************************************/ -//BOOL testLevelsDataPublishIntervalOverride( MESSAGE_T *message ) -//{ -// BOOL result = u32BroadcastIntervalOverride( message, &levelsDataPublishInterval, TASK_PRIORITY_INTERVAL ); -// -// return result; -//} +BOOL testLevelsDataPublishIntervalOverride( MESSAGE_T *message ) +{ + BOOL result = u32BroadcastIntervalOverride( message, &levelsDataPublishInterval, TASK_PRIORITY_INTERVAL ); + return result; +} + /*********************************************************************//** * @brief - * The testLevelStatusOverride function sets the override status - * for a specific level sensor. + * The testLevelStateOverride function sets the override state for the floater + * level sensor. * @details \b Inputs: none - * @details \b Outputs: levelStatus - * @param message Override message from Dialin which includes an ID of - * the level sensor to override and the state to override the level sensor to. + * @details \b Outputs: levelState + * @param message Override message from Dialin which includes the state to + * override the floater level sensor to. * @return TRUE if override successful, FALSE if not *************************************************************************/ -//BOOL testLevelStatusOverride( MESSAGE_T *message ) -//{ -// BOOL result = u32ArrayOverride( message, &levelsStatus[0].status, NUM_OF_LEVELS - 1, 0, NUM_OF_LEVELS_STATES -1 ); -// -// return result; -//} +BOOL testLevelStateOverride( MESSAGE_T *message ) +{ + BOOL result = u32Override( message, &levelState.level, 0, NUM_OF_LEVELS_STATES -1 ); + return result; +} + /**@}*/ Index: firmware/App/Monitors/Level.h =================================================================== diff -u -r2205857f59dd884c4af450239381387cfb560c2e -rc9aa3971be05f25a7b0d7124e57cc60617c90ad7 --- firmware/App/Monitors/Level.h (.../Level.h) (revision 2205857f59dd884c4af450239381387cfb560c2e) +++ firmware/App/Monitors/Level.h (.../Level.h) (revision c9aa3971be05f25a7b0d7124e57cc60617c90ad7) @@ -8,10 +8,10 @@ * @file Level.h * * @author (last) Sean Nash -* @date (last) 09-Nov-2024 +* @date (last) 19-Nov-2024 * * @author (original) Sean Nash -* @date (original) 09-Nov-2024 +* @date (original) 19-Nov-2024 * ***************************************************************************/ @@ -31,37 +31,31 @@ // ********** public definitions ********** -/// DD floater and level sensor enumeration -typedef enum level_names -{ - FLOATER = 0, ///< floater switch low to medium status - NUM_OF_LEVELS ///< Number of levels -} LELVEL_T; - /// floater and level sensor states. typedef enum level_States { - STATE_LOW = 0, ///< Low level - STATE_HIGH, ///< High level - STATE_MEDIUM, ///< Medium level + LEVEL_STATE_LOW = 0, ///< Low level + LEVEL_STATE_HIGH, ///< High level + LEVEL_STATE_MEDIUM, ///< Medium level + LEVEL_STATE_ILLEGAL, ///< Illegal level NUM_OF_LEVELS_STATES ///< Number of level states } LEVEL_STATE_T; /// DD floater and level sensor data publish structure typedef struct { - U32 floater1Level; ///< Floater 1 level + U32 floaterLevel; ///< Floater level } LEVEL_DATA_T; // ********** public function prototypes ********** void initLevels( void ); void execLevels( void ); -//LEVEL_STATE_T getLevelStatus( LELVEL_T levelId ); -// -//BOOL testLevelsDataPublishIntervalOverride( MESSAGE_T *message ); -//BOOL testLevelStatusOverride( MESSAGE_T *message ); +LEVEL_STATE_T getLevelStatus( void ); +BOOL testLevelsDataPublishIntervalOverride( MESSAGE_T *message ); +BOOL testLevelStateOverride( MESSAGE_T *message ); + /**@}*/ #endif Index: firmware/App/Monitors/Pressure.c =================================================================== diff -u -ra3988128df0950e1f03dcb4a5aa53336d8fb3a6f -rc9aa3971be05f25a7b0d7124e57cc60617c90ad7 --- firmware/App/Monitors/Pressure.c (.../Pressure.c) (revision a3988128df0950e1f03dcb4a5aa53336d8fb3a6f) +++ firmware/App/Monitors/Pressure.c (.../Pressure.c) (revision c9aa3971be05f25a7b0d7124e57cc60617c90ad7) @@ -112,6 +112,7 @@ pressuresState = PRESSURE_INIT_STATE; pressuresDataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; + // Initialize pressure sensors driver initPressureSensor(); // Initialize override structures for each pressure sensor @@ -449,7 +450,8 @@ /*********************************************************************//** * @brief * The handlePressuresContReadState function handles the continuous read state - * of the pressures monitor state machine. + * of the pressures monitor state machine. Raw readings are read from driver + * and then filtered via moving average. * @details \b Inputs: pressureFilterCounter * @details \b Outputs: pressure sensor values updated * @return next state @@ -458,9 +460,9 @@ { PRESSURE_STATE_T result = PRESSURE_CONTINUOUS_READ_STATE; - //Get raw pressure value + // Get raw pressure readings readPressureSensors(); - // filter pressure readings + // filter raw pressure readings filterPressureSensors(); return result; Index: firmware/App/Services/FpgaRO.c =================================================================== diff -u -rd8cd7de2f84b26aafc153e2bb665a5058a040bf0 -rc9aa3971be05f25a7b0d7124e57cc60617c90ad7 --- firmware/App/Services/FpgaRO.c (.../FpgaRO.c) (revision d8cd7de2f84b26aafc153e2bb665a5058a040bf0) +++ firmware/App/Services/FpgaRO.c (.../FpgaRO.c) (revision c9aa3971be05f25a7b0d7124e57cc60617c90ad7) @@ -518,4 +518,9 @@ return fpgaSensorReadings.errorCountPri; } +U08 getFPGAFloaterState( void ) +{ + return fpgaSensorReadings.levelSwitch; +} + /**@}*/ Index: firmware/App/Services/FpgaRO.h =================================================================== diff -u -rd8cd7de2f84b26aafc153e2bb665a5058a040bf0 -rc9aa3971be05f25a7b0d7124e57cc60617c90ad7 --- firmware/App/Services/FpgaRO.h (.../FpgaRO.h) (revision d8cd7de2f84b26aafc153e2bb665a5058a040bf0) +++ firmware/App/Services/FpgaRO.h (.../FpgaRO.h) (revision c9aa3971be05f25a7b0d7124e57cc60617c90ad7) @@ -73,6 +73,8 @@ U08 getFPGAPMpReadCount( void ); U08 getFPGAPMpErrorCount( void ); +U08 getFPGAFloaterState( void ); + /**@}*/ #endif Index: firmware/App/Services/Messaging.c =================================================================== diff -u -rd8cd7de2f84b26aafc153e2bb665a5058a040bf0 -rc9aa3971be05f25a7b0d7124e57cc60617c90ad7 --- firmware/App/Services/Messaging.c (.../Messaging.c) (revision d8cd7de2f84b26aafc153e2bb665a5058a040bf0) +++ firmware/App/Services/Messaging.c (.../Messaging.c) (revision c9aa3971be05f25a7b0d7124e57cc60617c90ad7) @@ -3,6 +3,7 @@ #include "BoostPump.h" #include "Compatible.h" +#include "Level.h" #include "Messaging.h" #include "OperationModes.h" #include "PAL.h" @@ -68,7 +69,9 @@ MSG_ID_RO_PRESSURE_READ_COUNT_OVERRIDE_REQUEST, MSG_ID_RO_PRESSURE_ERROR_COUNT_OVERRIDE_REQUEST, MSG_ID_RO_PRESSURE_PUBLISH_INTERVAL_OVERRIDE_REQUEST, - MSG_ID_RO_DEBUG_EVENT + MSG_ID_RO_DEBUG_EVENT, + MSG_ID_RO_LEVEL_PUBLISH_INTERVAL_OVERRIDE_REQUEST, + MSG_ID_RO_LEVEL_OVERRIDE_REQUEST }; /// Message handling function table @@ -88,7 +91,9 @@ &testPressureSensorReadCounterOverride, &testPressureSensorErrorCounterOverride, &testPressureSensorDataPublishIntervalOverride, - &handleUnhandledMsg + &handleUnhandledMsg, + &testLevelsDataPublishIntervalOverride, + &testLevelStateOverride }; #define NUM_OF_FUNCTION_HANDLERS (sizeof(MSG_FUNCTION_HANDLERS) / sizeof(MsgFuncPtr))