/*
 * @file ft_timer.c
 *
 * @brief This file contains function definitions for file tranfer internal timer.
 *
 * @copyright Copyright 2023 Antaris, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *        usage of TC TM Library APIs
 */


/******************************************************************************/
/*                      Include headers of the component                      */
/******************************************************************************/


#include "ft_timer.h"




/******************************************************************************/
/*                       Definition of local variables                        */
/******************************************************************************/

static uint32_t 		ft_timer_inc;
static uint32_t 		ft_timer_set;
static uint8_t 			ft_timer_flag;
static uint8_t 			ft_timer_on;
static uint32_t 		ft_timer_set_value_save;


/******************************************************************************/
/*                      Definition of exported functions                      */
/******************************************************************************/


void ft_update_timer()
{
	if(ft_timer_inc < ft_timer_set)
	{
		ft_timer_inc++;
	}
	else
	{
		ft_timer_flag = ft_timer_on;
	}

}


void ft_reset_timer()
{
	ft_timer_inc = 0;
	ft_timer_flag = 0;
}

/*
 * set timer in seconds
 * uint16_t set in seconds
 */
void ft_set_timer(uint16_t set)
{
	ft_timer_inc = 0;
	ft_timer_flag = 0;
	ft_timer_on = 1;

	/* assumed timer tick is incremented every 1 ms time */
	ft_timer_set = set * FT_TICK_TIME_IN_SEC; // ms or sec???
	ft_timer_set_value_save = set;
}



uint8_t ft_get_flag()
{
	return ft_timer_flag;
}


void ft_stop_timer()
{
	ft_timer_on = 0;
}


void ft_init_timer()
{
//	ft_tim_info.timer_inc = 0;
//	ft_tim_info.sus_res_timer_on =0;
//	ft_tim_info.tx_rx_timer_on =0;
}


uint16_t ft_get_previous_timer(void)
{
	return ft_timer_set_value_save;
}

