
/** @file timer_interra.c
*
* @brief A Timer used to generate the delay functionality, will later try to execute events.
*
* @par
* NOTICE: Property of in-Terra Limited www.in-terra.ch .
*/


#include "timer_interra.h"

APP_TIMER_DEF(m_led_0_timer_id);

uint8_t timer_exp_flag=0;

void timer_0_handler(void * p_context)
{ 
    timer_exp_flag=1; 
    
       
}


/*!
 * @brief Delay using the app timer
 *
 * @param[in] None
 *
 * @return    None
 */

uint8_t delay()
{

    if (timer_exp_flag == 1)
        {
            timer_exp_flag = 0;

            return 1;
        }
    else
        {   
            return 0;
        }
}


/*!
 * @brief Delay using the app timer
 *
 * @param[in] None
 *
 * @return    None
 */

uint8_t timer_ms(uint32_t time_miliseconds)
{

uint32_t err_code;
 
    err_code = app_timer_create(&m_led_0_timer_id,
                                APP_TIMER_MODE_SINGLE_SHOT,
                                timer_0_handler);
    APP_ERROR_CHECK(err_code);

    // Start timers
    err_code =app_timer_start(m_led_0_timer_id, APP_TIMER_TICKS(time_miliseconds), NULL);
    APP_ERROR_CHECK(err_code);
    
  while(delay()!=1);

 // while(timer_exp_flag!=1);
}




/*!
 * @brief Initilaize the Timer
 *
 * @param[in] None
 *
 * @return    None
 */

void
timer_init (void)
{
    
ret_code_t err_code;
err_code=app_timer_init();

 SEGGER_RTT_printf(0,"Error Code is %ld\r\n", err_code);      
   
}

/*!
 * @brief start the Timer
 *
 * @param[in] milsecond to expire
 *
 * @return    None
 */

void
timer_start(uint32_t ms_time)
{
    

        
   
}