Index: firmware/App/Controllers/AirTrap.c =================================================================== diff -u -ra2bc96881a5fc3d8f779246b2abebf15a8de9384 -r6b870cd0699bb3ee22b93981d51373a6c2d56162 --- firmware/App/Controllers/AirTrap.c (.../AirTrap.c) (revision a2bc96881a5fc3d8f779246b2abebf15a8de9384) +++ firmware/App/Controllers/AirTrap.c (.../AirTrap.c) (revision 6b870cd0699bb3ee22b93981d51373a6c2d56162) @@ -31,11 +31,14 @@ */ // ********** private definitions ********** + +/// Interval (ms/task time) at which the air trap data is published on the CAN bus. +#define AIR_TRAP_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) +/// Persistence period for illegal level sensors fault. +static const U32 AIR_TRAP_ILLEGAL_LEVELS_PERSISTENCE = ( MS_PER_SECOND * 2 / TASK_PRIORITY_INTERVAL ); +/// Volume (in mL) of venous portion of blood circuit line. TODO - get actual volume from Systems. +#define VENOUS_LINE_VOLUME_ML ( 200.0 ) -#define AIR_TRAP_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Interval (ms/task time) at which the air trap data is published on the CAN bus. -#define AIR_TRAP_ILLEGAL_LEVELS_PERSISTENCE ( MS_PER_SECOND * 2 / TASK_PRIORITY_INTERVAL ) ///< Persistence period for illegal level sensors fault. -#define VENOUS_LINE_VOLUME_ML ( 200.0 ) ///< TODO Volume (in mL) of venous portion of blood circuit line. - /// Defined states for the air trap controller state machine. typedef enum AirTrap_States { Index: firmware/App/Controllers/BloodFlow.c =================================================================== diff -u -r99bd0d8e0325f71dfa0e2608c0a032e6113cc033 -r6b870cd0699bb3ee22b93981d51373a6c2d56162 --- firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision 99bd0d8e0325f71dfa0e2608c0a032e6113cc033) +++ firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision 6b870cd0699bb3ee22b93981d51373a6c2d56162) @@ -53,7 +53,7 @@ #define MIN_BLOOD_PUMP_PWM_DUTY_CYCLE 0.12 ///< Controller will error if PWM duty cycle < 10%, so set min to 12% /// Interval (ms/task time) at which the blood pump is controlled. -#define BP_CONTROL_INTERVAL ( 10000 / TASK_GENERAL_INTERVAL ) +static const U32 BP_CONTROL_INTERVAL = ( 10000 / TASK_GENERAL_INTERVAL ); #define BP_P_COEFFICIENT 0.00035 ///< P term for blood pump control #define BP_I_COEFFICIENT 0.00035 ///< I term for blood pump control @@ -69,13 +69,19 @@ #define BP_MAX_FLOW_VS_SPEED_DIFF_RPM 200.0 ///< Maximum difference between measured speed and speed implied by measured flow. #define BP_MAX_MOTOR_SPEED_WHILE_OFF_RPM 100.0 ///< Maximum motor speed (RPM) while motor is commanded off. #define BP_MAX_ROTOR_VS_MOTOR_DIFF_RPM 5.0 ///< Maximum difference in speed between motor and rotor (in rotor RPM). -#define BP_MAX_MOTOR_SPEED_ERROR_RPM 300.0 ///< Maximum difference in speed between measured and commanded RPM. -#define BP_FLOW_VS_SPEED_PERSIST ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< Persist time (task intervals) for flow vs. motor speed error condition. -#define BP_OFF_ERROR_PERSIST ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< Persist time (task intervals) for motor off error condition. -#define BP_MOTOR_SPEED_ERROR_PERSIST ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< Persist time (task intervals) motor speed error condition. -#define BP_ROTOR_SPEED_ERROR_PERSIST ((12 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< Persist time (task intervals) rotor speed error condition. -#define BP_DIRECTION_ERROR_PERSIST (250 / TASK_PRIORITY_INTERVAL) ///< Persist time (task intervals) pump direction error condition. -#define BP_MAX_ROTOR_SPEED_ERROR_PERSIST ((1 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< Persist time (task intervals) blood pump rotor speed too fast error condition. +#define BP_MAX_MOTOR_SPEED_ERROR_RPM 300.0 ///< Maximum difference in speed between measured and commanded RPM. +/// Persist time (task intervals) for flow vs. motor speed error condition. +static const U32 BP_FLOW_VS_SPEED_PERSIST = ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL); +/// Persist time (task intervals) for motor off error condition. +static const U32 BP_OFF_ERROR_PERSIST = ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL); +/// Persist time (task intervals) motor speed error condition. +static const U32 BP_MOTOR_SPEED_ERROR_PERSIST = ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL); +/// Persist time (task intervals) rotor speed error condition. +static const U32 BP_ROTOR_SPEED_ERROR_PERSIST = ((12 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL); +/// Persist time (task intervals) pump direction error condition. +static const U32 BP_DIRECTION_ERROR_PERSIST = (250 / TASK_PRIORITY_INTERVAL); +/// Persist time (task intervals) blood pump rotor speed too fast error condition. +static const U32 BP_MAX_ROTOR_SPEED_ERROR_PERSIST = ((1 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL); #define BP_MAX_CURR_WHEN_STOPPED_MA 150.0 ///< Motor controller current should not exceed this when pump should be stopped #define BP_MIN_CURR_WHEN_RUNNING_MA 150.0 ///< Motor controller current should always exceed this when pump should be running Index: firmware/App/Controllers/DialInFlow.c =================================================================== diff -u -ra2bc96881a5fc3d8f779246b2abebf15a8de9384 -r6b870cd0699bb3ee22b93981d51373a6c2d56162 --- firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision a2bc96881a5fc3d8f779246b2abebf15a8de9384) +++ firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision 6b870cd0699bb3ee22b93981d51373a6c2d56162) @@ -48,8 +48,9 @@ #define MAX_DIAL_IN_PUMP_PWM_STEP_DN_CHANGE 0.02 ///< Max duty cycle change when ramping down ~ 300 mL/min/s. #define MAX_DIAL_IN_PUMP_PWM_DUTY_CYCLE 0.88 ///< Controller will error if PWM duty cycle > 90%, so set max to 88%. #define MIN_DIAL_IN_PUMP_PWM_DUTY_CYCLE 0.12 ///< Controller will error if PWM duty cycle < 10%, so set min to 12%. - -#define DIP_CONTROL_INTERVAL ( 10000 / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the dialIn pump is controlled + +/// Interval (ms/task time) at which the dialIn pump is controlled. +static const U32 DIP_CONTROL_INTERVAL = ( 10000 / TASK_GENERAL_INTERVAL ); #define DIP_P_COEFFICIENT 0.00035 ///< P term for dialIn pump control. #define DIP_I_COEFFICIENT 0.00035 ///< I term for dialIn pump control. @@ -64,12 +65,18 @@ #define DIP_MAX_FLOW_VS_SPEED_DIFF_RPM 200.0 ///< Maximum difference between measured motor speed and speed implied by measured flow. #define DIP_MAX_MOTOR_SPEED_WHILE_OFF_RPM 100.0 ///< Maximum motor speed (RPM) while motor is commanded off. #define DIP_MAX_ROTOR_VS_MOTOR_DIFF_RPM 5.0 ///< Maximum difference in speed between motor and rotor (in rotor RPM). -#define DIP_MAX_MOTOR_SPEED_ERROR_RPM 300.0 ///< Maximum difference in speed between measured and commanded RPM. -#define DIP_FLOW_VS_SPEED_PERSIST ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< Persist time (task intervals) for flow vs. motor speed error condition. -#define DIP_OFF_ERROR_PERSIST ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< Persist time (task intervals) for motor off error condition. -#define DIP_MOTOR_SPEED_ERROR_PERSIST ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< Persist time (task intervals) motor speed error condition. -#define DIP_ROTOR_SPEED_ERROR_PERSIST ((12 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< Persist time (task intervals) rotor speed error condition. -#define DIP_DIRECTION_ERROR_PERSIST (250 / TASK_PRIORITY_INTERVAL) ///< Persist time (task intervals) pump direction error condition. +#define DIP_MAX_MOTOR_SPEED_ERROR_RPM 300.0 ///< Maximum difference in speed between measured and commanded RPM. + +/// Persist time (task intervals) for flow vs. motor speed error condition. +static const U32 DIP_FLOW_VS_SPEED_PERSIST = ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL); +/// Persist time (task intervals) for motor off error condition. +static const U32 DIP_OFF_ERROR_PERSIST = ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL); +/// Persist time (task intervals) motor speed error condition. +static const U32 DIP_MOTOR_SPEED_ERROR_PERSIST = ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL); +/// Persist time (task intervals) rotor speed error condition. +static const U32 DIP_ROTOR_SPEED_ERROR_PERSIST = ((12 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL); +/// Persist time (task intervals) pump direction error condition. +static const U32 DIP_DIRECTION_ERROR_PERSIST = (250 / TASK_PRIORITY_INTERVAL); #define DIP_MAX_CURR_WHEN_STOPPED_MA 150.0 ///< Motor controller current should not exceed this when pump should be stopped. Index: firmware/App/Controllers/DialOutFlow.c =================================================================== diff -u -r766708fceb0bdf1af8c7897df29d4f5036bfd3db -r6b870cd0699bb3ee22b93981d51373a6c2d56162 --- firmware/App/Controllers/DialOutFlow.c (.../DialOutFlow.c) (revision 766708fceb0bdf1af8c7897df29d4f5036bfd3db) +++ firmware/App/Controllers/DialOutFlow.c (.../DialOutFlow.c) (revision 6b870cd0699bb3ee22b93981d51373a6c2d56162) @@ -51,7 +51,8 @@ #define MAX_DIAL_OUT_PUMP_PWM_DUTY_CYCLE 0.88 ///< Controller will error if PWM duty cycle > 90%, so set max to 88%. #define MIN_DIAL_OUT_PUMP_PWM_DUTY_CYCLE 0.12 ///< Controller will error if PWM duty cycle < 10%, so set min to 12%. -#define DOP_CONTROL_INTERVAL ( 1000 / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the dialysate outlet pump is controlled. +/// Interval (ms/task time) at which the dialysate outlet pump is controlled. +static const U32 DOP_CONTROL_INTERVAL = ( 1000 / TASK_GENERAL_INTERVAL ); #define DOP_P_COEFFICIENT 0.0050 ///< P term for dialysate outlet pump control. #define DOP_I_COEFFICIENT 0.0001 ///< I term for dialysate outlet pump control. @@ -66,11 +67,16 @@ #define DOP_MAX_MOTOR_SPEED_WHILE_OFF_RPM 100.0 ///< Maximum motor speed (RPM) while motor is commanded off. #define DOP_MAX_ROTOR_VS_MOTOR_DIFF_RPM 5.0 ///< Maximum difference in speed between motor and rotor (in rotor RPM). #define DOP_MAX_MOTOR_SPEED_ERROR_RPM 300.0 ///< Maximum difference in speed between measured and commanded RPM. -#define DOP_OFF_ERROR_PERSIST ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< Persist time (task intervals) for motor off error condition. -#define DOP_MOTOR_SPEED_ERROR_PERSIST ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< Persist time (task intervals) motor speed error condition. -#define DOP_ROTOR_SPEED_ERROR_PERSIST ((12 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< Persist time (task intervals) rotor speed error condition. -#define DOP_DIRECTION_ERROR_PERSIST (250 / TASK_PRIORITY_INTERVAL) ///< Persist time (task intervals) pump direction error condition. +/// Persist time (task intervals) for motor off error condition. +static const U32 DOP_OFF_ERROR_PERSIST = ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL); +/// Persist time (task intervals) motor speed error condition. +static const U32 DOP_MOTOR_SPEED_ERROR_PERSIST = ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL); +/// Persist time (task intervals) rotor speed error condition. +static const U32 DOP_ROTOR_SPEED_ERROR_PERSIST = ((12 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL); +/// Persist time (task intervals) pump direction error condition. +static const U32 DOP_DIRECTION_ERROR_PERSIST = (250 / TASK_PRIORITY_INTERVAL); + #define DOP_MAX_CURR_WHEN_STOPPED_MA 150.0 ///< Motor controller current should not exceed this when pump should be stopped. #define DOP_MIN_CURR_WHEN_RUNNING_MA 150.0 ///< Motor controller current should always exceed this when pump should be running. #define DOP_MAX_CURR_WHEN_RUNNING_MA 2000.0 ///< Motor controller current should not exceed this when pump should be running. Index: firmware/App/Controllers/PresOccl.c =================================================================== diff -u -ra997e6d608a9970a948bda978dade1148269ff90 -r6b870cd0699bb3ee22b93981d51373a6c2d56162 --- firmware/App/Controllers/PresOccl.c (.../PresOccl.c) (revision a997e6d608a9970a948bda978dade1148269ff90) +++ firmware/App/Controllers/PresOccl.c (.../PresOccl.c) (revision 6b870cd0699bb3ee22b93981d51373a6c2d56162) @@ -51,13 +51,13 @@ #define VENOUS_PRESSURE_STALE_DATA 2 ///< Venous pressure status bits indicate data is stale (no new data since last fpga read). #define VENOUS_PRESSURE_DIAG_CONDITION 3 ///< Venous pressure status bits diagnostic condition (alarm). -#define MAX_TIME_BETWEEN_VENOUS_READINGS ( 500 / TASK_GENERAL_INTERVAL ) ///< Maximum time without fresh inline venous pressure reading. +static const U32 MAX_TIME_BETWEEN_VENOUS_READINGS = ( 500 / TASK_GENERAL_INTERVAL ); ///< Maximum time without fresh inline venous pressure reading. #define OCCLUSION_THRESHOLD 25000 ///< Threshold above which an occlusion is detected. #define CARTRIDGE_LOADED_THRESHOLD 5000 ///< Threshold above which a cartridge is considered loaded. #define EMPTY_SALINE_BAG_THRESHOLD_MMHG -300.0 ///< Threshold below which the saline bag is considered empty (in mmHg). TODO - get real threshold from Systems -#define EMPTY_SALINE_BAG_PERSISTENCE ( 250 / TASK_GENERAL_INTERVAL ) ///< Time that saline bag looks empty before saying it is empty. TODO - use persistent alarm when updated +static const U32 EMPTY_SALINE_BAG_PERSISTENCE = ( 250 / TASK_GENERAL_INTERVAL ); ///< Time that saline bag looks empty before saying it is empty. TODO - use persistent alarm when updated #define PRES_ALARM_PERSISTENCE ( 1 * MS_PER_SECOND ) ///< Alarm persistence period for pressure alarms. Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -rc539499ea2dee6d62194d573ac93b313d9e2936d -r6b870cd0699bb3ee22b93981d51373a6c2d56162 --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision c539499ea2dee6d62194d573ac93b313d9e2936d) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision 6b870cd0699bb3ee22b93981d51373a6c2d56162) @@ -86,13 +86,17 @@ #define MAX_DEVIATION_FROM_TARGET_IN_COUNTS 150 ///< Maximum deviation from target in counts #define MAX_DEVIATION_FROM_TRAGET_IN_POS_B 1000 ///< Maximum allowed deviation from position B in counts #define MAX_ALLOWED_FAILED_HOMINGS 3U ///< Maximum allowed failed homings -#define HOMING_EDGE_DETECTION_TIME_INTERVAL ( MS_PER_SECOND / ( 2 * TASK_PRIORITY_INTERVAL ) ) ///< The time that the valve must be at the edge to be considered for edge detection +/// The time that the valve must be at the edge to be considered for edge detection +static const U32 HOMING_EDGE_DETECTION_TIME_INTERVAL = ( MS_PER_SECOND / ( 2 * TASK_PRIORITY_INTERVAL ) ); #define VALVES_CURRENT_THRESHOLD_AMPS 1.0 ///< Valves current threshold -#define MAX_OVER_CURRENT_TIME_INTERVAL_COUNTER ( MS_PER_SECOND / ( TASK_PRIORITY_INTERVAL ) ) ///< Valves over current time interval counter -#define MAX_POS_DEVIATION_TIME_INTERVAL_COUNTER ( MS_PER_SECOND / ( TASK_PRIORITY_INTERVAL ) ) ///< Valves out of range time interval counter +/// Valves over current time interval counter +static const U32 MAX_OVER_CURRENT_TIME_INTERVAL_COUNTER = ( MS_PER_SECOND / ( TASK_PRIORITY_INTERVAL ) ); +/// Valves out of range time interval counter +static const U32 MAX_POS_DEVIATION_TIME_INTERVAL_COUNTER = ( MS_PER_SECOND / ( TASK_PRIORITY_INTERVAL ) ); #define VALVE_TRANSITION_TIMEOUT_MS 3000U ///< Valves transition time out in ms -#define VALVES_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Valve data publication time interval +/// Valve data publication time interval +#define VALVES_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) #define VALVE_MAX_ALLOWED_PWM_PERCENT 100U ///< Valve maximum allowed PWM in percent #define VALVE_CW_PWM_TO_CNT_CONVERSION( pwm ) ( ( 20 * pwm ) + 2500 ) ///< Valve clockwise PWM to count conversion Index: firmware/App/Modes/BloodPrime.c =================================================================== diff -u -r4ac6a67ab2876d1f436704fe67a958e17d0b432a -r6b870cd0699bb3ee22b93981d51373a6c2d56162 --- firmware/App/Modes/BloodPrime.c (.../BloodPrime.c) (revision 4ac6a67ab2876d1f436704fe67a958e17d0b432a) +++ firmware/App/Modes/BloodPrime.c (.../BloodPrime.c) (revision 6b870cd0699bb3ee22b93981d51373a6c2d56162) @@ -47,10 +47,10 @@ #define BLOOD_PRIME_INIT_BP_FLOW_RATE_ML_MIN 100 /// Interval at which blood prime ramping is controlled. -#define BLOOD_PRIME_RAMPING_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) +static const U32 BLOOD_PRIME_RAMPING_INTERVAL = ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ); /// Interval at which blood prime progress is to be published to UI. -#define BLOOD_PRIME_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) +static const U32 BLOOD_PRIME_DATA_PUBLISH_INTERVAL = ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ); /// Multiplier to convert flow (mL/min) into volume (mL) for period of general task interval. static const F32 BLOOD_PRIME_FLOW_INTEGRATOR = 1.0 / (F32)( SEC_PER_MIN * ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ); Index: firmware/App/Modes/Dialysis.c =================================================================== diff -u -r161a56481d1a194704b63a5fd55d4c5583fa94df -r6b870cd0699bb3ee22b93981d51373a6c2d56162 --- firmware/App/Modes/Dialysis.c (.../Dialysis.c) (revision 161a56481d1a194704b63a5fd55d4c5583fa94df) +++ firmware/App/Modes/Dialysis.c (.../Dialysis.c) (revision 6b870cd0699bb3ee22b93981d51373a6c2d56162) @@ -42,9 +42,9 @@ #define MAX_UF_RATE_ML_PER_HOUR 2750.0 ///< Maximum ultrafiltration rate in mL/hour #define MAX_UF_ACCURACY_ERROR_ML 250.0 ///< Maximum ultrafiltration accuracy error in mL over the entire treatment. /// Saline bolus data broadcast interval (ms/task time) count. -#define SALINE_BOLUS_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) +static const U32 SALINE_BOLUS_DATA_PUB_INTERVAL = ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ); /// Ultrafiltration rate accuracy check interval count. -#define UF_ACCURACY_CHECK_INTERVAL ((1 * MIN_PER_HOUR * SEC_PER_MIN * MS_PER_SECOND) / TASK_GENERAL_INTERVAL) +static const U32 UF_ACCURACY_CHECK_INTERVAL = ((1 * MIN_PER_HOUR * SEC_PER_MIN * MS_PER_SECOND) / TASK_GENERAL_INTERVAL); #define MAX_SALINE_VOLUME_DELIVERED 800 ///< Maximum saline volume delivered for a treatment. #define SALINE_BOLUS_RATE_ML_MIN 150 ///< Fixed rate for saline bolus delivery. Index: firmware/App/Modes/ModeTreatment.c =================================================================== diff -u -r89f4c7f0995e2094b3f26fc7e7e12371e847abac -r6b870cd0699bb3ee22b93981d51373a6c2d56162 --- firmware/App/Modes/ModeTreatment.c (.../ModeTreatment.c) (revision 89f4c7f0995e2094b3f26fc7e7e12371e847abac) +++ firmware/App/Modes/ModeTreatment.c (.../ModeTreatment.c) (revision 6b870cd0699bb3ee22b93981d51373a6c2d56162) @@ -52,10 +52,12 @@ #define USER_CONFIRM_CHANGE_TIMEOUT_MS ( 60 * MS_PER_SECOND ) ///< Require user to confirm UF volume change within this time. #define PREVENT_UF_VOL_CHANGE_IF_NEARLY_DONE_SEC ( 10 * SEC_PER_MIN ) ///< Prevent UF volume change if treatment within this much time from end of treatment (in seconds). -#define TREATMENT_TIME_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the treatment time data is published on the CAN bus. -#define TREATMENT_STATE_DATA_PUB_INTERVAL ( 250 / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the treatment state data is published on the CAN bus. +/// Interval (ms/task time) at which the treatment time data is published on the CAN bus. +static const U32 TREATMENT_TIME_DATA_PUB_INTERVAL = ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ); +/// Interval (ms/task time) at which the treatment state data is published on the CAN bus. +static const U32 TREATMENT_STATE_DATA_PUB_INTERVAL = ( 250 / TASK_GENERAL_INTERVAL ); /// Interval (ms/task time) at which updated, valid treatment setting ranges are published on the CAN bus. -#define TREATMENT_SETTINGS_RANGES_PUB_INTERVAL ( ( 60 * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ) +static const U32 TREATMENT_SETTINGS_RANGES_PUB_INTERVAL = ( ( 60 * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ); #define CALC_ELAPSED_TREAT_TIME_IN_SECS() ( treatmentTimeMS / MS_PER_SECOND ) ///< Macro to calculate the elapsed treatment time in seconds. /// Macro to calculate the elapsed treatment time in minutes. @@ -529,7 +531,7 @@ { stopDialysis(); transitionToTreatmentEnd(); - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_END_OF_DIALYSIS_TREATMENT_WARNING, presTreatmentTimeSecs ); + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_END_OF_TREATMENT_WARNING, presTreatmentTimeSecs ); result = TREATMENT_END_STATE; } // Otherwise, execute state machine for treatment dialysis sub-mode Index: firmware/App/Modes/OperationModes.c =================================================================== diff -u -r30f049651877229042e3f8700c8596e5b9a1e0f4 -r6b870cd0699bb3ee22b93981d51373a6c2d56162 --- firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision 30f049651877229042e3f8700c8596e5b9a1e0f4) +++ firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision 6b870cd0699bb3ee22b93981d51373a6c2d56162) @@ -37,7 +37,8 @@ // ********** private data ********** -#define BROADCAST_HD_OP_MODE_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< HD operation mode broadcast interval (in task interval/sec). +/// HD operation mode broadcast interval (in task interval/sec). +static const U32 BROADCAST_HD_OP_MODE_INTERVAL = ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ); // ********** private data ********** Index: firmware/App/Modes/Rinseback.c =================================================================== diff -u -r89f4c7f0995e2094b3f26fc7e7e12371e847abac -r6b870cd0699bb3ee22b93981d51373a6c2d56162 --- firmware/App/Modes/Rinseback.c (.../Rinseback.c) (revision 89f4c7f0995e2094b3f26fc7e7e12371e847abac) +++ firmware/App/Modes/Rinseback.c (.../Rinseback.c) (revision 6b870cd0699bb3ee22b93981d51373a6c2d56162) @@ -49,13 +49,13 @@ static const F32 MIN_RINSEBACK_SAFETY_VOLUME_ML = ( TARGET_RINSEBACK_VOLUME_ML * 0.8 ); /// Interval at which rinseback progress is to be published to UI. -#define RINSEBACK_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) +static const U32 RINSEBACK_DATA_PUBLISH_INTERVAL = ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ); /// Maximum time allowed for rinseback operation until full volume is delivered. Timer is reset whenever BP is running. -#define MAX_RINSEBACK_TIME ( 5 * SEC_PER_MIN * ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ) +static const U32 MAX_RINSEBACK_TIME = ( 5 * SEC_PER_MIN * ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ); /// Maximum time allowed for each additional rinseback volume delivery. -#define MAX_RINSEBACK_ADDITIONAL_TIME ( 15 * MS_PER_SECOND / TASK_GENERAL_INTERVAL ) +static const U32 MAX_RINSEBACK_ADDITIONAL_TIME = ( 15 * MS_PER_SECOND / TASK_GENERAL_INTERVAL ); /// Multiplier to convert flow (mL/min) into volume (mL) for period of general task interval. -static const F32 RINSEBACK_FLOW_INTEGRATOR = 1.0 / (F32)( SEC_PER_MIN * ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ); +static const F32 RINSEBACK_FLOW_INTEGRATOR = 1.0 / (F32)( SEC_PER_MIN * ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ); // ********** private data ********** Index: firmware/App/Modes/TreatmentEnd.c =================================================================== diff -u -r89f4c7f0995e2094b3f26fc7e7e12371e847abac -r6b870cd0699bb3ee22b93981d51373a6c2d56162 --- firmware/App/Modes/TreatmentEnd.c (.../TreatmentEnd.c) (revision 89f4c7f0995e2094b3f26fc7e7e12371e847abac) +++ firmware/App/Modes/TreatmentEnd.c (.../TreatmentEnd.c) (revision 6b870cd0699bb3ee22b93981d51373a6c2d56162) @@ -37,13 +37,17 @@ #define TX_END_BP_FLOW_RATE_ML_MIN 100 /// Max time to wait for user to initiate final rinseback. -#define TX_END_TIMEOUT_MS ( ( 15 * 60 * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ) // TODO - get time from Systems +static const U32 TX_END_TIMEOUT_MS = ( ( 15 * 60 * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ); // TODO - get time from Systems +/// Maximum time in this mode before blood sitting warning given (in general task intervals). +static const U32 MAX_TIME_BLOOD_SITTING = ( ( 5 * SEC_PER_MIN * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ); + // ********** private data ********** static TREATMENT_END_STATE_T treatmentEndState; ///< Current state of the treatment end sub-mode. static U32 txEndTimerCtr; ///< Timer counter (in GP task intervals) counts time spent waiting for user to initiate final rinseback. +static U32 bloodSittingTimerCtr; ///< Timer counter tracks time in paused state while blood is sitting. static BOOL txEndAlarmResumeRequested; ///< Flag indicates user requesting resume from alarm. static BOOL txEndAlarmRinsebackRequested; ///< Flag indicates user requesting rinseback from alarm. @@ -74,6 +78,7 @@ { treatmentEndState = TREATMENT_END_WAIT_FOR_RINSEBACK_STATE; txEndTimerCtr = 0; + bloodSittingTimerCtr = 0; resetTreatmentEndFlags(); } @@ -139,6 +144,7 @@ setValvePosition( VBV, VALVE_POSITION_B_OPEN ); // Start blood pump at Tx End slow flow rate setBloodPumpTargetFlowRate( TX_END_BP_FLOW_RATE_ML_MIN, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); + bloodSittingTimerCtr = 0; // Start air trap leveling control startAirTrapControl(); } @@ -238,6 +244,8 @@ { TREATMENT_END_STATE_T result = TREATMENT_END_PAUSED_STATE; + bloodSittingTimerCtr++; + // Is final rinseback requested? if ( ( TRUE == txEndRinsebackRequested ) || ( TRUE == txEndAlarmRinsebackRequested ) ) { @@ -254,6 +262,14 @@ { signalEndTreatment(); } + else + { + // Ensure we do not sit in stopped state for too long + if ( bloodSittingTimerCtr > MAX_TIME_BLOOD_SITTING ) + { + activateAlarmNoData( ALARM_ID_BLOOD_SITTING_TOO_LONG_NO_RINSEBACK ); + } + } return result; } Index: firmware/App/Modes/TreatmentRecirc.c =================================================================== diff -u -r89f4c7f0995e2094b3f26fc7e7e12371e847abac -r6b870cd0699bb3ee22b93981d51373a6c2d56162 --- firmware/App/Modes/TreatmentRecirc.c (.../TreatmentRecirc.c) (revision 89f4c7f0995e2094b3f26fc7e7e12371e847abac) +++ firmware/App/Modes/TreatmentRecirc.c (.../TreatmentRecirc.c) (revision 6b870cd0699bb3ee22b93981d51373a6c2d56162) @@ -35,9 +35,9 @@ // ********** private definitions ********** /// Alarm if re-circulation is running for this much time. TODO - finalize these times w/ Systems -#define RECIRC_TIMEOUT_MS ( ( 15 * SEC_PER_MIN * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ) +static const U32 RECIRC_TIMEOUT_MS = ( ( 15 * SEC_PER_MIN * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ); /// Re-circulation status broadcast interval. -#define RECIRC_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) +static const U32 RECIRC_DATA_PUBLISH_INTERVAL = ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ); /// Target flow rate for re-circulation of saline on blood-side circuit. #define RECIRC_BP_FLOW_RATE_ML_MIN 100 Index: firmware/App/Modes/TreatmentStop.c =================================================================== diff -u -r89fb8ae8b3e451cb37ccd05b6ba9b92e89820f35 -r6b870cd0699bb3ee22b93981d51373a6c2d56162 --- firmware/App/Modes/TreatmentStop.c (.../TreatmentStop.c) (revision 89fb8ae8b3e451cb37ccd05b6ba9b92e89820f35) +++ firmware/App/Modes/TreatmentStop.c (.../TreatmentStop.c) (revision 6b870cd0699bb3ee22b93981d51373a6c2d56162) @@ -22,6 +22,7 @@ #include "DialOutFlow.h" #include "ModeTreatment.h" #include "OperationModes.h" +#include "TaskGeneral.h" #include "TreatmentStop.h" #include "Valves.h" @@ -30,9 +31,15 @@ * @{ */ +// ********** private definitions ********** + +/// Maximum time in this mode before blood sitting warning given (in general task intervals). +static const U32 MAX_TIME_BLOOD_SITTING = ( ( 5 * SEC_PER_MIN * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ); + // ********** private data ********** static TREATMENT_STOP_STATE_T currentTxStopState; ///< Current treatment stop state. +static U32 bloodSittingTimerCtr; ///< Timer counter tracks time in this mode while blood is sitting. // ********** private function prototypes ********** @@ -50,6 +57,7 @@ void initTreatmentStop( void ) { currentTxStopState = TREATMENT_STOP_RECIRC_STATE; + bloodSittingTimerCtr = 0; } /*********************************************************************//** @@ -124,6 +132,13 @@ *************************************************************************/ void execTreatmentStop( void ) { + // Ensure we do not sit in stopped state for too long + if ( ++bloodSittingTimerCtr > MAX_TIME_BLOOD_SITTING ) + { + activateAlarmNoData( ALARM_ID_BLOOD_SITTING_TOO_LONG_NO_RINSEBACK ); + } + + // Execute treatment stop sub-mode state machine switch ( currentTxStopState ) { case TREATMENT_STOP_RECIRC_STATE: Index: firmware/App/Services/AlarmMgmt.c =================================================================== diff -u -r161a56481d1a194704b63a5fd55d4c5583fa94df -r6b870cd0699bb3ee22b93981d51373a6c2d56162 --- firmware/App/Services/AlarmMgmt.c (.../AlarmMgmt.c) (revision 161a56481d1a194704b63a5fd55d4c5583fa94df) +++ firmware/App/Services/AlarmMgmt.c (.../AlarmMgmt.c) (revision 6b870cd0699bb3ee22b93981d51373a6c2d56162) @@ -34,7 +34,7 @@ // ********** private definitions ********** /// Interval to control lamp and audio and to publish alarm status data. -#define ALARM_STATUS_PUBLISH_INTERVAL ( ALARM_LAMP_AND_AUDIO_CONTROL_INTERVAL_MS / TASK_GENERAL_INTERVAL ) +static const U32 ALARM_STATUS_PUBLISH_INTERVAL = ( ALARM_LAMP_AND_AUDIO_CONTROL_INTERVAL_MS / TASK_GENERAL_INTERVAL ); #define ALARM_SILENCE_EXPIRES_IN_SECS (60) ///< Alarm silence expiration time in seconds.