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:
				
		}

	}
   
}
示例#2
0
文件: proc.c 项目: suond/csc159
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);
			}	
		}
	}
}
示例#3
0
文件: proc.c 项目: mios16/CPE159
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;
			}
		}
		
		
	}
}
示例#4
0
文件: proc.c 项目: mios16/CPE159
void ProducerProc() 
{
	int i, my_pid;
	

	//////////////////phase 4
	static int count;		
	msg_t my_msg;	

	my_pid = GetPid();

	while(1)	//loop forever
	{	
		my_msg.recipient = 0;
		my_msg.data = my_pid * 100 + count++;
		cons_printf("\n++ Producer (%d) producing data %d...\n", my_pid, my_msg.data);
		for(i = 0; i < 3333333; i++)
		{
			IO_DELAY();	//busy loop for 2 seconds
		}
		MsgSnd(&my_msg);
	}
}
示例#5
0
// *********************************************************************
// File System, a process to answer queries and return file contents
// via message passing
// *********************************************************************
void FileSystem() {
   int SHELL,     // the shell that's asking FileSystem for service
       result,    // the result to be included to return to shell
       i, my_pid;

   msg_t msg;

// after all the directory entries have been assigned, then fill in the size
// of this "directory". _dir[1] is ".." which must point to parent dir
   root_dir[0].size = sizeof( root_dir );

   bin_dir[0].size = sizeof( bin_dir );
   bin_dir[1].size = root_dir[0].size;

   www_dir[0].size = sizeof( www_dir );
   www_dir[1].size = root_dir[0].size;

// mark all file descriptors as available, make sure UNUSED in FileSystem.h
   for(i=0; i<MAX_FD; i++) fd_array[i].owner = UNUSED;

   my_pid = GetPid();

   while(1) {                    // start serving requests for shells
      MsgRcv(my_pid, &msg);

      SHELL = msg.sender;        // shell's pid to return query results

      switch( msg.code ) {       // depending on what's requested
// CHK_OBJ: Shell wants to "check" obj (name in msg.data),
// and attr of it will be returned via msg in msg.data as well
         case CHK_OBJ:
            result = ChkObj( msg.data, (attr_t *)msg.data );
            break;

// OPEN_OBJ: Shell wants to open obj, an FD will be returned
// in msg.number[0], the ownership (SHELL) will be recorded
         case OPEN_OBJ:
            result = OpenObj( msg.data, SHELL, &msg.number[0] );
            break;

// READ_OBJ: Shell wants content of obj FD (msg.number[0])
// return (msg.data) and # of bytes read (msg.number[1])
         case READ_OBJ:
            result = ReadObj( msg.number[0], msg.data, SHELL, &msg.number[1] );
            break;

// CLOSE_OBJ: Shell wants to close FD (msg.number[0])
// check if the owner of FD is Shell (SHELL)
         case CLOSE_OBJ:
            result = CloseObj( msg.number[0], SHELL );
            break;

         default: // unknown code received
            result = UNKNOWN;
            cons_printf( "FileSystem: Bad code %d in message from PID #%d\n",
                         msg.code, SHELL );
      }

      msg.code = result;
      MsgSnd( SHELL, &msg );
   }
}
void Shell()
{
   int term_num, stdin_pid, stdout_pid, print_driver_pid, 
		file_system_pid;
   char login[50], passwd[50], cmd_str[50];
   msg_t msg;
   MsgRcv(&msg); 
   msg.sender = msg.nums[0];
   term_num = msg.nums[1];
   print_driver_pid = msg.nums[2];
   file_system_pid = msg.nums[3];
   msg.nums[4] = ECHO_ON;
 
   
   stdin_pid = Spawn(Stdin); 
   stdout_pid = Spawn(Stdout);	
   MsgSnd(stdin_pid, &msg);	
   MsgSnd(stdout_pid, &msg);	
   TerminalInit(term_num);
   
   while(1){
      while(1){
         MyStrCpy(msg.bytes, "login : "******"password: "******"Illegal login and password!\n");
         MsgSnd(stdout_pid, &msg);
         MsgRcv(&msg);
      }
      
      while(1){
         MyStrCpy(msg.bytes, "\nOS Alpha > ");
         MsgSnd(stdout_pid, &msg);
         MsgRcv(&msg);
         
         MsgSnd(stdin_pid, &msg);
         MsgRcv(&msg);
         MyStrCpy(cmd_str, msg.bytes);
         
         if( StrCmpLen(cmd_str, "print", 5) == 1 ){
            ShellPrint(cmd_str, print_driver_pid, file_system_pid);
            MyStrCpy(msg.bytes, cmd_str);
            MsgSnd(stdout_pid, &msg);
            MsgRcv(&msg);            
         }
         else if( StrCmp(cmd_str, "bye") == 1){
            break;
         }
         else if( StrCmp(cmd_str, "\n")){
            continue;
         }
         else if(StrCmp(cmd_str, "help")){
            ShellHelp(stdout_pid);
         }
         else if(StrCmp(cmd_str, "who")){
            ShellWho(stdout_pid);
         }
         else if(StrCmpLen(cmd_str, "dir", 3)){
            ShellDir(cmd_str, stdout_pid,file_system_pid);            
         }
         else if(StrCmpLen(cmd_str, "type", 4)){
            ShellType(cmd_str, stdout_pid, file_system_pid);
         }
         else {
            MyStrCpy(msg.bytes, "Invalid command!\n");
            MsgSnd(stdout_pid, &msg);
            MsgRcv(&msg);
         }
      }
   }
}