#ifndef _SYSTICK_H_
#define _SYSTICK_H_
//----------------------------------------------------------------------------
///
/// \brief  Systick
///
///         See implementation files for further information.
//
/// \date   20150122
/// \author Maximilian Seesslen <mes@seesslen.net>
///
//----------------------------------------------------------------------------


//---Includes-----------------------------------------------------------------


//---Own------------------------------

extern "C"
{
   //#include <stm/stm32_hal.h>    // GPIO
}

#include <biwak/biwak.h>
#include <lepto/lepto.h>         // IS_ENABLED


//---System---------------------------

#include <sys/types.h>                  // useconds_t


//---Defines------------------------------------------------------------------


#define _1MHZ      (1000*1000)
#define _1KHZ      (1000)
#define HZ_TO_MHZ       (1000*1000)
#define SECS_PER_MIN   ( 60l )
#define SECS_PER_HOUR  ( 60l * SECS_PER_MIN )
#define MSECS_PER_SEC   ( 1000l )
#define MSECS_PER_MIN   ( 1000l * 60l )
#define MSECS_PER_HOUR  ( 1000l * 60l * 60l )
#define USECS_PER_MSEC  ( 1000l )
#define USECS_PER_SEC   ( 1000l * 1000l )
#define USECS_PER_MIN   ( 1000l * 1000l * 60l )
#define USECS_PER_HOUR  ( 1000l * 1000l * 60l *60l )
#define HOUR_PER_DAY    ( 24l )

#define sec2min(sec) ( ( sec ) / SECS_PER_MIN )
#define min2sec(min) ( ( min ) * SECS_PER_MIN )

//---Declaration--------------------------------------------------------------


extern "C"
{
   int usleep(useconds_t usecDelayValue);
   #if IS_ENABLED( CONFIG_BIWAK_DATA_EVENT )
      int usleepNoData(useconds_t usecDelayValue);
   #endif
}

int usleep_deep(useconds_t usecDelayValue);
void standby();
void stop();
void deepSleep();
void initSystick();
void systickKeeper( );
uint32_t getSystick();
hrtimer_t hrNow();

// High-Resolution/-0Speed
hrtimer_t getHrTimerValue();
int32_t hrtValueToUsec(hrtimer_t hrtValue);
int32_t hrtValueToMsec(hrtimer_t hrtValue);
hrtimer_t msecToHrtValue(int mseconds);
hrtimer_t usecToHrtValue(int useconds);

lrtimer_t getLrTimerValue();
int32_t lrtValueToMsec(lrtimer_t lrtValue);
int32_t lrtValueToSec(lrtimer_t lrtValue);
lrtimer_t secToLrt(int32_t sec);
lrtimer_t msecToLrt(int32_t msec);
void clearWakeup();
int getSystickCounter();


//---fin----------------------------------------------------------------------
#endif // ? ! _SYSTICK_H_
