void setOperationalMode(int newmode) { extern void buildMyStatsCSV(); extern void saveLogFile(int); if(newmode == (int)P_WAIT) { // stop(); --- should we see if we can WAIT while paused in an audio file? SysIntoWaitMode(); // when leaving wait mode, next instruction is executed, so we return here return; } else { // give visual feedback of shutting down (aural feedback when user causes shutdown in takeAction()) setLED(LED_ALL,TRUE); buildMyStatsCSV(); buildExchgOstats(); clearDeleteQueue(); write_config_bin(); // build a config.bin writeVersionToDisk(SYSTEM_PATH); // make sure the version file is correct confirmSNonDisk(); // make sure the serial number file is correct //cleanUpOldRevs(); // cleanup any old revs // assume calling for sleep or halt *P_Clock_Ctrl |= 0x200; //bit 9 KCEN enable IOB0-IOB2 key change interrupt if (newmode == (int)P_HALT) logString((char *)"Halting",BUFFER,LOG_NORMAL); else // newmode == (int)P_SLEEP logString((char *)"Sleeping",BUFFER,LOG_NORMAL); saveLogFile(0); Snd_Stop(); // no logging setLED(LED_ALL,FALSE); turnAmpOff(); disk_safe_exit(0); // try to get the sd card in a safe state - reversw what we do on startup _deviceunmount(0); fs_uninit(); SD_Uninitial(); turnSDoff(); turnNORoff(); if (newmode == (int)P_HALT) { /* setRTCalarmSeconds(61); // device should come back on in 61 seconds */ SysIntoHaltMode(); } else { // newmode == (int)P_SLEEP disk_safe_exit(0); _SystemOnOff(); } while(1); // cpu reset on exiting halt/sleep mode, so nothing below here executes } }
void resetSystem(void) { // set watchdog timer to reset device; 0x780A (Watchdog Reset Control Register) // see GPL Programmer's Manual (V1.0 Dec 20,2006), Section 3.5, page 18 checkVoltage(); // USB may have been supplying sole power -- need to check if voltage dropping fast stop(); if (PLEASE_WAIT_IDX && context.package) { // prevents trying to insert this sound before config & control files are loaded. insertSound(&pkgSystem.files[PLEASE_WAIT_IDX],NULL,TRUE); } checkVoltage(); // USB may have been supplying sole power -- need to check if voltage dropping fast saveVolumeProfile(); logString((char *)"* RESET *",ASAP,LOG_ALWAYS); saveLogFile(0); fs_safexit(); // should close all open files disk_safe_exit(0); // try to get the sd card in a safe state - reverse what we do on startup _deviceunmount(0); fs_uninit(); SD_Uninitial(); turnSDoff(); playBip(); setLED(LED_ALL,FALSE); *P_WatchDog_Ctrl &= ~0x4001; // clear bits 14 and 0 for resetting system and time=0.125 sec *P_WatchDog_Ctrl |= 0x8004; // set bits 2 and 15 for 0.125 sec, system reset, and enable watchdog while(1); }
void shutdown() { shuttingDown = 1; // prevents the call to wait() below from checking voltage *P_Clock_Ctrl |= 0x200; //bit 9 KCEN enable IOB0-IOB2 key change interrupt disk_safe_exit(0); // try to get the sd card in a safe state - reverse what we do on startup _deviceunmount(0); fs_uninit(); SD_Uninitial(); turnSDoff(); SACM_Volume(1); playDing(); turnAmpOff(); setLED(LED_ALL,FALSE); setLED(LED_RED,TRUE); wait(150); setLED(LED_RED,FALSE); setLED(LED_GREEN,TRUE); wait(50); setLED(LED_ALL,FALSE); turnNORoff(); }
void card_detect_demo(void) { INT8U err; INT32U msg_id; INT32S nRet; card_detect_q = OSQCreate(card_detect_area, 1); if (card_detect_q == NULL) while(1); card_detect_set_cf_callback(cf_card_plug_in_out); card_detect_set_sdms_callback(sdms_card_plug_in_out); card_detect_set_usb_h_callback(usb_h_plug_in_out); card_detect_set_usb_d_callback(usb_d_plug_in_out); card_detect_init(TYPE_CF|TYPE_SD|TYPE_MS|TYPE_USBH|TYPE_USBD|TYPE_NAND); if(card_detection(C_CFC)) { nRet = _devicemount(FS_CF); if(!nRet) DBG_PRINT("CF MOUNT Success\r\n"); else DBG_PRINT("CF MOUNT Fail!!!\r\n"); } if(card_detection(C_SDC)) { nRet = _devicemount(FS_SD); if(!nRet) DBG_PRINT("SD MOUNT Success\r\n"); else DBG_PRINT("SD MOUNT Fail!!!\r\n"); } if(card_detection(C_MSC)) { nRet = _devicemount(FS_MS); if(!nRet) DBG_PRINT("MS MOUNT Success\r\n"); else DBG_PRINT("MS MOUNT Fail!!!\r\n"); } if(card_detection(C_USBH)) { nRet = _devicemount(FS_USBH); if(!nRet) DBG_PRINT("USB Host MOUNT Success\r\n"); else DBG_PRINT("USB Host MOUNT Fail!!!\r\n"); } if(card_detection(C_USBD)) { DBG_PRINT("USBD plug in\r\n"); } if(card_detection(C_NAND)) { nRet = _devicemount(FS_NAND1); if(!nRet) DBG_PRINT("NAND1 MOUNT Success\r\n"); else DBG_PRINT("NAND1 MOUNT Fail!!!\r\n"); } if(card_detection(C_XDC)) { nRet = _devicemount(FS_XD); if(!nRet) DBG_PRINT("XD MOUNT Success\r\n"); else DBG_PRINT("XD MOUNT Fail!!!\r\n"); } while(1) { msg_id = (INT32U) OSQPend(card_detect_q, 0, &err); switch(msg_id) { case CF_PLUG_IN: cfc_detection(); if(card_detection(C_CFC)) { nRet = _devicemount(FS_CF); if(!nRet) DBG_PRINT("CF PLUG-IN & MOUNT-SUCCESS\r\n"); else DBG_PRINT("CF PLUG-IN & MOUNT-FAIL!!!\r\n"); } break; case CF_PLUG_OUT: disk_safe_exit(FS_CF); nRet = _deviceunmount(FS_CF); if(!nRet) DBG_PRINT("CF PLUG-OUT & UN-MOUNT-SUCCESS\r\n"); else DBG_PRINT("CF PLUG-OUT & UN-MOUNT-FAIL!!!\r\n"); break; case SDMSXD_PLUG_IN: sdms_detection(); if(card_detection(C_SDC)) { nRet = _devicemount(FS_SD); if(!nRet) DBG_PRINT("SD PLUG-IN & MOUNT-SUCCESS\r\n"); else DBG_PRINT("SD PLUG-IN & MOUNT-FAIL!!!\r\n"); } else if(card_detection(C_MSC)) { nRet = _devicemount(FS_MS); if(!nRet) DBG_PRINT("MS PLUG-IN & MOUNT-SUCCESS\r\n"); else DBG_PRINT("MS PLUG-IN & MOUNT-FAIL!!!\r\n"); } else if(card_detection(C_XDC)) { nRet = _devicemount(FS_XD); if(!nRet) DBG_PRINT("XD PLUG-IN & MOUNT-SUCCESS\r\n"); else DBG_PRINT("XD PLUG-IN & MOUNT-FAIL!!!\r\n"); } break; case SDMSXD_PLUG_OUT: if(card_detection(C_SDC)) { disk_safe_exit(FS_SD); nRet = _deviceunmount(FS_SD); if(!nRet) DBG_PRINT("SD PLUG-OUT & UN-MOUNT-SUCCESS\r\n"); else DBG_PRINT("SD PLUG-OUT & UN-MOUNT-FAIL!!!\r\n"); } else if(card_detection(C_MSC)) { disk_safe_exit(FS_MS); nRet = _deviceunmount(FS_MS); if(!nRet) DBG_PRINT("MS PLUG-OUT & UN-MOUNT-SUCCESS\r\n"); else DBG_PRINT("MS PLUG-OUT & UN-MOUNT-FAIL!!!\r\n"); } else if(card_detection(C_XDC)) { disk_safe_exit(FS_XD); nRet = _deviceunmount(FS_XD); if(!nRet) DBG_PRINT("XD PLUG-OUT & UN-MOUNT-SUCCESS\r\n"); else DBG_PRINT("XD PLUG-OUT & UN-MOUNT-FAIL!!!\r\n"); } break; case USB_H_PLUG_IN: if(card_detection(C_USBH)) { nRet = _devicemount(FS_USBH); if(!nRet) DBG_PRINT("USB Host PLUG-IN & MOUNT-SUCCESS\r\n"); else DBG_PRINT("USB Host PLUG-IN & MOUNT-FAIL!!!\r\n"); } break; case USB_H_PLUG_OUT: if(!card_detection(C_USBH)) { disk_safe_exit(FS_USBH); nRet = _deviceunmount(FS_USBH); if(!nRet) DBG_PRINT("USB Host PLUG-OUT & UN-MOUNT-SUCCESS\r\n"); else DBG_PRINT("USB Host PLUG-OUT & UN-MOUNT-FAIL!!!\r\n"); } break; case USB_D_PLUG_IN: if(card_detection(C_USBD)) { DBG_PRINT("USB Device PLUG-IN\r\n"); } break; case USB_D_PLUG_OUT: if(!card_detection(C_USBD)) { DBG_PRINT("USB Device PLUG-OUT\r\n"); } break; } } }