You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

47 lines
1.4 KiB

  1. #ifndef TIMER_H
  2. #define TIMER_H
  3. #include "config.h"
  4. /* Setup a 16-bit timer to overflow at the specified frequency
  5. timer = 1-9
  6. freq = Hz, or 0 to disable the timer.
  7. ie = 1 to enable interrupt, 0 to disable
  8. */
  9. int timer_setup_16bit(int timer, uint32_t freq, int ie);
  10. #define TISR_HANDLER(x) \
  11. __attribute__((__interrupt__,auto_psv)) _T##x##Interrupt(void)
  12. /* Clear TxIF corresponding to a timer */
  13. #define timer_clear_txif(timer) do { \
  14. if ((timer) == 1) IFS0bits.T1IF = 0; \
  15. if ((timer) == 2) IFS0bits.T2IF = 0; \
  16. if ((timer) == 3) IFS0bits.T3IF = 0; \
  17. if ((timer) == 4) IFS1bits.T4IF = 0; \
  18. if ((timer) == 5) IFS1bits.T5IF = 0; \
  19. if ((timer) == 6) IFS2bits.T6IF = 0; \
  20. if ((timer) == 7) IFS3bits.T7IF = 0; \
  21. if ((timer) == 8) IFS3bits.T8IF = 0; \
  22. if ((timer) == 9) IFS3bits.T9IF = 0; \
  23. } while(0)
  24. /* Set timer interrupt priority, 1-7. Default is 4, 7 is highest */
  25. #define timer_set_priority(timer, pri) do { \
  26. if ((timer) == 1) IPC0bits.T1IP = (pri); \
  27. if ((timer) == 2) IPC1bits.T2IP = (pri); \
  28. if ((timer) == 3) IPC2bits.T3IP = (pri); \
  29. if ((timer) == 4) IPC6bits.T4IP = (pri); \
  30. if ((timer) == 5) IPC7bits.T5IP = (pri); \
  31. if ((timer) == 6) IPC11bits.T6IP = (pri); \
  32. if ((timer) == 7) IPC12bits.T7IP = (pri); \
  33. if ((timer) == 8) IPC12bits.T8IP = (pri); \
  34. if ((timer) == 9) IPC13bits.T9IP = (pri); \
  35. } while(0)
  36. /* sleep for between "ms" and "ms+1" milliseconds */
  37. void msleep(int ms);
  38. #endif