private DaisyLink(Socket socket, DaisyLinkModule module) : base(socket, i2cDataPin, i2cClockPin, module) { Ready = false; this.Socket = socket; this.ReservedCount = 0; this.NodeCount = 0; // The link pin (port) is initialized as an input. It is only driven during initialization of the daisylinked modules. // Setting the initial state to false insures that the pin will always drive low when Active is set to true. //daisyLinkCpuPin = socket.ReservePin(daisyLinkPin, module); daisyLinkResetPort = new GTI.DigitalIO(socket, daisyLinkPin, false, GTI.GlitchFilterMode.Off, GTI.ResistorMode.PullUp, module); daisyLinkInterruptPort = null; }
/// <summary> /// Sends a reset pulse on the daisylink chain. This resets all DaisyLink nodes to INIT state, that is, waiting for a DaisyLink message. /// </summary> /// <remarks> /// It is recommended to reboot the mainboard after calling this method because communication to the DaisyLink nodes will fail. /// </remarks> internal void SendResetPulse() { lock (portLock) { if (daisyLinkInterruptPort != null) { daisyLinkInterruptPort.Interrupt -= daisyLinkInterruptPort_OnInterrupt; daisyLinkInterruptPort.Dispose(); // Ask hardware drivers to unreserve this pin daisyLinkInterruptPort = null; } if (daisyLinkResetPort == null) { daisyLinkResetPort = new GTI.DigitalIO(Socket, daisyLinkPin, false, GTI.GlitchFilterMode.Off, GTI.ResistorMode.PullUp, null); } daisyLinkResetPort.IOMode = GTI.DigitalIO.IOModes.Output; // Should drive the neighbor bus high Thread.Sleep(2); // 2 milliseconds is definitely more than 1 ms daisyLinkResetPort.IOMode = GTI.DigitalIO.IOModes.Input; // Pull-downs should take the neighbor bus back low daisyLinkResetPort.Dispose(); // Remove this pin from the hardware's reserved pin list daisyLinkResetPort = null; } }
// Note: A constructor summary is auto-generated by the doc builder. /// <summary></summary> /// <remarks>This automatically checks that the socket supports Type X or Y as appropriate, and reserves the SDA and SCL pins. /// An exception will be thrown if there is a problem with these checks.</remarks> /// <param name="socket">The socket for this software I2C device interface.</param> /// <param name="sdaPin">The socket pin used for I2C data.</param> /// <param name="sclPin">The socket pin used for I2C clock.</param> /// <param name="module">The module using this I2C interface, which can be null if unspecified.</param> public SoftwareI2C(Socket socket, Socket.Pin sdaPin, Socket.Pin sclPin, Module module) { // first check the socket is compatible if (sclPin > Socket.Pin.Five || sdaPin > Socket.Pin.Five) { socket.EnsureTypeIsSupported('Y', module); } else { socket.EnsureTypeIsSupported(new char[] { 'X', 'Y' }, module); } if (ForceManagedSoftwareI2CImplementation || socket.NativeI2CWriteRead == null) { usingManaged = true; } // then see if we've already reserved the pins and got instances of the ports, otherwise do that. string sdaPinString = socket.ToString() + "___" + sdaPin; if (!ReservedSdaPinPorts.Contains(sdaPinString)) { if (usingManaged) { sdaPort = new DigitalIO(socket, sdaPin, false, GlitchFilterMode.Off, ForceManagedPullUps ? ResistorMode.PullUp : ResistorMode.Disabled, module); } ReservedSdaPinPorts.Add(sdaPinString, sdaPort); } else { sdaPort = (DigitalIO)ReservedSdaPinPorts[sdaPinString]; } string sclPinString = socket.ToString() + "___" + sclPin; if (!ReservedSclPinPorts.Contains(sclPinString)) { if (usingManaged) { sclPort = new DigitalIO(socket, sclPin, false, GlitchFilterMode.Off, ForceManagedPullUps ? ResistorMode.PullUp : ResistorMode.Disabled, module); } ReservedSclPinPorts.Add(sclPinString, sclPort); } else { sclPort = (DigitalIO)ReservedSclPinPorts[sclPinString]; } this.socket = socket; this.sdaPin = sdaPin; this.sclPin = sclPin; if (usingManaged) { lock (SoftwareI2CTimeoutList) { timeoutCount = -1; // Prevent the TimeoutHandler thread from watching this port for now SoftwareI2CTimeoutList.Add(this); if (timeoutThread == null) { threadExit = false; timeoutThread = new Thread(new ThreadStart(TimeoutHandler)); timeoutThread.Start(); } } } }
// Note: A constructor summary is auto-generated by the doc builder. /// <summary></summary> /// <remarks>This automatically checks that the socket supports Type X or Y as appropriate, and reserves the SDA and SCL pins. /// An exception will be thrown if there is a problem with these checks.</remarks> /// <param name="socket">The socket for this software I2C device interface.</param> /// <param name="sdaPin">The socket pin used for I2C data.</param> /// <param name="sclPin">The socket pin used for I2C clock.</param> /// <param name="module">The module using this I2C interface, which can be null if unspecified.</param> public SoftwareI2C(Socket socket, Socket.Pin sdaPin, Socket.Pin sclPin, Module module) { // first check the socket is compatible if (sclPin > Socket.Pin.Five || sdaPin > Socket.Pin.Five) { socket.EnsureTypeIsSupported('Y', module); } else { socket.EnsureTypeIsSupported(new char[] { 'X', 'Y' }, module); } if (ForceManagedSoftwareI2CImplementation || socket.NativeI2CWriteRead == null) usingManaged = true; // then see if we've already reserved the pins and got instances of the ports, otherwise do that. string sdaPinString = socket.ToString() + "___" + sdaPin; if (!ReservedSdaPinPorts.Contains(sdaPinString)) { if (usingManaged) { sdaPort = new DigitalIO(socket, sdaPin, false, GlitchFilterMode.Off, ForceManagedPullUps ? ResistorMode.PullUp : ResistorMode.Disabled, module); } ReservedSdaPinPorts.Add(sdaPinString, sdaPort); } else { sdaPort = (DigitalIO)ReservedSdaPinPorts[sdaPinString]; } string sclPinString = socket.ToString() + "___" + sclPin; if (!ReservedSclPinPorts.Contains(sclPinString)) { if (usingManaged) { sclPort = new DigitalIO(socket, sclPin, false, GlitchFilterMode.Off, ForceManagedPullUps ? ResistorMode.PullUp : ResistorMode.Disabled, module); } ReservedSclPinPorts.Add(sclPinString, sclPort); } else { sclPort = (DigitalIO)ReservedSclPinPorts[sclPinString]; } this.socket = socket; this.sdaPin = sdaPin; this.sclPin = sclPin; if (usingManaged) { lock (SoftwareI2CTimeoutList) { timeoutCount = -1; // Prevent the TimeoutHandler thread from watching this port for now SoftwareI2CTimeoutList.Add(this); if (timeoutThread == null) { threadExit = false; timeoutThread = new Thread(new ThreadStart(TimeoutHandler)); timeoutThread.Start(); } } } }