Commit 254a2710da152ed1ef9a9579e63a5c9258b9eb1c

Authored by Grzegorz Jabłoński
1 parent dc1560f5

Fixed set_gpio

Showing 2 changed files with 31 additions and 8 deletions
hw/at91_pio.c
... ... @@ -88,6 +88,7 @@ typedef struct PIOState {
88 88  
89 89 void at91_pio_set_pin(void *opaque, int pin, int level)
90 90 {
  91 + printf("In at91_pio_set_pin, opaque=%p, pin=%d, level=%d\n", opaque, pin, level);
91 92 PIOState *s = opaque;
92 93 int mask = 1 << (pin % PIO_PINS);
93 94 int input_set = pin / PIO_PINS;
... ... @@ -97,6 +98,8 @@ void at91_pio_set_pin(void *opaque, int pin, int level)
97 98 if (input_set == 0) {
98 99 /* PIO pin -> Peripheral / IO */
99 100  
  101 + printf("In at91_pio_set_pin, s->osr=%08x, s->psr=%08x, mask=%08x\n",s->osr, s->psr, mask);
  102 +
100 103 /* Skip input if output mode is enabled for the pin */
101 104 if (s->osr & mask)
102 105 return;
... ... @@ -104,9 +107,11 @@ void at91_pio_set_pin(void *opaque, int pin, int level)
104 107 if (s->psr & mask) {
105 108 saved_pdsr = s->pdsr;
106 109 s->pdsr &= ~mask;
  110 + s->unknown_state &= ~mask;
107 111 if (level == -1) {
108 112 s->unknown_state |= mask;
109 113 } else if (level) {
  114 + printf("In at91_pio_set_pin, setting level\n");
110 115 s->unknown_state &= ~mask;
111 116 s->pdsr |= mask;
112 117 }
... ... @@ -117,6 +122,8 @@ void at91_pio_set_pin(void *opaque, int pin, int level)
117 122 } else {
118 123 qemu_set_irq(s->out[PIO_PINS + (output_set * PIO_PINS)], level);
119 124 }
  125 + printf("In at91_pio_set_pin, s->pdsr=%08x\n",s->pdsr);
  126 +
120 127 } else {
121 128 /* Peripheral -> PIO pin */
122 129 if ((~s->psr & mask) && input_set == output_set) {
... ... @@ -141,6 +148,10 @@ static uint32_t at91_pio_mem_read(void *opaque, target_phys_addr_t offset)
141 148 case PIO_ODSR:
142 149 return s->odsr;
143 150 case PIO_PDSR:
  151 + printf("In at91_pio_mem_read, reading PDSR, s->pdsr=%08x, s->unknown_state=%08x, retval=%08x\n",
  152 + s->pdsr, s->unknown_state,
  153 + (s->pdsr & ~s->unknown_state) |
  154 + (s->ppusr & s->unknown_state));
144 155 return
145 156 (s->pdsr & ~s->unknown_state) |
146 157 (s->ppusr & s->unknown_state);
... ... @@ -322,12 +333,14 @@ static void at91_pio_reset(void *opaque)
322 333 s->unknown_state = 0xffffffff;
323 334 }
324 335  
325   -void* at91_io_state = NULL;
  336 +void* at91_io_state[5];
  337 +int at91_io_cnt = 0;
326 338  
327 339 static void at91_pio_init(SysBusDevice *dev)
328 340 {
  341 + printf("at91_pio_init called\n");
329 342 PIOState *s = FROM_SYSBUS(typeof (*s), dev);
330   - at91_io_state = s;
  343 + at91_io_state[at91_io_cnt++] = s;
331 344 int pio_regs;
332 345  
333 346 sysbus_init_irq(dev, &s->parent_irq);
... ...
monitor.c
... ... @@ -521,16 +521,26 @@ static void do_screen_dump(Monitor *mon, const char *filename)
521 521  
522 522 static void do_set_gpio(Monitor* mon, const char* port, const char* value)
523 523 {
524   - extern void* at91_io_state;
  524 + extern void* at91_io_state[5];
525 525 extern void at91_pio_set_pin(void *opaque, int pin, int level);
526   - if (at91_io_state)
  526 + if (strlen(port)<1)
527 527 {
528   - printf("Setting gpio: %s %s\n", port, value);
529   - at91_pio_set_pin(at91_io_state, atoi(port), atoi(value));
  528 + printf("Invalid port\n");
  529 + return;
  530 + }
  531 + int channel = port[0]-'A';
  532 + if ((channel >= 0) && (channel < 5))
  533 + {
  534 + if (at91_io_state[channel])
  535 + {
  536 + printf("Setting gpio: %s %s\n", port, value);
  537 + at91_pio_set_pin(at91_io_state[channel], atoi(port+1), atoi(value));
  538 + }
  539 + else
  540 + printf("Cannot set pin: device pointer is NULL\n");
530 541 }
531 542 else
532   - printf("Cannot set pin: device pointer is NULL\n");
533   -
  543 + printf("Invalid channel\n");
534 544 }
535 545  
536 546 static void do_logfile(Monitor *mon, const char *filename)
... ...