/**
* @file Timer.c
*/

#include <stdbool.h>
#include <stdint.h>
#include "Timer.h"

volatile uint16_t uiCOMMSERIALTimer = 0;
volatile uint16_t uiMOTORStepTimer = 0;
volatile uint16_t uiLogTimer = 0;
volatile uint16_t uiGPSTimer = 0;
volatile uint16_t uiMotorTimeout = 0;

/**
 *
 * @brief  HAL_SYSTICK_Callback()
 * 		   System Timer callback - 1ms interval
 *
 * @param  None
 * *
 * @retval None
*******************************************************************************/

void HAL_SYSTICK_Callback(void)
{
	// locals
	static uint8_t timerticks = 0;			// general timer for systick

	// 1ms
	timerticks++;
	/* Log Timer --------------------------------------------------------------------------*/
    if (uiLogTimer != 0)
    {
        uiLogTimer--;
    }

	/* Debug communication timeout timer to detect message errors -------------------------*/
	if (uiCOMMSERIALTimer != 0)
	{
	    uiCOMMSERIALTimer--;
	}

    /* Motor stepping of ARR check -------------------------------------------------------------*/
    if (uiMOTORStepTimer != 0)
    {
        uiMOTORStepTimer--;
    }

    /* Motor communication timeout -------------------------------------------------------------*/
    if (uiMotorTimeout != 0)
    {
        uiMotorTimeout--;
    }
    /* GPS Timer -------------------------------------------------------------*/
    if (uiGPSTimer != 0)
    {
        uiGPSTimer--;
    }
}
