diff --git a/gecko.c b/gecko.c index a0a0918..5f90227 100644 --- a/gecko.c +++ b/gecko.c @@ -24,6 +24,7 @@ Copyright (C) 2009 Andre Heider "dhewg" #include "powerpc_elf.h" #include "gecko.h" +static u8 gecko_found = 0; static u8 gecko_console_enabled = 0; static u32 _gecko_command(u32 command) @@ -207,13 +208,12 @@ void gecko_init(void) write32(EXI0_CSR, 0); write32(EXI1_CSR, 0); write32(EXI2_CSR, 0); - write32(EXI0_CSR, 0x2000); - write32(EXI0_CSR, 3<<10); - write32(EXI1_CSR, 3<<10); if (!gecko_isalive()) return; + gecko_found = 1; + gecko_flush(); gecko_console_enabled = 1; } @@ -269,17 +269,12 @@ static u32 _gecko_receive_left = 0; static u32 _gecko_receive_len = 0; static u8 *_gecko_receive_buffer = NULL; -void gecko_timer_initialize(void) -{ - if (!gecko_isalive()) - return; - - irq_set_alarm(20, 1); -} - -void gecko_timer(void) { +void gecko_process(void) { u8 b; + if (!gecko_found) + return; + if (_gecko_cmd_start_time && read32(HW_TIMER) > (_gecko_cmd_start_time + IRQ_ALARM_MS2REG(5000))) goto cleanup; diff --git a/gecko.h b/gecko.h index 17aa234..bdf5c3b 100644 --- a/gecko.h +++ b/gecko.h @@ -27,14 +27,13 @@ u8 gecko_enable_console(const u8 enable); int gecko_printf(const char *fmt, ...) __attribute__((format (printf, 1, 2))); #endif -void gecko_timer_initialize(void); -void gecko_timer(void); +void gecko_process(void); #else #define gecko_init(...) do { } while(0) #define gecko_enable_console(...) do { } while(0) #define gecko_printf(...) do { } while(0) -#define gecko_timer_initialize(...) do { } while(0) +#define gecko_process(...) do { } while(0) #define gecko_timer(...) do { } while(0) #endif diff --git a/ipc.c b/ipc.c index 23d3760..128c257 100644 --- a/ipc.c +++ b/ipc.c @@ -343,6 +343,8 @@ u32 ipc_process_slow(void) if (!vector) { + gecko_process(); + u32 cookie = irq_kill(); if(slow_queue_head == slow_queue_tail) irq_wait(); diff --git a/irq.c b/irq.c index 45c857e..d1067d4 100644 --- a/irq.c +++ b/irq.c @@ -54,11 +54,9 @@ void irq_handler(void) flags = flags & enabled; if(flags & IRQF_TIMER) { - if (_alarm_frequency) { - // currently we use the alarm timer only for lame usbgecko polling - gecko_timer(); + if (_alarm_frequency) write32(HW_ALARM, read32(HW_TIMER) + _alarm_frequency); - } + write32(HW_ARMIRQFLAG, IRQF_TIMER); } if(flags & IRQF_NAND) { diff --git a/main.c b/main.c index daa1937..3a8c7fe 100644 --- a/main.c +++ b/main.c @@ -55,11 +55,11 @@ u32 _main(void *base) read32(0xffffff0c), read32(0xffffff10), read32(0xffffff14)); irq_initialize(); - irq_enable(IRQ_TIMER); // irq_enable(IRQ_GPIO1B); irq_enable(IRQ_GPIO1); irq_enable(IRQ_RESET); - gecko_timer_initialize(); + irq_enable(IRQ_TIMER); + irq_set_alarm(20, 1); gecko_printf("Interrupts initialized\n"); crypto_initialize();