/*
 * timer-flash.c
 *
 *  Created on: Oct 17, 2018
 *      Author: corrado
 */

#include "stm32_unict_lib.h"
int main()
{
	// LED at PC3
	GPIO_init(GPIOC);
	GPIO_config_output(GPIOC, 3);

	// init the timer
	TIM_init(TIM2);

	// Configure the timebase
	// Counter clock set to 0.1 ms
	TIM_config_timebase(TIM2, 8400, 5000);

	TIM_set(TIM2, 0); // resets the counter
	TIM_on(TIM2); // starts the timer

	TIM_enable_irq(TIM2, IRQ_UPDATE);

	// infinite loop
	for (;;) {
	}
}

void TIM2_IRQHandler(void)
{
	// check the update event
	if (TIM_update_check(TIM2)) {
		GPIO_toggle(GPIOC, 3);
		// clear the update event
		TIM_update_clear(TIM2);
	}
}
