Commit 2a3e33f7bb22492e16a7f75a7ed3b9657349f004

Authored by Evgeniy Dushistov
1 parent f5470d2b

PITC:

- PIT not stops immediately, to emulate hardware set CPIV to right value, when
user stop PIT

- zero PICNT part of register after read from PIVR register
Showing 1 changed file with 9 additions and 1 deletions
hw/at91_pit.c
... ... @@ -59,6 +59,7 @@ static void at91_pit_tick(void *opaque)
59 59 static uint32_t at91_pit_mem_read(void *opaque, target_phys_addr_t offset)
60 60 {
61 61 PITState *s = opaque;
  62 + uint32_t picnt = s->picnt;
62 63  
63 64 offset &= 0xf;
64 65 switch (offset) {
... ... @@ -68,12 +69,13 @@ static uint32_t at91_pit_mem_read(void *opaque, target_phys_addr_t offset)
68 69 return s->sr;
69 70 case PIT_PIVR:
70 71 s->sr = 0;
  72 + s->picnt = 0;
71 73 qemu_set_irq(s->irq, 0);
72 74 /* Fall-through */
73 75 case PIT_PIIR:
74 76 return
75 77 ((PIT_LIMIT(s) - ptimer_get_count(s->timer)) & 0xfffff) |
76   - (s->picnt << 20);
  78 + (picnt << 20);
77 79  
78 80 default:
79 81 return 0;
... ... @@ -94,6 +96,12 @@ static void at91_pit_mem_write(void *opaque, target_phys_addr_t offset,
94 96 ptimer_run(s->timer, 0);
95 97 } else {
96 98 ptimer_stop(s->timer);
  99 + /*
  100 + "After the PIT Enable bit is reset (PITEN= 0), the CPIV goes on counting until
  101 + the PIV value is reached, and is then reset"
  102 + Do not wait, set CPIV to right value now.
  103 + */
  104 + ptimer_set_count(s->timer, PIT_LIMIT(s));
97 105 }
98 106 }
99 107 }
... ...