Index: firmware/App/Controllers/BPModule.c =================================================================== diff -u --- firmware/App/Controllers/BPModule.c (revision 0) +++ firmware/App/Controllers/BPModule.c (revision 750cdff300aa45c5eb5c651cb1b9a09c859ba268) @@ -0,0 +1,199 @@ +/************************************************************************** +* +* Copyright (c) 2026 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 BPModule.c +* +* @author (last) Varshini Nagabooshanam +* @date (last) 18-May-2026 +* +* @author (original) Varshini Nagabooshanam +* @date (original) 18-May-2026 +* +***************************************************************************/ + +#include "AlarmDefs.h" +#include "BPDriver.h" +#include "BPModule.h" +#include "FpgaTD.h" + +/** + * @addtogroup BPModule + * @{ + */ + +// ********** private definitions ********** + +#define BP_SYSTOLIC_LOW_LIMIT 90 ///< Low systolic blood pressure threshold in mmHg +#define BP_SYSTOLIC_HIGH_LIMIT 180 ///< High systolic blood pressure threshold in mmHG +#define BP_HEART_RATE_LOW_LIMIT 40 ///< Low heart rate threshold in BPM +#define BP_HEART_RATE_HIGH_LIMIT 180 ///< High heart rate threshold in BPM +#define BP_LOW_SYSTOLIC_MAX_COUNT 3 ///< Maximum consecutive low systolic pressure events. + +/// Blood pressure module states. +typedef enum +{ + BP_MODULE_IDLE_STATE = 0, ///< Blood Pressure idle state. + BP_MODULE_MEASURE_STATE, ///< Blood pressure measurement state + BP_MODULE_CHECK_STATE, ///< Blood pressure validation state +} BP_MODULE_STATE_T; + +// ********** private data ********** + +static BP_MODULE_STATE_T bpModuleState = BP_MODULE_IDLE_STATE; ///< Current blood pressure module state. +static BP_RESULTS_T bpModuleResults; ///< Latest blood pressure measurement results. +static U08 lowSystolicCount; ///< Consecutive low systolic pressure counter. + +// ********** private function prototypes ********** + +static void checkBloodPressureReading( void ); + +/*********************************************************************//** +* @brief +* The initBPModule function initializes the blood pressure module. +* @details \b Inputs: none +* @details \b Outputs: bpModuleState +* @return none +***************************************************************************/ +void initBPModule( void ) +{ + initBPDriver(); + bpModuleState = BP_MODULE_IDLE_STATE; +} + +/*********************************************************************//** +* @brief +* The execBPModule function executes the blood pressure module state +* machine. +* @details \b Inputs: bpModuleState +* @details \b Outputs: bpModuleState, bpModuleResults +* @return none +***************************************************************************/ +void execBPModule( void ) +{ + switch ( bpModuleState ) + { + case BP_MODULE_IDLE_STATE: + { + break; + } + + case BP_MODULE_MEASURE_STATE: + { + execBPDriver(); + + if ( TRUE == isBPMeasurementReady() ) + { + ( void )getBPResults( &bpModuleResults ); + bpModuleState = BP_MODULE_CHECK_STATE; + } + else if ( TRUE == hasBPDriverError() ) + { + activateAlarm( ALARM_ID_TD_BP_MODULE_ERROR ); + bpModuleState = BP_MODULE_IDLE_STATE; + } + break; + } + + case BP_MODULE_CHECK_STATE: + { + checkBloodPressureReading(); + bpModuleState = BP_MODULE_IDLE_STATE; + break; + } + + default: + { + bpModuleState = BP_MODULE_IDLE_STATE; + break; + } + } +} + +/*********************************************************************//** +* @brief +* The initiateAdultBPReading function initiates an adult blood pressure +* measurement. +* @details \b Inputs: none +* @details \b Outputs: bpModuleState +* @return none +***************************************************************************/ +void initiateAdultBPReading( void ) +{ + startAdultBPMeasurement(); + bpModuleState = BP_MODULE_MEASURE_STATE; +} + +/*********************************************************************//** +* @brief +* The initiatePedsBPReading function initiates a pediatric blood pressure +* measurement. +* @details \b Inputs: none +* @details \b Outputs: bpModuleState +* @return none +***************************************************************************/ +void initiatePedsBPReading( void ) +{ + startPedsBPMeasurement(); + bpModuleState = BP_MODULE_MEASURE_STATE; +} + +/*********************************************************************//** +* @brief +* The abortBPReading function aborts the active blood pressure +* measurement. +* @details \b Inputs: none +* @details \b Outputs: bpModuleState +* @return none +***************************************************************************/ +void abortBPReading( void ) +{ + abortBPMeasurement(); + bpModuleState = BP_MODULE_IDLE_STATE; +} + +/*********************************************************************//** +* @brief +* The checkBloodPressureReading function validates blood pressure measurement +* results against configured limits. +* @details \b Inputs: bpModuleResults +* @details \b Outputs: BP alarm +* @return none +***************************************************************************/ +static void checkBloodPressureReading( void ) +{ + if ( bpModuleResults.systolic <= BP_SYSTOLIC_LOW_LIMIT ) + { + activateAlarm( ALARM_ID_TD_BP_SYSTOLIC_LOW ); + lowSystolicCount++; + + if ( lowSystolicCount >= BP_LOW_SYSTOLIC_MAX_COUNT ) + { + activateAlarm( ALARM_ID_TD_BP_SYSTOLIC_LOW_TOO_MANY ); + } + } + + else + { + lowSystolicCount = 0; + } + + if ( bpModuleResults.systolic >= BP_SYSTOLIC_HIGH_LIMIT ) + { + activateAlarm( ALARM_ID_TD_BP_SYSTOLIC_HIGH ); + } + if ( bpModuleResults.heartRate <= BP_HEART_RATE_LOW_LIMIT ) + { + activateAlarm( ALARM_ID_TD_BP_HEART_RATE_LOW ); + } + if ( bpModuleResults.heartRate >= BP_HEART_RATE_HIGH_LIMIT ) + { + activateAlarm( ALARM_ID_TD_BP_HEART_RATE_HIGH ); + } +} + +/**@}*/ + Index: firmware/App/Controllers/BPModule.h =================================================================== diff -u --- firmware/App/Controllers/BPModule.h (revision 0) +++ firmware/App/Controllers/BPModule.h (revision 750cdff300aa45c5eb5c651cb1b9a09c859ba268) @@ -0,0 +1,45 @@ +/************************************************************************** +* +* Copyright (c) 2026 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 BPModule.h +* +* @author (last) Varshini Nagabooshanam +* @date (last) 18-May-2026 +* +* @author (original) Varshini Nagabooshanam +* @date (original) 18-May-2026 +* +***************************************************************************/ + +#ifndef __BP_MODULE_H__ +#define __BP_MODULE_H__ + +#include "TDCommon.h" +#include "Types.h" + +/** + * @defgroup BPModule BPModule + * @brief Blood pressure module controller interface. + * + * @addtogroup BPModule + * @{ + */ + + +// ********** public function prototypes **************** + +void initBPModule( void ); +void execBPModule( void ); + +void initiateAdultBPReading( void ); +void initiatePedsBPReading( void ); +void abortBPReading( void ); + + +/**@}*/ + +#endif Index: firmware/App/Drivers/BPDriver.c =================================================================== diff -u --- firmware/App/Drivers/BPDriver.c (revision 0) +++ firmware/App/Drivers/BPDriver.c (revision 750cdff300aa45c5eb5c651cb1b9a09c859ba268) @@ -0,0 +1,216 @@ +/************************************************************************** +* +* Copyright (c) 2026 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 BPDriver.c +* +* @author (last) Varshini Nagabooshanam +* @date (last) 18-May-2026 +* +* @author (original) Varshini Nagabooshanam +* @date (original) 18-May-2026 +* +***************************************************************************/ + +#include "BPDriver.h" +#include "FpgaTD.h" + +/** + * @addtogroup BPDriver + * @{ + */ + +// ********** private definitions ********** + +#define BP_RESP_CODE_MASK 0x3C ///< Blood pressure response code mask. +#define BP_RESP_CODE_SHIFT 2 ///< Blood pressure response code bit shift. +#define BP_MODULE_ERROR_MASK 0x40 ///< Blood pressure module error mask. +#define BP_RESP_CODE_BPDATA 0x07 ///< Blood pressure response code indicating BP data is available. + +// ********** private data ********** + +static BP_DRIVER_STATE_T bpDriverState = BP_DRIVER_IDLE_STATE; ///< Current blood pressure driver state. +static BP_RESULTS_T bpResults; ///< Latest blood pressure measurement results. +static BOOL bpMeasurementReady; ///< Blood pressure measurement ready +static BOOL bpDriverError; ///< Blood pressure driver error flag. + +// ********** private function prototypes ********** + +static U08 getBPResponseCode( void ); + +/*********************************************************************//** + * @brief + * The getBPResponseCode function returns the FPGA NIBP response code. + * @details \b Inputs: FPGA NIBP response register + * @details \b Outputs: none + * @return FPGA NIBP response code. + ***************************************************************************/ +static U08 getBPResponseCode( void ) +{ + return ( ( getNIBPStatusResponse() & BP_RESP_CODE_MASK ) >> BP_RESP_CODE_SHIFT ); +} + +/*********************************************************************//** + * @brief + * The initBPDriver function initializes the blood pressure driver. + * @details \b Inputs: none + * @details \b Outputs: bpDriverState, bpResults, bpErrorCode + * @return none + ***************************************************************************/ +void initBPDriver( void ) +{ + bpDriverState = BP_DRIVER_IDLE_STATE; +} + +/*********************************************************************//** + * @brief + * The execBPDriver function executes the blood pressure driver state + * machine. + * @details \b Inputs: FPGA NIBP registers + * @details \b Outputs: bpDriverState, bpResults + * @return none + ***************************************************************************/ +void execBPDriver( void ) +{ + switch ( bpDriverState ) + { + case BP_DRIVER_IDLE_STATE: + { + // TODO + break; + } + + case BP_DRIVER_MEASURE_STATE: + { + if ( BP_RESP_CODE_BPDATA == getBPResponseCode() ) + { + bpDriverState = BP_DRIVER_GET_DATA_STATE; + } + else if ( ( getNIBPStatusResponse() & BP_MODULE_ERROR_MASK ) != 0 ) + { + bpDriverError = TRUE; + bpDriverState = BP_DRIVER_ERROR_STATE; + } + break; + } + + case BP_DRIVER_GET_DATA_STATE: + { + bpResults.systolic = getNIBPSystolicPressure(); + bpResults.diastolic = getNIBPDiastolicPressure(); + bpResults.heartRate = getNIBPHeartRate(); + bpMeasurementReady = TRUE; + bpDriverState = BP_DRIVER_IDLE_STATE; + break; + } + + case BP_DRIVER_ERROR_STATE: + { + bpDriverState = BP_DRIVER_IDLE_STATE; + break; + } + + default: + { + bpDriverState = BP_DRIVER_IDLE_STATE; + break; + } + } +} + +/*********************************************************************//** + * @brief + * The startAdultBPMeasurement function initiates an adult blood pressure + * measurement. + * @details \b Inputs: none + * @details \b Outputs: bpDriverState + * @return none + ***************************************************************************/ +void startAdultBPMeasurement( void ) +{ + setNIBPCommand( FPGA_NIBP_CMD_START_BP ); + bpMeasurementReady = FALSE; + bpDriverError = FALSE; + bpDriverState = BP_DRIVER_MEASURE_STATE; +} + +/*********************************************************************//** + * @brief + * The startPedsBPMeasurement function initiates a pediatric blood pressure + * measurement. + * @details \b Inputs: none + * @details \b Outputs: bpDriverState + * @return none + ***************************************************************************/ +void startPedsBPMeasurement( void ) +{ + setNIBPCommand( FPGA_NIBP_CMD_START_PEDS_BP ); + bpMeasurementReady = FALSE; + bpDriverError = FALSE; + bpDriverState = BP_DRIVER_MEASURE_STATE; +} + +/*********************************************************************//** + * @brief + * The abortBPMeasurement function aborts the active blood pressure + * measurement. + * @details \b Inputs: none + * @details \b Outputs: bpDriverState + * @return none + ***************************************************************************/ +void abortBPMeasurement( void ) +{ + setNIBPCommand( FPGA_NIBP_CMD_ABORT_BP ); + bpDriverState = BP_DRIVER_IDLE_STATE; +} + +/*********************************************************************//** + * @brief + * The isBPMeasurementReady function returns the blood pressure + * measurement ready state + * @details \b Inputs: bpMeasurementReady + * @details \b Outputs: none + * @return TRUE if measurement ready, FALSE otherwise. + ***************************************************************************/ +BOOL isBPMeasurementReady( void ) +{ + return bpMeasurementReady; +} + +/*********************************************************************//** + * @brief + * The hasBPDriverError function returns the blood pressure driver + * error state. + * @details \b Inputs: bpDriverError + * @details \b Outputs: none + * @return TRUE if module error exists, FALSE otherwise. + ***************************************************************************/ +BOOL hasBPDriverError( void ) +{ + return bpDriverError; +} + +/*********************************************************************//** + * @brief + * The getBPResults function returns the latest BP measurement results. + * @details \b Inputs: bpResults + * @details\b Outputs: results + * @return TRUE if results copied, FALSE otherwise. + ***************************************************************************/ +BOOL getBPResults( BP_RESULTS_T *results ) +{ + BOOL result = FALSE; + + if ( NULL != results ) + { + *results = bpResults; + result = TRUE; + } + + return result; +} + +/**@}*/ Index: firmware/App/Drivers/BPDriver.h =================================================================== diff -u --- firmware/App/Drivers/BPDriver.h (revision 0) +++ firmware/App/Drivers/BPDriver.h (revision 750cdff300aa45c5eb5c651cb1b9a09c859ba268) @@ -0,0 +1,68 @@ +/************************************************************************** +* +* Copyright (c) 2026 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 BPDriver.h +* +* @author (last) Varshini Nagabooshanam +* @date (last) 18-May-2026 +* +* @author (original) Varshini Nagabooshanam +* @date (original) 18-May-2026 +* +***************************************************************************/ + +#ifndef __BPDRIVER_H__ +#define __BPDRIVER_H__ + +// ********** public definitions ********** + +#include "TDCommon.h" +#include "Types.h" + +/** + * @defgroup BPDriver BPDriver + * @brief Blood pressure driver unit. + * + * @addtogroup BPDriver + * @{ + */ + +// ********** public definitions ********** + +/// Blood pressure measurement results. +typedef struct +{ + U16 systolic; ///< Systolic blood pressure in mmHg. + U16 diastolic; ///< Diastolic blood pressure in mmHg. + U16 heartRate; ///< Heart rate in BPM. +} BP_RESULTS_T; + +/// Blood pressure driver states. +typedef enum +{ + BP_DRIVER_IDLE_STATE = 0, ///< Idle state. + BP_DRIVER_MEASURE_STATE, ///< Measurement state. + BP_DRIVER_GET_DATA_STATE, ///< Get data state. + BP_DRIVER_ERROR_STATE ///< Error state. +} BP_DRIVER_STATE_T; + +// ********** public function prototypes ********** + +void initBPDriver( void ); +void execBPDriver( void ); + +void startAdultBPMeasurement( void ); +void startPedsBPMeasurement( void ); +void abortBPMeasurement( void ); + +BOOL isBPMeasurementReady( void ); +BOOL hasBPDriverError( void ); +BOOL getBPResults( BP_RESULTS_T *results ); + +/**@}*/ + +#endif