Index: App/Contollers/AlarmLamp.c =================================================================== diff -u -r765d2c35118e202444e737c66c77faf9678cc87e -rb14dbfe8cbfe2e6fcf7177f2584eab23f1945049 --- App/Contollers/AlarmLamp.c (.../AlarmLamp.c) (revision 765d2c35118e202444e737c66c77faf9678cc87e) +++ App/Contollers/AlarmLamp.c (.../AlarmLamp.c) (revision b14dbfe8cbfe2e6fcf7177f2584eab23f1945049) @@ -1,58 +1,75 @@ /************************************************************************* -* -* Copyright Diality, Inc. 2019-2020. All Rights Reserved. -* 181 Technology, Ste. 150 -* Irvine, CA 92618 -* -* Project Denali -* -* @file AlarmLamp.c -* -* @brief Controller for the alarm lamp. -* -* @date 20-Sep-2019 -* -*************************************************************************/ + * + * Copyright Diality, Inc. 2019-2020. All Rights Reserved. + * 181 Technology, Ste. 150 + * Irvine, CA 92618 + * + * Project Denali + * + * @file AlarmLamp.c + * + * @brief Controller for the alarm lamp. + * + * @date 20-Sep-2019 + * + *************************************************************************/ #include "Common.h" #include "CPLD.h" #include "TaskGeneral.h" +#include "Timers.h" #include "AlarmLamp.h" // ********** private definitions ********** typedef enum LampStates { - LAMP_STATE_OFF = 0, - LAMP_STATE_ON, - NUM_OF_LAMP_STATES + LAMP_STATE_OFF = 0, + LAMP_STATE_ON, + NUM_OF_LAMP_STATES } LAMP_STATE_T; // Lamp Pattern Record -struct LampPatterns { - uint32_t duration[NUM_OF_LAMP_STATES]; // in ms - LAMP_STATE_T green[NUM_OF_LAMP_STATES]; // green lamp state 1 and 2 - LAMP_STATE_T yellow[NUM_OF_LAMP_STATES]; // yellow lamp state 1 and 2 - LAMP_STATE_T red[NUM_OF_LAMP_STATES]; // red lamp state 1 and 2 +struct LampPatterns +{ + U32 duration[NUM_OF_LAMP_STATES]; // in ms + LAMP_STATE_T green[NUM_OF_LAMP_STATES]; // green lamp state 1 and 2 + LAMP_STATE_T yellow[NUM_OF_LAMP_STATES]; // yellow lamp state 1 and 2 + LAMP_STATE_T red[NUM_OF_LAMP_STATES]; // red lamp state 1 and 2 }; +typedef enum Alarm_Lamp_Self_Test_States +{ + ALARM_LAMP_SELF_TEST_STATE_START = 0, + ALARM_LAMP_SELF_TEST_STATE_RED, + ALARM_LAMP_SELF_TEST_STATE_YELLOW, + ALARM_LAMP_SELF_TEST_STATE_GREEN, + ALARM_LAMP_SELF_TEST_STATE_COMPLETE, + NUM_OF_ALARM_LAMP_SELF_TEST_STATES +} ALARM_LAMP_SELF_TEST_STATE_T; + +#define POST_LAMP_STEP_TIME_MS 1000 // ms for each lamp color + // ********** private data ********** static LAMP_PATTERN_T currentLampPattern = LAMP_PATTERN_OFF; static LAMP_PATTERN_T pendingLampPattern = LAMP_PATTERN_OFF; -static U32 currentLampPatternStep = 0; -static U32 lampPatternStepTimer = 0; +static U32 currentLampPatternStep = 0; +static U32 lampPatternStepTimer = 0; -static struct LampPatterns lampPatterns[NUM_OF_LAMP_PATTERNS] = { - { {500, 500}, {LAMP_STATE_OFF, LAMP_STATE_OFF}, {LAMP_STATE_OFF, LAMP_STATE_OFF}, {LAMP_STATE_OFF, LAMP_STATE_OFF} }, // LAMP_PATTERN_OFF - { {500, 500}, {LAMP_STATE_ON, LAMP_STATE_ON}, {LAMP_STATE_OFF, LAMP_STATE_OFF}, {LAMP_STATE_OFF, LAMP_STATE_OFF} }, // LAMP_PATTERN_OK - { {500, 500}, {LAMP_STATE_OFF, LAMP_STATE_OFF}, {LAMP_STATE_OFF, LAMP_STATE_OFF}, {LAMP_STATE_ON, LAMP_STATE_OFF} }, // LAMP_PATTERN_FAULT - { {500, 500}, {LAMP_STATE_OFF, LAMP_STATE_OFF}, {LAMP_STATE_OFF, LAMP_STATE_OFF}, {LAMP_STATE_ON, LAMP_STATE_OFF} }, // LAMP_PATTERN_HIGH_ALARM - { {1000, 1000}, {LAMP_STATE_OFF, LAMP_STATE_OFF}, {LAMP_STATE_ON, LAMP_STATE_OFF}, {LAMP_STATE_OFF, LAMP_STATE_OFF} }, // LAMP_PATTERN_MED_ALARM - { {500, 500}, {LAMP_STATE_OFF, LAMP_STATE_OFF}, {LAMP_STATE_ON, LAMP_STATE_ON}, {LAMP_STATE_OFF, LAMP_STATE_OFF} }, // LAMP_PATTERN_LOW_ALARM - { {0, 0}, {LAMP_STATE_OFF, LAMP_STATE_OFF}, {LAMP_STATE_OFF, LAMP_STATE_OFF}, {LAMP_STATE_OFF, LAMP_STATE_OFF} } // LAMP_PATTERN_MANUAL +const struct LampPatterns lampPatterns[NUM_OF_LAMP_PATTERNS] = { + { { 500, 500 }, { LAMP_STATE_OFF, LAMP_STATE_OFF }, { LAMP_STATE_OFF, LAMP_STATE_OFF }, { LAMP_STATE_OFF, LAMP_STATE_OFF } }, // LAMP_PATTERN_OFF + { { 500, 500 }, { LAMP_STATE_ON, LAMP_STATE_ON }, { LAMP_STATE_OFF, LAMP_STATE_OFF }, { LAMP_STATE_OFF, LAMP_STATE_OFF } }, // LAMP_PATTERN_OK + { { 500, 500 }, { LAMP_STATE_OFF, LAMP_STATE_OFF }, { LAMP_STATE_OFF, LAMP_STATE_OFF }, { LAMP_STATE_ON, LAMP_STATE_OFF } }, // LAMP_PATTERN_FAULT + { { 500, 500 }, { LAMP_STATE_OFF, LAMP_STATE_OFF }, { LAMP_STATE_OFF, LAMP_STATE_OFF }, { LAMP_STATE_ON, LAMP_STATE_OFF } }, // LAMP_PATTERN_HIGH_ALARM + { { 1000, 1000 }, { LAMP_STATE_OFF, LAMP_STATE_OFF }, { LAMP_STATE_ON, LAMP_STATE_OFF }, { LAMP_STATE_OFF, LAMP_STATE_OFF } }, // LAMP_PATTERN_MED_ALARM + { { 500, 500 }, { LAMP_STATE_OFF, LAMP_STATE_OFF }, { LAMP_STATE_ON, LAMP_STATE_ON }, { LAMP_STATE_OFF, LAMP_STATE_OFF } }, // LAMP_PATTERN_LOW_ALARM + { { 0, 0 }, { LAMP_STATE_OFF, LAMP_STATE_OFF }, { LAMP_STATE_OFF, LAMP_STATE_OFF }, { LAMP_STATE_OFF, LAMP_STATE_OFF } } // LAMP_PATTERN_MANUAL }; +static ALARM_LAMP_SELF_TEST_STATE_T alarmLampSelfTestState = ALARM_LAMP_SELF_TEST_STATE_START; +static U32 alarmLampSelfTestStepTimerCount = 0; + // ********** private function prototypes ********** static void setAlarmLampToPatternStep( void ); @@ -65,82 +82,166 @@ * Outputs : AlarmLamp module initialized. * @param none * @return none -*************************************************************************/ + *************************************************************************/ void initAlarmLamp( void ) { - currentLampPattern = LAMP_PATTERN_OFF; - pendingLampPattern = LAMP_PATTERN_OFF; - currentLampPatternStep = 0; - lampPatternStepTimer = 0; + currentLampPattern = LAMP_PATTERN_OFF; + pendingLampPattern = LAMP_PATTERN_OFF; + currentLampPatternStep = 0; + lampPatternStepTimer = 0; + + alarmLampSelfTestState = ALARM_LAMP_SELF_TEST_STATE_START; + alarmLampSelfTestStepTimerCount = 0; } /************************************************************************* - * @brief ExecuteAlarmLamp - * The ExecuteAlarmLamp function executes the alarm lamp service for the \n + * @brief execAlarmLamp + * The execAlarmLamp function executes the alarm lamp service for the \n * current lamp pattern. * @details * Inputs : pendingLampPattern, currentLampPattern, lampPatternStepTimer, \n * lampPatterns. * Outputs : * @param none * @return none -*************************************************************************/ -void ExecuteAlarmLamp( void ) + *************************************************************************/ +void execAlarmLamp( void ) { - // if starting a new lamp pattern, reset pattern variables - if ( ( pendingLampPattern != currentLampPattern ) ) - { - currentLampPattern = pendingLampPattern; - currentLampPatternStep = 0; + // if starting a new lamp pattern, reset pattern variables + if ( pendingLampPattern != currentLampPattern ) + { + currentLampPattern = pendingLampPattern; + currentLampPatternStep = 0; - setAlarmLampToPatternStep(); - } - // otherwise, increment pattern timer - else - { - lampPatternStepTimer += TASK_GENERAL_INTERVAL; - } + setAlarmLampToPatternStep(); + } + // otherwise, increment pattern timer + else + { + lampPatternStepTimer += TASK_GENERAL_INTERVAL; + } - // control alarm lamp to currently set pattern (unless we're in manual pattern) - if ( currentLampPattern != LAMP_PATTERN_MANUAL ) - { - // if pattern step duration has elapsed, move to next step - if ( lampPatternStepTimer >= lampPatterns[currentLampPattern].duration[currentLampPatternStep] ) - { - // increment pattern step - currentLampPatternStep++; - if ( currentLampPatternStep >= NUM_OF_LAMP_STATES ) - { - currentLampPatternStep = 0; - } - // set lamps according to pattern step - setAlarmLampToPatternStep(); - } - } + // control alarm lamp to currently set pattern (unless we're in manual pattern) + if ( currentLampPattern != LAMP_PATTERN_MANUAL ) + { + // if pattern step duration has elapsed, move to next step + if ( lampPatternStepTimer >= lampPatterns[currentLampPattern].duration[currentLampPatternStep] ) + { + // increment pattern step + currentLampPatternStep++; + if ( currentLampPatternStep >= NUM_OF_LAMP_STATES ) + { + currentLampPatternStep = 0; + } + // set lamps according to pattern step + setAlarmLampToPatternStep(); + } + } } /************************************************************************* - * @brief RequestLampPattern - * The RequestLampPattern function sets a request for a new lamp pattern. + * @brief requestAlarmLampPattern + * The requestAlarmLampPattern function sets a request for a new lamp pattern. * @details * Inputs : none * Outputs : pendingLampPattern * @param lampPattern : new lamp pattern * @return none -*************************************************************************/ -void RequestLampPattern( LAMP_PATTERN_T lampPattern ) + *************************************************************************/ +void requestAlarmLampPattern( LAMP_PATTERN_T lampPattern ) { - if ( lampPattern < NUM_OF_LAMP_PATTERNS ) - { - pendingLampPattern = lampPattern; - } - else - { - // TODO - s/w fault - } + if ( lampPattern < NUM_OF_LAMP_PATTERNS ) + { + pendingLampPattern = lampPattern; + } + else + { + // TODO - s/w fault + } } /************************************************************************* + * @brief getCurrentAlarmLampPattern + * The getCurrentAlarmLampPattern function gets the current alarm lamp \n + * pattern in effect. + * @details + * Inputs : currentLampPattern + * Outputs : none + * @param none + * @return currentLampPattern + *************************************************************************/ +LAMP_PATTERN_T getCurrentAlarmLampPattern( void ) +{ + return currentLampPattern; +} + +/************************************************************************* + * @brief execAlarmLampTest + * The execAlarmLampTest function executes the alarm lamp test. \n + * This function should be called periodically until a pass or fail \n + * result is returned. + * @details + * Inputs : + * Outputs : + * @param none + * @return in progress, passed, or failed + *************************************************************************/ +SELF_TEST_STATUS_T execAlarmLampTest( void ) +{ + SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; + + switch ( alarmLampSelfTestState ) + { + case ALARM_LAMP_SELF_TEST_STATE_START: + alarmLampSelfTestState = ALARM_LAMP_SELF_TEST_STATE_RED; + alarmLampSelfTestStepTimerCount = getMSTimerCount(); + setCPLDLampRed( PIN_SIGNAL_HIGH ); + break; + + case ALARM_LAMP_SELF_TEST_STATE_RED: + if ( TRUE == didTimeout( alarmLampSelfTestStepTimerCount, POST_LAMP_STEP_TIME_MS ) ) + { + alarmLampSelfTestState = ALARM_LAMP_SELF_TEST_STATE_YELLOW; + alarmLampSelfTestStepTimerCount = getMSTimerCount(); + setCPLDLampRed( PIN_SIGNAL_LOW ); + setCPLDLampYellow( PIN_SIGNAL_HIGH ); + } + break; + + case ALARM_LAMP_SELF_TEST_STATE_YELLOW: + if ( TRUE == didTimeout( alarmLampSelfTestStepTimerCount, POST_LAMP_STEP_TIME_MS ) ) + { + alarmLampSelfTestState = ALARM_LAMP_SELF_TEST_STATE_GREEN; + alarmLampSelfTestStepTimerCount = getMSTimerCount(); + setCPLDLampYellow( PIN_SIGNAL_LOW ); + setCPLDLampGreen( PIN_SIGNAL_HIGH ); + } + break; + + case ALARM_LAMP_SELF_TEST_STATE_GREEN: + if ( TRUE == didTimeout( alarmLampSelfTestStepTimerCount, POST_LAMP_STEP_TIME_MS ) ) + { + alarmLampSelfTestState = ALARM_LAMP_SELF_TEST_STATE_COMPLETE; + setCPLDLampGreen( PIN_SIGNAL_LOW ); + result = SELF_TEST_STATUS_PASSED; + } + break; + + case ALARM_LAMP_SELF_TEST_STATE_COMPLETE: + // if we get called in this state, assume we're doing self test again + alarmLampSelfTestState = ALARM_LAMP_SELF_TEST_STATE_START; + break; + + default: + result = SELF_TEST_STATUS_FAILED; + // TODO - s/w fault + break; + } + + return result; +} + +/************************************************************************* * @brief setAlarmLampToPatternStep * The setAlarmLampToPatternStep function sets the lamps according to the \n * current lamp pattern and lamp pattern step. @@ -149,28 +250,28 @@ * Outputs : lampPatternStepTimer reset. Lamps set per current pattern. * @param lampPattern : new lamp pattern * @return none -*************************************************************************/ -void setAlarmLampToPatternStep( void ) + *************************************************************************/ +static void setAlarmLampToPatternStep( void ) { - PIN_SIGNAL_STATE_T green = PIN_SIGNAL_LOW; - PIN_SIGNAL_STATE_T yellow = PIN_SIGNAL_LOW; - PIN_SIGNAL_STATE_T red = PIN_SIGNAL_LOW; + PIN_SIGNAL_STATE_T green = PIN_SIGNAL_LOW; + PIN_SIGNAL_STATE_T yellow = PIN_SIGNAL_LOW; + PIN_SIGNAL_STATE_T red = PIN_SIGNAL_LOW; - lampPatternStepTimer = 0; - if ( lampPatterns[currentLampPattern].green[currentLampPatternStep] == LAMP_STATE_ON ) - { - green = PIN_SIGNAL_HIGH; - } - if ( lampPatterns[currentLampPattern].yellow[currentLampPatternStep] == LAMP_STATE_ON ) - { - yellow = PIN_SIGNAL_HIGH; - } - if ( lampPatterns[currentLampPattern].red[currentLampPatternStep] == LAMP_STATE_ON ) - { - red = PIN_SIGNAL_HIGH; - } + lampPatternStepTimer = 0; + if ( lampPatterns[currentLampPattern].green[currentLampPatternStep] == LAMP_STATE_ON ) + { + green = PIN_SIGNAL_HIGH; + } + if ( lampPatterns[currentLampPattern].yellow[currentLampPatternStep] == LAMP_STATE_ON ) + { + yellow = PIN_SIGNAL_HIGH; + } + if ( lampPatterns[currentLampPattern].red[currentLampPatternStep] == LAMP_STATE_ON ) + { + red = PIN_SIGNAL_HIGH; + } - setCPLDLampGreen( green ); - setCPLDLampYellow( yellow ); - setCPLDLampRed( red ); + setCPLDLampGreen( green ); + setCPLDLampYellow( yellow ); + setCPLDLampRed( red ); }