ideidcommand.java

来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 121 行

JAVA
121
字号
/*
 * $Id: IDEIdCommand.java,v 1.1 2003/11/25 11:50:41 epr Exp $
 */
package org.jnode.driver.ide;

import org.jnode.util.NumberUtils;


/**
 * @author epr
 */
public class IDEIdCommand extends IDECommand {

	/** The result of this command */
	private IDEDriveDescriptor result;
	/** Should an ATAP ID command be issued(true) or a normal ID command (false) */
	private final boolean atapiID;
	/** Read data */
	private final int[] data = new int[256];
	/** Did IDENTIFY DEVICE return a packet response signature? */
	private boolean packetResponse;
	
	/**
	 * Create a new instance
	 * @param taskfile The taskfile to use. 0 for IDE0, 1 for IDE1
	 * @param master Command intended for master (true) or slave (false)
	 * @param atapiID  Should an ATAP ID command be issued(true) or a normal ID command (false) 
	 * @throws IllegalArgumentException Invalid argument
	 */
	protected IDEIdCommand(int taskfile, boolean master, boolean atapiID) 
	throws IllegalArgumentException {
		super(taskfile, master);
		this.atapiID = atapiID;
	}

	/**
	 * @see org.jnode.driver.ide.IDECommand#setup(IDEBus)
	 */
	protected void setup(IDEBus ide) {
		if (master) {
			ide.setSelectReg(SEL_BLANK | SEL_DRIVE_MASTER);
		} else {
			ide.setSelectReg(SEL_BLANK | SEL_DRIVE_SLAVE);
		}
		final int command;
		if (atapiID) {
			//ide.setFeatureReg(0);
			command = CMD_PIDENTIFY;
		} else {
			command = CMD_IDENTIFY;
		}
		ide.setCommandReg(command);
	}

	/**
	 * @see org.jnode.driver.ide.IDECommand#handleIRQ(IDEBus)
	 */
	protected void handleIRQ(IDEBus ide) {
		final int[] data = this.data;
		final int state = ide.getStatusReg();
		if ((state & ST_ERROR) != 0) {
			// Error in ID command.
			final int error = ide.getErrorReg();
			if ((error & ERR_ABORT) != 0) {
				final int sectCount = ide.getSectorCountReg();
				final int lbaLow = ide.getLbaLowReg();
				final int lbaMid = ide.getLbaMidReg();
				final int lbaHigh = ide.getLbaHighReg();
				ide.getSelectReg();
				if ((sectCount == 0x01) && (lbaLow == 0x01) && 
				    (lbaMid == 0x14) && (lbaHigh == 0xEB)) {
				    packetResponse = true;
				} else {
					packetResponse = false;
				}
				log.debug("Abort " + (packetResponse ? "packet" : "error"));
			} else {
				log.debug("Error " + NumberUtils.hex(error));				
			}
				
			result = null;
			notifyFinished();
		} else if ((state & ST_BUSY) == 0) { 
			if ((state & ST_DATA_REQUEST) != 0) {
				// Data is ready to read
				for (int i = 0; i < 256; i++) {
					data[i] = ide.getDataReg();
				}
				result = new IDEDriveDescriptor(data, atapiID);
			} else {
				// Not busy, but still no data ready??? strange
				//log.debug("irq:!drq");
				result = null;
			}
			notifyFinished();
		} else {
			// Controller is still busy, wait for the following IRQ.
			log.debug("irq:busy st=" + NumberUtils.hex(state) +
			 				     "lbal=" + NumberUtils.hex(ide.getLbaLowReg()) + 
			 				     "lbam=" + NumberUtils.hex(ide.getLbaMidReg()) + 
			 				     "lbah=" + NumberUtils.hex(ide.getLbaHighReg()) + 
			 				     "select=" + NumberUtils.hex(ide.getSelectReg()));
		}
	}

	/**
	 * The result of this command. Only valid when <code>isFinished</code>
	 * returns <code>true</code>.
	 */
	public IDEDriveDescriptor getResult() {
		return result;
	}
	
	/**
	 * Did IDENTIFY DEVICE return a packet response signature?
	 */
	public boolean isPacketResponse() {
		return packetResponse;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?