Beispiel #1
0
/*******************************************************************************
 * \do_latex
 *
 * \name floppy\\_init
 * \proto void floppy\\_init()
 * 
 * \desc This is where the floppy driver is initilized and where the floppy device(s)
 * \desc are registered with the system.
 * 
 * \date November 27, 2004
 * *****************************************************************************/
void floppy_init()
{
	DEBUG_MSG(("Initializing floppy controller"));
	process_t *floppy_timer_process;
	int floppy_count = 0;
	unsigned char c;
	unsigned char a;
	unsigned char b;
	
	outportb(0x70, 0x10);
	c = inportb(0x71);
	
	a = c >> 4; // get the high nibble
	b = c & 0xF; // get the low nibble by ANDing out the high nibble
	
	if (a > 0)
	{
		floppy_count++;
		device_register("fd0", floppy_block_read, floppy_block_write );
	}
	
	if (b > 0) {
		ERROR_MSG(("only one floppy disk supported!"));
	}

	floppy_dma_address = mm_physical_page_alloc(MM_TYPE_DMA);
	
	idt_interrupt_add(0x26, floppy_isr, 0);
	irq_umask(IRQ_6);
	floppy_timer_process = multitasking_process_new(floppy_timer, "floppy timer", PRIORITY_LOW, PROCESS_DRIVER);
	multitasking_process_add(floppy_timer_process);

	floppy_reset();
	DEBUG_MSG(("Initialized floppy controller"));
}
Beispiel #2
0
static void __init floppy_init(void)
{
	uint8_t v;

	/* Install handler for IRQ6 */
	set_irq_handler(6, floppy_isr, NULL);
	irq_on(6);

	dprintk("floppy: resetting floppy controllers\n");
	floppy_reset(dprts);

	floppy_send(dprts, CMD_VERSION);
	v = floppy_recv(dprts);
	if ( v == 0x80 ) {
		printk("floppy: NEC765 controller detected\n");
	}else{
		printk("floppy: enhanced controller detected (0x%x)\n", v);
	}

	/* Reset disk-change flag */
	inb(dprts->dir);

	blkdev_add(&floppy0);

}
Beispiel #3
0
void init_floppy() {
    floppy_motor = 0;
    floppy_C = 0;
    cli();
    init_floppy_DMA();
    write_idt_entry(0x36,&floppy_interrupt,INTERRUPT_GATE|INTERRUPT_NOT_FOR_PAGING);
    sti();
    floppy_reset();
    add_timer(9,floppy_motor_enabled,0);
    //Delay 500ms
}
Beispiel #4
0
void floppy_init()
{
	floppy_irq      = 0;
	floppy_motor_on = 0;
	
	floppy_motorOn();
	floppy_reset();
	
	//dma initialisieren
	outb(0x0a, 0x06);
	outb(0x0c, 0xff);
	//outb(0x04, );
}
Beispiel #5
0
/*******************************************************************************
 * bool floppy_log_disk(drive_geometry *g)
 * 
 * This checks the drive geometry.  This should be called after every disk change
 * 
 * Date:	December 31, 2004
 * *****************************************************************************/
