Index: firmware/App/Controllers/Switches.c =================================================================== diff -u --- firmware/App/Controllers/Switches.c (revision 0) +++ firmware/App/Controllers/Switches.c (revision d8fa48ead3336b1fe090b42030a8648264831076) @@ -0,0 +1,244 @@ + +#include "FPGA.h" +#include "Switches.h" +#include "SystemCommMessages.h" +#include "TaskGeneral.h" + +/** + * @addtogroup Switches + * @{ + */ + +// ********** private definitions ********** + +#define SWITCHES_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the switches data is published on the CAN bus. +#define FRONT_DOOR_SWITCH_BIT_MASK 0x00A0 ///< Front door switch bit mask. +#define SWITCHES_FPGA_STATUS_CHECK_INTERVAL ( MS_PER_SECOND / ( 5 * TASK_GENERAL_INTERVAL ) ) ///< Switches FPGA status check interval. + +// ********** private data ********** + +static U32 switchesDataPublicationCounter; ///< Switches data publication counter. +static OVERRIDE_U32_T switchesDataPublishInterval = { SWITCHES_DATA_PUB_INTERVAL, + SWITCHES_DATA_PUB_INTERVAL, + 0, 0 }; ///< Interval (in ms) at which to publish switches data to CAN bus. +static OVERRIDE_U32_T switchStatus[ NUM_OF_DOORS_AND_CAPS ]; ///< Switches status array. +static U32 switchesFPGAStatusCheckCounter; ///< Switches FPGA status check counter. + +// ********** private function prototypes ********** + +static void publishSwitchesData( void ); +static U32 getPublishSwitchesDataInterval( void ); + +/*********************************************************************//** + * @brief + * The initSwitches function initializes the switches module. + * @details Inputs: none + * @details Outputs: switchesDataPublicationCounter, switchStatus + * @return none + *************************************************************************/ +void initSwitches( void ) +{ + U08 i; + + switchesDataPublicationCounter = 0; + switchesFPGAStatusCheckCounter = 0; + + // Initialize all the switches + for ( i = 0; i < NUM_OF_DOORS_AND_CAPS; i++ ) + { + switchStatus[ i ].data = (U32)CLOSED; + } +} + +/*********************************************************************//** + * @brief + * The execSwitches function executes the switches executive. + * @details Inputs: switchStatus + * @details Outputs: switchStatus + * @return none + *************************************************************************/ +void execSwitches( void ) +{ + if ( ++switchesFPGAStatusCheckCounter > SWITCHES_FPGA_STATUS_CHECK_INTERVAL ) + { + U08 fpgaRegister = getFPGAGPIOCount(); + + switchStatus[ FRONT_DOOR ].data = fpgaRegister & FRONT_DOOR_SWITCH_BIT_MASK; + + switchesFPGAStatusCheckCounter = 0; + } + + publishSwitchesData(); +} + +/*********************************************************************//** + * @brief + * The getSwitchStatus function returns the status of the called switch. + * @details Inputs: switchStatus + * @details Outputs: switchStatus + * @param switchId which is the switch that its status is requested + * @return switch status + *************************************************************************/ +SWITCH_STATUS_T getSwitchStatus( SWITCH_T switchId ) +{ + U32 status; + + if ( OVERRIDE_KEY == switchStatus[ switchId ].override ) + { + status = switchStatus[ switchId ].ovData; + } + else + { + status = switchStatus[ switchId ].data; + } + + return (SWITCH_STATUS_T)status; +} + +/*********************************************************************//** + * @brief + * The testSetSwitchesDataPublishIntervalOverride function overrides + * the switches publish data interval. + * @details Inputs: switchesDataPublishInterval + * @details Outputs: switchesDataPublishInterval + * @param value switches data broadcast interval (in ms) to override + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetSwitchesDataPublishIntervalOverride( U32 value ) +{ + BOOL result = FALSE; + + if ( isTestingActivated() ) + { + U32 interval = value / TASK_GENERAL_INTERVAL; + + result = TRUE; + switchesDataPublishInterval.ovData = interval; + switchesDataPublishInterval.override = OVERRIDE_KEY; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testResetSwitchesDataPublishIntervalOverrid function resets + * the override value of switches publish data interval. + * @details Inputs: switchesDataPublishInterval + * @details Outputs: switchesDataPublishInterval + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testResetSwitchesDataPublishIntervalOverrid( void ) +{ + BOOL result = FALSE; + + if ( isTestingActivated() ) + { + result = TRUE; + switchesDataPublishInterval.override = OVERRIDE_RESET; + switchesDataPublishInterval.ovData = switchesDataPublishInterval.ovInitData; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testSetSwitchesStatusOverride function sets the override status + * for a specific switch. + * @details Inputs: none + * @details Outputs: switchStatus + * @param switchId switch index + * @param status switch status to override if testing is activated + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetSwitchesStatusOverride( U32 switchId, U32 status ) +{ + BOOL result = FALSE; + + if ( switchId < NUM_OF_DOORS_AND_CAPS ) + { + if ( isTestingActivated() ) + { + result = TRUE; + switchStatus[ switchId ].ovData = status; + switchStatus[ switchId ].override = OVERRIDE_KEY; + } + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testResetSwitchesStatusOverride function resets the override + * status of a specified switch. + * @details Inputs: none + * @details Outputs: switchStatus + * @param switchId switch index + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testResetSwitchesStatusOverride( U32 switchId ) +{ + BOOL result = FALSE; + + if ( switchId < NUM_OF_DOORS_AND_CAPS ) + { + if ( isTestingActivated() ) + { + result = TRUE; + switchStatus[ switchId ].override = OVERRIDE_RESET; + switchStatus[ switchId ].ovData = switchStatus[ switchId ].ovInitData; + } + } + + return result; +} + +// ********** private functions ********** + +/*********************************************************************//** + * @brief + * The publishSwitchesData function broadcasts the switches data at the + * publication interval. + * @details Inputs: switchesDataPublicationCounter + * @details Outputs: switchesDataPublicationCounter + * @return none + *************************************************************************/ +static void publishSwitchesData( void ) +{ + if ( ++switchesDataPublicationCounter > getPublishSwitchesDataInterval() ) + { + SWITCHES_DATA_T data; + + data.frontDoor = (U32)getSwitchStatus( FRONT_DOOR ); + + switchesDataPublicationCounter = 0; + + broadcastSwitchesData( &data ); + } +} + +/*********************************************************************//** + * @brief + * The getPublishSwitchesDataInterval function returns the data + * publication interval either from the data or from the override. + * @details Inputs: switchesDataPublishInterval + * @details Outputs: none + * @return data publish interval + *************************************************************************/ +static U32 getPublishSwitchesDataInterval( void ) +{ + U32 result = switchesDataPublishInterval.data; + + if ( OVERRIDE_KEY == switchesDataPublishInterval.override ) + { + result = switchesDataPublishInterval.ovData; + } + + return result; +} + +/**@}*/ + + Index: firmware/App/Controllers/Switches.h =================================================================== diff -u --- firmware/App/Controllers/Switches.h (revision 0) +++ firmware/App/Controllers/Switches.h (revision d8fa48ead3336b1fe090b42030a8648264831076) @@ -0,0 +1,51 @@ + + +#ifndef APP_CONTROLLERS_SWITCHES_H_ +#define APP_CONTROLLERS_SWITCHES_H_ + +#include "Common.h" + +/** + * @defgroup Switches Switches + * @brief Switches module. Monitors the status of the front door switch. + * + * @addtogroup Switches + * @{ + */ + +// ********** public definitions ********** + +/// HD door enumeration +typedef enum switches_names +{ + FRONT_DOOR = 0, ///< Front door + NUM_OF_DOORS_AND_CAPS ///< Number of doors and caps +} SWITCH_T; + +typedef enum switches_status +{ + CLOSED = 0, ///< Closed + OPEN, ///< Open + NUM_OF_SWITCH_STATUS ///< Number of switch status +} SWITCH_STATUS_T; + +/// DG doors and caps data publish structure +typedef struct +{ + U32 frontDoor; ///< Front door +} SWITCHES_DATA_T; + +// ********** public function prototypes ********** + +void initSwitches( void ); + +void execSwitches( void ); + +SWITCH_STATUS_T getSwitchStatus( SWITCH_T switchId ); + +BOOL testSetSwitchesDataPublishIntervalOverride( U32 value ); +BOOL testResetSwitchesDataPublishIntervalOverrid( void ); +BOOL testSetSwitchesStatusOverride( U32 switchId, U32 status ); +BOOL testResetSwitchesStatusOverride( U32 switchId ); + +#endif /* APP_CONTROLLERS_SWITCHES_H_ */ Index: firmware/App/Services/FPGA.c =================================================================== diff -u -r44a100f8e5210a02c23b8fcc4527d8e96d577381 -rd8fa48ead3336b1fe090b42030a8648264831076 --- firmware/App/Services/FPGA.c (.../FPGA.c) (revision 44a100f8e5210a02c23b8fcc4527d8e96d577381) +++ firmware/App/Services/FPGA.c (.../FPGA.c) (revision d8fa48ead3336b1fe090b42030a8648264831076) @@ -2292,6 +2292,18 @@ return fpgaSensorReadings.VBACurrent; } +/*********************************************************************//** + * @brief + * The getFPGAGPIOCount function reads the FPGA GPIO count. + * @details Inputs: none + * @details Outputs: fpgaSensorReadings + * @return The current FPGA GPIO count + *************************************************************************/ +U16 getFPGAGPIOCount( void ) +{ + return fpgaSensorReadings.fpgaGPIO; +} + #ifdef DEBUG_ENABLED /*********************************************************************//** * @brief Index: firmware/App/Services/FPGA.h =================================================================== diff -u -r44a100f8e5210a02c23b8fcc4527d8e96d577381 -rd8fa48ead3336b1fe090b42030a8648264831076 --- firmware/App/Services/FPGA.h (.../FPGA.h) (revision 44a100f8e5210a02c23b8fcc4527d8e96d577381) +++ firmware/App/Services/FPGA.h (.../FPGA.h) (revision d8fa48ead3336b1fe090b42030a8648264831076) @@ -150,6 +150,8 @@ S16 getFPGAValveBloodArterialPosition( void ); U16 getFPGAValveBloodArterialCurrentCounts( void ); +U16 getFPGAGPIOCount( void ); + // The PWM functions are only used during debugging #ifdef DEBUG_ENABLED void setFPGAValveDialyzerInletPWM( U16 count ); Index: firmware/App/Services/SystemComm.c =================================================================== diff -u -rabbad386f4cc94f315300dffef321fe8c03fbd52 -rd8fa48ead3336b1fe090b42030a8648264831076 --- firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision abbad386f4cc94f315300dffef321fe8c03fbd52) +++ firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision d8fa48ead3336b1fe090b42030a8648264831076) @@ -1589,6 +1589,14 @@ handleBubbleSelfTestRequest( message ); break; + case MSG_ID_HD_SWITCHES_STATUS_OVERRIDE: + handleSetSwitchesStatusOverrideRequest( message ); + break; + + case MSG_ID_HD_SWITCHES_PUBLISH_INTERVAL_OVERRIDE: + handleTestSwitchesPublishIntervalOverrideRequest( message ); + break; + case MSG_ID_HD_SET_OP_MODE_REQUEST: handleTestSetOpModeRequest( message ); break; Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -rabbad386f4cc94f315300dffef321fe8c03fbd52 -rd8fa48ead3336b1fe090b42030a8648264831076 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision abbad386f4cc94f315300dffef321fe8c03fbd52) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision d8fa48ead3336b1fe090b42030a8648264831076) @@ -2734,6 +2734,33 @@ return result; } +/*********************************************************************//** + * @brief + * The broadcastSwitchesData function sends out switches data. + * @details Inputs: none + * @details Outputs: switches data msg constructed and queued + * @param SWITCHES_DATA_T which is switches msg constructed and queued + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL broadcastSwitchesData( SWITCHES_DATA_T *switchesData ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + + // create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_HD_SWITCHES_DATA; + msg.hdr.payloadLen = sizeof( SWITCHES_DATA_T ); + + memcpy( payloadPtr, switchesData, sizeof( SWITCHES_DATA_T ) ); + + // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_BROADCAST, ACK_NOT_REQUIRED ); + + return result; +} + #ifdef EMC_TEST_BUILD BOOL broadcastCANErrorCount( U32 count ) { @@ -5918,6 +5945,70 @@ sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); } +/************************************************************************* + * @brief + * The handleSetSwitchesStatusOverrideRequest function handles a + * request to override the status of a switch in HD. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleSetSwitchesStatusOverrideRequest( MESSAGE_T *message ) +{ + TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; + BOOL result = FALSE; + + // verify payload length + if ( sizeof( TEST_OVERRIDE_ARRAY_PAYLOAD_T ) == message->hdr.payloadLen ) + { + memcpy( &payload, message->payload, sizeof( TEST_OVERRIDE_ARRAY_PAYLOAD_T ) ); + if ( FALSE == payload.reset ) + { + result = testSetSwitchesStatusOverride( payload.index, payload.state.u32 ); + } + else + { + result = testResetSwitchesStatusOverride( payload.index ); + } + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +/************************************************************************* + * @brief + * The handleTestSwitchesPublishIntervalOverrideRequest function handles a + * request to override the the switches data publish interval. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleTestSwitchesPublishIntervalOverrideRequest( MESSAGE_T *message ) +{ + TEST_OVERRIDE_PAYLOAD_T payload; + BOOL result = FALSE; + + // verify payload length + if ( sizeof( TEST_OVERRIDE_PAYLOAD_T ) == message->hdr.payloadLen ) + { + memcpy( &payload, message->payload, sizeof( TEST_OVERRIDE_PAYLOAD_T ) ); + if ( FALSE == payload.reset ) + { + result = testSetSwitchesDataPublishIntervalOverride( payload.state.u32 ); + } + else + { + result = testResetSwitchesDataPublishIntervalOverrid(); + } + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + /*********************************************************************//** * @brief * The handleHDSoftwareResetRequest function handles a request to reset the Index: firmware/App/Services/SystemCommMessages.h =================================================================== diff -u -rabbad386f4cc94f315300dffef321fe8c03fbd52 -rd8fa48ead3336b1fe090b42030a8648264831076 --- firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision abbad386f4cc94f315300dffef321fe8c03fbd52) +++ firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision d8fa48ead3336b1fe090b42030a8648264831076) @@ -32,12 +32,13 @@ #include "Prime.h" #include "ModePostTreat.h" #include "ModePreTreat.h" +#include "ModeStandby.h" #include "ModeTreatment.h" #include "MsgQueues.h" #include "NVDataMgmt.h" #include "PresOccl.h" #include "Rinseback.h" -#include "ModeStandby.h" +#include "Switches.h" #include "SyringePump.h" #include "Valves.h" #include "Voltages.h" @@ -450,6 +451,12 @@ // MSG_ID_HD_PRIMING_STATUS_DATA BOOL broadcastPrimeData( PRIMING_DATA_PAYLOAD_T *primeDataPtr ); +// MSG_ID_HD_DISINFECT_STANDBY_DATA +BOOL broadcastDisinfectsData( DISINFECTS_DATA_T *disinfectsData ); + +// MSG_ID_HD_SWITCHES_DATA +BOOL broadcastSwitchesData( SWITCHES_DATA_T *switchesData ); + // MSG_ID_HD_SEND_CALIBRATION_RECORD BOOL sendHDCalibrationRecord( U32 payloadCurrNum, U32 payloadTotalNum, U32 length, U08* calRcrdAddress ); @@ -459,9 +466,6 @@ // MSG_ID_Hd_SEND_SERVICE_RECORD BOOL sendHDServiceRecord( U32 payloadCurrNum, U32 payloadTotalNum, U32 length, U08* srvcRcrdAddress ); -// MSG_ID_HD_DISINFECT_STANDBY_DATA -BOOL broadcastDisinfectsData( DISINFECTS_DATA_T *disinfectsData ); - #ifdef EMC_TEST_BUILD // MSG_ID_CAN_ERROR_COUNT BOOL broadcastCANErrorCount( U32 count ); @@ -669,6 +673,12 @@ // MSG_ID_HD_BUBBLE_SELF_TEST_REQUEST void handleBubbleSelfTestRequest( MESSAGE_T *message ); +// MSG_ID_HD_SWITCHES_STATUS_OVERRIDE +void handleSetSwitchesStatusOverrideRequest( MESSAGE_T *message ); + +// MSG_ID_HD_SWITCHES_PUBLISH_INTERVAL_OVERRIDE +void handleTestSwitchesPublishIntervalOverrideRequest( MESSAGE_T *message ); + // MSG_ID_SUPER_CLEAR_ALARMS_CMD void handleTestSuperClearAlarmsRequest( MESSAGE_T *message ); Index: firmware/hd_build_history.txt =================================================================== diff -u -rabbad386f4cc94f315300dffef321fe8c03fbd52 -rd8fa48ead3336b1fe090b42030a8648264831076 --- firmware/hd_build_history.txt (.../hd_build_history.txt) (revision abbad386f4cc94f315300dffef321fe8c03fbd52) +++ firmware/hd_build_history.txt (.../hd_build_history.txt) (revision d8fa48ead3336b1fe090b42030a8648264831076) @@ -2,7 +2,7 @@ Bamboo Build Number: Bamboo Build Date: Bug Fixes: DEN-8819 fixed load cells inaccurate value beyond 3rd decimal overriding values. -New Feature: None +New Feature: HD switches Known Bugs: Fans RPM monitor and Temperature sensors ADC range check are disabled for further investigations Changes: Added calibration to flow sensor, temeperature sensors, pressure sensors, conductivity Index: firmware/source/sys_main.c =================================================================== diff -u -rabbad386f4cc94f315300dffef321fe8c03fbd52 -rd8fa48ead3336b1fe090b42030a8648264831076 --- firmware/source/sys_main.c (.../sys_main.c) (revision abbad386f4cc94f315300dffef321fe8c03fbd52) +++ firmware/source/sys_main.c (.../sys_main.c) (revision d8fa48ead3336b1fe090b42030a8648264831076) @@ -85,6 +85,7 @@ #include "PresOccl.h" #include "RTC.h" #include "SafetyShutdown.h" +#include "Switches.h" #include "SyringePump.h" #include "SystemComm.h" #include "TaskBG.h" @@ -195,6 +196,7 @@ initFluidLeak(); initPresOccl(); initVoltagesMonitor(); + initSwitches(); // Initialize controllers initAirTrap(); initAlarmLamp();