timer.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (C) 2011 by Vladimir Zapolskiy <vz@mleia.com>
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  17. * MA 02110-1301, USA.
  18. */
  19. #ifndef _LPC32XX_TIMER_H
  20. #define _LPC32XX_TIMER_H
  21. #include <asm/types.h>
  22. /* Timer/Counter Registers */
  23. struct timer_regs {
  24. u32 ir; /* Interrupt Register */
  25. u32 tcr; /* Timer Control Register */
  26. u32 tc; /* Timer Counter */
  27. u32 pr; /* Prescale Register */
  28. u32 pc; /* Prescale Counter */
  29. u32 mcr; /* Match Control Register */
  30. u32 mr[4]; /* Match Registers */
  31. u32 ccr; /* Capture Control Register */
  32. u32 cr[4]; /* Capture Registers */
  33. u32 emr; /* External Match Register */
  34. u32 reserved[12];
  35. u32 ctcr; /* Count Control Register */
  36. };
  37. /* Timer/Counter Interrupt Register bits */
  38. #define TIMER_IR_CR(n) (1 << ((n) + 4))
  39. #define TIMER_IR_MR(n) (1 << (n))
  40. /* Timer/Counter Timer Control Register bits */
  41. #define TIMER_TCR_COUNTER_RESET (1 << 1)
  42. #define TIMER_TCR_COUNTER_ENABLE (1 << 0)
  43. #define TIMER_TCR_COUNTER_DISABLE (0 << 0)
  44. /* Timer/Counter Match Control Register bits */
  45. #define TIMER_MCR_STOP(n) (1 << (3 * (n) + 2))
  46. #define TIMER_MCR_RESET(n) (1 << (3 * (n) + 1))
  47. #define TIMER_MCR_INTERRUPT(n) (1 << (3 * (n)))
  48. /* Timer/Counter Capture Control Register bits */
  49. #define TIMER_CCR_INTERRUPT(n) (1 << (3 * (n) + 2))
  50. #define TIMER_CCR_FALLING_EDGE(n) (1 << (3 * (n) + 1))
  51. #define TIMER_CCR_RISING_EDGE(n) (1 << (3 * (n)))
  52. /* Timer/Counter External Match Register bits */
  53. #define TIMER_EMR_EMC_TOGGLE(n) (0x3 << (2 * (n) + 4))
  54. #define TIMER_EMR_EMC_SET(n) (0x2 << (2 * (n) + 4))
  55. #define TIMER_EMR_EMC_CLEAR(n) (0x1 << (2 * (n) + 4))
  56. #define TIMER_EMR_EMC_NOTHING(n) (0x0 << (2 * (n) + 4))
  57. #define TIMER_EMR_EM(n) (1 << (n))
  58. /* Timer/Counter Count Control Register bits */
  59. #define TIMER_CTCR_INPUT(n) ((n) << 2)
  60. #define TIMER_CTCR_MODE_COUNTER_BOTH (0x3 << 0)
  61. #define TIMER_CTCR_MODE_COUNTER_FALLING (0x2 << 0)
  62. #define TIMER_CTCR_MODE_COUNTER_RISING (0x1 << 0)
  63. #define TIMER_CTCR_MODE_TIMER (0x0 << 0)
  64. #endif /* _LPC32XX_TIMER_H */