bool floppy_log_disk(drive_geometry *g)
{
	///get the floppy drive into a known condition
	floppy_reset();
	
	///assume that the disk is 1.6MB and try to read block #21 on first track
	floppy_geometry.heads = DG168_HEADS;
	floppy_geometry.tracks = DG168_TRACKS;
	floppy_geometry.spt = DG168_SPT;
	
	if (floppy_block_read(20, NULL, 1))
	{
		///this disk is 1.68MB
		if (g)
		{
			g->heads = floppy_geometry.heads;
			g->tracks = floppy_geometry.tracks;
			g->spt = floppy_geometry.spt;
		}
		return true;
	}
	
	///this disk is not 1.68MB
	///it might be a 1.44MB disk- we'll try reading block #18 on the first track
	floppy_geometry.heads = DG144_HEADS;
	floppy_geometry.tracks = DG144_TRACKS;
	floppy_geometry.spt = DG144_SPT;
	
	if (floppy_block_read(17, NULL, 1))
	{
		if (g)
		{
			g->heads = floppy_geometry.heads;
			g->tracks = floppy_geometry.tracks;
			g->spt = floppy_geometry.spt;
		}
		return true;
	}
	
	///if it reaches this point, then the floppy isn't a 1.68MB disk
	///or a 1.44MB disk.  We don't support it.
	
	return false;
}
Beispiel #6
0
/*******************************************************************************
 * bool floppy_rw(int block, unsigned char *blockbuff, 
 * 					unsigned char read, unsigned long nosectors)
 * 
 * Since the read and write to a floppy disk is not that much different, most of
 * the code is the same.  The only difference is dependent on what the 'read' 
 * variable is set as.
 * 
 * Parameters:
 * 	1) int block
 * 		This is the block that we want to read.
 * 	2) unsigned char *blockbuff
 * 		This is the buffer that we want it read into or written out to.  The size 
 * 		of this buffer should be 512 * nosectors, as each sector read in is 512 
 * 		bytes
 * 	3) unsigned char read
 * 		Are we going to read or write to this block.
 * 	4) unsigned long nosectors
 * 		The number of sectors that we want to be read in.
 * 
 * Return value:
 * 	This returns where or not the read/write was successfull.
 * 
 * Date:	December 31, 2004
 * *****************************************************************************/
bool floppy_rw(int block, unsigned char *blockbuff, unsigned char read, unsigned long nosectors)
{
	int head;
	int track;
	int sector;
	int tries;
	int copycount=0;
	unsigned char *p_track_buffer = (unsigned char*)floppy_dma_address;
	unsigned char *p_block_buffer = blockbuff;
	
	///convert logical address into physical address
	floppy_block2hts(block , &head, &track, &sector);
	
	///start the floppy motor
	floppy_motor_start();
	
	if (!read && blockbuff)
		///copy data from the data buffer into the track buffer
		for (copycount=0; copycount<(nosectors*512); copycount++)
			*(p_track_buffer++) = *(p_block_buffer++);
	
	for (tries = 0; tries < 3; tries++)
	{
		///check for disk change
		if (inportb(FDC_DIR) & 0x80)
		{
			floppy_dchange = true;
			floppy_seek(1);
			floppy_recalibrate();
			floppy_motor_stop();
			ERROR_MSG(("FDC: Disk change detected. Trying again."));
			return floppy_rw(block, blockbuff, read, nosectors);
		}
		
		///move head to the right track
		if (!floppy_seek(track))
		{
			floppy_motor_stop();
			ERROR_MSG(("FDC: Seek error"));
			return false;
		}
		
		///program data rate (500Kb/s)
		outportb(FDC_CCR, 0);
		
		///send command
		if (read)
		{
			dma_xfer(2, (unsigned long)floppy_dma_address, nosectors*512, false);
			floppy_sendbyte(CMD_READ);
		} else {
			dma_xfer(2, (unsigned long)floppy_dma_address, nosectors*512, true);
			floppy_sendbyte(CMD_WRITE);
		}
		
		floppy_sendbyte(head << 2);
		floppy_sendbyte(track);
		floppy_sendbyte(head);
		floppy_sendbyte(sector);
		floppy_sendbyte(2);
		floppy_sendbyte(floppy_geometry.spt);
		
		if (floppy_geometry.spt == DG144_SPT)
			floppy_sendbyte(DG144_GAP3RW);
		else
			floppy_sendbyte(DG168_GAP3RW);
		
		floppy_sendbyte(0xff);
		
		///wait for commmand completion
		if (!floppy_wait(true)) {
			ERROR_MSG(("Timed out, trying operation again after reset"));
			floppy_reset();
			return floppy_rw(block, blockbuff, read, nosectors);
		}
		
		///let's see if the transfer worked
		if ((floppy_status[0] & 0xC0) == 0) break;
		
		///it didn't work.  try again
		floppy_recalibrate();
	}
	
	floppy_motor_stop();
	
	if (read && blockbuff)
	{
		///copy data from track buffer into data buffer
		p_block_buffer = blockbuff;
		p_track_buffer = (unsigned char *)floppy_dma_address;
		for (copycount = 0; copycount <(nosectors*512); copycount++)
		{
			*p_block_buffer = *p_track_buffer;
			p_block_buffer++;
			p_track_buffer++;
		}
	}
	
	return (tries != 3);
}