コード例 #1
0
ファイル: proc.c プロジェクト: suond/csc159
void PrintDriver(){
	int i, code;
	char *p;
	msg_t msg;
	msg.recipient = 2;

	printing_semaphore = SemGet(0);

	outportb(LPT1_BASE+LPT_CONTROL, PC_SLCTIN);
	code = inportb(LPT1_BASE+LPT_STATUS);
	for(i=0; i<50; i++)IO_DELAY();
	outportb(LPT1_BASE+LPT_CONTROL, PC_INIT|PC_SLCTIN|PC_IRQEN);
	Sleep(1);
	for(;;){
		MsgRcv(&msg);
		cons_printf("PrintDriver (PID %d) now prints...\n",GetPid());
		p = msg.data;
		
		while(*p){
			SemWait(printing_semaphore);
			outportb(LPT1_BASE+LPT_DATA, *p);
			code = inportb(LPT1_BASE+LPT_CONTROL);
			outportb(LPT1_BASE+LPT_CONTROL, code|PC_STROBE);
			for(i=0; i<50; i++)IO_DELAY();
			outportb(LPT1_BASE+LPT_CONTROL, code);
			
			p++;
		}
	}
}
コード例 #2
0
ファイル: irq34.c プロジェクト: bicepjai/nanos
//*********************************************************************
// This serves as a shell's stdin, the terminal input/keyboard process
//*********************************************************************
//process to test the get_serial_char
void Stdin()
{
    msg_t msg;
    int term_num, shell_pid;
    char ch;
    MsgRcv(&msg); // sent from Init() for info below:

    term_num = msg.numbers[1];
    shell_pid = msg.numbers[2];
    printf("....\n");
    while(1) // loop of service, servicing shell_pid only actually
    {
        //MsgRcv(&msg); // request from shell to read terminal keyboard input
        //bzero(msg.bytes, NUM_BYTE);       // filled with zeroes (nulls)
        ch = get_serial_char();
        printf("_%c_",ch);
    }
}
コード例 #3
0
ファイル: proc.c プロジェクト: mios16/CPE159
void ConsumerProc() 
{
	int i, my_pid;
	msg_t my_msg;
	my_pid = GetPid();
	

	while(1)	//loop forever
	{
		my_msg.recipient = 0;
		MsgRcv(&my_msg);
		cons_printf("\n-- Consumer (%d) consuming data %d...\n", my_pid, my_msg.data);
		for(i = 0; i < 3333333; i++)
		{
			IO_DELAY();	//busy loop for 2 seconds
		}
	}
}
コード例 #4
0
ファイル: proc.c プロジェクト: mios16/CPE159
void PrintDriver() 
{
	int i, code;
	char *p;
	msg_t temp_msg;
	

 	printing_semaphore = SemGet(0);	//request semaphore printing_semaphore, limit 0.

	// reset printer (check printer power, cable, and paper), it will jitter
   	outportb(LPT1_BASE+LPT_CONTROL, PC_SLCTIN);   // CONTROL reg, SeLeCT INterrupt
   	code = inportb(LPT1_BASE+LPT_STATUS);         // read STATUS
   	for(i = 0; i < 50; i++)	//loop 50 times of IO_DELAY(); 		
   	{
		IO_DELAY();
  	}	        
   	outportb(LPT1_BASE+LPT_CONTROL, PC_INIT|PC_SLCTIN|PC_IRQEN); // IRQ ENable
   	Sleep(1);	//Sleep for a second, needs time resetting

	while(1)//forever loop:
	{
		temp_msg.recipient = running_pid;	
		MsgRcv(&temp_msg);//receive a message, get if msg to print *******
		p = temp_msg.data;
		cons_printf("PrintDriver (PID %d) now prints...\n", GetPid()); 	//a notification msg (match how demo runs)

    		//set p to point to start of character string in message
      		while (*p != '\0')	//"what p points to" is not null/empty/(char)0, 
         	{	
			outportb(LPT1_BASE+LPT_DATA, *p);       // write char to DATA reg
         		code = inportb(LPT1_BASE+LPT_CONTROL);  // read CONTROL reg
         		outportb(LPT1_BASE+LPT_CONTROL, code|PC_STROBE); // write CONTROL, STROBE added
         		for(i = 0; i < 50; i++)	   //do 50 times of IO_DELAY		
   			{
				IO_DELAY();
  			}	       
         		outportb(LPT1_BASE+LPT_CONTROL, code);  // send back original CONTROL
         		SemWait(printing_semaphore);//semaphore-wait on the printing semaphore

         		p++;	//move p to next character to print
      		}	
   	}	
}	
コード例 #5
0
ファイル: irq34.c プロジェクト: bicepjai/nanos
//put_serial_char test process
void Stdout()
{
    msg_t msg;
    int term_num, shell_pid;
    int i=0;

    MsgRcv(&msg); // msg provided by Init() for this process to know:
    term_num = msg.numbers[1];  // need info which terminal structure to use
    shell_pid = msg.numbers[2]; // need to know mbox ID of shell servicing
    printf("\nStd out ready");
    while(1) // service loop, servicing shell_pid only actually
    {
        //MsgRcv(&msg);
        //printf(".");
        //if(msg.numbers[3]==ECHO_OFF)
        //terminals[term_num].echo_mode=FALSE;

        put_serial_char('A'+i); // bytes is str to display
        i++;
        if(i>24) i=0;
        //MsgSnd(shell_pid, &msg);                // completion msg, content not important
    }
}
コード例 #6
0
ファイル: FileSystem.c プロジェクト: acbueff/MAARKos
// *********************************************************************
// 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 );
   }
}
コード例 #7
0
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);
         }
      }
   }
}