/************************************************************************** * * Copyright (c) 2024-2024 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 Utilities.h * * @author (last) Sean * @date (last) 30-Jul-2024 * * @author (original) Sean * @date (original) 30-Jul-2024 * ***************************************************************************/ #ifndef __UTILITIES_H__ #define __UTILITIES_H__ #ifdef _TD_ #include "TDCommon.h" #endif #ifdef _DD_ #include "DDCommon.h" #endif #ifdef _RO_ #include "ROCommon.h" #endif /** * @defgroup Utilities Utilities * @brief Utilities unit contains various utility functions. * * @addtogroup Utilities * @{ */ // ********** public definitions ********** // ******* Time Windowed Count Definitions ********* #define MAX_TIME_WINDOWED_COUNT 10 ///< Maximum number of counts that a time windowed count can count to /// Enumeration of time-windowed counts. typedef enum TimeWindowedCounts { TIME_WINDOWED_COUNT_BAD_MSG_CRC = 0, ///< Bad message CRC TIME_WINDOWED_COUNT_CAN_WARNING, ///< CAN warning TIME_WINDOWED_COUNT_CAN_OFF, ///< CAN off TIME_WINDOWED_COUNT_CAN_PARITY, ///< CAN parity error TIME_WINDOWED_COUNT_FPGA_CLOCK_SPEED_ERROR, ///< FPGA clock speed error #ifdef _TD_ TIME_WINDOWED_COUNT_BP_COMMUTATION_ERROR, ///< Blood pump commutation error TIME_WINDOWED_COUNT_DIP_COMMUTATION_ERROR, ///< Dialysate inlet pump commutation error TIME_WINDOWED_COUNT_DOP_COMMUTATION_ERROR, ///< Dialysate outlet pump commutation error TIME_WINDOWED_COUNT_FPGA_COMM_FAILURES, ///< FPGA communication failure (NAK, CRC, timeout) TIME_WINDOWED_COUNT_SYRINGE_PUMP_OFF_ERROR, ///< Syringe pump off movement error TIME_WINDOWED_COUNT_BATT_COMM_ERROR, ///< Battery communication error #endif #ifdef _DD_ TIME_WINDOWED_COUNT_FPGA_COMM_FAILURES, ///< FPGA communication failure (NAK, CRC, timeout) TIME_WINDOWED_COUNT_FPGA_FRESH_DIALYSATE_PUMP_HALL_SENSOR_ERROR,///< FPGA fresh dialysate pump hall sensor failure TIME_WINDOWED_COUNT_FPGA_SPENT_DIALYSATE_PUMP_HALL_SENSOR_ERROR,///< FPGA spent dialysate pump hall sensor failure #endif #ifdef _RO_ TIME_WINDOWED_COUNT_FPGA_CONDUCTIVITY_SENSOR_ERROR, ///< FPGA Conductivity sensor error TIME_WINDOWED_COUNT_FPGA_TEMPERATURE_SENSOR_ERROR, ///< FPGA Temperature sensor error TIME_WINDOWED_COUNT_FPGA_COMM_FAILURES, ///< FPGA communication failure (NAK, CRC, timeout) TIME_WINDOWED_COUNT_FPGA_DRAIN_PUMP_HALL_SENSOR_ERROR, ///< FPGA Drain pump hall sensor failure #endif NUM_OF_TIME_WINDOWED_COUNTS ///< Number of pressure sensors } TIME_WINDOWED_COUNT_T; // ******* Critical Data Definitions ********* /// Critical data types list. typedef enum Critical_Data_Types { CRITICAL_DATA_TYPE_U32 = 0, ///< Critical data is unsigned 32-bit integer type CRITICAL_DATA_TYPE_S32, ///< Critical data is signed 32-bit integer type CRITICAL_DATA_TYPE_F32, ///< Critical data is 32-bit floating point type NUM_OF_CRITICAL_DATA_TYPES ///< Total number of critical data types } CRITICAL_DATA_TYPES_T; /// Semaphore items typedef enum Semaphores { SEMAPHORE_RTC = 0, ///< Semaphore RTC NUM_OF_SEMAPHORES, ///< Number of semaphores } SEMAPHORE_T; /// Record structure for alarm data of any supported type. typedef union { U32 uInt; ///< critical data of unsigned integer type S32 sInt; ///< critical data of signed integer type F32 sFlt; ///< critical data of floating point type } CRITICAL_DATAS_T; /// critical integer data structure. typedef struct { CRITICAL_DATA_TYPES_T typ; ///< Type of data CRITICAL_DATAS_T minimum; ///< Minimum value for valid data CRITICAL_DATAS_T maximum; ///< Maximum value for valid data CRITICAL_DATAS_T defValue; ///< Default value CRITICAL_DATAS_T data; ///< Data value U32 comp; ///< One's compliment of value } CRITICAL_DATA_T; // ********** public function prototypes ********** U32 crc32( U32 const initialValue, const U08 *address, U32 len ); U16 crc16( const U08 *address, U32 len ); U08 crc8( const U08 *address, U32 len ); U08 crc4( U16* buffer, U32 byteCount ); S16 signExtend16( U16 value, U32 signBit ); U32 u32DiffWithWrap( U32 start, U32 end ); S32 u32BiDiffWithWrap( U32 start, U32 end ); U16 u16DiffWithWrap( U16 start, U16 end ); S16 u16BiDiffWithWrap( U16 start, U16 end ); void initTimeWindowedCount( TIME_WINDOWED_COUNT_T cnt, U32 maxCnt, U32 winMs ); BOOL incTimeWindowedCount( TIME_WINDOWED_COUNT_T cnt ); CRITICAL_DATAS_T getCriticalData( CRITICAL_DATA_T *data ); BOOL setCriticalData( CRITICAL_DATA_T *data, CRITICAL_DATAS_T value ); BOOL isCriticalDataInRange( CRITICAL_DATA_T *data ); void resetCriticalData( CRITICAL_DATA_T *data ); BOOL hexStrToDec( U08 const * const valuePtr, U32* convValueAddress, U08 size ); void initSemaphores( void ); BOOL acquireSemaphore( SEMAPHORE_T s ); void releaseSemaphore( SEMAPHORE_T s ); BOOL isSemaphoreAvailable( SEMAPHORE_T s ); /**@}*/ #endif