Revision e2733d20 hw/cuda.c

b/hw/cuda.c
85 85
#define CUDA_COMBINED_FORMAT_IIC	0x25
86 86

  
87 87
#define CUDA_TIMER_FREQ (4700000 / 6)
88
#define CUDA_ADB_POLL_FREQ 50
88 89

  
89 90
typedef struct CUDATimer {
90 91
    unsigned int latch;
......
121 122
    uint8_t autopoll;
122 123
    uint8_t data_in[128];
123 124
    uint8_t data_out[16];
125
    QEMUTimer *adb_poll_timer;
124 126
} CUDAState;
125 127

  
126 128
static CUDAState cuda_state;
......
469 471
    cuda_send_packet_to_host(s, data, len + 1);
470 472
}
471 473

  
474
void cuda_adb_poll(void *opaque)
475
{
476
    CUDAState *s = opaque;
477
    uint8_t obuf[ADB_MAX_OUT_LEN + 2];
478
    int olen;
479

  
480
    olen = adb_poll(&adb_bus, obuf + 2);
481
    if (olen > 0) {
482
        obuf[0] = ADB_PACKET;
483
        obuf[1] = 0x40; /* polled data */
484
        cuda_send_packet_to_host(s, obuf, olen + 2);
485
    }
486
    qemu_mod_timer(s->adb_poll_timer, 
487
                   qemu_get_clock(vm_clock) + 
488
                   (ticks_per_sec / CUDA_ADB_POLL_FREQ));
489
}
490

  
472 491
static void cuda_receive_packet(CUDAState *s, 
473 492
                                const uint8_t *data, int len)
474 493
{
475 494
    uint8_t obuf[16];
476
    int ti;
495
    int ti, autopoll;
477 496

  
478 497
    switch(data[0]) {
479 498
    case CUDA_AUTOPOLL:
480
        s->autopoll = data[1];
499
        autopoll = (data[1] != 0);
500
        if (autopoll != s->autopoll) {
501
            s->autopoll = autopoll;
502
            if (autopoll) {
503
                qemu_mod_timer(s->adb_poll_timer, 
504
                               qemu_get_clock(vm_clock) + 
505
                               (ticks_per_sec / CUDA_ADB_POLL_FREQ));
506
            } else {
507
                qemu_del_timer(s->adb_poll_timer);
508
            }
509
        }
481 510
        obuf[0] = CUDA_PACKET;
482 511
        obuf[1] = data[1];
483 512
        cuda_send_packet_to_host(s, obuf, 2);
......
522 551
#endif
523 552
    switch(data[0]) {
524 553
    case ADB_PACKET:
525
        adb_receive_packet(&adb_bus, data + 1, len - 1);
554
        {
555
            uint8_t obuf[ADB_MAX_OUT_LEN + 2];
556
            int olen;
557
            olen = adb_request(&adb_bus, obuf + 2, data + 1, len - 1);
558
            if (olen != 0) {
559
                obuf[0] = ADB_PACKET;
560
                obuf[1] = 0x00;
561
            } else {
562
                /* empty reply */
563
                obuf[0] = ADB_PACKET;
564
                obuf[1] = 0x02;
565
            }
566
            cuda_send_packet_to_host(s, obuf, olen + 2);
567
        }
526 568
        break;
527 569
    case CUDA_PACKET:
528 570
        cuda_receive_packet(s, data + 1, len - 1);
......
574 616
    s->timers[1].latch = 0x10000;
575 617
    s->ier = T1_INT | SR_INT;
576 618
    set_counter(s, &s->timers[1], 0xffff);
619

  
620
    s->adb_poll_timer = qemu_new_timer(vm_clock, cuda_adb_poll, s);
577 621
    cuda_mem_index = cpu_register_io_memory(0, cuda_read, cuda_write, s);
578 622
    return cuda_mem_index;
579 623
}

Also available in: Unified diff