/*--------------------------------------------------------------------------------- $Id: template.c,v 1.2 2005/09/07 20:06:06 wntrmute Exp $ Simple ARM7 stub (sends RTC, TSC, and X/Y data to the ARM 9) $Log: template.c,v $ Revision 1.2 2005/09/07 20:06:06 wntrmute updated for latest libnds changes Revision 1.8 2005/08/03 05:13:16 wntrmute corrected sound code ---------------------------------------------------------------------------------*/ #include #include #include #include #include #include #include #include "pm.h" void VblankHandler(void) { static int heartbeat = 0; uint16 but=0, x=0, y=0, xpx=0, ypx=0, z1=0, z2=0, batt=0, aux=0; int t1=0, t2=0; uint32 temp=0; // Read the time uint8 curtime[7]; rtcGetTimeAndDate(curtime); unsigned int i; for(i=0; itime.curtime[i+1] = curtime[i]; // Update the heartbeat heartbeat++; // Read the touch screen but = REG_KEYXY; if(!(but & (1<<6))) { touchPosition tempPos = touchReadXY(); x = tempPos.x; y = tempPos.y; xpx = tempPos.px; ypx = tempPos.py; } z1 = touchRead(TSC_MEASURE_Z1); z2 = touchRead(TSC_MEASURE_Z2); batt = touchRead(TSC_MEASURE_BATTERY); aux = touchRead(TSC_MEASURE_AUX); // Read the temperature temp = touchReadTemperature(&t1, &t2); // Update the IPC struct // IPC->heartbeat = heartbeat; IPC->buttons = but; IPC->touchX = x; IPC->touchY = y; IPC->touchXpx = xpx; IPC->touchYpx = ypx; IPC->touchZ1 = z1; IPC->touchZ2 = z2; IPC->battery = batt; IPC->aux = aux; IPC->temperature = temp; IPC->tdiode1 = t1; IPC->tdiode2 = t2; Wifi_Update(); // update wireless in vblank } // callback to allow wifi library to notify arm9 void arm7_synctoarm9() { // send fifo message REG_IPC_FIFO_TX = IPC_WIFI_SYNC; } // interrupt handler to allow incoming notifications from arm9 void arm7_fifo() { // check incoming fifo messages u32 msg = REG_IPC_FIFO_RX; bool top, bottom; switch(IPC_COMMAND(msg)) { case IPC_WIFI_SYNC: Wifi_Sync(); REG_IPC_FIFO_TX = IPC_OK; break; case IPC_BACKLIGHT: if(IPC_ARG(msg) != IPC_GET) pmSwitchBacklight(msg & IPC_BACKLIGHT_TOP, msg & IPC_BACKLIGHT_BOTTOM); pmGetBacklight(&top, &bottom); REG_IPC_FIFO_TX = (IPC_OK | (top ? IPC_BACKLIGHT_TOP : 0) | (bottom ? IPC_BACKLIGHT_BOTTOM : 0)); break; case IPC_BRIGHTNESS: if(IPC_ARG(msg) != IPC_GET) pmSetBacklightBrightness(IPC_ARG(msg)); REG_IPC_FIFO_TX = IPC_OK | pmGetBacklightBrightness(); break; case IPC_POWEROFF: pmPowerOff(); REG_IPC_FIFO_TX = IPC_OK; } #if 0 // check incoming fifo messages u32 msg = REG_IPC_FIFO_RX; if(msg == IPC_WIFI_SYNC) Wifi_Sync(); else if((msg & 0xfffffff0) == IPC_BACKLIGHT) pmSwitchBacklight(msg & IPC_BACKLIGHT_TOP, msg & IPC_BACKLIGHT_BOTTOM); else if(msg == IPC_POWEROFF) pmPowerOff(); #endif } int main(int argc, char ** argv) { pmSwitchBacklight(true, false); // enable & prepare fifo asap REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_SEND_CLEAR; // Reset the clock if needed rtcReset(); irqInit(); irqSet(IRQ_VBLANK, VblankHandler); irqEnable(IRQ_VBLANK); irqSet(IRQ_WIFI, Wifi_Interrupt); // set up wifi interrupt irqEnable(IRQ_WIFI); { // sync with arm9 and init wifi u32 fifo_temp; while(1) { // wait for magic number while(REG_IPC_FIFO_CR&IPC_FIFO_RECV_EMPTY) swiWaitForVBlank(); fifo_temp=REG_IPC_FIFO_RX; if(fifo_temp==IPC_WIFI_INIT) break; } while(REG_IPC_FIFO_CR&IPC_FIFO_RECV_EMPTY) swiWaitForVBlank(); fifo_temp=REG_IPC_FIFO_RX; // give next value to wifi_init Wifi_Init(fifo_temp); irqSet(IRQ_FIFO_NOT_EMPTY,arm7_fifo); // set up fifo irq irqEnable(IRQ_FIFO_NOT_EMPTY); REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_RECV_IRQ; Wifi_SetSyncHandler(arm7_synctoarm9); // allow wifi lib to notify arm9 } // arm7 wifi init complete // initialize reboot address *(vu32*)0x27ffffc = 0; while(1) { swiWaitForVBlank(); // reboot? if((*(vu32*)0x27ffffc) != 0) { REG_IE = 0; REG_IME = 0; REG_IF = 0xffff; typedef void (*eloop_type)(void); eloop_type eloop = *(eloop_type*)0x27ffffc; *(vu32*)0x27ffffc = 0; *(vu32*)0x27ffff8 = 0; eloop(); } } }