#ifndef AL_SWTIMER_H
#define AL_SWTIMER_H

#include <al_common.h>

#ifndef SWTIMER_RESOLUTION
#define SWTIMER_RESOLUTION		1000		//us
#endif

#if !defined(SWTIMER_0) && !defined(SWTIMER_1) && !defined(SWTIMER_2)
#error SWTIMER_0, SWTIMER_1 or SWTIMER_2 must be defined
#endif

#ifndef SWTIMER_COUNT
#error SWTIMER_COUNT is not defined
#endif

#ifndef SWTIMER_DIV
#ifdef SWTIMER_1
#define SWTIMER_DIV			1
#else
#if CLOCK_FREQ>=16000000
#define SWTIMER_DIV			256
#elif CLOCK_FREQ<=2000000
#define SWTIMER_DIV			8
#else
#define SWTIMER_DIV			64
#endif
#endif
#endif

void		swtimer_init(void);
uint16_t	swtimer_get(uint8_t id_);
void		swtimer_set(uint8_t id_,uint16_t value_);
uint8_t		swtimer_is_expired(uint8_t id_);
void		swtimer_delay(uint8_t id_,uint16_t value_);

#endif
