Ejemplo n.º 1
0
            internal HardwareInstance(Microsoft.SPOT.Hardware.SPI.SPI_module module)
            {
                Sharing = Socket.SocketInterfaces.SpiSharing.Shared;
                Users   = 0;

                Module = module;
            }
            internal HardwareInstance(Hardware.SPI.SPI_module module)
            {
                Sharing = SpiSharing.Shared;
                Users   = 0;

                Module = module;
            }
Ejemplo n.º 3
0
            internal HardwareInstance(Hardware.SPI.SPI_module module)
            {
                Sharing = SpiSharing.Shared;
                Users = 0;

                Module = module;
            }
Ejemplo n.º 4
0
            internal HardwareInstance(Microsoft.SPOT.Hardware.SPI.SPI_module module)
            {
                Sharing = Socket.SocketInterfaces.SpiSharing.Shared;
                Users = 0;

                Module = module;
            }
Ejemplo n.º 5
0
 private SPIInstance(Socket socket, Microsoft.SPOT.Hardware.SPI.SPI_module spimodule)
 {
     this.SPIModule   = spimodule;
     this.SharingMode = Sharing.Shared;
     this.Users       = 0;
     this.socket      = socket;
 }
Ejemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="socket">The <see cref="Socket"/> for the <see cref="SPI"/> interface.</param>
        /// <param name="spiConfiguration">The <see cref="Configuration"/> object for the <see cref="SPI"/> interface.</param>
        /// <param name="sharingMode">The <see cref="Sharing"/> mode of the <see cref="SPI"/> interface.</param>
        /// <param name="chipSelectSocket">The chip select <see cref="Socket"/>of the <see cref="SPI"/> interface.</param>
        /// <param name="chipSelectPin">The <see cref="Socket"/></param>
        /// <param name="module">The <see cref="Module"/> that is connected to the <see cref="SPI"/> interface.</param>
        public SPI(Socket socket, Configuration spiConfiguration, Sharing sharingMode, Socket chipSelectSocket, Socket.Pin chipSelectPin, Module module)
        {
            socket.EnsureTypeIsSupported('S', module);

            Cpu.Pin reservedSelectPin = Socket.UnspecifiedPin;

            if (chipSelectSocket != null)
            {
                reservedSelectPin = chipSelectSocket.ReservePin(chipSelectPin, module);
            }

            if (socket.SPIModule != Socket.SocketInterfaces.SPIMissing)
            {
                Interface = new NativeSpi(socket, spiConfiguration == null ? null : new Socket.SocketInterfaces.SpiConfiguration(
                                              spiConfiguration.ChipSelectActiveState,
                                              spiConfiguration.ChipSelectSetupTime,
                                              spiConfiguration.ChipSelectHoldTime,
                                              spiConfiguration.ClockIdleState,
                                              spiConfiguration.ClockEdge,
                                              spiConfiguration.ClockRateKHz,
                                              false), (Socket.SocketInterfaces.SpiSharing)sharingMode, reservedSelectPin, module, socket.SPIModule);
            }

            else
            {
                Interface = socket.SpiIndirector(socket, spiConfiguration == null ? null : new Socket.SocketInterfaces.SpiConfiguration(
                                                     spiConfiguration.ChipSelectActiveState,
                                                     spiConfiguration.ChipSelectSetupTime,
                                                     spiConfiguration.ChipSelectHoldTime,
                                                     spiConfiguration.ClockIdleState,
                                                     spiConfiguration.ClockEdge,
                                                     spiConfiguration.ClockRateKHz,
                                                     false), (Socket.SocketInterfaces.SpiSharing)sharingMode, chipSelectSocket, chipSelectPin, null, default(Socket.Pin), module);
            }

            _spiModule = socket.SPIModule;
        }
Ejemplo n.º 7
0
        private static Microsoft.SPOT.Hardware.SPI.Configuration ToNativeConfiguration(Socket.SocketInterfaces.SpiConfiguration config, Cpu.Pin chipSelectPin, Microsoft.SPOT.Hardware.SPI.SPI_module spiModule)
        {
            if (config == null)
            {
                return(new Microsoft.SPOT.Hardware.SPI.Configuration(chipSelectPin, false, 0, 0, false, false, 0, spiModule));
            }

            return(new Microsoft.SPOT.Hardware.SPI.Configuration(
                       chipSelectPin,
                       config.IsChipSelectActiveHigh,
                       config.ChipSelectSetupTime,
                       config.ChipSelectHoldTime,
                       config.IsClockIdleHigh,
                       config.IsClockSamplingEdgeRising,
                       config.ClockRateKHz,
                       spiModule));
        }
Ejemplo n.º 8
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);
            }
        }
Ejemplo n.º 9
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);
        }
        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);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="socket">The <see cref="Socket"/> for the <see cref="SPI"/> interface.</param>
        /// <param name="spiConfiguration">The <see cref="Configuration"/> object for the <see cref="SPI"/> interface.</param>
        /// <param name="sharingMode">The <see cref="Sharing"/> mode of the <see cref="SPI"/> interface.</param>
        /// <param name="chipSelectSocket">The chip select <see cref="Socket"/>of the <see cref="SPI"/> interface.</param>
        /// <param name="chipSelectPin">The <see cref="Socket"/></param>
        /// <param name="module">The <see cref="Module"/> that is connected to the <see cref="SPI"/> interface.</param>
        public SPI(Socket socket, Configuration spiConfiguration, Sharing sharingMode, Socket chipSelectSocket, Socket.Pin chipSelectPin, Module module)
        {
            socket.EnsureTypeIsSupported('S', module);

            Cpu.Pin reservedSelectPin = Socket.UnspecifiedPin;

            if (chipSelectSocket != null)
                reservedSelectPin = chipSelectSocket.ReservePin(chipSelectPin, module);

            if (socket.SPIModule != Socket.SocketInterfaces.SPIMissing)
                    Interface = new NativeSpi(socket, spiConfiguration == null ? null : new Socket.SocketInterfaces.SpiConfiguration(
                        spiConfiguration.ChipSelectActiveState,
                        spiConfiguration.ChipSelectSetupTime,
                        spiConfiguration.ChipSelectHoldTime,
                        spiConfiguration.ClockIdleState,
                        spiConfiguration.ClockEdge,
                        spiConfiguration.ClockRateKHz,
                        false), (Socket.SocketInterfaces.SpiSharing)sharingMode, reservedSelectPin, module, socket.SPIModule);

            else
                Interface = socket.SpiIndirector(socket, spiConfiguration == null ? null : new Socket.SocketInterfaces.SpiConfiguration(
                    spiConfiguration.ChipSelectActiveState,
                    spiConfiguration.ChipSelectSetupTime,
                    spiConfiguration.ChipSelectHoldTime,
                    spiConfiguration.ClockIdleState,
                    spiConfiguration.ClockEdge,
                    spiConfiguration.ClockRateKHz,
                    false), (Socket.SocketInterfaces.SpiSharing)sharingMode, chipSelectSocket, chipSelectPin, null, default(Socket.Pin), module);

            _spiModule = socket.SPIModule;
        }