static void __usb_flush(s32 chn) { char tmp; if(!EXI_Lock(chn,EXI_DEVICE_0,NULL)) return; while(__usb_recvbyte(chn,&tmp)); EXI_Unlock(chn); }
static __inline__ void __usbgecko_exi_wait(s32 chn) { u32 level; _CPU_ISR_Disable(level); if(!usbgecko_inited) __usbgecko_init(); while(EXI_Lock(chn,EXI_DEVICE_0,__usbgecko_exi_unlock)==0) { LWP_ThreadSleep(wait_exi_queue[chn]); } _CPU_ISR_Restore(level); }
static int __usb_isgeckoalive(s32 chn) { s32 ret; u16 val; if(!EXI_Lock(chn,EXI_DEVICE_0,NULL)) return 0; val = 0x9000; ret = __send_command(chn,&val); if(ret==1 && !(val&0x0470)) ret = 0; EXI_Unlock(chn); return ret; }
static __inline__ int __send_command1(s32 chn,u16 *cmd) { s32 ret; ret = 0; if(EXI_Lock(chn,EXI_DEVICE_0,NULL)) { if(!EXI_Select(chn,EXI_DEVICE_0,EXI_SPEED32MHZ)) ret |= 0x01; if(!EXI_Imm(chn,cmd,sizeof(u16),EXI_READWRITE,NULL)) ret |= 0x02; if(!EXI_Sync(chn)) ret |= 0x04; if(!EXI_Deselect(chn)) ret |= 0x08; if(!EXI_Unlock(chn)) ret |= 0x10; if(ret) ret = 0; else ret = 1; } return ret; }
static int __usb_sendbuffer(s32 chn,const void *buffer,int size) { s32 ret; s32 left = size; char *ptr = (char*)buffer; if(!EXI_Lock(chn,EXI_DEVICE_0,NULL)) return 0; while(left>0) { if(__usb_checksend(chn)) { ret = __usb_sendbyte(chn,*ptr); if(ret==0) break; ptr++; left--; } } EXI_Unlock(chn); return (size - left); }