Skip to content

Commit

Permalink
Clear the interrupt after setting BL808_UART_INT_CLEAR (0x30002028)
Browse files Browse the repository at this point in the history
  • Loading branch information
lupyuen committed Jan 20, 2024
1 parent 51965fc commit f9c1841
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
11 changes: 6 additions & 5 deletions riscv_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,11 +496,12 @@ int target_write_slow(RISCVCPUState *s, target_ulong addr,
print_console(NULL, buf, 1);
break;
}

// Console Input: Clear the interrupt after setting BL808_UART_INT_CLEAR (0x30002028)
// case 0x30002028:
// break;

case 0x30002028: {
void virtio_ack_irq(void *device0);
virtio_ack_irq(NULL);
break;
}
default: // Unknown Memory-Mapped I/O
#ifdef DUMP_INVALID_MEM_ACCESS
printf("target_write_slow: invalid physical address 0x");
Expand Down Expand Up @@ -1171,7 +1172,7 @@ static void raise_exception(RISCVCPUState *s, uint32_t cause)
{
printf("raise_exception: cause=%d\n", cause);////
#ifndef EMSCRIPTEN ////
printf("raise_exception: sleep\n"); sleep(4);////
// printf("raise_exception: sleep\n"); sleep(4);////
#endif //// EMSCRIPTEN
raise_exception2(s, cause, 0);
}
Expand Down
17 changes: 15 additions & 2 deletions virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ static void virtio_mmio_write(void *opaque, uint32_t offset,
static uint32_t virtio_pci_read(void *opaque, uint32_t offset, int size_log2);
static void virtio_pci_write(void *opaque, uint32_t offset,
uint32_t val, int size_log2);
void virtio_ack_irq(VIRTIODevice *device0);

static void virtio_reset(VIRTIODevice *s)
{
Expand Down Expand Up @@ -293,6 +294,7 @@ static void virtio_init(VIRTIODevice *s, VIRTIOBusDef *bus,
s->config_space_size = config_space_size;
s->device_recv = device_recv;
virtio_reset(s);
virtio_ack_irq(s); ////
}

static uint16_t virtio_read16(VIRTIODevice *s, virtio_phys_addr_t addr)
Expand Down Expand Up @@ -1337,8 +1339,6 @@ int virtio_console_write_data(VIRTIODevice *s, const uint8_t *buf, int buf_len)
s->int_status |= 1;
set_irq(s->irq, 1);

// TODO: Clear the interrupt after reading keypress
// set_irq(s->irq, 0);
#ifdef NOTUSED
int queue_idx = 0;
QueueState *qs = &s->queue[queue_idx];
Expand Down Expand Up @@ -2678,3 +2678,16 @@ VIRTIODevice *virtio_9p_init(VIRTIOBusDef *bus, FSDevice *fs,
return (VIRTIODevice *)s;
}

//// Begin Test: Acknowledge VirtIO Interrupt
void virtio_ack_irq(VIRTIODevice *device0) {
static VIRTIODevice *device = NULL;
if (device0 != NULL) { device = device0; return; }
if (device == NULL) { puts("virtio_ack_irq: Missing device"); }

puts("virtio_ack_irq");
// device->int_status &= ~val;
// if (device->int_status == 0) {
set_irq(device->irq, 0);
// }
}
//// End Test

0 comments on commit f9c1841

Please sign in to comment.