Example #1
0
BOOL CParallelPort::GetECPPort(unsigned short nBaseAddress)
{
    //If the ECP is idle and the FIFO empty,
    //in the ECP's Ecp (at base address+402h),
    //bit 1 (Fifo full)=0, and bit 0 (Fifo empty)=1.
    //The first test is to see if these bits differ from the
    //corresponding bits in the control port (at base address+2).
    //If so a further test is to write 34h to the Ecr,
    //then read it back. Bit 1 is read/write and bit 0 is read-only.
    //If the value read is 35h, the port is an ECP.
    BOOL bSuccess = FALSE;

    unsigned short nEcrAddress = (unsigned short)(nBaseAddress+0x402);
    int nEcrData = _inp(nEcrAddress);

    //Read bits 0 and 1 and control port bit 1
    int nEcrBit0 = nEcrData & 0x1;
    int nEcrBit1 = (nEcrData & 0x2) >> 1;
    int nControlBit1 = (ReadControl(nBaseAddress) & 0x2) >> 1;

    if (nEcrBit0 == 1 && nEcrBit1 == 0)
    {
        //Compare control bit 1 to ECR bit 1
        //Toggle the control bit if necessary
        //to be sure the two registers are different.
        if (nControlBit1 == 0)
        {
            WriteControl(nBaseAddress, 0xF);
            nControlBit1 = (ReadControl(nBaseAddress) & 0x2) >> 1;
        }

        if (nEcrBit1 != nControlBit1)
        {
            int nOriginalEcrData = nEcrData;
            _outp(nEcrAddress, 0x34);
            if (_inp(nEcrAddress) == 0x35)
                bSuccess = TRUE;

            //Restore the ECR to its original value
            _outp(nEcrAddress, nOriginalEcrData);
        }
    }
Example #2
0
void Selector::Run()
{
	while(m_loop)
	{
		struct timespec timeout;
		fd_set freads = m_freads;
		fd_set fwrites = m_fwrites;
		fd_set fexcept = m_fexcept;
		CalcTimeout(&timeout);
		int ret = pselect(m_maxfd + 1, &freads, &fwrites, &fexcept, &timeout, NULL);
		if (ret < 0)
		{
			switch(errno)
			{
				case EINTR:
					continue;
					break;
				case EBADF: /* It is possible to have a bad fd inside the set because it just changed after read took a copy of the set */
					m_err_ebadf++;
					continue;
					break;
				default:
					abort();
					break;
			}
		}

		do {
			ScopedLock lock = ScopedLock(&m_mutex);
			m_modified = false;
			//Check fd_set's
			for(std::map<int, ISelectable *>::iterator it = m_map.begin(); it != m_map.end(); it++)
			{
				int fd = it->first;
				bool work = false;
				if (FD_ISSET(fd, &freads))
				{
					it->second->DoRead(this);
					if (m_modified)
						goto skip_to_end;
					work = true;
				}
				if (FD_ISSET(fd, &fwrites))
				{
					it->second->DoWrite(this);
					if (m_modified)
						goto skip_to_end;
					work = true;
				}
				if (FD_ISSET(fd, &fexcept))
				{
					it->second->DoExcept(this);
					if (m_modified)
						goto skip_to_end;
					work = true;
				}

				if (work)
					UpdateMap(fd);
			}
					
			struct timespec now;
			if (clock_gettime(CLOCK_MONOTONIC, &now) < 0)
				abort();

			for(std::map<int, struct timespec>::iterator it = m_timeout.begin(); it != m_timeout.end(); it++)
			{
				if (Time::IsLess(&it->second, &now))
				{
					m_map[it->first]->DoTimeout(this);
					if (m_modified)
						goto skip_to_end;
					UpdateMap(it->first);
				}
			}

		} while(0);
skip_to_end:
		ReadControl();
	}
}
	void Device::ReadControl(u8 type, u8 req, u16 value, u16 index, ByteArray &data, int timeout)
	{ ReadControl(_dev, type, req, value, index, data, timeout); }