#include "systick.h"


__IO uint32_t msTicks = 0; 

void SysTick_Handler(void)
{
msTicks++;
}

//delay function using systick
void delay_ms(uint32_t end)
{
	uint64_t star = msTicks+end; 
while((int64_t)(msTicks-star)<=0);

}

uint32_t get_tick(void)
{
	return msTicks;
}

//inicialize systick interupt with timing 1ms
void SysTick_init(void)
{	
	SysTick->CTRL |= (0X01U<<2)|(0X01U)|(0X01U<<1);
	SysTick->VAL	=0;
	SysTick->LOAD =  (SystemCoreClock/1000)-1;
	NVIC_SetPriorityGrouping(0x03U);
	NVIC_SetPriority(SysTick_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0,0));
	NVIC_EnableIRQ(SysTick_IRQn);
}
