void my_SLEEP(INT32 duration) { INT32 wakeTime = my_GET_TIME_OF_DAY() + duration; debug(GREY, "WakeTime: %d", wakeTime); MEMORY_MAPPED_IO mmio; mmio.Mode = Z502GetCurrentContext; MEM_READ(Z502Context, &mmio); PCB *newPCB; if ((newPCB = PCB_Get_By_ContextID(mmio.Field1)) == NULL) { debug(RED, "ERROR: Process Terminated in Sleep\n"); return; } TimerQueue_Lock("SLEEP"); debug(GREY, "new Timer Queue Item: PID %d wakeTime %d", newPCB->PID, wakeTime); TimerQueue_Add(newPCB, wakeTime); newPCB->status = PROCESS_Waiting; if (currentTimer > wakeTime || currentTimer == 0) { currentTimer = wakeTime; setTimer(duration); } else { debug(BLUE, "No need to set timer %d < %d", currentTimer, wakeTime); } TimerQueue_Unlock("SLEEP"); debug(YELLOW, "Time Before Idle %d\n", my_GET_TIME_OF_DAY()); TestMode("Before Dispatcher"); my_Dispatcher(); debug(YELLOW, "Time After Idle %d\n", my_GET_TIME_OF_DAY()); }
void setMoveAction(int type) { switch (type) { case MOVE_SELECTION_TYPE_START: case MOVE_SELECTION_TYPE_STRAIGHT: printf("Straight Move\r\n"); StraightMove(); break; case MOVE_SELECTION_TYPE_STOP: printf("Stop Move\r\n"); StopMove(); break; case MOVE_SELECTION_TYPE_RIGHTSIFT_1: printf("Right Sift 1\r\n"); StraightMoveRightSift(); break; case MOVE_SELECTION_TYPE_LEFTSIFT_1: printf("Left Sift 1\r\n"); StraightMoveLeftSift(); break; case MOVE_SELECTION_TYPE_RIGHTSIFT_2: printf("Right Sift 2\r\n"); StraightMoveRightSift2(); break; case MOVE_SELECTION_TYPE_LEFTSIFT_2: printf("Left Sift 2\r\n"); StraightMoveLeftSift2(); break; case MOVE_SELECTION_TYPE_RIGHTTURN: printf("Right Turn\r\n"); //TurnMoveRight(); TurnLowMoveRight(); break; case MOVE_SELECTION_TYPE_LEFTTURN: printf("Left Turn\r\n"); //TurnMoveLeft(); TurnLowMoveLeft(); break; case MOVE_SELECTION_TYPE_RIGHTTURN_2: printf("Right Turn 2\r\n"); TurnMoveRight(); //TurnLowMoveRight(); break; case MOVE_SELECTION_TYPE_LEFTTURN_2: printf("Left Turn 2\r\n"); TurnMoveLeft(); //TurnLowMoveLeft(); break; case MOVE_SELECTION_TYPE_BACK: printf("Back Move\r\n"); StopMove(); _delay_ms(10); BackMove(); _delay_ms(1000); break; case MOVE_SELECTION_TYPE_S_MOVE_10: TestMode(); default: break; } }
/* Initialise the Maxim driver(s) */ void HCMAX7219::Init(void) { byte DriverIndex; for (DriverIndex = 0; DriverIndex < NUMBEROFDRIVERS; DriverIndex++) { Write(MAX7219DECODE, 0,DriverIndex); Intensity(0x0F, DriverIndex); SevenSegDigits(7, DriverIndex); TestMode(TESTMODEOFF, DriverIndex); Shutdown(MAX7219ON, DriverIndex); Clear(); Refresh(); } }
void input_eval_loop(int isRecording) { char** recHistory = NULL; int curRecHistEntry = 0; if(isRecording) recHistory = (char**)alloca(200); // space for 200 pointers to history entries while (1) { DefineStatusMessage((char*)"", 1, 0, 0); strcpy(expr, (char*)""); printf("\x1e"); dConsoleRedraw(); int res = gets(expr,INPUTBUFLEN); if(res == 2) { dConsolePut("\n"); select_script_and_run(); continue; } if(res == 4) { dConsolePut("\n"); select_strip_script(); continue; } if(res == 3) { dConsolePut("\n"); char buf[100] = ""; sprintf(buf, "prizmUIkeyHandler(%d,%d)", custom_key_to_handle, custom_key_to_handle_modifier); strcpy(expr, (char*)buf); execution_in_progress = 1; run(buf); execution_in_progress = 0; check_do_graph(); if(run_startup_script_again) { run_startup_script_again = 0; run_startup_script(); } continue; } puts(expr); update_cmd_history(expr); dConsoleRedraw(); if(strcmp(expr, "testmode") == 0) { TestMode(1); } else if(strcmp(expr, "meminfo") == 0) { print_mem_info(); } else if(strcmp(expr, "memgc") == 0) { gc(); } else if(strcmp(expr, "record") == 0) { if(!isRecording) script_recorder(); else { // create and save a script. this must be done here, because we used alloca // the "clean" way would be using malloc&free, but on the Prizm the heap is already being heavily used by the Eigenmath core. if(curRecHistEntry == 0) { printf("Nothing to record.\n"); return; } printf("Recording stopped.\n"); printf("Type a name for the script, or\n"); printf("leave empty to discard.\n:"); char inputname[MAX_FILENAME_SIZE+1] = ""; gets(inputname,MAX_FILENAME_SIZE-50); puts(inputname); if(!strlen(inputname)) { // user aborted printf("Recording discarded.\n"); return; } if (aborttimer > 0) { Timer_Stop(aborttimer); Timer_Deinstall(aborttimer); } char filename[MAX_FILENAME_SIZE+1] = ""; sprintf(filename, "\\\\fls0\\%s.txt", inputname); unsigned short pFile[MAX_FILENAME_SIZE+1]; Bfile_StrToName_ncpy(pFile, (unsigned char*)filename, strlen(filename)+1); // calculate size int size = 0; int maxHistory = curRecHistEntry - 1; //because we ++'ed at the end of last addition for(int i=0; i <= maxHistory; i++) { size = size + strlen(recHistory[i]) + 1; // 1 byte for \n. we will use unix line termination } int BCEres = Bfile_CreateEntry_OS(pFile, CREATEMODE_FILE, &size); if(BCEres >= 0) // Did it create? { BCEres = Bfile_OpenFile_OS(pFile, READWRITE, 0); // Get handle for(int i=0; i <= maxHistory; i++) { char* buf = (char*)alloca(strlen(recHistory[i])+5); strcpy(buf, recHistory[i]); strcat(buf, (char*)"\n"); Bfile_WriteFile_OS(BCEres, buf, strlen(recHistory[i])+1); } Bfile_CloseFile_OS(BCEres); printf("Script created.\n"); } else { printf("An error occurred when creating the script for recording.\n"); } aborttimer = Timer_Install(0, check_execution_abort, 100); if (aborttimer > 0) Timer_Start(aborttimer); return; } } else { execution_in_progress = 1; has_drawn_graph = 0; run(expr); // run_startup_script cannot run from inside eval_clear because then it would be a run() inside a run() if(run_startup_script_again) { run_startup_script_again = 0; run_startup_script(); } execution_in_progress = 0; // if recording, add input to record if(isRecording && curRecHistEntry <= 200) { recHistory[curRecHistEntry] = (char*)alloca(strlen(expr)+2); // 2 bytes for security strcpy(recHistory[curRecHistEntry], expr); curRecHistEntry++; } check_do_graph(); } } }
LONG CuDlgReplicationStaticPageCollision::OnUpdateData (WPARAM wParam, LPARAM lParam) { CWaitCursor doWaitCursor; int nNodeHandle = (int)wParam; LPIPMUPDATEPARAMS pUps = (LPIPMUPDATEPARAMS)lParam; CdIpmDoc* pIpmDoc = (CdIpmDoc*)wParam; try { if (!m_pCollisionData) { m_pCollisionData = new CaCollision(); ASSERT (m_pFrameLayout); if (m_pFrameLayout && IsWindow (m_pFrameLayout->m_hWnd)) { CvReplicationPageCollisionViewLeft* pView = (CvReplicationPageCollisionViewLeft*)m_pFrameLayout->GetLeftPane(); ASSERT (pView); if (pView) { CdReplicationPageCollisionDoc* pDoc = (CdReplicationPageCollisionDoc*)pView->GetDocument(); ASSERT (pDoc); if (pDoc) pDoc->SetCollisionData (m_pCollisionData); } } } switch (pUps->nIpmHint) { case 0: case FILTER_IPM_EXPRESS_REFRESH: break; default: return 0L; } ASSERT (pUps); if (pUps->nIpmHint != FILTER_IPM_EXPRESS_REFRESH) { m_SvrDta = *(LPRESOURCEDATAMIN)pUps->pStruct; } if (m_pFrameLayout && IsWindow (m_pFrameLayout->m_hWnd)) { CvReplicationPageCollisionViewLeft* pViewL = (CvReplicationPageCollisionViewLeft*)m_pFrameLayout->GetLeftPane(); ASSERT (pViewL); if (pViewL) pViewL->GetTreeCtrl().DeleteAllItems(); } m_pCollisionData->Cleanup(); // // Pass the FALSE to TestMode to disable the test data: BOOL bTest = FALSE; TestMode(FALSE); if (!bTest) IPM_RetrieveCollision(pIpmDoc, &m_SvrDta, m_pCollisionData); if (m_pFrameLayout && IsWindow (m_pFrameLayout->m_hWnd)) { CWnd* pWnd = m_pFrameLayout->GetLeftPane(); if (pWnd) pWnd->SendMessage (WM_USER_IPMPAGE_UPDATEING, wParam, lParam); } } catch (CMemoryException* e) { theApp.OutOfMemoryMessage (); e->Delete(); } catch (CeIpmException e) { AfxMessageBox (e.GetReason(), MB_ICONEXCLAMATION|MB_OK); } return 0L; }
void my_Dispatcher(){ INT32 PID; TestMode("Dispatcher 0"); PID = my_GET_PROCESS_ID_SYS(""); debug(YELLOW, "Dispatcher of PID %d", 0); PrintState(); TestMode("Dispatcher 1"); int loop = TRUE; int selfStarted = FALSE; while (loop){ //usleep(1000); CALL(ReadyQueue_Lock("Dispatcher loop")); if (PCB_Get_Self()->status == PROCESS_RUNNING){ selfStarted = TRUE; loop = FALSE; }else{ if (ReadyQueueHead->Next != NULL){ loop = FALSE; }else{ CALL(ReadyQueue_Unlock("Dispatcher Loop waiting")); //nothing on ready Q, advance time } } } if (selfStarted){ ReadyQueue_Unlock("Started Dispatcher"); debug(RED, "Self started by other dispatcher, returning"); return; } TestMode("Dispatcher 2"); if (multicore == TRUE){ int flag = TRUE; //multi core mode, start all contexts on ready queue while (ReadyQueueHead->Next != NULL){ PCB *pcb = ReadyQueueHead->Next->PCB; pcb->status = PROCESS_RUNNING; ReadyQueueHead->Next = ReadyQueueHead->Next->Next; Printer("Dispatch", pcb->PID, FALSE); Start_Context(pcb); if (pcb->PID == PID){ debug(RED, "Flag set to false "); flag = FALSE; } //take it off the ready queue } ReadyQueue_Unlock("Multi Core Dispatcher over"); if (flag){ //unless self is started, suspend self debug(RED, "Suspending self"); SuspendSelf(); } }else{ //single core mode if (ReadyQueueHead->Next!=NULL){ debug(RED, "Ready Queue Item PID %d", ReadyQueueHead->Next->PCB->PID); PCB *pcb = ReadyQueueHead->Next->PCB; pcb->status = PROCESS_RUNNING; ReadyQueueHead->Next = ReadyQueueHead->Next->Next; Printer("Dispatch", pcb->PID, FALSE); ReadyQueue_Unlock("Single core dispatcher over"); debug(RED, "TEMP: %d", pcb->PID); Start_Context(pcb); debug(GREEN, "After Start Context"); }else{ debug(RED, "Ready Queue is empty"); } } PrintState(); }