Index: firmware/App/Monitors/Level.c =================================================================== diff -u -r3b6bf2cb6d15da8cb273cff109d2c4b1ee99d546 -rc07917caced76b53a0ed8f35167fac6f9d8310a4 --- firmware/App/Monitors/Level.c (.../Level.c) (revision 3b6bf2cb6d15da8cb273cff109d2c4b1ee99d546) +++ firmware/App/Monitors/Level.c (.../Level.c) (revision c07917caced76b53a0ed8f35167fac6f9d8310a4) @@ -1,17 +1,17 @@ /************************************************************************** * -* Copyright (c) 2024-2024 Diality Inc. - All Rights Reserved. +* Copyright (c) 2024-2025 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file Level.c * * @author (last) Vinayakam Mani -* @date (last) 11-Oct-2024 +* @date (last) 21-Oct-2025 * * @author (original) Vinayakam Mani -* @date (original) 11-Oct-2024 +* @date (original) 14-Oct-2024 * ***************************************************************************/ @@ -28,11 +28,11 @@ */ // ********** private definitions ********** -#define FPGA_LEVEL_LOW 2 ///< Floater low level status -#define FPGA_LEVEL_MEDIUM 3 ///< Floater medium level status -#define FPGA_LEVEL_HIGH 1 ///< Floater high level status +#define FPGA_LEVEL_LOW 5 ///< Floater low level status +#define FPGA_LEVEL_MEDIUM 4 ///< Floater medium level status +#define FPGA_LEVEL_HIGH 6 ///< Floater high level status #define LEVEL_COUNT_LOW 0xFFFF ///< Level sensor count when fluid level is low or non submerged -#define LEVEL_COUNT_HIGH_START 0x2000 ///< Start range of level sensor count when fluid level is high or submerged +#define LEVEL_COUNT_HIGH_START 0x0000 ///< Start range of level sensor count when fluid level is high or submerged #define LEVEL_COUNT_HIGH_END 0x2FFF ///< End range of level sensor count when fluid level is high or submerged #define LOW_LEVEL_COUNT_TOLERANCE ( ( LEVEL_COUNT_LOW / 100 ) * 1 ) ///< Level sensor count 1% tolerance for low level #define HIGH_LEVEL_COUNT_TOLERANCE ( ( LEVEL_COUNT_HIGH / 100 ) * 1 ) ///< Level sensor count 1% tolerance for high level @@ -51,15 +51,17 @@ // ********** private data ********** static U32 levelsDataPublicationCounter; ///< Level data publication counter. -static OVERRIDE_U32_T levelsDataPublishInterval = { LEVEL_DATA_PUB_INTERVAL, - LEVEL_DATA_PUB_INTERVAL, 0, 0 }; ///< Interval (in ms) at which to publish Level data to CAN bus. +static U32 fplevelsDataPublicationCounter; ///< fp Level data publication counter. +static OVERRIDE_U32_T levelsDataPublishInterval; ///< Interval (in ms) at which to publish Level data to CAN bus. +static OVERRIDE_U32_T fplevelsDataPublishInterval; ///< Interval (in ms/task interval) for FP levels at which to publish valves state to CAN bus. static LEVEL_STATUS_T levelsStatus[ NUM_OF_LEVELS ]; ///< Level status array. static OVERRIDE_U32_T status[ NUM_OF_LEVELS ]; ///< Level status. // ********** private function prototypes ********** static void publishLevelsData( void ); static BOOL processLevelCount( U16 count ); +static LEVEL_STATE_T readFloaterLevelstatus( LEVEL_T levelId ); /*********************************************************************//** * @brief @@ -72,7 +74,15 @@ { U32 i; - levelsDataPublicationCounter = DATA_PUBLISH_COUNTER_START_COUNT; + levelsDataPublicationCounter = DATA_PUBLISH_COUNTER_START_COUNT; + fplevelsDataPublishInterval.data = LEVEL_DATA_PUB_INTERVAL; + fplevelsDataPublishInterval.ovData = LEVEL_DATA_PUB_INTERVAL; + fplevelsDataPublishInterval.ovInitData = 0; + fplevelsDataPublishInterval.override = OVERRIDE_RESET; + levelsDataPublishInterval.data = LEVEL_DATA_PUB_INTERVAL; + levelsDataPublishInterval.ovData = LEVEL_DATA_PUB_INTERVAL; + levelsDataPublishInterval.ovInitData = 0; + levelsDataPublishInterval.override = OVERRIDE_RESET; // Initialize all the Level for ( i = 0; i < NUM_OF_LEVELS; i++ ) @@ -108,25 +118,7 @@ { // Process the status of the Level case D6_LEVL: - if ( FPGA_LEVEL_LOW == getFPGAD6LevelStatus() ) - { - //currentLevelStatus = LEVEL_STATE_LOW ; - currentLevelStatus = LEVEL_STATE_HIGH ; - } - else if ( FPGA_LEVEL_MEDIUM == getFPGAD6LevelStatus() ) - { - currentLevelStatus = LEVEL_STATE_MEDIUM ; - } - else if ( FPGA_LEVEL_HIGH == getFPGAD6LevelStatus() ) - { - //currentLevelStatus = LEVEL_STATE_HIGH ; - currentLevelStatus = LEVEL_STATE_LOW ; - } - else - { - // Handle invalid level - alarm - currentLevelStatus = LEVEL_STATE_ILLEGAL ; - } + currentLevelStatus = readFloaterLevelstatus( D6_LEVL ); break; case D63_LEVL: @@ -137,6 +129,10 @@ currentLevelStatus = ( processLevelCount( getFPGAD46LevelSensor() ) == 0 ? LEVEL_STATE_LOW : LEVEL_STATE_HIGH ); break; + case P25_LEVL: + currentLevelStatus = readFloaterLevelstatus( P25_LEVL ); + break; + #ifndef _VECTORCAST_ default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_LEVEL_SELECTED, i ); @@ -201,7 +197,7 @@ * @param levelId which is the sensor that its status is requested * @return level status *************************************************************************/ -LEVEL_STATE_T getLevelStatus( LELVEL_T levelId ) +LEVEL_STATE_T getLevelStatus( LEVEL_T levelId ) { U32 stat = 0; @@ -237,17 +233,76 @@ BOOL level = FALSE; // Check the level count with in the high level range - if ( ( count >= LEVEL_COUNT_HIGH_START ) && - ( count <= LEVEL_COUNT_HIGH_END ) ) + if ( count <= LEVEL_COUNT_HIGH_END ) { level = TRUE; } + + return level; +} + +/*********************************************************************//** + * @brief + * The getFloaterLevelstatus function gets the floater level reported by FPGA + * @details \b Inputs: FPGA level sensor data + * @details \b Outputs: level + * @return level status + *************************************************************************/ +static LEVEL_STATE_T readFloaterLevelstatus( LEVEL_T levelId ) +{ + LEVEL_STATE_T currentLevelStatus = LEVEL_STATE_HIGH; + U32 levelStatus = 0; + + if ( D6_LEVL == levelId ) + { + levelStatus = getFPGAD6LevelStatus(); + + if ( FPGA_LEVEL_LOW == levelStatus ) + { + currentLevelStatus = LEVEL_STATE_LOW ; + } + else if ( FPGA_LEVEL_MEDIUM == levelStatus ) + { + currentLevelStatus = LEVEL_STATE_MEDIUM ; + } + else if ( FPGA_LEVEL_HIGH == levelStatus ) + { + currentLevelStatus = LEVEL_STATE_HIGH ; + } + else + { + // TODO - Handle invalid level alarm + currentLevelStatus = LEVEL_STATE_ILLEGAL ; + } + } + else if ( P25_LEVL == levelId ) + { + levelStatus = getFPGAP25FloaterState(); + + if ( FPGA_LEVEL_LOW == levelStatus ) + { + currentLevelStatus = LEVEL_STATE_LOW ; + } + else if ( FPGA_LEVEL_MEDIUM == levelStatus ) + { + currentLevelStatus = LEVEL_STATE_MEDIUM ; + } + else if ( FPGA_LEVEL_HIGH == levelStatus ) + { + currentLevelStatus = LEVEL_STATE_HIGH ; + } + else + { + // TODO - Handle invalid level alarm + currentLevelStatus = LEVEL_STATE_ILLEGAL ; + } + } else { - level = FALSE; + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_DD_INVALID_LEVEL_ID, (U32)levelId ) } - return level; + return currentLevelStatus; } /*********************************************************************//** @@ -264,17 +319,26 @@ { if ( ++levelsDataPublicationCounter >= getU32OverrideValue( &levelsDataPublishInterval ) ) { - LEVEL_DATA_T data; + DD_LEVEL_DATA_T data; data.d6Level = (U32)getLevelStatus( D6_LEVL ); data.d63Level = (U32)getLevelStatus( D63_LEVL ); data.d46Level = (U32)getLevelStatus( D46_LEVL ); - //data.spentDialysateLevel = (U32)getFPGAFloater1Status(); levelsDataPublicationCounter = 0; - broadcastData( MSG_ID_DD_LEVEL_DATA, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&data, sizeof( LEVEL_DATA_T ) ); + broadcastData( MSG_ID_DD_LEVEL_DATA, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&data, sizeof( DD_LEVEL_DATA_T ) ); } + + // publish IOFP float states on interval + if ( ++fplevelsDataPublicationCounter >= getU32OverrideValue( &fplevelsDataPublishInterval ) ) + { + FP_LEVEL_DATA_T data; + + data.p25Level = (U32)getLevelStatus( P25_LEVL ); + fplevelsDataPublicationCounter = 0; + broadcastData( MSG_ID_FP_LEVEL_DATA, COMM_BUFFER_OUT_CAN_FP_BROADCAST, (U08*)&data, sizeof( FP_LEVEL_DATA_T ) ); + } } @@ -317,4 +381,45 @@ return result; } +/*********************************************************************//** + * @brief + * The testFPLevelsDataPublishIntervalOverride 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 testFPLevelsDataPublishIntervalOverride( MESSAGE_T *message ) +{ + BOOL result = u32BroadcastIntervalOverride( message, &fplevelsDataPublishInterval, TASK_PRIORITY_INTERVAL ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testFPLevelStateOverride function sets the override state for the floater + * level sensor. + * @details \b Inputs: none + * @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 testFPLevelStateOverride( MESSAGE_T *message ) +{ + BOOL result = FALSE; + TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; + OVERRIDE_TYPE_T ovType = getOverrideArrayPayloadFromMessage( message, &payload ); + + if ( ( payload.index >= FIRST_FP_LEVL ) && ( payload.index <= LAST_FP_LEVL ) ) + { + BOOL result = u32Override( message, &status[0], 0, NUM_OF_LEVELS_STATES -1 ); + } + + return result; +} + /**@}*/