//----------------------------------------------------------------------------
///
///
///
//----------------------------------------------------------------------------


#include <fosh/command.h>
#include <stdio.h>
#include <time.h>       // time.h, localtime, strftime
#include <string.h>     // strncpy
#include <sys/time.h>   // settimeofday
#include <stdlib.h>      // atoi

#ifdef STM32
#include <HALWrapper/stm32_hal.h>    // HAL_IncTick(), PWR_LOWPOWERREGULATOR_ON
//#include <stm/stm32f0xx_ll_pwr.h>
#include <HALWrapper/stm32_pwr.h>
#endif

#ifdef STM32
   //#include <arena/platform.h>
   #include <biwak/rtc.hpp>
#endif

class CCommandStop: public CCommand
{
   private:
      //CRtc &m_rtc;
   CPlatform &pf;

   public:
      CCommandStop(const char *_name, CPlatform &platform)
         :CCommand( _name, "Stop: get/set time and Stop" )
         //,m_rtc(rtc)
         ,pf(platform)
      {}
      virtual int exec(int argc, const char *argv[]) const;
};


int CCommandStop::exec(int argc, const char *argv[]) const /* virtual */
{
   #ifdef STM32
      #pragma GCC diagnostic push
      #pragma GCC diagnostic ignored "-Wvolatile"

      __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
      __HAL_DBGMCU_FREEZE_IWDG();
      HAL_PWR_EnterSTANDBYMode();
      __WFE();
      __WFE();
      __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);

      #pragma GCC diagnostic pop
   #else
      printf("Host can not stop.\n");
   #endif

   return( 0 );
}


const CCommand *createInstance_stop(CPlatform *platform)
{
   return( new CCommandStop("stop", *platform) );
}

#if 0
STTERM_COMMAND(Stop);
#endif


//---fin----------------------------------------------------------------------
