예제 #1
0
//write a 512 byte sector to the current track
int P2_DiskWrite(int unit, int track, int first, int sectors, void *buffer) {
	if(permissionCheck() || track < 0 || track >= DISK_TRACKS[unit] || first < 0 || 
	first > 15 || unit < 0 || unit > 1 || sectors <= 0){
                return -1;
        }
	P1_P(diskSem[unit]);
	int status = 0;
	 //first make a device request struct for a seek
        USLOSS_DeviceRequest seekRequest;
        seekRequest.opr = USLOSS_DISK_SEEK;
        seekRequest.reg1 = (void *)track; //track number where the r/w head should be moved

        //make device request struct for write
        USLOSS_DeviceRequest writeRequest;
        writeRequest.opr = USLOSS_DISK_WRITE;

        USLOSS_DeviceOutput(USLOSS_DISK_DEV,unit,&seekRequest);
	P1_WaitDevice(USLOSS_DISK_DEV,unit,&status);
	int i = 0;
	while (sectors != 0 && status == 0)  {
		writeRequest.reg1 = (void *)first;
		writeRequest.reg2 = buffer + (i * USLOSS_DISK_SECTOR_SIZE);
		USLOSS_DeviceOutput(USLOSS_DISK_DEV,unit,&writeRequest);
		P1_WaitDevice(USLOSS_DISK_DEV,unit,&status);
		if (status == USLOSS_DEV_ERROR) {
                        USLOSS_Console("Error with disk write request, unit %d, track %d, sector %d\n",unit, track, first);
                }
                first++;
                sectors--;
		if (first == 16 && sectors > 0) {
                        //need to move on to next track.
                        track++;
                        seekRequest.reg1 = (void *) track;
                        USLOSS_DeviceOutput(USLOSS_DISK_DEV,unit,&seekRequest);
                        P1_WaitDevice(USLOSS_DISK_DEV,unit,&status);
                        first = 0; //set first to 0 sector of new track
                }
		writeRequest.reg1 = (void *)first;
		i++;
	}
	P1_V(diskSem[unit]);	
	return status;
}
예제 #2
0
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;
}
예제 #3
0
/*P2_DiskSize() returns info about the size of the disk indicated by unit*/
int P2_DiskSize(int unit, int *sector, int *track, int *disk) {
	if(permissionCheck() || unit < 0 || unit > 1){
                return -1;
        }
	P1_P(diskSem[unit]);
	int status;
	*sector = USLOSS_DISK_SECTOR_SIZE;
	*track = USLOSS_DISK_TRACK_SIZE;
	// Make device request for finding number of tracks in disk
	USLOSS_DeviceRequest request;
 	request.opr = USLOSS_DISK_TRACKS;
	//reg1 contains pointer to integer where number of disk tracks will be stored
	request.reg1 = disk;
	USLOSS_DeviceOutput(USLOSS_DISK_DEV,unit,&request);
	P1_WaitDevice(USLOSS_DISK_DEV,unit,&status);
	P1_V(diskSem[unit]);
	return 0;
}
예제 #4
0
파일: test11.c 프로젝트: TannerKoch/CS452
int P2_Startup(void *arg){
  
  USLOSS_Console(" \n---------Starting Test 11 ----------\n");
  int status;
  int r;
  int temp;
  int i=0;
  
  while(i<10){
    //USLOSS_Console("before: %d\t", temp=USLOSS_Clock());
	++i;
    temp=USLOSS_Clock();
    r=P1_WaitDevice(USLOSS_CLOCK_DEV, 0, &status);
    USLOSS_Console("wait period : %d\n", USLOSS_Clock()-temp);
  }
 
  USLOSS_Console(" ---------Ending Test 11 ----------\n");
  return 0;
}
예제 #5
0
static int ClockDriver(void *arg) {
	interruptsOn();
	int result;
	int status;
	int rc = 0;
	/*
	 * Let the parent know we are running and enable interrupts.
	 */
	P1_V(running);
	while (1) {
		result = P1_WaitDevice(USLOSS_CLOCK_DEV, 0, &status);
		if (result != 0) {
			rc = 1;
			goto done;
		}
		/*
		 * Compute the current time and wake up any processes
		 * whose time has come.
		 */
		wakeUpProcesses();
	}
	wakeUpProcesses();
	done: return rc;
}