Index: .cproject =================================================================== diff -u -r67c59954ab757ae9d57b3d80f2b3cb8087300be6 -r3323966fe741edbb36dffc78317ccf06ed93a68e --- .cproject (.../.cproject) (revision 67c59954ab757ae9d57b3d80f2b3cb8087300be6) +++ .cproject (.../.cproject) (revision 3323966fe741edbb36dffc78317ccf06ed93a68e) @@ -44,7 +44,7 @@ - + Index: .settings/org.eclipse.core.resources.prefs =================================================================== diff -u -r879f01d26ef663cceccf14963c09f53e72c13cec -r3323966fe741edbb36dffc78317ccf06ed93a68e --- .settings/org.eclipse.core.resources.prefs (.../org.eclipse.core.resources.prefs) (revision 879f01d26ef663cceccf14963c09f53e72c13cec) +++ .settings/org.eclipse.core.resources.prefs (.../org.eclipse.core.resources.prefs) (revision 3323966fe741edbb36dffc78317ccf06ed93a68e) @@ -1,6 +1,8 @@ eclipse.preferences.version=1 encoding//Debug/App/Contollers/subdir_rules.mk=UTF-8 encoding//Debug/App/Contollers/subdir_vars.mk=UTF-8 +encoding//Debug/App/Controllers/subdir_rules.mk=UTF-8 +encoding//Debug/App/Controllers/subdir_vars.mk=UTF-8 encoding//Debug/App/Drivers/subdir_rules.mk=UTF-8 encoding//Debug/App/Drivers/subdir_vars.mk=UTF-8 encoding//Debug/App/Modes/subdir_rules.mk=UTF-8 Fisheye: Tag 3323966fe741edbb36dffc78317ccf06ed93a68e refers to a dead (removed) revision in file `App/Contollers/AlarmLamp.c'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 3323966fe741edbb36dffc78317ccf06ed93a68e refers to a dead (removed) revision in file `App/Contollers/AlarmLamp.h'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 3323966fe741edbb36dffc78317ccf06ed93a68e refers to a dead (removed) revision in file `App/Contollers/Buttons.c'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 3323966fe741edbb36dffc78317ccf06ed93a68e refers to a dead (removed) revision in file `App/Contollers/Buttons.h'. Fisheye: No comparison available. Pass `N' to diff? Index: App/Controllers/AlarmLamp.c =================================================================== diff -u --- App/Controllers/AlarmLamp.c (revision 0) +++ App/Controllers/AlarmLamp.c (revision 3323966fe741edbb36dffc78317ccf06ed93a68e) @@ -0,0 +1,275 @@ +/************************************************************************** + * + * Copyright (c) 2019-2019 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 AlarmLamp.c + * + * @date 20-Sep-2019 + * @author S. Nash + * + * @brief Controller for the alarm lamp. + * + **************************************************************************/ + +#include +#include "Common.h" +#include "CPLD.h" +#include "TaskGeneral.h" +#include "Timers.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 +{ + 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 blue[NUM_OF_LAMP_STATES]; // blue 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; + +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_ON, LAMP_STATE_OFF }, { LAMP_STATE_OFF, LAMP_STATE_OFF }, { LAMP_STATE_ON, LAMP_STATE_OFF } }, // LAMP_PATTERN_MED_ALARM + { { 500, 500 }, { LAMP_STATE_ON, LAMP_STATE_ON }, { LAMP_STATE_OFF, LAMP_STATE_OFF }, { LAMP_STATE_ON, LAMP_STATE_ON } }, // 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 ); + +/************************************************************************* + * @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; + + alarmLampSelfTestState = ALARM_LAMP_SELF_TEST_STATE_START; + alarmLampSelfTestStepTimerCount = 0; +} + +/************************************************************************* + * @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 execAlarmLamp( 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 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 requestAlarmLampPattern( LAMP_PATTERN_T lampPattern ) +{ + 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(); + setCPLDLampGreen( PIN_SIGNAL_HIGH ); // green + red = yellow + } + 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(); + setCPLDLampRed( PIN_SIGNAL_LOW ); + } + 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. + * @details + * Inputs : none + * Outputs : lampPatternStepTimer reset. Lamps set per current pattern. + * @param lampPattern : new lamp pattern + * @return none + *************************************************************************/ +static void setAlarmLampToPatternStep( void ) +{ + PIN_SIGNAL_STATE_T green = PIN_SIGNAL_LOW; + PIN_SIGNAL_STATE_T blue = 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].blue[currentLampPatternStep] == LAMP_STATE_ON ) + { + blue = PIN_SIGNAL_HIGH; + } + if ( lampPatterns[currentLampPattern].red[currentLampPatternStep] == LAMP_STATE_ON ) + { + red = PIN_SIGNAL_HIGH; + } + + setCPLDLampGreen( green ); + setCPLDLampBlue( blue ); + setCPLDLampRed( red ); +} Index: App/Controllers/AlarmLamp.h =================================================================== diff -u --- App/Controllers/AlarmLamp.h (revision 0) +++ App/Controllers/AlarmLamp.h (revision 3323966fe741edbb36dffc78317ccf06ed93a68e) @@ -0,0 +1,44 @@ +/************************************************************************** + * + * Copyright (c) 2019-2019 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 AlarmLamp.h + * + * @date 20-Sep-2019 + * @author S. Nash + * + * @brief Header file for Alarm Lamp module. + * + **************************************************************************/ + +#ifndef __ALARM_LAMP_H__ +#define __ALARM_LAMP_H__ + +#include "Common.h" + +// ********** public definitions ********** + +typedef enum LampPatternEnum +{ + LAMP_PATTERN_OFF = 0, + LAMP_PATTERN_OK, + LAMP_PATTERN_FAULT, + LAMP_PATTERN_HIGH_ALARM, + LAMP_PATTERN_MED_ALARM, + LAMP_PATTERN_LOW_ALARM, + LAMP_PATTERN_MANUAL, + NUM_OF_LAMP_PATTERNS +} LAMP_PATTERN_T; + +// ********** public function prototypes ********** + +void initAlarmLamp( void ); +void execAlarmLamp( void ); +void requestAlarmLampPattern( LAMP_PATTERN_T lampPattern ); +LAMP_PATTERN_T getCurrentAlarmLampPattern( void ); +SELF_TEST_STATUS_T execAlarmLampTest( void ); + +#endif Index: App/Controllers/Buttons.c =================================================================== diff -u --- App/Controllers/Buttons.c (revision 0) +++ App/Controllers/Buttons.c (revision 3323966fe741edbb36dffc78317ccf06ed93a68e) @@ -0,0 +1,363 @@ +/************************************************************************** + * + * Copyright (c) 2019-2019 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 Buttons.c + * + * @date 20-Sep-2019 + * @author S. Nash + * + * @brief Monitor/Controller for the off and stop buttons. + * + **************************************************************************/ + +#include +#include "Common.h" +#include "CPLD.h" +#include "OperationModes.h" +#include "SystemCommMessages.h" +#include "TaskPriority.h" +#include "Timers.h" + +// ********** private definitions ********** + +typedef enum Button_States +{ + BUTTON_STATE_RELEASED = 0, + BUTTON_STATE_PRESSED, + NUM_OF_BUTTON_STATES +} BUTTON_STATE_T; + +typedef enum Button_Self_Test_States +{ + BUTTON_SELF_TEST_STATE_START = 0, + BUTTON_SELF_TEST_STATE_IN_PROGRESS, + BUTTON_SELF_TEST_STATE_COMPLETE, + NUM_OF_BUTTON_SELF_TEST_STATES +} BUTTON_SELF_TEST_STATE_T; + +#define OFF_REQUEST_PULSE_COUNT 4 +#define OFF_REQUEST_PULSE_INTVL 50 // ms +#define STOP_BUTTON_PENDING_TIMEOUT 500 // ms +#define STUCK_BUTTON_TIMEOUT 1000 // ms + +#define USER_CONFIRMED 1 +#define USER_REJECTED 0 + +// ********** private data ********** + +static BUTTON_STATE_T offButtonState = BUTTON_STATE_RELEASED; +static BUTTON_STATE_T prevOffButtonState = BUTTON_STATE_RELEASED; +static BOOL offButtonPressPending = FALSE; + +static BUTTON_STATE_T stopButtonState = BUTTON_STATE_RELEASED; +static BUTTON_STATE_T prevStopButtonState = BUTTON_STATE_RELEASED; +static BOOL stopButtonPressPending = FALSE; +static U32 stopButtonPendingTimer = 0; + +static U32 offRequestPulseCount = 0; +static U32 offRequestPulseTimer = 0; + +static BUTTON_SELF_TEST_STATE_T buttonSelfTestState = BUTTON_SELF_TEST_STATE_START; +static U32 buttonSelfTestTimerCount = 0; + +// ********** private function prototypes ********** + +static void handleOffButtonProcessing( void ); +static void handleStopButtonProcessing( void ); +static BOOL isCurrentOpModeOkToTurnOff( void ); + +/************************************************************************* + * @brief initButtons + * The initButtons function initializes the Buttons module. + * @details + * Inputs : none + * Outputs : Buttons module initialized. + * @param none + * @return none + *************************************************************************/ +void initButtons( void ) +{ + offButtonState = BUTTON_STATE_RELEASED; + prevOffButtonState = BUTTON_STATE_RELEASED; + offButtonPressPending = FALSE; + + stopButtonState = BUTTON_STATE_RELEASED; + prevStopButtonState = BUTTON_STATE_RELEASED; + stopButtonPressPending = FALSE; + stopButtonPendingTimer = 0; + + offRequestPulseCount = 0; + offRequestPulseTimer = 0; + + buttonSelfTestState = BUTTON_SELF_TEST_STATE_START; + buttonSelfTestTimerCount = 0; +} + +/************************************************************************* + * @brief execButtons + * The execButtons function executes the Buttons monitor. + * @details + * Inputs : none + * Outputs : offButtonState, stopButtonState, prevOffButtonState, prevStopButtonState + * @param none + * @return none + *************************************************************************/ +void execButtons( void ) +{ + PIN_SIGNAL_STATE_T off = getCPLDOffButton(); + PIN_SIGNAL_STATE_T stop = getCPLDStopButton(); + + // set current button states read from CPLD + offButtonState = ( off == PIN_SIGNAL_HIGH ? BUTTON_STATE_PRESSED : BUTTON_STATE_RELEASED ); + stopButtonState = ( stop == PIN_SIGNAL_HIGH ? BUTTON_STATE_PRESSED : BUTTON_STATE_RELEASED ); + + // handle button state transitions for stop button + handleStopButtonProcessing(); + + // handle button state transitions for off button + handleOffButtonProcessing(); +} + +/************************************************************************* + * @brief isStopButtonPressed + * The isStopButtonPressed function determines whether the stop button has been \n + * pressed. Once the stop button has transitioned from released to pressed, a \n + * press for the stop button will be pending until this function is called. \n + * @details + * Inputs : stopButtonPressPending + * Outputs : stopButtonPressPending + * @param button + * @return true if the stop button is pressed, false if not + *************************************************************************/ +BOOL isStopButtonPressed( void ) +{ + BOOL result = stopButtonPressPending; + + stopButtonPressPending = FALSE; + + return result; +} + +/************************************************************************* + * @brief isButtonPressedRaw + * The isButtonPressedRaw function determines whether a given button is currently \n + * pressed. + * @details + * Inputs : offButtonState, prevOffButtonState, stopButtonState, prevStopButtonState + * Outputs : none + * @param button + * @return true if given button is pressed, false if not + *************************************************************************/ +BOOL isButtonPressedRaw( BUTTON_T button ) +{ + BOOL result = FALSE; + + switch ( button ) + { + case BUTTON_OFF: + if ( offButtonState == BUTTON_STATE_PRESSED ) + { + result = TRUE; + } + break; + case BUTTON_STOP: + if ( stopButtonState == BUTTON_STATE_PRESSED ) + { + result = TRUE; + } + break; + default: + // TODO - s/w fault + break; + } + + return result; +} + +/************************************************************************* + * @brief userConfirmOffButton + * The userConfirmOffButton function handles user confirmation of the off \n + * button. The off request will be initiated here if confirmed or cancelled \n + * if rejected by user. + * @details + * Inputs : current operation mode + * Outputs : stopButtonPressPending + * @param response : 1 = confirmed, 0 = rejected + * @return none + *************************************************************************/ +void userConfirmOffButton( U08 response ) +{ + // did user confirm? + if ( USER_CONFIRMED == response ) + { + if ( TRUE == isCurrentOpModeOkToTurnOff() ) + { + offButtonPressPending = TRUE; + offRequestPulseCount = OFF_REQUEST_PULSE_COUNT; + offRequestPulseTimer = 0; + } + } + else // user did not confirm + { + // for now, don't need to do anything to reject off button press + } +} + +/************************************************************************* + * @brief execStuckButtonTest + * The execStuckButtonTest function executes the stuck button 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 execStuckButtonTest( void ) +{ + SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; + + switch ( buttonSelfTestState ) + { + case BUTTON_SELF_TEST_STATE_START: + buttonSelfTestState = BUTTON_SELF_TEST_STATE_IN_PROGRESS; + buttonSelfTestTimerCount = getMSTimerCount(); + // no break here so we pass through directly to in progress processing + + case BUTTON_SELF_TEST_STATE_IN_PROGRESS: + if ( ( offButtonState == BUTTON_STATE_RELEASED ) && ( stopButtonState == BUTTON_STATE_RELEASED ) ) + { + result = SELF_TEST_STATUS_PASSED; + buttonSelfTestState = BUTTON_SELF_TEST_STATE_COMPLETE; + } + else if ( TRUE == didTimeout( buttonSelfTestTimerCount, STUCK_BUTTON_TIMEOUT ) ) + { + result = SELF_TEST_STATUS_FAILED; + // TODO - trigger stuck button POST failure + buttonSelfTestState = BUTTON_SELF_TEST_STATE_COMPLETE; + } + // else just stay in progress and wait for next call + break; + + case BUTTON_SELF_TEST_STATE_COMPLETE: + // if we get called in this state, assume we're doing self test again + buttonSelfTestState = BUTTON_SELF_TEST_STATE_START; + break; + + default: + result = SELF_TEST_STATUS_FAILED; + // TODO - s/w fault + break; + } + + return result; +} + +/************************************************************************* + * @brief isCurrentOpModeOkToTurnOff + * The isCurrentOpModeOkToTurnOff function determines whether the system can \n + * be turned off in current operation mode. + * @details + * Inputs : Current operation mode. + * Outputs : none + * @param none + * @return true if can turn system off in current mode, false if not + *************************************************************************/ +static BOOL isCurrentOpModeOkToTurnOff( void ) +{ + OP_MODE opMode = getCurrentOperationMode(); + BOOL result = FALSE; + + if ( ( opMode == MODE_STAN ) || ( opMode == MODE_SERV ) || ( opMode == MODE_FAUL ) ) + { + result = TRUE; + } + + return result; +} + +/************************************************************************* + * @brief handleOffButtonProcessing + * The handleOffButtonProcessing function checks for and processes off button \n + * activity. + * @details + * Inputs : offButtonState, prevOffButtonState + * Outputs : offButtonPressPending, offRequestPulseCount, offRequestPulseTimer + * @param none + * @return none + *************************************************************************/ +static void handleOffButtonProcessing( void ) +{ + // handle button state transitions for off button + if ( offButtonState != prevOffButtonState ) + { + if ( offButtonState == BUTTON_STATE_PRESSED ) + { + // if off request in a valid mode, send to UI for user confirmation + if ( TRUE == isCurrentOpModeOkToTurnOff() ) + { + // send off button to UI for user confirmation + sendOffButtonMsgToUI(); +#ifdef SIMULATE_UI + userConfirmOffButton( USER_CONFIRMED ); +#endif + } + } + prevOffButtonState = offButtonState; + } + + if ( TRUE == offButtonPressPending ) + { + offRequestPulseTimer += TASK_PRIORITY_INTERVAL; + if ( offRequestPulseTimer >= OFF_REQUEST_PULSE_INTVL ) + { + offRequestPulseTimer = 0; + offRequestPulseCount--; + if ( offRequestPulseCount == 0 ) + { + offButtonPressPending = false; + } + toggleCPLDOffRequest(); + } + } +} + +/************************************************************************* + * @brief handleStopButtonProcessing + * The handleStopButtonProcessing function checks for and processes stop button \n + * activity. + * @details + * Inputs : stopButtonState, prevStopButtonState + * Outputs : stopButtonPressPending + * @param none + * @return none + *************************************************************************/ +static void handleStopButtonProcessing( void ) +{ + // handle button state transitions for stop button + if ( stopButtonState != prevStopButtonState ) + { + if ( stopButtonState == BUTTON_STATE_PRESSED ) + { + stopButtonPressPending = TRUE; + stopButtonPendingTimer = getMSTimerCount(); + } + prevStopButtonState = stopButtonState; + } + + // handle when a stop button press is pending + if ( TRUE == stopButtonPressPending ) + { + // if stop button not consumed within a reasonable time, s/w fault + if ( TRUE == didTimeout( stopButtonPendingTimer, STOP_BUTTON_PENDING_TIMEOUT ) ) + { + // TODO - s/w fault + } + } +} + Index: App/Controllers/Buttons.h =================================================================== diff -u --- App/Controllers/Buttons.h (revision 0) +++ App/Controllers/Buttons.h (revision 3323966fe741edbb36dffc78317ccf06ed93a68e) @@ -0,0 +1,40 @@ +/************************************************************************** + * + * Copyright (c) 2019-2019 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 Buttons.h + * + * @date 20-Sep-2019 + * @author S. Nash + * + * @brief Buttons header file. + * + **************************************************************************/ + +#ifndef __BUTTONS_H__ +#define __BUTTONS_H__ + +#include "Common.h" + +// ********** public definitions ********** + +typedef enum Buttons +{ + BUTTON_OFF = 0, // Off button + BUTTON_STOP, // Stop button + NUM_OF_BUTTONS +} BUTTON_T; + +// ********** public function prototypes ********** + +void initButtons( void ); +void execButtons( void ); +BOOL isStopButtonPressed( void ); +BOOL isButtonPressedRaw( BUTTON_T button ); +void userConfirmOffButton( U08 response ); +SELF_TEST_STATUS_T execStuckButtonTest( void ); + +#endif Index: App/Drivers/CPLD.c =================================================================== diff -u -r8ba82119080b77f804fa2b3edadd11422f57371b -r3323966fe741edbb36dffc78317ccf06ed93a68e --- App/Drivers/CPLD.c (.../CPLD.c) (revision 8ba82119080b77f804fa2b3edadd11422f57371b) +++ App/Drivers/CPLD.c (.../CPLD.c) (revision 3323966fe741edbb36dffc78317ccf06ed93a68e) @@ -14,11 +14,11 @@ * **************************************************************************/ +#include +#include #include "gio.h" #include "mibspi.h" -#include "AlarmLamp.h" -#include "Buttons.h" #include "WatchdogMgmt.h" #include "CPLD.h" Index: App/Modes/ModeFault.c =================================================================== diff -u -r9aec79f151c686b730888c98f70f53ad958fe9b5 -r3323966fe741edbb36dffc78317ccf06ed93a68e --- App/Modes/ModeFault.c (.../ModeFault.c) (revision 9aec79f151c686b730888c98f70f53ad958fe9b5) +++ App/Modes/ModeFault.c (.../ModeFault.c) (revision 3323966fe741edbb36dffc78317ccf06ed93a68e) @@ -14,8 +14,8 @@ * **************************************************************************/ +#include #include "Common.h" -#include "AlarmLamp.h" #include "OperationModes.h" #include "ModeFault.h" Index: App/Modes/ModeInitPOST.c =================================================================== diff -u -r9aec79f151c686b730888c98f70f53ad958fe9b5 -r3323966fe741edbb36dffc78317ccf06ed93a68e --- App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision 9aec79f151c686b730888c98f70f53ad958fe9b5) +++ App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision 3323966fe741edbb36dffc78317ccf06ed93a68e) @@ -14,9 +14,9 @@ * **************************************************************************/ +#include +#include #include "Common.h" -#include "AlarmLamp.h" -#include "Buttons.h" #include "CPLD.h" #include "OperationModes.h" #include "WatchdogMgmt.h" Index: App/Modes/ModeOpParams.c =================================================================== diff -u -r9aec79f151c686b730888c98f70f53ad958fe9b5 -r3323966fe741edbb36dffc78317ccf06ed93a68e --- App/Modes/ModeOpParams.c (.../ModeOpParams.c) (revision 9aec79f151c686b730888c98f70f53ad958fe9b5) +++ App/Modes/ModeOpParams.c (.../ModeOpParams.c) (revision 3323966fe741edbb36dffc78317ccf06ed93a68e) @@ -14,9 +14,9 @@ * **************************************************************************/ +#include +#include #include "Common.h" -#include "AlarmLamp.h" -#include "Buttons.h" #include "OperationModes.h" #include "ModeOpParams.h" Index: App/Modes/ModePostTreat.c =================================================================== diff -u -r9aec79f151c686b730888c98f70f53ad958fe9b5 -r3323966fe741edbb36dffc78317ccf06ed93a68e --- App/Modes/ModePostTreat.c (.../ModePostTreat.c) (revision 9aec79f151c686b730888c98f70f53ad958fe9b5) +++ App/Modes/ModePostTreat.c (.../ModePostTreat.c) (revision 3323966fe741edbb36dffc78317ccf06ed93a68e) @@ -14,9 +14,9 @@ * **************************************************************************/ +#include +#include #include "Common.h" -#include "AlarmLamp.h" -#include "Buttons.h" #include "OperationModes.h" #include "ModePostTreat.h" Index: App/Modes/ModePreTreat.c =================================================================== diff -u -r9aec79f151c686b730888c98f70f53ad958fe9b5 -r3323966fe741edbb36dffc78317ccf06ed93a68e --- App/Modes/ModePreTreat.c (.../ModePreTreat.c) (revision 9aec79f151c686b730888c98f70f53ad958fe9b5) +++ App/Modes/ModePreTreat.c (.../ModePreTreat.c) (revision 3323966fe741edbb36dffc78317ccf06ed93a68e) @@ -14,9 +14,9 @@ * *************************************************************************/ +#include +#include #include "Common.h" -#include "AlarmLamp.h" -#include "Buttons.h" #include "OperationModes.h" #include "ModePreTreat.h" Index: App/Modes/ModePrescription.c =================================================================== diff -u -r9aec79f151c686b730888c98f70f53ad958fe9b5 -r3323966fe741edbb36dffc78317ccf06ed93a68e --- App/Modes/ModePrescription.c (.../ModePrescription.c) (revision 9aec79f151c686b730888c98f70f53ad958fe9b5) +++ App/Modes/ModePrescription.c (.../ModePrescription.c) (revision 3323966fe741edbb36dffc78317ccf06ed93a68e) @@ -14,9 +14,9 @@ * **************************************************************************/ +#include +#include #include "Common.h" -#include "AlarmLamp.h" -#include "Buttons.h" #include "OperationModes.h" #include "ModePrescription.h" Index: App/Modes/ModeStandby.c =================================================================== diff -u -r9aec79f151c686b730888c98f70f53ad958fe9b5 -r3323966fe741edbb36dffc78317ccf06ed93a68e --- App/Modes/ModeStandby.c (.../ModeStandby.c) (revision 9aec79f151c686b730888c98f70f53ad958fe9b5) +++ App/Modes/ModeStandby.c (.../ModeStandby.c) (revision 3323966fe741edbb36dffc78317ccf06ed93a68e) @@ -14,9 +14,9 @@ * **************************************************************************/ +#include +#include #include "Common.h" -#include "AlarmLamp.h" -#include "Buttons.h" #include "OperationModes.h" #include "ModeStandby.h" Index: App/Modes/ModeTreatment.c =================================================================== diff -u -r9aec79f151c686b730888c98f70f53ad958fe9b5 -r3323966fe741edbb36dffc78317ccf06ed93a68e --- App/Modes/ModeTreatment.c (.../ModeTreatment.c) (revision 9aec79f151c686b730888c98f70f53ad958fe9b5) +++ App/Modes/ModeTreatment.c (.../ModeTreatment.c) (revision 3323966fe741edbb36dffc78317ccf06ed93a68e) @@ -14,9 +14,9 @@ * **************************************************************************/ +#include +#include #include "Common.h" -#include "AlarmLamp.h" -#include "Buttons.h" #include "OperationModes.h" #include "ModeTreatment.h" Index: App/Services/SystemComm.c =================================================================== diff -u -ra0f8a69651a1c29c9f76894aed5ab23ee8ace7c7 -r3323966fe741edbb36dffc78317ccf06ed93a68e --- App/Services/SystemComm.c (.../SystemComm.c) (revision a0f8a69651a1c29c9f76894aed5ab23ee8ace7c7) +++ App/Services/SystemComm.c (.../SystemComm.c) (revision 3323966fe741edbb36dffc78317ccf06ed93a68e) @@ -16,12 +16,12 @@ * **************************************************************************/ +#include #include // for memcpy() #include "can.h" #include "Common.h" -#include "Buttons.h" #include "MsgQueues.h" #include "SystemCommMessages.h" #include "SystemComm.h" Index: App/Services/SystemCommMessages.c =================================================================== diff -u -r1d856a336fbfdc72a1e1165b64f1725e497c5f65 -r3323966fe741edbb36dffc78317ccf06ed93a68e --- App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 1d856a336fbfdc72a1e1165b64f1725e497c5f65) +++ App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 3323966fe741edbb36dffc78317ccf06ed93a68e) @@ -16,10 +16,10 @@ * **************************************************************************/ +#include #include // for memcpy() #include "Common.h" -#include "Buttons.h" #include "MsgQueues.h" #include "SystemCommMessages.h" #include "SystemComm.h" Index: App/Tasks/TaskGeneral.c =================================================================== diff -u -r8ba82119080b77f804fa2b3edadd11422f57371b -r3323966fe741edbb36dffc78317ccf06ed93a68e --- App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 8ba82119080b77f804fa2b3edadd11422f57371b) +++ App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 3323966fe741edbb36dffc78317ccf06ed93a68e) @@ -14,11 +14,11 @@ * **************************************************************************/ +#include #include "gio.h" #include "lin.h" #include "Common.h" -#include "AlarmLamp.h" #include "OperationModes.h" #include "SystemComm.h" #include "WatchdogMgmt.h" Index: App/Tasks/TaskPriority.c =================================================================== diff -u -r9aec79f151c686b730888c98f70f53ad958fe9b5 -r3323966fe741edbb36dffc78317ccf06ed93a68e --- App/Tasks/TaskPriority.c (.../TaskPriority.c) (revision 9aec79f151c686b730888c98f70f53ad958fe9b5) +++ App/Tasks/TaskPriority.c (.../TaskPriority.c) (revision 3323966fe741edbb36dffc78317ccf06ed93a68e) @@ -14,10 +14,10 @@ * **************************************************************************/ +#include #include "gio.h" #include "WatchdogMgmt.h" -#include "Buttons.h" #include "TaskPriority.h" /************************************************************************* Index: Debug/App/Drivers/subdir_rules.mk =================================================================== diff -u -r67c59954ab757ae9d57b3d80f2b3cb8087300be6 -r3323966fe741edbb36dffc78317ccf06ed93a68e --- Debug/App/Drivers/subdir_rules.mk (.../subdir_rules.mk) (revision 67c59954ab757ae9d57b3d80f2b3cb8087300be6) +++ Debug/App/Drivers/subdir_rules.mk (.../subdir_rules.mk) (revision 3323966fe741edbb36dffc78317ccf06ed93a68e) @@ -6,7 +6,7 @@ App/Drivers/%.obj: ../App/Drivers/%.c $(GEN_OPTS) | $(GEN_FILES) @echo 'Building file: "$<"' @echo 'Invoking: ARM Compiler' - "/home/fw/ti/ccs910/ccs/tools/compiler/ti-cgt-arm_18.12.2.LTS/bin/armcl" -mv7R4 --code_state=32 --float_support=VFPv3D16 -me --include_path="/home/fw/workspace_HD/HD/hdproject/App" --include_path="/home/fw/workspace_HD/HD/hdproject/App/Tasks" --include_path="/home/fw/workspace_HD/HD/hdproject/App/Modes" --include_path="/home/fw/workspace_HD/HD/hdproject/App/Drivers" --include_path="/home/fw/workspace_HD/HD/hdproject/App/Contollers" --include_path="/home/fw/workspace_HD/HD/hdproject/App/Services" --include_path="/home/fw/workspace_HD/HD/hdproject" --include_path="/home/fw/workspace_HD/HD/hdproject/include" --include_path="/home/fw/ti/ccs910/ccs/tools/compiler/ti-cgt-arm_18.12.2.LTS/include" --define=__TI_VIM_128CH__ -g --diag_warning=225 --diag_wrap=off --display_error_number --enum_type=packed --abi=eabi --preproc_with_compile --preproc_dependency="App/Drivers/$(basename $(ABOTR = (uint32)110U; + canREG1->ABOTR = (uint32)103U; /** - Initialize message 1 * - Wait until IF1 is ready for use @@ -401,10 +401,10 @@ * - Setup baud rate prescaler */ canREG1->BTR = (uint32)((uint32)0U << 16U) | - (uint32)((uint32)(4U - 1U) << 12U) | - (uint32)((uint32)((2U + 4U) - 1U) << 8U) | - (uint32)((uint32)(4U - 1U) << 6U) | - (uint32)39U; + (uint32)((uint32)(3U - 1U) << 12U) | + (uint32)((uint32)((2U + 3U) - 1U) << 8U) | + (uint32)((uint32)(3U - 1U) << 6U) | + (uint32)45U; /** - CAN1 Port output values */ Index: source/mibspi.c =================================================================== diff -u -r7de64c199413a3f74d69efbdd1424b37c6f607c9 -r3323966fe741edbb36dffc78317ccf06ed93a68e --- source/mibspi.c (.../mibspi.c) (revision 7de64c199413a3f74d69efbdd1424b37c6f607c9) +++ source/mibspi.c (.../mibspi.c) (revision 3323966fe741edbb36dffc78317ccf06ed93a68e) @@ -96,7 +96,7 @@ | (uint32)((uint32)0U << 20U) /* shift direction */ | (uint32)((uint32)0U << 17U) /* clock polarity */ | (uint32)((uint32)0U << 16U) /* clock phase */ - | (uint32)((uint32)109U << 8U) /* baudrate prescale */ + | (uint32)((uint32)102U << 8U) /* baudrate prescale */ | (uint32)((uint32)16U << 0U); /* data word length */ /** - Data Format 1 */ @@ -107,7 +107,7 @@ | (uint32)((uint32)0U << 20U) /* shift direction */ | (uint32)((uint32)0U << 17U) /* clock polarity */ | (uint32)((uint32)0U << 16U) /* clock phase */ - | (uint32)((uint32)109U << 8U) /* baudrate prescale */ + | (uint32)((uint32)102U << 8U) /* baudrate prescale */ | (uint32)((uint32)16U << 0U); /* data word length */ /** - Data Format 2 */ @@ -118,7 +118,7 @@ | (uint32)((uint32)0U << 20U) /* shift direction */ | (uint32)((uint32)0U << 17U) /* clock polarity */ | (uint32)((uint32)0U << 16U) /* clock phase */ - | (uint32)((uint32)109U << 8U) /* baudrate prescale */ + | (uint32)((uint32)102U << 8U) /* baudrate prescale */ | (uint32)((uint32)16U << 0U); /* data word length */ /** - Data Format 3 */ @@ -129,7 +129,7 @@ | (uint32)((uint32)0U << 20U) /* shift direction */ | (uint32)((uint32)0U << 17U) /* clock polarity */ | (uint32)((uint32)0U << 16U) /* clock phase */ - | (uint32)((uint32)109U << 8U) /* baudrate prescale */ + | (uint32)((uint32)102U << 8U) /* baudrate prescale */ | (uint32)((uint32)16U << 0U); /* data word length */ /** - Default Chip Select */ Index: source/notification.c =================================================================== diff -u -r8ba82119080b77f804fa2b3edadd11422f57371b -r3323966fe741edbb36dffc78317ccf06ed93a68e --- source/notification.c (.../notification.c) (revision 8ba82119080b77f804fa2b3edadd11422f57371b) +++ source/notification.c (.../notification.c) (revision 3323966fe741edbb36dffc78317ccf06ed93a68e) @@ -52,7 +52,6 @@ #include "sys_selftest.h" #include "can.h" #include "gio.h" -#include "lin.h" #include "mibspi.h" #include "sci.h" #include "rti.h" @@ -146,16 +145,6 @@ /* USER CODE BEGIN (20) */ /* USER CODE END */ -#pragma WEAK(linNotification) -void linNotification(linBASE_t *lin, uint32 flags) -{ -/* enter user code between the USER CODE BEGIN and USER CODE END. */ -/* USER CODE BEGIN (23) */ -/* USER CODE END */ -} - -/* USER CODE BEGIN (24) */ -/* USER CODE END */ #pragma WEAK(mibspiNotification) void mibspiNotification(mibspiBASE_t *mibspi, uint32 flags) { Index: source/rti.c =================================================================== diff -u -r29f1ba03faefd982327916590818a260a3e4aa48 -r3323966fe741edbb36dffc78317ccf06ed93a68e --- source/rti.c (.../rti.c) (revision 29f1ba03faefd982327916590818a260a3e4aa48) +++ source/rti.c (.../rti.c) (revision 3323966fe741edbb36dffc78317ccf06ed93a68e) @@ -102,7 +102,7 @@ * - 0x00000000: Divide by 2^32 * - 0x00000001-0xFFFFFFFF: Divide by (CPUC0 + 1) */ - rtiREG1->CNT[0U].CPUCx = 10U; + rtiREG1->CNT[0U].CPUCx = 9U; /** - Reset up counter 1 */ rtiREG1->CNT[1U].UCx = 0x00000000U; @@ -114,31 +114,31 @@ * - 0x00000000: Divide by 2^32 * - 0x00000001-0xFFFFFFFF: Divide by (CPUC1 + 1) */ - rtiREG1->CNT[1U].CPUCx = 10U; + rtiREG1->CNT[1U].CPUCx = 9U; /** - Setup compare 0 value. This value is compared with selected free running counter. */ - rtiREG1->CMP[0U].COMPx = 10000U; + rtiREG1->CMP[0U].COMPx = 10334U; /** - Setup update compare 0 value. This value is added to the compare 0 value on each compare match. */ - rtiREG1->CMP[0U].UDCPx = 10000U; + rtiREG1->CMP[0U].UDCPx = 10334U; /** - Setup compare 1 value. This value is compared with selected free running counter. */ - rtiREG1->CMP[1U].COMPx = 50000U; + rtiREG1->CMP[1U].COMPx = 51668U; /** - Setup update compare 1 value. This value is added to the compare 1 value on each compare match. */ - rtiREG1->CMP[1U].UDCPx = 50000U; + rtiREG1->CMP[1U].UDCPx = 51668U; /** - Setup compare 2 value. This value is compared with selected free running counter. */ - rtiREG1->CMP[2U].COMPx = 80000U; + rtiREG1->CMP[2U].COMPx = 82668U; /** - Setup update compare 2 value. This value is added to the compare 2 value on each compare match. */ - rtiREG1->CMP[2U].UDCPx = 80000U; + rtiREG1->CMP[2U].UDCPx = 82668U; /** - Setup compare 3 value. This value is compared with selected free running counter. */ - rtiREG1->CMP[3U].COMPx = 500000U; + rtiREG1->CMP[3U].COMPx = 516675U; /** - Setup update compare 3 value. This value is added to the compare 3 value on each compare match. */ - rtiREG1->CMP[3U].UDCPx = 500000U; + rtiREG1->CMP[3U].UDCPx = 516675U; /** - Clear all pending interrupts */ rtiREG1->INTFLAG = 0x0007000FU; Index: source/sci.c =================================================================== diff -u -r7de64c199413a3f74d69efbdd1424b37c6f607c9 -r3323966fe741edbb36dffc78317ccf06ed93a68e --- source/sci.c (.../sci.c) (revision 7de64c199413a3f74d69efbdd1424b37c6f607c9) +++ source/sci.c (.../sci.c) (revision 3323966fe741edbb36dffc78317ccf06ed93a68e) @@ -90,13 +90,13 @@ sciREG->GCR1 = (uint32)((uint32)1U << 25U) /* enable transmit */ | (uint32)((uint32)1U << 24U) /* enable receive */ | (uint32)((uint32)1U << 5U) /* internal clock (device has no clock pin) */ - | (uint32)((uint32)(2U-1U) << 4U) /* number of stop bits */ + | (uint32)((uint32)(1U-1U) << 4U) /* number of stop bits */ | (uint32)((uint32)0U << 3U) /* even parity, otherwise odd */ | (uint32)((uint32)0U << 2U) /* enable parity */ | (uint32)((uint32)1U << 1U); /* asynchronous timing mode */ /** - set baudrate */ - sciREG->BRS = 715U; /* baudrate */ + sciREG->BRS = 55U; /* baudrate */ /** - transmission length */ sciREG->FORMAT = 8U - 1U; /* length */ @@ -110,7 +110,7 @@ | (uint32)((uint32)0U << 1U); /* rx pin */ /** - set SCI pins output direction */ - sciREG->PIO1 = (uint32)((uint32)0U << 2U) /* tx pin */ + sciREG->PIO1 = (uint32)((uint32)1U << 2U) /* tx pin */ | (uint32)((uint32)0U << 1U); /* rx pin */ /** - set SCI pins open drain enable */ @@ -135,22 +135,103 @@ | (uint32)((uint32)0U << 0U); /* Break detect */ /** - set interrupt enable */ - sciREG->SETINT = (uint32)((uint32)0U << 26U) /* Framing error */ - | (uint32)((uint32)0U << 25U) /* Overrun error */ + sciREG->SETINT = (uint32)((uint32)1U << 26U) /* Framing error */ + | (uint32)((uint32)1U << 25U) /* Overrun error */ | (uint32)((uint32)0U << 24U) /* Parity error */ - | (uint32)((uint32)0U << 9U) /* Receive */ + | (uint32)((uint32)1U << 9U) /* Receive */ | (uint32)((uint32)0U << 1U) /* Wakeup */ | (uint32)((uint32)0U << 0U); /* Break detect */ /** - initialize global transfer variables */ - g_sciTransfer_t[0U].mode = (uint32)0U << 8U; + g_sciTransfer_t[0U].mode = (uint32)1U << 8U; g_sciTransfer_t[0U].tx_length = 0U; g_sciTransfer_t[0U].rx_length = 0U; /** - Finaly start SCI */ sciREG->GCR1 |= 0x80U; + + /** @b initialize @b SCILIN */ + + /** - bring SCI out of reset */ + scilinREG->GCR0 = 0U; + scilinREG->GCR0 = 1U; + + /** - Disable all interrupts */ + scilinREG->CLEARINT = 0xFFFFFFFFU; + scilinREG->CLEARINTLVL = 0xFFFFFFFFU; + + /** - global control 1 */ + scilinREG->GCR1 = (uint32)((uint32)1U << 25U) /* enable transmit */ + | (uint32)((uint32)1U << 24U) /* enable receive */ + | (uint32)((uint32)1U << 5U) /* internal clock (device has no clock pin) */ + | (uint32)((uint32)(1U-1U) << 4U) /* number of stop bits */ + | (uint32)((uint32)0U << 3U) /* even parity, otherwise odd */ + | (uint32)((uint32)0U << 2U) /* enable parity */ + | (uint32)((uint32)1U << 1U); /* asynchronous timing mode */ + + /** - set baudrate */ + scilinREG->BRS = 6U; /* baudrate */ + + /** - transmission length */ + scilinREG->FORMAT = 8U - 1U; /* length */ + + /** - set SCI pins functional mode */ + scilinREG->PIO0 = (uint32)((uint32)1U << 2U) /* tx pin */ + | (uint32)((uint32)1U << 1U); /* rx pin */ + + + /** - set SCI pins default output value */ + scilinREG->PIO3 = (uint32)((uint32)0U << 2U) /* tx pin */ + | (uint32)((uint32)0U << 1U); /* rx pin */ + + + /** - set SCI pins output direction */ + scilinREG->PIO1 = (uint32)((uint32)1U << 2U) /* tx pin */ + | (uint32)((uint32)0U << 1U); /* rx pin */ + + + /** - set SCI pins open drain enable */ + scilinREG->PIO6 = (uint32)((uint32)0U << 2U) /* tx pin */ + | (uint32)((uint32)0U << 1U); /* rx pin */ + + + /** - set SCI pins pullup/pulldown enable */ + scilinREG->PIO7 = (uint32)((uint32)0U << 2U) /* tx pin */ + | (uint32)((uint32)0U << 1U); /* rx pin */ + + + /** - set SCI pins pullup/pulldown select */ + scilinREG->PIO8 = (uint32)((uint32)1U << 2U) /* tx pin */ + | (uint32)((uint32)1U << 1U); /* rx pin */ + + + /** - set interrupt level */ + scilinREG->SETINTLVL = (uint32)((uint32)0U << 26U) /* Framing error */ + | (uint32)((uint32)0U << 25U) /* Overrun error */ + | (uint32)((uint32)0U << 24U) /* Parity error */ + | (uint32)((uint32)0U << 9U) /* Receive */ + | (uint32)((uint32)0U << 8U) /* Transmit */ + | (uint32)((uint32)0U << 1U) /* Wakeup */ + | (uint32)((uint32)0U); /* Break detect */ + + /** - set interrupt enable */ + scilinREG->SETINT = (uint32)((uint32)1U << 26U) /* Framing error */ + | (uint32)((uint32)1U << 25U) /* Overrun error */ + | (uint32)((uint32)0U << 24U) /* Parity error */ + | (uint32)((uint32)1U << 9U) /* Receive */ + | (uint32)((uint32)0U << 1U) /* Wakeup */ + | (uint32)((uint32)0U); /* Break detect */ + + /** - initialize global transfer variables */ + g_sciTransfer_t[1U].mode = (uint32)1U << 8U; + g_sciTransfer_t[1U].tx_length = 0U; + g_sciTransfer_t[1U].rx_length = 0U; + + /** - Finaly start SCILIN */ + scilinREG->GCR1 |= 0x80U; + /* USER CODE BEGIN (3) */ /* USER CODE END */ } @@ -192,7 +273,7 @@ /* Requirements : HL_SR232 */ void sciSetBaudrate(sciBASE_t *sci, uint32 baud) { - float64 vclk = 110.000 * 1000000.0; + float64 vclk = 103.335 * 1000000.0; uint32 f = ((sci->GCR1 & 2U) == 2U) ? 16U : 1U; uint32 temp; float64 temp2; @@ -661,6 +742,56 @@ } } +/** @fn void scilinGetConfigValue(sci_config_reg_t *config_reg, config_value_type_t type) +* @brief Get the initial or current values of the SCILIN ( SCI2) configuration registers +* +* @param[in] *config_reg: pointer to the struct to which the initial or current +* value of the configuration registers need to be stored +* @param[in] type: whether initial or current value of the configuration registers need to be stored +* - InitialValue: initial value of the configuration registers will be stored +* in the struct pointed by config_reg +* - CurrentValue: initial value of the configuration registers will be stored +* in the struct pointed by config_reg +* +* This function will copy the initial or current value (depending on the parameter 'type') +* of the configuration registers to the struct pointed by config_reg +* +*/ +/* SourceId : SCI_SourceId_017 */ +/* DesignId : SCI_DesignId_016 */ +/* Requirements : HL_SR247 */ +void scilinGetConfigValue(sci_config_reg_t *config_reg, config_value_type_t type) +{ + if (type == InitialValue) + { + config_reg->CONFIG_GCR0 = SCILIN_GCR0_CONFIGVALUE; + config_reg->CONFIG_GCR1 = SCILIN_GCR1_CONFIGVALUE; + config_reg->CONFIG_SETINT = SCILIN_SETINT_CONFIGVALUE; + config_reg->CONFIG_SETINTLVL = SCILIN_SETINTLVL_CONFIGVALUE; + config_reg->CONFIG_FORMAT = SCILIN_FORMAT_CONFIGVALUE; + config_reg->CONFIG_BRS = SCILIN_BRS_CONFIGVALUE; + config_reg->CONFIG_PIO0 = SCILIN_PIO0_CONFIGVALUE; + config_reg->CONFIG_PIO1 = SCILIN_PIO1_CONFIGVALUE; + config_reg->CONFIG_PIO6 = SCILIN_PIO6_CONFIGVALUE; + config_reg->CONFIG_PIO7 = SCILIN_PIO7_CONFIGVALUE; + config_reg->CONFIG_PIO8 = SCILIN_PIO8_CONFIGVALUE; + } + else + { + /*SAFETYMCUSW 134 S MR:12.2 "LDRA Tool issue" */ + config_reg->CONFIG_GCR0 = scilinREG->GCR0; + config_reg->CONFIG_GCR1 = scilinREG->GCR1; + config_reg->CONFIG_SETINT = scilinREG->SETINT; + config_reg->CONFIG_SETINTLVL = scilinREG->SETINTLVL; + config_reg->CONFIG_FORMAT = scilinREG->FORMAT; + config_reg->CONFIG_BRS = scilinREG->BRS; + config_reg->CONFIG_PIO0 = scilinREG->PIO0; + config_reg->CONFIG_PIO1 = scilinREG->PIO1; + config_reg->CONFIG_PIO6 = scilinREG->PIO6; + config_reg->CONFIG_PIO7 = scilinREG->PIO7; + config_reg->CONFIG_PIO8 = scilinREG->PIO8; + } +} /* USER CODE BEGIN (37) */ Index: source/sys_main.c =================================================================== diff -u -r8ba82119080b77f804fa2b3edadd11422f57371b -r3323966fe741edbb36dffc78317ccf06ed93a68e --- source/sys_main.c (.../sys_main.c) (revision 8ba82119080b77f804fa2b3edadd11422f57371b) +++ source/sys_main.c (.../sys_main.c) (revision 3323966fe741edbb36dffc78317ccf06ed93a68e) @@ -47,6 +47,8 @@ /* Include Files */ +#include +#include #include "sys_common.h" /* USER CODE BEGIN (1) */ @@ -57,8 +59,6 @@ #include "rti.h" #include "Common.h" -#include "AlarmLamp.h" -#include "Buttons.h" #include "CommBuffers.h" #include "CPLD.h" #include "MsgQueues.h" Index: source/system.c =================================================================== diff -u -r765d2c35118e202444e737c66c77faf9678cc87e -r3323966fe741edbb36dffc78317ccf06ed93a68e --- source/system.c (.../system.c) (revision 765d2c35118e202444e737c66c77faf9678cc87e) +++ source/system.c (.../system.c) (revision 3323966fe741edbb36dffc78317ccf06ed93a68e) @@ -104,7 +104,7 @@ | (uint32)((uint32)0x1FU << 24U) | (uint32)0x00000000U | (uint32)((uint32)(6U - 1U)<< 16U) - | (uint32)(0xA400U); + | (uint32)(0x9A00U); /** - Setup pll control register 2 * - Setup spreading rate