nrf51_timer.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * nRF51 System-on-Chip Timer peripheral
  3. *
  4. * QEMU interface:
  5. * + sysbus MMIO regions 0: GPIO registers
  6. * + sysbus irq
  7. *
  8. * Copyright 2018 Steffen Görtz <contrib@steffen-goertz.de>
  9. *
  10. * This code is licensed under the GPL version 2 or later. See
  11. * the COPYING file in the top-level directory.
  12. */
  13. #ifndef NRF51_TIMER_H
  14. #define NRF51_TIMER_H
  15. #include "hw/sysbus.h"
  16. #include "qemu/timer.h"
  17. #include "qom/object.h"
  18. #define TYPE_NRF51_TIMER "nrf51_soc.timer"
  19. OBJECT_DECLARE_SIMPLE_TYPE(NRF51TimerState, NRF51_TIMER)
  20. #define NRF51_TIMER_REG_COUNT 4
  21. #define NRF51_TIMER_TASK_START 0x000
  22. #define NRF51_TIMER_TASK_STOP 0x004
  23. #define NRF51_TIMER_TASK_COUNT 0x008
  24. #define NRF51_TIMER_TASK_CLEAR 0x00C
  25. #define NRF51_TIMER_TASK_SHUTDOWN 0x010
  26. #define NRF51_TIMER_TASK_CAPTURE_0 0x040
  27. #define NRF51_TIMER_TASK_CAPTURE_3 0x04C
  28. #define NRF51_TIMER_EVENT_COMPARE_0 0x140
  29. #define NRF51_TIMER_EVENT_COMPARE_1 0x144
  30. #define NRF51_TIMER_EVENT_COMPARE_2 0x148
  31. #define NRF51_TIMER_EVENT_COMPARE_3 0x14C
  32. #define NRF51_TIMER_REG_SHORTS 0x200
  33. #define NRF51_TIMER_REG_SHORTS_MASK 0xf0f
  34. #define NRF51_TIMER_REG_INTENSET 0x304
  35. #define NRF51_TIMER_REG_INTENCLR 0x308
  36. #define NRF51_TIMER_REG_INTEN_MASK 0xf0000
  37. #define NRF51_TIMER_REG_MODE 0x504
  38. #define NRF51_TIMER_REG_MODE_MASK 0x01
  39. #define NRF51_TIMER_TIMER 0
  40. #define NRF51_TIMER_COUNTER 1
  41. #define NRF51_TIMER_REG_BITMODE 0x508
  42. #define NRF51_TIMER_REG_BITMODE_MASK 0x03
  43. #define NRF51_TIMER_WIDTH_16 0
  44. #define NRF51_TIMER_WIDTH_8 1
  45. #define NRF51_TIMER_WIDTH_24 2
  46. #define NRF51_TIMER_WIDTH_32 3
  47. #define NRF51_TIMER_REG_PRESCALER 0x510
  48. #define NRF51_TIMER_REG_PRESCALER_MASK 0x0F
  49. #define NRF51_TIMER_REG_CC0 0x540
  50. #define NRF51_TIMER_REG_CC3 0x54C
  51. struct NRF51TimerState {
  52. SysBusDevice parent_obj;
  53. MemoryRegion iomem;
  54. qemu_irq irq;
  55. uint8_t id;
  56. QEMUTimer timer;
  57. int64_t timer_start_ns;
  58. int64_t update_counter_ns;
  59. uint32_t counter;
  60. bool running;
  61. uint8_t events_compare[NRF51_TIMER_REG_COUNT];
  62. uint32_t cc[NRF51_TIMER_REG_COUNT];
  63. uint32_t shorts;
  64. uint32_t inten;
  65. uint32_t mode;
  66. uint32_t bitmode;
  67. uint32_t prescaler;
  68. };
  69. #endif