diff options
Diffstat (limited to 'src/occ/dcom/dcom_thread.c')
-rwxr-xr-x | src/occ/dcom/dcom_thread.c | 223 |
1 files changed, 223 insertions, 0 deletions
diff --git a/src/occ/dcom/dcom_thread.c b/src/occ/dcom/dcom_thread.c new file mode 100755 index 0000000..fe62a1f --- /dev/null +++ b/src/occ/dcom/dcom_thread.c @@ -0,0 +1,223 @@ +/****************************************************************************** +// @file dcom_thread.c +// @brief OCC to OCC communication handler thread +*/ +/****************************************************************************** + * + * @page ChangeLogs Change Logs + * @section dcom_thread.c DCOM_THREAD.C + * @verbatim + * + * Flag Def/Fea Userid Date Description + * ------- ---------- -------- ---------- ---------------------------------- + * @th022 thallet 07/11/2012 Pstate Enablement + * @th025 857856 thallet 10/16/2012 Dcom Master/Slave SMS part 2 + * @th032 thallet 04/16/2013 Tuleta HW Bringup + * @th035 881654 thallet 05/06/2013 Tuleta Bringup Pstate Fixes + * @at015 885884 alvinwan 06/10/2013 Support Observation/Active state change + * @th042 892056 thallet 07/19/2013 Send OCC to safe mode if first APSS GPE fails + * @gm025 915973 milesg 02/14/2014 Full support for sapphire (KVM) mode + * + * @endverbatim + * + *///*************************************************************************/ + +#ifndef _DCOM_THREAD_C +#define _DCOM_THREAD_C + +/** \defgroup OCC-OCC Communication + * + */ + +//************************************************************************* +// Includes +//************************************************************************* +#include <pgp_pmc.h> +#include "pgp_pba.h" +#include <rtls.h> +#include <apss.h> +#include <dcom.h> +#include <dcom_service_codes.h> +#include <occ_service_codes.h> +#include <trac.h> +#include <state.h> +#include <proc_pstate.h> + +//************************************************************************* +// Externs +//************************************************************************* + +//************************************************************************* +// Macros +//************************************************************************* + +//************************************************************************* +// Defines/Enums +//************************************************************************* + +//************************************************************************* +// Structures +//************************************************************************* + +//************************************************************************* +// Globals +//************************************************************************* + +// Debug Counter to make sure dcom thread is running +uint16_t G_dcom_thread_counter = 0; + +SsxSemaphore G_dcomThreadWakeupSem; // @th025 + +//************************************************************************* +// Function Prototypes +//************************************************************************* + +//************************************************************************* +// Functions +//************************************************************************* + + +// Function Specification +// +// Name: Dcom_thread_routine +// +// Description: Purpose of this task is to handle messages passed from +// Master to Slave and vice versa. +// +// Nothing in this thread should be time-critical, but should +// happen more often than the 1-second that other threads run +// at. +// +// This thread currently runs ~1ms, based on the RTL loop of +// 250us. +// +// FWIW -- It is pointless to set this thread to run any more +// often than the length of the RTL loop, since it is acting +// on data passed back and forth via that loop. +// +// Flow: XX-XX-XX FN= +// +// End Function Specification +void Dcom_thread_routine(void *arg) +{ + OCC_STATE l_newOccState = 0; + OCC_MODE l_newOccMode = 0; + SsxTimer l_timeout_timer; + errlHndl_t l_errlHndl = NULL; // @at015a + // -------------------------------------------------- + // Create a timer that pops every 10 seconds to wake up + // this thread, in case a semaphore never gets posted. + // TODO: Is this really needed? @th035 + // -------------------------------------------------- + ssx_timer_create(&l_timeout_timer, + (SsxTimerCallback) ssx_semaphore_post, + (void *) &G_dcomThreadWakeupSem); + ssx_timer_schedule(&l_timeout_timer, + SSX_SECONDS(10), + SSX_SECONDS(10)); + + for(;;) + { + // -------------------------------------------------- + // Wait on Semaphore until we get new data over DCOM + // (signalled by sem_post() or timeout occurs. + // Sem timeout is designed to be the slowest + // interval we will attempt to run this thread at. + // -------------------------------------------------- + + // Wait for sem_post before we run through this thread. + ssx_semaphore_pend(&G_dcomThreadWakeupSem, SSX_WAIT_FOREVER); // @th035 + + // -------------------------------------------------- + // Counter to ensure thread is running (can wrap) + // -------------------------------------------------- + G_dcom_thread_counter++; + + // -------------------------------------------------- + // Check if we need to update the sapphire table + // -------------------------------------------------- + if(G_sysConfigData.system_type.kvm) //gm025 + { + proc_check_for_sapphire_updates(); + } + + // -------------------------------------------------- + // Set Mode and State Based on Master + // -------------------------------------------------- + l_newOccState = (G_occ_master_state == CURRENT_STATE()) ? OCC_STATE_NOCHANGE : G_occ_master_state; + // @at019a + if(G_sysConfigData.system_type.kvm) + { + l_newOccMode = (G_occ_master_mode == G_occ_external_req_mode_kvm ) ? OCC_MODE_NOCHANGE : G_occ_master_mode; + } + else + { + l_newOccMode = (G_occ_master_mode == CURRENT_MODE() ) ? OCC_MODE_NOCHANGE : G_occ_master_mode; + } + + // Override State if SAFE state is requested -- @th042 + l_newOccState = ( isSafeStateRequested() ) ? OCC_STATE_SAFE : l_newOccState; + + // Override State if we are in SAFE state already -- @th042 + l_newOccState = ( OCC_STATE_SAFE == CURRENT_STATE() ) ? OCC_STATE_NOCHANGE : l_newOccState; + + if( (OCC_STATE_NOCHANGE != l_newOccState) + || (OCC_MODE_NOCHANGE != l_newOccMode) ) + { + // If we're active, then we should always process the mode change first + // If we're not active, then we should always process the state change first + // @at015c - start + if(OCC_STATE_ACTIVE == CURRENT_STATE()) + { + // Set the new mode + l_errlHndl = SMGR_set_mode(l_newOccMode, 0 /* TODO V/F */ ); + if(l_errlHndl) + { + commitErrl(&l_errlHndl); + } + // Set the new state + l_errlHndl = SMGR_set_state(l_newOccState); + if(l_errlHndl) + { + commitErrl(&l_errlHndl); + } + } + else + { + // Set the new state + l_errlHndl = SMGR_set_state(l_newOccState); + if(l_errlHndl) + { + commitErrl(&l_errlHndl); + } + // Set the new mode + l_errlHndl = SMGR_set_mode(l_newOccMode, 0 /* TODO V/F */ ); + if(l_errlHndl) + { + commitErrl(&l_errlHndl); + } + } + // @at015c - end + } + + // -------------------------------------------------- + // DCM PStates + // \_ can do sem_post to increment through state machine + // -------------------------------------------------- + if(OCC_STATE_SAFE != CURRENT_STATE()) // @th042 + { + proc_gpsm_dcm_sync_enable_pstates_smh(); + } + + // -------------------------------------------------- + // SSX Sleep + // -------------------------------------------------- + // Even if semaphores are continually posted, there is no reason + // for us to run this thread any more often than once every 250us + // so we don't starve any other thread + ssx_sleep(SSX_MICROSECONDS(250)); // @th025 + } +} + +#endif //_DCOM_THREAD_C + |