コード例 #1
0
ファイル: termread.c プロジェクト: UA-CSC452/usloss
//
// 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++;
        }
    }
}
コード例 #2
0
ファイル: test14.c プロジェクト: JFitzMan/UslossPhase2
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 */
コード例 #3
0
int TermReader(void *arg){
        int unit = (int) arg;
        char buffer[P2_MAX_LINE] = { 0 };
        int i = 0;
        int status;
        P1_V(termRunningSem[unit]);
        while(1){
                P2_MboxReceive(termReaderMB[unit],&status,&INT_SIZE);
                if(done != 0){
                        break;
                }
                char c = USLOSS_TERM_STAT_CHAR(status);
                if(i < P2_MAX_LINE){
                        buffer[i] = c;
                        i++;
                }
                if(c == '\n'){
                        if(i > P2_MAX_LINE){
                                i = P2_MAX_LINE;
                        }
                        P2_MboxCondSend(termLookAhead[unit],buffer,&i);
                        i = 0;
                        memset(buffer,0,MAX_LINE);
                }
        }
        return unit;
}
コード例 #4
0
ファイル: interrupt.c プロジェクト: UA-CSC452/usloss
//
// 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);
    }
}