Example #1
0
        static void TestNonVoltatileRam(INonVolatileRam nvram)
        {
            Console.Write("*** Test NVRAM: ");

            try {
                // read/write manufacters and product names
                string manufacterName = nvram.ManufacterName;
                string productName    = nvram.ProductName;

                nvram.ManufacterName = "Myself";
                nvram.ProductName    = "SomeProduct";

                string manufacterNameAfter = nvram.ManufacterName;
                string productNameAfter    = nvram.ProductName;

                nvram.ManufacterName = manufacterName;
                nvram.ProductName    = productName;

                // read USB settings
                UsbKeyPowerSettings usbPowerSettings0 = nvram.ReadUsbSettings();
                nvram.WriteUsbSettings(usbPowerSettings0);
                UsbKeyPowerSettings usbPowerSettings1 = nvram.ReadUsbSettings();

                // set the chip configuration
                ChipSettings chipSettings = new ChipSettings();
                chipSettings.InterruptBitMode    = DedicatedFunction.NoInterruptCounting;
                chipSettings.RemoteWakeUpEnabled = true;
                chipSettings.SpiBusReleaseEnable = true;
                chipSettings.AccessControl       = NramChipAccessControl.PasswordProtected;
                chipSettings.Password            = Password;
                chipSettings.PinDirections       = new PinDirection[] {
                    PinDirection.Output,
                    PinDirection.Output,
                    PinDirection.Output,
                    PinDirection.Output,
                    PinDirection.Output,
                    PinDirection.Output,
                    PinDirection.Output,
                    PinDirection.Output,
                    PinDirection.Output
                };

                chipSettings.PinModes = new PinMode[] {
                    PinMode.GPIO,
                    PinMode.GPIO,
                    PinMode.GPIO,
                    PinMode.GPIO,
                    PinMode.GPIO,
                    PinMode.GPIO,
                    PinMode.GPIO,
                    PinMode.GPIO,
                    PinMode.GPIO
                };

                chipSettings.DefaultOutput = new bool[] {
                    true,
                    true,
                    true,
                    true,
                    false,
                    false,
                    false,
                    true,
                    true
                };

                nvram.ConfigureChip(chipSettings);
                ChipSettings readSettings = nvram.ReadChipConfiguration();

                // configure SPI
                SpiSetup spiSetup = new SpiSetup();
                spiSetup.BitRate               = 300000;
                spiSetup.BytesToTransfer       = NumberOfBytes;
                spiSetup.ChipSelectToDataDelay = 3;
                spiSetup.BetweenDataDelay      = 3;
                spiSetup.DataToChipSelectDelay = 3;
                spiSetup.Mode = SpiModes.Spi0;
                spiSetup.ActiveChipSelectValues = new bool[] {
                    true,
                    true,
                    true,
                    true,
                    true,
                    true,
                    true,
                    true,
                    true
                };
                spiSetup.IdleChipSelectValues = new bool[] {
                    false,
                    false,
                    false,
                    false,
                    false,
                    false,
                    false,
                    false,
                    false
                };

                nvram.ConfigureSpi(spiSetup);

                // read spi configuration
                SpiSetup readSpiSetup = nvram.ReadSpiConfiguration();

                Console.WriteLine("completed successfully");
            } catch (Exception ex) {
                PrintException(ex);
            }
        }
Example #2
0
        static void TestVoltatileRam(IVolatileRam ram)
        {
            Console.Write("*** Test RAM: ");

            try {
                // set the chip configuration
                ChipSettings chipSettings = new ChipSettings();
                chipSettings.InterruptBitMode    = DedicatedFunction.NoInterruptCounting;
                chipSettings.RemoteWakeUpEnabled = false;
                chipSettings.SpiBusReleaseEnable = false;
                // these are never used by the volatile RAM
                //chipSettings.AccessControl = NramChipAccessControl.PasswordProtected;
                //chipSettings.Password = "******";
                chipSettings.PinDirections = new PinDirection[] {
                    PinDirection.Output,
                    PinDirection.Output,
                    PinDirection.Output,
                    PinDirection.Output,
                    PinDirection.Output,
                    PinDirection.Output,
                    PinDirection.Output,
                    PinDirection.Output,
                    PinDirection.Output
                };

                chipSettings.PinModes = new PinMode[] {
                    PinMode.GPIO,
                    PinMode.GPIO,
                    PinMode.GPIO,
                    PinMode.GPIO,
                    PinMode.GPIO,
                    PinMode.GPIO,
                    PinMode.GPIO,
                    PinMode.DedicatedFunction, // release status bit
                    PinMode.GPIO
                };

                chipSettings.DefaultOutput = new bool[] {
                    true,
                    false,
                    false,
                    true,
                    false,
                    false,
                    false,
                    true,
                    true
                };

                ram.ConfigureChip(chipSettings);
                ChipSettings readSettings = ram.ReadChipConfiguration();

                // configure SPI
                SpiSetup spiSetup = new SpiSetup();
                spiSetup.BitRate               = 200000;
                spiSetup.BytesToTransfer       = NumberOfBytes;
                spiSetup.ChipSelectToDataDelay = 0;
                spiSetup.BetweenDataDelay      = 0;
                spiSetup.DataToChipSelectDelay = 0;
                spiSetup.Mode = SpiModes.Spi2;
                spiSetup.ActiveChipSelectValues = new bool[] {
                    true,
                    true,
                    true,
                    true,
                    true,
                    true,
                    true,
                    true,
                    true
                };
                spiSetup.IdleChipSelectValues = new bool[] {
                    false,
                    false,
                    false,
                    false,
                    false,
                    false,
                    false,
                    false,
                    false
                };

                ram.ConfigureSpi(spiSetup);

                // read spi configuration
                SpiSetup readSpiSetup = ram.ReadSpiConfiguration();

                // set the gpio output
                bool[] output = new bool[] {
                    false,
                    true,
                    true,
                    false,
                    true,
                    true,
                    false,
                    true,
                    true
                };

                ram.GpioPinsValue = output;

                Console.WriteLine("completed successfully");
            } catch (Exception ex) {
                PrintException(ex);
            }
        }