// // Read characters from the terminals and puts them in the buffers. // When a buffer is full verify its content against the inputs. // void term_handler(int type, void *arg) { int result; int status; char ch; int unit = (int) arg; int i; // Get the device status for the terminal. result = USLOSS_DeviceInput(USLOSS_TERM_DEV, unit, &status); if (result != USLOSS_DEV_OK) { USLOSS_Console("Something is wrong with terminal %d!!", unit); USLOSS_Halt(1); } // If the status is "USLOSS_DEV_BUSY" then a character has been received. if (USLOSS_TERM_STAT_RECV(status) == USLOSS_DEV_BUSY) { ch = USLOSS_TERM_STAT_CHAR(status); // Get the characte USLOSS_Console("%d: %c\n", unit, ch); i = counts[unit]++; buffers[unit][i] = ch; if (i == NUMCHARS-1) { assert(!strncmp(inputs[unit], buffers[unit], NUMCHARS)); done++; } } }
int XXp1(char *arg) { int result, status; USLOSS_Console("XXp1(): started, calling waitDevice for terminal 1\n"); result = waitDevice(USLOSS_TERM_DEV, 1, &status); USLOSS_Console("XXp1(): after waitDevice call\n"); if ( result == -1 ) { USLOSS_Console("XXp1(): got zap'd result from waitDevice() call. "); USLOSS_Console("Should not have happened!\n"); } else if ( result == 0 ) USLOSS_Console("XXp1(): status = %d\n", status); else USLOSS_Console("XXp1(): got %d instead of -1 or 0 from waitDevice\n", result); USLOSS_Console("XXp1(): receive status for terminal 1 = %d\n", USLOSS_TERM_STAT_RECV(status)); USLOSS_Console("XXp1(): character received = %c\n", USLOSS_TERM_STAT_CHAR(status)); quit(-3); return 0; /* so gcc will not complain about its absence... */ } /* XXp1 */
int TermDriver(void *arg){ int unit = (int) arg; termReaderMB[unit] = P2_MboxCreate(1,INT_SIZE); termLookAhead[unit] = P2_MboxCreate(10,MAX_LINE); termCharToWrite[unit] = P2_MboxCreate(1,INT_SIZE); termWriteSem[unit] = P1_SemCreate(1); termRunningSem[unit] = P1_SemCreate(0); P1_Fork("Term Reader", TermReader, (void *) unit,USLOSS_MIN_STACK, 2); P1_P(termRunningSem[unit]); /*Turn on Terminal interrupts*/ int ctrl = 0; int ctrl2 = 0; ctrl = USLOSS_TERM_CTRL_RECV_INT(ctrl); USLOSS_DeviceOutput(USLOSS_TERM_DEV,unit,(void *)ctrl); P1_V(running); int status = 0; int c = 0; int result; while(1){ result = P1_WaitDevice(USLOSS_TERM_DEV,unit,&status); if(result != 0 || done != 0){ break; } if(USLOSS_TERM_STAT_RECV(status) == USLOSS_DEV_BUSY){ P2_MboxSend(termReaderMB[unit],&status,&INT_SIZE); } if(USLOSS_TERM_STAT_XMIT(status) == USLOSS_DEV_READY){ if(P2_MboxCondReceive(termCharToWrite[unit],&c,&INT_SIZE) != -2){ ctrl2 = 0; ctrl2 = USLOSS_TERM_CTRL_XMIT_INT(ctrl2); ctrl2 = USLOSS_TERM_CTRL_RECV_INT(ctrl2); ctrl2 = USLOSS_TERM_CTRL_CHAR(ctrl2, c); ctrl2 = USLOSS_TERM_CTRL_XMIT_CHAR(ctrl2); USLOSS_DeviceOutput(USLOSS_TERM_DEV, unit, (void *)ctrl2); }else{ ctrl2 = 0; ctrl2 = USLOSS_TERM_CTRL_RECV_INT(ctrl2); USLOSS_DeviceOutput(USLOSS_TERM_DEV, unit, (void *)ctrl2); } } } status = 0; P2_MboxCondSend(termReaderMB[unit],&ctrl,&status); P1_Join(&status); return unit; }
// // Read characters from terminal 0 and writes them to the USLOSS_Console. // void term_handler(int type, void *arg) { int result; int status; char ch; int unit = (int) arg; if (unit != 0) { return; } // Get the device status for terminal 0. result = USLOSS_DeviceInput(USLOSS_TERM_DEV, 0, &status); if (result != USLOSS_DEV_OK) { USLOSS_Console("Something is wrong with terminal 0!!"); USLOSS_Halt(1); } // If the status is "USLOSS_DEV_BUSY" then a character has been received. if (USLOSS_TERM_STAT_RECV(status) == USLOSS_DEV_BUSY) { ch = USLOSS_TERM_STAT_CHAR(status); // Get the character USLOSS_Console("%c", ch); } }