#ifndef TIMER_H
#define TIMER_H

#include "config.h"

/* Setup a 16-bit timer to overflow at the specified frequency
     timer = 1-9
     freq = Hz, or 0 to disable the timer.
     ie = 1 to enable interrupt, 0 to disable
*/
int timer_setup_16bit(int timer, uint32_t freq, int ie);

#define TISR_HANDLER(x) \
	__attribute__((__interrupt__,auto_psv)) _T##x##Interrupt(void)

/* Clear TxIF corresponding to a timer */
#define timer_clear_txif(timer) do { \
 if ((timer) == 1) IFS0bits.T1IF = 0; \
 if ((timer) == 2) IFS0bits.T2IF = 0; \
 if ((timer) == 3) IFS0bits.T3IF = 0; \
 if ((timer) == 4) IFS1bits.T4IF = 0; \
 if ((timer) == 5) IFS1bits.T5IF = 0; \
 if ((timer) == 6) IFS2bits.T6IF = 0; \
 if ((timer) == 7) IFS3bits.T7IF = 0; \
 if ((timer) == 8) IFS3bits.T8IF = 0; \
 if ((timer) == 9) IFS3bits.T9IF = 0; \
} while(0)



#endif
