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,6 +59,7 @@ static void at91_pit_tick(void *opaque)
59 static uint32_t at91_pit_mem_read(void *opaque, target_phys_addr_t offset) 59 static uint32_t at91_pit_mem_read(void *opaque, target_phys_addr_t offset)
60 { 60 {
61 PITState *s = opaque; 61 PITState *s = opaque;
  62 + uint32_t picnt = s->picnt;
62 63
63 offset &= 0xf; 64 offset &= 0xf;
64 switch (offset) { 65 switch (offset) {
@@ -68,12 +69,13 @@ static uint32_t at91_pit_mem_read(void *opaque, target_phys_addr_t offset) @@ -68,12 +69,13 @@ static uint32_t at91_pit_mem_read(void *opaque, target_phys_addr_t offset)
68 return s->sr; 69 return s->sr;
69 case PIT_PIVR: 70 case PIT_PIVR:
70 s->sr = 0; 71 s->sr = 0;
  72 + s->picnt = 0;
71 qemu_set_irq(s->irq, 0); 73 qemu_set_irq(s->irq, 0);
72 /* Fall-through */ 74 /* Fall-through */
73 case PIT_PIIR: 75 case PIT_PIIR:
74 return 76 return
75 ((PIT_LIMIT(s) - ptimer_get_count(s->timer)) & 0xfffff) | 77 ((PIT_LIMIT(s) - ptimer_get_count(s->timer)) & 0xfffff) |
76 - (s->picnt << 20); 78 + (picnt << 20);
77 79
78 default: 80 default:
79 return 0; 81 return 0;
@@ -94,6 +96,12 @@ static void at91_pit_mem_write(void *opaque, target_phys_addr_t offset, @@ -94,6 +96,12 @@ static void at91_pit_mem_write(void *opaque, target_phys_addr_t offset,
94 ptimer_run(s->timer, 0); 96 ptimer_run(s->timer, 0);
95 } else { 97 } else {
96 ptimer_stop(s->timer); 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 }