/************************************************************************** * * Copyright (c) 2024-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 GLXferPump.c * * @author (last) Dara Navaei * @date (last) 03-Sep-2025 * * @author (original) Sean Nash * @date (original) 19-Sep-2024 * ***************************************************************************/ #include "AlarmMgmtTD.h" #include "FpgaTD.h" #include "GLXferPump.h" #include "GPIO.h" #include "Messaging.h" /** * @addtogroup GLXferPump * @{ */ // ********** private definitions ********** #define AIR_PUMP_PWM_TIME 20 ///< Time (in 10ns increments) per PWM register count for the air pump = 20 kHz. #define AIR_PUMP_MAX_PWM 255.0f ///< Air pump maximum PWM. #define AIR_PUMP_PWM_PCT 100.0f ///< Air pump pwm percentage // ********** private data ********** static F32 currentAirPumpMotorPowerLevel; ///< Current air pump motor state: 0=off, 1..255=power level. // ********** private function prototypes ********** static U08 PercentageToScalar(F32 percentage); /*********************************************************************//** * @brief * The initGasLiqXferPumpDriver function initializes the gas/liquid transfer * pump driver unit. * @details \b Inputs: none * @details \b Outputs: currentAirPumpMotorPowerLevel * @return none *************************************************************************/ void initGasLiqXferPumpDriver(void) { currentAirPumpMotorPowerLevel = AIR_PUMP_MOTOR_OFF; setH12AirPumpMotorPowerLevel( currentAirPumpMotorPowerLevel ); setH12AirPumpMotorPWMCntTime( AIR_PUMP_PWM_TIME ); } /*********************************************************************//** * @brief * The setAirPumpMotorPower function sets the air pump motor to the given * power level. * @details \b Message \b Sent: MSG_ID_TD_EVENT if changing air pump power level. * @details \b Inputs: none * @details \b Outputs: currentAirPumpMotorPowerLevel * @param power Power level for air pump (0..2=off, 3..100=lower to higher power level). * @return none. *************************************************************************/ void setAirPumpMotorPower( F32 power ) { // if state is changing, set the air pump to the given on/off state and send event if ( power != currentAirPumpMotorPowerLevel ) { SEND_EVENT_WITH_2_F32_DATA(TD_EVENT_AIR_PUMP_ON_OFF, currentAirPumpMotorPowerLevel, power ); setH12AirPumpMotorPowerLevel( PercentageToScalar( power ) ); currentAirPumpMotorPowerLevel = power; } } /*********************************************************************//** * @brief * The getAirPumpMotorState function gets the current set power level of the * air pump motor. * @details \b Inputs: currentAirPumpMotorPowerLevel * @details \b Outputs: none * @return Current set power level of the air pump motor. *************************************************************************/ F32 getAirPumpMotorPower( void ) { return currentAirPumpMotorPowerLevel; } /*********************************************************************//** * @brief * The PercentageToScalar function convert percentage 0-100% duty * cycle to 0-255 scalar value. * @details \b Inputs: none * @details \b Outputs: none * @param percentage Power level for air pump (0...2=off, 3-100.0 for ON). * @return U08 8-bit PWM value (0-255) *************************************************************************/ static U08 PercentageToScalar(F32 percentage) { // Clamp input to 0-100% if ( percentage < 0.0f ) { percentage = 0.0f; } if ( percentage > AIR_PUMP_PWM_PCT ) { percentage = AIR_PUMP_PWM_PCT; } // Calculate 0-255 value (255 * percent / 100) return (U08)( ( ( percentage * AIR_PUMP_MAX_PWM ) / AIR_PUMP_PWM_PCT ) ); } /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ /**@}*/