Index: firmware/App/Monitors/Level.c =================================================================== diff -u -rbce6e6d1cfb6e8a0b186419416460ead3a44e5e1 -r322747d530c1b8205be257557e53dcfe9caad50a --- firmware/App/Monitors/Level.c (.../Level.c) (revision bce6e6d1cfb6e8a0b186419416460ead3a44e5e1) +++ firmware/App/Monitors/Level.c (.../Level.c) (revision 322747d530c1b8205be257557e53dcfe9caad50a) @@ -28,15 +28,22 @@ */ // ********** 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 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_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 #define LEVEL_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Interval (ms/task time) at which the level data is published on the CAN bus. #define LEVEL_DEBOUNCE_TIME_MS ( MS_PER_SECOND / 10 ) ///< Level debounce time in milliseconds. #define DATA_PUBLISH_COUNTER_START_COUNT 7 ///< Data publish counter start count. /// Level status structure typedef struct { - OVERRIDE_U32_T status; ///< Level status. + U32 priorRawLevel; ///< Prior level state (not debounced). U32 debounceStartTime; ///< Debounce start time. U32 debounceTime; ///< Debounce time } LEVEL_STATUS_T; @@ -47,10 +54,13 @@ 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 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 getFloaterLevelstatus( void ); /*********************************************************************//** * @brief @@ -68,12 +78,13 @@ // Initialize all the Level for ( i = 0; i < NUM_OF_LEVELS; i++ ) { - levelsStatus[ i ].status.data = (U32)STATE_HIGH; - levelsStatus[ i ].status.ovData = (U32)STATE_HIGH; - levelsStatus[ i ].status.ovInitData = (U32)STATE_HIGH; - levelsStatus[ i ].status.override = OVERRIDE_RESET; + status[ i ].data = (U32)LEVEL_STATE_HIGH; + status[ i ].ovData = (U32)LEVEL_STATE_HIGH; + status[ i ].ovInitData = (U32)LEVEL_STATE_HIGH; + status[ i ].override = OVERRIDE_RESET; levelsStatus[ i ].debounceStartTime = 0; levelsStatus[ i ].debounceTime = LEVEL_DEBOUNCE_TIME_MS; + levelsStatus[ i ].priorRawLevel = (U32)LEVEL_STATE_HIGH; } } @@ -97,24 +108,18 @@ switch ( i ) { // Process the status of the Level - case FLOATER_1: - //currentLevelStatus = ( getFPGAFloater1Status() != 0 ? STATE_LOW : STATE_MEDIUM ); - currentLevelStatus = ( getFPGAFloater1Status() != TRUE ? STATE_LOW : STATE_HIGH ); + case D6_LEVL: + currentLevelStatus = getFloaterLevelstatus(); break; - case FLOATER_2: - // TODO: Commenting for alpha protoype - //currentLevelStatus = ( getFPGAFloater2Status() != 0 ? STATE_MEDIUM : STATE_HIGH ); + case D63_LEVL: + currentLevelStatus = ( processLevelCount( getFPGAD63LevelSensor() ) == 0 ? LEVEL_STATE_LOW : LEVEL_STATE_HIGH ); break; - case BICARB_LEVEL: - currentLevelStatus = ( getFPGALevelSensor1() != 0 ? STATE_LOW : STATE_HIGH ); + case D46_LEVL: + currentLevelStatus = ( processLevelCount( getFPGAD46LevelSensor() ) == 0 ? LEVEL_STATE_LOW : LEVEL_STATE_HIGH ); break; - case SPENT_DIALYSATE_LEVEL: - currentLevelStatus = ( getFPGALevelSensor2() != 0 ? STATE_LOW : STATE_HIGH ); - break; - #ifndef _VECTORCAST_ default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_LEVEL_SELECTED, i ); @@ -123,10 +128,10 @@ } // Check if the current level status is not the same as the recorded data - if ( currentLevelStatus != levelsStatus[ i ].status.data ) + if ( currentLevelStatus != status[ i ].data ) { // If the debounce time is 0, start the timer - if ( 0 == levelsStatus[ i ].debounceStartTime ) + if ( ( 0 == levelsStatus[ i ].debounceStartTime ) || ( currentLevelStatus != levelsStatus[i].priorRawLevel ) ) { levelsStatus[ i ].debounceStartTime = getMSTimerCount(); } @@ -135,22 +140,18 @@ { switch ( i ) { - case FLOATER_1: - SEND_EVENT_WITH_2_U32_DATA( DD_EVENT_FLOATER_1_LEVEL_CHANGE, (U32)levelsStatus[ i ].status.data, (U32)currentLevelStatus ); + case D6_LEVL: + SEND_EVENT_WITH_2_U32_DATA( DD_EVENT_D6_LEVL_CHANGE, (U32)status[ i ].data, (U32)currentLevelStatus ); break; - case FLOATER_2: - SEND_EVENT_WITH_2_U32_DATA( DD_EVENT_FLOATER_2_LEVEL_CHANGE, (U32)levelsStatus[ i ].status.data, (U32)currentLevelStatus ); + case D63_LEVL: + SEND_EVENT_WITH_2_U32_DATA( DD_EVENT_D63_LEVL_CHANGE, (U32)status[ i ].data, (U32)currentLevelStatus ); break; - case BICARB_LEVEL: - SEND_EVENT_WITH_2_U32_DATA( DD_EVENT_BICARB_LEVEL_CHANGE, (U32)levelsStatus[ i ].status.data, (U32)currentLevelStatus ); + case D46_LEVL: + SEND_EVENT_WITH_2_U32_DATA( DD_EVENT_D46_LEVL_CHANGE, (U32)status[ i ].data, (U32)currentLevelStatus ); break; - case SPENT_DIALYSATE_LEVEL: - SEND_EVENT_WITH_2_U32_DATA( DD_EVENT_SPENT_DIALYSATE_LEVEL_CHANGE, (U32)levelsStatus[ i ].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, i ); @@ -159,13 +160,15 @@ } levelsStatus[ i ].debounceStartTime = 0; - levelsStatus[ i ].status.data = currentLevelStatus; + status[ i ].data = currentLevelStatus; } } else { levelsStatus[ i ].debounceStartTime = 0; } + + levelsStatus[i].priorRawLevel = currentLevelStatus; } publishLevelsData(); @@ -183,28 +186,87 @@ *************************************************************************/ LEVEL_STATE_T getLevelStatus( LELVEL_T levelId ) { - U32 status = 0; + U32 stat = 0; if ( levelId < NUM_OF_LEVELS ) { // Assume there is no override - status = levelsStatus[ levelId ].status.data; + stat = status[ levelId ].data; - if ( OVERRIDE_KEY == levelsStatus[ levelId ].status.override ) + if ( OVERRIDE_KEY == status[ levelId ].override ) { - status = levelsStatus[ levelId ].status.ovData; + stat = status[ levelId ].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; + return (LEVEL_STATE_T)stat; } /*********************************************************************//** * @brief + * The processLevelCount function checks the range of count reported by FPGA + * and determine level based on the count. + * @details \b Inputs: none + * @details \b Outputs: level + * @param count The level count reported by FPGA + * @return level status + *************************************************************************/ +static BOOL processLevelCount( U16 count ) +{ + BOOL level = FALSE; + + // Check the level count with in the high level range + if ( ( count >= LEVEL_COUNT_HIGH_START ) && + ( count <= LEVEL_COUNT_HIGH_END ) ) + { + level = TRUE; + } + else + { + level = FALSE; + } + + 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 getFloaterLevelstatus( void ) +{ + LEVEL_STATE_T currentLevelStatus = LEVEL_STATE_HIGH; + + if ( FPGA_LEVEL_LOW == getFPGAD6LevelStatus() ) + { + currentLevelStatus = LEVEL_STATE_HIGH ; + } + else if ( FPGA_LEVEL_MEDIUM == getFPGAD6LevelStatus() ) + { + currentLevelStatus = LEVEL_STATE_MEDIUM ; + } + else if ( FPGA_LEVEL_HIGH == getFPGAD6LevelStatus() ) + { + currentLevelStatus = LEVEL_STATE_LOW ; + } + else + { + // TODO - Handle invalid level alarm + currentLevelStatus = LEVEL_STATE_ILLEGAL ; + } + + return currentLevelStatus; +} + +/*********************************************************************//** + * @brief * The publishLevelsData function broadcasts the level data at the * publication interval. * @details \b Inputs: levelsDataPublicationCounter @@ -219,10 +281,9 @@ { 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 ); + data.d6Level = (U32)getLevelStatus( D6_LEVL ); + data.d63Level = (U32)getLevelStatus( D63_LEVL ); + data.d46Level = (U32)getLevelStatus( D46_LEVL ); levelsDataPublicationCounter = 0; @@ -265,7 +326,7 @@ *************************************************************************/ BOOL testLevelStatusOverride( MESSAGE_T *message ) { - BOOL result = u32ArrayOverride( message, &levelsStatus[0].status, NUM_OF_LEVELS - 1, 0, NUM_OF_LEVELS_STATES -1 ); + BOOL result = u32ArrayOverride( message, &status[0], NUM_OF_LEVELS - 1, 0, NUM_OF_LEVELS_STATES -1 ); return result; }