/* Sets the system to sleep into the lowest possible energy mode. 
This function takes care of the system states protected by the sleep block provided by  */
SLEEP_EnergyMode_t SLEEP_Sleep(void)
/* Sets the system to sleep into the lowest possible energy mode. 
This function takes care of the system states protected by the sleep block provided by  */
SLEEP_EnergyMode_t SLEEP_Sleep(void)
{
  CORE_DECLARE_IRQ_STATE;
  SLEEP_EnergyMode_t allowedEM;
  CORE_ENTER_CRITICAL();
  allowedEM = SLEEP_LowestEnergyModeGet();
  if ((allowedEM >= sleepEM1) && (allowedEM <= sleepEM3))
  {
    enterEMx(allowedEM);
  }
  else
  {
    allowedEM = sleepEM0;
  }
  CORE_EXIT_CRITICAL();
  return allowedEM;
}