⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmos.java

📁 纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统
💻 JAVA
字号:
/*
 * $Id: CMOS.java,v 1.1 2003/11/25 11:42:34 epr Exp $
 */
package org.jnode.driver.cmos.def;

import javax.naming.NameNotFoundException;

import org.jnode.driver.cmos.CMOSConstants;
import org.jnode.naming.InitialNaming;
import org.jnode.system.IOResource;
import org.jnode.system.ResourceManager;
import org.jnode.system.ResourceNotFreeException;
import org.jnode.system.ResourceOwner;

/**
 * @author epr
 */
final class CMOS implements CMOSConstants {

	/** CMOS I/O ports */
	private final IOResource cmosIO;

	/**
	 * Create a new instance
	 * @param owner
	 * @throws ResourceNotFreeException
	 */	
	public CMOS(ResourceOwner owner) 
	throws ResourceNotFreeException {
		try {
			final ResourceManager rm = (ResourceManager)InitialNaming.lookup(ResourceManager.NAME);
			this.cmosIO = rm.claimIOResource(owner, CMOS_FIRST_PORT, CMOS_LAST_PORT - CMOS_FIRST_PORT + 1);
		} catch (NameNotFoundException ex) {
			throw new ResourceNotFreeException("Cannot find ResourceManager", ex);
		}
	}

	/**
	 * Release all resources
	 */	
	public void release() {
		cmosIO.release();
	}
	
	/**
	 * Gets a register from the CMOS data
	 * @param register [0..63]
	 * @return
	 */
	public synchronized int getRegister(int register) {
		// We must make sure that bit 7 of the address data is not
		// changed, since it controls the NMI.
		int addr = cmosIO.inPortByte(PRW8_ADDRESS);
		addr &= 0xE0; /* Clear lower 5 bits */
		addr |= (register & 0x1F);
		cmosIO.outPortByte(PRW8_ADDRESS, addr);
		return cmosIO.inPortByte(PRW8_DATA);
	}

	/**
	 * Sets a register from the CMOS data
	 * @param register [0..63]
	 * @param value 
	 */
	public synchronized void setRegister(int register, int value) {
		// We must make sure that bit 7 of the address data is not
		// changed, since it controls the NMI.
		int addr = cmosIO.inPortByte(PRW8_ADDRESS);
		addr &= 0xE0; /* Clear lower 5 bits */
		addr |= (register & 0x1F);
		cmosIO.outPortByte(PRW8_ADDRESS, addr);
		cmosIO.outPortByte(PRW8_DATA, value);
	}


}

⌨️ 快捷键说明

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