void Init() { int cpid, i, key, print_driver_pid, file_system_pid; msg_t my_msg; print_driver_pid = Spawn(PrintDriver); // spawn driver proc file_system_pid = Spawn(FileSys); for(i = 0; i < NUM_TERM; i++){ cpid = Spawn(Shell); my_msg.nums[0] = cpid; my_msg.nums[1] = i; my_msg.nums[2] = print_driver_pid; my_msg.nums[3] = file_system_pid; MsgSnd(cpid, &my_msg); } for(;;){ //cons_printf("%d ", GetPid()); //for(i=0; i<83300; i++)IO_DELAY(); key = cons_getchar(); switch(key) { case 'b': breakpoint(); break; case 'q': exit(0); default: } } }
void InitProc(){ int i; msg_t msg; msg.recipient = 2; MyStrcpy(msg.data,"Hello World! Team Null\n"); while(1){ cons_printf("0 "); for(i=0; i<1666668; i++)IO_DELAY(); if(cons_kbhit()){ char key = cons_getchar(); switch(key) { case('p'): MsgSnd(&msg); break; case('b'): breakpoint(); break; case('x'): exit(0); } } } }
void InitProc(int product_sem_id) { char key; while(1) //loops infinitely to poll for a key { Sleep(1); //repeat to sleep for a second inside the infinite loop if(cons_kbhit()) { key = cons_getchar(); switch(key) { case 'p': StartProc(ProducerProc);//create a producer process break; case 'c': StartProc(ConsumerProc);//create a consumer process break; case 'b': breakpoint(); //breakpoint() to go into GDB break; case 'x': exit(0); //exit(0) to quit MyOS.dli break; default : // no keys were pressed break; } } } }
char * cons_gets(char *buf, int n) { char *lp; char *limit; int c; lp = buf; limit = &buf[n - 1]; for (;;) { c = cons_getchar() & 0177; switch (c) { case '\n': case '\r': *lp = '\0'; return (buf); case '\b': if (lp > buf) lp--; continue; case 'u'&037: /* ^U */ lp = buf; prom_putchar('\r'); prom_putchar('\n'); continue; case 0: continue; default: if (lp < limit) *lp++ = (char)c; else prom_putchar('\a'); /* bell */ } } }
void InitProc(int product_sem_id) { char key; msg_t temp_msg; char greet[] = "Greetings from team MIOS!\n"; MyStrcpy((char *) &temp_msg.data, (char *) &greet); //send a greetings message temp_msg.recipient = 2; while(1) //loops infinitely to poll for a key { Sleep(1); //repeat to sleep for a second inside the infinite loop if(cons_kbhit()) { key = cons_getchar(); switch(key) { case 'p': MsgSnd(&temp_msg); break; case 'b': breakpoint(); //breakpoint() to go into GDB break; case 'x': exit(0); //exit(0) to quit MyOS.dli break; default : // no keys were pressed break; } } } }
void Kernel(tf_t *tf_p) // kernel directly enters here when interrupt occurs { // Save "tf_p" to pcbs[cur_pid].tf_p for future resume of process runtime pcbs[cur_pid].tf_p = tf_p; // tf_p->intr_id tells what intr made CPU get here, pushed in entry.S switch(tf_p->intr_id) { case TIMER_INTR: TimerISR(); // this must include dismissal of timer interrupt break; case SLEEP_INTR: SleepISR(tf_p->eax); break; case GETPID_INTR: tf_p->eax = cur_pid; break; } // still handles other keyboard-generated simulated events if(cons_kbhit()) // check if a key was pressed (returns non zero) { char key = cons_getchar(); // get the pressed key switch(key) // see if it's one of the following for service { case 'n': if(EmptyQ(&avail_q)) cons_printf("No more available PIDs!\n"); else { SpawnISR(DeQ(&avail_q), SimpleProc); } break; case 'k': KillISR(); break; // non-functional in phase 2 case 's': ShowStatusISR(); break; case 'b': breakpoint(); break; // this stops when run in GDB mode case 'q': exit(0); } // switch(key) } // if(cons_kbhit()) Scheduler(); // select a process to run Loader(pcbs[cur_pid].tf_p); // run the process selected }
void KernelMain(TF_t *TF_ptr) { int new_pid, i, pid, len; char key; pcb[running_pid].TF_ptr = TF_ptr; //save TF_ptr to PCB of running process switch(TF_ptr->intr_id) //switch on TF_ptr->intr_id { case TIMER_INTR: TimerISR(); //call TimerISR() outportb(0x20, 0x60); //dismiss timer event: send PIC with a code OS_clock++; len = sleep_q.len; for(i = 0; i < len; i++) { pid = DeQ(&sleep_q); if(OS_clock == pcb[pid].wake_time) { EnQ(pid, &ready_q); pcb[pid].state = READY; } else { EnQ(pid, &sleep_q); } } break; case GETPID_INTR: GetPidISR(); break; case SLEEP_INTR: SleepISR(); break; default: cons_printf("Panic: unknown intr ID (%d)!\n", TF_ptr->intr_id); breakpoint(); //fallback to GDB } //same as simulated, handle keystroke simulated events (s/e/b/x, but no 't' key) if(cons_kbhit()) { key = cons_getchar(); switch(key) { case 's': new_pid = DeQ(&free_q); //dequeue free_q for a new pid if (new_pid == -1) //if the new pid (is -1) indicates no ID left { cons_printf("Panic: no more available process ID left!\n"); //show msg on target PC } else { StartProcISR(new_pid); //call StartProcISR(new pid) to create new proc } break; case 'e': EndProcISR(); //call EndProcISR() to handle this event break; case 'b': breakpoint(); //call breakpoint(); to go into GDB break; case 'x': exit(0); //just call exit(0) to quit MyOS.dli break; default : // no keys were pressed break; } } Scheduler(); //call scheduler() to process to load/run if needed LoadRun(pcb[running_pid].TF_ptr); //call LoadRun(pcb[running_pid].TF_ptr) to load/run selected proc }
static void task_calibration_entry(void) { int16_t autoboot_ms = 3000; int c; uint8_t quit = 0; /* wait for keypress, or schedule */ while (!usart_is_data_arrived(&USART_CONSOLE)) { cons_printf("Press a key to enter calibration... %ds remaining\r", autoboot_ms / 1000); kos_set_next_schedule_delay_ms(250); autoboot_ms -= 250; if (autoboot_ms > 0) kos_yield(); else /* time elapsed, we bypass calibration * and continue to game mode. */ goto exit_point; } cons_printf("\n\n"); getchar(); mcurses_init(); mach_calibration_usage(); while (!quit) { /* display prompt */ cons_printf("$ "); /* wait for command */ c = cons_getchar(); cons_printf("%c\n", c); switch (c) { #if defined(CONFIG_ANALOG_SENSORS) case 'a': analog_sensor_enter_calibration(&ana_sensors); break; #endif case 'o': encoder_enter_calibration(); /* TODO; odometry_enter_calibration */ break; case 'p': hbridge_enter_calibration(&hbridges); break; #if defined(CONFIG_SD21) case 's': sd21_enter_calibration(&sd21); break; #endif case 'r': controller_enter_calibration(); break; case 'g': planner_enter_calibration(); break; case 'h': mach_calibration_usage(); break; case 'e': quit = 1; break; default: cons_printf("\n"); break; } } exit_point: cons_printf("calibration ended\n"); planner_start_game(); kos_task_exit(); }