void CFE_PSP_Panic(int32 ErrorCode)
{

   OS_printf("\nWarning: CFE PSP Panic with error code %d!  A restart will occur!\n\n", ErrorCode);

   /*
   ** Delay for second or two, allow the print statement to send
   */

   taskDelay(100);

   /*
   ** Debug Switch is not set, do a processor Reset
   */
   CFE_PSP_Restart(CFE_ES_PROCESSOR_RESET);
}
/*
** Name: CFE_ES_SetupResetVariables
**
** Purpose: This function initializes the ES reset variables depending on the reset type.
**          It will also initiate a power on reset when too many processor resets
**           have happened.
**
*/
void CFE_ES_SetupResetVariables(uint32 StartType, uint32 StartSubtype, uint32 BootSource )
{

   int32  status;
   uint32 resetAreaSize;
   
   /*
   ** Get the pointer to the Reset area from the BSP
   */
   status = CFE_PSP_GetResetArea (&(CFE_ES_ResetDataPtr), &(resetAreaSize));
      
   /*
   ** Make sure the status is OK or size is big enough
   */
   if ( status == OS_ERROR )
   {
      /*
      ** Cannot use the ES System log without the Reset Area
      */
      OS_printf("ES Startup: CFE_PSP_GetResetArea call Failed!\n");
      
      /*
      ** Delay to allow the message to be read
      */
      OS_TaskDelay(CFE_ES_PANIC_DELAY);
      
      /* 
      ** cFE Cannot continue to start up. 
      */
      CFE_PSP_Panic(CFE_PSP_PANIC_MEMORY_ALLOC);
      
   }
   else if ( resetAreaSize < sizeof(CFE_ES_ResetData_t))
   {
      /*
      ** Cannot use the ES system log without the Reset Area
      */
      OS_printf("ES Startup: Error: ES Reset area not big enough. Needed: %d, Given: %d.\n",
              sizeof(CFE_ES_ResetData_t),
              resetAreaSize);      
      /*
      ** Delay to allow the message to be read
      */
      OS_TaskDelay(CFE_ES_PANIC_DELAY);
      
      /* 
      ** cFE Cannot continue to start up. 
      */
      CFE_PSP_Panic(CFE_PSP_PANIC_MEMORY_ALLOC);
      
   }

   /*
   ** Determine how the system was started. The choices are:
   **   CFE_ES_POWER_ON_RESET, or CFE_ES_PROCESSOR_RESET
   ** The subtypes include:
   **   CFE_ES_POWER_CYCLE, CFE_ES_PUSH_BUTTON, CFE_ES_HW_SPECIAL_COMMAND,
   **   CFE_ES_HW_WATCHDOG, CFE_ES_RESET_COMMAND, or CFE_ES_EXCEPTION.
   */
   if ( StartType == CFE_ES_POWERON_RESET )
   {
      /*
      ** Record the reset type and subtype
      */
      CFE_ES_ResetDataPtr->ResetVars.ResetSubtype = StartSubtype;
      CFE_ES_ResetDataPtr->ResetVars.ResetType = CFE_ES_POWERON_RESET;

      /*
      ** Always log the power-on reset. 
      */
      status =  CFE_ES_WriteToERLog(CFE_ES_CORE_LOG_ENTRY, CFE_ES_POWERON_RESET, StartSubtype,
                                    "ES Startup: POWER ON Reset", NULL,0 );

      /*
      ** Initialize all reset counters.
      */
      CFE_ES_ResetDataPtr->ResetVars.ProcessorResetCount = 0;
      CFE_ES_ResetDataPtr->ResetVars.MaxProcessorResetCount = CFE_ES_MAX_PROCESSOR_RESETS;
      CFE_ES_Global.DebugVars.DebugFlag = 0;
      
   }
   else if ( StartType == CFE_ES_PROCESSOR_RESET )
   {
      /*
      ** If a Processor reset was not commanded, it must be a watchdog reset.
      ** Log the reset before updating any reset variables.
      */
      if ( CFE_ES_ResetDataPtr->ResetVars.ES_CausedReset != TRUE )
      {

         CFE_ES_ResetDataPtr->ResetVars.ResetType = CFE_ES_PROCESSOR_RESET;
         CFE_ES_ResetDataPtr->ResetVars.ResetSubtype = CFE_ES_HW_WATCHDOG;
         
         /*
         ** Log the watchdog reset 
         */
         status =  CFE_ES_WriteToERLog(CFE_ES_CORE_LOG_ENTRY, CFE_ES_PROCESSOR_RESET, StartSubtype,
                                       "ES Startup: PROCESSOR RESET due to Watchdog.", NULL,0 );

         /*
         ** When coming up from a Processor reset that was not caused by ES, check to see 
         ** if the maximum number has been exceeded
         */
         if ( CFE_ES_ResetDataPtr->ResetVars.ProcessorResetCount >= 
              CFE_ES_ResetDataPtr->ResetVars.MaxProcessorResetCount )
         {
         
             CFE_ES_WriteToSysLog("ES Startup: CFE ES Power On Reset Due to Max Processor Resets.\n");

             /*
             ** Log the reset in the ER Log. The log will be wiped out, but it's good to have
             ** the entry just in case something fails.
             */
             status =  CFE_ES_WriteToERLog(CFE_ES_CORE_LOG_ENTRY, CFE_ES_POWERON_RESET, StartSubtype,
                                       "ES Startup: POWER ON RESET due to Maximum Processor Resets in ES Startup.", NULL,0 );
        
             /*
             ** Call the BSP reset routine 
             */
             CFE_PSP_Restart(CFE_ES_POWERON_RESET);
             
             /*
             ** Should not return here.
             */
             CFE_ES_WriteToSysLog("ES Startup: Error: CFE_PSP_Restart returned.\n");
           
         }
         else
         {
            /* 
            ** Increment the Processor Reset Count after the check to see
            ** if there are too many processor resets. This keeps the logic consistent with
            ** the resets that are caused by the cFE ( command or exception )
            */
            CFE_ES_ResetDataPtr->ResetVars.ProcessorResetCount++;
  
         } /* end if */
         
      }
      /*
      ** If a processor reset was commanded, the reset has already been logged.
      ** Update the reset variables only.
      ** The logic for detecting maximum resets is done on the command side
      ** on the "way down", or when the command is executed.
      */
      else
      {
         CFE_ES_ResetDataPtr->ResetVars.ResetType    = CFE_ES_PROCESSOR_RESET;
         CFE_ES_ResetDataPtr->ResetVars.ResetSubtype = StartSubtype;
      }

      /*
      ** Initialize processor reset counters.
      */
      CFE_ES_Global.DebugVars.DebugFlag = 0;
   }
   
   /*
   ** Clear the commanded reset flag, in case a watchdog happens.
   */
   CFE_ES_ResetDataPtr->ResetVars.ES_CausedReset = FALSE;
   CFE_ES_ResetDataPtr->ResetVars.BootSource   = BootSource;
      
}