Esempio n. 1
0
void floppy_reset(void)
{
	int a;

	prepare_wait_irq(FLOPPY_IRQ);
	outportb((FLOPPY_FIRST + DIGITAL_OUTPUT_REGISTER), 0x00); /*disable controller*/
	kwait(0, 1000 * 50);
	outportb((FLOPPY_FIRST + DIGITAL_OUTPUT_REGISTER), 0x0c); /*enable controller*/

	kprintf("FDD: Reseted controller\n");
	wait_irq(FLOPPY_IRQ);
	kprintf("FDD: Waited for it\n");

	for(a = 0; a < 4; a++) {
		floppy_sense_interrupt();
	}

	outportb(FLOPPY_FIRST + CONFIGURATION_CONTROL_REGISTER, 0);

	floppy_configure();

	if (floppy_drives[0].type) {
		floppy_calibrate(0);
	}
	if (floppy_drives[1].type) {
		floppy_calibrate(1);
	}
	kprintf("FDD: Calibrated drives\n");
}
Esempio n. 2
0
int init_floppy()
{
	int drive = floppy_get_current_drive();
	uint8_t drive_type = 0;
	uint8_t CCR;
	
	/* On vérifie qu'on a bien un controleur standard, sinon on affiche un warning */
	if(floppy_get_version() != 0x90)
		kerr("WARNING: Floppy driver may not work with 0x%x controler.", floppy_get_version());

	floppy_reset_irq();
	
	// On fait le reset du controler + activation DMA/IRQ
	outb(0x00, FLOPPY_BASE + FLOPPY_DOR);
	outb(0x0C, FLOPPY_BASE + FLOPPY_DOR);
	
	floppy_wait_irq();
	floppy_sense_interrupt(NULL,NULL);
	
	// On regle la vitesse de transfert en fonction du type de disquette
	drive_type = floppy_get_type(drive);
	switch(drive_type)
	{
		case 1: // 300 kbps (01)
		case 3:
			CCR = 0x01;
			break;
			
		case 2: // 500 kbps (00)	
		case 4:
		
			CCR = 0x00;
			break;
		case 5: // 1 Mbps (11)
			CCR= 0x03;
			break;
			
		default:
			CCR = 0x00; // choix arbitraire btw
			break;
	}
	outb(CCR, FLOPPY_BASE + FLOPPY_CCR);
	
	
/* Totalement hardcodé et moche à fortiori*/
	floppy_write_command(SPECIFY);
    floppy_write_command(0xdf); /* steprate = 3ms, unload time = 240ms */
    floppy_write_command(0x02); /* load time = 16ms, no-DMA = 0 */
/* *************************************** */
	
	// On calibre le lecteur
	if(floppy_calibrate()) return -1;
	return 0;
}
Esempio n. 3
0
void io_init() {
    uint8_t st, cy;
    floppy_irq = false;
    _out8(DIGITAL_OUTPUT_REGISTER, 0x00); // reset
    _out8(DIGITAL_OUTPUT_REGISTER, 0x0c); // DMA and normal mode
    wait_floppy_irq();

    for(uint32_t index_1 = 0; index_1 < 4; index_1++)
        floppy_check_int(&st, &cy);

    _out8(CONFIGURATION_CONTROL_REGISTER, 0x00); // rotate speed 500Kbps
    // configure implied seek on, FIFO on, drive polling mode off, threshold = 8, precompensation 0
    floppy_specify(13, 1, 0xf, true);

    floppy_calibrate(0);
    return;
}
Esempio n. 4
0
File: floppy.c Progetto: n3on/madOS
void floppy_reset()
{
	outb(FP_DIGITAL_OUTPUT_REGISTER,0x00);
	outb(FP_DIGITAL_OUTPUT_REGISTER,0x0C);	
	floppy_waitIrq();
	floppy_out(FC_SENSE_INTERRUPT);
	floppy_read(FP_STATUS_REGISTER_A);
	floppy_read(FP_STATUS_REGISTER_A); 
	
	//geschwindigkeit auf 500 kb/s setzen
	outb(FP_CONFIGURATION_CONTROL_REGISTER, 0x00);
	
	floppy_out(FC_SPECIFY);
	floppy_out(0xdf);
	floppy_out(0x02);
	
	floppy_calibrate();
	
	kprint("\nFloppy zurueckgesetzt\n");
}
Esempio n. 5
0
int floppy_rw_sector(uint_t drive, uint8_t sector, uint8_t head, uint8_t cylinder, uintptr_t buffer, int write)
{
	int a;
alku:
	if (drive >= MAX_DRIVES || !floppy_drives[drive].type) {
		return -1;
	}

	if (inportb(FLOPPY_FIRST + DIGITAL_INPUT_REGISTER) & 0x80) {
		/* disk was changed */
		floppy_seek_track(drive, 1);
		floppy_calibrate(drive);
		floppy_motor_off(drive);
		if (inportb(FLOPPY_FIRST + DIGITAL_INPUT_REGISTER) & 0x80) {
			kprintf("FDD: No floppy in fd%u\n", drive);
			return -2;
		} else {
			kprintf("FDD: Floppy changed, trying again...\n");
			goto alku;
		}
	}

	if (floppy_seek_track(drive, cylinder))
	if (floppy_seek_track(drive, cylinder))
	if (floppy_seek_track(drive, cylinder)) {
		return -1; /* three seeks? */
	}

	/* floppy_seek_track actually starts motor already, but... */
	floppy_motor_on(drive);

	if (!(inportb(FLOPPY_FIRST + MAIN_STATUS_REGISTER) & 0x20)) {
		panic("Non-dma floppy transfer?\n");
	}

	/* block size */
	floppy_init_dma(buffer, 512, write);

	kwait(0, 1000 * floppy_params.head_settle_time);
	floppy_wait();

	prepare_wait_irq(FLOPPY_IRQ);
	floppy_command(write ? WRITE_DATA : READ_DATA);
	floppy_command((head << 2) | drive);
	floppy_command(cylinder);
	floppy_command(head);
	floppy_command(sector);
	floppy_command(floppy_params.bytes_per_sector);  /*sector size = 128*2^size*/
	floppy_command(floppy_params.sectors_per_track); /*last sector*/
	floppy_command(floppy_params.gap_length);        /*27 default gap3 value*/
	floppy_command(floppy_params.data_length);       /*default value for data length*/

	//kprintf("FDD: BPS: %u, SPT: %u, GL: %u, DL: %u\n", floppy_params.bytes_per_sector, floppy_params.sectors_per_track, floppy_params.gap_length, floppy_params.data_length);

	wait_irq(FLOPPY_IRQ);
	//kprintf("We got values ");
	for (a = 0; a < 7; a++) { /* TODO: Put these values somewhere? */
		floppy_wait_data();
		inportb(FLOPPY_FIRST + DATA_FIFO);
		//kprintf("%d ", inportb(FLOPPY_FIRST + DATA_FIFO));
	}
	//kprintf(" from floppy controller after reading\n");
	floppy_prepare_motor_off(drive);
	return 0;
}