static __inline__ int __send_command(s32 chn,u16 *cmd) { s32 ret = 0; 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(ret) return 0; return 1; }
static u32 __SRAM_Read(void *buffer) { u32 command = 0x20000100; EXI_Select(0, 1, 3); EXI_Imm(0, &command, 4, EXI_WRITE, 0); EXI_Sync(0); EXI_ImmEx(0, buffer, 64, EXI_READ); EXI_Sync(0); EXI_Deselect(0); return 0; }
static u32 __SRAM_Write(void *buffer, u32 loc, u32 length) { u32 command = 0xA0000100 + (loc << 6); EXI_Select(0, 1, 3); EXI_Imm(0, &command, 4, EXI_WRITE, 0); EXI_Sync(0); EXI_ImmEx(0, buffer, 64, EXI_WRITE); EXI_Sync(0); EXI_Deselect(0); return 0; }
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; }
s32 EXI_ImmEx(int chan, void *buffer, int length, int mode) { u8 *v = (u8*)buffer; int blength; while(length) { blength = 4; if(blength >= length) blength = length; EXI_Imm(chan, v, blength, mode, 0); EXI_Sync(chan); length -= blength; v += blength; } if(length == 0) return 0; return 1; }