Index: App/Contollers/AlarmLamp.c =================================================================== diff -u -r765d2c35118e202444e737c66c77faf9678cc87e -r894b734327eb6e7cfa6bf651623576bc10214195 --- App/Contollers/AlarmLamp.c (.../AlarmLamp.c) (revision 765d2c35118e202444e737c66c77faf9678cc87e) +++ App/Contollers/AlarmLamp.c (.../AlarmLamp.c) (revision 894b734327eb6e7cfa6bf651623576bc10214195) @@ -1,18 +1,18 @@ /************************************************************************* -* -* 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" @@ -23,34 +23,35 @@ 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 +{ + 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; +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 }; // ********** private function prototypes ********** @@ -65,13 +66,13 @@ * 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; } /************************************************************************* @@ -84,39 +85,39 @@ * Outputs : * @param none * @return none -*************************************************************************/ + *************************************************************************/ void ExecuteAlarmLamp( 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(); + } + } } /************************************************************************* @@ -127,17 +128,17 @@ * 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 - } + if ( lampPattern < NUM_OF_LAMP_PATTERNS ) + { + pendingLampPattern = lampPattern; + } + else + { + // TODO - s/w fault + } } /************************************************************************* @@ -149,28 +150,28 @@ * 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; + 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 ); }