private static void WaitForWriteReady() { while ((PortIO.In8((ushort)(Port.Com1 + (ushort)Cmd.COM_ModemStatus)) & 0x20) == 0x0) { ; } }
public NodePort( int id, int nodeId, NodeGraph graph, string fieldName, PortIO direction = PortIO.Input, ConnectionType connectionType = ConnectionType.Multiple, ShowBackingValue showBackingValue = ShowBackingValue.Always, IEnumerable <Type> types = null, bool distinctValue = false) { this.id = id; this.nodeId = nodeId; this.graph = graph; this.fieldName = fieldName; this.direction = direction; this.connectionType = connectionType; this.showBackingValue = showBackingValue; this.distinctValue = distinctValue; portValue.SetValueTypeFilter(types); portValue.distinctValues = distinctValue; Initialize(nodeId, graph); }
/* * private bool Access_Disk(UInt32 SectorNo, uint SectorCount, byte* xData, bool IsReading) * { * if (mDevice == Device.IDE_ATAPI) * { * if (IsReading) * { * if (SectorCount != 1)// Only 1 sector we can read at a time * return false; * * // Lock up device * //Monitor.AcquireLock(this); * * // SCSI Packet Command * mATAPI_Packet[0] = (byte)Cmd.ATAPI_CMD_READ; * mATAPI_Packet[1] = 0x00; * mATAPI_Packet[2] = (byte)((SectorNo >> 24) & 0xFF); * mATAPI_Packet[3] = (byte)((SectorNo >> 16) & 0xFF); * mATAPI_Packet[4] = (byte)((SectorNo >> 8) & 0xFF); * mATAPI_Packet[5] = (byte)((SectorNo >> 0) & 0xFF); * mATAPI_Packet[6] = 0x00; * mATAPI_Packet[7] = 0x00; * mATAPI_Packet[8] = 0x00; * mATAPI_Packet[9] = (byte)(SectorCount & 0xFF); * mATAPI_Packet[10] = 0x00; * mATAPI_Packet[11] = 0x00; * * // Enable IRQ * IRQInvoked = false; * PortIO.Out8(ControlReg, 0x0); * * SelectDrive(); * * PortIO.Out8(FeatureReg, 0x0);// Tell controller that we are going to use PIO mode * * // Tell constroller the size of each buffer * PortIO.Out8(LBA1, (byte)((mBufferSize) & 0xFF));// Lower Byte of Sector Size. ATA_LBA_MID_PORT * PortIO.Out8(LBA2, (byte)((mBufferSize >> 8) & 0xFF));// Upper Byte of Sector Size. ATA_LBA_HI_PORT * * // Send Packet command * Send_SCSI_Package(); * * // Actual size that is to transferred * int size = (PortIO.In8(LBA2) << 8 | PortIO.In8(LBA1)); * * // Read the data * PortIO.Read16(DataReg, xData, size); * * WaitIRQ(); * while (((Status)PortIO.In8(StatusReg) & (Status.ATA_SR_BSY | Status.ATA_SR_DRQ)) != 0) ; * * // UnLock up device * //Monitor.ReleaseLock(this); * * return true; * } * return false; * } * else if (mDevice == Device.IDE_ATA) * { * // Lock up device * //Monitor.AcquireLock(this); * * // Disable IRQ * IRQInvoked = false; * PortIO.Out8(ControlReg, 0x2); * * ushort lba_mode, cyl; * byte head, sect; * byte[] lba_io = new byte[6]; * * // (I) Select one from LBA28, LBA48 or CHS; * if (SectorNo >= 0x10000000) * { * // LBA48: * lba_mode = 2; * lba_io[0] = (byte)((SectorNo & 0x000000FF) >> 0); * lba_io[1] = (byte)((SectorNo & 0x0000FF00) >> 8); * lba_io[2] = (byte)((SectorNo & 0x00FF0000) >> 16); * lba_io[3] = (byte)((SectorNo & 0xFF000000) >> 24); * lba_io[4] = 0; // LBA28 is integer, so 32-bits are enough to access 2TB. * lba_io[5] = 0; // LBA28 is integer, so 32-bits are enough to access 2TB. * head = 0; // Lower 4-bits of HDDEVSEL are not used here. * } * else if ((mCommandSet & (1 << 26)) != 0) * { * // LBA28: * lba_mode = 1; * lba_io[0] = (byte)((SectorNo & 0x00000FF) >> 0); * lba_io[1] = (byte)((SectorNo & 0x000FF00) >> 8); * lba_io[2] = (byte)((SectorNo & 0x0FF0000) >> 16); * lba_io[3] = 0; // These Registers are not used here. * lba_io[4] = 0; // These Registers are not used here. * lba_io[5] = 0; // These Registers are not used here. * head = (byte)((SectorNo & 0xF000000) >> 24); * } * else * { * // CHS: * lba_mode = 0; * sect = (byte)((SectorNo % 63) + 1); * cyl = (ushort)((SectorNo + 1 - sect) / (16 * 63)); * lba_io[0] = (byte)(sect & 0xFF); * lba_io[1] = (byte)((cyl >> 0) & 0xFF); * lba_io[2] = (byte)((cyl >> 8) & 0xFF); * lba_io[3] = 0; * lba_io[4] = 0; * lba_io[5] = 0; * head = (byte)((SectorNo + 1 - sect) % (16 * 63) / (63)); // Head number is written to HDDEVSEL lower 4-bits. * } * * while (((Status)PortIO.In8(StatusReg) & Status.ATA_SR_BSY) != 0) ; * * // (IV) Select Drive from the controller; * if (lba_mode == 0) * SelectDrive(head, false); * else * SelectDrive(head, true); * * // (V) Write Parameters; * if (lba_mode == 2) * { * Debug.Write("IDE: LBA_MODE=2 YET TO IMPLEMENT\n"); * throw new Exception("Yet to implement"); * } * PortIO.Out8(SectorCountReg, (byte)(SectorCount & 0xFF)); * PortIO.Out8(LBA0, lba_io[0]); * PortIO.Out8(LBA1, lba_io[1]); * PortIO.Out8(LBA2, lba_io[2]); * * // Free up this memory * Heap.Free(lba_io); * * // We are not using DMA so don't care about that * byte cmd = 0; * if (lba_mode == 0 && IsReading) cmd = (byte)Cmd.ATA_CMD_READ_PIO; * else if (lba_mode == 1 && IsReading) cmd = (byte)Cmd.ATA_CMD_READ_PIO; * else if (lba_mode == 2 && IsReading) cmd = (byte)Cmd.ATA_CMD_READ_PIO_EXT; * else if (lba_mode == 0 && !IsReading) cmd = (byte)Cmd.ATA_CMD_WRITE_PIO; * else if (lba_mode == 1 && !IsReading) cmd = (byte)Cmd.ATA_CMD_WRITE_PIO; * else if (lba_mode == 2 && !IsReading) cmd = (byte)Cmd.ATA_CMD_WRITE_PIO_EXT; * * PortIO.Out8(CommandReg, cmd); * * if (IsReading) * { * // PIO Read. * Poll(true);// Polling, set error and exit if there is. * PortIO.Read16(DataReg, xData); * } * else * { * // PIO Write. * Poll(false);// Just Poll we don't want any error * PortIO.Write16(DataReg, xData); * switch (lba_mode) * { * case 0: * case 1: * PortIO.Out8(CommandReg, (byte)Cmd.ATA_CMD_CACHE_FLUSH); * break; * case 2: * PortIO.Out8(CommandReg, (byte)Cmd.ATA_CMD_CACHE_FLUSH_EXT); * break; * }; * Poll(false); * } * * // UnLock up device * //Monitor.ReleaseLock(this); * return true; * } * return false; * }*/ internal override bool Eject() { if (mDevice == Device.IDE_ATAPI) { // SCSI Packet Command mATAPI_Packet[0] = (byte)Cmd.ATAPI_CMD_EJECT; mATAPI_Packet[1] = 0x00; mATAPI_Packet[2] = 0x00; mATAPI_Packet[3] = 0x00; mATAPI_Packet[4] = 0x02; mATAPI_Packet[5] = 0x00; mATAPI_Packet[6] = 0x00; mATAPI_Packet[7] = 0x00; mATAPI_Packet[8] = 0x00; mATAPI_Packet[9] = 0x00; mATAPI_Packet[10] = 0x00; mATAPI_Packet[11] = 0x00; // Enable IRQ; Currently IRQ is not working...so we ignore it but very important IRQInvoked = false; PortIO.Out8(ControlReg, 0x0); SelectDrive(); Send_SCSI_Package(); return(true); } return(false); }
/// <summary> /// Handles incoming packets /// </summary> private static unsafe void HandlePackets() { /** * While buffer is not empty... */ while ((PortIO.In8((ushort)(m_io_base + REG_CMD)) & CMD_BUFE) == 0) { uint offset = m_curRX % 8192; uint status = *(uint *)(m_buffer + offset); uint size = (status >> 16); status &= 0xFFFF; // Add packet byte[] buffer = new byte[size]; Memory.Memcpy(Util.ObjectToVoidPtr(buffer), &m_buffer[offset + 4], (int)size); Network.QueueReceivePacket(buffer, (int)size); Heap.Free(buffer); // Next packet and align m_curRX += 4 + size; m_curRX = (uint)((m_curRX + 3) & ~3); if (m_curRX > 8192) { m_curRX -= 8192; } // Update receive pointer PortIO.Out16((ushort)(m_io_base + REG_CAPR), (ushort)(m_curRX - 16)); } }
private static void Write(byte data) { Wait(true); PortIO.Out8(MOUSE_STATUS, MOUSE_WRITE); Wait(true); PortIO.Out8(MOUSE_PORT, data); }
/// <summary> /// Select IDE drive /// </summary> /// <param name="channel">Channel slave of master?</param> /// <param name="drive">Drive slave of master?</param> private static void selectDrive(byte channel, byte drive) { ushort io = (channel == ATA_PRIMARY) ? ATA_PRIMARY_IO : ATA_SECONDARY_IO; byte data = (drive == ATA_MASTER) ? (byte)0xA0 : (byte)0xB0; PortIO.Out8((ushort)(io + ATA_REG_DRIVE), data); }
/// <summary> /// Transmit packet /// </summary> /// <param name="bytes">The bytes</param> /// <param name="size">The size of the packet</param> public static unsafe void Transmit(byte *bytes, uint size) { /** * Max packetsize */ if (size >= 1500) { return; } m_tx_mutex.Lock(); uint current = m_curTX; m_curTX++; if (m_curTX == 4) { m_curTX = 0; } m_tx_mutex.Unlock(); // Acquire mutex on current descriptor m_mutexes[current].Lock(); // Copy data to buffer byte *bufferPtr = m_transmits[current]; Memory.Memcpy(bufferPtr, bytes, (int)size); // Set status on this TX uint status = size & 0x1FFF; PortIO.Out32((ushort)(m_io_base + REG_TSD0 + (current * 4)), status); }
private static void Wait(bool type) { int timeout = 100000; if (!type) { while (--timeout > 0) { if ((PortIO.In8(MOUSE_STATUS) & MOUSE_BBIT) != 0) { return; } } Debug.Write("[mouse]: TIMEOUT\n"); return; } else { while (--timeout > 0) { if ((PortIO.In8(MOUSE_STATUS) & MOUSE_ABIT) == 0) { return; } } Debug.Write("[mouse]: TIMEOUT\n"); return; } }
/// <summary> /// Update link status /// </summary> private static void updateLinkStatus() { byte b = PortIO.In8((ushort)(m_io_base + REG_MS)); m_linkFail = ((b & MS_LINKB) == 0); m_100mbit = ((b & MS_SPEED_10) == 0); }
/// <summary> /// Init device /// </summary> /// <param name="num"></param> private static void initDevice(int num) { if (comports[num].Address == 0) { return; } ushort port = comports[num].Address; PortIO.Out8((ushort)(port + 1), 0x00); PortIO.Out8((ushort)(port + 3), 0x80); PortIO.Out8((ushort)(port + 0), 0x01); PortIO.Out8((ushort)(port + 1), 0x00); PortIO.Out8((ushort)(port + 3), 0x03); PortIO.Out8((ushort)(port + 2), 0xC7); PortIO.Out8((ushort)(port + 4), 0x0B); PortIO.Out8((ushort)(port + 1), 0x01); comports[num].Buffer = new Fifo(256, true); Node node = new Node(); node.Flags = NodeFlags.FILE; node.Write = writeImpl; node.Read = readImpl; node.GetSize = getSizeImpl; node.Cookie = new IDCookie(num); RootPoint dev = new RootPoint(comports[num].Name, node); VFS.MountPointDevFS.AddEntry(dev); }
/// <summary> /// Unset bit on port /// </summary> /// <param name="port">Port number</param> /// <param name="bit">Bit to unset</param> private static void unsetPortBit(UHCIController uhciDev, ushort port, ushort bit) { ushort status = PortIO.In16((ushort)(uhciDev.IOBase + port)); status &= (ushort)~bit; PortIO.Out16((ushort)(uhciDev.IOBase + port), status); }
internal static void Setup() { Debug.Write("PS/2 Mouse Controller Setup\n"); MouseCycle = 0; MouseData = new byte[4]; MouseData[0] = MOUSE_MAGIC; MousePipe = new Pipe(4, 1024); IDT.RegisterInterrupt(HandleIRQ, 0x2C); Wait(true); PortIO.Out8(MOUSE_STATUS, 0xA8); Wait(true); PortIO.Out8(MOUSE_STATUS, 0x20); Wait(false); byte status = (byte)(PortIO.In8(MOUSE_PORT) | 2); Wait(true); PortIO.Out8(MOUSE_STATUS, 0x60); Wait(true); PortIO.Out8(MOUSE_PORT, status); Write(0xF6); Read(); Write(0xF4); Read(); Debug.Write("Mouse Done\n"); }
private static void Remap(byte masterStart, byte masterMask, byte slaveStart, byte slaveMask) { PortIO.Out8(PIC1_Command, ICW1_Initialization + ICW1_ICW4); PortIO.Wait(); PortIO.Out8(PIC2_Command, ICW1_Initialization + ICW1_ICW4); PortIO.Wait(); PortIO.Out8(PIC1_Data, masterStart); PortIO.Wait(); PortIO.Out8(PIC2_Data, slaveStart); PortIO.Wait(); PortIO.Out8(PIC1_Data, 4); PortIO.Wait(); PortIO.Out8(PIC2_Data, 2); PortIO.Wait(); // set modes: PortIO.Out8(PIC1_Data, ICW4_8086); PortIO.Wait(); PortIO.Out8(PIC2_Data, ICW4_8086); PortIO.Wait(); // set masks: PortIO.Out8(PIC1_Data, masterMask); PortIO.Wait(); //PortIO.Out8(PIC2_Data, slaveMask); //PortIO.Wait(); }
private static void Sleep(int cnt) { for (int i = 0; i < cnt; i++) { PortIO.In32(0x80); } }
/// <summary> /// Wait for drive to be finished /// </summary> /// <param name="port">Port IO base</param> private static void poll(uint port) { wait400ns(port); byte status; do { status = PortIO.In8((ushort)(port + ATA_REG_STATUS)); }while ((status & ATA_STATUS_BSY) > 0); while ((status & ATA_STATUS_DRQ) == 0) { status = PortIO.In8((ushort)(port + ATA_REG_STATUS)); if ((status & ATA_STATUS_DF) > 0) { Panic.DoPanic("Device fault!"); } if ((status & ATA_STATUS_ERR) > 0) { Panic.DoPanic("ERR IN ATA!!"); } } }
/// <summary> /// Read mac address from device /// </summary> private static void readMac() { for (int i = 0; i < 6; i++) { m_mac[i] = PortIO.In8((ushort)(m_io_base + i)); } }
/// <summary> /// Waits 400 ns on an ATA device /// </summary> /// <param name="port">The base IO port</param> private static void wait400ns(uint port) { PortIO.In8((ushort)(port + ATA_REG_ALTSTATUS)); PortIO.In8((ushort)(port + ATA_REG_ALTSTATUS)); PortIO.In8((ushort)(port + ATA_REG_ALTSTATUS)); PortIO.In8((ushort)(port + ATA_REG_ALTSTATUS)); }
private void UpdatePort(NodePort port, PortIO direction) { var portData = port.portData; var connectionType = portData.acceptMultipleEdges ? ConnectionType.Multiple : ConnectionType.Override; var portValue = this.UpdatePortValue(port.fieldName, direction, connectionType, ShowBackingValue.Always); var nodePort = GetPort(port.fieldName); }
/// <summary> /// IDE identify /// </summary> /// <param name="channel">Channel</param> /// <param name="drive">Slave or master?</param> /// <returns>The identification buffer</returns> private static byte[] identify(byte channel, byte drive) { // Select correct drive selectDrive(channel, drive); // Select base port for ATA drive ushort port = (channel == ATA_PRIMARY) ? ATA_PRIMARY_IO : ATA_SECONDARY_IO; // Set to first LBA PortIO.Out8((ushort)(port + ATA_REG_SECCNT), 0x00); PortIO.Out8((ushort)(port + ATA_REG_LBALO), 0x00); PortIO.Out8((ushort)(port + ATA_REG_LBAMID), 0x00); PortIO.Out8((ushort)(port + ATA_REG_LBAHI), 0x00); PortIO.Out8((ushort)(port + ATA_REG_CMD), ATA_CMD_IDENTIFY); // Check if a drive is found byte status = PortIO.In8((ushort)(port + ATA_REG_STATUS)); if (status == 0) { return(null); } // Wait until drive is not busy anymore do { status = PortIO.In8((ushort)(port + ATA_REG_STATUS)); }while ((status & ATA_STATUS_BSY) != 0); while (true) { status = PortIO.In8((ushort)(port + ATA_REG_STATUS)); if ((status & ATA_STATUS_ERR) != 0) { return(null); } if ((status & ATA_STATUS_DRQ) != 0) { break; } } // Read data from ATA drive byte[] buffer = new byte[256]; int offset = 0; for (int i = 0; i < 128; i++) { ushort shrt = PortIO.In16((ushort)(port + ATA_REG_DATA)); buffer[offset + 0] = (byte)(shrt >> 8); buffer[offset + 1] = (byte)(shrt); offset += 2; } return(buffer); }
private void Wait() { // reading status byte takes 100ns PortIO.In8(StatusReg); PortIO.In8(StatusReg); PortIO.In8(StatusReg); PortIO.In8(StatusReg); }
/// <summary> /// Prepares the PIT to sleep a couple of microseconds /// </summary> /// <param name="us">The microseconds</param> /// <returns>The sleep divisor</returns> public static uint PrepareSleep(uint us) { // Initialize PIT PortIO.Out8(PIT_CMD, PIT_DATA_2 | PIT_MODE_IOTC | PIT_ACCESS_LOHIBYTE); uint sleepDivisor = PIT_FREQUENCY / (1000000 / us); return(sleepDivisor); }
public void SetPortData(IPortData portData) { fieldName = portData.ItemName; direction = portData.Direction; connectionType = portData.ConnectionType; showBackingValue = portData.ShowBackingValue; portValue.SetValueTypeFilter(portData.ValueTypes); }
public PortData(IPortData portData) { fieldName = portData.ItemName; direction = portData.Direction; connectionType = portData.ConnectionType; showBackingValue = portData.ShowBackingValue; valueTypes = portData.ValueTypes.ToList(); }
internal static void EndOfInterrupt(int irq) { if (irq >= 40) // or untranslated IRQ >= 8 { PortIO.Out8(PIC2_Command, EOI); } PortIO.Out8(PIC1_Command, EOI); }
/// <summary> /// Read from serial port /// </summary> /// <param name="port">The serial port</param> /// <returns>Read data</returns> private static byte read(ushort port) { while (!hasReceived(port)) { CPU.HLT(); } return(PortIO.In8(port)); }
/// <summary> /// Write to serial port /// </summary> /// <param name="d">The data</param> /// <param name="port">The port</param> public static void write(byte d, ushort port) { while (isTransmitEmpty(port)) { CPU.HLT(); } PortIO.Out8(port, d); }
/// <summary> /// Moves the VGA cursor /// </summary> private static void MoveCursor() { int index = Y * 80 + X; PortIO.Out8(0x3D4, 14); PortIO.Out8(0x3D5, (byte)(index >> 8)); PortIO.Out8(0x3D4, 15); PortIO.Out8(0x3D5, (byte)(index & 0xFF)); }
public static IPortValue UpdatePortValue( this INode node, string portName, PortIO direction = PortIO.Output, bool distinctValue = false, IEnumerable <Type> types = null) { return(UpdatePortValue(node, portName, direction, ConnectionType.Multiple, ShowBackingValue.Always, types, distinctValue)); }
private void ConnectToGraphPort(INodePort sourcePort, INodePort targetPort, PortIO direction) { var source = direction == PortIO.Input ? sourcePort : targetPort; var target = direction == PortIO.Input ? targetPort : sourcePort; source.Value. Broadcast(target.Value). AddTo(LifeTime); }
public PortAttribute( PortIO direction = PortIO.Input, ConnectionType connectionType = ConnectionType.Multiple, ShowBackingValue backingValue = ShowBackingValue.Always) { this.direction = direction; this.connectionType = connectionType; this.showBackingValue = backingValue; }