internal HardwareInstance(Hardware.SPI.SPI_module module) { Sharing = SpiSharing.Shared; Users = 0; Module = module; }
internal HardwareInstance(Hardware.SPI.SPI_module module) { Sharing = SpiSharing.Shared; Users = 0; Module = module; }
/// <summary> /// Creates an instance of <see cref="Spi" /> for the given socket. /// </summary> /// <param name="socket">The <see cref="Socket"/> for the <see cref="Spi"/> interface.</param> /// <param name="spiConfiguration">The <see cref="SpiConfiguration"/> object for the <see cref="Spi"/> interface.</param> /// <param name="sharingMode">The <see cref="SpiSharing"/> mode of the <see cref="SPI"/> interface.</param> /// <param name="chipSelectSocket">The chip select <see cref="Socket"/> of the <see cref="Spi"/> interface. Can be null if not used.</param> /// <param name="chipSelectSocketPin">The chip select pin on <paramref name="chipSelectSocket"/>.</param> /// <param name="busySocket">The busy <see cref="Socket"/> of the <see cref="Spi" /> interface. Can be null if not used.</param> /// <param name="busySocketPin">The busy pin to on the <paramref name="busySocket"/>.</param> /// <param name="module">The <see cref="Module"/> that is connected to the <see cref="Spi"/> interface.</param> /// <returns></returns> public static Spi Create(Socket socket, SpiConfiguration spiConfiguration, SpiSharing sharingMode, Socket chipSelectSocket, Socket.Pin chipSelectSocketPin, Socket busySocket, Socket.Pin busySocketPin, Module module) { socket.EnsureTypeIsSupported('S', module); Cpu.Pin reservedSelectPin = Socket.UnspecifiedPin; Cpu.Pin reservedBusyPin = Socket.UnspecifiedPin; if (chipSelectSocket != null) { reservedSelectPin = chipSelectSocket.ReservePin(chipSelectSocketPin, module); } if (busySocket != null) { reservedBusyPin = busySocket.ReservePin(busySocketPin, module); } // reserved pins will be: // UnspecifiedPin if no chip select/busy pin is used // UnnumberedPin if a chip select/busy pin was used on an indirected (non-forwarded socket) // a valid Cpu.Pin otherwise if (socket.SPIModule != Socket.SocketInterfaces.SPIMissing) { return(new NativeSpi(socket, spiConfiguration, sharingMode, reservedSelectPin, reservedBusyPin, module, socket.SPIModule)); } else { return(socket.SpiIndirector(socket, spiConfiguration, sharingMode, chipSelectSocket, chipSelectSocketPin, busySocket, busySocketPin, module)); } }
public NativeSpi(Socket socket, SpiConfiguration configuration, SpiSharing sharing, Hardware.Cpu.Pin chipSelectPin, Hardware.Cpu.Pin busyPin, Module module, Hardware.SPI.SPI_module spiModule) { _hardwareInstance = GetAndUseInstance(socket, sharing, module, spiModule); _chipSelectPin = chipSelectPin; _busyPin = busyPin; _configuration = ToNativeConfiguration(configuration, chipSelectPin, busyPin, spiModule); if (_hardwareInstance.Interface == null && _configuration != null) _hardwareInstance.Interface = new Hardware.SPI(_configuration); }
public NativeSpi(Socket socket, SpiConfiguration configuration, SpiSharing sharing, Hardware.Cpu.Pin chipSelectPin, Hardware.Cpu.Pin busyPin, Module module, Hardware.SPI.SPI_module spiModule) { _hardwareInstance = GetAndUseInstance(socket, sharing, module, spiModule); _chipSelectPin = chipSelectPin; _busyPin = busyPin; _configuration = ToNativeConfiguration(configuration, chipSelectPin, busyPin, spiModule); if (_hardwareInstance.Interface == null && _configuration != null) { _hardwareInstance.Interface = new Hardware.SPI(_configuration); } }
private static HardwareInstance GetAndUseInstance(Socket socket, SpiSharing sharing, Module module, Hardware.SPI.SPI_module spiModule) { if (spiModule == Socket.SocketInterfaces.SPIMissing) { // this is a mainboard error that should not happen (we already check for it in SocketInterfaces.RegisterSocket) but just in case... throw Socket.InvalidSocketException.FunctionalityException(socket, "SPI"); } HardwareInstance foundInstance = null; for (int i = 0; i < Instances.Count; i++) { HardwareInstance instance = (HardwareInstance)Instances[i]; if (instance.Module == spiModule) { foundInstance = instance; } } if (foundInstance == null) { Instances.Add(foundInstance = new HardwareInstance(spiModule)); } if (foundInstance.Users == 0) { socket.ReservePin(Socket.Pin.Seven, module); socket.ReservePin(Socket.Pin.Eight, module); socket.ReservePin(Socket.Pin.Nine, module); } else { if (foundInstance.Sharing != SocketInterfaces.SpiSharing.Shared) { throw new Exception("SPI bus " + spiModule + " is already reserved, cannot instantiate it again."); } if (foundInstance.Sharing == SocketInterfaces.SpiSharing.Exclusive) { throw new Exception("SPI bus " + spiModule + " is already shared among " + foundInstance.Users + " users, cannot instantiate it for exclusive use."); } } lock (foundInstance) { foundInstance.Users++; foundInstance.Sharing = sharing; } return(foundInstance); }
/// <summary> /// Creates an instance of <see cref="Spi" /> for the given socket. /// </summary> /// <param name="socket">The <see cref="Socket"/> for the <see cref="Spi"/> interface.</param> /// <param name="spiConfiguration">The <see cref="SpiConfiguration"/> object for the <see cref="Spi"/> interface.</param> /// <param name="sharingMode">The <see cref="SpiSharing"/> mode of the <see cref="SPI"/> interface.</param> /// <param name="chipSelectSocket">The chip select <see cref="Socket"/> of the <see cref="Spi"/> interface. Can be null if not used.</param> /// <param name="chipSelectSocketPin">The chip select pin on <paramref name="chipSelectSocket"/>.</param> /// <param name="busySocket">The busy <see cref="Socket"/> of the <see cref="Spi" /> interface. Can be null if not used.</param> /// <param name="busySocketPin">The busy pin to on the <paramref name="busySocket"/>.</param> /// <param name="module">The <see cref="Module"/> that is connected to the <see cref="Spi"/> interface.</param> /// <returns></returns> public static Spi Create(Socket socket, SpiConfiguration spiConfiguration, SpiSharing sharingMode, Socket chipSelectSocket, Socket.Pin chipSelectSocketPin, Socket busySocket, Socket.Pin busySocketPin, Module module) { socket.EnsureTypeIsSupported('S', module); Cpu.Pin reservedSelectPin = Socket.UnspecifiedPin; Cpu.Pin reservedBusyPin = Socket.UnspecifiedPin; if (chipSelectSocket != null) reservedSelectPin = chipSelectSocket.ReservePin(chipSelectSocketPin, module); if (busySocket != null) reservedBusyPin = busySocket.ReservePin(busySocketPin, module); // reserved pins will be: // UnspecifiedPin if no chip select/busy pin is used // UnnumberedPin if a chip select/busy pin was used on an indirected (non-forwarded socket) // a valid Cpu.Pin otherwise if (socket.SPIModule != Socket.SocketInterfaces.SPIMissing) return new NativeSpi(socket, spiConfiguration, sharingMode, reservedSelectPin, reservedBusyPin, module, socket.SPIModule); else return socket.SpiIndirector(socket, spiConfiguration, sharingMode, chipSelectSocket, chipSelectSocketPin, busySocket, busySocketPin, module); }
/// <summary> /// Creates an instance of <see cref="Spi" /> for the given socket. /// </summary> /// <param name="socket">The <see cref="Socket"/> for the <see cref="Spi"/> interface.</param> /// <param name="spiConfiguration">The <see cref="SpiConfiguration"/> object for the <see cref="Spi"/> interface.</param> /// <param name="sharingMode">The <see cref="SpiSharing"/> mode of the <see cref="SPI"/> interface.</param> /// <param name="chipSelectSocket">The chip select <see cref="Socket"/> of the <see cref="Spi"/> interface. Can be null if not used.</param> /// <param name="chipSelectSocketPin">The chip select pin on <paramref name="chipSelectSocket"/>.</param> /// <param name="module">The <see cref="Module"/> that is connected to the <see cref="Spi"/> interface.</param> /// <returns></returns> public static Spi Create(Socket socket, SpiConfiguration spiConfiguration, SpiSharing sharingMode, Socket chipSelectSocket, Socket.Pin chipSelectSocketPin, Module module) { return(Create(socket, spiConfiguration, sharingMode, chipSelectSocket, chipSelectSocketPin, null, Socket.Pin.None, module)); }
private static HardwareInstance GetAndUseInstance(Socket socket, SpiSharing sharing, Module module, Hardware.SPI.SPI_module spiModule) { if (spiModule == Socket.SocketInterfaces.SPIMissing) { // this is a mainboard error that should not happen (we already check for it in SocketInterfaces.RegisterSocket) but just in case... throw Socket.InvalidSocketException.FunctionalityException(socket, "SPI"); } HardwareInstance foundInstance = null; for (int i = 0; i < Instances.Count; i++) { HardwareInstance instance = (HardwareInstance)Instances[i]; if (instance.Module == spiModule) foundInstance = instance; } if (foundInstance == null) Instances.Add(foundInstance = new HardwareInstance(spiModule)); if (foundInstance.Users == 0) { socket.ReservePin(Socket.Pin.Seven, module); socket.ReservePin(Socket.Pin.Eight, module); socket.ReservePin(Socket.Pin.Nine, module); } else { if (foundInstance.Sharing != SocketInterfaces.SpiSharing.Shared) throw new Exception("SPI bus " + spiModule + " is already reserved, cannot instantiate it again."); if (foundInstance.Sharing == SocketInterfaces.SpiSharing.Exclusive) throw new Exception("SPI bus " + spiModule + " is already shared among " + foundInstance.Users + " users, cannot instantiate it for exclusive use."); } lock (foundInstance) { foundInstance.Users++; foundInstance.Sharing = sharing; } return foundInstance; }
/// <summary> /// Creates an instance of <see cref="Spi" /> for the given socket. /// </summary> /// <param name="socket">The <see cref="Socket"/> for the <see cref="Spi"/> interface.</param> /// <param name="spiConfiguration">The <see cref="SpiConfiguration"/> object for the <see cref="Spi"/> interface.</param> /// <param name="sharingMode">The <see cref="SpiSharing"/> mode of the <see cref="SPI"/> interface.</param> /// <param name="chipSelectSocket">The chip select <see cref="Socket"/> of the <see cref="Spi"/> interface. Can be null if not used.</param> /// <param name="chipSelectSocketPin">The chip select pin on <paramref name="chipSelectSocket"/>.</param> /// <param name="module">The <see cref="Module"/> that is connected to the <see cref="Spi"/> interface.</param> /// <returns></returns> public static Spi Create(Socket socket, SpiConfiguration spiConfiguration, SpiSharing sharingMode, Socket chipSelectSocket, Socket.Pin chipSelectSocketPin, Module module) { return Create(socket, spiConfiguration, sharingMode, chipSelectSocket, chipSelectSocketPin, null, Socket.Pin.None, module); }