Ejemplo n.º 1
0
void resetFDD()
{
	/*
	1. Bit 2 (value = 4) in the DOR: Save the current/"original" value of the DOR, write a 0 to the DOR, wait 4 microseconds, then write the original value (bit 2 is always set) back to the DOR.
   	2. Wait for the resulting IRQ6 (unless you have IRQs turned off in the DOR)
   	3. If (and only if) drive polling mode is turned on, send 4 Sense Interrupt commands (required).
   	4. If your OS/driver never sent a Lock command, then you probably need to send a new Configure command (the fifo settings were lost in the reset).
   	5. Do a Drive Select procedure for the next drive to be accessed. */

	enum FDCREG reg;
	
	uint8_t dor = inb( reg=DOR );
	outb( reg=DOR, 0 );
	sleepTicks(1);
	
	//DEBUG_MSG("DOR = %d", dor);
	dor |= 0x04; //.........................................To set the RESET bit
	//dor &= 0xFB; //To set the  DMA  bit
	//DEBUG_MSG("DOR = %d", dor);
	///modify dor
	outb( reg=DOR, dor );
	
	if(fdc.drive_polling_mode);
	if (!fdc.lock)
	{
		configure(fdc.drive_polling_mode, fdc.FIFO, fdc.threshold, fdc.implied_seek, fdc.precompensation);
	}
}
Ejemplo n.º 2
0
uint8_t read_data()
{
	enum FDCREG reg;
	uint8_t timeout;
	for(timeout = 0; timeout < 200; timeout++)
	{
		if((inb(reg = MSR) & 0xC0) == 0xC0)
			return inb(reg=DATA_FIFO);
		sleepTicks(1);
	}
	return 0;
}
Ejemplo n.º 3
0
/*
      #     #               ###    ###
      #                    #   #  #
      #     #   ###   ##   #   #   ##
      #     #  #   #  # #  #   #     #
      ####  #   ###   # #   ###   ###
                   Floppy
*/
void sendData(uint8_t data)
{
	uint8_t timeout;
	enum FDCREG reg;
	for (timeout = 0; timeout < 200; timeout++)
	{
		if ((inb(reg=MSR) & 0xC0) == 0x80)
		{
			outb(reg=DATA_FIFO, data);
			return;
		}
		sleepTicks(5);  //5ms warten vor dem nächsten Versuch
	}
}
Ejemplo n.º 4
0
void recalibrateFDC()
{
	setMotor(true);
	enum FDCREG reg;
	enum FDCCMD cmd;
	/*
 	 * Recalibrate command = 0x7
 	 * First parameter byte = drive number = 0 to 3.
 	 * No result bytes.
	 * The interrupt may take up to 3 seconds to arrive, so use a long timeout. 
	 */
	if (!testMSR())
	{	//We must reset and restart. Something wrong...
		resetFDD();
		recalibrateFDC();
	}
	
	outb( reg=DATA_FIFO, cmd=RECALIBRATE );
	sendPara( fdc.acDrive );
	sleepTicks(10); //TODO Better sleep here
}
Ejemplo n.º 5
0
void *carAssistant(void *car){
	
	//Variable which will be used to store the time
	clock_t t;
	
	//Stores the car's information in new variables for easier handling
	struct carAssistInfo *info = (struct carInfo *) car;
	int idCar = info->idCar;
	int parkingTime = info->parkingTime;
	
	int messagelen;
	char message[100];
	
	//Creates a new fifo for the car using the car's unique ID
	char * fifoCar = malloc (sizeof (char));
	sprintf(fifoCar, "car%d", idCar);
	mkfifo(fifoCar,FIFO_PERMISSIONS);	

	//Opens the car's fifo for writing
	int fdA = open(fifoCar, O_WRONLY);
	
	//Locks the access to a critical section
	pthread_mutex_lock(&nLugaresLock); 
	
	//If the park is not full
	if(n_lugares> 0)
	{
		//If there is only one spot left the car enters and the park is now full
		if(n_lugares == 1){
			
			//Registers current time to print in log
			t = clock();
			pthread_mutex_lock(&nLugLock); 
			
			//Registers that there is one more car in the park
			nLug++;
			
			//Prints to log
			printToLog (t, nLug, idCar, "cheio");
			pthread_mutex_unlock(&nLugLock); 
		}else{
			
			//Registers current time to print in log
			t = clock();
			pthread_mutex_lock(&nLugLock); 
			
			//Registers that there is one more car in the park
			nLug++;
			
			//Prints to log
			printToLog (t, nLug, idCar, "estacionamento");
			pthread_mutex_unlock(&nLugLock); 
		}
		
		//Registers that there is one less available spot in the park
		n_lugares--;
		
		sprintf(message,"Entrou!");
		messagelen=strlen(message)+1;
		
		//Transmits to the vehicle tracker thread that the car has entered
		write(fdA,message,messagelen);
		pthread_mutex_unlock(&nLugaresLock);
		
		//The car is parked of the amount that it wants to be
		sleepTicks(parkingTime);

		
		
		pthread_mutex_lock(&nLugaresLock); 
		
		//The car leaves and there is another spot in the park
		n_lugares++; 
		pthread_mutex_unlock(&nLugaresLock);
		pthread_mutex_lock(&nLugLock);
		
		//Registers current time
		t = clock();
		nLug--;
		
		//If the park is opened, the car leaves, else prints that it is closed and won't receive any more cars
		if(opened==0){
			printToLog (t, nLug, idCar, "encerrado");
		}else{
			printToLog (t, nLug, idCar, "saida");
		}
		pthread_mutex_unlock(&nLugLock); 
		
		//Writes to the car's fifo that it left
		sprintf(message,"Saiu!");
		write(fdA,message,messagelen);
		close(fdA);
	}
	//If the park is full:
	else
	{
		
		sprintf(message,"Cheio!");
		messagelen=strlen(message)+1;
		write(fdA,message,messagelen);
		pthread_mutex_unlock(&nLugaresLock);
		close(fdA);
	}
}