示例#1
0
            internal HardwareInstance(Microsoft.SPOT.Hardware.SPI.SPI_module module)
            {
                Sharing = Socket.SocketInterfaces.SpiSharing.Shared;
                Users   = 0;

                Module = module;
            }
示例#2
0
            internal HardwareInstance(Microsoft.SPOT.Hardware.SPI.SPI_module module)
            {
                Sharing = Socket.SocketInterfaces.SpiSharing.Shared;
                Users = 0;

                Module = module;
            }
示例#3
0
        private static HardwareInstance GetAndUseInstance(Socket socket, Socket.SocketInterfaces.SpiSharing sharing, Module module, Microsoft.SPOT.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 != Socket.SocketInterfaces.SpiSharing.Shared)
                {
                    throw new Exception("SPI bus " + spiModule + " is already reserved, cannot instantiate it again.");
                }

                if (foundInstance.Sharing == Socket.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);
        }
示例#4
0
        public NativeSpi(Socket socket, Socket.SocketInterfaces.SpiConfiguration configuration, Socket.SocketInterfaces.SpiSharing sharing, Cpu.Pin chipSelectPin, Module module, Microsoft.SPOT.Hardware.SPI.SPI_module spiModule)
        {
            _hardwareInstance = GetAndUseInstance(socket, sharing, module, spiModule);
            _chipSelectPin    = chipSelectPin;
            _configuration    = ToNativeConfiguration(configuration, chipSelectPin, spiModule);

            if (_hardwareInstance.Interface == null && _configuration != null)
            {
                _hardwareInstance.Interface = new Microsoft.SPOT.Hardware.SPI(_configuration);
            }
        }