/************************************************************************* * * 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 "AlarmLamp.h" // ********** private definitions ********** typedef enum LampStates { 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 }; // ********** 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; 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 }; // ********** private function prototypes ********** static void setAlarmLampToPatternStep( void ); /************************************************************************* * @brief initAlarmLamp * The initAlarmLamp function initializes the AlarmLamp module. * @details * Inputs : none * Outputs : AlarmLamp module initialized. * @param none * @return none *************************************************************************/ void initAlarmLamp( void ) { currentLampPattern = LAMP_PATTERN_OFF; pendingLampPattern = LAMP_PATTERN_OFF; currentLampPatternStep = 0; lampPatternStepTimer = 0; } /************************************************************************* * @brief ExecuteAlarmLamp * The ExecuteAlarmLamp 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 ) { // 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; } // 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. * @details * Inputs : none * Outputs : pendingLampPattern * @param lampPattern : new lamp pattern * @return none *************************************************************************/ void RequestLampPattern( LAMP_PATTERN_T lampPattern ) { if ( lampPattern < NUM_OF_LAMP_PATTERNS ) { pendingLampPattern = lampPattern; } else { // TODO - s/w fault } } /************************************************************************* * @brief setAlarmLampToPatternStep * The setAlarmLampToPatternStep function sets the lamps according to the \n * current lamp pattern and lamp pattern step. * @details * Inputs : none * Outputs : lampPatternStepTimer reset. Lamps set per current pattern. * @param lampPattern : new lamp pattern * @return none *************************************************************************/ 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; 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 ); }