Index: firmware/App/Services/FpgaDD.c =================================================================== diff -u -r26ee1d67dca19aac1850077cbd41c05498cf059d -rf7c714a1a09b10d85a8b013712532d37b4d7b97a --- firmware/App/Services/FpgaDD.c (.../FpgaDD.c) (revision 26ee1d67dca19aac1850077cbd41c05498cf059d) +++ firmware/App/Services/FpgaDD.c (.../FpgaDD.c) (revision f7c714a1a09b10d85a8b013712532d37b4d7b97a) @@ -6,7 +6,7 @@ * 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 FPGADD.c +* @file FpgaDD.c * * @author (last) Vinayakam Mani * @date (last) 05-Aug-2024 @@ -16,25 +16,23 @@ * ***************************************************************************/ -#include -#include // for memset(), memcpy() +#include "string.h" // for memset(), memcpy() -#include "gio.h" +#include "gio.h" // hal headers #include "sci.h" #include "sys_dma.h" -#include "FPGA.h" -#include "Messaging.h" + #include "Comm.h" #include "Compatible.h" -//#include "NVDataMgmt.h" +#include "FPGA.h" +#include "Messaging.h" #include "OperationModes.h" #include "PersistentAlarm.h" -#include "Messaging.h" #include "Timers.h" #include "Utilities.h" /** - * @addtogroup FPGADD + * @addtogroup FpgaDD * @{ */ @@ -48,7 +46,7 @@ #define FPGA_FLUIDLEAK_STATE_MASK 0x0004 ///< Bit mask for fluid leak detector. -//ToDo : Define the default values for the Valves ( 0: Deenergized, 1 : Energized) on power up. +//TODO : Define the default values for the Valves ( 0: Deenergized, 1 : Energized) on power up. #define FPGA_ENABLE_VALVES_CONTROL 0x0000 ///< FPGA enable valves control. #define FPGA_ENABLE_BC_VALVES_CONTROL 0x00 ///< FPGA enable Balancing chamber valves control. #define FPGA_ENABLE_UF_VALVES_CONTROL 0x00 ///< FPGA enable Balancing Chamber valves control. @@ -69,7 +67,6 @@ #define FPGA_CP1_PARK_FAULT_BIT 0x08 ///< Concentrate pump 1 park fault status bit mask. #define FPGA_CP2_PARK_FAULT_BIT 0x20 ///< Concentrate pump 2 park fault status bit mask. #define FPGA_CONC_PUMP_PARK_COMMAND 0x80 ///< Park command bit for the concentrate pumps. -#define DIALYSATE_CAP_SWITCH_MASK 0x20 ///< Dialysate cap switch bit mask. #define FPGA_THD_CONTROL_COMMAND 0X01 ///< FPGA THd control command. #define FPGA_POWER_OUT_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< FPGA power out timeout in milliseconds. #define FPGA_GPIO_POWER_STATUS_PIN 7 ///< FPGA GPIO power status pin. @@ -85,8 +82,8 @@ #define MAX_FPGA_COMM_FAILURES 3 ///< FPGA maximum comm failures per MAX_FPGA_COMM_FAILURES_WINDOW_MS #define MIN_POWER_ON_TIME_FOR_COMM_FAILS ( 1 * MS_PER_SECOND ) ///< Allow FPGA comm errors for first second after power-up -// FPGA header struct. #pragma pack(push,1) +/// FPGA header struct. typedef struct { U08 fpgaId; ///< Reg 0. FPGA ID code. Checked against expected value at power up to verify basic FPGA communication and operation @@ -95,7 +92,7 @@ U08 fpgaRevLab; ///< Reg 3. FPGA revision (lab) being reported } FPGA_HEADER_T; // read only on FPGA -/// FPGA sensors' readings struct. +/// FPGA sensor readings struct. typedef struct { U16 fpgaCompatibilityRev; ///< Reg 256. Compatibility revision @@ -171,7 +168,6 @@ U08 fpgaValveBCPWMStates; ///< Reg 363. Balancing Chamber Valve PWM states U08 fpgaValveUFStates; ///< Reg 364. Ultrafiltration Valves states U08 fpgaValveUFPWMStates; ///< Reg 365. Ultrafiltration Valves PWM states - } DD_FPGA_SENSORS_T; typedef struct @@ -247,24 +243,24 @@ U08 fpgaBloodLeakSensorTest; ///< Reg 114. Blood leak sensor test U08 fpgaBloodLeakUARTControl; ///< Reg 115. Blood leak sensor UART control U08 fpgaBloodLeakFIFOTx; ///< Reg 116. Blood leak sensor FIFO transmit control - } FPGA_ACTUATORS_T; #pragma pack(pop) // ********** private data ********** -// FPGA data static FPGA_HEADER_T fpgaHeader; ///< FPGA header structure. static DD_FPGA_SENSORS_T fpgaSensorReadings; ///< DD FPGA sensors structure. static FPGA_ACTUATORS_T fpgaActuatorSetPoints; ///< FPGA actuator set points structure. // ********** private function prototypes ********** +static U16 getFPGATimerCount( void ); + /*********************************************************************//** * @brief - * The initFPGADD function initializes the DD FPGA module. + * The initFPGADD function initializes the DD FPGA unit. * @details \b Inputs: none - * @details \b Outputs: FPGA module initialized. + * @details \b Outputs: FPGA unit initialized. * @return none *************************************************************************/ void initFPGADD( void ) @@ -280,6 +276,8 @@ // Set the THd control register to 0x1 to make sure its ADC is running //fpgaActuatorSetPoints.fpgaTHdControlReg = FPGA_THD_CONTROL_COMMAND; + + // Set the valve control mode and default state of valve fpgaActuatorSetPoints.fpgaValveControl = FPGA_ENABLE_VALVES_CONTROL; fpgaActuatorSetPoints.fpgaValvePWMEnable = FPGA_ENABLE_VALVES_PWM; fpgaActuatorSetPoints.fpgaBCValveControl = FPGA_ENABLE_BC_VALVES_CONTROL; @@ -289,7 +287,6 @@ // initialize FPGA clock speed error time windowed count initTimeWindowedCount( TIME_WINDOWED_COUNT_FPGA_COMM_FAILURES, MAX_FPGA_COMM_FAILURES, MAX_FPGA_COMM_FAILURES_WINDOW_MS); - } /*********************************************************************//** @@ -332,21 +329,16 @@ * @brief * The execFPGAClockSpeedTest function verifies the processor clock speed * against the FPGA clock. - * @details \b Inputs: fpgaHeader, - * window timer TIME_WINDOWED_COUNT_FPGA_CLOCK_SPEED_ERROR + * @details \b Inputs: time windowed error count for FPGA clock speed alarm * @details \b Outputs: none * @details \b Alarm: ALARM_ID_DD_FPGA_CLOCK_SPEED_CHECK_FAILURE when clock speed * mismatch seen. - * @return: none + * @warning: It may be necessary to comment out the following code to prevent + * the alarm from occurring while debugging. + * @return: none *************************************************************************/ void execFPGAClockSpeedTest( void ) { - /* DEBUG WARNING - * It may be necessary to comment out the following - * code to prevent the alarm from occurring while - * debugging. - */ - static U16 currentFPGATimerCount_ms = 0; static U32 currentTimerCount_ms = 0; @@ -834,11 +826,11 @@ /*********************************************************************//** * @brief - * The getFPGAPnReadCount function gets Pn/PHo pressure sensor counter of + * The getFPGAPnReadCount function gets hydraulics outlet pressure sensor counter of * good I2C transmissions between FPGA and Sensor. * @details \b Inputs: fpgaSensorReadings.fpgaPnReadCnt * @details \b Outputs: none - * @return Latest Pn/PHo Pressure sensor read count + * @return Latest hydraulics outlet Pressure sensor read count *************************************************************************/ U08 getFPGAPnReadCount( void ) { @@ -847,10 +839,10 @@ /*********************************************************************//** * @brief - * The getFPGAPnErrorCount function gets Pn/PHo pressure sensor error count. + * The getFPGAPnErrorCount function gets hydraulics outlet pressure sensor error count. * @details \b Inputs: fpgaSensorReadings.fpgaPnErrorCnt * @details \b Outputs: none - * @return Latest Pn/PHo pressure sensor read error count + * @return Latest hydraulics outlet pressure sensor read error count *************************************************************************/ U08 getFPGAPnErrorCount( void ) { @@ -859,11 +851,11 @@ /*********************************************************************//** * @brief - * The getFPGAPnRawPressure function gets Pn/PHo pressure sensor raw + * The getFPGAPnRawPressure function gets hydraulics outlet pressure sensor raw * pressure value. * @details \b Inputs: fpgaSensorReadings.fpgaPnPressure * @details \b Outputs: none - * @return Latest Pn/PHo pressure sensor raw pressure data + * @return Latest hydraulics outlet pressure sensor raw pressure data *************************************************************************/ U32 getFPGAPnRawPressure( void ) { @@ -872,11 +864,11 @@ /*********************************************************************//** * @brief - * The getFPGAPnRawTemperature function gets Pn/PHo pressure sensor raw + * The getFPGAPnRawTemperature function gets hydraulics outlet pressure sensor raw * temperature value. * @details \b Inputs: fpgaSensorReadings.fpgaPnTemp * @details \b Outputs: none - * @return Latest Pn/PHo pressure sensor raw temperature data + * @return Latest hydraulics outlet pressure sensor raw temperature data *************************************************************************/ U32 getFPGAPnRawTemperature( void ) { @@ -885,11 +877,11 @@ /*********************************************************************//** * @brief - * The getFPGAPCbReadCount function gets PCb/PDB pressure sensor counter of + * The getFPGAPCbReadCount function gets Bibag pressure sensor counter of * good I2C transmissions between FPGA and Sensor. * @details \b Inputs: fpgaSensorReadings.fpgaPCbReadCnt * @details \b Outputs: none - * @return Latest PCb/PDB Pressure sensor read count + * @return Latest Bibag Pressure sensor read count *************************************************************************/ U08 getFPGAPCbReadCount( void ) { @@ -898,10 +890,10 @@ /*********************************************************************//** * @brief - * The getFPGAPCbErrorCount function gets PCb/PDB pressure sensor error count. + * The getFPGAPCbErrorCount function gets Bibag pressure sensor error count. * @details \b Inputs: fpgaSensorReadings.fpgaPCbErrorCnt * @details \b Outputs: none - * @return Latest PCb/PDB pressure sensor read error count + * @return Latest Bibag pressure sensor read error count *************************************************************************/ U08 getFPGAPCbErrorCount( void ) { @@ -910,11 +902,11 @@ /*********************************************************************//** * @brief - * The getFPGAPCbRawPressure function gets PCb/PDB pressure sensor raw + * The getFPGAPCbRawPressure function gets Bibag pressure sensor raw * pressure value. * @details \b Inputs: fpgaSensorReadings.fpgaPCbPressure * @details \b Outputs: none - * @return Latest PCb/PDB pressure sensor raw pressure data + * @return Latest Bibag pressure sensor raw pressure data *************************************************************************/ U32 getFPGAPCbRawPressure( void ) { @@ -923,11 +915,11 @@ /*********************************************************************//** * @brief - * The getFPGAPCbRawTemperature function gets PCb/PDB pressure sensor raw + * The getFPGAPCbRawTemperature function gets Bibag pressure sensor raw * temperature value. * @details \b Inputs: fpgaSensorReadings.fpgaPCbTemp * @details \b Outputs: none - * @return Latest PCb/PDB pressure sensor raw temperature data + * @return Latest Bibag pressure sensor raw temperature data *************************************************************************/ U32 getFPGAPCbRawTemperature( void ) { @@ -936,11 +928,11 @@ /*********************************************************************//** * @brief - * The getFPGAPDsReadCount function gets PDs pressure sensor counter of + * The getFPGAPDsReadCount function gets spent dialysate pressure sensor counter of * good I2C transmissions between FPGA and Sensor. * @details \b Inputs: fpgaSensorReadings.fpgaPDsReadCnt * @details \b Outputs: none - * @return Latest PDs Pressure sensor read count + * @return Latest spent dialysate Pressure sensor read count *************************************************************************/ U08 getFPGAPDsReadCount( void ) { @@ -949,10 +941,10 @@ /*********************************************************************//** * @brief - * The getFPGAPDsErrorCount function gets PDs pressure sensor error count. + * The getFPGAPDsErrorCount function gets spent dialysate pressure sensor error count. * @details \b Inputs: fpgaSensorReadings.fpgaPDsErrorCnt * @details \b Outputs: none - * @return Latest PDs pressure sensor read error count + * @return Latest spent dialysate pressure sensor read error count *************************************************************************/ U08 getFPGAPDsErrorCount( void ) { @@ -961,11 +953,11 @@ /*********************************************************************//** * @brief - * The getFPGAPDsRawPressure function gets PDs pressure sensor raw + * The getFPGAPDsRawPressure function gets spent dialysate pressure sensor raw * pressure value. * @details \b Inputs: fpgaSensorReadings.fpgaPDsPressure * @details \b Outputs: none - * @return Latest PDs pressure sensor raw pressure data + * @return Latest spent dialysate pressure sensor raw pressure data *************************************************************************/ U32 getFPGAPDsRawPressure( void ) { @@ -974,11 +966,11 @@ /*********************************************************************//** * @brief - * The getFPGAPDsRawTemperature function gets PDs pressure sensor raw + * The getFPGAPDsRawTemperature function gets spent dialysate pressure sensor raw * temperature value. * @details \b Inputs: fpgaSensorReadings.fpgaPDsTemp * @details \b Outputs: none - * @return Latest PDs pressure sensor raw temperature data + * @return Latest spent dialysate pressure sensor raw temperature data *************************************************************************/ U32 getFPGAPDsRawTemperature( void ) { @@ -987,11 +979,11 @@ /*********************************************************************//** * @brief - * The getFPGAPDfReadCount function gets PDf pressure sensor counter of + * The getFPGAPDfReadCount function gets fresh dialysate pressure sensor counter of * good I2C transmissions between FPGA and Sensor. * @details \b Inputs: fpgaSensorReadings.fpgaPDfReadCnt * @details \b Outputs: none - * @return Latest PDf Pressure sensor read count + * @return Latest fresh dialysate Pressure sensor read count *************************************************************************/ U08 getFPGAPDfReadCount( void ) { @@ -1000,10 +992,10 @@ /*********************************************************************//** * @brief - * The getFPGAPDfErrorCount function gets PDf pressure sensor error count. + * The getFPGAPDfErrorCount function gets fresh dialysate pressure sensor error count. * @details \b Inputs: fpgaSensorReadings.fpgaPDfErrorCnt * @details \b Outputs: none - * @return Latest PDf pressure sensor read error count + * @return Latest fresh dialysate pressure sensor read error count *************************************************************************/ U08 getFPGAPDfErrorCount( void ) { @@ -1012,11 +1004,11 @@ /*********************************************************************//** * @brief - * The getFPGAPDfRawPressure function gets PDf pressure sensor raw + * The getFPGAPDfRawPressure function gets fresh dialysate pressure sensor raw * pressure value. * @details \b Inputs: fpgaSensorReadings.fpgaPDfPressure * @details \b Outputs: none - * @return Latest PDf pressure sensor raw pressure data + * @return Latest fresh dialysate pressure sensor raw pressure data *************************************************************************/ U32 getFPGAPDfRawPressure( void ) { @@ -1025,11 +1017,11 @@ /*********************************************************************//** * @brief - * The getFPGAPDfRawTemperature function gets PDf pressure sensor raw + * The getFPGAPDfRawTemperature function gets fresh dialysate pressure sensor raw * temperature value. * @details \b Inputs: fpgaSensorReadings.fpgaPDfTemp * @details \b Outputs: none - * @return Latest PDf pressure sensor raw temperature data + * @return Latest fresh dialysate pressure sensor raw temperature data *************************************************************************/ U32 getFPGAPDfRawTemperature( void ) { @@ -1038,11 +1030,11 @@ /*********************************************************************//** * @brief - * The getFPGAPtmReadCount function gets Ptm pressure sensor counter of + * The getFPGAPtmReadCount function gets transmembrane pressure sensor counter of * good I2C transmissions between FPGA and Sensor. * @details \b Inputs: fpgaSensorReadings.fpgaPtmReadCnt * @details \b Outputs: none - * @return Latest Ptm Pressure sensor read count + * @return Latest transmembrane Pressure sensor read count *************************************************************************/ U08 getFPGAPtmReadCount( void ) { @@ -1051,10 +1043,10 @@ /*********************************************************************//** * @brief - * The getFPGAPtmErrorCount function gets Ptm pressure sensor error count. + * The getFPGAPtmErrorCount function gets transmembrane pressure sensor error count. * @details \b Inputs: fpgaSensorReadings.fpgaPtmErrorCnt * @details \b Outputs: none - * @return Latest Ptm pressure sensor read error count + * @return Latest transmembrane pressure sensor read error count *************************************************************************/ U08 getFPGAPtmErrorCount( void ) { @@ -1063,11 +1055,11 @@ /*********************************************************************//** * @brief - * The getFPGAPtmRawPressure function gets Ptm pressure sensor raw + * The getFPGAPtmRawPressure function gets transmembrane pressure sensor raw * pressure value. * @details \b Inputs: fpgaSensorReadings.fpgaPtmPressure * @details \b Outputs: none - * @return Latest Ptm pressure sensor raw pressure data + * @return Latest transmembrane pressure sensor raw pressure data *************************************************************************/ U32 getFPGAPtmRawPressure( void ) { @@ -1076,11 +1068,11 @@ /*********************************************************************//** * @brief - * The getFPGAPtmRawTemperature function gets Ptm pressure sensor raw + * The getFPGAPtmRawTemperature function gets transmembrane pressure sensor raw * temperature value. * @details \b Inputs: fpgaSensorReadings.fpgaPtmTemp * @details \b Outputs: none - * @return Latest Ptm pressure sensor raw temperature data + * @return Latest transmembrane pressure sensor raw temperature data *************************************************************************/ U32 getFPGAPtmRawTemperature( void ) { @@ -1360,7 +1352,7 @@ * @details \b Outputs: none * @return last FPGA timer count *************************************************************************/ -U16 getFPGATimerCount( void ) +static U16 getFPGATimerCount( void ) { return fpgaSensorReadings.fpgaTimerCountMS; }